00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00027 {
00028 internalCreate(16, 16, 8, false);
00029
00030 PLASSERT_VALID(this);
00031 }
00032
00033
00034 PLAnyBmp::~PLAnyBmp
00035 ()
00036 {
00037
00038 freeMembers();
00039 }
00040
00041
00042 long PLAnyBmp::GetMemUsed
00043 ()
00044
00045 {
00046 PLASSERT_VALID (this);
00047
00048 return GetMemNeeded (GetWidth(), GetHeight(), GetBitsPerPixel())+
00049 sizeof (*this);
00050 }
00051
00052
00053 long PLAnyBmp::GetBytesPerLine
00054 ()
00055
00056 {
00057
00058 int nBytes = GetWidth() * GetBitsPerPixel() / 8;
00059 if (GetBitsPerPixel() == 1 && GetWidth() % 8)
00060 ++nBytes;
00061 return nBytes;
00062 }
00063
00064
00066
00067
00068 long PLAnyBmp::GetBitsMemNeeded
00069 ( PLLONG width,
00070 PLLONG height,
00071 PLWORD BitsPerPixel
00072 )
00073
00074 {
00075
00076 int LineMem = width*BitsPerPixel/8;
00077
00078
00079 if (BitsPerPixel == 1 && width % 8)
00080 ++LineMem;
00081
00082
00083 return LineMem*height;
00084 }
00085
00086
00087 long PLAnyBmp::GetMemNeeded
00088 ( PLLONG width,
00089 PLLONG height,
00090 PLWORD BitsPerPixel
00091 )
00092
00093 {
00094 int HeaderMem = sizeof (PLAnyBmp);
00095 if (BitsPerPixel < 16)
00096 {
00097 HeaderMem += (1 << BitsPerPixel)*sizeof (PLPixel32);
00098 }
00099
00100 return HeaderMem+GetBitsMemNeeded (width, height, BitsPerPixel);
00101 }
00102
00103
00105
00106
00107
00108 void PLAnyBmp::internalCreate
00109 ( PLLONG Width,
00110 PLLONG Height,
00111 PLWORD BitsPerPixel,
00112 bool bAlphaChannel
00113 )
00114
00115
00116 {
00117
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
00127
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
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
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212