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 #include "BitmapUpdate.h"
00026 #include "Bitmap.h"
00027
00028
00029 namespace cmlabs {
00030
00031
00032
00033
00034
00035 BitmapUpdate::BitmapUpdate() : DataSample("BitmapUpdate") {
00036 init(0, 0);
00037 }
00038
00039 BitmapUpdate::BitmapUpdate(int w, int h) : DataSample("BitmapUpdate") {
00040 init(w, h);
00041 }
00042
00043 BitmapUpdate::BitmapUpdate(JString filename, bool compress) : DataSample("BitmapUpdate") {
00044 init(0, 0);
00045 if (compress) {
00046 if (!readFromFileRLE(filename)) {
00047 }
00048 }
00049 else {
00050 if (!readFromFile(filename)) {
00051 }
00052 }
00053 }
00054
00055 BitmapUpdate::~BitmapUpdate() {
00056 reset();
00057 }
00058
00059 bool BitmapUpdate::init(int w, int h) {
00060
00061 width = w;
00062 height = h;
00063
00064 return true;
00065 }
00066
00067 bool BitmapUpdate::reset() {
00068
00069
00070 width = height = 0;
00071 setUpdateType("");
00072 delete(data);
00073 clearDataFields();
00074 return true;
00075 }
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 bool BitmapUpdate::setUpdateType(JString updateType) {
00094 return this->params.put("Update", updateType);
00095 }
00096
00097 JString BitmapUpdate::getUpdateType() {
00098 return this->params.get("Update");
00099 }
00100
00101 Bitmap* BitmapUpdate::toBitmap() {
00102 return new Bitmap(this);
00103 }
00104
00105 HTMLPage* BitmapUpdate::toHTMLBitmap() {
00106 Bitmap* bitmap = this->toBitmap();
00107 HTMLPage* page = NULL;
00108 if (bitmap != NULL) {
00109 page = new HTMLPage(bitmap);
00110 delete(bitmap);
00111 }
00112 return page;
00113 }
00114
00115
00116 bool BitmapUpdate::setFullUpdate(Bitmap* bitmap) {
00117 if ((bitmap == NULL) || (bitmap->data == NULL))
00118 return false;
00119 reset();
00120 setUpdateType("Full");
00121 init(bitmap->width, bitmap->height);
00122 return setDataCopy(bitmap->data, bitmap->size);
00123 }
00124
00125 bool BitmapUpdate::readFromFile(JString filename) {
00126
00127
00128
00129 BITMAPFILEHEADER* bmfh;
00130 BITMAPINFOHEADER* bmih;
00131 long count = 0;
00132
00133 int len;
00134 char* dat = JFile::readAFileBinary(filename, len);
00135 if (dat == NULL)
00136 return false;
00137
00138
00139
00140 char* src = (char*) dat;
00141 bmfh = (BITMAPFILEHEADER*) src;
00142 src += sizeof(BITMAPFILEHEADER);
00143 bmih = (BITMAPINFOHEADER*) src;
00144 src += sizeof(BITMAPINFOHEADER);
00145
00146 if (bmih->biCompression != 0) {
00147 delete [] dat;
00148 return false;
00149 }
00150
00151 if (bmih->biBitCount != 24) {
00152 delete [] dat;
00153 return false;
00154 }
00155
00156
00157
00158 int depth = bmih->biBitCount;
00159 int planes = bmih->biPlanes;
00160 width = bmih->biWidth;
00161 height = bmih->biHeight;
00162
00163 if(bmih->biSizeImage==0)
00164 bmih->biSizeImage=bmfh->bfSize-bmfh->bfOffBits;
00165
00166 if (len < (int)(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (width * height * ((int)(depth/8))) ) ) {
00167 delete [] dat;
00168 return false;
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178 this->size = width * height * 4;
00179 data = new char[this->size];
00180 if (data == NULL) {
00181 this->size = 0;
00182 delete [] dat;
00183 return false;
00184 }
00185
00186
00187 Bitmap::convertBitmapFileData(src, width, height, (int)(bmih->biBitCount/8), data, this->size);
00188
00189
00190 delete [] dat;
00191 setUpdateType("Full");
00192
00193
00194
00195 return true;
00196 }
00197
00198 bool BitmapUpdate::readFromFileRLE(JString filename) {
00199
00200 BITMAPFILEHEADER* bmfh;
00201 BITMAPINFOHEADER* bmih;
00202 long count = 0;
00203
00204 int len;
00205 char* dat = JFile::readAFileBinary(filename, len);
00206 if (dat == NULL)
00207 return false;
00208
00209 char* src = (char*) dat;
00210 bmfh = (BITMAPFILEHEADER*) src;
00211 src += sizeof(BITMAPFILEHEADER);
00212 bmih = (BITMAPINFOHEADER*) src;
00213 src += sizeof(BITMAPINFOHEADER);
00214
00215 if (bmih->biCompression != 0) {
00216 delete [] dat;
00217 return false;
00218 }
00219
00220 if (bmih->biBitCount != 24) {
00221 delete [] dat;
00222 return false;
00223 }
00224
00225 int depth = bmih->biBitCount;
00226 int planes = bmih->biPlanes;
00227 width = bmih->biWidth;
00228 height = bmih->biHeight;
00229
00230 if(bmih->biSizeImage==0)
00231 bmih->biSizeImage=bmfh->bfSize-bmfh->bfOffBits;
00232
00233 if (len < (int)(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (width * height * ((int)(depth/8))) ) ) {
00234 delete [] dat;
00235 return false;
00236 }
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 data = Bitmap::convertBitmapFileDataRunLength(src, width, height, (int)(bmih->biBitCount/8), this->size);
00250
00251 delete [] dat;
00252 if (data == NULL)
00253 return false;
00254
00255 setUpdateType("RunLength");
00256 return true;
00257 }
00258
00259 bool BitmapUpdate::readFromFileDiff(JString filename, Bitmap* oldBitmap) {
00260 BITMAPFILEHEADER* bmfh;
00261 BITMAPINFOHEADER* bmih;
00262 long count = 0;
00263
00264 int len;
00265 char* dat = JFile::readAFileBinary(filename, len);
00266 if (dat == NULL)
00267 return false;
00268
00269 char* src = (char*) dat;
00270 bmfh = (BITMAPFILEHEADER*) src;
00271 src += sizeof(BITMAPFILEHEADER);
00272 bmih = (BITMAPINFOHEADER*) src;
00273 src += sizeof(BITMAPINFOHEADER);
00274
00275 if (bmih->biCompression != 0) {
00276 delete [] dat;
00277 return false;
00278 }
00279
00280 if (bmih->biBitCount != 24) {
00281 delete [] dat;
00282 return false;
00283 }
00284
00285 int depth = bmih->biBitCount;
00286 int planes = bmih->biPlanes;
00287 width = bmih->biWidth;
00288 height = bmih->biHeight;
00289
00290 if(bmih->biSizeImage==0)
00291 bmih->biSizeImage=bmfh->bfSize-bmfh->bfOffBits;
00292
00293 if (len < (int)(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (width * height * ((int)(depth/8))) ) ) {
00294 delete [] dat;
00295 return false;
00296 }
00297
00298
00299
00300
00301 data = Bitmap::differenceBitmapFileData(oldBitmap->data, src, width, height, (int)(bmih->biBitCount/8), this->size);
00302
00303 delete [] dat;
00304 if (data == NULL)
00305 return false;
00306
00307 setUpdateType("Dif");
00308 return true;
00309 }
00310
00311 bool BitmapUpdate::readFromFileRLEDiff(JString filename, Bitmap* oldBitmap) {
00312 BITMAPFILEHEADER* bmfh;
00313 BITMAPINFOHEADER* bmih;
00314 long count = 0;
00315
00316 int len;
00317 char* dat = JFile::readAFileBinary(filename, len);
00318 if (dat == NULL)
00319 return false;
00320
00321 char* src = (char*) dat;
00322 bmfh = (BITMAPFILEHEADER*) src;
00323 src += sizeof(BITMAPFILEHEADER);
00324 bmih = (BITMAPINFOHEADER*) src;
00325 src += sizeof(BITMAPINFOHEADER);
00326
00327 if (bmih->biCompression != 0) {
00328 delete [] dat;
00329 return false;
00330 }
00331
00332 if (bmih->biBitCount != 24) {
00333 delete [] dat;
00334 return false;
00335 }
00336
00337 int depth = bmih->biBitCount;
00338 int planes = bmih->biPlanes;
00339 width = bmih->biWidth;
00340 height = bmih->biHeight;
00341
00342 if(bmih->biSizeImage==0)
00343 bmih->biSizeImage=bmfh->bfSize-bmfh->bfOffBits;
00344
00345 if (len < (int)(sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (width * height * ((int)(depth/8))) ) ) {
00346 delete [] dat;
00347 return false;
00348 }
00349
00350
00351
00352
00353 data = Bitmap::differenceBitmapFileDataRunLength(oldBitmap->data, src, width, height, (int)(bmih->biBitCount/8), this->size);
00354
00355 delete [] dat;
00356 if (data == NULL)
00357 return false;
00358
00359 setUpdateType("DifRunLength");
00360 return true;
00361 }
00362
00363
00364 bool BitmapUpdate::update(BitmapUpdate* update) {
00365 return false;
00366 }
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383 }