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