color.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*=============================================================================
  2. Name : color.h
  3. Purpose : Definitions for color definition.
  4. Created 7/7/1997 by lmoloney
  5. Copyright Relic Entertainment, Inc. All rights reserved.
  6. =============================================================================*/
  7. #ifndef ___COLOR_H
  8. #define ___COLOR_H
  9. #include "types.h"
  10. /*=============================================================================
  11. Type definitions:
  12. =============================================================================*/
  13. typedef udword rgbquad;
  14. typedef udword rgbaquad;
  15. typedef rgbquad color;
  16. /*=============================================================================
  17. Macros:
  18. =============================================================================*/
  19. //create RGB/RGBA quads
  20. #define colRGB(r,g,b) (0xff000000 | (((ubyte)(b)) << 16) | (((ubyte)(g)) << 8) | ((ubyte)(r)))
  21. #define colRGBA(r,g,b,a) ((((udword)(a)) << 24) | (((udword)(b)) << 16) | (((udword)(g)) << 8) | (udword)(r))
  22. //extract elements from RGB/RGBA quads
  23. #define colRed(rgb) ((ubyte)((rgb) & 0x000000ff))
  24. #define colGreen(rgb) ((ubyte)(((rgb) & 0x0000ff00) >> 8))
  25. #define colBlue(rgb) ((ubyte)(((rgb) & 0x00ff0000) >> 16))
  26. #define colAlpha(rgba) ((ubyte)(((rgba) & 0xff000000) >> 24))
  27. #define colClampRed(rgb) colClamp256(colRed(rgb))
  28. #define colClampGreen(rgb) colClamp256(colGreen(rgb))
  29. #define colClampBlue(rgb) colClamp256(colBlue(rgb))
  30. #define colClampAlpha(rgba) colClamp256(colAlpha(rgb))
  31. #define colReal32(c) ((real32)(c) / 256.0f)
  32. //stock colors
  33. #define colWhite colRGB(255, 255, 255)
  34. #define colBlack colRGB(0, 0, 0)
  35. #define colFuscia colRGB(73, 98, 100)
  36. #define colReddish colRGB(239, 61, 46)
  37. //convert between ubyte colors (0..255) and floating point colors (0..1)
  38. #define colUbyteToReal(b) ((real32)(b) / 255.0f)
  39. #define colRealToUbyte(r) ((ubyte)((r) * 255.0f))
  40. #define colUdwordToReal(b) ((real32)(b) / 256.0f)
  41. #define colRealToUdword(r) ((udword)((r) * 256.0f))
  42. #define colClamp256(n) ((n) < 0 ? 0 : ((n) > 255 ? 255 : (n)))
  43. /*=============================================================================
  44. Functions:
  45. =============================================================================*/
  46. //color-space conversions
  47. void colRGBToHSV(real32 *H, real32 *S, real32 *V, real32 R, real32 G, real32 B);
  48. void colHSVToRGB(real32 *R, real32 *G, real32 *B, real32 H, real32 S, real32 V);
  49. void colRGBToHLS(real32 *H, real32 *L, real32 *S, real32 R, real32 G, real32 B);
  50. void colHLSToRGB(real32 *R, real32 *G, real32 *B, real32 H, real32 L, real32 S);
  51. udword colIntensityNTSC(color c);
  52. //palette mapping crap
  53. color colBestFitFindRGB(color *palette, color colorToMatch, sdword length);
  54. //utilities
  55. color colMultiply(color c, real32 factor);
  56. color colMultiplyClamped(color c, real32 factor);
  57. sdword colRGBCompare(color *p0, color *p1, sdword nPixels);
  58. color colBlend(color c0, color c1, real32 factor);
  59. #endif //___COLOR_H