- Main Page
- Classes
- Files

- File List
- File Members

# flColor.h

Go to the documentation of this file.

    00001 // Funclib Color v1.0.0
    00002 //
    00003 // This module contains color manipulation functions.
    00004 // Use it in games/apps where complex colors are required.
    00005 // This module doesn't have any module requirements.
    00006 // This module works better when used in conjunction with MATH.
    00007 //
    00008 // Contributor(s): Flatmush
    00009
    00010
    00011
    00012 #ifndef FLCOLOR_H
    00013 #define FLCOLOR_H
    00014
    00015 #include "flGlobal.h"
    00016
    00017 #if FL_COLOR != 0
    00018
    00019 #ifdef __cplusplus
    00020 extern "C" {
    00021 #endif
    00022
    00023 /*extern u8 colorRed8888(u32 inColor);
    00024 extern u8  colorGreen8888(u32 inColor);
    00025 extern u8  colorBlue8888(u32 inColor);
    00026 extern u8  colorAlpha8888(u32 inColor);
    00027 extern u32 colorRGB8888(u8 inRed, u8 inGreen, u8 inBlue);
    00028 extern u32 colorRGBA8888(u8 inRed, u8 inGreen, u8 inBlue, u8 inAlpha);*/
    00029 #define colorRed8888(inColor) color8888_Red(inColor)
    00030 #define colorGreen8888(inColor) color8888_Green(inColor)
    00031 #define colorBlue8888(inColor) color8888_Blue(inColor)
    00032 #define colorAlpha8888(inColor) color8888_Alpha(inColor)
    00033 #define colorRGB8888(inRed, inGreen, inBlue) color8888_RGB(inRed, inGreen, inBlue)
    00034 #define colorRGBA8888(inRed, inGreen, inBlue, inAlpha) color8888_RGBA(inRed, inGreen, inBlue, inAlpha)
    00035
    00036
    00037 extern u32 colorHSL(u8 inHue, u8 inSat, u8 inLum);
    00038 extern u8  colorHue8888(u32 inColor);
    00039 extern u8  colorLum8888(u32 inColor);
    00040 extern u8  colorSat8888(u32 inColor);
    00041 //extern u32 colorBlend8888(u32 inColor0, u32 inColor1, float inRatio);
    00042 #define colorBlend8888(inColor0, inColor1, inRatio) color8888_Blend(inColor0, inColor1, inRatio)
    00043 #define colorMerge8888(inColor0, inColor1) color8888_Merge(inColor0, inColor1)
    00044 extern u32 colorMergeN8888(u32* inColor, u32 inColorCount);
    00045 extern u16 colorMergeN4444(u16* inColor, u16 inColorCount);
    00046 extern u16 colorMergeN5551(u16* inColor, u16 inColorCount);
    00047 extern u16 colorMergeN565(u16* inColor, u16 inColorCount);
    00048 #define colorMergeN5650(inColor, inColorCount) colorMergeN565(inColor, inColorCount)
    00049 extern u32 colorRandom8888(u8 inBaseLum, u8 inRandLum, u8 inAlpha);
    00050 extern u32 colorLumMult8888(u32 inColor, float inLum);
    00051 extern u32 colorAlphaMult8888(u32 inColor, float inMult);
    00052
    00053 #ifdef __cplusplus
    00054 }
    00055 #endif
    00056
    00057 #else
    00058
    00059 #define colorRed8888(inColor) color8888_Red(inColor)
    00060 #define colorGreen8888(inColor) color8888_Green(inColor)
    00061 #define colorBlue8888(inColor) color8888_Blue(inColor)
    00062 #define colorAlpha8888(inColor) color8888_Alpha(inColor)
    00063 #define colorRGB8888(inRed, inGreen, inBlue) color8888_RGB(inRed, inGreen, inBlue)
    00064 #define colorRGBA8888(inRed, inGreen, inBlue, inAlpha) color8888_RGBA(inRed, inGreen, inBlue, inAlpha)
    00065 #define colorBlend8888(inColor0, inColor1, inRatio) color8888_Blend(inColor0, inColor1, inRatio)
    00066 #define colorMerge8888(inColor0, inColor1) color8888_Merge(inColor0, inColor1)
    00067
    00068 #endif
    00069
    00070 #define color8888_Red(inColor) ((inColor) & 0x000000FF)
    00071 #define color8888_Green(inColor) (((inColor) & 0x0000FF00) >> 8)
    00072 #define color8888_Blue(inColor) (((inColor) & 0x00FF0000) >> 16)
    00073 #define color8888_Alpha(inColor) (((inColor) & 0xFF0000) >> 24)
    00074 #define color8888_SetAlpha(inColor, inAlpha) (((inColor) & 0x00FFFFFF) | (((inAlpha) & 0xFF) << 24))
    00075 #define color8888_RGBA(inRed, inGreen, inBlue, inAlpha) (((inRed) + ((inGreen) << 8) + ((inBlue) << 16)) | ((inAlpha) << 24))
    00076 #define color8888_RGB(inRed, inGreen, inBlue) (((inRed) + ((inGreen) << 8) + ((inBlue) << 16)) | (0xFF000000))
    00077 #define color8888_Merge(inColor0, inColor1) color8888_RGBA(((color8888_Red(inColor0) + color8888_Red(inColor1)) >> 1), ((color8888_Green(inColor0) + color8888_Green(inColor1)) >> 1), ((color8888_Blue(inColor0) + color8888_Blue(inColor1)) >> 1), ((color8888_Alpha(inColor0) + color8888_Alpha(inColor1)) >> 1))
    00078 #define color8888_Merge3(inColor0, inColor1, inColor2) color8888_RGBA(((color8888_Red(inColor0) + color8888_Red(inColor1) + color8888_Red(inColor2)) / 3), ((color8888_Green(inColor0) + color8888_Green(inColor1) + color8888_Green(inColor2)) / 3), ((color8888_Blue(inColor0) + color8888_Blue(inColor1) + color8888_Blue(inColor2)) / 3), ((color8888_Alpha(inColor0) + color8888_Alpha(inColor1) + color8888_Alpha(inColor2)) / 3))
    00079 #define color8888_Merge4(inColor0, inColor1, inColor2, inColor3) color8888_RGBA(((color8888_Red(inColor0) + color8888_Red(inColor1) + color8888_Red(inColor2) + color8888_Red(inColor3)) >> 2), ((color8888_Green(inColor0) + color8888_Green(inColor1) + color8888_Green(inColor2) + color8888_Green(inColor3)) >> 2), ((color8888_Blue(inColor0) + color8888_Blue(inColor1) + color8888_Blue(inColor2) + color8888_Blue(inColor3)) >> 2), ((color8888_Alpha(inColor0) + color8888_Alpha(inColor1) + color8888_Alpha(inColor2) + color8888_Alpha(inColor3)) >> 2))
    00080 #define color8888_Blend(inColor0, inColor1, inFract) color8888_RGBA((int)(((float)color8888_Red(inColor0) * (float)(inFract)) + ((float)color8888_Red(inColor1) * (1.0f - (float)(inFract)))), (int)(((float)color8888_Green(inColor0) * (float)(inFract)) + ((float)color8888_Green(inColor1) * (1.0f - (float)(inFract)))), (int)(((float)color8888_Blue(inColor0) * (float)(inFract)) + ((float)color8888_Blue(inColor1) * (1.0f - (float)(inFract)))), (int)(((float)color8888_Alpha(inColor0) * (float)(inFract)) + ((float)color8888_Alpha(inColor1) * (1.0f - (float)(inFract)))))
    00081 #define color8888_CMYK(inCyan, inMagenta, inYellow, inKey) color8888_Merge3(color8888_Blend(0xFFFFFF00, colorRGB((inKey), (inKey), (inKey)), ((float)(inCyan) / 255.0f)), color8888_Blend(0xFFFF00FF, colorRGB((inKey), (inKey), (inKey)), ((float)(inMagenta) / 255.0f)), color8888_Blend(0xFF00FFFF, colorRGB((inKey), (inKey), (inKey)), ((float)(inYellow) / 255.0f)))
    00082 #define color8888_CMYKA(inCyan, inMagenta, inYellow, inKey, inAlpha) color8888_SetAlpha(color8888_CMYK(inCyan, inMagenta, inYellow, inKey), inAlpha)
    00083 #define color8888_CMY(inCyan, inMagenta, inYellow) color8888_RGB((255 - (inCyan)), (255 - (inMagenta)), (255 - (inYellow)))
    00084 #define color8888_CMYA(inCyan, inMagenta, inYellow, inAlpha) color8888_SetAlpha(color8888_CMY(inCyan, inMagenta, inYellow), inAlpha)
    00085 #define color8888_Cmp(inColor0, inColor1) (pos((int)color8888_Red(inColor0) - (int)color8888_Red(inColor1)) + pos((int)color8888_Green(inColor0) - (int)color8888_Green(inColor1)) + pos((int)color8888_Blue(inColor0) - (int)color8888_Blue(inColor1)) + pos((int)color8888_Alpha(inColor0) - (int)color8888_Alpha(inColor1)))
    00086 #define color8888_Compare(inColor0, inColor1) color8888_Cmp(inColor0, inColor1)
    00087
    00088 #define color4444_Red(inColor) ((inColor) & 0x000F)
    00089 #define color4444_Green(inColor) (((inColor) & 0x00F0) >> 4)
    00090 #define color4444_Blue(inColor) (((inColor) & 0x0F00) >> 8)
    00091 #define color4444_Alpha(inColor) (((inColor) & 0xF000) >> 12)
    00092 #define color4444_RGBA(inRed, inGreen, inBlue, inAlpha) (((inRed) & 0x000F) + (((inGreen) & 0x000F) << 4) + (((inBlue) & 0x000F) << 8) + (((inAlpha) & 0x000F) << 12))
    00093 #define color4444_RGB(inRed, inGreen, inBlue) color4444_RGBA(inRed, inGreen, inBlue, 15);
    00094 #define color4444_Merge(inColor0, inColor1) color4444_RGBA(((color4444_Red(inColor0) + color4444_Red(inColor1)) >> 1), ((color4444_Green(inColor0) + color4444_Green(inColor1)) >> 1), ((color4444_Blue(inColor0) + color4444_Blue(inColor1)) >> 1), ((color4444_Alpha(inColor0) + color4444_Alpha(inColor1)) >> 1))
    00095 #define color4444_Merge4(inColor0, inColor1, inColor2, inColor3) color4444_RGBA(((color4444_Red(inColor0) + color4444_Red(inColor1) + color4444_Red(inColor2) + color4444_Red(inColor3)) >> 2), ((color4444_Green(inColor0) + color4444_Green(inColor1) + color4444_Green(inColor2) + color4444_Green(inColor3)) >> 2), ((color4444_Blue(inColor0) + color4444_Blue(inColor1) + color4444_Blue(inColor2) + color4444_Blue(inColor3)) >> 2), ((color4444_Alpha(inColor0) + color4444_Alpha(inColor1) + color4444_Alpha(inColor2) + color4444_Alpha(inColor3)) >> 2))
    00096 #define color4444_Cmp(inColor0, inColor1) (pos((int)color4444_Red(inColor0) - (int)color4444_Red(inColor1)) + pos((int)color4444_Green(inColor0) - (int)color4444_Green(inColor1)) + pos((int)color4444_Blue(inColor0) - (int)color4444_Blue(inColor1)) + pos((int)color4444_Alpha(inColor0) - (int)color4444_Alpha(inColor1)))
    00097 #define color4444_Compare(inColor0, inColor1) color4444_Cmp(inColor0, inColor1)
    00098
    00099 #define color5551_Red(inColor) ((inColor) & 0x001F)
    00100 #define color5551_Green(inColor) (((inColor) & 0x03E0) >> 5)
    00101 #define color5551_Blue(inColor) (((inColor) & 0x7C00) >> 10)
    00102 #define color5551_Alpha(inColor) (((inColor) & 0x8000) >> 15)
    00103 #define color5551_RGBA(inRed, inGreen, inBlue, inAlpha) (((inRed) & 0x001F) + (((inGreen) & 0x001F) << 5) + (((inBlue) & 0x001F) << 10) + (((inAlpha) & 0x0001) << 15))
    00104 #define color5551_RGB(inRed, inGreen, inBlue) color5551_RGBA(inRed, inGreen, inBlue, 1);
    00105 #define color5551_Merge(inColor0, inColor1) color5551_RGBA(((color5551_Red(inColor0) + color5551_Red(inColor1)) >> 1), ((color5551_Green(inColor0) + color5551_Green(inColor1)) >> 1), ((color5551_Blue(inColor0) + color5551_Blue(inColor1)) >> 1), ((color5551_Alpha(inColor0) + color5551_Alpha(inColor1)) >> 1))
    00106 #define color5551_Merge4(inColor0, inColor1, inColor2, inColor3) color5551_RGBA(((color5551_Red(inColor0) + color5551_Red(inColor1) + color5551_Red(inColor2) + color5551_Red(inColor3)) >> 2), ((color5551_Green(inColor0) + color5551_Green(inColor1) + color5551_Green(inColor2) + color5551_Green(inColor3)) >> 2), ((color5551_Blue(inColor0) + color5551_Blue(inColor1) + color5551_Blue(inColor2) + color5551_Blue(inColor3)) >> 2), ((color5551_Alpha(inColor0) + color5551_Alpha(inColor1) + color5551_Alpha(inColor2) + color5551_Alpha(inColor3)) >> 2))
    00107 #define color5551_Cmp(inColor0, inColor1) (pos((int)color5551_Red(inColor0) - (int)color5551_Red(inColor1)) + pos((int)color5551_Green(inColor0) - (int)color5551_Green(inColor1)) + pos((int)color5551_Blue(inColor0) - (int)color5551_Blue(inColor1)) + pos((int)color5551_Alpha(inColor0) - (int)color5551_Alpha(inColor1)))
    00108 #define color5551_Compare(inColor0, inColor1) color5551_Cmp(inColor0, inColor1)
    00109
    00110 #define color565_Red(inColor) ((inColor) & 0x001F)
    00111 #define color565_Green(inColor) (((inColor) & 0x07E0) >> 5)
    00112 #define color565_Blue(inColor) (((inColor) & 0xF800) >> 11)
    00113 #define color565_RGB(inRed, inGreen, inBlue) (((inRed) & 0x001F) + (((inGreen) & 0x003F) << 5) + (((inBlue) & 0x001F) << 11))
    00114 #define color565_Merge(inColor0, inColor1) color565_RGB(((color565_Red(inColor0) + color565_Red(inColor1)) >> 1), ((color565_Green(inColor0) + color565_Green(inColor1)) >> 1), ((color565_Blue(inColor0) + color565_Blue(inColor1)) >> 1))
    00115 #define color565_Merge4(inColor0, inColor1, inColor2, inColor3) color565_RGB(((color565_Red(inColor0) + color565_Red(inColor1) + color565_Red(inColor2) + color565_Red(inColor3)) >> 2), ((color565_Green(inColor0) + color565_Green(inColor1) + color565_Green(inColor2) + color565_Green(inColor3)) >> 2), ((color565_Blue(inColor0) + color565_Blue(inColor1) + color565_Blue(inColor2) + color565_Blue(inColor3)) >> 2))
    00116 #define color565_Cmp(inColor0, inColor1) (pos((int)color565_Red(inColor0) - (int)color565_Red(inColor1)) + pos((int)color565_Green(inColor0) - (int)color565_Green(inColor1)) + pos((int)color565_Blue(inColor0) - (int)color565_Blue(inColor1)))
    00117 #define color565_Compare(inColor0, inColor1) color565_Cmp(inColor0, inColor1)
    00118
    00119 #define color5650_Red(inColor) color565_Red(inColor)
    00120 #define color5650_Green(inColor) color565_Green(inColor)
    00121 #define color5650_Blue(inColor) color565_Blue(inColor)
    00122 #define color5650_RGB(inRed, inGreen, inBlue) color565_RGB(inRed, inGreen, inBlue)
    00123 #define color5650_Merge(inColor0, inColor1) color565_Merge(inColor0, inColor1)
    00124 #define color5650_Merge4(inColor0, inColor1, inColor2, inColor3) color565_Merge4(inColor0, inColor1, inColor2, inColor3)
    00125 #define color5650_Cmp(inColor0, inColor1) color565_Cmp(inColor0, inColor1)
    00126 #define color5650_Compare(inColor0, inColor1) color565_Compare(inColor0, inColor1)
    00127
    00128 #endif