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 #if !defined(AFX_BITMAP_H__7CFDF35A_B689_4481_8F4C_EF7B5AD00BE7__INCLUDED_)
00028 #define AFX_BITMAP_H__7CFDF35A_B689_4481_8F4C_EF7B5AD00BE7__INCLUDED_
00029
00030 namespace cmlabs {
00031
00032
00033 #define GET_RGB_FROM_RGBA(a) (a & 0x00ffffff)
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #define GET_R_FROM_RGBA(a) (unsigned char)(a & 0x000000ff)
00044 #define GET_G_FROM_RGBA(a) (unsigned char)((a & 0x0000ff00)>>8)
00045 #define GET_B_FROM_RGBA(a) (unsigned char)((a & 0x00ff0000)>>16)
00046 #define GET_RGB_FROM_GRAY(a) (unsigned int)(((unsigned int)a<<16) + ((unsigned int)a<<8) + (unsigned int)a)
00047 #define GET_RGB_FROM_COMP(r,g,b) (unsigned int)((((unsigned int)b)<<16) + (((unsigned int)g)<<8) + (unsigned int)r)
00048 #define GET_GRAY_FROM_RGB(a) (unsigned char)((GET_R_FROM_RGBA(a)+GET_G_FROM_RGBA(a)+GET_B_FROM_RGBA(a))/3)
00049
00050
00051 #define GET_DRGB_FROM_2RGBS(a,b) (((unsigned int)GET_R_FROM_RGBA(a)>>3)<<27) + (((unsigned int)GET_G_FROM_RGBA(a)>>2)<<21) + (((unsigned int)GET_B_FROM_RGBA(a)>>3)<<16) + (((unsigned int)GET_R_FROM_RGBA(b)>>3)<<11) + (((unsigned int)GET_G_FROM_RGBA(b)>>2)<<5) + (((unsigned int)GET_B_FROM_RGBA(b)>>3)<<0)
00052 #define GET_FIRSTRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)((a>>16)&0xF800)>>8)) | ((unsigned int)((unsigned short)((a>>16)&0xE000)>>13)) | ((unsigned int)((unsigned short)((a>>16)&0x07E0)<<5)) | ((unsigned int)((unsigned short)((a>>16)&0x0600))>>1) | ((unsigned int)((unsigned short)(a>>16)&0x001F)<<19) | (((unsigned int)(unsigned short)(a>>16)&0x001C)<<14)
00053 #define GET_SECONDRGB_FROM_DRGB(a) ((unsigned int)((unsigned short)(a&0xF800)>>8)) | ((unsigned int)((unsigned short)(a&0xE000)>>13)) | ((unsigned int)((unsigned short)(a&0x07E0)<<5)) | ((unsigned int)((unsigned short)(a&0x0600))>>1) | ((unsigned int)((unsigned short)a&0x001F)<<19) | (((unsigned int)(unsigned short)a&0x001C)<<14)
00054
00055 }
00056
00057 #if _MSC_VER > 1000
00058 #pragma once
00059 #endif // _MSC_VER > 1000
00060
00061 #include "Object.h"
00062 #include "JString.h"
00063 #include "JTime.h"
00064 #include "Color.h"
00065 #include <stdio.h>
00066 #include <math.h>
00067
00068 #include "MathClasses.h"
00069 #include "DataSample.h"
00070
00071 namespace cmlabs {
00072
00073 #define DATACTRL 1
00074 #define RLECTRL 2
00075 #define DIFCTRL 3
00076
00077 #ifndef WIN32
00078 typedef unsigned char BYTE;
00079 typedef unsigned int UINT;
00080 typedef unsigned int DWORD;
00081 typedef unsigned short WORD;
00082 typedef signed int LONG;
00083
00084 #pragma pack(2)
00085
00086 typedef struct tagBITMAPFILEHEADER {
00087 WORD bfType;
00088 DWORD bfSize;
00089 WORD bfReserved1;
00090 WORD bfReserved2;
00091 DWORD bfOffBits;
00092 } BITMAPFILEHEADER;
00093
00094 #pragma pack(2)
00095 typedef struct tagBITMAPINFOHEADER {
00096 DWORD biSize;
00097 LONG biWidth;
00098 LONG biHeight;
00099 WORD biPlanes;
00100 WORD biBitCount;
00101 DWORD biCompression;
00102 DWORD biSizeImage;
00103 LONG biXPelsPerMeter;
00104 LONG biYPelsPerMeter;
00105 DWORD biClrUsed;
00106 DWORD biClrImportant;
00107 } BITMAPINFOHEADER;
00108 #pragma pack()
00109 #endif
00110
00111 typedef struct tagRGBA {
00112 BYTE red;
00113 BYTE green;
00114 BYTE blue;
00115 BYTE alpha;
00116 } valRGBA;
00117
00118 class Pixel {
00119 public:
00120 Pixel() {x=0; y=0; value = NULL; }
00121 int x;
00122 int y;
00123 unsigned int* value;
00124 };
00125
00126 class HTMLPage;
00127 class BitmapUpdate;
00128 class Bitmap : public DataSample
00129 {
00130 public:
00131
00132 Bitmap();
00133 Bitmap(int w, int h);
00134 Bitmap(char* imgData, int w, int h, bool takeData = false);
00135 Bitmap(const JString& filename);
00136 Bitmap(BitmapUpdate* update);
00137 virtual ~Bitmap();
00138 bool init(int w, int h);
00139
00140 BitmapUpdate* operator -( const Bitmap &bitmap ) const;
00141 bool updateBitmap(BitmapUpdate* update, bool takeData);
00142 BitmapUpdate* runLengthEncode() const;
00143 BitmapUpdate* runLengthDestructiveEncode() const;
00144
00145 Object* clone() const;
00146 bool reset();
00147
00148
00149 bool setPixel(int x, int y, int red, int green, int blue, int alpha = 0);
00150 bool setPixel(long pos, int red, int green, int blue, int alpha = 0);
00151 bool setPixelXOR(int x, int y, int red, int green, int blue, int alpha = 0);
00152 bool setPixelXOR(long pos, int red, int green, int blue, int alpha = 0);
00153
00154 Pixel getPixel(int x, int y);
00155 bool getPixel(Pixel* pixel);
00156
00157 long getPos(int x, int y);
00158 double getDPos(double x, double y);
00159 Pixel getXY(long pos);
00160
00161 Color getPixelColor(int x, int y);
00162
00163
00164 bool eraseBitmap();
00165 bool eraseBitmap(int r, int g, int b, int a = 0);
00166 bool eraseBitmap(const Color& color);
00167 bool replaceColor(const Color& oldColor, const Color& newColor);
00168
00169 bool fillBox(const Box& box, const Color& color);
00170 bool fillBox(int x, int y, int w, int h, const Color& color);
00171
00172 bool putTransPixel(int x, int y, const Color& color, double weight);
00173 bool drawLine(const Line& line, const Color& color);
00174 bool drawLine(const PolyLine& polyline, const Color& color);
00175 bool drawBox(const Box& box, const Color& color);
00176 bool drawCircle(int xCenter, int yCenter, int radius, const Color& color, double weight, double lineWidth, bool filled = false);
00177 bool putQuadPixel(int xCenter, int yCenter, int x, int y, const Color& color, double weight);
00178
00179 bool drawBitmap(Bitmap* bitmap, int x, int y);
00180 bool drawBitmap(Bitmap* bitmap, int x, int y, int w, int h);
00181 bool drawBitmap(Bitmap* bitmap, const Point& p);
00182 bool drawBitmap(Bitmap* bitmap, const Box& box);
00183 bool drawBitmap(Bitmap* bitmap, int srcx, int srcy, int dstx, int dsty, int w, int h);
00184
00185 Bitmap* getCopy(const Box& box);
00186
00187 bool canBeResizedTo(int width, int height);
00188 Bitmap* getResizedCopy(int w, int h, bool proportional);
00189 Bitmap* getResizedCopy(double scale);
00190 bool resizeTo(int w, int h, bool proportional);
00191 bool copyDataFromBitmap(Bitmap* bitmap, bool shouldResize = false);
00192 bool takeDataFromBitmap(Bitmap* bitmap);
00193 double getBestResizeFactor(double factor);
00194 double getBestResizeFactors(double factor, int &scaleUp, int &scaleDown, int &scale66);
00195 char* createResizedData(int newWidth, int newHeight, int scaleUp, int scaleDown, int scale66);
00196
00197 bool shape(int x1, int y1, int x2, int y2, int x3, int y3);
00198 bool shapeSlow(int x1, int y1, int x2, int y2, int x3, int y3);
00199
00200
00201 bool rotate(double angle);
00202 bool rotateSlow(double angle);
00203
00204
00205 bool readFromFile(const JString& filename);
00206 bool saveToFile(const JString& filename);
00207
00208 static bool convertBitmapFileData(char* src, int width, int height, int depth, char* dst, long dstlen);
00209 static char* convertBitmapFileDataRunLength(char* src, int width, int height, int depth, long &dstlen);
00210 static char* differenceBitmapFileData(char* orig, char* src, int width, int height, int depth, long &dstlen);
00211 static char* differenceBitmapFileDataRunLength(char* orig, char* src, int width, int height, int depth, long &dstlen);
00212
00213 BitmapUpdate* getCompressedUpdate(bool destructive) const;
00214
00215 char* getGrayScaleDataCopy(int &len);
00216 bool copyGrayScaleData(char* src, int len);
00217
00218 int getMaxUpdates();
00219 bool setMaxUpdates(int max);
00220 bool resetBitmapUpdates();
00221 bool setBitmapUpdated();
00222 bool addBitmapUpdateRegion(const Box& updateBox);
00223 bool addBitmapUpdateRegion(Box* box);
00224 bool hasBitmapBeenUpdated();
00225 bool hasBitmapBeenTotallyChanged();
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 #ifdef WIN32
00248 bool drawOn(HDC hdc, int x, int y, int w, int h);
00249 bool copyFromHDC(HDC hdc, int x, int y, int w, int h);
00250
00251
00252
00253 #else
00254 #endif // WIN32
00255
00256
00257 int round(double d);
00258
00259 HTMLPage* toHTMLBitmap();
00260 char* toBitmapFileFormat(int& len);
00261 JString toHTML();
00262 JString toXML();
00263 bool fromXML(XMLNode* node);
00264
00265
00266 protected:
00267
00268
00269
00270 };
00271
00272 char* ImageResizeDown66(char* bytesource, int &cols, int &rows);
00273 char* ImageResizeDown(char* bytesource, int &cols, int &rows, int factor);
00274 char* ImageResizeUp66(char* bytesource, int &cols, int &rows);
00275 char* ImageResizeUp(char* bytesource, int &cols, int &rows, int factor);
00276
00277 }
00278
00279 #include "BitmapUpdate.h"
00280 #include "HTML.h"
00281
00282 #endif // !defined(AFX_BITMAP_H__7CFDF35A_B689_4481_8F4C_EF7B5AD00BE7__INCLUDED_)