Back to index

lightning-sunbird  0.9+nobinonly
nsImageWin.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsImageWin_h___
00039 #define nsImageWin_h___
00040 
00041 #include <windows.h>
00042 #include "nsIImage.h"
00043 #include "nsCOMPtr.h"
00044 #include "nsITimer.h"
00045 
00046 // Remove DDB after 60s of non-use
00047 #define GFX_MS_REMOVE_DBB          60000
00048 
00049 /* for compatibility with VC++ 5 */
00050 #if !defined(AC_SRC_OVER)
00051 #define AC_SRC_OVER                 0x00
00052 #define AC_SRC_ALPHA                0x01
00053 #pragma pack(1)
00054 typedef struct {
00055     BYTE   BlendOp;
00056     BYTE   BlendFlags;
00057     BYTE   SourceConstantAlpha;
00058     BYTE   AlphaFormat;
00059 }BLENDFUNCTION;
00060 #pragma pack()
00061 #endif
00062 
00063 typedef BOOL (WINAPI *ALPHABLENDPROC)(
00064   HDC hdcDest,
00065   int nXOriginDest,
00066   int nYOriginDest,
00067   int nWidthDest,
00068   int hHeightDest,
00069   HDC hdcSrc,
00070   int nXOriginSrc,
00071   int nYOriginSrc,
00072   int nWidthSrc,
00073   int nHeightSrc,
00074   BLENDFUNCTION blendFunction);
00075 
00076 /* For gOsMajorVersion */
00077 #define VER_OSMAJOR_WINNT31        3
00078 #define VER_OSMAJOR_WIN9598MENT    4
00079 #define VER_OSMAJOR_WIN2KXP        5
00080 
00081 class nsImageWin : public nsIImage{
00082 public:
00083   nsImageWin();
00084   ~nsImageWin();
00085 
00086   NS_DECL_ISUPPORTS
00087 
00091   virtual PRInt32     GetBytesPix()       { return mNumBytesPixel; }
00092   virtual PRInt32     GetHeight()         { return mBHead->biHeight; }
00093   virtual PRBool      GetIsRowOrderTopToBottom() { return PR_FALSE; }
00094   virtual PRInt32     GetWidth()          { return mBHead->biWidth; }
00095   virtual PRUint8*    GetBits() ;
00096   virtual PRInt32     GetLineStride()     { return mRowBytes; }
00097 
00098   virtual PRBool      GetHasAlphaMask()   { return mAlphaBits != nsnull; }
00099 
00100   NS_IMETHOD          Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aX, PRInt32 aY,
00101                            PRInt32 aWidth, PRInt32 aHeight);
00102   NS_IMETHOD          Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aSX, PRInt32 aSY,
00103                            PRInt32 aSWidth, PRInt32 aSHeight,
00104                            PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00105   NS_IMETHOD          DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
00106                                   nscoord aDWidth, nscoord aDHeight);
00107   virtual nsColorMap* GetColorMap() {return mColorMap;}
00108   virtual void        ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect);
00109   virtual PRBool      GetIsImageComplete();
00110   virtual nsresult    Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
00111   virtual nsresult    Optimize(nsIDeviceContext* aContext);
00112   virtual PRUint8*    GetAlphaBits()      { return mAlphaBits; }
00113   virtual PRInt32     GetAlphaLineStride(){ return mARowBytes; }
00114 
00115 
00116   NS_IMETHOD DrawTile(nsIRenderingContext &aContext,
00117                       nsIDrawingSurface* aSurface,
00118                       PRInt32 aSXOffset, PRInt32 aSYOffset,
00119                       PRInt32 aPadX, PRInt32 aPadY,
00120                       const nsRect &aTileRect);
00121 
00126   PRIntn      GetSizeHeader(){return sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * mNumPaletteColors;}
00127 
00133   PRIntn      GetSizeImage(){ return mSizeImage; }
00134 
00140   PRInt32  CalcBytesSpan(PRUint32  aWidth);
00141 
00147   virtual PRInt8 GetAlphaDepth() {return(mAlphaDepth);}
00148 
00154   void* GetBitInfo() {return mBHead;}
00155 
00156   NS_IMETHOD   LockImagePixels(PRBool aMaskPixels);
00157   NS_IMETHOD   UnlockImagePixels(PRBool aMaskPixels);
00158 
00159   // VER_PLATFORM_WIN32_WINDOWS == Win 95/98/ME
00160   // VER_PLATFORM_WIN32_NT == Win NT/2K/XP/.NET Server
00161   static PRInt32 gPlatform;
00162   static PRInt32 gOsMajorVersion;
00163 
00166   NS_IMETHOD CreateDDB();
00169   NS_IMETHOD RemoveDDB();
00170 
00171 private:
00176   void CleanUpDIB();
00177 
00182   void CleanUpDDB();
00183 
00184   void CreateImageWithAlphaBits(HDC TheHDC);
00185 
00186   void DrawComposited24(unsigned char *aBits,
00187                         PRUint8 *aImageRGB, PRUint32 aStrideRGB,
00188                         PRUint8 *aImageAlpha, PRUint32 aStrideAlpha,
00189                         int aWidth, int aHeight);
00190   nsresult DrawComposited(HDC TheHDC, int aDX, int aDY, int aDWidth, int aDHeight,
00191                           int aSX, int aSY, int aSWidth, int aSHeight,
00192                           int aOrigDWidth, int aOrigDHeight);
00193   static PRBool CanAlphaBlend(void);
00194 
00199   nsresult ConvertDDBtoDIB();
00200 
00201 
00216   nsresult PrintDDB(nsIDrawingSurface* aSurface,
00217                     PRInt32 aDX, PRInt32 aDY,
00218                     PRInt32 aDWidth, PRInt32 aDHeight,
00219                     PRInt32 aSX, PRInt32 aSY,
00220                     PRInt32 aSWidth, PRInt32 aSHeight,
00221                     PRUint32 aROP);
00222 
00223 
00228   PRBool ProgressiveDoubleBlit(nsIDeviceContext *aContext,
00229                                nsIDrawingSurface* aSurface,
00230                                PRInt32 aSXOffset, PRInt32 aSYOffset,
00231                                nsRect aDestRect);
00232 
00251   void BlitImage(HDC aDstDC, HDC aDstMaskDC, PRInt32 aDstX, PRInt32 aDstY,
00252                  PRInt32 aWidth, PRInt32 aHeight,
00253                  HDC aSrcDC, HDC aSrcMaskDC, PRInt32 aSrcX, PRInt32 aSrcY,
00254                  PRBool aUseAlphaBlend);
00255   
00264   PRUint8 PaletteMatch(PRUint8 r, PRUint8 g, PRUint8 b);
00265 
00266   PRPackedBool        mInitialized;
00267   PRPackedBool        mWantsOptimization;
00268   PRPackedBool        mIsOptimized;       // Did we convert our DIB to a HBITMAP
00269   PRPackedBool        mIsLocked;          // variable to keep track of the locking
00270   PRPackedBool        mDIBTemp;           // boolean to let us know if DIB was created as temp
00271   PRPackedBool        mImagePreMultiplied;// Are the image bits pre-multiplied with alpha?
00272   PRInt8              mNumBytesPixel;     // number of bytes per pixel
00273   PRInt16             mNumPaletteColors;  // Number of colors in the pallete 256 
00274   PRInt32             mSizeImage;         // number of bytes
00275   PRInt32             mRowBytes;          // number of bytes per row
00276   PRUint8*            mImageBits;         // starting address of DIB bits
00277   nsColorMap*         mColorMap;          // Redundant with mColorTable, but necessary
00278 
00279   PRInt32             mDecodedX1;         //Keeps track of what part of image
00280   PRInt32             mDecodedY1;         // has been decoded.
00281   PRInt32             mDecodedX2; 
00282   PRInt32             mDecodedY2; 
00283 
00284   // alpha layer members
00285   PRUint8             *mAlphaBits;        // alpha layer if we made one
00286   PRInt8              mAlphaDepth;        // alpha layer depth
00287   PRInt32             mARowBytes;         // number of bytes per row in the image for tha alpha
00288   PRInt8              mImageCache;        // place to save off the old image for fast animation
00289   HBITMAP             mHBitmap;           // the GDI bitmaps
00290   LPBITMAPINFOHEADER  mBHead;             // BITMAPINFOHEADER
00291 
00292   static ALPHABLENDPROC gAlphaBlend;      // AlphaBlend function pointer
00293 
00294   nsCOMPtr<nsITimer>  mTimer;             // Timer for releasing DDB
00295   static void TimerCallBack(nsITimer *aTimer, void *aClosure);
00296 };
00297 
00298 #endif