windows stretching code

git-svn-id: svn://10.0.0.236/branches/IMGLIB2_20010126_BRANCH@86803 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pavlov%netscape.com
2001-02-12 05:03:20 +00:00
parent 95d27a4c41
commit 3d4da65ace
4 changed files with 65 additions and 0 deletions

View File

@@ -144,4 +144,17 @@ NS_IMETHODIMP nsImageContainer::DrawImage(HDC aDestDC, const nsRect * aSrcRect,
return rv;
return NS_REINTERPRET_CAST(nsImageFrame*, img.get())->DrawImage(aDestDC, aSrcRect, aDestPoint);
}
NS_IMETHODIMP nsImageContainer::DrawScaledImage(HDC aDestDC, const nsRect * aSrcRect, const nsRect * aDestRect)
{
nsresult rv;
nsCOMPtr<nsIImageFrame> img;
rv = this->GetCurrentFrame(getter_AddRefs(img));
if (NS_FAILED(rv))
return rv;
return NS_REINTERPRET_CAST(nsImageFrame*, img.get())->DrawScaledImage(aDestDC, aSrcRect, aDestRect);
}

View File

@@ -23,6 +23,8 @@
#include "nsImageFrame.h"
#include "nsTransform2D.h"
NS_IMPL_ISUPPORTS1(nsImageFrame, nsIImageFrame)
@@ -428,3 +430,51 @@ nsresult nsImageFrame::DrawImage(HDC aDestDC, const nsRect * aSrcRect, const nsP
}
nsresult nsImageFrame::DrawScaledImage(HDC aDestDC, const nsRect * aSrcRect, const nsRect * aDestRect)
{
LPBITMAPINFOHEADER mBHead = (LPBITMAPINFOHEADER)new char[sizeof(BITMAPINFO)];
nsTransform2D trans;
trans.SetToScale((float(mRect.width) / float(aDestRect->width)), (float(mRect.height) / float(aDestRect->height)));
nsRect source(*aSrcRect);
nsRect dest(*aDestRect);
trans.TransformCoord(&source.x, &source.y, &source.width, &source.height);
// trans.TransformCoord(&dest.x, &dest.y, &dest.width, &dest.height);
mBHead->biSize = sizeof(BITMAPINFOHEADER);
mBHead->biWidth = mRect.width;
mBHead->biHeight = -source.height;
mBHead->biPlanes = 1;
mBHead->biBitCount = 24;
mBHead->biCompression = BI_RGB;
mBHead->biSizeImage = mImageData.length;
mBHead->biXPelsPerMeter = 0;
mBHead->biYPelsPerMeter = 0;
mBHead->biClrUsed = 0;
mBHead->biClrImportant = 0;
int rop = SRCCOPY;
if (mAlphaData && mAlphaData->depth == 1) {
MONOBITMAPINFO bmi(mRect.width, -source.height);
bmi.bmiHeader.biSizeImage = mAlphaData->length;
::StretchDIBits(aDestDC, (aDestRect->x + aSrcRect->x), (aDestRect->y + aSrcRect->y), dest.width, dest.height,
source.x, 0, mRect.width, source.height,
mAlphaData->data + (source.y * mAlphaData->bytesPerRow),
(LPBITMAPINFO)&bmi, DIB_RGB_COLORS, SRCAND);
rop = SRCPAINT;
}
::StretchDIBits(aDestDC, (aDestRect->x + aSrcRect->x), (aDestRect->y + aSrcRect->y), dest.width, dest.height,
source.x, 0, mRect.width, source.height,
mImageData.data + (source.y * mImageData.bytesPerRow),
(LPBITMAPINFO)mBHead, DIB_RGB_COLORS, rop);
delete[] mBHead;
return NS_OK;
}

View File

@@ -61,6 +61,7 @@ public:
nsresult DrawImage(HDC aDestDC, const nsRect * aSrcRect, const nsPoint * aDestPoint);
nsresult DrawScaledImage(HDC aDestDC, const nsRect * aSrcRect, const nsRect * aDestRect);
private:

View File

@@ -46,4 +46,5 @@ interface nsPIImageContainerWin : nsISupports
/**
*/
void drawImage(in HDC aDestDC, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint);
void drawScaledImage(in HDC aDestDC, [const] in nsRect aSrcRect, [const] in nsRect aDestRect);
};