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
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #include "camtypes.h"
00104 #include "cdrbitm.h"
00105 #include "cdrform.h"
00106
00107 #include "wbitmap.h"
00108 #include "cdrfiltr.h"
00109
00110 DECLARE_SOURCE("$Revision: 1282 $");
00111
00112 #define new CAM_DEBUG_NEW
00113
00114
00115
00116
00117 #define PROGRESS_BLOCKSIZE 2048
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 KernelBitmap *CDRBitmap::ConvertPattern(RIFFFile *RIFF, DWORD *Reference, CDRFilter *C)
00134 {
00135 TRACEUSER( "Ben", _T("Converting pattern\n"));
00136
00137 ERROR3IF(RIFF->GetObjChunkType() != cdrT_bmpf, "ConvertPattern called for non-pattern RIFF chunk");
00138 ERROR3IF(RIFF->GetObjType() != RIFFOBJECTTYPE_CHUNK, "ConvertPattern called for a non-chunk RIFF object");
00139
00140 if(RIFF->GetObjSize() < sizeof(cdrfPatternBitmapHeader))
00141 {
00142
00143
00144
00145
00146 }
00147
00148
00149 cdrfPatternBitmapHeader Hdr;
00150
00151
00152 if(!RIFF->GetChunkData((ADDR)&Hdr, sizeof(Hdr), 0))
00153 return 0;
00154
00155
00156 if(((Hdr.SizeX * Hdr.SizeY) / 8) > Hdr.DataSize || Hdr.DataSize > (DWORD)RIFF->GetObjSize())
00157 {
00158 TRACEUSER( "Ben", _T("Header in CDR pattern doesn't check out\n"));
00159 return 0;
00160 }
00161
00162
00163 TRACEUSER( "Ben", _T("Pattern reference = %X\n"), Hdr.Reference);
00164 *Reference = Hdr.Reference;
00165
00166
00167
00168 LPBYTE Image;
00169 LPBITMAPINFO ImageHeader;
00170 ImageHeader = AllocDIB(Hdr.SizeX, Hdr.SizeX, 1, &Image);
00171
00172 if(ImageHeader == 0)
00173 return 0;
00174
00175
00176 if(ImageHeader->bmiHeader.biSizeImage < (Hdr.DataSize - (sizeof(DWORD) * 3)))
00177 {
00178 FreeDIB(ImageHeader, Image);
00179 return 0;
00180 }
00181
00182
00183 ImageHeader->bmiColors[0].rgbBlue = 0;
00184 ImageHeader->bmiColors[0].rgbGreen = 0;
00185 ImageHeader->bmiColors[0].rgbRed = 0;
00186 ImageHeader->bmiColors[0].rgbReserved = 0;
00187 ImageHeader->bmiColors[1].rgbBlue = 0xff;
00188 ImageHeader->bmiColors[1].rgbGreen = 0xff;
00189 ImageHeader->bmiColors[1].rgbRed = 0xff;
00190 ImageHeader->bmiColors[1].rgbReserved = 0;
00191
00192
00193
00194 INT32 SourceScanlineLength = (Hdr.SizeX + 7) / 8;
00195
00196
00197 INT32 DestScanlineLength = ((Hdr.SizeX + 31) / 32) * 4;
00198
00199
00200 ERROR3IF(DestScanlineLength < SourceScanlineLength, "Problem with scanline length calculations");
00201
00202
00203 INT32 SourceOffset = Hdr.DataOffset + (sizeof(DWORD) * 3);
00204 INT32 DestOffset = ImageHeader->bmiHeader.biSizeImage - DestScanlineLength;
00205
00206
00207 INT32 Line;
00208 for(Line = 0; Line < (INT32)Hdr.SizeY; Line++)
00209 {
00210 if(!RIFF->GetChunkData(((ADDR)Image) + DestOffset,
00211 SourceScanlineLength, SourceOffset))
00212 {
00213 FreeDIB(ImageHeader, Image);
00214 return 0;
00215 }
00216
00217 SourceOffset += SourceScanlineLength;
00218 DestOffset -= DestScanlineLength;
00219
00220 if((Line & 0xf) == 0)
00221 C->UpdateProgress(TRUE);
00222 }
00223
00224
00225
00226 WinBitmap *WinB = new WinBitmap(ImageHeader, Image);
00227
00228 if(WinB == 0)
00229 {
00230 FreeDIB(ImageHeader, Image);
00231 return 0;
00232 }
00233
00234
00235 KernelBitmap *KerB = new KernelBitmap(WinB);
00236
00237 if(KerB == 0)
00238 {
00239 delete WinB;
00240 return 0;
00241 }
00242
00243
00244 return KerB;
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 KernelBitmap *CDRBitmap::ConvertBitmap5(RIFFFile *RIFF, DWORD *Reference, CDRFilter *C)
00263 {
00264
00265 ERROR3IF(RIFF->GetObjChunkType() != cdrT_bmp, "ConvertBitmap called for non-bitmap RIFF chunk");
00266 ERROR3IF(RIFF->GetObjType() != RIFFOBJECTTYPE_CHUNK, "ConvertBitmap called for a non-chunk RIFF object");
00267
00268 if(RIFF->GetObjSize() < sizeof(cdrfBitmapHeader))
00269 {
00270
00271
00272
00273
00274 }
00275
00276
00277 cdrfBitmapHeader Hdr;
00278
00279
00280 if(!RIFF->GetChunkData((ADDR)&Hdr, sizeof(Hdr), 0))
00281 return 0;
00282
00283
00284 UINT32 BitmapSize = DIBUtil::ScanlineSize( Hdr.SizeX, Hdr.Depth ) * Hdr.SizeY;
00285
00286
00287
00288
00289 if( (BitmapSize + Hdr.ImageOffset - cdrfBitmapHeaderImageOffsetCorrect)
00290 > (DWORD)RIFF->GetObjSize()
00291 || Hdr.Depth < 1 || Hdr.Depth > 32)
00292 {
00293 TRACEUSER( "Ben", _T("Header in CDR bitmap doesn't check out\n"));
00294 return 0;
00295 }
00296
00297
00298 TRACEUSER( "Ben", _T("Bitmap reference = %X\n"), Hdr.Reference);
00299 *Reference = Hdr.Reference;
00300
00301
00302 INT32 NPaletteEntries = Hdr.NPaletteEntries;
00303
00304 if(NPaletteEntries > (1 << Hdr.Depth))
00305 NPaletteEntries = (1 << Hdr.Depth);
00306
00307 if(NPaletteEntries < 0)
00308 NPaletteEntries = 0;
00309
00310
00311 BOOL Greyscale = FALSE;
00312 if(Hdr.Depth <= 8 && Hdr.ImageType == cdrfBITMAPTYPE_GREYSCALE)
00313 Greyscale = TRUE;
00314
00315
00316 LPBYTE Image;
00317 LPBITMAPINFO ImageHeader;
00318 ImageHeader = AllocDIB(Hdr.SizeX, Hdr.SizeY, Hdr.Depth, &Image);
00319
00320 if(ImageHeader == 0)
00321 return 0;
00322
00323
00324 if(Hdr.Depth <= 8)
00325 {
00326 if(Greyscale)
00327 {
00328 UINT32 Entries = 1 << Hdr.Depth;
00329 UINT32 Inc = 256 / Entries;
00330 UINT32 Value = 0;
00331 UINT32 l;
00332
00333 for(l = 0; l < Entries; l++)
00334 {
00335 ImageHeader->bmiColors[l].rgbRed = Value;
00336 ImageHeader->bmiColors[l].rgbGreen = Value;
00337 ImageHeader->bmiColors[l].rgbBlue = Value;
00338 ImageHeader->bmiColors[l].rgbReserved = 0;
00339
00340 Value += Inc;
00341 }
00342 }
00343 else
00344 {
00345
00346 if(!RIFF->GetChunkData((ADDR)ImageHeader->bmiColors,
00347 sizeof(cdrfBitmapPaletteEntry) * NPaletteEntries, sizeof(cdrfBitmapHeader)))
00348 {
00349 FreeDIB(ImageHeader, Image);
00350 return 0;
00351 }
00352
00353
00354 INT32 l;
00355 cdrfBitmapPaletteEntry *Palette = (cdrfBitmapPaletteEntry *)ImageHeader->bmiColors;
00356 cdrfBitmapPaletteEntry TempCol;
00357 for(l = NPaletteEntries - 1; l >= 0; l--)
00358 {
00359 TempCol = Palette[l];
00360 ImageHeader->bmiColors[l].rgbRed = TempCol.Red;
00361 ImageHeader->bmiColors[l].rgbGreen = TempCol.Green;
00362 ImageHeader->bmiColors[l].rgbBlue = TempCol.Blue;
00363 ImageHeader->bmiColors[l].rgbReserved = 0;
00364 }
00365
00366 if (Hdr.Depth == 1)
00367 {
00368
00369 if (ImageHeader->bmiColors[0].rgbRed == ImageHeader->bmiColors[1].rgbRed &&
00370 ImageHeader->bmiColors[0].rgbGreen == ImageHeader->bmiColors[1].rgbGreen &&
00371 ImageHeader->bmiColors[0].rgbBlue == ImageHeader->bmiColors[1].rgbBlue)
00372 {
00373 ImageHeader->bmiColors[0].rgbRed = 0x00;
00374 ImageHeader->bmiColors[0].rgbGreen = 0x00;
00375 ImageHeader->bmiColors[0].rgbBlue = 0x00;
00376
00377 ImageHeader->bmiColors[1].rgbRed = 0xff;
00378 ImageHeader->bmiColors[1].rgbGreen = 0xff;
00379 ImageHeader->bmiColors[1].rgbBlue = 0xff;
00380 }
00381 }
00382 }
00383 }
00384
00385
00386 INT32 RawScanlineLength = Hdr.SizeX * Hdr.Depth;
00387 INT32 ScanlineLength = DIBUtil::ScanlineSize( Hdr.SizeX, Hdr.Depth );
00388
00389
00390
00391 INT32 SourceOffset;
00392
00393 if(Greyscale)
00394 {
00395 SourceOffset = cdrfBitmapGreyscaleImageStart;
00396 }
00397 else
00398 {
00399 SourceOffset = sizeof(cdrfBitmapHeader) + Hdr.ImageOffset - cdrfBitmapHeaderImageOffsetCorrect;
00400 }
00401
00402
00403 INT32 SizeLeftToGet = ScanlineLength * Hdr.SizeY;
00404 INT32 Size, Got = 0;
00405
00406 while(SizeLeftToGet > 0)
00407 {
00408 if(SizeLeftToGet > PROGRESS_BLOCKSIZE)
00409 Size = PROGRESS_BLOCKSIZE;
00410 else
00411 Size = SizeLeftToGet;
00412
00413 if(!RIFF->GetChunkData((ADDR)Image + Got, Size, SourceOffset + Got))
00414 {
00415 FreeDIB(ImageHeader, Image);
00416 return 0;
00417 }
00418
00419 SizeLeftToGet -= Size;
00420 Got += Size;
00421
00422 C->UpdateProgress(TRUE);
00423 }
00424
00425
00426
00427 WinBitmap *WinB = new WinBitmap(ImageHeader, Image);
00428
00429 if(WinB == 0)
00430 {
00431 FreeDIB(ImageHeader, Image);
00432 return 0;
00433 }
00434
00435
00436 WinB->CacheGeometry();
00437
00438
00439 KernelBitmap *KerB = new KernelBitmap(WinB);
00440
00441 if(KerB == 0)
00442 {
00443 delete WinB;
00444 return 0;
00445 }
00446
00447
00448 return KerB;
00449 }
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466 KernelBitmap *CDRBitmap::ConvertBitmap4(RIFFFile *RIFF, DWORD *Reference, CDRFilter *C)
00467 {
00468
00469 ERROR3IF(RIFF->GetObjChunkType() != cdrT_bmp, "ConvertBitmap called for non-bitmap RIFF chunk");
00470 ERROR3IF(RIFF->GetObjType() != RIFFOBJECTTYPE_CHUNK, "ConvertBitmap called for a non-chunk RIFF object");
00471
00472 if(RIFF->GetObjSize() < sizeof(cdrfBitmapHeader4))
00473 {
00474
00475
00476
00477
00478 }
00479
00480
00481 cdrfBitmapHeader4 Hdr;
00482
00483
00484 if(!RIFF->GetChunkData((ADDR)&Hdr, sizeof(Hdr), 0))
00485 return 0;
00486
00487
00488 if((((Hdr.SizeX * Hdr.SizeY) / Hdr.Depth) + Hdr.ImageOffset - cdrfBitmapHeaderImageOffsetCorrect)
00489 > (DWORD)RIFF->GetObjSize()
00490 || Hdr.Depth < 1 || Hdr.Depth > 32)
00491 {
00492 TRACEUSER( "Ben", _T("Header in CDR bitmap doesn't check out\n"));
00493 return 0;
00494 }
00495
00496
00497 TRACEUSER( "Ben", _T("Bitmap reference = %X\n"), Hdr.Reference);
00498 *Reference = Hdr.Reference;
00499
00500
00501 INT32 NPaletteEntries = Hdr.NPaletteEntries;
00502
00503 if(NPaletteEntries > (1 << Hdr.Depth))
00504 NPaletteEntries = (1 << Hdr.Depth);
00505
00506 if(NPaletteEntries < 0)
00507 NPaletteEntries = 0;
00508
00509
00510 BOOL Greyscale = FALSE;
00511
00512
00513
00514
00515 LPBYTE Image;
00516 LPBITMAPINFO ImageHeader;
00517 ImageHeader = AllocDIB(Hdr.SizeX, Hdr.SizeY, Hdr.Depth, &Image);
00518
00519 if(ImageHeader == 0)
00520 return 0;
00521
00522
00523 if(Hdr.Depth <= 8)
00524 {
00525 if(Greyscale)
00526 {
00527 UINT32 Entries = 1 << Hdr.Depth;
00528 UINT32 Inc = 256 / Entries;
00529 UINT32 Value = 0;
00530 UINT32 l;
00531
00532 for(l = 0; l < Entries; l++)
00533 {
00534 ImageHeader->bmiColors[l].rgbRed = Value;
00535 ImageHeader->bmiColors[l].rgbGreen = Value;
00536 ImageHeader->bmiColors[l].rgbBlue = Value;
00537 ImageHeader->bmiColors[l].rgbReserved = 0;
00538
00539 Value += Inc;
00540 }
00541 }
00542 else
00543 {
00544
00545 if(!RIFF->GetChunkData((ADDR)ImageHeader->bmiColors,
00546 sizeof(cdrfBitmapPaletteEntry4) * NPaletteEntries, sizeof(cdrfBitmapHeader4)))
00547 {
00548 FreeDIB(ImageHeader, Image);
00549 return 0;
00550 }
00551 }
00552 }
00553
00554
00555 INT32 RawScanlineLength = Hdr.SizeX * Hdr.Depth;
00556 INT32 ScanlineLength = ((RawScanlineLength + 31) / 32) * 4;
00557
00558
00559 INT32 SourceOffset;
00560
00561 if(Greyscale)
00562 {
00563 SourceOffset = cdrfBitmapGreyscaleImageStart;
00564 }
00565 else
00566 {
00567 SourceOffset = sizeof(cdrfBitmapHeader) + Hdr.ImageOffset - cdrfBitmapHeaderImageOffsetCorrect;
00568 }
00569
00570
00571
00572
00573
00574
00575
00576 INT32 SizeLeftToGet = ScanlineLength * Hdr.SizeY;
00577 INT32 Size, Got = 0;
00578
00579 while(SizeLeftToGet > 0)
00580 {
00581 if(SizeLeftToGet > PROGRESS_BLOCKSIZE)
00582 Size = PROGRESS_BLOCKSIZE;
00583 else
00584 Size = SizeLeftToGet;
00585
00586 if(!RIFF->GetChunkData((ADDR)Image + Got, Size, SourceOffset + Got))
00587 {
00588 FreeDIB(ImageHeader, Image);
00589 return 0;
00590 }
00591
00592 SizeLeftToGet -= Size;
00593 Got += Size;
00594
00595 C->UpdateProgress(TRUE);
00596 }
00597
00598
00599
00600 WinBitmap *WinB = new WinBitmap(ImageHeader, Image);
00601
00602 if(WinB == 0)
00603 {
00604 FreeDIB(ImageHeader, Image);
00605 return 0;
00606 }
00607
00608
00609 WinB->CacheGeometry();
00610
00611
00612 KernelBitmap *KerB = new KernelBitmap(WinB);
00613
00614 if(KerB == 0)
00615 {
00616 delete WinB;
00617 return 0;
00618 }
00619
00620
00621 return KerB;
00622 }
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640 KernelBitmap *GenerateBitmap(Node *Objects, DocRect *BBox, Document *pDocument)
00641 {
00642 return 0;
00643 }
00644
00645
00646
00647
00648
00649
00650