00001 /** \file 00002 * \brief Image Conversion 00003 * 00004 * See Copyright Notice in im_lib.h 00005 */ 00006 00007 #ifndef __IM_CONVERT_H 00008 #define __IM_CONVERT_H 00009 00010 #include "im_image.h" 00011 00012 #if defined(__cplusplus) 00013 extern "C" { 00014 #endif 00015 00016 00017 /** \defgroup convert Image Conversion 00018 * \par 00019 * Converts one type of image into another. Can convert between color modes 00020 * and between data types. 00021 * \par 00022 * See \ref im_convert.h 00023 * \ingroup imgclass */ 00024 00025 00026 /** Complex to real conversions 00027 * \ingroup convert */ 00028 enum imComplex2Real 00029 { 00030 IM_CPX_REAL, 00031 IM_CPX_IMAG, 00032 IM_CPX_MAG, 00033 IM_CPX_PHASE 00034 }; 00035 00036 /** Predefined Gamma factors. Gamma can be any real number. 00037 * When gamma<0 use logarithmic, when gamma>0 use exponential. 00038 * gamma(x,g) = ((e^(g*x))-1)/(exp(g)-1) 00039 * gamma(x,g) = (log((g*x)+1))/(log(g+1)) 00040 * \ingroup convert */ 00041 enum imGammaFactor 00042 { 00043 IM_GAMMA_LINEAR = 0, 00044 IM_GAMMA_LOGLITE = -10, 00045 IM_GAMMA_LOGHEAVY = -1000, 00046 IM_GAMMA_EXPLITE = 2, 00047 IM_GAMMA_EXPHEAVY = 7 00048 }; 00049 00050 /** Predefined Cast Modes 00051 * \ingroup convert */ 00052 enum imCastMode 00053 { 00054 IM_CAST_MINMAX, /**< scan for min and max values */ 00055 IM_CAST_FIXED, /**< use predefied 0-max values, see \ref color Color Manipulation. */ 00056 IM_CAST_DIRECT /**< direct type cast the value. Only byte and ushort will be cropped. */ 00057 }; 00058 00059 /** Changes the image data type, using a complex2real conversion, 00060 * a gamma factor, and an abssolute mode (modulus). \n 00061 * When demoting the data type the function will scan for min/max values or use fixed values (cast_mode) 00062 * to scale the result according to the destiny range. \n 00063 * Except complex to real that will use only the complex2real conversion. \n 00064 * Images must be of the same size and color mode. \n 00065 * Returns IM_ERR_NONE, IM_ERR_DATA or IM_ERR_COUNTER, see also \ref imErrorCodes. 00066 * See also \ref imComplex2Real, \ref imGammaFactor and \ref imCastMode. 00067 * 00068 * \verbatim im.ConvertDataType(src_image: imImage, dst_image: imImage, cpx2real: number, gamma: number, abssolute: boolean, cast_mode: number) -> error: number [in Lua 5] \endverbatim 00069 * \verbatim im.ConvertDataTypeNew(image: imImage, data_type: number, cpx2real: number, gamma: number, abssolute: boolean, cast_mode: number) -> error: number, new_image: imImage [in Lua 5] \endverbatim 00070 * \ingroup convert */ 00071 int imConvertDataType(const imImage* src_image, imImage* dst_image, int cpx2real, float gamma, int abssolute, int cast_mode); 00072 00073 /** Converts one color space to another. Images must be of the same size and data type. \n 00074 * CMYK can be converted to RGB only, and it is a very simple conversion. \n 00075 * All colors can be converted to Binary, the non zero gray values are converted to 1. \n 00076 * RGB to Map uses the median cut implementation from the free IJG JPEG software, copyright Thomas G. Lane. \n 00077 * Alpha channel is considered and Transparency* attributes are converted to alpha channel. \n 00078 * All other color space conversions assume sRGB and CIE definitions. \n 00079 * Returns IM_ERR_NONE, IM_ERR_DATA or IM_ERR_COUNTER, see also \ref imErrorCodes. 00080 * 00081 * \verbatim im.ConvertColorSpace(src_image: imImage, dst_image: imImage) -> error: number [in Lua 5] \endverbatim 00082 * \verbatim im.ConvertColorSpaceNew(image: imImage, color_space: number, has_alpha: boolean) -> error: number, new_image: imImage [in Lua 5] \endverbatim 00083 * \ingroup convert */ 00084 int imConvertColorSpace(const imImage* src_image, imImage* dst_image); 00085 00086 /** Converts the image to its bitmap equivalent, 00087 * uses \ref imConvertColorSpace and \ref imConvertDataType. \n 00088 * Returns IM_ERR_NONE, IM_ERR_DATA or IM_ERR_COUNTER, see also \ref imErrorCodes. 00089 * See also \ref imComplex2Real, \ref imGammaFactor and \ref imCastMode. \n 00090 * The function im.ConvertToBitmapNew uses the default convertion result from \ref imColorModeToBitmap if color_space is nil. 00091 * 00092 * \verbatim im.ConvertToBitmap(src_image: imImage, dst_image: imImage, cpx2real: number, gamma: number, abssolute: boolean, cast_mode: number) -> error: number [in Lua 5] \endverbatim 00093 * \verbatim im.ConvertToBitmapNew(image: imImage, color_space: number, has_alpha: boolean, cpx2real: number, gamma: number, abssolute: boolean, cast_mode: number) -> error: number, new_image: imImage [in Lua 5] \endverbatim 00094 * \ingroup convert */ 00095 int imConvertToBitmap(const imImage* src_image, imImage* dst_image, int cpx2real, float gamma, int abssolute, int cast_mode); 00096 00097 /** Returns an OpenGL compatible data buffer. Also returns the correspondant pixel format. \n 00098 * The memory allocated is stored in the attribute "GLDATA" with BYTE type. And it will exists while the image exists. \n 00099 * It can be cleared by setting the attribute to NULL. \n 00100 * MAP images are converted to RGB, and BINARY images are converted to GRAY. 00101 * Alpha channel is considered and Transparency* attributes are converted to alpha channel. 00102 * So calculate depth from glformat, not from image depth. 00103 * 00104 * \verbatim image:GetOpenGLData() -> gldata: userdata, glformat: number [in Lua 5] \endverbatim 00105 * \ingroup convert */ 00106 void* imImageGetOpenGLData(const imImage* image, int *glformat); 00107 00108 00109 00110 /** \defgroup cnvutil Raw Data Conversion Utilities 00111 * \par 00112 * Utilities for raw data buffers. 00113 * \par 00114 * See \ref im_convert.h 00115 * \ingroup imagerep */ 00116 00117 00118 /** Changes the packing of the data buffer. Both must have the same depth. 00119 * \ingroup cnvutil */ 00120 void imConvertPacking(const void* src_data, void* dst_data, int width, int height, int depth, int data_type, int src_is_packed); 00121 00122 /** Changes in-place a MAP data into a RGB data. The data must have room for the RGB image. \n 00123 * depth can be 3 or 4. count=width*height. \n 00124 * \ingroup cnvutil */ 00125 void imConvertMapToRGB(unsigned char* data, int count, int depth, int packed, long* palette, int palette_count); 00126 00127 00128 00129 /* Converts a RGB bitmap into a map bitmap using the median cut algorithm. 00130 * Used only "im_convertcolor.cpp" implemented in "im_rgb2map.cpp". 00131 * Internal function kept here because of the compatibility module. 00132 * Will not be at the documentation. */ 00133 int imConvertRGB2Map(int width, int height, 00134 unsigned char *red, unsigned char *green, unsigned char *blue, 00135 unsigned char *map, long *palette, int *palette_count); 00136 00137 00138 #if defined(__cplusplus) 00139 } 00140 #endif 00141 00142 #endif