Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

planybmp.cpp

Go to the documentation of this file.
00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: planybmp.cpp,v 1.1 2004/05/21 21:02:52 maxx Exp $
00005 |      Device independent bitmap class
00006 |
00007 |        Plattform-independent version
00008 |
00009 |        Manipulates uncompressed device independent bitmaps.
00010 |
00011 |        Supported data formats are 8, 24 (partial) and 32 bpp. The 
00012 |        data is stored sequentially without padding in the bitmap.
00013 |
00014 |      Copyright (c) 1996-2002 Ulrich von Zadow
00015 |
00016 \--------------------------------------------------------------------
00017 */
00018 
00019 #include "plstdpch.h"
00020 #include "planybmp.h"
00021 #include "plexcept.h"
00022 
00023 
00024 PLAnyBmp::PLAnyBmp
00025   () : m_pBits(NULL)
00026     // Creates an empty bitmap.
00027 {
00028   internalCreate(16, 16, 8, false);
00029 
00030   PLASSERT_VALID(this);
00031 }
00032 
00033 
00034 PLAnyBmp::~PLAnyBmp
00035     ()
00036 {
00037   // Free the memory.
00038   freeMembers();
00039 }
00040 
00041 
00042 long PLAnyBmp::GetMemUsed
00043     ()
00044     // Returns the memory used by the object.
00045 {
00046   PLASSERT_VALID (this);
00047 
00048   return GetMemNeeded (GetWidth(), GetHeight(), GetBitsPerPixel())+
00049                                                 sizeof (*this);
00050 }
00051 
00052 
00053 long PLAnyBmp::GetBytesPerLine
00054     ()
00055     // Returns number of bytes used per line.
00056 {
00057   // bdelmee code change
00058   int nBytes = GetWidth() * GetBitsPerPixel() / 8;
00059   if (GetBitsPerPixel() == 1 && GetWidth() % 8)
00060     ++nBytes;
00061   return nBytes;
00062 }
00063 
00064 
00066 // Static functions
00067 
00068 long PLAnyBmp::GetBitsMemNeeded
00069     ( PLLONG width,
00070       PLLONG height,
00071       PLWORD BitsPerPixel
00072     )
00073     // Returns memory needed by bitmap bits.
00074 {
00075   // Calculate memory per line.
00076   int LineMem = width*BitsPerPixel/8;
00077 
00078   // bdelmee code change
00079   if (BitsPerPixel == 1 && width % 8)
00080     ++LineMem;
00081 
00082   // Multiply by number of lines
00083   return LineMem*height;
00084 }
00085 
00086 
00087 long PLAnyBmp::GetMemNeeded
00088     ( PLLONG width,
00089       PLLONG height,
00090       PLWORD BitsPerPixel
00091     )
00092     // Returns memory needed by a bitmap with the specified attributes.
00093 {
00094   int HeaderMem = sizeof (PLAnyBmp);
00095   if (BitsPerPixel < 16)
00096   { // Palette memory
00097     HeaderMem += (1 << BitsPerPixel)*sizeof (PLPixel32);
00098   }
00099 
00100   return HeaderMem+GetBitsMemNeeded (width, height, BitsPerPixel);
00101 }
00102 
00103 
00105 // Local functions
00106 
00107 
00108 void PLAnyBmp::internalCreate
00109     ( PLLONG Width,
00110       PLLONG Height,
00111       PLWORD BitsPerPixel,
00112       bool bAlphaChannel
00113     )
00114     // Create a new empty bitmap. Bits are uninitialized.
00115     // Assumes that no memory is allocated before the call.
00116 {
00117   // Allocate memory
00118 
00119 #ifdef MAX_BITMAP_SIZE
00120   int MemNeeded = GetMemNeeded (Width, Height, BitsPerPixel);
00121 
00122   if (MemNeeded > MAX_BITMAP_SIZE)
00123     throw PLTextException(PL_ERRDIB_TOO_LARGE, "Bitmap size too large.\n");
00124 #endif
00125 
00126 //  m_pBits = (PLBYTE *) malloc (GetBitsMemNeeded (Width, Height,
00127 //                                               BitsPerPixel));
00128   m_pBits = new PLBYTE [GetBitsMemNeeded (Width, Height, BitsPerPixel)];
00129 
00130   if (BitsPerPixel <= 8)
00131     m_pClrTab = new PLPixel32 [1 << BitsPerPixel];
00132    else
00133     m_pClrTab = NULL;
00134   initLocals (Width, Height, BitsPerPixel, bAlphaChannel);
00135 
00136   PLASSERT_VALID (this);
00137 }
00138 
00139 
00140 void PLAnyBmp::initLineArray
00141     ()
00142 {
00143 //  m_pLineArray = (PLBYTE **) malloc (m_Height * sizeof (PLBYTE *));
00144   m_pLineArray = new PLBYTE * [m_Height];
00145   int LineLen = GetBytesPerLine();
00146 
00147   for (int y=0; y<m_Height; y++)
00148     m_pLineArray[y] = m_pBits + y*LineLen;
00149 }
00150 
00151 void PLAnyBmp::freeMembers
00152     ()
00153 {
00154   delete [] m_pBits;
00155   m_pBits = NULL;
00156 
00157   if (m_pClrTab)
00158   {
00159     delete [] m_pClrTab;
00160     m_pClrTab = NULL;
00161   }
00162 
00163   delete [] m_pLineArray;
00164   m_pLineArray = NULL;
00165 }
00166 
00167 /*
00168 /--------------------------------------------------------------------
00169 |
00170 |      $Log: planybmp.cpp,v $
00171 |      Revision 1.1  2004/05/21 21:02:52  maxx
00172 |      Initial Version of vuVolume, moderatly changed to make it compile on my windows and linux machine.
00173 |
00174 |      Revision 1.1  2002/11/13 01:58:20  mspindle
00175 |      *** empty log message ***
00176 |
00177 |      Revision 1.3  2002/02/24 13:00:12  uzadow
00178 |      Documentation update; removed buggy PLFilterRotate.
00179 |
00180 |      Revision 1.2  2001/10/06 22:03:26  uzadow
00181 |      Added PL prefix to basic data types.
00182 |
00183 |      Revision 1.1  2001/09/16 19:03:22  uzadow
00184 |      Added global name prefix PL, changed most filenames.
00185 |
00186 |      Revision 1.10  2001/02/04 14:31:52  uzadow
00187 |      Member initialization list cleanup (Erik Hoffmann).
00188 |
00189 |      Revision 1.9  2001/01/21 14:28:21  uzadow
00190 |      Changed array cleanup from delete to delete[].
00191 |
00192 |      Revision 1.8  2000/12/18 22:42:52  uzadow
00193 |      Replaced RGBAPIXEL with PLPixel32.
00194 |
00195 |      Revision 1.7  2000/08/13 12:11:43  Administrator
00196 |      Added experimental DirectDraw-Support
00197 |
00198 |      Revision 1.6  2000/01/16 20:43:12  anonymous
00199 |      Removed MFC dependencies
00200 |
00201 |      Revision 1.5  2000/01/10 23:52:59  Ulrich von Zadow
00202 |      Changed formatting & removed tabs.
00203 |
00204 |      Revision 1.4  1999/12/08 15:39:45  Ulrich von Zadow
00205 |      Unix compatibility changes
00206 |
00207 |      Revision 1.3  1999/10/03 18:50:51  Ulrich von Zadow
00208 |      Added automatic logging of changes.
00209 |
00210 |
00211 \--------------------------------------------------------------------
00212 */

Generated on Wed Dec 15 21:20:30 2004 for vuVolume by  doxygen 1.3.9.1