From d577d991b97ae2b5ee1af23641bcffc3f83af5b2 Mon Sep 17 00:00:00 2001 From: Pixel Date: Wed, 4 Nov 2009 11:56:41 -0800 Subject: Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux. --- im/src/im_colormode.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 im/src/im_colormode.cpp (limited to 'im/src/im_colormode.cpp') diff --git a/im/src/im_colormode.cpp b/im/src/im_colormode.cpp new file mode 100755 index 0000000..2a99183 --- /dev/null +++ b/im/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 +#include +#include + +#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; +} -- cgit v1.2.3