1 /** \file 2 * \brief Main API 3 * 4 * See Copyright Notice in im_lib.d 5 */ 6 7 module im.im; 8 9 extern (C) @safe nothrow: 10 11 /** Image data type descriptors. \n 12 * See also \ref datatypeutl. 13 * \ingroup imagerep */ 14 enum imDataType 15 { 16 IM_BYTE, /**< "unsigned char". 1 byte from 0 to 255. */ 17 IM_SHORT, /**< "short". 2 bytes from -32,768 to 32,767. */ 18 IM_USHORT, /**< "unsigned short". 2 bytes from 0 to 65,535. */ 19 IM_INT, /**< "int". 4 bytes from -2,147,483,648 to 2,147,483,647. */ 20 IM_FLOAT, /**< "float". 4 bytes single precision IEEE floating point. */ 21 IM_DOUBLE, /**< "double". 8 bytes double precision IEEE floating point. */ 22 IM_CFLOAT, /**< complex "float". 2 float values in sequence, real and imaginary parts. */ 23 IM_CDOUBLE /**< complex "double". 2 double values in sequence, real and imaginary parts. */ 24 }; 25 26 /** Image color mode color space descriptors (first byte). \n 27 * See also \ref colormodeutl. 28 * \ingroup imagerep */ 29 enum imColorSpace 30 { 31 IM_RGB, /**< Red, Green and Blue (nonlinear). */ 32 IM_MAP, /**< Indexed by RGB color map (data_type=IM_BYTE). */ 33 IM_GRAY, /**< Shades of gray, luma (nonlinear Luminance), or an intensity value that is not related to color. */ 34 IM_BINARY, /**< Indexed by 2 colors: black (0) and white (1) (data_type=IM_BYTE). */ 35 IM_CMYK, /**< Cian, Magenta, Yellow and Black (nonlinear). */ 36 IM_YCBCR, /**< ITU-R 601 Y'CbCr. Y' is luma (nonlinear Luminance). */ 37 IM_LAB, /**< CIE L*a*b*. L* is Lightness (nonlinear Luminance, nearly perceptually uniform). */ 38 IM_LUV, /**< CIE L*u*v*. L* is Lightness (nonlinear Luminance, nearly perceptually uniform). */ 39 IM_XYZ /**< CIE XYZ. Linear Light Tristimulus, Y is linear Luminance. */ 40 }; 41 42 /** Image color mode configuration/extra descriptors (1 bit each in the second byte). \n 43 * See also \ref colormodeutl. 44 * \ingroup imagerep */ 45 enum imColorModeConfig 46 { 47 IM_ALPHA = 0x100, /**< adds an Alpha channel */ 48 IM_PACKED = 0x200, /**< packed components (rgbrgbrgb...) */ 49 IM_TOPDOWN = 0x400 /**< orientation from top down to bottom */ 50 }; 51 52 53 54 /** File Access Error Codes 55 * \par 56 * In Lua use im.ErrorStr(err) to convert the error number into a string. 57 * \ingroup file */ 58 enum imErrorCodes 59 { 60 IM_ERR_NONE, /**< No error. */ 61 IM_ERR_OPEN, /**< Error while opening the file (read or write). */ 62 IM_ERR_ACCESS, /**< Error while accessing the file (read or write). */ 63 IM_ERR_FORMAT, /**< Invalid or unrecognized file format. */ 64 IM_ERR_DATA, /**< Invalid or unsupported data. */ 65 IM_ERR_COMPRESS, /**< Invalid or unsupported compression. */ 66 IM_ERR_MEM, /**< Insufficient memory */ 67 IM_ERR_COUNTER /**< Interrupted by the counter */ 68 }; 69 70 /** \brief Image File Structure (Private). 71 * \ingroup file */ 72 struct _imFile; 73 alias imFile = _imFile; 74 75 /** Opens the file for reading. It must exists. Also reads file header. 76 * It will try to identify the file format. 77 * See also \ref imErrorCodes. \n 78 * In Lua the IM file metatable name is "imFile". 79 * When converted to a string will return "imFile(%p)" where %p is replaced by the userdata address. 80 * If the file is already closed by im.FileClose, then it will return also the suffix "-closed". 81 * 82 * \verbatim im.FileOpen(file_name: string) -> ifile: imFile, error: number [in Lua 5] \endverbatim 83 * \ingroup file */ 84 imFile* imFileOpen(const(char) * file_name, int *error); 85 86 /** Opens the file for reading using a specific format. It must exists. Also reads file header. 87 * See also \ref imErrorCodes and \ref format. 88 * 89 * \verbatim im.FileOpenAs(file_name, format: string) -> ifile: imFile, error: number [in Lua 5] \endverbatim 90 * \ingroup file */ 91 imFile* imFileOpenAs(const(char) * file_name, const(char) * format, int *error); 92 93 /** Creates a new file for writing using a specific format. If the file exists will be replaced. \n 94 * It will only initialize the format driver and create the file, no data is actually written. 95 * See also \ref imErrorCodes and \ref format. 96 * 97 * \verbatim im.FileNew(file_name: string, format: string) -> ifile: imFile, error: number [in Lua 5] \endverbatim 98 * \ingroup file */ 99 imFile* imFileNew(const(char) * file_name, const(char) * format, int *error); 100 101 /** Closes the file. \n 102 * In Lua if this function is not called, the file is closed by the garbage collector. 103 * 104 * \verbatim im.FileClose(ifile: imFile) [in Lua 5] \endverbatim 105 * \verbatim ifile:Close() [in Lua 5] \endverbatim 106 * \ingroup file */ 107 void imFileClose(imFile* ifile); 108 109 /** Returns an internal handle. 110 * index=0 returns always an imBinFile* handle, 111 * but for some formats returns NULL because they do not use imBinFile (like AVI and WMV). 112 * index=1 return an internal structure used by the format, usually is a handle 113 * to a third party library structure. This is file format dependent. 114 * 115 * \verbatim ifile:Handle() -> handle: userdata [in Lua 5] \endverbatim 116 * \ingroup file */ 117 void* imFileHandle(imFile* ifile, int index); 118 119 /** Returns file information. 120 * image_count is the number of images in a stack or 121 * the number of frames in a video/animation or the depth of a volume data. \n 122 * compression and image_count can be NULL. \n 123 * These information are also available as attributes: 124 * \verbatim FileFormat (string) \endverbatim 125 * \verbatim FileCompression (string) \endverbatim 126 * \verbatim FileImageCount IM_INT (1) \endverbatim 127 * See also \ref format. 128 * 129 * \verbatim ifile:GetInfo() -> format: string, compression: string, image_count: number [in Lua 5] \endverbatim 130 * \ingroup file */ 131 void imFileGetInfo(imFile* ifile, char* format, char* compression, int *image_count); 132 133 /** Changes the write compression method. \n 134 * If the compression is not supported will return an error code when writing. \n 135 * Use NULL to set the default compression. You can use the imFileGetInfo to retrieve the actual compression 136 * but only after \ref imFileWriteImageInfo. Only a few formats allow you to change the compression between frames. 137 * 138 * \verbatim ifile:SetInfo(compression: string) [in Lua 5] \endverbatim 139 * \ingroup file */ 140 void imFileSetInfo(imFile* ifile, const(char) * compression); 141 142 /** Changes an extended attribute. \n 143 * The data will be internally duplicated. \n 144 * If data is NULL the attribute is removed. 145 * If data_type is BYTE then count can be -1 to indicate a NULL terminated string. 146 * See also \ref imDataType. 147 * 148 * \verbatim ifile:SetAttribute(attrib: string, data_type: number, data: table of numbers or string) [in Lua 5] \endverbatim 149 * If data_type is IM_BYTE, as_string can be used as data. 150 * \ingroup file */ 151 void imFileSetAttribute(imFile* ifile, const(char) * attrib, int data_type, int count, const(void) * data); 152 153 /** Changes an extended attribute as an integer. 154 * \ingroup file */ 155 void imFileSetAttribInteger(const(imFile) * ifile, const(char) * attrib, int data_type, int value); 156 157 /** Changes an extended attribute as a real. 158 * \ingroup file */ 159 void imFileSetAttribReal(const(imFile) * ifile, const(char) * attrib, int data_type, double value); 160 161 /** Changes an extended attribute as a string. 162 * \ingroup file */ 163 void imFileSetAttribString(const(imFile) * ifile, const(char) * attrib, const(char) * value); 164 165 /** Returns an extended attribute. \n 166 * Returns NULL if not found. data_type and count can be NULL. 167 * See also \ref imDataType. 168 * 169 * \verbatim ifile:GetAttribute(attrib: string, [as_string: boolean]) -> data: table of numbers or string, data_type: number [in Lua 5] \endverbatim 170 * If data_type is IM_BYTE, as_string can be used to return a string instead of a table. 171 * \verbatim ifile:GetAttributeRaw(attrib: string) -> data: userdata, data_type, count: number [in Lua 5] \endverbatim 172 * \ingroup file */ 173 const(void) * imFileGetAttribute(imFile* ifile, const(char) * attrib, int *data_type, int *count); 174 175 /** Returns an extended attribute as an integer. 176 * \ingroup file */ 177 int imFileGetAttribInteger(const(imFile) * ifile, const(char) * attrib, int index); 178 179 /** Returns an extended attribute as a real. 180 * \ingroup file */ 181 double imFileGetAttribReal(const(imFile) * ifile, const(char) * attrib, int index); 182 183 /** Returns an extended attribute as a string. 184 * \ingroup file */ 185 const(char) * imFileGetAttribString(const(imFile) * ifile, const(char) * attrib); 186 187 /** Returns a list of the attribute names. \n 188 * "attrib" must contain room enough for "attrib_count" names. Use "attrib=NULL" to return only the count. 189 * 190 * \verbatim ifile:GetAttributeList() -> data: table of strings [in Lua 5] \endverbatim 191 * \ingroup file */ 192 void imFileGetAttributeList(imFile* ifile, char** attrib, int *attrib_count); 193 194 /** Returns the palette if any. \n 195 * "palette" must be a 256 colors allocated array. \n 196 * Returns zero in "palette_count" if there is no palette. "palette_count" is >0 and <=256. 197 * 198 * \verbatim ifile:GetPalette() -> palette: imPalette [in Lua 5] \endverbatim 199 * \ingroup file */ 200 void imFileGetPalette(imFile* ifile, long* palette, int *palette_count); 201 202 /** Changes the pallete. \n 203 * "palette_count" is >0 and <=256. 204 * 205 * \verbatim ifile:SetPalette(palette: imPalette) [in Lua 5] \endverbatim 206 * \ingroup file */ 207 void imFileSetPalette(imFile* ifile, long* palette, int palette_count); 208 209 /** Reads the image header if any and returns image information. \n 210 * Reads also the extended image attributes, so other image attributes will be available only after calling this function. \n 211 * Returns an error code. 212 * index specifies the image number between 0 and image_count-1. \n 213 * Some drivers reads only in sequence, so "index" can be ignored by the format driver. \n 214 * Any parameters can be NULL. This function must be called at least once, check each format documentation. 215 * See also \ref imErrorCodes, \ref imDataType, \ref imColorSpace and \ref imColorModeConfig. 216 * 217 * \verbatim ifile:ReadImageInfo([index: number]) -> error: number, width: number, height: number, file_color_mode: number, file_data_type: number [in Lua 5] \endverbatim 218 * Default index is 0. 219 * \ingroup file */ 220 int imFileReadImageInfo(imFile* ifile, int index, int *width, int *height, int *file_color_mode, int *file_data_type); 221 222 /** Writes the image header. Writes the file header at the first time it is called. 223 * Writes also the extended image attributes. \n 224 * Must call imFileSetPalette and set other attributes before calling this function. \n 225 * In some formats the color space will be converted to match file format specification. \n 226 * Returns an error code. This function must be called at least once, check each format documentation. 227 * See also \ref imErrorCodes, \ref imDataType, \ref imColorSpace and \ref imColorModeConfig. 228 * 229 * \verbatim ifile:WriteImageInfo(width: number, height: number, user_color_mode: number, user_data_type: number) -> error: number [in Lua 5] \endverbatim 230 * \ingroup file */ 231 int imFileWriteImageInfo(imFile* ifile, int width, int height, int user_color_mode, int user_data_type); 232 233 /** Reads the image data with or without conversion. \n 234 * The data can be converted to bitmap when reading. 235 * Data type conversion to byte will always scan for min-max then scale to 0-255, 236 * except integer values that min-max are already between 0-255. Complex to real conversions will use the magnitude. \n 237 * Color mode flags contains packed, alpha and top-bottom information. 238 * If flag is 0 means unpacked, no alpha and bottom up. If flag is -1 the file original flags are used. \n 239 * Returns an error code. 240 * See also \ref imErrorCodes, \ref imDataType, \ref imColorSpace and \ref imColorModeConfig. 241 * 242 * \verbatim ifile:ReadImageData(data: userdata, convert2bitmap: boolean, color_mode_flags: number) -> error: number [in Lua 5] \endverbatim 243 * \ingroup file */ 244 int imFileReadImageData(imFile* ifile, void* data, int convert2bitmap, int color_mode_flags); 245 246 /** Writes the image data. \n 247 * Returns an error code. 248 * 249 * \verbatim ifile:WriteImageData(data: userdata) -> error: number [in Lua 5] \endverbatim 250 * \ingroup file */ 251 int imFileWriteImageData(imFile* ifile, void* data); 252 253 254 255 256 /** Registers all the internal formats. \n 257 * It is automatically called internally when a format is accessed, 258 * but can be called to force the internal formats to be registered before other formats. 259 * Notice that additional formats when registered will be registered before the internal formats 260 * if imFormatRegisterInternal is not called yet. \n 261 * To control the register order is useful when two format drivers handle the same format. 262 * The first registered format will always be used first. 263 * \ingroup format */ 264 void imFormatRegisterInternal(); 265 266 /** Remove all registered formats. Call this if you are checking memory leaks. 267 * \ingroup format */ 268 void imFormatRemoveAll(); 269 270 /** Returns a list of the registered formats. \n 271 * format_list is an array of format identifiers. 272 * Each format identifier is 10 chars max, maximum of 50 formats. 273 * You can use "char* format_list[50]". 274 * 275 * \verbatim im.FormatList() -> format_list: table of strings [in Lua 5] \endverbatim 276 * \ingroup format */ 277 void imFormatList(char** format_list, int *format_count); 278 279 /** Returns the format description. \n 280 * Format description is 50 chars max. \n 281 * Extensions are separated like "*.tif;*.tiff;", 50 chars max. \n 282 * Returns an error code. The parameters can be NULL, except format. 283 * See also \ref format. 284 * 285 * \verbatim im.FormatInfo(format: string) -> error: number, desc: string, ext: string, can_sequence: boolean [in Lua 5] \endverbatim 286 * \ingroup format */ 287 int imFormatInfo(const(char) * format, char* desc, char* ext, int *can_sequence); 288 289 /** Returns the format information of the third party library used to support the format. \n 290 * Format extra is 50 chars max. \n 291 * Returns an error code. 292 * See also \ref format. 293 * 294 * \verbatim im.FormatInfoExtra(format: string) -> error: number, extra: string [in Lua 5] \endverbatim 295 * \ingroup format */ 296 int imFormatInfoExtra(const(char) * format, char* extra); 297 298 /** Returns the format compressions. \n 299 * Compressions are 20 chars max each, maximum of 50 compressions. You can use "char* comp[50]". \n 300 * color_mode and data_type are optional, use -1 to ignore them. \n 301 * If you use them they will select only the allowed compressions checked like in \ref imFormatCanWriteImage. \n 302 * Returns an error code. 303 * See also \ref format, \ref imErrorCodes, \ref imDataType, \ref imColorSpace and \ref imColorModeConfig. 304 * 305 * \verbatim im.FormatCompressions(format: string, [color_mode: number], [data_type: number]) -> error: number, comp: table of strings [in Lua 5] \endverbatim 306 * \ingroup format */ 307 int imFormatCompressions(const(char) * format, char** comp, int *comp_count, int color_mode, int data_type); 308 309 /** Checks if the format support the given image class at the given compression. \n 310 * Returns an error code. 311 * See also \ref format, \ref imErrorCodes, \ref imDataType, \ref imColorSpace and \ref imColorModeConfig. 312 * 313 * \verbatim im.FormatCanWriteImage(format: string, compression: string, color_mode: number, data_type: number) -> can_write: boolean [in Lua 5] \endverbatim 314 * \ingroup format */ 315 int imFormatCanWriteImage(const(char) * format, const(char) * compression, int color_mode, int data_type); 316