00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __CXUTILS_IMAGES_IMAGE__H
00042 #define __CXUTILS_IMAGES_IMAGE__H
00043
00044 #include <string>
00045 #include <iostream>
00046 #include "cxutils/images/jpeg/jpeg.h"
00047 #include "cxutils/images/png/png.h"
00048
00049 namespace CxUtils
00050 {
00068 class CX_UTILS_DLL Image
00069 {
00070 public:
00077 enum Format
00078 {
00079 Unused = 0,
00080 Invalid = 0,
00081 MPEG2,
00082 MPEG4,
00083 MJPEG,
00084 NTSC,
00085 PAL,
00086 TIFF,
00087 JPEG,
00088 GIF,
00089 H263,
00090 H264,
00091 PNG,
00092 BMP,
00093 RAW,
00094 PPM,
00095 PGM,
00096 PNM
00097 };
00098 Image();
00099 Image(const Image& img);
00100 ~Image();
00101 int Create(const unsigned short width,
00102 const unsigned short height,
00103 const unsigned char channels,
00104 const unsigned char* rawImage = NULL,
00105 const bool verticalFlip = false);
00106 int Create(const unsigned short width,
00107 const unsigned short height,
00108 const unsigned char channels,
00109 const unsigned char* rawImage,
00110 const double scale,
00111 const bool verticalFlip = false);
00112 int Create(const unsigned short width,
00113 const unsigned short height,
00114 const unsigned char channels,
00115 const unsigned char* rawImage,
00116 const unsigned short maxWidth,
00117 const unsigned short maxHeight,
00118 const bool verticalFlip);
00119 int Destroy();
00120 int Decompress(const unsigned char* compressed,
00121 const unsigned int len,
00122 const Format format);
00123 int Compress(unsigned char** buffer,
00124 unsigned int* len,
00125 unsigned int* clen,
00126 const Format format,
00127 void* args = NULL) const;
00128 static int Compress(unsigned char* image,
00129 unsigned int width,
00130 unsigned int height,
00131 unsigned char channels,
00132 unsigned char** buffer,
00133 unsigned int* len,
00134 unsigned int* clen,
00135 const Format format,
00136 void* args = NULL);
00137 void ApplyTile(const Image& tile);
00138 int Load(const std::string& file);
00139 int Save(const std::string& file) const;
00140 static int SaveCompressedImage(const std::string& name,
00141 const unsigned char* data,
00142 const unsigned int size,
00143 const Format format);
00144 static Format GetFormat(const std::string& file);
00145 inline void FlipChannels()
00146 {
00147 if(mpImage && mChannels == 3)
00148 {
00149 FlipColorChannels(mpImage, mWidth, mHeight);
00150 }
00151 }
00152 inline static void FlipColorChannels(unsigned char* colorImage, unsigned int width, unsigned int height)
00153 {
00154
00155 unsigned char* ptr = colorImage;
00156 unsigned char temp;
00157 unsigned int size = width*height*3;
00158 for(unsigned int i = 0; i < size; i+= 3)
00159 {
00160 temp = *ptr;
00161 *ptr = *(ptr + 2);
00162 *(ptr + 2) = temp;
00163 ptr += 3;
00164 }
00165 }
00166 Image& operator=(const Image& img);
00167
00168 unsigned char mChannels;
00169 unsigned short mWidth;
00170 unsigned short mHeight;
00171 unsigned int mDataSize;
00172 unsigned char* mpImage;
00173 };
00174 }
00175
00176 #endif
00177