1
0

nximage.c 622 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "nximage.h"
  2. static HANDLE image_heap;
  3. void NXImageSetHeap(HANDLE _image_heap)
  4. {
  5. if (!image_heap)
  6. image_heap = _image_heap;
  7. }
  8. static size_t NXImageMallocSize(size_t bytes)
  9. {
  10. return sizeof(nx_image_s) + bytes - sizeof(ARGB32);
  11. }
  12. nx_image_t NXImageMalloc(uint32_t width, uint32_t height)
  13. {
  14. size_t bytes;
  15. nx_image_t img;
  16. bytes = width*height*4; // TODO: overflow check
  17. img = (nx_image_t)malloc(NXImageMallocSize(bytes));
  18. img->ref_count = 1;
  19. img->len = bytes;
  20. img->width = width;
  21. img->height = height;
  22. return img;
  23. }
  24. nx_image_t NXImageRetain(nx_image_t image)
  25. {
  26. image->ref_count++;
  27. return image;
  28. }