1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
40 //M*/// RasterDoc.cpp : implementation file
47 /////////////////////////////////////////////////////////////////////////////
50 /*======================================================================================*/
68 fileName = "Default.bmp";
70 }/* CRaster::CRaster */
73 /*======================================================================================*/
78 }/* CRaster::~CRaster */
81 /*======================================================================================*/
83 int CRaster::CreateRaster(DWORD width, DWORD height, int bitPerPixel)
89 shiftPixel = (width + 7) / 8;
92 shiftPixel = (width + 1) / 2;
98 shiftPixel = width * 3;
108 numColor = 1 << bitPerPixel;
110 if( bitPerPixel == 1 ||
112 bitPerPixel == 8) { // type of bitmap
114 imgInfo = (BITMAPINFO*)malloc( sizeof(BITMAPINFO)
115 + sizeof(RGBQUAD) * numColor);
116 // Create Palette for 1<<bitCount colors
117 pal = new CPalette();
118 logPal = (LOGPALETTE*)calloc( 1, sizeof(LOGPALETTE)
119 + sizeof(PALETTEENTRY) * numColor);
120 logPal->palVersion = 0x300;
121 logPal->palNumEntries = (WORD)numColor;
123 for(DWORD Index = 0; Index < numColor; Index++) {
124 logPal->palPalEntry[Index].peRed = (BYTE)Index;
125 logPal->palPalEntry[Index].peGreen = (BYTE)Index;
126 logPal->palPalEntry[Index].peBlue = (BYTE)Index;
129 pal->CreatePalette(logPal);
132 if( bitPerPixel == 24 ) {
133 imgInfo = (BITMAPINFO*)malloc( sizeof(BITMAPINFO)
137 sizeString = (shiftPixel + 3) / 4 * 4; // Attention !!! divided 4 !!!;
139 imgInfo = (BITMAPINFO*)calloc( sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1);
140 imgInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
141 imgInfo->bmiHeader.biWidth = width;
142 imgInfo->bmiHeader.biHeight = -(int)(height);
143 imgInfo->bmiHeader.biPlanes = 1;
144 imgInfo->bmiHeader.biBitCount = WORD(bitPerPixel);
145 imgInfo->bmiHeader.biCompression = BI_RGB;
146 imgInfo->bmiHeader.biSizeImage = sizeString*height;
148 imgDataSave = new BYTE[sizeString*height];
149 imgData = new BYTE[sizeString*height];
152 }/* CRaster::CreateRaster */
155 /*======================================================================================*/
157 int CRaster::UpdateImage(BYTE* imgSrc)
159 BYTE* imgDst = imgData;
161 imgSrc = imgDataSave;
164 for(DWORD index = 0; index < (DWORD)abs(imgInfo->bmiHeader.biHeight); index++){
165 memcpy( imgDst, imgSrc, shiftPixel);
166 imgDst += sizeString;
167 imgSrc += sizeString;
170 }/* CRaster::UpdateImage */
173 /*======================================================================================*/
175 int CRaster::LoadBMP(const char* cfileName)
178 BITMAPFILEHEADER fileHeader;
179 BITMAPINFOHEADER infoHeader;
192 if(file.Open(cfileName, CFile::modeRead, NULL) == 0)
195 fileName = cfileName;
197 file.Read(&fileHeader, sizeof(BITMAPFILEHEADER));
198 if(fileHeader.bfType != 0x4d42) {
201 } /* if... it's not BMP */
204 file.Read(&infoHeader, sizeof(BITMAPINFOHEADER));
205 bitCount = infoHeader.biBitCount;
206 if(infoHeader.biCompression != BI_RGB ) {
212 bitCount == 8) { // type of bitmap
214 DWORD numColor = infoHeader.biClrUsed;
216 numColor = 1<<bitCount;
219 imgInfo = (BITMAPINFO*)malloc( sizeof(BITMAPINFO)
220 + sizeof(RGBQUAD) * (1<<bitCount));
221 file.Read(imgInfo->bmiColors, sizeof(RGBQUAD) * numColor);
223 // Create Palette for 1<<bitCount colors
224 pal = new CPalette();
225 logPal = (LOGPALETTE*)
226 calloc( 1, sizeof(LOGPALETTE)
227 + sizeof(PALETTEENTRY) * (1<<bitCount));
229 logPal->palVersion = 0x300;
230 logPal->palNumEntries = BYTE(1<<bitCount);
232 for(Index = 0; Index < numColor; Index++) {
234 logPal->palPalEntry[Index].peRed =
235 imgInfo->bmiColors[Index].rgbRed;
237 logPal->palPalEntry[Index].peGreen =
238 imgInfo->bmiColors[Index].rgbGreen;
240 logPal->palPalEntry[Index].peBlue =
241 imgInfo->bmiColors[Index].rgbBlue;
244 pal->CreatePalette(logPal);
246 } else if( bitCount == 24 ) {
247 imgInfo = (BITMAPINFO*)malloc( sizeof(BITMAPINFO)
252 } /* if... not support BMP */
254 imgInfo->bmiHeader = infoHeader;
257 width = imgInfo->bmiHeader.biWidth;
258 height = abs(imgInfo->bmiHeader.biHeight);
262 shiftPixel = (width + 7) / 8;
265 shiftPixel = (width + 1) / 2;
271 shiftPixel = width * 3;
280 sizeString = (shiftPixel + 3) / 4 * 4; // Attention !!! divided 4 !!!;
282 tempImage = new BYTE[sizeString*height];
283 imgData = new BYTE[sizeString*height];
284 imgDataSave = tempImage;
286 for(Index = 0; Index < height; Index++) {
287 file.Read(tempImage, sizeString);
288 tempImage+=sizeString;
291 imgInfo->bmiHeader.biHeight = -abs(imgInfo->bmiHeader.biHeight);
297 }/* CRaster::LoadBMP */
300 /*======================================================================================*/
302 int CRaster::Draw(CDC* pDC)
310 oldPal = pDC->SelectPalette(pal, TRUE);
313 pDC->SetStretchBltMode(COLORONCOLOR);
317 DestWidth, DestHeight,
321 DIB_RGB_COLORS, SRCCOPY);
324 pDC->SelectPalette(oldPal, TRUE);
331 /*======================================================================================*/
332 int CRaster::Draw(CDC* pDC, RECT , RECT)
341 oldPal = pDC->SelectPalette(pal, TRUE);
344 pDC->SetStretchBltMode(COLORONCOLOR);
348 DestWidth, DestHeight,
352 DIB_RGB_COLORS, SRCCOPY);
355 pDC->SelectPalette(oldPal, TRUE);
362 /*======================================================================================*/
364 int CRaster::Draw(CDC* pDC, SIZE dstSize)
373 oldPal = pDC->SelectPalette(pal, TRUE);
376 pDC->SetStretchBltMode(COLORONCOLOR);
378 ::StretchDIBits( hDC,
380 dstSize.cx, dstSize.cy,
382 GetWidth(), GetHeight(),
384 DIB_RGB_COLORS, SRCCOPY);
387 pDC->SelectPalette(oldPal, TRUE);
394 /*======================================================================================*/
396 int CRaster::Draw(CDC* pDC, POINT point,SIZE size)
405 oldPal = pDC->SelectPalette(pal, TRUE);
408 pDC->SetStretchBltMode(COLORONCOLOR);
416 DIB_RGB_COLORS, SRCCOPY);
419 pDC->SelectPalette(oldPal, TRUE);
426 /*======================================================================================*/
428 void CRaster::DeleteAllData()
447 }/* CRaster::DeleteAllData */
450 /*======================================================================================*/
452 unsigned long CRaster::GetWidth()
454 return imgInfo->bmiHeader.biWidth;
455 }/* CRaster::GetWidth */
458 /*======================================================================================*/
460 unsigned long CRaster::GetHeight()
462 return abs(imgInfo->bmiHeader.biHeight);
463 }/* CRaster::GetHeight */
466 /*======================================================================================*/
468 unsigned long CRaster::GetSizeString()
471 }/* CRaster::GetSizeString */
474 /*======================================================================================*/
476 BYTE* CRaster::GetImage()
479 }/* CRaster::GetImage */
482 /*======================================================================================*/
484 int CRaster::GetNumBitPerPixel()
486 return imgInfo->bmiHeader.biBitCount;
487 }/* CRaster::GetNumBitPerPixel */
490 /*======================================================================================*/
492 BITMAPINFO* CRaster::GetBitmapInfo()
495 }/* CRaster::GetBitmapInfo */
498 /*======================================================================================*/