Back to index

lightning-sunbird  0.9+nobinonly
nsImageXlib.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  *   Peter Hartshorn <peter@igelaus.com.au>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsImageXlib_h__
00040 #define nsImageXlib_h__
00041 
00042 #include "nsIImage.h"
00043 #include "nsPoint.h"
00044 #include "nsGCCache.h"
00045 #include "nsRegion.h"
00046 #include "xlibrgb.h"
00047 
00048 class nsImageXlib : public nsIImage {
00049 public:
00050   nsImageXlib();
00051   virtual ~nsImageXlib();
00052 
00053   NS_DECL_ISUPPORTS
00054 
00055   virtual PRInt32     GetBytesPix()       { return mNumBytesPixel; }
00056   virtual PRInt32     GetHeight();
00057   virtual PRInt32     GetWidth();
00058   virtual PRUint8*    GetBits();
00059   virtual void*       GetBitInfo();
00060   virtual PRBool      GetIsRowOrderTopToBottom() { return PR_TRUE; }
00061   virtual PRInt32     GetLineStride();
00062 
00063   virtual nsColorMap* GetColorMap();
00064 
00065   NS_IMETHOD Draw(nsIRenderingContext &aContext,
00066                   nsIDrawingSurface* aSurface,
00067                   PRInt32 aX, PRInt32 aY,
00068                   PRInt32 aWidth, PRInt32 aHeight);
00069   NS_IMETHOD Draw(nsIRenderingContext &aContext,
00070                   nsIDrawingSurface* aSurface,
00071                   PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
00072                   PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00073 
00074   NS_IMETHOD DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
00075                          nscoord aDWidth, nscoord aDHeight);
00076 
00077   NS_IMETHOD DrawTile(nsIRenderingContext &aContext,
00078                       nsIDrawingSurface* aSurface,
00079                       PRInt32 aSXOffset, PRInt32 aSYOffset,
00080                       PRInt32 aPadX, PRInt32 aPadY,
00081                       const nsRect &aTileRect);
00082 
00083   void UpdateCachedImage();
00084   virtual void ImageUpdated(nsIDeviceContext *aContext,
00085                             PRUint8 aFlags, nsRect *aUpdateRect);
00086   virtual PRBool      GetIsImageComplete();
00087   virtual nsresult    Init(PRInt32 aWidth, PRInt32 aHeight,
00088                            PRInt32 aDepth,
00089                            nsMaskRequirements aMaskRequirements);
00090 
00091   virtual nsresult    Optimize(nsIDeviceContext* aContext);
00092 
00093   virtual PRBool      GetHasAlphaMask()     { return mAlphaBits != nsnull; }     
00094   virtual PRUint8*    GetAlphaBits();
00095   virtual PRInt32     GetAlphaLineStride();
00101   virtual PRInt8 GetAlphaDepth() {return(mAlphaDepth);}  
00102 
00103   NS_IMETHOD   LockImagePixels(PRBool aMaskPixels);
00104   NS_IMETHOD   UnlockImagePixels(PRBool aMaskPixels);
00105 
00106 private:
00110   void ComputeMetrics() {
00111     mRowBytes = (mWidth * mDepth) >> 5;
00112 
00113     if (((PRUint32)mWidth * mDepth) & 0x1F)
00114       mRowBytes++;
00115     mRowBytes <<= 2;
00116 
00117     mSizeImage = mRowBytes * mHeight;
00118   };
00119   void ComputePaletteSize(PRIntn nBitCount);
00120 
00121 private:
00122   NS_IMETHODIMP DrawScaled(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
00123                            PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
00124                            PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00125 
00126   static unsigned scaled6[1<<6];
00127   static unsigned scaled5[1<<5];
00128 
00129   void DrawComposited32(PRBool isLSB, PRBool flipBytes,
00130                         PRUint8 *imageOrigin, PRUint32 imageStride,
00131                         PRUint8 *alphaOrigin, PRUint32 alphaStride,
00132                         unsigned width, unsigned height,
00133                         XImage *ximage, unsigned char *readData);
00134   void DrawComposited24(PRBool isLSB, PRBool flipBytes,
00135                         PRUint8 *imageOrigin, PRUint32 imageStride,
00136                         PRUint8 *alphaOrigin, PRUint32 alphaStride,
00137                         unsigned width, unsigned height,
00138                         XImage *ximage, unsigned char *readData);
00139   void DrawComposited16(PRBool isLSB, PRBool flipBytes,
00140                         PRUint8 *imageOrigin, PRUint32 imageStride,
00141                         PRUint8 *alphaOrigin, PRUint32 alphaStride,
00142                         unsigned width, unsigned height,
00143                         XImage *ximage, unsigned char *readData);
00144   void DrawCompositedGeneral(PRBool isLSB, PRBool flipBytes,
00145                              PRUint8 *imageOrigin, PRUint32 imageStride,
00146                              PRUint8 *alphaOrigin, PRUint32 alphaStride,
00147                              unsigned width, unsigned height,
00148                              XImage *ximage, unsigned char *readData);
00149   inline void DrawComposited(nsIRenderingContext &aContext,
00150                              nsIDrawingSurface* aSurface,
00151                              PRInt32 aSX, PRInt32 aSY,
00152                              PRInt32 aSWidth, PRInt32 aSHeight,
00153                              PRInt32 aDX, PRInt32 aDY,
00154                              PRInt32 aDWidth, PRInt32 aDHeight);
00155 
00156   inline void TilePixmap(Pixmap src, Pixmap dest, PRInt32 aSXOffset, PRInt32 aSYOffset,
00157                          const nsRect &destRect, const nsRect &clipRect, PRBool useClip);
00158   inline void CreateAlphaBitmap(PRInt32 aWidth, PRInt32 aHeight);
00159   inline void CreateOffscreenPixmap(PRInt32 aWidth, PRInt32 aHeight);
00160   inline void DrawImageOffscreen(PRInt32 aSX, PRInt32 aSY,
00161                                  PRInt32 aWidth, PRInt32 aHeight);
00162   inline void SetupGCForAlpha(GC aGC, PRInt32 aX, PRInt32 aY);
00163 
00164   // image bits
00165   PRUint8      *mImageBits;
00166   PRUint8      *mAlphaBits;
00167   Pixmap        mImagePixmap;
00168   Pixmap        mAlphaPixmap;
00169 
00170   PRInt32       mWidth;
00171   PRInt32       mHeight;
00172   PRInt32       mDepth;       // bits per pixel
00173   PRInt32       mRowBytes;
00174   GC            mGC;
00175 
00176   PRInt32       mSizeImage;
00177   PRInt8        mNumBytesPixel;
00178 
00179   PRInt32       mDecodedX1;       //Keeps track of what part of image
00180   PRInt32       mDecodedY1;       // has been decoded.
00181   PRInt32       mDecodedX2;
00182   PRInt32       mDecodedY2;
00183 
00184   nsRegion      mUpdateRegion;
00185 
00186   static XlibRgbHandle *mXlibRgbHandle;
00187   static Display       *mDisplay;
00188 
00189   // alpha layer members
00190   PRInt8        mAlphaDepth;        // alpha layer depth
00191   PRInt16       mAlphaRowBytes;     // alpha bytes per row
00192   PRPackedBool  mAlphaValid;
00193   PRPackedBool  mIsSpacer;
00194   PRPackedBool  mPendingUpdate;
00195 
00196   PRUint8       mFlags;             // flags set by ImageUpdated
00197 };
00198 
00199 #endif /* !nsImageXlib_h__ */