mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
fixed some bugs, intermediate checkin
This commit is contained in:
parent
14b98d4773
commit
052bbf9a8c
@ -36,9 +36,16 @@ class nsIBlender : public nsISupports
|
||||
public:
|
||||
/**
|
||||
* Initialize the Blender
|
||||
* @param aSrc is the source drawing image to buffer
|
||||
* @param aDst is the dest drawing image to buffer
|
||||
* @result The result of the initialization, NS_OK if no errors
|
||||
*/
|
||||
virtual nsresult Init() = 0;
|
||||
virtual nsresult Init(nsDrawingSurface aSrc,nsDrawingSurface aDst) = 0;
|
||||
|
||||
/**
|
||||
* Clean up the intialization stuff
|
||||
*/
|
||||
virtual void CleanUp() = 0;
|
||||
|
||||
/**
|
||||
* NOTE: if we can make this static, that would be great. I don't think we can.
|
||||
|
@ -42,10 +42,53 @@ NS_IMPL_ISUPPORTS(nsBlenderWin, kIBlenderIID);
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsresult
|
||||
nsBlenderWin::Init()
|
||||
nsBlenderWin::Init(nsDrawingSurface aSrc,nsDrawingSurface aDst)
|
||||
{
|
||||
PRInt32 numbytes;
|
||||
HDC srcdc,dstdc;
|
||||
HBITMAP srcbits,dstbits;
|
||||
|
||||
// lets build some DIB's for the source and destination from the HDC's
|
||||
srcdc = (HDC)aSrc;
|
||||
dstdc = (HDC)aDst;
|
||||
|
||||
// source
|
||||
mTempB1 = CreateCompatibleBitmap(srcdc,3,3);
|
||||
srcbits = ::SelectObject(srcdc, mTempB1);
|
||||
numbytes = ::GetObject(srcbits,sizeof(BITMAP),&mSrcInfo);
|
||||
BuildDIB(&mSrcbinfo,&mSrcBytes,mSrcInfo.bmWidth,mSrcInfo.bmHeight,mSrcInfo.bmBitsPixel);
|
||||
numbytes = ::GetDIBits(srcdc,srcbits,0,mSrcInfo.bmHeight,mSrcBytes,(LPBITMAPINFO)mSrcbinfo,DIB_RGB_COLORS);
|
||||
|
||||
if(numbytes > 0)
|
||||
{
|
||||
// destination
|
||||
mTempB2 = CreateCompatibleBitmap(dstdc,3,3);
|
||||
dstbits = ::SelectObject(dstdc, mTempB2);
|
||||
::GetObject(dstbits,sizeof(BITMAP),&mDstInfo);
|
||||
BuildDIB(&mDstbinfo,&mDstBytes,mDstInfo.bmWidth,mDstInfo.bmHeight,mDstInfo.bmBitsPixel);
|
||||
numbytes = ::GetDIBits(dstdc,dstbits,0,mDstInfo.bmHeight,mDstBytes,(LPBITMAPINFO)mDstbinfo,DIB_RGB_COLORS);
|
||||
|
||||
// put the old stuff back
|
||||
::SelectObject(srcdc,srcbits);
|
||||
::SelectObject(dstdc,dstbits);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
void
|
||||
nsBlenderWin::CleanUp()
|
||||
{
|
||||
|
||||
return NS_OK;
|
||||
::DeleteObject(mTempB1);
|
||||
::DeleteObject(mTempB2);
|
||||
|
||||
|
||||
// get rid of the DIB's
|
||||
DeleteDIB(&mSrcbinfo,&mSrcBytes);
|
||||
DeleteDIB(&mDstbinfo,&mDstBytes);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
@ -54,52 +97,24 @@ void
|
||||
nsBlenderWin::Blend(nsDrawingSurface aSrc,PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
nsDrawingSurface aDst, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity)
|
||||
{
|
||||
HDC srcdc,dstdc;
|
||||
HBITMAP srcbits,dstbits,tb1,tb2;
|
||||
BITMAP srcinfo,dstinfo;
|
||||
HDC dstdc,tb1;
|
||||
HBITMAP dstbits;
|
||||
nsPoint srcloc,maskloc;
|
||||
PRInt32 dlinespan,slinespan,mlinespan,numbytes,numlines,level;
|
||||
PRUint8 *s1,*d1,*m1,*srcbytes,*dstbytes;
|
||||
LPBITMAPINFOHEADER srcbinfo,dstbinfo;
|
||||
PRUint8 *mask=NULL;
|
||||
PRUint8 *s1,*d1,*m1,*mask=NULL;
|
||||
nsColorMap *colormap;
|
||||
|
||||
// we have to extract the bitmaps from the nsDrawingSurface, which in this case is a hdc
|
||||
srcdc = (HDC)aSrc;
|
||||
dstdc = (HDC)aDst;
|
||||
|
||||
// we use this bitmap to select into the HDC's while we work on the ones they give us
|
||||
tb1 = CreateCompatibleBitmap(aSrc,3,3);
|
||||
|
||||
// get the HBITMAP, and then grab the information about the source bitmap and bits
|
||||
srcbits = ::SelectObject(srcdc, tb1);
|
||||
numbytes = ::GetObject(srcbits,sizeof(BITMAP),&srcinfo);
|
||||
// put into a DIB
|
||||
BuildDIB(&srcbinfo,&srcbytes,srcinfo.bmWidth,srcinfo.bmHeight,srcinfo.bmBitsPixel);
|
||||
|
||||
if(srcinfo.bmBitsPixel != 24)
|
||||
numbytes = ::GetDIBits(srcdc,srcbits,1,srcinfo.bmHeight,srcbytes,(LPBITMAPINFO)srcbinfo,DIB_PAL_COLORS);
|
||||
else
|
||||
numbytes = ::GetDIBits(srcdc,srcbits,1,srcinfo.bmHeight,srcbytes,(LPBITMAPINFO)srcbinfo,DIB_RGB_COLORS);
|
||||
|
||||
// get the HBITMAP, and then grab the information about the destination bitmap
|
||||
tb2 = CreateCompatibleBitmap(aSrc,3,3);
|
||||
dstbits = ::SelectObject(dstdc, tb2);
|
||||
::GetObject(dstbits,sizeof(BITMAP),&dstinfo);
|
||||
// put into a DIB
|
||||
BuildDIB(&dstbinfo,&dstbytes,dstinfo.bmWidth,dstinfo.bmHeight,dstinfo.bmBitsPixel);
|
||||
numbytes = ::GetDIBits(dstdc,dstbits,1,dstinfo.bmHeight,dstbytes,(LPBITMAPINFO)dstbinfo,DIB_RGB_COLORS);
|
||||
|
||||
// calculate the metrics, no mask right now
|
||||
srcloc.x = aSX;
|
||||
srcloc.y = aSY;
|
||||
srcinfo.bmBits = srcbytes;
|
||||
dstinfo.bmBits = dstbytes;
|
||||
if(CalcAlphaMetrics(&srcinfo,&dstinfo,&srcloc,NULL,&maskloc,&numlines,&numbytes,
|
||||
mSrcInfo.bmBits = mSrcBytes;
|
||||
mDstInfo.bmBits = mDstBytes;
|
||||
if(CalcAlphaMetrics(&mSrcInfo,&mDstInfo,&srcloc,NULL,&maskloc,&numlines,&numbytes,
|
||||
&s1,&d1,&m1,&slinespan,&dlinespan,&mlinespan))
|
||||
{
|
||||
// now do the blend
|
||||
if ((srcinfo.bmBitsPixel==24) && (dstinfo.bmBitsPixel==24))
|
||||
if ((mSrcInfo.bmBitsPixel==24) && (mDstInfo.bmBitsPixel==24))
|
||||
{
|
||||
if(mask)
|
||||
{
|
||||
@ -113,7 +128,7 @@ nsColorMap *colormap;
|
||||
}
|
||||
}
|
||||
else
|
||||
if ((srcinfo.bmBitsPixel==8) && (dstinfo.bmBitsPixel==8))
|
||||
if ((mSrcInfo.bmBitsPixel==8) && (mDstInfo.bmBitsPixel==8))
|
||||
{
|
||||
if(mask)
|
||||
{
|
||||
@ -126,22 +141,13 @@ nsColorMap *colormap;
|
||||
}
|
||||
}
|
||||
|
||||
// put the new bits in
|
||||
dstdc = (HDC)aDst;
|
||||
dstbits = ::CreateDIBitmap(dstdc, mDstbinfo, CBM_INIT, mDstBytes, (LPBITMAPINFO)mDstbinfo, DIB_RGB_COLORS);
|
||||
tb1 = ::SelectObject(dstdc,dstbits);
|
||||
::DeleteObject(tb1);
|
||||
}
|
||||
|
||||
// put the new bits in
|
||||
::DeleteObject(dstbits);
|
||||
dstbits = ::CreateDIBitmap(dstdc, dstbinfo, CBM_INIT, dstbytes, (LPBITMAPINFO)dstbinfo, DIB_RGB_COLORS);
|
||||
|
||||
|
||||
::SelectObject(srcdc,srcbits);
|
||||
::SelectObject(dstdc,dstbits);
|
||||
|
||||
::DeleteObject(tb1);
|
||||
::DeleteObject(tb2);
|
||||
|
||||
// get rid of the DIB's
|
||||
DeleteDIB(&srcbinfo,&srcbytes);
|
||||
DeleteDIB(&dstbinfo,&dstbytes);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
@ -249,6 +255,7 @@ PRUint8 *colortable;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (numpalletcolors >= 0)
|
||||
{
|
||||
(*aBHead) = (LPBITMAPINFOHEADER) new char[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * numpalletcolors];
|
||||
|
@ -29,6 +29,8 @@
|
||||
// Blender interface
|
||||
class nsBlenderWin : public nsIBlender
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
@ -36,17 +38,14 @@ public:
|
||||
nsBlenderWin();
|
||||
~nsBlenderWin();
|
||||
|
||||
/**
|
||||
* Initialize the Blender
|
||||
* @result The result of the initialization, NS_OK if no errors
|
||||
*/
|
||||
virtual nsresult Init();
|
||||
|
||||
virtual nsresult Init(nsDrawingSurface aSrc,nsDrawingSurface aDst);
|
||||
virtual void CleanUp();
|
||||
virtual void Blend(nsDrawingSurface aSrc,
|
||||
PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
nsDrawingSurface aDest, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity);
|
||||
|
||||
PRBool CalcAlphaMetrics(BITMAP *aSrcInfo,BITMAP *aDestInfo,nsPoint *ASrcUL,
|
||||
private:
|
||||
PRBool CalcAlphaMetrics(BITMAP *aSrcInfo,BITMAP *aDestInfo,nsPoint *ASrcUL,
|
||||
BITMAP *aMapInfo,nsPoint *aMaskUL,
|
||||
PRInt32 *aNumlines,
|
||||
PRInt32 *aNumbytes,PRUint8 **aSImage,PRUint8 **aDImage,
|
||||
@ -54,7 +53,6 @@ public:
|
||||
|
||||
PRInt32 CalcBytesSpan(PRUint32 aWidth,PRUint32 aBitsPixel);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Create a DIB header and bits for a bitmap
|
||||
* @param aBHead information header for the DIB
|
||||
@ -133,6 +131,13 @@ private:
|
||||
void Do8Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,
|
||||
PRInt32 aSLSpan,PRInt32 aDLSpan,nsColorMap *aColorMap,nsBlendQuality aBlendQuality);
|
||||
|
||||
|
||||
private:
|
||||
LPBITMAPINFOHEADER mDstbinfo,mSrcbinfo;
|
||||
PRUint8 *mSrcBytes,*mDstBytes;
|
||||
BITMAP mSrcInfo,mDstInfo;
|
||||
HBITMAP mTempB1,mTempB2;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -69,12 +69,7 @@ static nsITextWidget *gBlendMessage;
|
||||
static nsITextWidget *gQualMessage;
|
||||
|
||||
|
||||
#ifdef OLDWAY
|
||||
extern void Compositetest(PRInt32 aTestNum,nsIImage *aImage,nsIImage *aBImage,nsIImage *aMImage, PRInt32 aX, PRInt32 aY);
|
||||
#else
|
||||
extern void Compositetest(nsIImage *aImage,PRInt32 aTestNum,HDC aSrcDC,HDC aDestDC);
|
||||
#endif
|
||||
|
||||
extern PRInt32 speedtest(nsIImage *aTheImage,nsIRenderingContext *aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
extern PRInt32 drawtest(nsIRenderingContext *aSurface);
|
||||
extern PRInt32 filltest(nsIRenderingContext *aSurface);
|
||||
@ -149,10 +144,6 @@ MyBlendObserver::Notify(nsIImageRequest *aImageRequest,
|
||||
{
|
||||
nsColorMap *cmap = (*mImage)->GetColorMap();
|
||||
nsRect *rect = (nsRect *)aParam3;
|
||||
#ifdef OLDWAY
|
||||
Compositetest(gTestNum,gImage,gBlendImage,gMaskImage,gXOff,gYOff);
|
||||
#else
|
||||
{
|
||||
HBITMAP dobits,sobits,srcbits,destbits;
|
||||
HDC destdc,srcdc,screendc;
|
||||
void *bits1,*bits2;
|
||||
@ -180,9 +171,6 @@ MyBlendObserver::Notify(nsIImageRequest *aImageRequest,
|
||||
DeleteObject(srcbits);
|
||||
DeleteObject(destbits);
|
||||
ReleaseDC(gHwnd,screendc);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -462,17 +450,18 @@ nsString str;
|
||||
}
|
||||
#else
|
||||
void
|
||||
Compositetest(nsIImage *aImage,PRInt32 aTestNum,HDC aSrcHDC,HDC DestHDC)
|
||||
Compositetest(nsIImage *aImage,PRInt32 aTestNum,HDC aSrcHDC,HDC aDstHDC)
|
||||
{
|
||||
PRUint8 *thebytes,*curbyte,*srcbytes,*cursourcebytes;
|
||||
PRInt32 w,h,ls,x,y,numbytes,sls,numerror;
|
||||
float blendamount;
|
||||
nsIBlender *imageblender;
|
||||
nsresult rv;
|
||||
HBITMAP srcbits,tb1;
|
||||
BITMAP srcinfo;
|
||||
PRUint8 *thebytes,*curbyte,*srcbytes,*cursourcebytes;
|
||||
PRInt32 w,h,ls,x,y,numbytes,sls,numerror;
|
||||
float blendamount;
|
||||
nsIBlender *imageblender;
|
||||
nsresult rv;
|
||||
HBITMAP srcbits,tb1;
|
||||
BITMAP srcinfo;
|
||||
LPBITMAPINFOHEADER srcbinfo;
|
||||
nsString str;
|
||||
nsString str;
|
||||
nsIRenderingContext *drawCtx = gWindow->GetRenderingContext();
|
||||
|
||||
static NS_DEFINE_IID(kBlenderCID, NS_BLENDER_CID);
|
||||
static NS_DEFINE_IID(kBlenderIID, NS_IBLENDER_IID);
|
||||
@ -485,18 +474,20 @@ nsString str;
|
||||
blendamount = 1.0f;
|
||||
|
||||
rv = NSRepository::CreateInstance(kBlenderCID, nsnull, kBlenderIID, (void **)&imageblender);
|
||||
imageblender->Init();
|
||||
imageblender->Blend(nsDrawingSurface (aSrcHDC),0,0,0,0,(DestHDC),0, 0,blendamount);
|
||||
imageblender->Init(aSrcHDC,aDstHDC);
|
||||
imageblender->Blend(aSrcHDC,0,0,0,0,aDstHDC,0, 0,blendamount);
|
||||
imageblender->CleanUp();
|
||||
|
||||
|
||||
// this takes the Destination DC and copies the information into aImage
|
||||
tb1 = CreateCompatibleBitmap(DestHDC,3,3);
|
||||
srcbits = ::SelectObject(DestHDC, tb1);
|
||||
tb1 = CreateCompatibleBitmap(aDstHDC,3,3);
|
||||
srcbits = ::SelectObject(aDstHDC, tb1);
|
||||
numbytes = ::GetObject(srcbits,sizeof(BITMAP),&srcinfo);
|
||||
// put into a DIB
|
||||
BuildDIB(&srcbinfo,&srcbytes,srcinfo.bmWidth,srcinfo.bmHeight,srcinfo.bmBitsPixel);
|
||||
numbytes = ::GetDIBits(DestHDC,srcbits,1,srcinfo.bmHeight,srcbytes,(LPBITMAPINFO)srcbinfo,DIB_RGB_COLORS);
|
||||
numbytes = ::GetDIBits(aDstHDC,srcbits,0,srcinfo.bmHeight,srcbytes,(LPBITMAPINFO)srcbinfo,DIB_RGB_COLORS);
|
||||
|
||||
// copy the information back into the source
|
||||
thebytes = aImage->GetBits();
|
||||
h = aImage->GetHeight();
|
||||
w = aImage->GetWidth();
|
||||
@ -512,9 +503,9 @@ nsString str;
|
||||
curbyte++;
|
||||
cursourcebytes++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
drawCtx->DrawImage(aImage, 0, 0, aImage->GetWidth(), aImage->GetHeight());
|
||||
}
|
||||
#endif
|
||||
//------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user