Back to index

lightning-sunbird  0.9+nobinonly
nsImagePh.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 nsImagePh_h___
00039 #define nsImagePh_h___
00040 
00041 #include <Pt.h>
00042 #include "nsIImage.h"
00043 #include "nsRect.h"
00044 
00045 class nsImagePh : public nsIImage {
00046 public:
00047   nsImagePh();
00048   virtual ~nsImagePh();
00049 
00050   NS_DECL_ISUPPORTS
00051 
00055   virtual PRInt32     GetBytesPix()       { return mNumBytesPixel; }
00056   virtual PRInt32     GetHeight() { return mHeight; }
00057   virtual PRInt32     GetWidth() { return mWidth; }
00058 
00059   virtual PRUint8*    GetBits() {  return mImageBits; }
00060 
00061   virtual void*       GetBitInfo() { return nsnull; }
00062 
00063   virtual PRBool      GetIsRowOrderTopToBottom() { return PR_TRUE; }
00064   virtual PRInt32     GetLineStride() { return mRowBytes; }
00065 
00066        inline
00067   NS_IMETHODIMP       SetDecodedRect(PRInt32 x1, PRInt32 y1, PRInt32 x2, PRInt32 y2)
00068               {
00069               mDecodedX1 = x1;
00070               mDecodedY1 = y1;
00071               mDecodedX2 = x2;
00072               mDecodedY2 = y2;
00073               return NS_OK;
00074               }
00075 
00076   virtual PRInt32     GetDecodedX1() { return mDecodedX1;}
00077   virtual PRInt32     GetDecodedY1() { return mDecodedY1;}
00078   virtual PRInt32     GetDecodedX2() { return mDecodedX2;}
00079   virtual PRInt32     GetDecodedY2() { return mDecodedY2;}
00080 
00081   NS_IMETHOD     SetNaturalWidth(PRInt32 naturalwidth) { mNaturalWidth= naturalwidth; return NS_OK;}
00082   NS_IMETHOD     SetNaturalHeight(PRInt32 naturalheight) { mNaturalHeight= naturalheight; return NS_OK;}
00083   virtual PRInt32     GetNaturalWidth() {return mNaturalWidth; }
00084   virtual PRInt32     GetNaturalHeight() {return mNaturalHeight; }
00085 
00086 
00087   virtual nsColorMap* GetColorMap() { return nsnull; }
00088 
00089   NS_IMETHOD          Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
00090   NS_IMETHOD          Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth,  \
00091                                           PRInt32 aSHeight, PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00092 
00093   NS_IMETHOD DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
00094              nscoord aDWidth, nscoord aDHeight);
00095 
00096   NS_IMETHOD           DrawTile(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface,
00097                         PRInt32 aSXOffset, PRInt32 aSYOffset, PRInt32 aPadX, PRInt32 aPadY,
00098                                                                                     const nsRect &aTileRect);
00099 
00100   virtual void        ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect)
00101               {
00102               PRInt32 y = aUpdateRect->YMost();
00103               PRInt32 x = aUpdateRect->XMost();
00104               if( y > mDecodedY2 ) mDecodedY2 = y;
00105               if( x > mDecodedX2 ) mDecodedX2 = x;
00106               mDirtyFlags = aFlags;
00107               mPhImage.size.h = mDecodedY2;
00108               }
00109   virtual PRBool      GetIsImageComplete();
00110 
00111   virtual nsresult    Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
00112 //  virtual PRBool      IsOptimized() { return mIsOptimized; }
00113 
00114   virtual nsresult    Optimize(nsIDeviceContext* aContext);
00115 
00116   virtual PRBool      GetHasAlphaMask() { return mAlphaBits != nsnull; } 
00117   virtual PRUint8*    GetAlphaBits() { return mAlphaBits; }
00118   virtual PRInt32     GetAlphaWidth() { return mAlphaWidth; }
00119   virtual PRInt32     GetAlphaHeight() { return mAlphaHeight; }
00120   virtual PRInt32     GetAlphaLineStride() { return mAlphaRowBytes; }
00121   virtual nsIImage*   DuplicateImage() { return nsnull; }
00122   
00128   virtual PRInt8 GetAlphaDepth() { return mAlphaDepth; }  
00129   virtual void         MoveAlphaMask(PRInt32 aX, PRInt32 aY) { }
00130 
00131   inline
00132        NS_IMETHODIMP          LockImagePixels(PRBool aMaskPixels) { return NS_OK; }
00133 
00134        inline
00135   NS_IMETHODIMP        UnlockImagePixels(PRBool aMaskPixels) { return NS_OK; }
00136 
00137 private:
00138   void ComputePaletteSize(PRIntn nBitCount);
00139 
00140 private:
00141   PRInt32             mWidth;
00142   PRInt32             mHeight;
00143   PRInt32             mDepth;
00144   PRInt32             mRowBytes;          // number of bytes per row
00145   PRUint8*            mImageBits;         // starting address of DIB bits
00146 
00147   PRInt8              mNumBytesPixel;     // number of bytes per pixel
00148   PRUint8             mImageFlags;
00149        PRUint8                                                 mDirtyFlags;
00150 
00151   PRInt32             mDecodedX1;       //Keeps track of what part of image
00152   PRInt32             mDecodedY1;       // has been decoded.
00153   PRInt32             mDecodedX2; 
00154   PRInt32             mDecodedY2;    
00155 
00156   // alpha layer members
00157   PRUint8             *mAlphaBits;        // alpha layer if we made one
00158   PRInt8              mAlphaDepth;        // alpha layer depth
00159   PRInt16             mAlphaRowBytes;         // number of bytes per row in the image for the alpha
00160   PRInt16             mAlphaWidth;        // alpha layer width
00161   PRInt16             mAlphaHeight;       // alpha layer height
00162   PhImage_t           mPhImage;
00163   PhImage_t           *mPhImageZoom;                    // the zoomed version of mPhImage
00164        PRInt32                                                 mDecodedY2_when_scaled;
00165 
00166   PRInt32 mNaturalWidth;
00167   PRInt32 mNaturalHeight;
00168 };
00169 #endif