Files
Work/jpgimg/scraps.txt
2024-08-07 09:16:27 -04:00

44 lines
1.6 KiB
Plaintext

bool JPGImage::resample(PureDevice &pureDevice,int newWidth)
{
Array<RGB888> rgbArray;
Array<RGB888> 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<height();row++)::resampleClipRow(&getRGBArray()[(row*width())],&tmpArray[(row*newWidth)],width(),newWidth);
rgbArray.size(bitmapInfo.width()*(bitmapInfo.height()<0?-bitmapInfo.height():bitmapInfo.height()));
for(int col=0;col<bitmapInfo.width();col++)::resampleClipCol(&tmpArray[col],&rgbArray[col],height(),bitmapInfo.width(),bitmapInfo.height()<0?-bitmapInfo.height():bitmapInfo.height(),bitmapInfo.width());
destroy();
getBitmapInfo()=bitmapInfo;
getRGBArray()=rgbArray;
mhBitmap=::CreateDIBitmap((HDC)pureDevice,(BITMAPINFOHEADER*)getBitmapInfo(),CBM_INIT,&getRGBArray()[0],(BITMAPINFO*)getBitmapInfo(),DIB_RGB_COLORS);
// BITMAP bm;
// ::GetObject(mhBitmap,sizeof(BITMAP),&bm);
return true;
}
/*
*/