Back to index

lightning-sunbird  0.9+nobinonly
nsICODecoder.h
Go to the documentation of this file.
00001 /* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
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 the Mozilla ICO Decoder.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   David Hyatt <hyatt@netscape.com> (Original Author)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * 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 
00040 #ifndef _nsICODecoder_h
00041 #define _nsICODecoder_h
00042 
00043 #include "nsCOMPtr.h"
00044 #include "imgIDecoder.h"
00045 #include "imgIContainer.h"
00046 #include "imgIDecoderObserver.h"
00047 #include "gfxIImageFrame.h"
00048 #include "nsBMPDecoder.h"
00049 
00050 // {CB3EDE1A-0FA5-4e27-AAFE-0F7801E5A1F1}
00051 #define NS_ICODECODER_CID \
00052 { 0xcb3ede1a, 0xfa5, 0x4e27, { 0xaa, 0xfe, 0xf, 0x78, 0x1, 0xe5, 0xa1, 0xf1 } }
00053 
00054 #if defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS) || defined(MOZ_WIDGET_PHOTON)
00055 #define GFXFORMATALPHA8 gfxIFormats::BGR_A8
00056 #else
00057 #define USE_RGBA1
00058 #define GFXFORMATALPHA8 gfxIFormats::RGB_A8
00059 #endif
00060 
00061 struct IconDirEntry
00062 {
00063   PRUint8   mWidth;
00064   PRUint8   mHeight;
00065   PRUint8   mColorCount;
00066   PRUint8   mReserved;
00067   union {
00068     PRUint16 mPlanes;   // ICO
00069     PRUint16 mXHotspot; // CUR
00070   };
00071   union {
00072     PRUint16 mBitCount; // ICO
00073     PRUint16 mYHotspot; // CUR
00074   };
00075   PRUint32  mBytesInRes;
00076   PRUint32  mImageOffset;
00077 };
00078 
00079 class nsICODecoder : public imgIDecoder
00080 {
00081 public:
00082   NS_DECL_ISUPPORTS
00083   NS_DECL_IMGIDECODER
00084 
00085   nsICODecoder();
00086   virtual ~nsICODecoder();
00087 
00088 private:
00090   static NS_METHOD ReadSegCb(nsIInputStream* aIn, void* aClosure,
00091                              const char* aFromRawSegment, PRUint32 aToOffset,
00092                              PRUint32 aCount, PRUint32 *aWriteCount);
00093 
00094   // Private helper methods
00095   nsresult ProcessData(const char* aBuffer, PRUint32 aCount);
00096   void ProcessDirEntry(IconDirEntry& aTarget);
00097   void ProcessInfoHeader();
00098 
00099   nsresult SetImageData();
00100   nsresult SetAlphaData();
00101 
00102   PRUint32 CalcAlphaRowSize();
00103 
00104 private:
00105   nsCOMPtr<imgIDecoderObserver> mObserver;
00106   nsCOMPtr<imgIContainer> mImage;
00107   nsCOMPtr<gfxIImageFrame> mFrame;
00108   
00109   PRUint8 mHaveAlphaData;
00110   PRPackedBool mDecodingAndMask;
00111 
00112   PRUint32 mPos;
00113   PRUint16 mNumIcons;
00114   PRUint16 mCurrIcon;
00115   PRUint32 mImageOffset;
00116 
00117   char mDirEntryArray[16];
00118   IconDirEntry mDirEntry;
00119 
00120   char mBIHraw[40];
00121   BMPINFOHEADER mBIH;
00122 
00123   PRUint32 mNumColors;
00124   colorTable* mColors;
00125 
00126   PRUint8* mRow; // Holds one raw line of the image
00127   PRUint32 mRowBytes; // How many bytes of the row were already received
00128   PRInt32 mCurLine;
00129 
00130   nsresult mStatus;
00131 
00132   PRUint8* mDecodedBuffer;
00133   PRUint8* mAlphaBuffer;
00134   PRPackedBool mIsCursor;
00135 };
00136 
00137 
00138 #endif