1 /** \file 2 * \brief Image Conversion 3 * 4 * See Copyright Notice in im_lib.d 5 */ 6 7 module im.convert; 8 9 import im.image; 10 11 extern (C) @safe nothrow: 12 13 14 /** \defgroup convert Image Conversion 15 * \par 16 * Converts one type of image into another. Can convert between color modes 17 * and between data types. 18 * \par 19 * See \ref im_convert.h 20 * \ingroup imgclass */ 21 22 23 /** Complex to real conversions 24 * \ingroup convert */ 25 enum imComplex2Real 26 { 27 IM_CPX_REAL, 28 IM_CPX_IMAG, 29 IM_CPX_MAG, 30 IM_CPX_PHASE 31 }; 32 33 /** Predefined Gamma factors. Gamma can be any real number. 34 * When gamma<0 use logarithmic, when gamma>0 use exponential. 35 * gamma(x,g) = ((e^(g*x))-1)/(exp(g)-1) 36 * gamma(x,g) = (log((g*x)+1))/(log(g+1)) 37 * \ingroup convert */ 38 enum imGammaFactor 39 { 40 IM_GAMMA_LINEAR = 0, 41 IM_GAMMA_LOGLITE = -10, 42 IM_GAMMA_LOGHEAVY = -1000, 43 IM_GAMMA_EXPLITE = 2, 44 IM_GAMMA_EXPHEAVY = 7 45 }; 46 47 /** Predefined Cast Modes \n 48 * See also \ref color Color Manipulation, Color Component Intervals section. 49 * \ingroup convert */ 50 enum imCastMode 51 { 52 IM_CAST_MINMAX, /**< scan for min and max values. */ 53 IM_CAST_FIXED, /**< use predefined min-max values. */ 54 IM_CAST_DIRECT, /**< direct type cast the value. */ 55 IM_CAST_USER /**< user attributes called "UserMin" and "UserMax", both float values. */ 56 }; 57 58 /** Changes the image data type, using a complex2real conversion, 59 * a gamma factor, and an absolute mode (modulus). \n 60 * When demoting the data type the function will scan source for min/max values or use fixed values (cast_mode) 61 * to scale the result according to the target range. \n 62 * Except complex to real that will use only the complex2real conversion. \n 63 * Images must be of the same size and color mode. If data type is the same nothing is done. \n 64 * Returns IM_ERR_NONE, IM_ERR_DATA or IM_ERR_COUNTER, see also \ref imErrorCodes. \n 65 * See also \ref imDataType, \ref datatypeutl, \ref imComplex2Real, \ref imGammaFactor and \ref imCastMode. 66 * 67 * \verbatim im.ConvertDataType(src_image: imImage, dst_image: imImage, cpx2real: number, gamma: number, absolute: boolean, cast_mode: number) -> error: number [in Lua 5] \endverbatim 68 * \verbatim im.ConvertDataTypeNew(image: imImage, data_type: number, cpx2real: number, gamma: number, absolute: boolean, cast_mode: number) -> error: number, new_image: imImage [in Lua 5] \endverbatim 69 * \ingroup convert */ 70 int imConvertDataType(const(imImage) * src_image, imImage* dst_image, int cpx2real, float gamma, int absolute, int cast_mode); 71 72 /** Converts one color space to another. \n 73 * Images must be of the same size and data type. If color mode is the same nothing is done. \n 74 * CMYK can be converted to RGB only, and it is a very simple conversion. \n 75 * All colors can be converted to Binary, the non zero gray values are converted to 1. \n 76 * RGB to Map uses the median cut implementation from the free IJG JPEG software, copyright Thomas G. Lane. \n 77 * Alpha channel is considered and Transparency* attributes are converted to alpha channel. \n 78 * All other color space conversions assume sRGB and CIE definitions, see \ref color. \n 79 * Returns IM_ERR_NONE, IM_ERR_DATA or IM_ERR_COUNTER, see also \ref imErrorCodes. \n 80 * See also \ref imColorSpace, \ref imColorModeConfig and \ref colormodeutl. 81 * 82 * \verbatim im.ConvertColorSpace(src_image: imImage, dst_image: imImage) -> error: number [in Lua 5] \endverbatim 83 * \verbatim im.ConvertColorSpaceNew(image: imImage, color_space: number, has_alpha: boolean) -> error: number, new_image: imImage [in Lua 5] \endverbatim 84 * \ingroup convert */ 85 int imConvertColorSpace(const(imImage) * src_image, imImage* dst_image); 86 87 /** Converts the image to its bitmap equivalent, 88 * uses \ref imConvertColorSpace and \ref imConvertDataType. \n 89 * Returns IM_ERR_NONE, IM_ERR_DATA or IM_ERR_COUNTER, see also \ref imErrorCodes. 90 * See also \ref imImageIsBitmap, \ref imComplex2Real, \ref imGammaFactor and \ref imCastMode. \n 91 * The function im.ConvertToBitmapNew uses the default conversion result from \ref imColorModeToBitmap if color_space is nil. 92 * 93 * \verbatim im.ConvertToBitmap(src_image: imImage, dst_image: imImage, cpx2real: number, gamma: number, absolute: boolean, cast_mode: number) -> error: number [in Lua 5] \endverbatim 94 * \verbatim im.ConvertToBitmapNew(image: imImage, color_space: number, has_alpha: boolean, cpx2real: number, gamma: number, absolute: boolean, cast_mode: number) -> error: number, new_image: imImage [in Lua 5] \endverbatim 95 * \ingroup convert */ 96 int imConvertToBitmap(const(imImage) * src_image, imImage* dst_image, int cpx2real, float gamma, int absolute, int cast_mode); 97 98 /** Returns an OpenGL compatible data buffer. Also returns the correspondant pixel format. \n 99 * The memory allocated is stored in the attribute "GLDATA" with BYTE type. And it will exists while the image exists. \n 100 * It can be cleared by setting the attribute to NULL. \n 101 * MAP images are converted to RGB, and BINARY images are converted to GRAY. 102 * Alpha channel is considered and Transparency* attributes are converted to alpha channel. 103 * So calculate depth from glformat, not from image depth. 104 * 105 * \verbatim image:GetOpenGLData() -> gldata: userdata, glformat: number [in Lua 5] \endverbatim 106 * \ingroup convert */ 107 void* imImageGetOpenGLData(const(imImage) * image, int *glformat); 108 109 /** Creates an image from an OpenGL data. 110 * 111 * \verbatim im.ImageCreateFromOpenGLData(width, height, glformat: number, gldata: userdata) -> image: imImage [in Lua 5] \endverbatim 112 * \ingroup convert */ 113 imImage* imImageCreateFromOpenGLData(int width, int height, int glformat, const(void) * gldata); 114 115 116 /** \defgroup cnvutil Raw Data Conversion Utilities 117 * \par 118 * Utilities for raw data buffers. 119 * \par 120 * See \ref im_convert.h 121 * \ingroup imagerep */ 122 123 124 /** Changes the packing of the data buffer. Both must have the same width, height and data_type. \n 125 * It can be used to copy data even if depth=1. 126 * \ingroup cnvutil */ 127 void imConvertPacking(const(void) * src_data, void* dst_data, int width, int height, int src_depth, int dst_depth, int data_type, int src_is_packed); 128 129 /** Changes in-place a MAP data into a RGB data. The data must have room for the RGB image. \n 130 * depth can be 3 or 4. count=width*height. \n 131 * \ingroup cnvutil */ 132 void imConvertMapToRGB(ubyte* data, int count, int depth, int packed, long* palette, int palette_count); 133 134 135 136 /* Converts a RGB bitmap into a map bitmap using the median cut algorithm. 137 * Used only "im_convertcolor.cpp" implemented in "im_rgb2map.cpp". 138 * Internal function kept here because of the compatibility module. 139 * Will not be at the documentation. */ 140 int imConvertRGB2Map(int width, int height, 141 ubyte *red, ubyte *green, ubyte *blue, 142 ubyte *map, long *palette, int *palette_count); 143 144