/* /-------------------------------------------------------------------- | | $Id: planybmp.cpp,v 1.9 2004/09/11 12:41:34 uzadow Exp $ | Device independent bitmap class | | Plattform-independent version | | Manipulates uncompressed device independent bitmaps. | | Supported data formats are 8, 24 (partial) and 32 bpp. The | data is stored sequentially without padding in the bitmap. | | Copyright (c) 1996-2002 Ulrich von Zadow | \-------------------------------------------------------------------- */ #include "planybmp.h" #include "plexcept.h" #include using namespace std; PLAnyBmp::PLAnyBmp () : m_pBits(NULL) // Creates an empty bitmap. { internalCreate(16, 16, PLPixelFormat::I8); PLASSERT_VALID(this); } PLAnyBmp::~PLAnyBmp () { // Free the memory. freeMembers(); } long PLAnyBmp::GetMemUsed () // Returns the memory used by the object. { PLASSERT_VALID (this); return GetMemNeeded (GetWidth(), GetHeight(), GetBitsPerPixel())+ sizeof (*this); } long PLAnyBmp::GetBytesPerLine () // Returns number of bytes used per line. { // bdelmee code change int nBytes = GetWidth() * GetBitsPerPixel() / 8; if (GetBitsPerPixel() == 1 && GetWidth() % 8) ++nBytes; return nBytes; } ///////////////////////////////////////////////////////////////////// // Static functions long PLAnyBmp::GetBitsMemNeeded ( PLLONG width, PLLONG height, PLWORD BitsPerPixel ) // Returns memory needed by bitmap bits. { // Calculate memory per line. int LineMem = width*BitsPerPixel/8; // bdelmee code change if (BitsPerPixel == 1 && width % 8) ++LineMem; // Multiply by number of lines return LineMem*height; } long PLAnyBmp::GetMemNeeded ( PLLONG width, PLLONG height, PLWORD BitsPerPixel ) // Returns memory needed by a bitmap with the specified attributes. { int HeaderMem = sizeof (PLAnyBmp); if (BitsPerPixel < 16) { // Palette memory HeaderMem += (1 << BitsPerPixel)*sizeof (PLPixel32); } return HeaderMem+GetBitsMemNeeded (width, height, BitsPerPixel); } ///////////////////////////////////////////////////////////////////// // Local functions void PLAnyBmp::internalCreate ( PLLONG Width, PLLONG Height, const PLPixelFormat& pf ) // Create a new empty bitmap. Bits are uninitialized. // Assumes that no memory is allocated before the call. { // Allocate memory #ifdef MAX_BITMAP_SIZE int MemNeeded = GetMemNeeded (Width, Height, pf.GetBitsPerPixel()); if (MemNeeded > MAX_BITMAP_SIZE) throw PLTextException(PL_ERRDIB_TOO_LARGE, "Bitmap size too large.\n"); #endif m_pBits = new PLBYTE [GetBitsMemNeeded (Width, Height, pf.GetBitsPerPixel())]; if (pf.GetBitsPerPixel() <= 8) m_pClrTab = new PLPixel32 [1 << pf.GetBitsPerPixel()]; else m_pClrTab = NULL; initLocals (Width, Height, pf); PLASSERT_VALID (this); } void PLAnyBmp::initLineArray () { m_pLineArray = new PLBYTE * [m_Size.y]; int LineLen = GetBytesPerLine(); for (int y=0; y