mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
updated the blending, fixed 8 bit blending, and fixed a leak in the blender
This commit is contained in:
parent
c970b74647
commit
3c44a29c2c
@ -33,25 +33,19 @@ nsBlender :: nsBlender()
|
||||
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
* Initialize a nsBlender object, or re-initialize if it is re-used
|
||||
* @update dc - 10/29/98
|
||||
* @param aSrc -- source drawing surface
|
||||
* @param aDst -- destination drawing surface
|
||||
* @result NS_OK if everything initialized
|
||||
*/
|
||||
nsBlender :: ~nsBlender()
|
||||
nsBlender::~nsBlender()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsBlender, kIBlenderIID);
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsresult
|
||||
nsBlender::Init(nsDrawingSurface aSrc, nsDrawingSurface aDst)
|
||||
nsBlender::Init(nsIDeviceContext *aTheDevCon)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
@ -508,7 +502,7 @@ extern void inv_colormap(PRInt16 colors,PRUint8 *aCMap,PRInt16 bits,PRUint32 *di
|
||||
* @param aSaveBlendArea informs routine if the area affected area will be save first
|
||||
*/
|
||||
void
|
||||
nsBlender::Do8Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsColorMap *aColorMap,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea)
|
||||
nsBlender::Do8Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRInt32 aSLSpan,PRInt32 aDLSpan,IL_ColorSpace *aColorMap,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea)
|
||||
{
|
||||
PRUint32 r,g,b,r1,g1,b1,i;
|
||||
PRUint8 *d1,*d2,*s1,*s2;
|
||||
@ -516,26 +510,48 @@ PRInt32 x,y,val1,val2,numlines,xinc,yinc;;
|
||||
PRUint8 *mapptr,*invermap;
|
||||
PRUint32 *distbuffer;
|
||||
PRUint32 quantlevel,tnum,num,shiftnum;
|
||||
NI_RGB *map;
|
||||
|
||||
aBlendVal = (aBlendVal*255)/100;
|
||||
val2 = aBlendVal;
|
||||
val1 = 255-val2;
|
||||
|
||||
// calculate the inverse map
|
||||
mapptr = aColorMap->Index;
|
||||
// build a colormap we can use to get an inverse map
|
||||
map = aColorMap->cmap.map+10;
|
||||
mapptr = new PRUint8[256*3];
|
||||
invermap = mapptr;
|
||||
for(i=0;i<216;i++){
|
||||
*invermap=map->red;
|
||||
invermap++;
|
||||
*invermap=map->green;
|
||||
invermap++;
|
||||
*invermap=map->blue;
|
||||
invermap++;
|
||||
map++;
|
||||
}
|
||||
for(i=216;i<256;i++){
|
||||
*invermap=255;
|
||||
invermap++;
|
||||
*invermap=255;
|
||||
invermap++;
|
||||
*invermap=255;
|
||||
invermap++;
|
||||
}
|
||||
|
||||
quantlevel = aBlendQuality+2;
|
||||
shiftnum = (8-quantlevel)+8;
|
||||
tnum = 2;
|
||||
quantlevel = 4; // 4
|
||||
shiftnum = (8-quantlevel)+8; // 12
|
||||
tnum = 2; // 2
|
||||
for(i=1;i<quantlevel;i++)
|
||||
tnum = 2*tnum;
|
||||
tnum = 2*tnum; // 2, 4, 8, tnum = 16
|
||||
|
||||
num = tnum;
|
||||
num = tnum; // num = 16
|
||||
for(i=1;i<3;i++)
|
||||
num = num*tnum;
|
||||
num = num*tnum; // 256, 4096
|
||||
|
||||
distbuffer = new PRUint32[num];
|
||||
invermap = new PRUint8[num*3];
|
||||
inv_colormap(256,mapptr,quantlevel,distbuffer,invermap );
|
||||
distbuffer = new PRUint32[num]; // new PRUint[4096]
|
||||
invermap = new PRUint8[num*3]; // new PRUint8[12288]
|
||||
inv_colormap(256,mapptr,quantlevel,distbuffer,invermap ); // 216,mapptr[],4,distbuffer[4096],invermap[12288])
|
||||
|
||||
// now go thru the image and blend (remember, its bottom upwards)
|
||||
s1 = aSImage;
|
||||
@ -551,24 +567,27 @@ PRUint32 quantlevel,tnum,num,shiftnum;
|
||||
|
||||
for(x = 0; x < aNumbytes; x++){
|
||||
i = (*d2);
|
||||
r = aColorMap->Index[(3 * i) + 2];
|
||||
g = aColorMap->Index[(3 * i) + 1];
|
||||
b = aColorMap->Index[(3 * i)];
|
||||
r = mapptr[(3 * i) + 2];
|
||||
g = mapptr[(3 * i) + 1];
|
||||
b = mapptr[(3 * i)];
|
||||
|
||||
i =(*s2);
|
||||
r1 = aColorMap->Index[(3 * i) + 2];
|
||||
g1 = aColorMap->Index[(3 * i) + 1];
|
||||
b1 = aColorMap->Index[(3 * i)];
|
||||
r1 = mapptr[(3 * i) + 2];
|
||||
g1 = mapptr[(3 * i) + 1];
|
||||
b1 = mapptr[(3 * i)];
|
||||
|
||||
r = ((r*val1)+(r1*val2))>>shiftnum;
|
||||
//r = ((r*val1)+(r1*val2))>>shiftnum;
|
||||
r=r>>quantlevel;
|
||||
if(r>tnum)
|
||||
r = tnum;
|
||||
|
||||
g = ((g*val1)+(g1*val2))>>shiftnum;
|
||||
//g = ((g*val1)+(g1*val2))>>shiftnum;
|
||||
g=g>>quantlevel;
|
||||
if(g>tnum)
|
||||
g = tnum;
|
||||
|
||||
b = ((b*val1)+(b1*val2))>>shiftnum;
|
||||
//b = ((b*val1)+(b1*val2))>>shiftnum;
|
||||
b=b>>quantlevel;
|
||||
if(b>tnum)
|
||||
b = tnum;
|
||||
|
||||
@ -608,7 +627,7 @@ static PRInt32 blueloop( PRInt32 );
|
||||
* @update dc - 10/29/98
|
||||
* @param colors -- Number of colors
|
||||
* @param aCMap -- The color map
|
||||
* @param aBits -- The bits to make the color map from
|
||||
* @param aBits -- Resolution in bits for the inverse map
|
||||
* @param dist_buf -- a buffer to hold the temporary colors in while we calculate the map
|
||||
* @param aRGBMap -- the map to put the inverse colors into for the color table
|
||||
* @return VOID
|
||||
|
@ -35,6 +35,8 @@
|
||||
#include "nsPoint.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsIImage.h"
|
||||
#include "libimg.h"
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
@ -49,22 +51,22 @@ public:
|
||||
* General constructor for a nsBlender object
|
||||
* @update dc - 10/29/98
|
||||
*/
|
||||
nsBlender();
|
||||
nsBlender();
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
* Destructor for a nsBlender object
|
||||
* @update dc - 10/29/98
|
||||
*/
|
||||
~nsBlender();
|
||||
virtual ~nsBlender();
|
||||
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
* Initialize a nsBlender object, or re-initialize if it is re-used
|
||||
* @update dc - 10/29/98
|
||||
* @param aSrc -- source drawing surface
|
||||
* @param aDst -- destination drawing surface
|
||||
* @result NS_OK if everything initialized
|
||||
*/
|
||||
virtual nsresult Init(nsDrawingSurface aSrc,nsDrawingSurface aDst);
|
||||
* Initialize a nsBlender object, or re-initialize if it is re-used
|
||||
* @update dc 11/4/98
|
||||
* @param aDeviceContext is where the blender can get info about the device its blending on
|
||||
* @result The result of the initialization, NS_OK if no errors
|
||||
*/
|
||||
virtual nsresult Init(nsIDeviceContext *aDeviceContext);
|
||||
|
||||
protected:
|
||||
|
||||
@ -172,11 +174,12 @@ public:
|
||||
* @param aSaveBlendArea informs routine if the area affected area will be save first
|
||||
*/
|
||||
void Do8Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,
|
||||
PRInt32 aSLSpan,PRInt32 aDLSpan,nsColorMap *aColorMap,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea);
|
||||
PRInt32 aSLSpan,PRInt32 aDLSpan,IL_ColorSpace *aColorMap,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea);
|
||||
|
||||
|
||||
PRUint8 *mSaveBytes; // place to save bits
|
||||
PRInt32 mSaveLS;
|
||||
nsIDeviceContext *mTheDeviceCon;
|
||||
|
||||
};
|
||||
|
||||
|
@ -34,44 +34,33 @@
|
||||
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
|
||||
* @update dc 11/4/98
|
||||
* @param aDeviceContext is where the blender can get info about the device its blending on
|
||||
* @result The result of the initialization, NS_OK if no errors
|
||||
*/
|
||||
virtual nsresult Init(nsDrawingSurface aSrc,nsDrawingSurface aDst) = 0;
|
||||
virtual nsresult Init(nsIDeviceContext *aDeviceContext) = 0;
|
||||
|
||||
/**
|
||||
* NOTE: if we can make this static, that would be great. I don't think we can.
|
||||
* Blend source and destination nsDrawingSurfaces. Both drawing surfaces
|
||||
* will have bitmaps associated with them.
|
||||
* @param aSrc source for blending
|
||||
* @param aSX x offset into source drawing surface of blend area
|
||||
* @param aSY y offset into source drawing surface of blend area
|
||||
* @param aWidth width of blend area
|
||||
* @param aHeight width of blend area
|
||||
* @param aSrc source for the blending
|
||||
* @param aDest destination for blending
|
||||
* @param aDX x offset into destination drawing surface of blend area
|
||||
* @param aDY y offset into destination drawing surface of blend area
|
||||
* @param aSrcOpacity 0.0f -> 1.0f opacity value of source area. 1.0f indicates
|
||||
* complete opacity.
|
||||
*/
|
||||
virtual nsresult Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
virtual nsresult Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,nsDrawingSurface aSrc,
|
||||
nsDrawingSurface aDest, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity,PRBool aSaveBlendArea) = 0;
|
||||
|
||||
/**
|
||||
* Return the source drawing surface to be blended
|
||||
* @return The platform specific drawing surface
|
||||
*/
|
||||
virtual nsDrawingSurface GetSrcDS()=0;
|
||||
|
||||
/**
|
||||
* Return the destination drawing surface to be blended and modified
|
||||
* @return The platform specific drawing surface
|
||||
*/
|
||||
virtual nsDrawingSurface GetDstDS()=0;
|
||||
|
||||
/**
|
||||
* Restore the the blended area of the image if one was save on a previous blend.
|
||||
*/
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <windows.h>
|
||||
#include "nsBlenderWin.h"
|
||||
#include "nsRenderingContextWin.h"
|
||||
#include "il_util.h"
|
||||
|
||||
|
||||
#ifdef NGLAYOUT_DDRAW
|
||||
#include "ddraw.h"
|
||||
@ -42,8 +44,6 @@ nsBlenderWin :: nsBlenderWin()
|
||||
mResLS = 0;
|
||||
mSRowBytes = 0;
|
||||
mDRowBytes = 0;
|
||||
mSrcDS = nsnull;
|
||||
mDstDS = nsnull;
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
@ -52,8 +52,6 @@ nsBlenderWin :: nsBlenderWin()
|
||||
*/
|
||||
nsBlenderWin :: ~nsBlenderWin()
|
||||
{
|
||||
NS_IF_RELEASE(mSrcDS);
|
||||
NS_IF_RELEASE(mDstDS);
|
||||
|
||||
// get rid of the DIB's
|
||||
if (nsnull != mSrcbinfo)
|
||||
@ -74,25 +72,18 @@ nsBlenderWin :: ~nsBlenderWin()
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
* Set all the windows specific data for a blender to some initial values
|
||||
* @update dc - 10/29/98
|
||||
* @update dc 11/4/98
|
||||
* @param - aTheDevCon is the device context we will use to get information from for the blend
|
||||
*/
|
||||
nsresult
|
||||
nsBlenderWin::Init(nsDrawingSurface aSrc, nsDrawingSurface aDst)
|
||||
nsBlenderWin::Init(nsIDeviceContext *aTheDevCon)
|
||||
{
|
||||
NS_ASSERTION(!(aSrc == nsnull), "no source surface");
|
||||
NS_ASSERTION(!(aDst == nsnull), "no dest surface");
|
||||
|
||||
if (mSaveBytes != nsnull)
|
||||
{
|
||||
if (mSaveBytes != nsnull){
|
||||
delete [] mSaveBytes;
|
||||
mSaveBytes = nsnull;
|
||||
}
|
||||
|
||||
mSrcDS = (nsDrawingSurfaceWin *)aSrc;
|
||||
mDstDS = (nsDrawingSurfaceWin *)aDst;
|
||||
|
||||
NS_IF_ADDREF(mSrcDS);
|
||||
NS_IF_ADDREF(mDstDS);
|
||||
mTheDeviceCon = aTheDevCon;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -112,17 +103,25 @@ nsBlenderWin::Init(nsDrawingSurface aSrc, nsDrawingSurface aDst)
|
||||
* @result NS_OK if the blend worked.
|
||||
*/
|
||||
nsresult
|
||||
nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,nsDrawingSurface aSrc,
|
||||
nsDrawingSurface aDst, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity,PRBool aSaveBlendArea)
|
||||
{
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
HBITMAP dstbits, tb1;
|
||||
nsPoint srcloc, maskloc;
|
||||
PRInt32 dlinespan, slinespan, mlinespan, numbytes, numlines, level, size, oldsize;
|
||||
PRUint8 *s1, *d1, *m1, *mask = NULL;
|
||||
nsColorMap *colormap;
|
||||
HDC srcdc, dstdc;
|
||||
PRBool srcissurf = PR_FALSE, dstissurf = PR_FALSE;
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
HBITMAP dstbits, tb1;
|
||||
nsPoint srcloc, maskloc;
|
||||
PRInt32 dlinespan, slinespan, mlinespan, numbytes, numlines, level, size, oldsize;
|
||||
PRUint8 *s1, *d1, *m1, *mask = NULL;
|
||||
IL_ColorSpace *thespace=nsnull;
|
||||
HDC srcdc, dstdc;
|
||||
PRBool srcissurf = PR_FALSE, dstissurf = PR_FALSE;
|
||||
|
||||
// This is a temporary solution, nsDrawingSurface is a void*, but on windows it is really a
|
||||
// nsDrawingSurfaceWin, which is an XPCom object. I am going to cast it here just temporarily
|
||||
// until I fix all the platforms to use a XPComed version of the nsDrawingSurface
|
||||
nsDrawingSurfaceWin *SrcWinSurf,*DstWinSurf;
|
||||
|
||||
SrcWinSurf = (nsDrawingSurfaceWin*)aSrc;
|
||||
DstWinSurf = (nsDrawingSurfaceWin*)aDst;
|
||||
|
||||
// source
|
||||
|
||||
@ -134,31 +133,25 @@ nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
srect.right = aSX + aWidth;
|
||||
srect.bottom = aSY + aHeight;
|
||||
|
||||
if (PR_TRUE == LockSurface(mSrcDS->mSurface, &mSrcSurf, &mSrcInfo, &srect, DDLOCK_READONLY))
|
||||
{
|
||||
if (PR_TRUE == LockSurface(SrcWinSurf->mSurface, &mSrcSurf, &mSrcInfo, &srect, DDLOCK_READONLY)){
|
||||
srcissurf = PR_TRUE;
|
||||
mSRowBytes = mSrcInfo.bmWidthBytes;
|
||||
}
|
||||
else
|
||||
}else
|
||||
#endif
|
||||
{
|
||||
if (nsnull == mSrcbinfo)
|
||||
{
|
||||
if (nsnull == mSrcbinfo){
|
||||
HBITMAP srcbits;
|
||||
srcdc = mSrcDS->mDC;
|
||||
srcdc = SrcWinSurf->mDC;
|
||||
|
||||
if (nsnull == mSrcDS->mSelectedBitmap)
|
||||
{
|
||||
if (nsnull == SrcWinSurf->mSelectedBitmap){
|
||||
HBITMAP hbits = ::CreateCompatibleBitmap(srcdc, 2, 2);
|
||||
srcbits = (HBITMAP)::SelectObject(srcdc, hbits);
|
||||
::GetObject(srcbits, sizeof(BITMAP), &mSrcInfo);
|
||||
::SelectObject(srcdc, srcbits);
|
||||
::DeleteObject(hbits);
|
||||
}
|
||||
else
|
||||
{
|
||||
::GetObject(mSrcDS->mSelectedBitmap, sizeof(BITMAP), &mSrcInfo);
|
||||
srcbits = mSrcDS->mSelectedBitmap;
|
||||
}else{
|
||||
::GetObject(SrcWinSurf->mSelectedBitmap, sizeof(BITMAP), &mSrcInfo);
|
||||
srcbits = SrcWinSurf->mSelectedBitmap;
|
||||
}
|
||||
|
||||
BuildDIB(&mSrcbinfo, &mSrcBytes, mSrcInfo.bmWidth, mSrcInfo.bmHeight, mSrcInfo.bmBitsPixel);
|
||||
@ -180,31 +173,26 @@ nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
drect.right = aDX + aWidth;
|
||||
drect.bottom = aDY + aHeight;
|
||||
|
||||
if (PR_TRUE == LockSurface(mDstDS->mSurface, &mDstSurf, &mDstInfo, &drect, 0))
|
||||
{
|
||||
if (PR_TRUE == LockSurface(DstWinSurf->mSurface, &mDstSurf, &mDstInfo, &drect, 0)){
|
||||
dstissurf = PR_TRUE;
|
||||
mDRowBytes = mDstInfo.bmWidthBytes;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
if (nsnull == mDstbinfo)
|
||||
{
|
||||
if (nsnull == mDstbinfo){
|
||||
HBITMAP dstbits;
|
||||
dstdc = mDstDS->mDC;
|
||||
dstdc = DstWinSurf->mDC;
|
||||
|
||||
if (nsnull == mDstDS->mSelectedBitmap)
|
||||
{
|
||||
if (nsnull == DstWinSurf->mSelectedBitmap){
|
||||
HBITMAP hbits = CreateCompatibleBitmap(dstdc, 2, 2);
|
||||
dstbits = (HBITMAP)::SelectObject(dstdc, hbits);
|
||||
::GetObject(dstbits, sizeof(BITMAP), &mDstInfo);
|
||||
::SelectObject(dstdc, dstbits);
|
||||
::DeleteObject(hbits);
|
||||
}
|
||||
else
|
||||
{
|
||||
::GetObject(mDstDS->mSelectedBitmap, sizeof(BITMAP), &mDstInfo);
|
||||
dstbits = mDstDS->mSelectedBitmap;
|
||||
}else{
|
||||
::GetObject(DstWinSurf->mSelectedBitmap, sizeof(BITMAP), &mDstInfo);
|
||||
dstbits = DstWinSurf->mSelectedBitmap;
|
||||
}
|
||||
|
||||
BuildDIB(&mDstbinfo, &mDstBytes, mDstInfo.bmWidth, mDstInfo.bmHeight, mDstInfo.bmBitsPixel);
|
||||
@ -223,10 +211,8 @@ nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
maskloc.y = 0;
|
||||
|
||||
if (CalcAlphaMetrics(&mSrcInfo, &mDstInfo, &srcloc, NULL, &maskloc, aWidth, aHeight, &numlines, &numbytes,
|
||||
&s1, &d1, &m1, &slinespan, &dlinespan, &mlinespan))
|
||||
{
|
||||
if (nsnull != aSaveBlendArea)
|
||||
{
|
||||
&s1, &d1, &m1, &slinespan, &dlinespan, &mlinespan)){
|
||||
if (nsnull != aSaveBlendArea){
|
||||
oldsize = mSaveLS * mSaveNumLines;
|
||||
|
||||
// allocate some memory
|
||||
@ -235,45 +221,35 @@ nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
size = mSaveLS * numlines;
|
||||
mSaveNumBytes = numbytes;
|
||||
|
||||
if(mSaveBytes != nsnull)
|
||||
{
|
||||
if(oldsize != size)
|
||||
{
|
||||
if(mSaveBytes != nsnull) {
|
||||
if(oldsize != size){
|
||||
delete [] mSaveBytes;
|
||||
mSaveBytes = new unsigned char[size];
|
||||
}
|
||||
}
|
||||
else
|
||||
mSaveBytes = new unsigned char[size];
|
||||
} else
|
||||
mSaveBytes = new unsigned char[size];
|
||||
|
||||
mRestorePtr = d1;
|
||||
mResLS = dlinespan;
|
||||
}
|
||||
|
||||
if (mSrcInfo.bmBitsPixel == mDstInfo.bmBitsPixel)
|
||||
{
|
||||
if (mSrcInfo.bmBitsPixel == mDstInfo.bmBitsPixel){
|
||||
// now do the blend
|
||||
switch (mSrcInfo.bmBitsPixel)
|
||||
{
|
||||
switch (mSrcInfo.bmBitsPixel){
|
||||
case 32:
|
||||
if (!mask)
|
||||
{
|
||||
if (!mask){
|
||||
level = (PRInt32)(100 - aSrcOpacity*100);
|
||||
Do32Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,nsHighQual,aSaveBlendArea);
|
||||
result = NS_OK;
|
||||
}
|
||||
else
|
||||
}else
|
||||
result = NS_ERROR_FAILURE;
|
||||
break;
|
||||
|
||||
case 24:
|
||||
if (mask)
|
||||
{
|
||||
if (mask){
|
||||
Do24BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,nsHighQual,aSaveBlendArea);
|
||||
result = NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
}else{
|
||||
level = (PRInt32)(100 - aSrcOpacity*100);
|
||||
Do24Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,nsHighQual,aSaveBlendArea);
|
||||
result = NS_OK;
|
||||
@ -281,8 +257,7 @@ nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
break;
|
||||
|
||||
case 16:
|
||||
if (!mask)
|
||||
{
|
||||
if (!mask){
|
||||
level = (PRInt32)(100 - aSrcOpacity*100);
|
||||
Do16Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,nsHighQual,aSaveBlendArea);
|
||||
result = NS_OK;
|
||||
@ -292,39 +267,37 @@ nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
break;
|
||||
|
||||
case 8:
|
||||
if (mask)
|
||||
{
|
||||
if (mask){
|
||||
Do8BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,nsHighQual,aSaveBlendArea);
|
||||
result = NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
level = (PRInt32)(100 - aSrcOpacity*100);
|
||||
Do8Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,colormap,nsHighQual,aSaveBlendArea);
|
||||
result = NS_OK;
|
||||
}else{
|
||||
if( mTheDeviceCon->GetILColorSpace(thespace) == NS_OK){
|
||||
level = (PRInt32)(100 - aSrcOpacity*100);
|
||||
Do8Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,thespace,nsHighQual,aSaveBlendArea);
|
||||
result = NS_OK;
|
||||
IL_ReleaseColorSpace(thespace);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (PR_FALSE == dstissurf)
|
||||
{
|
||||
if (PR_FALSE == dstissurf){
|
||||
// put the new bits in
|
||||
dstdc = ((nsDrawingSurfaceWin *)aDst)->mDC;
|
||||
dstdc = ((nsDrawingSurfaceWin *)DstWinSurf)->mDC;
|
||||
dstbits = ::CreateDIBitmap(dstdc, mDstbinfo, CBM_INIT, mDstBytes, (LPBITMAPINFO)mDstbinfo, DIB_RGB_COLORS);
|
||||
tb1 = (HBITMAP)::SelectObject(dstdc, dstbits);
|
||||
::DeleteObject(tb1);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
result == NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
#ifdef NGLAYOUT_DDRAW
|
||||
if (PR_TRUE == srcissurf)
|
||||
mSrcDS->mSurface->Unlock(mSrcSurf.lpSurface);
|
||||
aSrc->mSurface->Unlock(mSrcSurf.lpSurface);
|
||||
|
||||
if (PR_TRUE == dstissurf)
|
||||
mDstDS->mSurface->Unlock(mDstSurf.lpSurface);
|
||||
DstWinSurf->mSurface->Unlock(mDstSurf.lpSurface);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
@ -348,19 +321,16 @@ HBITMAP dstbits, tb1;
|
||||
|
||||
//XXX this is busted with directdraw... MMP
|
||||
|
||||
if(mSaveBytes!=nsnull)
|
||||
{
|
||||
if(mSaveBytes!=nsnull){
|
||||
result = PR_TRUE;
|
||||
saveptr = mSaveBytes;
|
||||
orgptr = mRestorePtr;
|
||||
|
||||
for(y=0;y<mSaveNumLines;y++)
|
||||
{
|
||||
for(y=0;y<mSaveNumLines;y++){
|
||||
savebyteptr = saveptr;
|
||||
orgbyteptr = orgptr;
|
||||
|
||||
for(x=0;x<mSaveNumBytes;x++)
|
||||
{
|
||||
for(x=0;x<mSaveNumBytes;x++){
|
||||
*orgbyteptr = *savebyteptr;
|
||||
savebyteptr++;
|
||||
orgbyteptr++;
|
||||
@ -394,18 +364,15 @@ HBITMAP dstbits, tb1;
|
||||
*/
|
||||
PRBool nsBlenderWin :: LockSurface(IDirectDrawSurface *aSurface, DDSURFACEDESC *aDesc, BITMAP *aBitmap, RECT *aRect, DWORD aLockFlags)
|
||||
{
|
||||
if (nsnull != aSurface)
|
||||
{
|
||||
if (nsnull != aSurface){
|
||||
aDesc->dwSize = sizeof(DDSURFACEDESC);
|
||||
|
||||
if (DD_OK == aSurface->Lock(aRect, aDesc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | aLockFlags, NULL))
|
||||
{
|
||||
if (DD_OK == aSurface->Lock(aRect, aDesc, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR | aLockFlags, NULL)){
|
||||
if ((aDesc->ddpfPixelFormat.dwFlags &
|
||||
(DDPF_ALPHA | DDPF_PALETTEINDEXED1 |
|
||||
DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4 |
|
||||
DDPF_PALETTEINDEXEDTO8 | DDPF_YUV | DDPF_ZBUFFER)) ||
|
||||
(aDesc->ddpfPixelFormat.dwRGBBitCount < 8))
|
||||
{
|
||||
(aDesc->ddpfPixelFormat.dwRGBBitCount < 8)){
|
||||
//this is a surface that we can't, or don't want to handle.
|
||||
|
||||
aSurface->Unlock(aDesc->lpSurface);
|
||||
@ -421,8 +388,7 @@ PRBool nsBlenderWin :: LockSurface(IDirectDrawSurface *aSurface, DDSURFACEDESC *
|
||||
aBitmap->bmBits = aDesc->lpSurface;
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
else
|
||||
}else
|
||||
return PR_FALSE;
|
||||
}
|
||||
else
|
||||
@ -463,14 +429,11 @@ PRBool doalpha = PR_FALSE;
|
||||
nsRect arect,srect,drect,irect;
|
||||
PRInt32 startx,starty;
|
||||
|
||||
if(aMaskInfo)
|
||||
{
|
||||
if(aMaskInfo){
|
||||
arect.SetRect(0,0,aDestInfo->bmWidth,aDestInfo->bmHeight);
|
||||
srect.SetRect(aMaskUL->x,aMaskUL->y,aMaskInfo->bmWidth,aSrcInfo->bmHeight);
|
||||
arect.IntersectRect(arect,srect);
|
||||
}
|
||||
else
|
||||
{
|
||||
}else{
|
||||
//arect.SetRect(0,0,aDestInfo->bmWidth,aDestInfo->bmHeight);
|
||||
//srect.SetRect(aMaskUL->x,aMaskUL->y,aWidth,aHeight);
|
||||
//arect.IntersectRect(arect,srect);
|
||||
@ -481,8 +444,7 @@ PRInt32 startx,starty;
|
||||
srect.SetRect(aSrcUL->x, aSrcUL->y, aSrcInfo->bmWidth, aSrcInfo->bmHeight);
|
||||
drect = arect;
|
||||
|
||||
if (irect.IntersectRect(srect, drect))
|
||||
{
|
||||
if (irect.IntersectRect(srect, drect)){
|
||||
// calculate destination information
|
||||
*aDLSpan = mDRowBytes;
|
||||
*aNumbytes = CalcBytesSpan(irect.width,aDestInfo->bmBitsPixel);
|
||||
@ -505,13 +467,10 @@ PRInt32 startx,starty;
|
||||
|
||||
doalpha = PR_TRUE;
|
||||
|
||||
if(aMaskInfo)
|
||||
{
|
||||
if(aMaskInfo){
|
||||
*aMLSpan = aMaskInfo->bmWidthBytes;
|
||||
*aMImage = (PRUint8*)aMaskInfo->bmBits;
|
||||
}
|
||||
else
|
||||
{
|
||||
}else{
|
||||
aMLSpan = 0;
|
||||
*aMImage = nsnull;
|
||||
}
|
||||
@ -537,8 +496,7 @@ nsBlenderWin :: BuildDIB(LPBITMAPINFOHEADER *aBHead,unsigned char **aBits,PRInt
|
||||
PRUint8 *colortable;
|
||||
DWORD bicomp, masks[3];
|
||||
|
||||
switch (aDepth)
|
||||
{
|
||||
switch (aDepth) {
|
||||
case 8:
|
||||
palsize = 256;
|
||||
allocsize = 256;
|
||||
@ -574,8 +532,7 @@ nsBlenderWin :: BuildDIB(LPBITMAPINFOHEADER *aBHead,unsigned char **aBits,PRInt
|
||||
break;
|
||||
}
|
||||
|
||||
if (palsize >= 0)
|
||||
{
|
||||
if (palsize >= 0){
|
||||
spanbytes = CalcBytesSpan(aWidth, aDepth);
|
||||
imagesize = spanbytes * aHeight;
|
||||
|
||||
@ -603,8 +560,7 @@ nsBlenderWin :: BuildDIB(LPBITMAPINFOHEADER *aBHead,unsigned char **aBits,PRInt
|
||||
*aBits = new unsigned char[imagesize];
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
}else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
@ -618,7 +574,6 @@ nsBlenderWin :: BuildDIB(LPBITMAPINFOHEADER *aBHead,unsigned char **aBits,PRInt
|
||||
void
|
||||
nsBlenderWin::DeleteDIB(LPBITMAPINFOHEADER *aBHead,unsigned char **aBits)
|
||||
{
|
||||
|
||||
delete[] *aBHead;
|
||||
aBHead = 0;
|
||||
delete[] *aBits;
|
||||
|
@ -40,19 +40,20 @@ public:
|
||||
* Construct and set the initial values for this windows specific blender
|
||||
* @update dc - 10/29/98
|
||||
*/
|
||||
nsBlenderWin();
|
||||
nsBlenderWin();
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
* Release and cleanup all the windows specific information for this blender
|
||||
* @update dc - 10/29/98
|
||||
*/
|
||||
~nsBlenderWin();
|
||||
~nsBlenderWin();
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
* Set all the windows specific data for a blender to some initial values
|
||||
* @update dc - 10/29/98
|
||||
* @param - aTheDevCon is the device context we will use to get information from for the blend
|
||||
*/
|
||||
virtual nsresult Init(nsDrawingSurface aSrc,nsDrawingSurface aDst);
|
||||
virtual nsresult Init(nsIDeviceContext *aDeviceCon);
|
||||
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
@ -62,6 +63,7 @@ public:
|
||||
* @param aSY -- top location for the blend
|
||||
* @param aWidth -- width of the blend
|
||||
* @param aHeight -- height of the blend
|
||||
* @param aSrc -- Source drawing surface for the blend
|
||||
* @param aDst -- Destination drawing surface for the blend
|
||||
* @param aDX -- left location for the destination of the blend
|
||||
* @param aDY -- top location for the destination of the blend
|
||||
@ -69,12 +71,9 @@ public:
|
||||
* @param aSaveBlendArea -- If true, will save off the blended area to restore later
|
||||
* @result NS_OK if the blend worked.
|
||||
*/
|
||||
virtual nsresult Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,
|
||||
virtual nsresult Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,nsDrawingSurface aSrc,
|
||||
nsDrawingSurface aDest, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity,PRBool aSaveBlendArea);
|
||||
|
||||
nsDrawingSurface GetSrcDS() {return(mSrcDS);}
|
||||
nsDrawingSurface GetDstDS() {return(mDstDS);}
|
||||
|
||||
/** --------------------------------------------------------------------------
|
||||
* Replace the bits saved from the last blend if the restore flag was set
|
||||
* @update dc - 10/29/98
|
||||
@ -150,7 +149,6 @@ public:
|
||||
PRUint8 *mSrcBytes;
|
||||
PRUint8 *mDstBytes;
|
||||
BITMAP mSrcInfo, mDstInfo;
|
||||
nsDrawingSurfaceWin *mSrcDS, *mDstDS;
|
||||
|
||||
PRInt32 mSRowBytes;
|
||||
PRInt32 mDRowBytes;
|
||||
|
@ -271,6 +271,7 @@ SetUpBlend()
|
||||
{
|
||||
void *bits1,*bits2;
|
||||
nsresult rv;
|
||||
nsIDeviceContext *dx;
|
||||
|
||||
static NS_DEFINE_IID(kBlenderCID, NS_BLENDER_CID);
|
||||
static NS_DEFINE_IID(kBlenderIID, NS_IBLENDER_IID);
|
||||
@ -291,7 +292,8 @@ nsresult rv;
|
||||
gDobits = (HBITMAP)::SelectObject(gDestdc, gDestbits);
|
||||
|
||||
rv = nsRepository::CreateInstance(kBlenderCID, nsnull, kBlenderIID, (void **)&gImageblender);
|
||||
gImageblender->Init(gSrcdc,gDestdc);
|
||||
//gImageblender->Init(gSrcdc,gDestdc);
|
||||
gImageblender->Init(dx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -325,7 +327,7 @@ BITMAP srcinfo;
|
||||
LPBITMAPINFOHEADER srcbinfo;
|
||||
nsIRenderingContext *drawCtx = gWindow->GetRenderingContext();
|
||||
|
||||
dstdc = (HDC)aBlender->GetDstDS();
|
||||
//dstdc = (HDC)aBlender->GetDstDS();
|
||||
|
||||
aBlender->RestoreImage(dstdc);
|
||||
|
||||
@ -519,11 +521,11 @@ LPBITMAPINFOHEADER srcbinfo;
|
||||
nsIRenderingContext *drawCtx = gWindow->GetRenderingContext();
|
||||
|
||||
|
||||
srcdc = (HDC)aBlender->GetSrcDS();
|
||||
dstdc = (HDC)aBlender->GetDstDS();
|
||||
|
||||
result = aBlender->Blend(aSX,aSY,aWidth,aHeight,dstdc,0, 0,aBlendAmount,aBuff);
|
||||
//srcdc = (HDC)aBlender->GetSrcDS();
|
||||
//dstdc = (HDC)aBlender->GetDstDS();
|
||||
|
||||
//result = aBlender->Blend(aSX,aSY,aWidth,aHeight,dstdc,0, 0,aBlendAmount,aBuff);gSrcdc
|
||||
result = aBlender->Blend(aSX,aSY,aWidth,aHeight,srcdc,dstdc,0, 0,aBlendAmount,aBuff);
|
||||
if(result == NS_OK)
|
||||
{
|
||||
// this takes the Destination DC and copies the information into aImage
|
||||
|
Loading…
Reference in New Issue
Block a user