MMBitmap.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #ifndef MMBITMAP_H
  3. #define MMBITMAP_H
  4. #include "types.h"
  5. #include "rgb.h"
  6. #include <assert.h>
  7. #include <stdint.h>
  8. struct _MMBitmap {
  9. uint8_t *imageBuffer; /* Pixels stored in Quad I format; */
  10. int32_t width; /* Never 0, unless image is NULL. */
  11. int32_t height; /* Never 0, unless image is NULL. */
  12. int32_t bytewidth; /* The aligned width (width + padding). */
  13. uint8_t bitsPerPixel; /* Should be either 24 or 32. */
  14. uint8_t bytesPerPixel; /* For convenience; should be bitsPerPixel / 8. */
  15. };
  16. typedef struct _MMBitmap MMBitmap;
  17. typedef MMBitmap *MMBitmapRef;
  18. #define MMBitmapPointInBounds(image, p) ((p).x < (image)->width && (p).y < (image)->height)
  19. /* Get pointer to pixel of MMBitmapRef. No bounds checking is performed */
  20. #define MMRGBColorRefAtPoint(image, x, y) \
  21. (MMRGBColor *)(assert(MMBitmapPointInBounds(image, MMPointInt32Make(x, y))), \
  22. ((image)->imageBuffer) + (((image)->bytewidth * (y)) + ((x) * (image)->bytesPerPixel)))
  23. /* Dereference pixel of MMBitmapRef. Again, no bounds checking is performed. */
  24. #define MMRGBColorAtPoint(image, x, y) *MMRGBColorRefAtPoint(image, x, y)
  25. /* Hex/integer value of color at point. */
  26. #define MMRGBHexAtPoint(image, x, y) hexFromMMRGB(MMRGBColorAtPoint(image, x, y))
  27. #endif /* MMBITMAP_H */