From 23c777f686bed6b575dcdc8803de74370bf00e50 Mon Sep 17 00:00:00 2001 From: dcone Date: Wed, 29 Apr 1998 20:28:16 +0000 Subject: [PATCH] Updated nsImageWin and gfx bit test for composite functionality --- gfx/src/nsIImage.h | 29 +++-- gfx/src/windows/nsImageWin.cpp | 14 +- gfx/src/windows/nsImageWin.h | 1 + gfx/tests/btest/BitTest.cpp | 230 +++++++++++++++++++++++++++++---- gfx/tests/btest/image.rc | 5 +- gfx/tests/btest/resources.h | 1 + 6 files changed, 239 insertions(+), 41 deletions(-) diff --git a/gfx/src/nsIImage.h b/gfx/src/nsIImage.h index c46141cd4e35..6b1aae7b1354 100644 --- a/gfx/src/nsIImage.h +++ b/gfx/src/nsIImage.h @@ -139,20 +139,29 @@ public: /** * BitBlit the pixelmap to a device, the source and dest can be scaled - @param aSurface the surface to blit to - @param aSX The source width of the pixelmap - @param aSY The source vertical location - @param aSWidth The source width of the pixelmap - @param aSHeight The source height of the pixelmap - @param aDX The destination horizontal location - @param aDY The destination vertical location - @param aDWidth The destination width of the pixelmap - @param aDHeight The destination height of the pixelmap - @return if TRUE, no errors + * @param aSurface the surface to blit to + * @param aSX The source width of the pixelmap + * @param aSY The source vertical location + * @param aSWidth The source width of the pixelmap + * @param aSHeight The source height of the pixelmap + * @param aDX The destination horizontal location + * @param aDY The destination vertical location + * @param aDWidth The destination width of the pixelmap + * @param aDHeight The destination height of the pixelmap + * @return if TRUE, no errors */ virtual PRBool Draw(nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight) = 0; + + /** + * Composite this image with the passed in image using the alpha mask + * @param aTheImage The image to blend into this image + * @param aULLocation The upper left coordinate to place the passed in image + */ + virtual void CompositeImage(nsIImage *aTheImage,nsPoint *aULLocation) = 0; + + //get the color space metrics for this image //virtual NI_ColorSpec * GetColorSpec() = 0; fix diff --git a/gfx/src/windows/nsImageWin.cpp b/gfx/src/windows/nsImageWin.cpp index 92c804d32d89..eeeef4bb1a4f 100644 --- a/gfx/src/windows/nsImageWin.cpp +++ b/gfx/src/windows/nsImageWin.cpp @@ -205,7 +205,19 @@ HDC the_hdc = (HDC)aSurface; //------------------------------------------------------------ -PRBool nsImageWin :: MakePalette() +void +nsImageWin::CompositeImage(nsIImage *aTheImage,nsPoint *aULLocation) +{ + + + + +} + +//------------------------------------------------------------ + +PRBool +nsImageWin::MakePalette() { // makes a logical palette (mHPalette) from the DIB's color table // this palette will be selected and realized prior to drawing the DIB diff --git a/gfx/src/windows/nsImageWin.h b/gfx/src/windows/nsImageWin.h index 1886c9c21f2e..aa34badc5f65 100644 --- a/gfx/src/windows/nsImageWin.h +++ b/gfx/src/windows/nsImageWin.h @@ -42,6 +42,7 @@ public: virtual PRBool Draw(nsDrawingSurface aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); virtual PRBool Draw(nsDrawingSurface aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight, PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight); + virtual void CompositeImage(nsIImage *aTheImage,nsPoint *aULLocation); virtual nsColorMap* GetColorMap() {return mColorMap;} virtual void ImageUpdated(PRUint8 aFlags, nsRect *aUpdateRect); virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements); diff --git a/gfx/tests/btest/BitTest.cpp b/gfx/tests/btest/BitTest.cpp index b9e452b045c8..bfdccd61961f 100644 --- a/gfx/tests/btest/BitTest.cpp +++ b/gfx/tests/btest/BitTest.cpp @@ -54,12 +54,122 @@ static nsIImageRequest *gImageReq = nsnull; static HWND gHwnd; static nsIWidget *gWindow = nsnull; static nsIImage *gImage = nsnull; +static nsIImage *gBlendImage = nsnull; static PRBool gInstalledColorMap = PR_FALSE; +extern void Compositetest(nsIImage *aTheImage,nsIImage *aBlendImage,nsIRenderingContext *aSurface, PRInt32 aX, PRInt32 aY); 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); extern PRInt32 arctest(nsIRenderingContext *aSurface); +extern PRBool IsImageLoaded(); + + + + +//------------------------------------------------------------ + + +class MyBlendObserver : public nsIImageRequestObserver +{ +private: + nsIImage **mImage; // address of pointer to put info into + +public: + MyBlendObserver(nsIImage **aImage); + //MyBlendObserver(); + ~MyBlendObserver(); + + NS_DECL_ISUPPORTS + + virtual void Notify(nsIImageRequest *aImageRequest,nsIImage *aImage, + nsImageNotification aNotificationType, + PRInt32 aParam1, PRInt32 aParam2,void *aParam3); + + virtual void NotifyError(nsIImageRequest *aImageRequest,nsImageError aErrorType); + +}; + +//------------------------------------------------------------ + +MyBlendObserver::MyBlendObserver(nsIImage **aImage) +{ + mImage = aImage; +} + +//------------------------------------------------------------ + +MyBlendObserver::~MyBlendObserver() +{ +} + +//------------------------------------------------------------ + +NS_IMPL_ISUPPORTS(MyBlendObserver, kIImageObserverIID) + +void +MyBlendObserver::Notify(nsIImageRequest *aImageRequest, + nsIImage *aImage, + nsImageNotification aNotificationType, + PRInt32 aParam1, PRInt32 aParam2, + void *aParam3) +{ + switch (aNotificationType) + { + case nsImageNotification_kDimensions: + break; + case nsImageNotification_kPixmapUpdate: + case nsImageNotification_kImageComplete: + case nsImageNotification_kFrameComplete: + { + if (*mImage == nsnull && aImage) + { + *mImage = aImage; + NS_ADDREF(aImage); + } + + + //if (gBlendImage == nsnull && aImage) + //{ + //gBlendImage = aImage; + //NS_ADDREF(aImage); + //} + + + if (!gInstalledColorMap && gBlendImage) + { + nsColorMap *cmap = (*mImage)->GetColorMap(); + + if(aNotificationType == nsImageNotification_kImageComplete) + { + nsIRenderingContext *drawCtx = gWindow->GetRenderingContext(); + Compositetest(gImage,gBlendImage,drawCtx,0,0); + } + + //if (cmap != nsnull && cmap->NumColors > 0) + //{ + //gWindow->SetColorMap(cmap); + //} + //gInstalledColorMap = PR_TRUE; + } + //nsRect *rect = (nsRect *)aParam3; + //nsIRenderingContext *drawCtx = gWindow->GetRenderingContext(); + + } + break; + } +} + +//------------------------------------------------------------ + +void +MyBlendObserver::NotifyError(nsIImageRequest *aImageRequest, + nsImageError aErrorType) +{ + ::MessageBox(NULL, "Blend Image loading error!",class1Name, MB_OK); +} + +//------------------------------------------------------------ class MyObserver : public nsIImageRequestObserver { @@ -77,6 +187,8 @@ public: }; + + //------------------------------------------------------------ MyObserver::MyObserver() @@ -134,14 +246,39 @@ MyObserver::Notify(nsIImageRequest *aImageRequest, nsIRenderingContext *drawCtx = gWindow->GetRenderingContext(); if (gImage) - { - drawCtx->DrawImage(gImage, 0, 0, gImage->GetWidth(), gImage->GetHeight()); - } + { + drawCtx->DrawImage(gImage, 0, 0, gImage->GetWidth(), gImage->GetHeight()); + } } break; } } +//------------------------------------------------------------ + +void +MyObserver::NotifyError(nsIImageRequest *aImageRequest, + nsImageError aErrorType) +{ + ::MessageBox(NULL, "Image loading error!",class1Name, MB_OK); +} + +//------------------------------------------------------------ + +// This tests the compositing for the image +void +Compositetest(nsIImage *aTheImage,nsIImage *aBlendImage,nsIRenderingContext *aSurface, PRInt32 aX, PRInt32 aY) +{ +PRInt32 swidth, sheight,bwidth,bheight; + + swidth = aTheImage->GetWidth(); + sheight = aTheImage->GetHeight(); + + bwidth = aBlendImage->GetWidth(); + bheight = aBlendImage->GetHeight(); +} + + //------------------------------------------------------------ // This tests the speed for the bliting, @@ -181,6 +318,7 @@ SYSTEMTIME thetime; return(milli); } + //------------------------------------------------------------ PRInt32 @@ -328,13 +466,6 @@ nscolor white,black; //------------------------------------------------------------ -void -MyObserver::NotifyError(nsIImageRequest *aImageRequest, - nsImageError aErrorType) -{ - ::MessageBox(NULL, "Image loading error!",class1Name, MB_OK); -} - nsEventStatus PR_CALLBACK MyHandleEvent(nsGUIEvent *aEvent) { @@ -394,13 +525,14 @@ MyInterrupt() #define FILE_URL_PREFIX "file://" void -MyLoadImage(char *aFileName) +MyLoadImage(char *aFileName,PRBool aGenLoad,nsIImage **aTheImage) { - char fileURL[256]; - char *str; +char fileURL[256]; +char *str; MyInterrupt(); - MyReleaseImages(); + if(aGenLoad!=PR_TRUE) + MyReleaseImages(); if (gImageGroup == NULL) { @@ -422,10 +554,21 @@ MyLoadImage(char *aFileName) *str = '/'; nscolor white; - MyObserver *observer = new MyObserver(); + + // set up which image gets loaded + if(aGenLoad == PR_TRUE) + { + MyBlendObserver *observer = new MyBlendObserver(aTheImage); + NS_ColorNameToRGB("white", &white); + gImageReq = gImageGroup->GetImage(fileURL,observer,white, 0, 0, 0); + } + else + { + MyObserver *observer = new MyObserver(); + NS_ColorNameToRGB("white", &white); + gImageReq = gImageGroup->GetImage(fileURL,observer,white, 0, 0, 0); + } - NS_ColorNameToRGB("white", &white); - gImageReq = gImageGroup->GetImage(fileURL,observer,white, 0, 0, 0); if (gImageReq == NULL) { ::MessageBox(NULL, "Couldn't create image request",class1Name, MB_OK); @@ -473,6 +616,25 @@ OpenFileDialog(char *aBuffer, int32 aBufLen) //------------------------------------------------------------ +PRBool +IsImageLoaded() +{ + + if(gImageGroup == NULL) // go get an image for the window + { + char szFile[256]; + + ::MessageBox(NULL, "Need To Open an Image",NULL, MB_OK); + + if (!OpenFileDialog(szFile, 256)) + return PR_FALSE; + MyLoadImage(szFile,PR_FALSE,NULL); + } + return PR_TRUE; +} + +//------------------------------------------------------------ + long PASCAL WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam) { @@ -491,27 +653,33 @@ WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam) if (!OpenFileDialog(szFile, 256)) return 0L; - MyLoadImage(szFile); + MyLoadImage(szFile,PR_FALSE,NULL); break; } case TIMER_EXIT: ::DestroyWindow(hWnd); exit(0); break; - case BSTNOOPT: - case BSTOPT: - - if(gImageGroup == NULL) // go get an image + case COMPTST: + IsImageLoaded(); + if(gImage) { char szFile[256]; + + if (gBlendImage!=nsnull) + { + NS_RELEASE(gBlendImage); + gBlendImage = nsnull; + } - ::MessageBox(NULL, "Need To Open an Image",NULL, MB_OK); - - if (!OpenFileDialog(szFile, 256)) - return 0L; - MyLoadImage(szFile); + if (OpenFileDialog(szFile, 256)) + MyLoadImage(szFile,PR_TRUE,&gBlendImage); } - if(gImageGroup != NULL && gImage) + break; + case BSTNOOPT: + case BSTOPT: + IsImageLoaded(); + if(gImage) { PRBool opt; nsIRenderingContext *drawCtx = gWindow->GetRenderingContext(); @@ -569,6 +737,12 @@ WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam) { NS_RELEASE(gImageManager); } + if (gBlendImage) + { + NS_RELEASE(gBlendImage); + gBlendImage = NULL; + } + PostQuitMessage(0); break; diff --git a/gfx/tests/btest/image.rc b/gfx/tests/btest/image.rc index 3cdc2c203ce1..a38f865d4bf7 100644 --- a/gfx/tests/btest/image.rc +++ b/gfx/tests/btest/image.rc @@ -28,8 +28,9 @@ IMAGETEST MENU DISCARDABLE POPUP "TEST" { - MENUITEM "BST NO Opt.",BSTNOOPT - MENUITEM "BST Opt.",BSTOPT + MENUITEM "Composite Test", COMPTST + MENUITEM "Blit Speed",BSTNOOPT + MENUITEM "Blit Speed, Optimzed.",BSTOPT MENUITEM "Draw Test",DRAWTEST MENUITEM "Fill Test",FILLTEST MENUITEM "Arc Test",ARCTEST diff --git a/gfx/tests/btest/resources.h b/gfx/tests/btest/resources.h index 531eb822aac2..07f0650c6f63 100644 --- a/gfx/tests/btest/resources.h +++ b/gfx/tests/btest/resources.h @@ -27,5 +27,6 @@ #define DRAWTEST 40014 #define FILLTEST 40015 #define ARCTEST 40016 +#define COMPTST 40017 #endif /* resources_h___ */