void IHDRParse(struct XPng* xpng, struct XBitmap* xbitmap, const unsigned char* stream,const char* bmpFileName) { int pixelFormat; xpng->m_header.width= BYTE_TO_INT(stream); xpng->m_header.height = BYTE_TO_INT(stream+4); xpng->m_header.bitDepth = BYTE_TO_CHAR(stream+8); xpng->m_header.colorType = BYTE_TO_CHAR(stream+9); xpng->m_header.compressionMethod = BYTE_TO_CHAR(stream+10); xpng->m_header.filterMode = BYTE_TO_CHAR(stream+11); xpng->m_header.interlaceMethod = BYTE_TO_CHAR(stream+12); printf("HEAD parsing %d %d %02x %02x %02x %02x %02x\n", xpng->m_header.width,xpng->m_header.height, xpng->m_header.bitDepth,xpng->m_header.colorType, xpng->m_header.compressionMethod,xpng->m_header.filterMode, xpng->m_header.interlaceMethod); xpng->m_ColorMapTablePos = 0; xpng->m_bPaletted = false; if(xpng->m_header.colorType==COLORTYPE_COLOR_ALPHA) { xpng->m_ColorMapTableCur = colorMapTable_RGBA_2_BGRA; xpng->m_ColorMapTableLen = sizeof(colorMapTable_RGBA_2_BGRA) / sizeof(colorMapTable_RGBA_2_BGRA[0]); // 결국은 4 pixelFormat = PIXELFORMAT_32; } else if(xpng->m_header.colorType==COLORTYPE_COLOR) { xpng->m_ColorMapTableCur = colorMapTable_RGB_2_BGR; xpng->m_ColorMapTableLen = sizeof(colorMapTable_RGB_2_BGR) / sizeof(colorMapTable_RGB_2_BGR[0]); // 결국은 3 pixelFormat = PIXELFORMAT_24; } else if(xpng->m_header.colorType==COLORTYPE_COLOR_PAL) { // 빨레트를 쓴다. ALPHA 는 없다. 그래서 RGB 2 BGR 사용 xpng->m_ColorMapTableCur = colorMapTable_RGB_2_BGR; xpng->m_ColorMapTableLen = sizeof(colorMapTable_RGB_2_BGR) / sizeof(colorMapTable_RGB_2_BGR[0]); // 결국은 3 xpng->m_bPaletted = true; pixelFormat = PIXELFORMAT_32; } else { } CreateDib(xbitmap, xpng->m_header.width, xpng->m_header.height, pixelFormat); SetDecodeData(xpng, xbitmap->m_pixel, xbitmap->m_stride, xbitmap->m_paddingByte, xbitmap->m_pixelFormat / 8); // BMP Header 생성 MakeBMPHeader(xbitmap, bmpFileName); }
void CDib::CreateCompatibleDIB( CDC& dc, int width, int height ) { Empty(); CreateDib( CSize (width,height), dc.GetDeviceCaps( BITSPIXEL ) ); if( IsIndexed() ) { if( dc.GetCurrentPalette() ) SetPalette( *(dc.GetCurrentPalette()) ); else CreateDefaultPalette(); } }
/*BOOL CDib::SetBitmap(CBitmap* pBitmap, CPalette& palette) { BITMAP bm; pBitmap->GetBitmap(&bm); CSize size(bm.bmWidth, bm.bmHeight); CreateDib(size, bm.bmBitsPixel); SetPalette(palette); CreateSection(); //SetPalette(*pDC->GetCurrentPalette()); //CreateSection(pDC); ASSERT(m_lpImage); return GetDIBits( NULL, // handle to device context (HBITMAP)(*pBitmap), // handle to bitmap 0, // first scan line to set in destination bitmap bm.bmHeight, // number of scan lines to copy m_lpImage, // address of array for bitmap bits (BITMAPINFO*)m_lpBMIH, // address of structure with bitmap data DIB_RGB_COLORS) == bm.bmHeight; // RGB or palette index //return pBitmap->GetBitmapBits(m_dwSizeImage, m_lpImage) != 0; } */ BOOL CDib::SetBitmap(CDC& dc) { BOOL bRep = false; if( dc.GetCurrentBitmap() ) { CDC memDC; memDC.CreateCompatibleDC(&dc); bRep = true; CBitmap& bitmap = *dc.GetCurrentBitmap(); //bitmap.FromHandle(hBitmap); BITMAP bm; bitmap.GetBitmap(&bm); CSize size(bm.bmWidth, bm.bmHeight); CreateDib(size, bm.bmBitsPixel); if( IsIndexed() ) { if( dc.GetCurrentPalette() ) { SetPalette(*dc.GetCurrentPalette()); memDC.SelectPalette(dc.GetCurrentPalette(), false); } } memDC.SelectObject( (HBITMAP)*this); memDC.BitBlt( 0,0, size.cx, size.cy, &dc, 0,0, SRCCOPY); //HBITMAP hBitmap = dc.SelectObject( (HBITMAP)*this ); //bitmap.GetBitmapBits() /*for(int i=0; i<size.cx; i++) { for(int j=0; j<size.cy; j++) { SetPixel(i,j, dc.GetPixel(i, j) ); } } */ } return bRep; }
/************************************************************************* * * CopyScreenToBitmap() * * Parameter: * * LPRECT lpRect - specifies the window * * Return Value: * * HDIB - identifies the device-dependent bitmap * * Description: * * This function copies the specified part of the screen to a device- * dependent bitmap. * * ************************************************************************/ void CDib::CopyFromScreen(const CRect& rectIn) { // check for an empty rectangle if (rectIn.IsRectEmpty()) { Empty(); return; } CDC ScrDC; CDC MemDC; // create a DC for the screen and create // a memory DC compatible to screen DC ScrDC.CreateDCW(L"DISPLAY", NULL, NULL, NULL); MemDC.CreateCompatibleDC(&ScrDC); // get screen resolution int xScrn = ScrDC.GetDeviceCaps(HORZRES); int yScrn = ScrDC.GetDeviceCaps(VERTRES); CRect rect(rectIn); rect.NormalizeRect(); //make sure bitmap rectangle is visible if (rect.left < 0) rect.left = 0; if (rect.top < 0) rect.top = 0; if (rect.right > xScrn) rect.right = xScrn; if (rect.bottom> yScrn) rect.bottom = yScrn; // create a bitmap compatible with the screen DC CreateDib( CSize(rect.Width(), rect.Height()), 32); CBitmap* pBitmap = CBitmap::FromHandle( (HBITMAP)(*this)); //pBitmap->GetBitmap(&bmp); //ASSERT(false); //HBITMAP hBitmap = NULL;//C reateCompatibleDIB( ScrDC, rect.Width(), rect.Height()); // select new bitmap into memory DC CBitmap* pOldBitmap = MemDC.SelectObject(pBitmap); //HBITMAP hOldBitmap = (HBITMAP)MemDC.SelectObject((hBitmap); // bitblt screen DC to memory DC MemDC.BitBlt(0, 0, rect.Width(), rect.Height(), &ScrDC, rect.left, rect.top, SRCCOPY); //CreatePaletteFromImage(m_palette); // select old bitmap back into memory DC and get handle to // bitmap of the screen //hBitmap = (HBITMAP)MemDC.SelectObject(hOldBitmap); MemDC.SelectObject(pOldBitmap); // clean up ScrDC.DeleteDC(); MemDC.DeleteDC(); }
CDib::CDib(CSize size, int nBitCount) { CreateDib(size, nBitCount); }
CDib::CDib(int width, int height, int nBitCount) { CreateDib(CSize( width, height), nBitCount); }