Back to index

lightning-sunbird  0.9+nobinonly
nsImageOS2.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Mozilla OS/2 libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * John Fairhurst, <john_fairhurst@iname.com>.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Pierre Phaneuf <pp@ludusdesign.com>
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  * This Original Code has been modified by IBM Corporation. Modifications made by IBM 
00039  * described herein are Copyright (c) International Business Machines Corporation, 2000.
00040  * Modifications to Mozilla code or documentation identified per MPL Section 3.3
00041  *
00042  * Date             Modified by     Description of modification
00043  * 05/11/2000       IBM Corp.      Make it look more like Windows.
00044  */
00045 
00046 #ifndef _nsImageOS2_h_
00047 #define _nsImageOS2_h_
00048 
00049 #include "nsIImage.h"
00050 #include "nsRect.h"
00051 
00052 struct nsDrawingSurfaceOS2;
00053 
00054 class nsImageOS2 : public nsIImage{
00055 public:
00056   nsImageOS2();
00057   ~nsImageOS2();
00058 
00059   NS_DECL_ISUPPORTS
00060 
00064   virtual PRInt32     GetBytesPix()       { return mInfo ? (mInfo->cBitCount <= 8 ? 1 : mInfo->cBitCount / 8) : 0; }
00065   virtual PRInt32     GetHeight()         { return mInfo ? mInfo->cy : 0; }
00066   virtual PRBool      GetIsRowOrderTopToBottom() { return PR_FALSE; }
00067   virtual PRInt32     GetWidth()          { return mInfo ? mInfo->cx : 0; }
00068   virtual PRUint8*    GetBits()           { return mImageBits; }
00069   virtual PRInt32     GetLineStride()     { return mRowBytes; }
00070 
00071   virtual PRBool      GetHasAlphaMask()   { return mAlphaBits != nsnull; }
00072 
00073   NS_IMETHOD          Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
00074   NS_IMETHOD          Draw(nsIRenderingContext &aContext, nsIDrawingSurface* aSurface, PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
00075                       PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00076   virtual nsColorMap* GetColorMap() {return mColorMap;}
00077   virtual void        ImageUpdated(nsIDeviceContext *aContext, PRUint8 aFlags, nsRect *aUpdateRect);
00078   virtual PRBool      GetIsImageComplete();
00079   virtual nsresult    Init(PRInt32 aWidth, PRInt32 aHeight, PRInt32 aDepth, nsMaskRequirements aMaskRequirements);
00080   virtual nsresult    Optimize(nsIDeviceContext* aContext);
00081   virtual PRUint8*    GetAlphaBits()      { return mAlphaBits; }
00082   virtual PRInt32     GetAlphaLineStride(){ return mARowBytes; }
00083 
00092   NS_IMETHOD DrawTile(nsIRenderingContext &aContext,
00093                       nsIDrawingSurface* aSurface,
00094                       PRInt32 aSXOffset, PRInt32 aSYOffset,
00095                     PRInt32 aPadX, PRInt32 aPadY,
00096                       const nsRect &aTileRect);
00097 
00098   NS_IMETHOD DrawToImage(nsIImage* aDstImage, nscoord aDX, nscoord aDY,
00099                          nscoord aDWidth, nscoord aDHeight);
00100 
00105 #if 0 // OS2TODO
00106   PRIntn      GetSizeHeader(){return sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * mNumPaletteColors;}
00107 #endif
00108 
00114 #if 0 // OS2TODO
00115   PRIntn      GetSizeImage(){ return mSizeImage; }
00116 #endif
00117 
00123 #if 0 // OS2TODO
00124   PRInt32  CalcBytesSpan(PRUint32  aWidth);
00125 #endif
00126 
00132   virtual PRInt8 GetAlphaDepth() {return(mAlphaDepth);}
00133 
00139   void* GetBitInfo()  { return mInfo; }
00140 
00141   NS_IMETHOD   LockImagePixels(PRBool aMaskPixels);
00142   NS_IMETHOD   UnlockImagePixels(PRBool aMaskPixels);
00143 
00144 
00145  private:
00151   void CleanUp(PRBool aCleanUpAll);
00152 
00153   void DrawComposited24(unsigned char *aBits,
00154                         PRUint8 *aImageRGB, PRUint32 aStrideRGB,
00155                         PRUint8 *aImageAlpha, PRUint32 aStrideAlpha,
00156                         int aWidth, int aHeight);
00157 
00158 #ifdef OS2TODO
00159 
00166   nsresult ConvertDDBtoDIB(PRInt32 aWidth,PRInt32 aHeight);
00167 
00168 
00178   nsresult PrintDDB(nsIDrawingSurface* aSurface,PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight);
00179 
00180 
00189   PRUint8 PaletteMatch(PRUint8 r, PRUint8 g, PRUint8 b);
00190 #endif
00191   BITMAPINFO2*        mInfo;
00192   PRUint32            mDeviceDepth;
00193   PRInt32             mRowBytes;          // number of bytes per row
00194   PRUint8*            mImageBits;         // starting address of DIB bits
00195   PRBool              mIsOptimized;       // Did we convert our DIB to a HBITMAP
00196   nsColorMap*         mColorMap;          // Redundant with mColorTable, but necessary
00197 
00198   nsRect              mDecodedRect;       // Keeps track of what part of image has been decoded.
00199     
00200   // alpha layer members
00201   PRUint8             *mAlphaBits;        // alpha layer if we made one
00202   PRInt8              mAlphaDepth;        // alpha layer depth
00203   PRInt16             mARowBytes;         // number of bytes per row in the image for tha alpha
00204 
00205   static PRUint8      gBlenderLookup [65536];    // Lookup table for fast alpha blending
00206   static PRBool       gBlenderReady;
00207   static void         BuildBlenderLookup (void);
00208   static PRUint8      FAST_BLEND (PRUint8 Source, PRUint8 Dest, PRUint8 Alpha) { return gBlenderLookup [(Alpha << 8) + Source] + 
00209                                                                                         gBlenderLookup [((255 - Alpha) << 8) + Dest]; }
00210 
00211   NS_IMETHODIMP UpdateImageBits( HPS mPS );
00212   void NS2PM_ININ( const nsRect &in, RECTL &rcl);
00213   void CreateBitmaps( nsDrawingSurfaceOS2 *surf);
00214 
00215   void     BuildTile (HPS hpsTile, PRUint8* pImageBits, PBITMAPINFO2 pBitmapInfo, nscoord aTileWidth, nscoord aTileHeight, float scale);
00216 };
00217 
00218 #endif