#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(0); int imageCol; 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_scanline>3)*(LONG)desiredHeight; if(imageExtent==(LONG)desiredWidth*(LONG)desiredHeight)return; else desiredWidth=(WORD)(imageExtent/(LONG)desiredHeight); someBitmapInfo.width(desiredWidth); } bool JPGImage::resample(PureDevice &pureDevice,int newWidth) { Array rgbArray; Array tmpArray; BitmapInfo bitmapInfo; float heightFactor; float aspectRatio; int newHeight; 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)); bitmapInfo.planes(1); bitmapInfo.compression(BI_RGB); bitmapInfo.sizeImage(0); bitmapInfo.colorUsed(0); bitmapInfo.colorImportant(0); verifyDimensions(bitmapInfo); tmpArray.size(bitmapInfo.width()*(height()<0?-height():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); verifyDimensions(bitmapInfo); 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; }