dibutil.h File Reference

(r1785/r923)

#include "memblk.h"

Go to the source code of this file.

Classes

class  DIBUtil
 Contains static functions for handy DIB manipulation. Never instantiate one of these. That would be silly. More...

Defines

#define CC_BMPTYPE   mmioFOURCC('R','G','B','T')
#define EXTRA_GAVIN_BYTES   4

Typedefs

typedef void(* FNPTR_SCANLINE )(INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits)

Enumerations

enum  BitmapConvertHint {
  CONVHINT_NONE, CONVHINT_FINAL24, CONVHINT_FINAL16, CONVHINT_FINAL555,
  CONVHINT_FINAL565, CONVHINT_FINAL655, CONVHINT_FINAL664, CONVHINT_SCREEN8,
  CONVHINT_SCREEN4, CONVHINT_METAFILE, CONVHINT_PRINTER, CONVHINT_MAXVALUE = CONVHINT_PRINTER
}
 Enum for hinting when converting bitmaps. More...

Functions

LPBITMAPINFO AllocDIB (UINT32 Width, UINT32 Height, UINT32 Depth, LPBYTE *Bits, MemoryBlock *Blk=NULL, BOOL UseLimitedHeap=FALSE)
 Allocate and initialise a Windows DIB. Note biclrUsed is set only for 8-bit and less deep bitmaps, 0 for high-colour ones. biClrImportant is zeroed.
void FreeDIB (LPBITMAPINFO, LPBYTE, MemoryBlock *Blk=NULL, BOOL UseLimitedHeap=FALSE)
 Free up a DIB allocated with AllocDIB.
INT32 GetDIBBitsSize (LPBITMAPINFOHEADER bh)
 Give actual mem size allocations made by AllocDIB - more mem is allocated than width * height * Bytes per pix.


Define Documentation

#define CC_BMPTYPE   mmioFOURCC('R','G','B','T')
 

Definition at line 115 of file dibutil.h.

#define EXTRA_GAVIN_BYTES   4
 

Definition at line 119 of file dibutil.h.


Typedef Documentation

typedef void(* FNPTR_SCANLINE)(INT32 PixelWidth, LPBYTE InputBits, LPBYTE OutputBits)
 

Definition at line 295 of file dibutil.h.


Enumeration Type Documentation

enum BitmapConvertHint
 

Enum for hinting when converting bitmaps.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/2/95
Enumerator:
CONVHINT_NONE 
CONVHINT_FINAL24 
CONVHINT_FINAL16 
CONVHINT_FINAL555 
CONVHINT_FINAL565 
CONVHINT_FINAL655 
CONVHINT_FINAL664 
CONVHINT_SCREEN8 
CONVHINT_SCREEN4 
CONVHINT_METAFILE 
CONVHINT_PRINTER 
CONVHINT_MAXVALUE 

Definition at line 136 of file dibutil.h.

00137 {
00138     CONVHINT_NONE,              // no hints
00139     CONVHINT_FINAL24,           // final output 24-bit
00140     CONVHINT_FINAL16,           // final output 16-bit RGB not known
00141     CONVHINT_FINAL555,          // final output 15-bit
00142     CONVHINT_FINAL565,
00143     CONVHINT_FINAL655,
00144     CONVHINT_FINAL664,
00145     CONVHINT_SCREEN8,           // 8-bit screen
00146     CONVHINT_SCREEN4,           // 4-bit screen
00147     CONVHINT_METAFILE,
00148     CONVHINT_PRINTER,           // printer
00149 
00150     CONVHINT_MAXVALUE = CONVHINT_PRINTER
00151 };


Function Documentation

LPBITMAPINFO AllocDIB UINT32  Width,
UINT32  Height,
UINT32  Depth,
LPBYTE Bits,
MemoryBlock Blk,
BOOL  UseLimitedHeap
 

Allocate and initialise a Windows DIB. Note biclrUsed is set only for 8-bit and less deep bitmaps, 0 for high-colour ones. biClrImportant is zeroed.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/4/94
Parameters:
Size in pixels of DIB, Depth of bitmap (1,4,8,16,24,32) [INPUTS] UseLimitedHeap - TRUE if we should use the Limited memory allocator
Bits is updated to point to an array of bytes, or NULL if failed. If Blk is [OUTPUTS] not NULL then the bitmap is allocated into it instead of using CCMalloc and Bits will point to that. If Bits is NULL then no memory for the bitmap bytes are allocated, just the bitmap header. Due to GDraw restrictions, we actually allocate an extra 2 bytes plus one scanline.
Returns:
Pointer to suitable BITMAPINFO or NULL if failed.

Errors: If passed an invalid depth, will ensure and return NULL. If passed a zero width or height, it will return a 0x0 bitmap with four bytes allocated for the 'bits'. Scope: Global

See also:
FreeDIB & GetDIBBitsSize
NB NB NB If this changes please ensure mem allocation changes are reflected in GetDIBBitsSize as well.

Definition at line 181 of file dibutil.cpp.

00182 {
00183     LPBITMAPINFO lpInfo;
00184 
00185     ENSURE(Blk==NULL, "Cannot do blks yet");
00186 
00187     INT32 size = DIBUtil::ScanlineSize( Width, Depth ) * Height;
00188     #if DIB_DEBUG
00189     const INT32 dbsize = DIBUtil::ScanlineSize( Width, Depth ) * DIB_DEBUG*2;
00190     if (dbsize<16)
00191         dbsize = 16;
00192     #else
00193     const INT32 dbsize = 0;
00194     #endif
00195 
00196     if (size==0)
00197         size = 4;                                       // in case of zero w or h
00198 
00199     // Get the memory manager
00200     TunedMemory* pTuned = GetTunedMemManager();
00201 
00202     // get the bytes
00203     LPBYTE Bytes = NULL;
00204     if (Bits)
00205     {
00206         // in case of failure
00207         *Bits = NULL;
00208 
00209         // allocate the actual bits of the bitmap first
00210         if (UseLimitedHeap)
00211             Bytes = (LPBYTE) pTuned->LimitedCCMalloc(size + dbsize + EXTRA_GAVIN_BYTES + DIBUtil::ScanlineSize(Width, Depth));
00212         else
00213             Bytes = (LPBYTE)CCMalloc(size + dbsize + EXTRA_GAVIN_BYTES + DIBUtil::ScanlineSize(Width, Depth));
00214 
00215         // See what we got
00216         if (Bytes==NULL)
00217             return NULL;
00218     }
00219 
00220     // we need a BITMAPINFO structure
00221     size_t extras;
00222     INT32 used_cols = 0;
00223 
00224     switch (Depth)
00225     {
00226         case 1:
00227             extras = 2*sizeof(COLORREF);
00228             used_cols = 2;
00229             break;
00230         case 4:
00231             extras = 16*sizeof(COLORREF);
00232             used_cols = 16;
00233             break;
00234         case 8:
00235             extras = 256*sizeof(COLORREF);
00236             used_cols = 256;
00237             break;
00238         case 16:
00239             extras = 3*sizeof(COLORREF);
00240             break;
00241         case 24:
00242             extras = 0;
00243             break;
00244         case 32:
00245             extras = 3*sizeof(COLORREF);
00246             break;
00247         default:
00248             ENSURE(FALSE, "Bad bitmap depth");
00249             return NULL;
00250     }
00251 
00252     // get the bitmap info block
00253     if (UseLimitedHeap)
00254         lpInfo = (LPBITMAPINFO) pTuned->LimitedCCMalloc(sizeof(BITMAPINFO) + extras);
00255     else
00256         lpInfo = (LPBITMAPINFO) CCMalloc(sizeof(BITMAPINFO) + extras);
00257         
00258     // See if it worked
00259     if (lpInfo == NULL)
00260     {
00261         // Free the memory from the appropriate place
00262         if (UseLimitedHeap)
00263             pTuned->LimitedCCFree(Bytes);
00264         else
00265             CCFree(Bytes);
00266 
00267         return NULL;
00268     }
00269 
00270     lpInfo->bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
00271     lpInfo->bmiHeader.biWidth       = Width;
00272     lpInfo->bmiHeader.biHeight      = Height;
00273     lpInfo->bmiHeader.biPlanes      = 1;
00274     lpInfo->bmiHeader.biBitCount    = Depth;
00275     lpInfo->bmiHeader.biCompression = BI_RGB;
00276     lpInfo->bmiHeader.biXPelsPerMeter   = 3780;             // Default to 96 dpi
00277     lpInfo->bmiHeader.biYPelsPerMeter   = 3780;
00278     lpInfo->bmiHeader.biClrUsed         = used_cols;
00279     lpInfo->bmiHeader.biClrImportant    = 0;
00280     lpInfo->bmiHeader.biSizeImage       = size;
00281 
00282     if (extras > 0)
00283     {
00284         memset(&(lpInfo->bmiColors[0]), 0, extras);
00285     }
00286 
00287     if (Bits)
00288     {
00289         #if DIB_DEBUG
00290         const size_t count = DIBUtil::ScanlineSize( Width, Depth ); // bytes per scanline
00291         memset( Bytes, 0x42, count*DIB_DEBUG );                     // top area
00292         memset( Bytes + count * (Height + DIB_DEBUG), 0x42, count*DIB_DEBUG );
00293         Bytes += count * DIB_DEBUG;
00294         PINT32 lpLong = (PINT32) (Bytes-4);
00295         *lpLong = count;                                    // store count
00296         lpLong[-1] = (INT32)(Bytes + count * Height);       // and ptr to end
00297         #endif
00298         *Bits = Bytes;                                      // return for caller
00299     }
00300 
00301     return lpInfo;
00302 }

void FreeDIB LPBITMAPINFO  lpInfo,
LPBYTE  Bits,
MemoryBlock Blk,
BOOL  UseLimitedHeap
 

Free up a DIB allocated with AllocDIB.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
13/4/94
Parameters:
Results of AllocDIB. [INPUTS] UseLimitedHeap - TRUE if we should use the Limited heap. Defaults to FALSE
- [OUTPUTS]
Returns:
-

Errors: - Scope: Global

See also:
AllocDIB

Definition at line 321 of file dibutil.cpp.

00322 {
00323     ENSURE(Blk==NULL, "Cannot free blocks");
00324     #if DIB_DEBUG
00325     if (Bits)
00326     {
00327         const size_t count = *(PINT32)(Bits-4);
00328         const LPBYTE endbuf= (LPBYTE)*(PINT32)(Bits-8);
00329         LPBYTE p = Bits - count * DIB_DEBUG;
00330         size_t i = count - 8;
00331         while (i--)
00332         {
00333             if (*p != 0x42)
00334                 ENSURE(FALSE, "top of bitmap corrupted");
00335             p++;
00336         }
00337         p = endbuf;
00338         i = count;
00339         while (i--)
00340         {
00341             if (*p != 0x42)
00342                 ENSURE(FALSE, "bottom of bitmap corrupted");
00343             p++;
00344         }
00345         Bits -= count * DIB_DEBUG;
00346     }
00347     #endif
00348 
00349     // Free the bits
00350     if (UseLimitedHeap)
00351     {
00352         // Get the memory manager
00353         TunedMemory* pTuned = GetTunedMemManager();
00354         pTuned->LimitedCCFree(Bits);
00355         pTuned->LimitedCCFree(lpInfo);
00356     }
00357     else
00358     {
00359         CCFree(Bits);
00360         CCFree(lpInfo);
00361     }
00362 }

INT32 GetDIBBitsSize LPBITMAPINFOHEADER  bh  ) 
 

Give actual mem size allocations made by AllocDIB - more mem is allocated than width * height * Bytes per pix.

Author:
Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/5/00
Parameters:
lpInfo - LPBITMAPINFO struct returned by AllocDIB [INPUTS]
Returns:
Actual size of bmp memory block allocated by AllocDIB for the bitmap bits described by the bmp header lpInfo

Errors: - Scope: Global

See also:
AllocDIB
NOTES: NB NB Don't use this on a LPBITMAPINFO that was not created by AllocDIB. The calculations are specific to the way AllocDIB allocs mem, so may give you inaccurate results for other bmp buffers

Definition at line 384 of file dibutil.cpp.

00385 {
00386     // Mem calc from Dibutils AllocDIB
00387     // Bytes = (LPBYTE)CCMalloc(size + dbsize + EXTRA_GAVIN_BYTES + DIBUtil::ScanlineSize(Width, Depth));
00388     return bh->biSizeImage;
00389 /*  INT32 size = DIBUtil::ScanlineSize( bh->biWidth, bh->biBitCount ) * bh->biHeight;
00390     #if DIB_DEBUG
00391     const INT32 dbsize = DIBUtil::ScanlineSize( bh->biWidth, bh->biBitCount ) * DIB_DEBUG*2;
00392     if (dbsize<16)
00393         dbsize = 16;
00394     #else
00395     const INT32 dbsize = 0;
00396     #endif
00397 
00398     if (size==0)
00399         size = 4;                                       // in case of zero w or h
00400 
00401     return size + dbsize + EXTRA_GAVIN_BYTES + DIBUtil::ScanlineSize( bh->biWidth, bh->biBitCount );
00402 */
00403 }


Generated on Sat Nov 10 03:49:30 2007 for Camelot by  doxygen 1.4.4