diff options
author | scuri <scuri> | 2008-10-17 06:10:15 +0000 |
---|---|---|
committer | scuri <scuri> | 2008-10-17 06:10:15 +0000 |
commit | 5a422aba704c375a307a902bafe658342e209906 (patch) | |
tree | 5005011e086bb863d8fb587ad3319bbec59b2447 /src/im_colormode.cpp |
First commit - moving from LuaForge to SourceForge
Diffstat (limited to 'src/im_colormode.cpp')
-rw-r--r-- | src/im_colormode.cpp | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/im_colormode.cpp b/src/im_colormode.cpp new file mode 100644 index 0000000..2a99183 --- /dev/null +++ b/src/im_colormode.cpp @@ -0,0 +1,87 @@ +/** \file + * \brief Color Mode Utilities + * + * See Copyright Notice in im_lib.h + * $Id: im_colormode.cpp,v 1.1 2008/10/17 06:10:16 scuri Exp $ + */ + + +#include <stdlib.h> +#include <memory.h> +#include <string.h> + +#include "im.h" +#include "im_util.h" + +const char* imColorModeSpaceName(int color_mode) +{ + int color_space = imColorModeSpace(color_mode); + switch (color_space) + { + case IM_RGB: return "RGB"; + case IM_MAP: return "Map"; + case IM_GRAY: return "Gray"; + case IM_BINARY: return "Binary"; + case IM_CMYK: return "CMYK"; + case IM_YCBCR: return "Y'CbCr"; + case IM_LAB: return "CIE L*a*b*"; + case IM_LUV: return "CIE L*u*v*"; + case IM_XYZ: return "CIE XYZ"; + } + + return NULL; +} + +int imColorModeDepth(int color_mode) +{ + int depth = 0; + + int color_space = imColorModeSpace(color_mode); + switch (color_space) + { + case IM_GRAY: + case IM_BINARY: + case IM_MAP: + depth = 1; + break; + case IM_CMYK: + depth = 4; + break; + default: + depth = 3; + break; + } + + if (imColorModeHasAlpha(color_mode)) + depth++; + + return depth; +} + +int imColorModeToBitmap(int color_mode) +{ + int color_space = imColorModeSpace(color_mode); + switch (color_space) + { + case IM_BINARY: + case IM_GRAY: + case IM_MAP: + return color_space; + default: + return IM_RGB; + } +} + +int imColorModeIsBitmap(int color_mode, int data_type) +{ + if (imColorModeSpace(color_mode) == IM_BINARY || + imColorModeSpace(color_mode) == IM_MAP) + return 1; + + if ((imColorModeSpace(color_mode) == IM_RGB || + imColorModeSpace(color_mode) == IM_GRAY) && + (data_type == IM_BYTE)) + return 1; + + return 0; +} |