HSBSupport.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //==============================================================================
  2. //
  3. // HSBSupport
  4. // HSBSupport
  5. //
  6. // Created by Troy Gaul on 7 Aug 2010.
  7. //
  8. // Copyright (c) 2011-2013 InfinitApps LLC: http://infinitapps.com
  9. // Some rights reserved: http://opensource.org/licenses/MIT
  10. //
  11. //==============================================================================
  12. #import <UIKit/UIKit.h>
  13. //------------------------------------------------------------------------------
  14. float pin(float minValue, float value, float maxValue);
  15. //------------------------------------------------------------------------------
  16. // These functions convert between an RGB value with components in the
  17. // 0.0f..1.0f range to HSV where Hue is 0 .. 360 and Saturation and
  18. // Value (aka Brightness) are percentages expressed as 0.0f..1.0f.
  19. //
  20. // Note that HSB (B = Brightness) and HSV (V = Value) are interchangeable
  21. // names that mean the same thing. I use V here as it is unambiguous
  22. // relative to the B in RGB, which is Blue.
  23. void HSVtoRGB(float h, float s, float v, float* r, float* g, float* b);
  24. void RGBToHSV(float r, float g, float b, float* h, float* s, float* v,
  25. BOOL preserveHS);
  26. //------------------------------------------------------------------------------
  27. CGImageRef createSaturationBrightnessSquareContentImageWithHue(float hue);
  28. // Generates a 256x256 image with the specified constant hue where the
  29. // Saturation and value vary in the X and Y axes respectively.
  30. //------------------------------------------------------------------------------
  31. typedef enum {
  32. InfComponentIndexHue = 0,
  33. InfComponentIndexSaturation = 1,
  34. InfComponentIndexBrightness = 2,
  35. } InfComponentIndex;
  36. CGImageRef createHSVBarContentImage(InfComponentIndex barComponentIndex, float hsv[3]);
  37. // Generates an image where the specified barComponentIndex (0=H, 1=S, 2=V)
  38. // varies across the x-axis of the 256x1 pixel image and the other components
  39. // remain at the constant value specified in the hsv array.
  40. //------------------------------------------------------------------------------