#include #include #include #include #include #include bool JPGImage::draw(PureDevice &pureDevice) { PureDevice compatibleDevice; if(!isOkay())return FALSE; compatibleDevice.compatibleDevice(pureDevice); compatibleDevice.select((GDIObj)mhBitmap,TRUE); pureDevice.bitBlt(Rect(0,0,width(),height()),compatibleDevice,Point(0,0)); compatibleDevice.select((GDIObj)mhBitmap,FALSE); return TRUE; } bool JPGImage::draw(PureDevice &pureDevice,int xSrc,int ySrc) { PureDevice compatibleDevice; if(!isOkay())return FALSE; compatibleDevice.compatibleDevice(pureDevice); compatibleDevice.select((GDIObj)mhBitmap,TRUE); pureDevice.bitBlt(Rect(xSrc,ySrc,width(),height()),compatibleDevice,Point(0,0)); compatibleDevice.select((GDIObj)mhBitmap,FALSE); return TRUE; } bool JPGImage::draw(PureDevice &pureDevice,const Rect &dstRect,const Point &srcPoint) { PureDevice compatibleDevice; if(!isOkay())return FALSE; compatibleDevice.compatibleDevice(pureDevice); compatibleDevice.select((GDIObj)mhBitmap,TRUE); pureDevice.bitBlt(dstRect,compatibleDevice,srcPoint); compatibleDevice.select((GDIObj)mhBitmap,FALSE); return TRUE; } bool JPGImage::stretch(PureDevice &pureDevice,const Point &xyPoint,int strwidth,int strheight) { PureDevice compatibleDevice; if(!isOkay())return FALSE; compatibleDevice.compatibleDevice(pureDevice); compatibleDevice.select((GDIObj)mhBitmap,TRUE); pureDevice.stretchBlt(Rect(xyPoint.x(),xyPoint.y(),strwidth,strheight),compatibleDevice,Rect(0,0,width(),height())); compatibleDevice.select((GDIObj)mhBitmap,FALSE); return FALSE; } bool JPGImage::decode(const String &strPathFileName,PureDevice &pureDevice) { JSAMPARRAY buffer; int row_stride; int row_elements; int row(0); jpeg_decompress_struct cinfo; FILE *fp; destroy(); if((fp=::fopen((char*)(String&)strPathFileName,"rb"))==NULL)return FALSE; ::jpeg_create_decompress(&cinfo); ::jpeg_stdio_src(&cinfo,fp); try{::jpeg_read_header(&cinfo,TRUE);} catch(JPGError){return FALSE;} try{::jpeg_start_decompress(&cinfo);} catch(JPGError){return FALSE;} row_stride=cinfo.output_width*cinfo.output_components; buffer=(*cinfo.mem->alloc_sarray)((j_common_ptr)&cinfo,JPOOL_IMAGE,row_stride,cinfo.output_height); while(cinfo.output_scanlinealloc_sarray)((j_common_ptr)&cinfo,JPOOL_IMAGE,row_stride,cinfo.output_height); while(cinfo.output_scanline &rgbArray=getRGBArray(); Array tmpArray; tmpArray.size(rgbArray.size()); bmInfo.height(-bmInfo.height()); for(int row=0;row rgbArray; Array tmpArray; BitmapInfo bitmapInfo; float heightFactor; float aspectRatio; int newHeight; newWidth-=(newWidth%4); // align the width on DWORD boundary if(!isOkay())return false; aspectRatio=(float)width()/(float)height(); newHeight=(float)newWidth/aspectRatio; heightFactor=(float)newHeight/height(); bitmapInfo.rgbColors(0); bitmapInfo.bitCount(BitmapInfo::Bit24); bitmapInfo.width(newWidth); bitmapInfo.height(int((float)getBitmapInfo().height()*heightFactor)); if(bitmapInfo.height()<0)bitmapInfo.height(-newHeight); else bitmapInfo.height(newHeight); bitmapInfo.planes(1); bitmapInfo.compression(BI_RGB); bitmapInfo.sizeImage(0); bitmapInfo.colorUsed(0); bitmapInfo.colorImportant(0); tmpArray.size(bitmapInfo.width()*height()); for(int row=0;row rgbArray; Array tmpArray; BitmapInfo bitmapInfo; if(!isOkay())return false; bitmapInfo.rgbColors(0); bitmapInfo.bitCount(BitmapInfo::Bit24); bitmapInfo.width(newWidth); bitmapInfo.height(-newHeight); bitmapInfo.planes(1); bitmapInfo.compression(BI_RGB); bitmapInfo.sizeImage(0); bitmapInfo.colorUsed(0); bitmapInfo.colorImportant(0); bitmapInfo.verifyDimensions(); tmpArray.size(bitmapInfo.width()*(height()<0?-height():height())); for(int row=0;row rgbArray; Array tmpArray; BitmapInfo bitmapInfo; if(!getRGBArray().size())return false; bitmapInfo.rgbColors(0); bitmapInfo.bitCount(BitmapInfo::Bit24); bitmapInfo.width(newWidth); bitmapInfo.height(-newHeight); bitmapInfo.planes(1); bitmapInfo.compression(BI_RGB); bitmapInfo.sizeImage(0); bitmapInfo.colorUsed(0); bitmapInfo.colorImportant(0); bitmapInfo.verifyDimensions(); tmpArray.size(bitmapInfo.width()*(height()<0?-height():height())); for(int row=0;row &rawData) { return RawImage::getRawData(rawData); } bool JPGImage::setRawData(GlobalData &rawData,PureDevice &pureDevice) { destroy(); if(!RawImage::setRawData(rawData))return false; mhBitmap=::CreateDIBitmap((HDC)pureDevice,(BITMAPINFOHEADER*)getBitmapInfo(),CBM_INIT,&getRGBArray()[0],(BITMAPINFO*)getBitmapInfo(),DIB_RGB_COLORS); return true; } bool JPGImage::rotateLeft(PureDevice &pureDevice) { Array rgbArray; RawImage rawImage; RGB888 rgb888; if(!isOkay())return false; rawImage.getBitmapInfo().rgbColors(0); rawImage.getBitmapInfo().bitCount(BitmapInfo::Bit24); rawImage.getBitmapInfo().width(getBitmapInfo().height()<0?-getBitmapInfo().height():getBitmapInfo().height()); rawImage.getBitmapInfo().height(getBitmapInfo().height()<0?-getBitmapInfo().width():getBitmapInfo().width()); rawImage.getBitmapInfo().planes(1); rawImage.getBitmapInfo().compression(BI_RGB); rawImage.getBitmapInfo().sizeImage(0); rawImage.getBitmapInfo().colorUsed(0); rawImage.getBitmapInfo().colorImportant(0); rawImage.getBitmapInfo().verifyDimensions(); rawImage.getRGBArray().size(rawImage.width()*rawImage.height()); for(int rowIndex=0;rowIndex<(height()<0?-height():height());rowIndex++) { for(int colIndex=0;colIndex rgbArray; RawImage rawImage; RGB888 rgb888; if(!isOkay())return false; rawImage.getBitmapInfo().rgbColors(0); rawImage.getBitmapInfo().bitCount(BitmapInfo::Bit24); rawImage.getBitmapInfo().width(getBitmapInfo().height()<0?-getBitmapInfo().height():getBitmapInfo().height()); rawImage.getBitmapInfo().height(getBitmapInfo().height()<0?-getBitmapInfo().width():getBitmapInfo().width()); rawImage.getBitmapInfo().planes(1); rawImage.getBitmapInfo().compression(BI_RGB); rawImage.getBitmapInfo().sizeImage(0); rawImage.getBitmapInfo().colorUsed(0); rawImage.getBitmapInfo().colorImportant(0); rawImage.getBitmapInfo().verifyDimensions(); rawImage.getRGBArray().size(rawImage.width()*rawImage.height()); for(int rowIndex=0;rowIndex<(height()<0?-height():height());rowIndex++) { for(int colIndex=0;colIndex