CDRBitmap Class Reference

Does conversion of Corel format bitmaps. More...

#include <cdrbitm.h>

List of all members.

Static Public Member Functions

static KernelBitmapConvertPattern (RIFFFile *RIFF, DWORD *Reference, CDRFilter *C)
 Convert a CDR pattern.
static KernelBitmapConvertBitmap5 (RIFFFile *RIFF, DWORD *Reference, CDRFilter *C)
 Convert a CDR 5 bitmap.
static KernelBitmapConvertBitmap4 (RIFFFile *RIFF, DWORD *Reference, CDRFilter *C)
 Convert a CDR 4 bitmap.
static KernelBitmapGenerateBitmap (Node *Objects, DocRect *BBox, Document *pDocument)


Detailed Description

Does conversion of Corel format bitmaps.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
10/03/95

Definition at line 122 of file cdrbitm.h.


Member Function Documentation

KernelBitmap * CDRBitmap::ConvertBitmap4 RIFFFile RIFF,
DWORD Reference,
CDRFilter C
[static]
 

Convert a CDR 4 bitmap.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/04/95
Parameters:
RIFFFile with the chunk containing the bitmap current, a pointer to the [INPUTS] reference number of this bitmap to fill in
Returns:
a kernel bitmap or zero
See also:
CDRFilter

Definition at line 466 of file cdrbitm.cpp.

00467 {
00468     // check various things
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         // Empty 'if' statement
00475         // Anyone's guess if this was intended
00476         // Changed to this form to remove a compiler warning
00477         // Markn 19/3/99
00478     }
00479 
00480     // get some data from the RIFF file
00481     cdrfBitmapHeader4 Hdr;
00482 
00483     // get the header from offset 0
00484     if(!RIFF->GetChunkData((ADDR)&Hdr, sizeof(Hdr), 0))
00485         return 0;
00486 
00487     // check the header...
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     // store the reference
00497 TRACEUSER( "Ben", _T("Bitmap reference = %X\n"), Hdr.Reference);
00498     *Reference = Hdr.Reference;
00499 
00500     // find a plausible number of palette entries...
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     // is it a greyscale type bitmap?
00510     BOOL Greyscale = FALSE;
00511 //  if(Hdr.Depth <= 8 && Hdr.ImageType == cdrfBITMAPTYPE_GREYSCALE)
00512 //      Greyscale = TRUE;
00513 
00514     // OK, create a bitmap...
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     // right then, sort out that there palette if we really want to
00523     if(Hdr.Depth <= 8)
00524     {
00525         if(Greyscale)
00526         {   // it's a greyscale image - create a nice palette
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         {   // it's a colour image - load it's palette from the file
00544             // load the palette data into the palette in the created bitmap
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     // work out the scanline lengths (aligns to 4 bytes)
00555     INT32 RawScanlineLength = Hdr.SizeX * Hdr.Depth;    // in bits
00556     INT32 ScanlineLength = ((RawScanlineLength + 31) / 32) * 4;
00557 
00558     // set up offsets of current line
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     // grab the image data, it's in the same sort of format as a DIB file. Helpfully
00571 //  if(!RIFF->GetChunkData((ADDR)Image, ScanlineLength * Hdr.SizeY, SourceOffset))
00572 //  {
00573 //      FreeDIB(ImageHeader, Image);
00574 //      return 0;
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     // OK, it's all filled in. Create a KernelBitmap from it.
00599     // first of all, get ourself a nice OIL bitmap
00600     WinBitmap *WinB = new WinBitmap(ImageHeader, Image);
00601 
00602     if(WinB == 0)
00603     {
00604         FreeDIB(ImageHeader, Image);
00605         return 0;
00606     }
00607 
00608     // get it to cache some interesting stuff
00609     WinB->CacheGeometry();
00610 
00611     // and now get a KernelBitmap
00612     KernelBitmap *KerB = new KernelBitmap(WinB);
00613 
00614     if(KerB == 0)
00615     {
00616         delete WinB;
00617         return 0;
00618     }
00619 
00620     // and that's it for now, folks
00621     return KerB;
00622 }

KernelBitmap * CDRBitmap::ConvertBitmap5 RIFFFile RIFF,
DWORD Reference,
CDRFilter C
[static]
 

Convert a CDR 5 bitmap.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
12/04/95
Parameters:
RIFFFile with the chunk containing the bitmap current, a pointer to the [INPUTS] reference number of this bitmap to fill in
Returns:
a kernel bitmap or zero
See also:
CDRFilter

Definition at line 262 of file cdrbitm.cpp.

00263 {
00264     // check various things
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         // Empty 'if' statement
00271         // Anyone's guess if this was intended
00272         // Changed to this form to remove a compiler warning
00273         // Markn 19/3/99
00274     }
00275 
00276     // get some data from the RIFF file
00277     cdrfBitmapHeader Hdr;
00278 
00279     // get the header from offset 0
00280     if(!RIFF->GetChunkData((ADDR)&Hdr, sizeof(Hdr), 0))
00281         return 0;
00282 
00283     // check the header...
00284     UINT32 BitmapSize = DIBUtil::ScanlineSize( Hdr.SizeX, Hdr.Depth ) * Hdr.SizeY;
00285 
00286 //  if((((Hdr.SizeX * Hdr.SizeY) / Hdr.Depth) + Hdr.ImageOffset - cdrfBitmapHeaderImageOffsetCorrect)
00287 //                  > (DWORD)RIFF->GetObjSize()
00288 //                  || Hdr.Depth < 1 || Hdr.Depth > 32)
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     // store the reference
00298 TRACEUSER( "Ben", _T("Bitmap reference = %X\n"), Hdr.Reference);
00299     *Reference = Hdr.Reference;
00300 
00301     // find a plausible number of palette entries...
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     // is it a greyscale type bitmap?
00311     BOOL Greyscale = FALSE;
00312     if(Hdr.Depth <= 8 && Hdr.ImageType == cdrfBITMAPTYPE_GREYSCALE)
00313         Greyscale = TRUE;
00314 
00315     // OK, create a bitmap...
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     // right then, sort out that there palette if we really want to
00324     if(Hdr.Depth <= 8)
00325     {
00326         if(Greyscale)
00327         {   // it's a greyscale image - create a nice palette
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         {   // it's a colour image - load it's palette from the file
00345             // load the palette data into the palette in the created bitmap
00346             if(!RIFF->GetChunkData((ADDR)ImageHeader->bmiColors,
00347                     sizeof(cdrfBitmapPaletteEntry) * NPaletteEntries, sizeof(cdrfBitmapHeader)))
00348             {
00349                 FreeDIB(ImageHeader, Image);
00350                 return 0;
00351             }
00352 
00353             // run through the loaded entries expanding them to DIB entries
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                 // Ensure the palette entries are not the same!
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     // work out the scanline lengths (aligns to 4 bytes)
00386     INT32 RawScanlineLength = Hdr.SizeX * Hdr.Depth;    // in bits
00387     INT32 ScanlineLength = DIBUtil::ScanlineSize( Hdr.SizeX, Hdr.Depth ); // in bytes 
00388     //INT32 ScanlineLength = ((RawScanlineLength + 31) / 32) * 4;
00389 
00390     // set up offsets of current line
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     // grab the image data, it's in the same sort of format as a DIB file. Helpfully
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     // OK, it's all filled in. Create a KernelBitmap from it.
00426     // first of all, get ourself a nice OIL bitmap
00427     WinBitmap *WinB = new WinBitmap(ImageHeader, Image);
00428 
00429     if(WinB == 0)
00430     {
00431         FreeDIB(ImageHeader, Image);
00432         return 0;
00433     }
00434 
00435     // get it to cache some interesting stuff
00436     WinB->CacheGeometry();
00437 
00438     // and now get a KernelBitmap
00439     KernelBitmap *KerB = new KernelBitmap(WinB);
00440 
00441     if(KerB == 0)
00442     {
00443         delete WinB;
00444         return 0;
00445     }
00446 
00447     // and that's it for now, folks
00448     return KerB;
00449 }

KernelBitmap * CDRBitmap::ConvertPattern RIFFFile RIFF,
DWORD Reference,
CDRFilter C
[static]
 

Convert a CDR pattern.

Author:
Ben_Summers (Xara Group Ltd) <camelotdev@xara.com>
Date:
10/04/95
Parameters:
RIFFFile with the chunk containing the pattern current, a pointer to the [INPUTS] reference number of this bitmap to fill in
Returns:
a kernel bitmap or zero
See also:
CDRFilter

Definition at line 133 of file cdrbitm.cpp.

00134 {
00135 TRACEUSER( "Ben", _T("Converting pattern\n"));
00136     // check various things
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         // Empty 'if' statement
00143         // Anyone's guess if this was intended
00144         // Changed to this form to remove a compiler warning
00145         // Markn 19/3/99
00146     }
00147 
00148     // get some data from the RIFF file
00149     cdrfPatternBitmapHeader Hdr;
00150 
00151     // get the header from offset 0
00152     if(!RIFF->GetChunkData((ADDR)&Hdr, sizeof(Hdr), 0))
00153         return 0;
00154 
00155     // check the header...
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     // store the reference
00163 TRACEUSER( "Ben", _T("Pattern reference = %X\n"), Hdr.Reference);
00164     *Reference = Hdr.Reference;
00165 
00166     // OK, create a bitmap...
00167     // it's always a 1 bpp bitmap
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     // check and then fill in the image data
00176     if(ImageHeader->bmiHeader.biSizeImage < (Hdr.DataSize - (sizeof(DWORD) * 3)))
00177     {
00178         FreeDIB(ImageHeader, Image);
00179         return 0;
00180     }
00181 
00182     // set some palette data
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     // corel bitmaps align the scanlines to the nearest byte, not the nearest word
00193     // how long is a corel scanline
00194     INT32 SourceScanlineLength = (Hdr.SizeX + 7)    / 8;
00195     
00196     // how long is the destination scanline?
00197     INT32 DestScanlineLength = ((Hdr.SizeX + 31) / 32) * 4;
00198 
00199     // sanity check
00200     ERROR3IF(DestScanlineLength < SourceScanlineLength, "Problem with scanline length calculations");
00201     
00202     // set up offsets of current line
00203     INT32 SourceOffset = Hdr.DataOffset + (sizeof(DWORD) * 3);
00204     INT32 DestOffset = ImageHeader->bmiHeader.biSizeImage - DestScanlineLength;
00205     
00206     // grab the image data, backwards
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     // OK, it's all filled in. Create a KernelBitmap from it.
00225     // first of all, get ourself a nice OIL bitmap
00226     WinBitmap *WinB = new WinBitmap(ImageHeader, Image);
00227 
00228     if(WinB == 0)
00229     {
00230         FreeDIB(ImageHeader, Image);
00231         return 0;
00232     }
00233 
00234     // and now get a KernelBitmap
00235     KernelBitmap *KerB = new KernelBitmap(WinB);
00236 
00237     if(KerB == 0)
00238     {
00239         delete WinB;
00240         return 0;
00241     }
00242 
00243     // and that's it for now, folks
00244     return KerB;
00245 }

static KernelBitmap* CDRBitmap::GenerateBitmap Node Objects,
DocRect BBox,
Document pDocument
[static]
 


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:52:16 2007 for Camelot by  doxygen 1.4.4