This commit is contained in:
michaelp%netscape.com 1998-12-01 02:15:44 +00:00
Родитель 76e2dbea0e
Коммит 2f03a0e858
5 изменённых файлов: 180 добавлений и 329 удалений

Просмотреть файл

@ -27,9 +27,6 @@ static NS_DEFINE_IID(kIBlenderIID, NS_IBLENDER_IID);
nsBlender :: nsBlender()
{
NS_INIT_REFCNT();
mSaveBytes = nsnull;
mSaveLS = 0;
}
nsBlender::~nsBlender()
@ -81,17 +78,14 @@ nsBlender :: CalcBytesSpan(PRUint32 aWidth, PRUint32 aBitsPixel)
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void
nsBlender::Do32Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea)
nsBlender::Do32Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRUint8 *aSecondSImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,nscolor aSrcBackColor, nscolor aSecondSrcBackColor)
{
PRUint8 *d1,*d2,*s1,*s2;
PRUint32 val1,val2;
PRInt32 x,y,temp1,numlines,xinc,yinc;
PRUint8 *saveptr,*sv2;
saveptr = mSaveBytes;
aBlendVal = (aBlendVal*255)/100;
val2 = aBlendVal;
val1 = 255-val2;
@ -104,52 +98,25 @@ PRUint8 *saveptr,*sv2;
xinc = 1;
yinc = 1;
if (aSaveBlendArea){
for (y = 0; y < aNumlines; y++){
s2 = s1;
d2 = d1;
sv2 = saveptr;
for (y = 0; y < aNumlines; y++){
s2 = s1;
d2 = d1;
for (x = 0; x < aNumbytes; x++){
*sv2 = *d2;
for (x = 0; x < aNumbytes; x++) {
temp1 = (((*d2) * val1) + ((*s2) * val2)) >> 8;
temp1 = (((*d2) * val1) + ((*s2) * val2)) >> 8;
if (temp1 > 255)
temp1 = 255;
if (temp1 > 255)
temp1 = 255;
*d2 = (PRUint8)temp1;
*d2 = (PRUint8)temp1;
sv2++;
d2++;
s2++;
}
s1 += aSLSpan;
d1 += aDLSpan;
saveptr+= mSaveLS;
d2++;
s2++;
}
} else {
for (y = 0; y < aNumlines; y++){
s2 = s1;
d2 = d1;
for (x = 0; x < aNumbytes; x++) {
temp1 = (((*d2) * val1) + ((*s2) * val2)) >> 8;
if (temp1 > 255)
temp1 = 255;
*d2 = (PRUint8)temp1;
d2++;
s2++;
}
s1 += aSLSpan;
d1 += aDLSpan;
}
}
s1 += aSLSpan;
d1 += aDLSpan;
}
}
/** --------------------------------------------------------------------------
@ -164,10 +131,9 @@ PRUint8 *saveptr,*sv2;
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void
nsBlender::Do24BlendWithMask(PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea)
nsBlender::Do24BlendWithMask(PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality)
{
PRUint8 *d1,*d2,*s1,*s2,*m1,*m2;
PRInt32 x,y;
@ -237,17 +203,14 @@ PRInt32 sspan,dspan,mspan;
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void
nsBlender::Do24Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea)
nsBlender::Do24Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRUint8 *aSecondSImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,nscolor aSrcBackColor, nscolor aSecondSrcBackColor)
{
PRUint8 *d1,*d2,*s1,*s2;
PRUint32 val1,val2;
PRInt32 x,y,temp1,numlines,xinc,yinc;
PRUint8 *saveptr,*sv2;
saveptr = mSaveBytes;
aBlendVal = (aBlendVal*255)/100;
val2 = aBlendVal;
val1 = 255-val2;
@ -260,46 +223,22 @@ PRUint8 *saveptr,*sv2;
xinc = 1;
yinc = 1;
if(aSaveBlendArea){
for(y = 0; y < aNumlines; y++){
s2 = s1;
d2 = d1;
sv2 = saveptr;
for(y = 0; y < aNumlines; y++){
s2 = s1;
d2 = d1;
for(x = 0; x < aNumbytes; x++){
temp1 = (((*d2)*val1)+((*s2)*val2))>>8;
if(temp1>255)
temp1 = 255;
*sv2 = *d2;
*d2 = (PRUint8)temp1;
for(x = 0; x < aNumbytes; x++){
temp1 = (((*d2)*val1)+((*s2)*val2))>>8;
if(temp1>255)
temp1 = 255;
*d2 = (PRUint8)temp1;
sv2++;
d2++;
s2++;
}
s1 += aSLSpan;
d1 += aDLSpan;
saveptr+= mSaveLS;
d2++;
s2++;
}
}else{
for(y = 0; y < aNumlines; y++){
s2 = s1;
d2 = d1;
for(x = 0; x < aNumbytes; x++){
temp1 = (((*d2)*val1)+((*s2)*val2))>>8;
if(temp1>255)
temp1 = 255;
*d2 = (PRUint8)temp1;
d2++;
s2++;
}
s1 += aSLSpan;
d1 += aDLSpan;
}
s1 += aSLSpan;
d1 += aDLSpan;
}
}
@ -321,19 +260,17 @@ PRUint8 *saveptr,*sv2;
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void
nsBlender::Do16Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea)
nsBlender::Do16Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRUint8 *aSecondSImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,nscolor aSrcBackColor, nscolor aSecondSrcBackColor)
{
PRUint16 *d1,*d2,*s1,*s2;
PRUint32 val1,val2,red,green,blue,stemp,dtemp;
PRUint16 *d1,*d2,*s1,*s2,*ss1,*ss2;
PRUint32 val1,val2,red,green,blue,stemp,dtemp,sstemp;
PRInt32 x,y,numlines,xinc,yinc;
PRUint16 *saveptr,*sv2;
PRInt16 dspan,sspan,span,savesp;
PRUint16 srccolor,secsrccolor;
PRInt16 dspan,sspan,span;
// since we are using 16 bit pointers, the num bytes need to be cut by 2
saveptr = (PRUint16*)mSaveBytes;
aBlendVal = (aBlendVal * 255) / 100;
val2 = aBlendVal;
val1 = 255-val2;
@ -344,49 +281,67 @@ PRInt16 dspan,sspan,span,savesp;
dspan = aDLSpan >> 1;
sspan = aSLSpan >> 1;
span = aNumbytes >> 1;
savesp = mSaveLS >> 1;
numlines = aNumlines;
xinc = 1;
yinc = 1;
if (aSaveBlendArea){
if (nsnull != aSecondSImage)
{
ss1 = (PRUint16*)aSecondSImage;
srccolor = ((NS_GET_R(aSrcBackColor) & 0xf8) << 8) |
((NS_GET_G(aSrcBackColor) & 0xfc) << 3) |
((NS_GET_B(aSrcBackColor) & 0xf8) >> 3);
secsrccolor = ((NS_GET_R(aSecondSrcBackColor) & 0xf8) << 8) |
((NS_GET_G(aSecondSrcBackColor) & 0xfc) << 3) |
((NS_GET_B(aSecondSrcBackColor) & 0xf8) >> 3);
}
else
ss1 = nsnull;
if (nsnull != ss1){
for (y = 0; y < aNumlines; y++){
s2 = s1;
d2 = d1;
sv2 = saveptr;
ss2 = ss1;
for (x = 0; x < span; x++){
stemp = *s2;
dtemp = *d2;
sstemp = *ss2;
red = (RED16(dtemp) * val1 + RED16(stemp) * val2) >> 8;
if ((stemp != srccolor) || (sstemp != secsrccolor))
{
dtemp = *d2;
if (red > 255)
red = 255;
red = (RED16(dtemp) * val1 + RED16(stemp) * val2) >> 8;
green = (GREEN16(dtemp) * val1 + GREEN16(stemp) * val2) >> 8;
if (red > 255)
red = 255;
if (green > 255)
green = 255;
green = (GREEN16(dtemp) * val1 + GREEN16(stemp) * val2) >> 8;
blue = (BLUE16(dtemp) * val1 + BLUE16(stemp) * val2) >> 8;
if (green > 255)
green = 255;
if (blue > 255)
blue = 255;
blue = (BLUE16(dtemp) * val1 + BLUE16(stemp) * val2) >> 8;
*sv2 = *d2;
*d2 = (PRUint16)((red & 0xf8) << 8) | ((green & 0xfc) << 3) | ((blue & 0xf8) >> 3);
if (blue > 255)
blue = 255;
*d2 = (PRUint16)((red & 0xf8) << 8) | ((green & 0xfc) << 3) | ((blue & 0xf8) >> 3);
}
sv2++;
d2++;
s2++;
ss2++;
}
s1 += sspan;
d1 += dspan;
saveptr += savesp;
ss1 += sspan;
}
} else {
}
else
{
for (y = 0; y < aNumlines; y++){
s2 = s1;
d2 = d1;
@ -434,10 +389,9 @@ PRInt16 dspan,sspan,span,savesp;
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void
nsBlender::Do8BlendWithMask(PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea)
nsBlender::Do8BlendWithMask(PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality)
{
PRUint8 *d1,*d2,*s1,*s2,*m1,*m2;
PRInt32 x,y;
@ -496,10 +450,9 @@ extern void inv_colormap(PRInt16 colors,PRUint8 *aCMap,PRInt16 bits,PRUint32 *di
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @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,IL_ColorSpace *aColorMap,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea)
nsBlender::Do8Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRUint8 *aSecondSImage,PRInt32 aSLSpan,PRInt32 aDLSpan,IL_ColorSpace *aColorMap,nsBlendQuality aBlendQuality,nscolor aSrcBackColor, nscolor aSecondSrcBackColor)
{
PRUint32 r,g,b,r1,g1,b1,i;
PRUint8 *d1,*d2,*s1,*s2;

Просмотреть файл

@ -83,10 +83,10 @@ public:
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void Do32Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,
PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea);
PRUint8 *aSecondSImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,
nscolor aSrcBackColor, nscolor aSecondSrcBackColor);
/** --------------------------------------------------------------------------
* Blend two 24 bit image arrays using an 8 bit alpha mask
@ -99,10 +99,9 @@ public:
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void Do24BlendWithMask(PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,
PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea);
PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality);
/** --------------------------------------------------------------------------
* Blend two 24 bit image arrays using a passed in blend value
@ -115,10 +114,10 @@ public:
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void Do24Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,
PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea);
PRUint8 *aSecondSImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,
nscolor aSrcBackColor, nscolor aSecondSrcBackColor);
/** --------------------------------------------------------------------------
@ -132,10 +131,10 @@ public:
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void Do16Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,
PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea);
PRUint8 *aSecondSImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality,
nscolor aSrcBackColor, nscolor aSecondSrcBackColor);
/** --------------------------------------------------------------------------
* Blend two 8 bit image arrays using an 8 bit alpha mask
@ -148,10 +147,9 @@ public:
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @param aSaveBlendArea informs routine if the area affected area will be save first
*/
void Do8BlendWithMask(PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,
PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea);
PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality);
/** --------------------------------------------------------------------------
* Blend two 8 bit image arrays using a passed in blend value
@ -164,16 +162,13 @@ public:
* @param aDLSpan number of bytes per line for the destination bytes
* @param aMLSpan number of bytes per line for the Mask bytes
* @param aBlendQuality The quality of this blend, this is for tweening if neccesary
* @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,IL_ColorSpace *aColorMap,nsBlendQuality aBlendQuality,PRBool aSaveBlendArea);
PRUint8 *aSecondSImage,PRInt32 aSLSpan,PRInt32 aDLSpan,IL_ColorSpace *aColorMap,nsBlendQuality aBlendQuality,
nscolor aSrcBackColor, nscolor aSecondSrcBackColor);
PRUint8 *mSaveBytes; // place to save bits
PRInt32 mSaveLS;
nsIDeviceContext *mTheDeviceCon;
};
#endif

Просмотреть файл

@ -1,70 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIBlender_h___
#define nsIBlender_h___
#include "nscore.h"
#include "nsISupports.h"
#include "nsIRenderingContext.h"
// IID for the nsIBlender interface
#define NS_IBLENDER_IID \
{ 0xbdb4b5b0, 0xf0db, 0x11d1, \
{ 0xa8, 0x2a, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
//----------------------------------------------------------------------
// Blender interface
class nsIBlender : public nsISupports
{
public:
/**
* Initialize the Blender
* @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
*/
NS_IMETHOD 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 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.
*/
NS_IMETHOD Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,nsDrawingSurface aSrc,
nsDrawingSurface aDest, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity,PRBool aSaveBlendArea) = 0;
/**
* Restore the the blended area of the image if one was save on a previous blend.
*/
NS_IMETHOD RestoreImage(nsDrawingSurface aDst) = 0;
};
#endif

Просмотреть файл

@ -35,13 +35,11 @@
nsBlenderWin :: nsBlenderWin()
{
mSrcBytes = nsnull;
mSecondSrcBytes = nsnull;
mDstBytes = nsnull;
mSaveNumLines = 0;
mSrcbinfo = nsnull;
mDstbinfo = nsnull;
mRestorePtr = nsnull;
mSaveNumBytes = 0;
mResLS = 0;
mSecondSrcbinfo = nsnull;
mSRowBytes = 0;
mDRowBytes = 0;
}
@ -52,7 +50,6 @@ nsBlenderWin :: nsBlenderWin()
*/
nsBlenderWin :: ~nsBlenderWin()
{
// get rid of the DIB's
if (nsnull != mSrcbinfo)
DeleteDIB(&mSrcbinfo, &mSrcBytes);
@ -60,14 +57,10 @@ nsBlenderWin :: ~nsBlenderWin()
if (nsnull != mDstbinfo)
DeleteDIB(&mDstbinfo, &mDstBytes);
if (mSaveBytes != nsnull){
delete [] mSaveBytes;
mSaveBytes == nsnull;
}
if (nsnull != mSecondSrcbinfo)
DeleteDIB(&mSecondSrcbinfo, &mSecondSrcBytes);
mDstBytes = nsnull;
mSaveLS = 0;
mSaveNumLines = 0;
}
/** --------------------------------------------------------------------------
@ -78,11 +71,6 @@ nsBlenderWin :: ~nsBlenderWin()
NS_IMETHODIMP
nsBlenderWin::Init(nsIDeviceContext *aTheDevCon)
{
if (mSaveBytes != nsnull){
delete [] mSaveBytes;
mSaveBytes = nsnull;
}
mTheDeviceCon = aTheDevCon;
return NS_OK;
@ -99,29 +87,33 @@ nsBlenderWin::Init(nsIDeviceContext *aTheDevCon)
* @param aDX -- left location for the destination of the blend
* @param aDY -- top location for the destination of the blend
* @param aSrcOpacity -- the percentage for the blend
* @param aSaveBlendArea -- If true, will save off the blended area to restore later
* @result NS_OK if the blend worked.
*/
NS_IMETHODIMP
nsBlenderWin::Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,nsDrawingSurface aSrc,
nsDrawingSurface aDst, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity,PRBool aSaveBlendArea)
nsDrawingSurface aDst, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity,
nsDrawingSurface aSecondSrc, nscolor aSrcBackColor, nscolor aSecondSrcBackColor)
{
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;
PRInt32 dlinespan, slinespan, mlinespan, numbytes, numlines, level;
PRUint8 *s1, *d1, *m1, *mask = NULL, *ssl = NULL;
IL_ColorSpace *thespace=nsnull;
HDC srcdc, dstdc;
PRBool srcissurf = PR_FALSE, dstissurf = PR_FALSE;
HDC srcdc, dstdc, secondsrcdc;
PRBool srcissurf = PR_FALSE;
PRBool secondsrcissurf = PR_FALSE;
PRBool 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;
nsDrawingSurfaceWin *SrcWinSurf, *DstWinSurf, *SecondSrcWinSurf;
SrcWinSurf = (nsDrawingSurfaceWin*)aSrc;
DstWinSurf = (nsDrawingSurfaceWin*)aDst;
SecondSrcWinSurf = (nsDrawingSurfaceWin*)aSecondSrc;
// source
@ -204,42 +196,63 @@ nsDrawingSurfaceWin *SrcWinSurf,*DstWinSurf;
mDstInfo.bmBits = mDstBytes;
}
// optional second source
if (nsnull != SecondSrcWinSurf)
{
#ifdef NGLAYOUT_DDRAW
RECT srect;
srect.left = aSX;
srect.top = aSY;
srect.right = aSX + aWidth;
srect.bottom = aSY + aHeight;
if (PR_TRUE == LockSurface(SecondSrcWinSurf->mSurface, &mSecondSrcSurf, &mSecondSrcInfo, &srect, DDLOCK_READONLY)){
secondsrcissurf = PR_TRUE;
}else
#endif
{
if (nsnull == mSecondSrcbinfo){
HBITMAP srcbits;
secondsrcdc = SecondSrcWinSurf->mDC;
if (nsnull == SecondSrcWinSurf->mSelectedBitmap){
HBITMAP hbits = ::CreateCompatibleBitmap(secondsrcdc, 2, 2);
srcbits = (HBITMAP)::SelectObject(secondsrcdc, hbits);
::GetObject(srcbits, sizeof(BITMAP), &mSecondSrcInfo);
::SelectObject(secondsrcdc, srcbits);
::DeleteObject(hbits);
}else{
::GetObject(SecondSrcWinSurf->mSelectedBitmap, sizeof(BITMAP), &mSecondSrcInfo);
srcbits = SecondSrcWinSurf->mSelectedBitmap;
}
BuildDIB(&mSecondSrcbinfo, &mSecondSrcBytes, mSecondSrcInfo.bmWidth, mSecondSrcInfo.bmHeight, mSecondSrcInfo.bmBitsPixel);
numbytes = ::GetDIBits(secondsrcdc, srcbits, 0, mSecondSrcInfo.bmHeight, mSecondSrcBytes, (LPBITMAPINFO)mSecondSrcbinfo, DIB_RGB_COLORS);
}
mSecondSrcInfo.bmBits = mSecondSrcBytes;
}
}
// calculate the metrics, no mask right now
srcloc.x = aSX;
srcloc.y = aSY;
maskloc.x = 0;
maskloc.y = 0;
if (CalcAlphaMetrics(&mSrcInfo, &mDstInfo, &srcloc, NULL, &maskloc, aWidth, aHeight, &numlines, &numbytes,
&s1, &d1, &m1, &slinespan, &dlinespan, &mlinespan)){
if (nsnull != aSaveBlendArea){
oldsize = mSaveLS * mSaveNumLines;
// allocate some memory
mSaveLS = numbytes;
mSaveNumLines = numlines;
size = mSaveLS * numlines;
mSaveNumBytes = numbytes;
if(mSaveBytes != nsnull) {
if(oldsize != size){
delete [] mSaveBytes;
mSaveBytes = new unsigned char[size];
}
} else
mSaveBytes = new unsigned char[size];
mRestorePtr = d1;
mResLS = dlinespan;
}
if (CalcAlphaMetrics(&mSrcInfo, &mDstInfo,
((nsnull != mSecondSrcbinfo) || (PR_TRUE == secondsrcissurf)) ? &mSecondSrcInfo : nsnull,
&srcloc, NULL, &maskloc, aWidth, aHeight, &numlines, &numbytes,
&s1, &d1, &ssl, &m1, &slinespan, &dlinespan, &mlinespan)){
if (mSrcInfo.bmBitsPixel == mDstInfo.bmBitsPixel){
// now do the blend
switch (mSrcInfo.bmBitsPixel){
case 32:
if (!mask){
level = (PRInt32)(100 - aSrcOpacity*100);
Do32Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,nsHighQual,aSaveBlendArea);
level = (PRInt32)(aSrcOpacity*100);
Do32Blend(level,numlines,numbytes,s1,d1,ssl,slinespan,dlinespan,nsHighQual,aSrcBackColor,aSecondSrcBackColor);
result = NS_OK;
}else
result = NS_ERROR_FAILURE;
@ -247,19 +260,19 @@ nsDrawingSurfaceWin *SrcWinSurf,*DstWinSurf;
case 24:
if (mask){
Do24BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,nsHighQual,aSaveBlendArea);
Do24BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,nsHighQual);
result = NS_OK;
}else{
level = (PRInt32)(100 - aSrcOpacity*100);
Do24Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,nsHighQual,aSaveBlendArea);
level = (PRInt32)(aSrcOpacity*100);
Do24Blend(level,numlines,numbytes,s1,d1,ssl,slinespan,dlinespan,nsHighQual,aSrcBackColor,aSecondSrcBackColor);
result = NS_OK;
}
break;
case 16:
if (!mask){
level = (PRInt32)(100 - aSrcOpacity*100);
Do16Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,nsHighQual,aSaveBlendArea);
level = (PRInt32)(aSrcOpacity*100);
Do16Blend(level,numlines,numbytes,s1,d1,ssl,slinespan,dlinespan,nsHighQual,aSrcBackColor,aSecondSrcBackColor);
result = NS_OK;
}
else
@ -268,12 +281,12 @@ nsDrawingSurfaceWin *SrcWinSurf,*DstWinSurf;
case 8:
if (mask){
Do8BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,nsHighQual,aSaveBlendArea);
Do8BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,nsHighQual);
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);
level = (PRInt32)(aSrcOpacity*100);
Do8Blend(level,numlines,numbytes,s1,d1,ssl,slinespan,dlinespan,thespace,nsHighQual,aSrcBackColor,aSecondSrcBackColor);
result = NS_OK;
IL_ReleaseColorSpace(thespace);
}
@ -289,7 +302,7 @@ nsDrawingSurfaceWin *SrcWinSurf,*DstWinSurf;
::DeleteObject(tb1);
}
} else
result == NS_ERROR_FAILURE;
result = NS_ERROR_FAILURE;
}
#ifdef NGLAYOUT_DDRAW
@ -298,58 +311,14 @@ nsDrawingSurfaceWin *SrcWinSurf,*DstWinSurf;
if (PR_TRUE == dstissurf)
DstWinSurf->mSurface->Unlock(mDstSurf.lpSurface);
if (PR_TRUE == secondsrcissurf)
SecondSrcWinSurf->mSurface->Unlock(mSecondSrcSurf.lpSurface);
#endif
return result;
}
/** --------------------------------------------------------------------------
* Replace the bits saved from the last blend if the restore flag was set
* @update dc - 10/29/98
* @param aDst -- Destination drawing surface to restore to
* @result PR_TRUE if the restore worked.
*/
NS_IMETHODIMP
nsBlenderWin::RestoreImage(nsDrawingSurface aDst)
{
nsresult result = NS_ERROR_FAILURE;
PRInt32 y,x;
PRUint8 *saveptr,*savebyteptr;
PRUint8 *orgptr,*orgbyteptr;
HDC dstdc;
HBITMAP dstbits, tb1;
//XXX this is busted with directdraw... MMP
if(mSaveBytes!=nsnull){
result = NS_OK;
saveptr = mSaveBytes;
orgptr = mRestorePtr;
for(y=0;y<mSaveNumLines;y++){
savebyteptr = saveptr;
orgbyteptr = orgptr;
for(x=0;x<mSaveNumBytes;x++){
*orgbyteptr = *savebyteptr;
savebyteptr++;
orgbyteptr++;
}
saveptr+=mSaveLS;
orgptr+=mResLS;
}
// put the new bits in
dstdc = ((nsDrawingSurfaceWin *)aDst)->mDC;
dstbits = ::CreateDIBitmap(dstdc, mDstbinfo, CBM_INIT, mDstBytes, (LPBITMAPINFO)mDstbinfo, DIB_RGB_COLORS);
tb1 = (HBITMAP)::SelectObject(dstdc,dstbits);
::DeleteObject(tb1);
}
return result;
}
#ifdef NGLAYOUT_DDRAW
/** --------------------------------------------------------------------------
@ -418,11 +387,13 @@ PRBool nsBlenderWin :: LockSurface(IDirectDrawSurface *aSurface, DDSURFACEDESC *
* @result PR_TRUE if calculation was succesful
*/
PRBool
nsBlenderWin::CalcAlphaMetrics(BITMAP *aSrcInfo,BITMAP *aDestInfo,nsPoint *aSrcUL,
nsBlenderWin::CalcAlphaMetrics(BITMAP *aSrcInfo,BITMAP *aDestInfo, BITMAP *aSecondSrcInfo,
nsPoint *aSrcUL,
BITMAP *aMaskInfo,nsPoint *aMaskUL,
PRInt32 aWidth,PRInt32 aHeight,
PRInt32 *aNumlines,
PRInt32 *aNumbytes,PRUint8 **aSImage,PRUint8 **aDImage,
PRUint8 **aSecondSImage,
PRUint8 **aMImage,PRInt32 *aSLSpan,PRInt32 *aDLSpan,PRInt32 *aMLSpan)
{
PRBool doalpha = PR_FALSE;
@ -463,8 +434,11 @@ PRInt32 startx,starty;
*aSLSpan = mSRowBytes;
startx = drect.x;
starty = aSrcInfo->bmHeight - (drect.y + drect.height);
*aSImage = ((PRUint8*)aSrcInfo->bmBits) + (starty * (*aSLSpan)) + ((aDestInfo->bmBitsPixel >> 3) * startx);
*aSImage = ((PRUint8*)aSrcInfo->bmBits) + (starty * (*aSLSpan)) + ((aSrcInfo->bmBitsPixel >> 3) * startx);
if (nsnull != aSecondSrcInfo)
*aSecondSImage = ((PRUint8*)aSecondSrcInfo->bmBits) + (starty * (*aSLSpan)) + ((aSrcInfo->bmBitsPixel >> 3) * startx);
doalpha = PR_TRUE;
if(aMaskInfo){
@ -575,8 +549,8 @@ void
nsBlenderWin::DeleteDIB(LPBITMAPINFOHEADER *aBHead,unsigned char **aBits)
{
delete[] *aBHead;
aBHead = 0;
delete[] *aBits;
aBits = 0;
*aBHead = nsnull;
delete[] *aBits;
*aBits = nsnull;
}

Просмотреть файл

@ -50,9 +50,9 @@ public:
NS_IMETHOD Init(nsIDeviceContext *aDeviceCon);
NS_IMETHOD Blend(PRInt32 aSX, PRInt32 aSY, PRInt32 aWidth, PRInt32 aHeight,nsDrawingSurface aSrc,
nsDrawingSurface aDest, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity,PRBool aSaveBlendArea);
NS_IMETHOD RestoreImage(nsDrawingSurface aDst);
nsDrawingSurface aDest, PRInt32 aDX, PRInt32 aDY, float aSrcOpacity,
nsDrawingSurface aSecondSrc = nsnull, nscolor aSrcBackColor = NS_RGB(0, 0, 0),
nscolor aSecondSrcBackColor = NS_RGB(0, 0, 0));
private:
@ -76,12 +76,14 @@ public:
* @param aMLSpan -- number of bytes per span for the mask
* @result PR_TRUE if calculation was succesful
*/
PRBool CalcAlphaMetrics(BITMAP *aSrcInfo,BITMAP *aDestInfo,nsPoint *ASrcUL,
BITMAP *aMapInfo,nsPoint *aMaskUL,
PRInt32 aWidth,PRInt32 aHeight,
PRInt32 *aNumlines,
PRInt32 *aNumbytes,PRUint8 **aSImage,PRUint8 **aDImage,
PRUint8 **aMImage,PRInt32 *aSLSpan,PRInt32 *aDLSpan,PRInt32 *aMLSpan);
PRBool CalcAlphaMetrics(BITMAP *aSrcInfo,BITMAP *aDestInfo,
BITMAP *aSecondSrcInfo, nsPoint *ASrcUL,
BITMAP *aMapInfo,nsPoint *aMaskUL,
PRInt32 aWidth,PRInt32 aHeight,
PRInt32 *aNumlines,
PRInt32 *aNumbytes,PRUint8 **aSImage,PRUint8 **aDImage,
PRUint8 **aSecondSImage,
PRUint8 **aMImage,PRInt32 *aSLSpan,PRInt32 *aDLSpan,PRInt32 *aMLSpan);
/**
@ -117,21 +119,18 @@ public:
#endif
private:
BITMAPINFOHEADER *mDstbinfo, *mSrcbinfo;
BITMAPINFOHEADER *mDstbinfo, *mSrcbinfo, *mSecondSrcbinfo;
PRUint8 *mSrcBytes;
PRUint8 *mSecondSrcBytes;
PRUint8 *mDstBytes;
BITMAP mSrcInfo, mDstInfo;
BITMAP mSrcInfo, mDstInfo, mSecondSrcInfo;
PRInt32 mSRowBytes;
PRInt32 mDRowBytes;
PRInt32 mSaveNumLines;
PRInt32 mSaveNumBytes;
PRUint8 *mRestorePtr; // starting area of save dst
PRUint32 mResLS; // line span for restore area
#ifdef NGLAYOUT_DDRAW
DDSURFACEDESC mSrcSurf;
DDSURFACEDESC mSecondSrcSurf;
DDSURFACEDESC mDstSurf;
#endif
};