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