color_find.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #ifndef COLOR_FIND_H
  3. #define COLOR_FIND_H
  4. #include "MMBitmap.h"
  5. #include "MMPointArray.h"
  6. /* Convenience wrapper around findColorInRect(), where |rect| is the bounds of
  7. * the image. */
  8. #define findColorInImage(image, color, pointPtr, tolerance) \
  9. findColorInRect(image, color, pointPtr, MMBitmapGetBounds(image), tolerance)
  10. /* Attempt to find a pixel with the given color in |image| inside |rect|.
  11. * Returns 0 on success, non-zero on failure. If the color was found and
  12. * |point| is not NULL, it will be initialized to the (x, y) coordinates the
  13. * RGB color.
  14. *
  15. * |tolerance| should be in the range 0.0f - 1.0f, denoting how closely the
  16. * colors need to match, with 0 being exact and 1 being any. */
  17. int findColorInRect(MMBitmapRef image, MMRGBHex color, MMPoint *point,
  18. MMRect rect, float tolerance);
  19. /* Convenience wrapper around findAllRGBInRect(), where |rect| is the bounds of
  20. * the image. */
  21. #define findAllColorInImage(image, color, tolerance) \
  22. findAllColorInRect(image, color, MMBitmapGetBounds(image), tolerance)
  23. /* Returns MMPointArray of all pixels of given color in |image| inside of
  24. * |rect|. Note that an array is returned regardless of whether the color was
  25. * found; check array->count to see if it actually was.
  26. *
  27. * Responsibility for freeing the MMPointArray with destroyMMPointArray() is
  28. * given to the caller.
  29. *
  30. * |tolerance| should be in the range 0.0f - 1.0f, denoting how closely the
  31. * colors need to match, with 0 being exact and 1 being any. */
  32. MMPointArrayRef findAllColorInRect(MMBitmapRef image, MMRGBHex color,
  33. MMRect rect, float tolerance);
  34. /* Convenience wrapper around countOfColorsInRect, where |rect| is the bounds
  35. * of the image. */
  36. #define countOfColorsInImage(image, color, tolerance) \
  37. countOfColorsInRect(image, color, MMBitmapGetBounds(image), tolerance)
  38. /* Returns the count of the given color in |rect| inside of |image|. */
  39. size_t countOfColorsInRect(MMBitmapRef image, MMRGBHex color, MMRect rect,
  40. float tolerance);
  41. #endif /* COLOR_FIND_H */