Back to index

lightning-sunbird  0.9+nobinonly
nsImageMac.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 nsImageMac_h___
00039 #define nsImageMac_h___
00040 
00041 #include "nsIImage.h"
00042 #include "nsIImageMac.h"
00043 
00044 class nsImageMac : public nsIImage, public nsIImageMac_MOZILLA_1_8_BRANCH
00045 {
00046 public:
00047                       nsImageMac();
00048   virtual             ~nsImageMac();
00049 
00050   NS_DECL_ISUPPORTS
00051 
00055   virtual nsresult    Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
00056   virtual PRInt32     GetBytesPix()         { return mBytesPerPixel; }    // this is unused
00057   virtual PRBool      GetIsRowOrderTopToBottom() { return PR_FALSE; }
00058 
00059   virtual PRInt32     GetWidth()            { return mWidth;  }
00060   virtual PRInt32     GetHeight()           { return mHeight; }
00061 
00062   virtual PRUint8*    GetBits()             { return mImageBits; }
00063   virtual PRInt32     GetLineStride()       { return mRowBytes; }
00064   virtual PRBool      GetHasAlphaMask()     { return mAlphaBits != nsnull; }
00065 
00066   virtual PRUint8*    GetAlphaBits()        { return mAlphaBits; }
00067   virtual PRInt32     GetAlphaLineStride()  { return mAlphaRowBytes; }
00068 
00069   // Called when an image decoder updates the image bits (mImageBits &
00070   // mAlphaBits).  'aFlags' is ignored.
00071   virtual void        ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags,
00072                                    nsRect *aUpdateRect);
00073   virtual PRBool      GetIsImageComplete();
00074 
00075   // Optimizes memory usage for object.
00076   virtual nsresult    Optimize(nsIDeviceContext* aContext);
00077 
00078   virtual nsColorMap* GetColorMap()         { return nsnull; }
00079 
00080   NS_IMETHOD          Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
00081                               PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
00082 
00083   NS_IMETHOD          Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
00084                               PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
00085                               PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00086 
00087   NS_IMETHOD          DrawTile(nsIRenderingContext &aContext,
00088                               nsIDrawingSurface* aSurface,
00089                               PRInt32 aSXOffset, PRInt32 aSYOffset,
00090                               PRInt32 aPadX, PRInt32 aPadY,
00091                               const nsRect &aTileRect);
00092 
00093 
00099   virtual PRInt8      GetAlphaDepth() { return mAlphaDepth; }
00100 
00101   NS_IMETHOD          DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
00102                                   nscoord aDWidth, nscoord aDHeight);
00103 
00104   virtual void*       GetBitInfo()          { return nsnull; }
00105 
00106   NS_IMETHOD          LockImagePixels(PRBool aMaskPixels);
00107   NS_IMETHOD          UnlockImagePixels(PRBool aMaskPixels);
00108 
00109 
00110   // Convert to and from the os-native PICT format. Most likely
00111   // used for clipboard.
00112   NS_IMETHOD          ConvertToPICT(PicHandle* outPicture);
00113   NS_IMETHOD          ConvertFromPICT(PicHandle inPicture);
00114 
00115   NS_IMETHOD          GetCGImageRef(CGImageRef* aCGImageRef);
00116 
00117 protected:
00118 
00119   nsresult          SlowTile(nsIRenderingContext &aContext,
00120                                         nsIDrawingSurface* aSurface,
00121                                         PRInt32 aSXOffset, PRInt32 aSYOffset,
00122                                         PRInt32 aPadX, PRInt32 aPadY,
00123                                         const nsRect &aTileRect);
00124 
00125   nsresult          DrawTileQuickly(nsIRenderingContext &aContext,
00126                                         nsIDrawingSurface* aSurface,
00127                                         PRInt32 aSXOffset, PRInt32 aSYOffset,
00128                                         const nsRect &aTileRect);
00129 
00130   nsresult          DrawTileWithQuartz(nsIDrawingSurface* aSurface,
00131                                         PRInt32 aSXOffset, PRInt32 aSYOffset,
00132                                         PRInt32 aPadX, PRInt32 aPadY,
00133                                         const nsRect &aTileRect);
00134   
00135   static PRInt32    CalculateRowBytes(PRUint32 aWidth, PRUint32 aDepth);
00136 
00137   inline static PRInt32 CalculateRowBytesInternal(PRUint32 aWidth,
00138                                                   PRUint32 aDepth,
00139                                                   PRBool aAllow2Bytes);
00140 
00141   static PRBool     RenderingToPrinter(nsIRenderingContext &aContext);
00142 
00143   // Recreate internal image structure from updated image bits.
00144   nsresult          EnsureCachedImage();
00145 
00146   // Get/Set/Clear alpha bit at position 'x' in the row pointed to by 'rowptr'.
00147   inline PRUint8 GetAlphaBit(PRUint8* rowptr, PRUint32 x) {
00148     return (rowptr[x >> 3] & (1 << (7 - x & 0x7)));
00149   }
00150   inline void SetAlphaBit(PRUint8* rowptr, PRUint32 x) {
00151     rowptr[x >> 3] |= (1 << (7 - x & 0x7));
00152   }
00153   inline void ClearAlphaBit(PRUint8* rowptr, PRUint32 x) {
00154     rowptr[x >> 3] &= ~(1 << (7 - x & 0x7));
00155   }
00156 
00157   // Takes ownership of the given image and bitmap.  The CGImageRef is retained.
00158   void AdoptImage(CGImageRef aNewImage, PRUint8* aNewBitamp);
00159 
00160 private:
00161 
00162   PRUint8*        mImageBits;     // malloc'd block
00163   CGImageRef      mImage;
00164 
00165   PRInt32         mWidth;
00166   PRInt32         mHeight;
00167 
00168   PRInt32         mRowBytes;
00169   PRInt32         mBytesPerPixel;
00170 
00171   // alpha layer members
00172   PRUint8*        mAlphaBits;      // malloc'd block
00173 
00174   PRInt32         mAlphaRowBytes;   // alpha row bytes
00175   PRInt8          mAlphaDepth;      // alpha layer depth
00176 
00177   PRPackedBool    mPendingUpdate;   // true when we need to recreate CGImageRef
00178   PRPackedBool    mOptimized;       // true when nsImage object has been
00179                                     // optimized (see |Optimize()|)
00180 
00181   PRInt32         mDecodedX1;       // Keeps track of what part of image
00182   PRInt32         mDecodedY1;       // has been decoded.
00183   PRInt32         mDecodedX2;
00184   PRInt32         mDecodedY2;
00185 };
00186 
00187 #endif