IM: im.h Source File

IM - An Imaging Tool

im.h

Go to the documentation of this file.
00001 /** \file
00002  * \brief Main API
00003  *
00004  * See Copyright Notice in im_lib.h
00005  * $Id: im.h,v 1.5 2005/12/12 13:31:08 scuri Exp $
00006  */
00007 
00008 #ifndef __IM_H
00009 #define __IM_H
00010 
00011 #include "im_lib.h"
00012 
00013 #if defined(__cplusplus)
00014 extern "C" {
00015 #endif
00016       
00017 
00018 /** Image data type descriptors. \n
00019  * See also \ref datatypeutl.
00020  * \ingroup imagerep */
00021 enum imDataType
00022 {
00023   IM_BYTE,   /**< "unsigned char". 1 byte from 0 to 255.                  */
00024   IM_USHORT, /**< "unsigned short". 2 bytes from 0 to 65,535.             */
00025   IM_INT,    /**< "int". 4 bytes from -2,147,483,648 to 2,147,483,647.    */
00026   IM_FLOAT,  /**< "float". 4 bytes single precision IEEE floating point.  */
00027   IM_CFLOAT  /**< complex "float". 2 float values in sequence, real and imaginary parts.   */
00028 };
00029 
00030 /** Image color mode color space descriptors (first byte). \n
00031  * See also \ref colormodeutl.
00032  * \ingroup imagerep */
00033 enum imColorSpace
00034 {
00035   IM_RGB,    /**< Red, Green and Blue (nonlinear).              */
00036   IM_MAP,    /**< Indexed by RGB color map (data_type=IM_BYTE). */
00037   IM_GRAY,   /**< Shades of gray, luma (nonlinear Luminance), or an intensity value that is not related to color. */
00038   IM_BINARY, /**< Indexed by 2 colors: black (0) and white (1) (data_type=IM_BYTE).     */
00039   IM_CMYK,   /**< Cian, Magenta, Yellow and Black (nonlinear).                          */
00040   IM_YCBCR,  /**< ITU-R 601 Y'CbCr. Y' is luma (nonlinear Luminance).                   */
00041   IM_LAB,    /**< CIE L*a*b*. L* is Lightness (nonlinear Luminance, nearly perceptually uniform). */
00042   IM_LUV,    /**< CIE L*u*v*. L* is Lightness (nonlinear Luminance, nearly perceptually uniform). */
00043   IM_XYZ     /**< CIE XYZ. Linear Light Tristimulus, Y is linear Luminance.             */
00044 };
00045 
00046 /** Image color mode configuration/extra descriptors (1 bit each in the second byte). \n
00047  * See also \ref colormodeutl.
00048  * \ingroup imagerep */
00049 enum imColorModeConfig
00050 {
00051   IM_ALPHA    = 0x100,  /**< adds an Alpha channel */
00052   IM_PACKED   = 0x200,  /**< packed components (rgbrgbrgb...) */
00053   IM_TOPDOWN  = 0x400   /**< orientation from top down to bottom */
00054 };
00055 
00056 
00057 
00058 /** File Access Error Codes
00059  * \ingroup file */
00060 enum imErrorCodes 
00061 {
00062   IM_ERR_NONE,     /**< No error. */
00063   IM_ERR_OPEN,     /**< Error while opening the file (read or write). */
00064   IM_ERR_ACCESS,   /**< Error while accessing the file (read or write). */
00065   IM_ERR_FORMAT,   /**< Invalid or unrecognized file format. */
00066   IM_ERR_DATA,     /**< Invalid or unsupported data. */
00067   IM_ERR_COMPRESS, /**< Invalid or unsupported compression. */
00068   IM_ERR_MEM,      /**< Insuficient memory */
00069   IM_ERR_COUNTER   /**< Interrupted by the counter */
00070 };
00071 
00072 /* Internal Image File Structure. */
00073 typedef struct _imFile imFile;
00074 
00075 /** Opens the file for reading. It must exists. Also reads file header.
00076  *
00077  * \verbatim im.FileOpen(file_name: string) -> ifile: imFile, error: number [in Lua 5] \endverbatim
00078  * \ingroup file */
00079 imFile* imFileOpen(const char* file_name, int *error);
00080 
00081 /** Creates a new file for writing. If the file exists will be replaced. \n
00082  * It will only initialize the format driver and create the file, no data is actually written.
00083  *
00084  * \verbatim im.FileNew(file_name: string, format: string) -> ifile: imFile, error: number [in Lua 5] \endverbatim
00085  * \ingroup file */
00086 imFile* imFileNew(const char* file_name, const char* format, int *error);
00087 
00088 /** Closes the file
00089  *
00090  * \verbatim im.FileClose(ifile: imFile) [in Lua 5] \endverbatim
00091  * \verbatim ifile:Close() [in Lua 5] \endverbatim
00092  * \ingroup file */
00093 void imFileClose(imFile* ifile);  
00094 
00095 /** Returns the internal handle. It is file format dependent.
00096  *
00097  * \verbatim ifile:Handle() -> handle: userdata [in Lua 5] \endverbatim
00098  * \ingroup file */
00099 void* imFileHandle(imFile* ifile);  
00100 
00101 /** Returns file information. 
00102  *  image_count is the number of images in a stack or 
00103  *  the number of frames in a video/animation or the depth of a volume data. \n
00104  *  compression and image_count can be NULL.
00105  *
00106  * \verbatim ifile:GetInfo() -> format: string, compression: string, image_count: number [in Lua 5] \endverbatim
00107  * \ingroup file */
00108 void imFileGetInfo(imFile* ifile, char* format, char* compression, int *image_count);
00109 
00110 /** Changes the write compression method. \n
00111  * If the compression is not supported will return an error code when writting. \n
00112  * Use NULL to set the default compression. You can use the imFileGetInfo to retrieve the actual compression
00113  * but only after \ref imFileWriteImageInfo. Only a few formats allow you to change the compression between frames.
00114  *
00115  * \verbatim ifile:SetInfo(compression: string) [in Lua 5] \endverbatim
00116  * \ingroup file */
00117 void imFileSetInfo(imFile* ifile, const char* compression);
00118 
00119 /** Changes an extended attribute. \n
00120  * The data will be internally duplicated. \n
00121  * If data is NULL the attribute is removed.
00122  *
00123  * \verbatim ifile:SetAttribute(attrib: string, data_type: number, data: table of numbers or string) [in Lua 5] \endverbatim
00124  * If data_type is IM_BYTE, as_string can be used as data.
00125  * \ingroup file */
00126 void imFileSetAttribute(imFile* ifile, const char* attrib, int data_type, int count, const void* data);
00127 
00128 /** Returns an extended attribute. \n
00129  * Returns NULL if not found. data_type and count can be NULL.
00130  *
00131  * \verbatim ifile:GetAttribute(attrib: string, [as_string: boolean]) -> data: table of numbers or string, data_type: number [in Lua 5] \endverbatim
00132  * If data_type is IM_BYTE, as_string can be used to return a string instead of a table.
00133  * \ingroup file */
00134 const void* imFileGetAttribute(imFile* ifile, const char* attrib, int *data_type, int *count);
00135 
00136 /** Returns a list of the attribute names. \n
00137  * "attrib" must contain room enough for "attrib_count" names. Use "attrib=NULL" to return only the count.
00138  *
00139  * \verbatim ifile:GetAttributeList() -> data: table of strings [in Lua 5] \endverbatim
00140  * \ingroup file */
00141 void imFileGetAttributeList(imFile* ifile, char** attrib, int *attrib_count);
00142 
00143 /** Returns the pallete if any. \n
00144  * "palette" must be a 256 colors alocated array. \n
00145  * Returns zero in "palette_count" if there is no palette. "palette_count" is >0 and <=256.
00146  *
00147  * \verbatim ifile:GetPalette() -> palette: imPalette [in Lua 5] \endverbatim
00148  * \ingroup file */
00149 void imFileGetPalette(imFile* ifile, long* palette, int *palette_count);
00150 
00151 /** Changes the pallete. \n
00152  *  "palette_count" is >0 and <=256.
00153  *
00154  * \verbatim ifile:SetPalette(palette: imPalette) [in Lua 5] \endverbatim
00155  * \ingroup file */
00156 void imFileSetPalette(imFile* ifile, long* palette, int palette_count);
00157 
00158 /** Reads the image header if any and returns image information. \n
00159  * Reads also the extended image attributes, so other image attributes will be available only after calling this function. \n
00160  * Returns an error code.
00161  * index specifies the image number between 0 and image_count-1. \n
00162  * Some drivers reads only in sequence, so "index" can be ignored by the format driver. \n
00163  * Any parameters can be NULL. This function must be called at least once, check each format documentation.
00164  *
00165  * \verbatim ifile:ReadImageInfo([index: number]) -> error: number, width: number, height: number, file_color_mode: number, file_data_type: number [in Lua 5] \endverbatim
00166  * Default index is 0.
00167  * \ingroup file */
00168 int imFileReadImageInfo(imFile* ifile, int index, int *width, int *height, int *file_color_mode, int *file_data_type);
00169 
00170 /** Writes the image header. Writes the file header at the first time it is called.
00171  * Writes also the extended image attributes. \n
00172  * Must call imFileSetPalette and set other attributes before calling this function. \n
00173  * In some formats the color space will be converted to match file format specification. \n
00174  * Returns an error code. This function must be called at least once, check each format documentation.
00175  *
00176  * \verbatim ifile:WriteImageInfo(width: number, height: number, user_color_mode: number, user_data_type: number) -> error: number [in Lua 5] \endverbatim
00177  * \ingroup file */
00178 int imFileWriteImageInfo(imFile* ifile, int width, int height, int user_color_mode, int user_data_type);
00179 
00180 /** Reads the image data with or without conversion. \n
00181  * The data can be converted to bitmap when reading.
00182  * Data type conversion to byte will always scan for min-max then scale to 0-255, 
00183  * except integer values that min-max are already between 0-255. Complex to real conversions will use the magnitude. \n
00184  * Color mode flags contains packed, alpha and top-botttom information.
00185  * If flag is 0 means unpacked, no alpha and bottom up. If flag is -1 the file original flags are used. \n
00186  * Returns an error code.
00187  *
00188  * \verbatim ifile:ReadImageData(data: userdata, convert2bitmap: number, color_mode_flags: number) -> error: number [in Lua 5] \endverbatim
00189  * \ingroup file */
00190 int imFileReadImageData(imFile* ifile, void* data, int convert2bitmap, int color_mode_flags);
00191                            
00192 /** Writes the image data. \n
00193  * Returns an error code.
00194  *
00195  * \verbatim ifile:WriteImageData(data: userdata) -> error: number [in Lua 5] \endverbatim
00196  * \ingroup file */
00197 int imFileWriteImageData(imFile* ifile, void* data);
00198 
00199 
00200 
00201 /** Returns a list of the registered formats. \n
00202  * format_list is an array of format identifiers. 
00203  * Each format identifier is 10 chars max, maximum of 50 formats. 
00204  * You can use "char* format_list[50]". 
00205  *
00206  * \verbatim im.FormatList() -> format_list: table of strings [in Lua 5] \endverbatim
00207  * \ingroup format */
00208 void imFormatList(char** format_list, int *format_count);
00209 
00210 /** Returns the format description. \n
00211  * Format description is 50 chars max. \n
00212  * Extensions are separated like "*.tif;*.tiff;", 50 chars max. \n
00213  * Returns an error code. The parameters can be NULL, except format.
00214  *
00215  * \verbatim im.FormatInfo(format: string) -> error: number, desc: string, ext: string, can_sequence: boolean [in Lua 5] \endverbatim
00216  * \ingroup format */
00217 int imFormatInfo(const char* format, char* desc, char* ext, int *can_sequence);
00218 
00219 /** Returns the format compressions. \n
00220  * Compressions are 20 chars max each, maximum of 50 compressions. You can use "char* comp[50]". \n
00221  * color_mode and data_type are optional, use -1 to ignore them. \n
00222  * If you use them they will select only the allowed compressions checked like in \ref imFormatCanWriteImage. \n
00223  * Returns an error code.
00224  *
00225  * \verbatim im.FormatCompressions(format: string, [color_mode: number], [data_type: number]) -> error: number, comp: table of strings [in Lua 5] \endverbatim
00226  * \ingroup format */
00227 int imFormatCompressions(const char* format, char** comp, int *comp_count, int color_mode, int data_type);
00228 
00229 /** Checks if the format suport the given image class at the given compression. \n
00230  * Returns an error code.
00231  *
00232  * \verbatim im.FormatCanWriteImage(format: string, compression: string, color_mode: number, data_type: number) -> can_write: boolean [in Lua 5] \endverbatim
00233  * \ingroup format */
00234 int imFormatCanWriteImage(const char* format, const char* compression, int color_mode, int data_type);
00235 
00236 
00237 #if defined(__cplusplus)
00238 }
00239 #endif
00240 
00241 #include "old_im.h"
00242 
00243 #endif