From 76471f424eb75e724570c6962fa701dc0bbbbb63 Mon Sep 17 00:00:00 2001 From: dcone Date: Wed, 20 May 1998 21:12:38 +0000 Subject: [PATCH] put in the inverse color table routine and did 8 bit alpha git-svn-id: svn://10.0.0.236/trunk@2052 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/src/nsIImage.h | 19 +- mozilla/gfx/src/windows/nsImageWin.cpp | 546 +++++++++++++++++++++++-- mozilla/gfx/src/windows/nsImageWin.h | 45 +- mozilla/gfx/tests/btest/BitTest.cpp | 103 +++-- 4 files changed, 625 insertions(+), 88 deletions(-) diff --git a/mozilla/gfx/src/nsIImage.h b/mozilla/gfx/src/nsIImage.h index 7fdb91d1420..bff1b95e915 100644 --- a/mozilla/gfx/src/nsIImage.h +++ b/mozilla/gfx/src/nsIImage.h @@ -43,9 +43,11 @@ typedef enum { } nsMaskRequirements; typedef enum{ - nsHighQual, + nsLowQual=0, + nsLowMedQual, nsMedQual, - nsLowQual + nsHighMedQual, + nsHighQual, }nsBlendQuality; @@ -215,6 +217,19 @@ public: */ virtual nsIImage* DuplicateImage() = 0; + + /** + * Set the alpha level for the image + * @param the alpha level to set for the image, from 0 to 100% + */ + virtual void SetAlphaLevel(PRInt32 aAlphaLevel) = 0; + + /** + * Get the alpha level for the image + * @return the alpha level for the image, from 0 to 100% + */ + virtual PRInt32 GetAlphaLevel() = 0; + //get the color space metrics for this image //virtual NI_ColorSpec * GetColorSpec() = 0; fix diff --git a/mozilla/gfx/src/windows/nsImageWin.cpp b/mozilla/gfx/src/windows/nsImageWin.cpp index 999b381df20..8189f957ed3 100644 --- a/mozilla/gfx/src/windows/nsImageWin.cpp +++ b/mozilla/gfx/src/windows/nsImageWin.cpp @@ -16,6 +16,7 @@ * Reserved. */ + #include "nsImageWin.h" #include "nsRenderingContextWin.h" @@ -265,11 +266,44 @@ PRBool nsImageWin :: Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurfa void nsImageWin::CompositeImage(nsIImage *aTheImage, nsPoint *aULLocation,nsBlendQuality aBlendQuality) { - // call the correct sub routine for each blend +PRInt32 dlinespan,slinespan,mlinespan,numbytes,numlines,level; +PRUint8 *alphabits,*s1,*d1,*m1; - if ((mNumBytesPixel == 3) && (((nsImageWin *)aTheImage)->mNumBytesPixel == 3)) - this->Comp24to24((nsImageWin*)aTheImage, aULLocation,aBlendQuality); + // optimized bitmaps cannot be composited, "YET" + if( IsOptimized() ) + return; + if(CalcAlphaMetrics(aTheImage,aULLocation,&numlines,&numbytes,&s1,&d1,&m1,&slinespan,&dlinespan,&mlinespan)) + { + alphabits = aTheImage->GetAlphaBits(); + + if ((mNumBytesPixel == 3) && (((nsImageWin *)aTheImage)->mNumBytesPixel == 3)) + { + if(alphabits) + { + numbytes/=3; // since the mask is only 8 bits, this routine wants number of pixels + Do24BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,aBlendQuality); + } + else + { + level = aTheImage->GetAlphaLevel(); + Do24Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,aBlendQuality); + } + } + else + if ((mNumBytesPixel == 1) && (((nsImageWin *)aTheImage)->mNumBytesPixel == 1)) + { + if(alphabits) + { + Do8BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,aBlendQuality); + } + else + { + level = aTheImage->GetAlphaLevel(); + Do8Blend(level,numlines,numbytes,s1,d1,slinespan,dlinespan,aBlendQuality); + } + } + } } //------------------------------------------------------------ @@ -338,7 +372,7 @@ PRUint8 *alphabits; *aNumlines = irect.height; startx = irect.x; starty = this->GetHeight() - (irect.y + irect.height); - *aDImage = mImageBits + (starty * (*aDLSpan)) + (3 * startx); + *aDImage = mImageBits + (starty * (*aDLSpan)) + (mNumBytesPixel * startx); // get the intersection relative to the source rectangle srect.SetRect(0, 0, aTheImage->GetWidth(), aTheImage->GetHeight()); @@ -349,9 +383,8 @@ PRUint8 *alphabits; *aSLSpan = aTheImage->GetLineStride(); startx = drect.x; starty = aTheImage->GetHeight() - (drect.y + drect.height); - *aSImage = aTheImage->GetBits() + (starty * (*aSLSpan)) + (3 * startx); + *aSImage = aTheImage->GetBits() + (starty * (*aSLSpan)) + (mNumBytesPixel * startx); - // 24 bit doalpha = PR_TRUE; if(alphabits) @@ -371,41 +404,14 @@ PRUint8 *alphabits; //------------------------------------------------------------ -// this routine has to flip the y, since the bits are in bottom scan -// line to top. -void nsImageWin::Comp24to24(nsImageWin *aTheImage,nsPoint *aULLocation,nsBlendQuality aBlendQuality) -{ -nsRect arect,srect,drect,irect; -PRInt32 dlinespan,slinespan,mlinespan,numbytes,numlines; -PRUint8 *alphabits,*s1,*d1,*m1; - - if( IsOptimized() ) - return; - - if(CalcAlphaMetrics(aTheImage,aULLocation,&numlines,&numbytes,&s1,&d1,&m1,&slinespan,&dlinespan,&mlinespan)) - { - alphabits = aTheImage->GetAlphaBits(); - if(alphabits) - { - numbytes/=3; // since the mask is only 8 bits, this routine wants number of pixels - Do24BlendWithMask(numlines,numbytes,s1,d1,m1,slinespan,dlinespan,mlinespan,aBlendQuality); - } - else - { - Do24Blend(128,numlines,numbytes,s1,d1,slinespan,dlinespan,aBlendQuality); - } - } -} - -//------------------------------------------------------------ - // This routine can not be fast enough void nsImageWin::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; -PRUint32 val1,val2,temp1,numlines,xinc,yinc; +PRUint32 val1,val2; +PRUint32 temp1,numlines,xinc,yinc; PRInt32 sspan,dspan,mspan; sspan = aSLSpan; @@ -467,15 +473,18 @@ void nsImageWin::Do24Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality) { PRUint8 *d1,*d2,*s1,*s2; -PRInt32 x,y,val1,val2,temp1,numlines,xinc,yinc;; +PRUint32 val1,val2; +PRInt32 x,y,temp1,numlines,xinc,yinc; + aBlendVal = (aBlendVal*255)/100; + val2 = aBlendVal; + val1 = 255-val2; + // now go thru the image and blend (remember, its bottom upwards) s1 = aSImage; d1 = aDImage; - val1 = aBlendVal; - val2 = 255-val1; numlines = aNumlines; xinc = 1; @@ -504,6 +513,157 @@ PRInt32 x,y,val1,val2,temp1,numlines,xinc,yinc;; //------------------------------------------------------------ +// This routine can not be fast enough +void +nsImageWin::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; +PRUint32 val1,val2,temp1,numlines,xinc,yinc; +PRInt32 sspan,dspan,mspan; + + sspan = aSLSpan; + dspan = aDLSpan; + mspan = aMLSpan; + + // now go thru the image and blend (remember, its bottom upwards) + s1 = aSImage; + d1 = aDImage; + m1 = aMImage; + + numlines = aNumlines; + xinc = 1; + yinc = 1; + + for (y = 0; y < aNumlines; y++) + { + s2 = s1; + d2 = d1; + m2 = m1; + + for(x=0;x>8; + if(temp1>255) + temp1 = 255; + *d2 = (unsigned char)temp1; + d2++; + s2++; + m2++; + } + s1 += sspan; + d1 += dspan; + m1 += mspan; + } +} + +//------------------------------------------------------------ + +extern void inv_cmap(PRInt16 colors,PRUint8 *aCMap,PRInt16 bits,PRUint32 *dist_buf,PRUint8 *aRGBMap ); + +// This routine can not be fast enough +void +nsImageWin::Do8Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage,PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality) +{ +PRUint32 r,g,b,r1,g1,b1,i; +PRUint8 *d1,*d2,*s1,*s2; +PRInt32 x,y,val1,val2,numlines,xinc,yinc;; +PRUint8 *mapptr,*invermap; +PRUint32 *distbuffer; +PRUint32 quantlevel,tnum,num,shiftnum; + + aBlendVal = (aBlendVal*255)/100; + val2 = aBlendVal; + val1 = 255-val2; + + // calculate the inverse map + mapptr = mColorMap->Index; + quantlevel = aBlendQuality+2; + shiftnum = (8-quantlevel)+8; + tnum = 2; + for(i=1;iIndex[(3 * i) + 2]; + g = mColorMap->Index[(3 * i) + 1]; + b = mColorMap->Index[(3 * i)]; + + i =(*s2); + r1 = mColorMap->Index[(3 * i) + 2]; + g1 = mColorMap->Index[(3 * i) + 1]; + b1 = mColorMap->Index[(3 * i)]; + + r = ((r*val1)+(r1*val2))>>shiftnum; + if(r>tnum) + r = tnum; + + g = ((g*val1)+(g1*val2))>>shiftnum; + if(g>tnum) + g = tnum; + + b = ((b*val1)+(b1*val2))>>shiftnum; + if(b>tnum) + b = tnum; + + r = (r<<(2*quantlevel))+(g<Index; + int i; + + mapptr = mColorMap->Index; + for (i=0; i < mColorMap->NumColors; i++) + { + *mapptr++ = i; + *mapptr++ = i; + *mapptr++ = i; + } + }*/ + + delete[] distbuffer; + delete[] invermap; + +} + +//------------------------------------------------------------ + nsIImage* nsImageWin::DuplicateImage() { @@ -518,8 +678,8 @@ nsImageWin *theimage; NS_ADDREF(theimage); // get the header and copy it - theimage->mBHead = (LPBITMAPINFOHEADER)new char[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * theimage->mNumPalleteColors]; - num = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * theimage->mNumPalleteColors; + theimage->mBHead = (LPBITMAPINFOHEADER)new char[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * this->mNumPalleteColors]; + num = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * this->mNumPalleteColors; memcpy(theimage->mBHead,this->mBHead,num); // set in compute metrics @@ -652,7 +812,7 @@ PRBool nsImageWin :: SetSystemPalette(HDC* aHdc) // creates an optimized bitmap, or HBITMAP nsresult nsImageWin :: Optimize(nsDrawingSurface aSurface) { - return NS_OK; // TAKE THIS OUT + //return NS_OK; // TAKE THIS OUT HDC the_hdc = (HDC)aSurface; @@ -723,9 +883,9 @@ void nsImageWin :: ComputeMetrics() mColorTable = (PRUint8 *)mBHead + sizeof(BITMAPINFOHEADER); } - //------------------------------------------------------------ + // clean up our memory void nsImageWin :: CleanUp(PRBool aCleanUpAll) { @@ -775,3 +935,305 @@ void nsImageWin :: CleanUp(PRBool aCleanUpAll) mImageBits = nsnull; mColorMap = nsnull; } + +//------------------------------------------------------------ + +static PRInt32 bcenter, gcenter, rcenter; +static PRUint32 gdist, rdist, cdist; +static PRInt32 cbinc, cginc, crinc; +static PRUint32 *gdp, *rdp, *cdp; +static PRUint8 *grgbp, *rrgbp, *crgbp; +static PRInt32 gstride, rstride; +static PRInt32 x, xsqr, colormax; +static PRInt32 cindex; + + +static void maxfill(PRUint32 *buffer,PRInt32 side ); +static PRInt32 redloop( void ); +static PRInt32 greenloop( PRInt32 ); +static PRInt32 blueloop( PRInt32 ); + +void +inv_cmap(PRInt16 colors,PRUint8 *aCMap,PRInt16 aBits,PRUint32 *dist_buf,PRUint8 *aRGBMap ) +{ +PRInt32 nbits = 8 - aBits; +PRUint32 r,g,b; + + colormax = 1 << aBits; + x = 1 << nbits; + xsqr = 1 << (2 * nbits); + + // Compute "strides" for accessing the arrays. */ + gstride = colormax; + rstride = colormax * colormax; + + maxfill( dist_buf, colormax ); + + for (cindex = 0;cindex < colors;cindex++ ) + { + r = aCMap[(3 * cindex) + 2]; + g = aCMap[(3 * cindex) + 1]; + b = aCMap[(3 * cindex)]; + + rcenter = r >> nbits; + gcenter = g >> nbits; + bcenter = b >> nbits; + + rdist = r - (rcenter * x + x/2); + gdist = g - (gcenter * x + x/2); + cdist = b - (bcenter * x + x/2); + cdist = rdist*rdist + gdist*gdist + cdist*cdist; + + crinc = 2 * ((rcenter + 1) * xsqr - (r * x)); + cginc = 2 * ((gcenter + 1) * xsqr - (g * x)); + cbinc = 2 * ((bcenter + 1) * xsqr - (b * x)); + + // Array starting points. + cdp = dist_buf + rcenter * rstride + gcenter * gstride + bcenter; + crgbp = aRGBMap + rcenter * rstride + gcenter * gstride + bcenter; + + (void)redloop(); + } +} + +//------------------------------------------------------------ + +// redloop -- loop up and down from red center. +static PRInt32 +redloop() +{ +PRInt32 detect,r,first; +PRInt32 txsqr = xsqr + xsqr; +static PRInt32 rxx; + + detect = 0; + + rdist = cdist; + rxx = crinc; + rdp = cdp; + rrgbp = crgbp; + first = 1; + for (r=rcenter;r=0;r--,rdp-=rstride,rrgbp-=rstride,rxx-=txsqr,rdist-=rxx,first=0) + { + if ( greenloop( first ) ) + detect = 1; + else + if ( detect ) + break; + } + + return detect; +} + +// greenloop -- loop up and down from green center. +static PRInt32 +greenloop(PRInt32 aRestart) +{ +PRInt32 detect,g,first; +PRInt32 txsqr = xsqr + xsqr; +static PRInt32 here, min, max; +static PRInt32 ginc, gxx, gcdist; +static PRUint32 *gcdp; +static PRUint8 *gcrgbp; + + if(aRestart) + { + here = gcenter; + min = 0; + max = colormax - 1; + ginc = cginc; + } + + detect = 0; + + + gcdp=rdp; + gdp=rdp; + gcrgbp=rrgbp; + grgbp=rrgbp; + gcdist=rdist; + gdist=rdist; + + // loop up. + for(g=here,gxx=ginc,first=1;g<=max; + g++,gdp+=gstride,gcdp+=gstride,grgbp+=gstride,gcrgbp+=gstride, + gdist+=gxx,gcdist+=gxx,gxx+=txsqr,first=0) + { + if(blueloop(first)) + { + if (!detect) + { + if (g>here) + { + here = g; + rdp = gcdp; + rrgbp = gcrgbp; + rdist = gcdist; + ginc = gxx; + } + detect=1; + } + } + else + if (detect) + { + break; + } + } + + // loop down + gcdist = rdist-gxx; + gdist = gcdist; + gdp=rdp-gstride; + gcdp=gdp; + grgbp=rrgbp-gstride; + gcrgbp = grgbp; + + for (g=here-1,gxx=ginc-txsqr, + first=1;g>=min;g--,gdp-=gstride,gcdp-=gstride,grgbp-=gstride,gcrgbp-=gstride, + gxx-=txsqr,gdist-=gxx,gcdist-=gxx,first=0) + { + if (blueloop(first)) + { + if (!detect) + { + here = g; + rdp = gcdp; + rrgbp = gcrgbp; + rdist = gcdist; + ginc = gxx; + detect = 1; + } + } + else + if ( detect ) + { + break; + } + } + return detect; +} + +static PRInt32 +blueloop(PRInt32 aRestart ) +{ +PRInt32 detect,b,i=cindex; +register PRUint32 *dp; +register PRUint8 *rgbp; +register PRInt32 bxx; +PRUint32 bdist; +register PRInt32 txsqr = xsqr + xsqr; +register PRInt32 lim; +static PRInt32 here, min, max; +static PRInt32 binc; + + if (aRestart) + { + here = bcenter; + min = 0; + max = colormax - 1; + binc = cbinc; + } + + detect = 0; + bdist = gdist; + +// Basic loop, finds first applicable cell. + for (b=here,bxx=binc,dp=gdp,rgbp=grgbp,lim=max;b<=lim; + b++,dp++,rgbp++,bdist+=bxx,bxx+=txsqr) + { + if(*dp>bdist) + { + if(b>here) + { + here = b; + gdp = dp; + grgbp = rgbp; + gdist = bdist; + binc = bxx; + } + detect = 1; + break; + } + } + +// Second loop fills in a run of closer cells. +for (;b<=lim;b++,dp++,rgbp++,bdist+=bxx,bxx+=txsqr) + { + if (*dp>bdist) + { + *dp = bdist; + *rgbp = i; + } + else + { + break; + } + } + +// Basic loop down, do initializations here +lim = min; +b = here - 1; +bxx = binc - txsqr; +bdist = gdist - bxx; +dp = gdp - 1; +rgbp = grgbp - 1; + +// The 'find' loop is executed only if we didn't already find something. +if (!detect) + for (;b>=lim;b--,dp--,rgbp--,bxx-=txsqr,bdist-=bxx) + { + if (*dp>bdist) + { + here = b; + gdp = dp; + grgbp = rgbp; + gdist = bdist; + binc = bxx; + detect = 1; + break; + } + } + +// Update loop. +for (;b>=lim;b--,dp--,rgbp--,bxx-=txsqr,bdist-=bxx) + { + if (*dp>bdist) + { + *dp = bdist; + *rgbp = i; + } + else + { + break; + } + } + +// If we saw something, update the edge trackers. +return detect; +} + +static void +maxfill(PRUint32 *buffer,PRInt32 side ) +{ +register PRInt32 maxv = ~0L; +register PRInt32 i; +register PRUint32 *bp; + +for (i=side*side*side,bp=buffer;i>0;i--,bp++) + *bp = maxv; +} diff --git a/mozilla/gfx/src/windows/nsImageWin.h b/mozilla/gfx/src/windows/nsImageWin.h index b55b7c11864..f5334cd9ddf 100644 --- a/mozilla/gfx/src/windows/nsImageWin.h +++ b/mozilla/gfx/src/windows/nsImageWin.h @@ -98,6 +98,10 @@ public: PRBool SetAlphaMask(nsIImage *aTheMask); + virtual void SetAlphaLevel(PRInt32 aAlphaLevel) {mAlphaLevel=aAlphaLevel;} + + virtual PRInt32 GetAlphaLevel() {return(mAlphaLevel);} + void MoveAlphaMask(PRInt32 aX, PRInt32 aY){mLocation.x=aX;mLocation.y=aY;} private: @@ -133,6 +137,37 @@ private: PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality); + /** + * Blend two 8 bit image arrays using an 8 bit alpha mask + * @param aNumlines Number of lines to blend + * @param aNumberBytes Number of bytes per line to blend + * @param aSImage Pointer to beginning of the source bytes + * @param aDImage Pointer to beginning of the destination bytes + * @param aMImage Pointer to beginning of the mask bytes + * @param aSLSpan number of bytes per line for the source bytes + * @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 + */ + void Do8BlendWithMask(PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage, + PRUint8 *aMImage,PRInt32 aSLSpan,PRInt32 aDLSpan,PRInt32 aMLSpan,nsBlendQuality aBlendQuality); + + /** + * Blend two 8 bit image arrays using a passed in blend value + * @param aNumlines Number of lines to blend + * @param aNumberBytes Number of bytes per line to blend + * @param aSImage Pointer to beginning of the source bytes + * @param aDImage Pointer to beginning of the destination bytes + * @param aMImage Pointer to beginning of the mask bytes + * @param aSLSpan number of bytes per line for the source bytes + * @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 + */ + void Do8Blend(PRUint8 aBlendVal,PRInt32 aNumlines,PRInt32 aNumbytes,PRUint8 *aSImage,PRUint8 *aDImage, + PRInt32 aSLSpan,PRInt32 aDLSpan,nsBlendQuality aBlendQuality); + + /** * Calculate the information we need to do a blend * @param aNumlines Number of lines to blend @@ -161,14 +196,6 @@ private: */ void ComputePaletteSize(PRIntn aBitCount); - /** - * Composite a 24 bit image into another 24 bit image - * @param aTheImage The image to blend into this image - * @param aULLocation The upper left coordinate to place the passed in image - * @param aBlendQuality The quality of this blend, this is for tweening if neccesary - */ - void Comp24to24(nsImageWin *aTheImage,nsPoint *aULLocation,nsBlendQuality aBlendQuality); - /** * Calculate the amount of memory needed for the initialization of the pixelmap @@ -194,7 +221,7 @@ private: PRInt16 mAlphaHeight; // alpha layer height nsPoint mLocation; // alpha mask location PRInt8 mImageCache; // place to save off the old image for fast animation - + PRInt16 mAlphaLevel; // an alpha level every pixel uses // for Set/GetColorMap HPALETTE mHPalette; diff --git a/mozilla/gfx/tests/btest/BitTest.cpp b/mozilla/gfx/tests/btest/BitTest.cpp index 0464fdc02bd..a37ed15f9a2 100644 --- a/mozilla/gfx/tests/btest/BitTest.cpp +++ b/mozilla/gfx/tests/btest/BitTest.cpp @@ -30,6 +30,7 @@ #include "nsIImageRequest.h" #include "nsIImageObserver.h" #include "nsIRenderingContext.h" +#include "nsIDeviceContext.h" #include "nsIImage.h" #include "nsIWidget.h" #include "nsGUIEvent.h" @@ -40,9 +41,16 @@ #include +#include "nsWidgetsCID.h" +#include "nsITextWidget.h" + +// widget interface +static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID); +static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID); + + static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); static NS_DEFINE_IID(kIImageObserverIID, NS_IIMAGEREQUESTOBSERVER_IID); - static NS_DEFINE_IID(kCWindowIID, NS_WINDOW_CID); static NS_DEFINE_IID(kCChildWindowIID, NS_CHILD_CID); static NS_DEFINE_IID(kCScrollbarIID, NS_VERTSCROLLBAR_CID); @@ -60,6 +68,9 @@ static nsIImage *gBlendImage = nsnull; static nsIImage *gMaskImage = nsnull; static PRBool gInstalledColorMap = PR_FALSE; static PRInt32 gXOff,gYOff,gTestNum; +static nsITextWidget *gBlendMessage; +static nsITextWidget *gQualMessage; + extern void Compositetest(PRInt32 aTestNum,nsIImage *aImage,nsIImage *aBImage,nsIImage *aMImage, PRInt32 aX, PRInt32 aY); extern PRInt32 speedtest(nsIImage *aTheImage,nsIRenderingContext *aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); @@ -134,7 +145,6 @@ MyBlendObserver::Notify(nsIImageRequest *aImageRequest, { nsColorMap *cmap = (*mImage)->GetColorMap(); nsRect *rect = (nsRect *)aParam3; - Compositetest(gTestNum,gImage,gBlendImage,gMaskImage,gXOff,gYOff); } } @@ -249,31 +259,49 @@ MyObserver::NotifyError(nsIImageRequest *aImageRequest, void Compositetest(PRInt32 aTestNum,nsIImage *aImage,nsIImage *aBImage,nsIImage *aMImage, PRInt32 aX, PRInt32 aY) { -nsPoint *location; +nsPoint location; PRUint32 min,seconds,milli,i,h,w; +PRInt32 numtemp,numerror; nsBlendQuality quality=nsMedQual; SYSTEMTIME thetime; nsIRenderingContext *drawCtx = gWindow->GetRenderingContext(); nsIImage *theimage; +nsString str; + // get the quality that we are going to blend to + gQualMessage->GetText(str,3); + quality = (nsBlendQuality)str.ToInteger(&numerror); + if(quality < nsLowQual) + quality = nsLowQual; + if(quality > nsHighQual) + quality = nsHighQual; - if(aTestNum == 1) + // set the blend amount + gBlendMessage->GetText(str,3); + numtemp = str.ToInteger(&numerror); + if(numtemp < 0) + numtemp = 0; + if(numtemp > 100) + numtemp = 100; + aBImage->SetAlphaLevel(numtemp); + + location.x=0; + location.y=0; + + if(aTestNum == 1) { - location = new nsPoint(aX,aY); + if(aMImage) { aBImage->SetAlphaMask(aMImage); aBImage->MoveAlphaMask(rand() % aImage->GetWidth(),rand() % aImage->GetHeight()); } - if(aMImage == nsnull) - { - location->x = rand() % aImage->GetWidth(); - location->y = rand() % aImage->GetHeight(); - printf("\n Image Location is %d, %d\n", location->x,location->y); - } - - aImage->CompositeImage(aBImage,location,quality); + theimage = aImage->DuplicateImage(); + nsIDeviceContext *dx = drawCtx->GetDeviceContext(); + theimage->ImageUpdated(dx, nsImageUpdateFlags_kColorMapChanged, nsnull); + theimage->CompositeImage(aBImage,&location,quality); + drawCtx->DrawImage(theimage, 0, 0, aImage->GetWidth(), aImage->GetHeight()); } // speed test @@ -284,7 +312,8 @@ nsIImage *theimage; min = thetime.wMinute; seconds = thetime.wSecond; milli = thetime.wMilliseconds; - location = new nsPoint(aX,aY); + location.x = aX; + location.y = aY; w = gImage->GetWidth(); h = gImage->GetHeight(); @@ -295,7 +324,7 @@ nsIImage *theimage; { aBImage->MoveAlphaMask(rand()%w,rand()%h); theimage = aImage->DuplicateImage(); - theimage->CompositeImage(aBImage,location,quality); + theimage->CompositeImage(aBImage,&location,quality); drawCtx->DrawImage(theimage, 0, 0, theimage->GetWidth(), theimage->GetHeight()); NS_RELEASE(theimage); @@ -306,6 +335,7 @@ nsIImage *theimage; } else { + nsIDeviceContext *dx = drawCtx->GetDeviceContext(); for(i=0;i<200;i++) { aBImage->MoveAlphaMask(rand()%w,rand()%h); @@ -315,9 +345,12 @@ nsIImage *theimage; //NS_RELEASE(theimage); // non buffered - aImage->CompositeImage(aBImage,location,quality); + aImage->CompositeImage(aBImage,&location,quality); + // let everyone know that the colors have changed + aImage->ImageUpdated(dx, nsImageUpdateFlags_kColorMapChanged, nsnull); drawCtx->DrawImage(aImage, 0, 0, aImage->GetWidth(), aImage->GetHeight()); } + NS_IF_RELEASE(dx); } ::GetSystemTime(&thetime); @@ -337,7 +370,8 @@ nsIImage *theimage; if(aTestNum == 3) { - location = new nsPoint(aX,aY); + location.x = aX; + location.y = aY; if(aMImage) { @@ -355,7 +389,7 @@ nsIImage *theimage; aBImage->MoveAlphaMask(cpos.x,cpos.y); theimage = aImage->DuplicateImage(); - theimage->CompositeImage(aBImage,location,quality); + theimage->CompositeImage(aBImage,&location,quality); drawCtx->DrawImage(theimage, 0, 0, theimage->GetWidth(), theimage->GetHeight()); NS_RELEASE(theimage); @@ -372,13 +406,13 @@ nsIImage *theimage; { aBImage->MoveAlphaMask(rand()%w,rand()%h); theimage = aImage->DuplicateImage(); - theimage->CompositeImage(aBImage,location,quality); + theimage->CompositeImage(aBImage,&location,quality); drawCtx->DrawImage(theimage, 0, 0, theimage->GetWidth(), theimage->GetHeight()); NS_RELEASE(theimage); } } - drawCtx->DrawImage(aImage, 0, 0, aImage->GetWidth(), aImage->GetHeight()); + //drawCtx->DrawImage(aImage, 0, 0, aImage->GetWidth(), aImage->GetHeight()); // we are finished with this if (gBlendImage) @@ -852,21 +886,6 @@ WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam) } gImageManager->SetCacheSize(1024*1024); break; - - /*case WM_MOUSEMOVE: - { - DWORD pos = ::GetMessagePos(); - POINT cpos; - - cpos.x = LOWORD(pos); - cpos.y = HIWORD(pos); - - ::ScreenToClient(hWnd, &cpos); - // Dothing(cpos.x, cpos.y); - - } - break;*/ - case WM_DESTROY: MyInterrupt(); MyReleaseImages(); @@ -898,6 +917,7 @@ WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam) static HWND CreateTopLevel(const char* clazz, const char* title,int aWidth, int aHeight) { + // Create a simple top level window HWND window = ::CreateWindowEx(WS_EX_CLIENTEDGE, clazz, title, @@ -913,11 +933,24 @@ static HWND CreateTopLevel(const char* clazz, const char* title,int aWidth, int nsresult rv = NSRepository::CreateInstance(kCChildWindowIID, NULL, kIWidgetIID, (void**)&gWindow); + if (NS_OK == rv) { gWindow->Create((nsNativeWindow)window, rect, MyHandleEvent, NULL); } + // something for input + NSRepository::RegisterFactory(kCTextFieldCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); + rect.SetRect(25, 370, 40, 25); + NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&gBlendMessage); + gBlendMessage->Create(gWindow, rect, nsnull, nsnull); + gBlendMessage->SetText("50"); + + rect.SetRect(70,370,40,25); + NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID, (void**)&gQualMessage); + gQualMessage->Create(gWindow, rect, nsnull, nsnull); + gQualMessage->SetText("3"); + ::ShowWindow(window, SW_SHOW); ::UpdateWindow(window); return window;