00001 /** \file
00002 * \brief Utilities
00003 *
00004 * See Copyright Notice in im_lib.h
00005 */
00006
00007 #ifndef __IM_UTIL_H
00008 #define __IM_UTIL_H
00009
00010 #if defined(__cplusplus)
00011 extern "C" {
00012 #endif
00013
00014
00015 /** \defgroup util Utilities
00016 * \par
00017 * See \ref im_util.h
00018 * @{
00019 */
00020
00021 #define IM_MIN(_a, _b) (_a < _b? _a: _b)
00022 #define IM_MAX(_a, _b) (_a > _b? _a: _b)
00023
00024 /** @} */
00025
00026
00027 /** \defgroup str String Utilities
00028 * \par
00029 * See \ref im_util.h
00030 * \ingroup util */
00031
00032 /** Check if the two strings are equal.
00033 * \ingroup str */
00034 int imStrEqual(const char* str1, const char* str2);
00035
00036 /** Calculate the size of the string but limited to max_len.
00037 * \ingroup str */
00038 int imStrNLen(const char* str, int max_len);
00039
00040 /** Check if the data is a string.
00041 * \ingroup str */
00042 int imStrCheck(const void* data, int count);
00043
00044
00045
00046 /** \defgroup imageutil Raw Data Utilities
00047 * \par
00048 * See \ref im_util.h
00049 * \ingroup imagerep */
00050
00051 /** Returns the size of the data buffer.
00052 *
00053 * \verbatim im.ImageDataSize(width: number, height: number, color_mode: number, data_type: number) -> datasize: number [in Lua 5] \endverbatim
00054 * \ingroup imageutil */
00055 int imImageDataSize(int width, int height, int color_mode, int data_type);
00056
00057 /** Returns the size of one line of the data buffer. \n
00058 * This depends if the components are packed. If packed includes all components, if not includes only one.
00059 *
00060 * \verbatim im.ImageLineSize(width: number, color_mode: number, data_type: number) -> linesize: number [in Lua 5] \endverbatim
00061 * \ingroup imageutil */
00062 int imImageLineSize(int width, int color_mode, int data_type);
00063
00064 /** Returns the number of elements of one line of the data buffer. \n
00065 * This depends if the components are packed. If packed includes all components, if not includes only one.
00066 *
00067 * \verbatim im.ImageLineCount(width: number, color_mode: number) -> linecount: number [in Lua 5] \endverbatim
00068 * \ingroup imageutil */
00069 int imImageLineCount(int width, int color_mode);
00070
00071 /** Check if the combination color_mode+data_type is valid.
00072 *
00073 * \verbatim im.ImageCheckFormat(color_mode: number, data_type: number) -> check: boolean [in Lua 5] \endverbatim
00074 * \ingroup imageutil */
00075 int imImageCheckFormat(int color_mode, int data_type);
00076
00077
00078
00079 /** \defgroup colorutl Color Utilities
00080 * \par
00081 * See \ref im_util.h
00082 * \ingroup util */
00083
00084 /** Encode RGB components in a long for palete usage. \n
00085 * "long" definition is compatible with the CD library definition.
00086 *
00087 * \verbatim im.ColorEncode(red: number, green: number, blue: number) -> color: lightuserdata [in Lua 5] \endverbatim
00088 * \ingroup colorutl */
00089 long imColorEncode(unsigned char red, unsigned char green, unsigned char blue);
00090
00091 /** Decode RGB components from a long for palete usage. \n
00092 * "long" definition is compatible with the CD library definition.
00093 *
00094 * \verbatim im.ColorDecode(color: lightuserdata) -> red: number, green: number, blue: number [in Lua 5] \endverbatim
00095 * \ingroup colorutl */
00096 void imColorDecode(unsigned char *red, unsigned char *green, unsigned char *blue, long color);
00097
00098
00099
00100 /** \defgroup colormodeutl Color Mode Utilities
00101 * \par
00102 * See \ref im_util.h
00103 * \ingroup imagerep */
00104
00105 /** Returns the color mode name.
00106 *
00107 * \verbatim im.ColorModeSpaceName(color_mode: number) -> name: string [in Lua 5] \endverbatim
00108 * \ingroup colormodeutl */
00109 const char* imColorModeSpaceName(int color_mode);
00110
00111 /** Returns the number of components of the color space including alpha.
00112 *
00113 * \verbatim im.ColorModeDepth(color_mode: number) -> depth: number [in Lua 5] \endverbatim
00114 * \ingroup colormodeutl */
00115 int imColorModeDepth(int color_mode);
00116
00117 /** Returns the color space of the color mode.
00118 *
00119 * \verbatim im.ColorModeSpace(color_mode: number) -> color_space: number [in Lua 5] \endverbatim
00120 * \ingroup colormodeutl */
00121 #define imColorModeSpace(_cm) (_cm & 0xFF)
00122
00123 /** Check if the two color modes match. Only the color space is compared.
00124 *
00125 * \verbatim im.ColorModeMatch(color_mode1: number, color_mode2: number) -> match: boolean [in Lua 5] \endverbatim
00126 * \ingroup colormodeutl */
00127 #define imColorModeMatch(_cm1, _cm2) (imColorModeSpace(_cm1) == imColorModeSpace(_cm2))
00128
00129 /** Check if the color mode has an alpha channel.
00130 *
00131 * \verbatim im.ColorModeHasAlpha(color_mode: number) -> has_alpha: boolean [in Lua 5] \endverbatim
00132 * \ingroup colormodeutl */
00133 #define imColorModeHasAlpha(_cm) (_cm & IM_ALPHA)
00134
00135 /** Check if the color mode components are packed in one plane.
00136 *
00137 * \verbatim im.ColorModeIsPacked(color_mode: number) -> is_packed: boolean [in Lua 5] \endverbatim
00138 * \ingroup colormodeutl */
00139 #define imColorModeIsPacked(_cm) (_cm & IM_PACKED)
00140
00141 /** Check if the color mode orients the image from top down to bottom.
00142 *
00143 * \verbatim im.ColorModeIsTopDown(color_mode: number) -> is_top_down: boolean [in Lua 5] \endverbatim
00144 * \ingroup colormodeutl */
00145 #define imColorModeIsTopDown(_cm) (_cm & IM_TOPDOWN)
00146
00147 /** Returns the color space of the equivalent display bitmap image. \n
00148 * Original packing and alpha are ignored. Returns IM_RGB, IM_GRAY, IM_MAP or IM_BINARY.
00149 *
00150 * \verbatim im.ColorModeToBitmap(color_mode: number) -> color_space: number [in Lua 5] \endverbatim
00151 * \ingroup colormodeutl */
00152 int imColorModeToBitmap(int color_mode);
00153
00154 /** Check if the color mode and data_type defines a display bitmap image.
00155 *
00156 * \verbatim im.ColorModeIsBitmap(color_mode: number, data_type: number) -> is_bitmap: boolean [in Lua 5] \endverbatim
00157 * \ingroup colormodeutl */
00158 int imColorModeIsBitmap(int color_mode, int data_type);
00159
00160
00161
00162 /** \defgroup datatypeutl Data Type Utilities
00163 * \par
00164 * See \ref im_util.h
00165 * \ingroup util
00166 * @{
00167 */
00168
00169 typedef unsigned char imbyte;
00170 typedef unsigned short imushort;
00171
00172 #define IM_BYTECROP(_v) (_v < 0? 0: _v > 255? 255: _v)
00173 #define IM_CROPMAX(_v, _max) (_v < 0? 0: _v > _max? _max: _v)
00174
00175 /** @} */
00176
00177 /** Returns the size in bytes of a specified numeric data type.
00178 *
00179 * \verbatim im.DataTypeSize(data_type: number) -> size: number [in Lua 5] \endverbatim
00180 * \ingroup datatypeutl */
00181 int imDataTypeSize(int data_type);
00182
00183 /** Returns the numeric data type name given its identifier.
00184 *
00185 * \verbatim im.DataTypeName(data_type: number) -> name: string [in Lua 5] \endverbatim
00186 * \ingroup datatypeutl */
00187 const char* imDataTypeName(int data_type);
00188
00189 /** Returns the maximum value of an integer data type. For floating point returns 0.
00190 *
00191 * \verbatim im.DataTypeIntMax(data_type: number) -> int_max: number [in Lua 5] \endverbatim
00192 * \ingroup datatypeutl */
00193 unsigned long imDataTypeIntMax(int data_type);
00194
00195 /** Returns the minimum value of an integer data type. For floating point returns 0.
00196 *
00197 * \verbatim im.DataTypeIntMin(data_type: number) -> int_min: number [in Lua 5] \endverbatim
00198 * \ingroup datatypeutl */
00199 long imDataTypeIntMin(int data_type);
00200
00201
00202
00203 /** \defgroup bin Binary Data Utilities
00204 * \par
00205 * See \ref im_util.h
00206 * \ingroup util */
00207
00208 /** CPU Byte Orders.
00209 * \ingroup bin */
00210 enum imByteOrder
00211 {
00212 IM_LITTLEENDIAN, /**< Little Endian - The most significant byte is on the right end of a word. Used by Intel processors. */
00213 IM_BIGENDIAN /**< Big Endian - The most significant byte is on the left end of a word. Used by Motorola processors, also is the network standard byte order. */
00214 };
00215
00216 /** Returns the current CPU byte order.
00217 * \ingroup bin */
00218 int imBinCPUByteOrder(void);
00219
00220 /** Changes the byte order of an array of 2, 4 or 8 byte values.
00221 * \ingroup bin */
00222 void imBinSwapBytes(void *data, int count, int size);
00223
00224 /** Changes the byte order of an array of 2 byte values.
00225 * \ingroup bin */
00226 void imBinSwapBytes2(void *data, int count);
00227
00228 /** Inverts the byte order of the 4 byte values
00229 * \ingroup bin */
00230 void imBinSwapBytes4(void *data, int count);
00231
00232 /** Inverts the byte order of the 8 byte values
00233 * \ingroup bin */
00234 void imBinSwapBytes8(void *data, int count);
00235
00236
00237
00238 /** \defgroup compress Data Compression Utilities
00239 * \par
00240 * Deflate compression support uses zlib version 1.2.3. \n
00241 * http://www.zlib.org/ \n
00242 * Copyright (C) 1995-2004 Jean-loup Gailly and Mark Adler
00243 * \par
00244 * LZF compression support uses libLZF version 1.51. \n
00245 * http://liblzf.plan9.de/ \n
00246 * Copyright (C) 2000-2005 Marc Alexander Lehmann
00247 * See \ref im_util.h
00248 * \ingroup util */
00249
00250 /** Compresses the data using the ZLIB Deflate compression. \n
00251 * The destination buffer must be at least 0.1% larger than source_size plus 12 bytes. \n
00252 * It compresses raw byte data. zip_quality can be 1 to 9. \n
00253 * Returns the size of the compressed buffer or zero if failed.
00254 * \ingroup compress */
00255 int imCompressDataZ(const void* src_data, int src_size, void* dst_data, int dst_size, int zip_quality);
00256
00257 /** Uncompresses the data compressed with the ZLIB Deflate compression. \n
00258 * Returns zero if failed.
00259 * \ingroup compress */
00260 int imCompressDataUnZ(const void* src_data, int src_size, void* dst_data, int dst_size);
00261
00262 /** Compresses the data using the libLZF compression. \n
00263 * Returns the size of the compressed buffer or zero if failed.
00264 * \ingroup compress */
00265 int imCompressDataLZF(const void* src_data, int src_size, void* dst_data, int dst_size, int zip_quality);
00266
00267 /** Uncompresses the data compressed with the libLZF compression.
00268 * Returns zero if failed.
00269 * \ingroup compress */
00270 int imCompressDataUnLZF(const void* src_data, int src_size, void* dst_data, int dst_size);
00271
00272
00273 #if defined(__cplusplus)
00274 }
00275 #endif
00276
00277 #endif