michael@0: /* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: #ifndef _nsICODecoder_h michael@0: #define _nsICODecoder_h michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "Decoder.h" michael@0: #include "nsBMPDecoder.h" michael@0: #include "nsPNGDecoder.h" michael@0: #include "ICOFileHeaders.h" michael@0: michael@0: namespace mozilla { michael@0: namespace image { michael@0: michael@0: class RasterImage; michael@0: michael@0: class nsICODecoder : public Decoder michael@0: { michael@0: public: michael@0: michael@0: nsICODecoder(RasterImage &aImage); michael@0: virtual ~nsICODecoder(); michael@0: michael@0: // Obtains the width of the icon directory entry michael@0: uint32_t GetRealWidth() const michael@0: { michael@0: return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth; michael@0: } michael@0: michael@0: // Obtains the height of the icon directory entry michael@0: uint32_t GetRealHeight() const michael@0: { michael@0: return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight; michael@0: } michael@0: michael@0: virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy); michael@0: virtual void FinishInternal(); michael@0: virtual bool NeedsNewFrame() const; michael@0: virtual nsresult AllocateFrame(); michael@0: michael@0: private: michael@0: // Writes to the contained decoder and sets the appropriate errors michael@0: // Returns true if there are no errors. michael@0: bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy); michael@0: michael@0: // Processes a single dir entry of the icon resource michael@0: void ProcessDirEntry(IconDirEntry& aTarget); michael@0: // Sets the hotspot property of if we have a cursor michael@0: void SetHotSpotIfCursor(); michael@0: // Creates a bitmap file header buffer, returns true if successful michael@0: bool FillBitmapFileHeaderBuffer(int8_t *bfh); michael@0: // Fixes the ICO height to match that of the BIH. michael@0: // and also fixes the BIH height to be /2 of what it was. michael@0: // See definition for explanation. michael@0: // Returns false if invalid information is contained within. michael@0: bool FixBitmapHeight(int8_t *bih); michael@0: // Fixes the ICO width to match that of the BIH. michael@0: // Returns false if invalid information is contained within. michael@0: bool FixBitmapWidth(int8_t *bih); michael@0: // Extract bitmap info header size count from BMP information header michael@0: int32_t ExtractBIHSizeFromBitmap(int8_t *bih); michael@0: // Extract bit count from BMP information header michael@0: int32_t ExtractBPPFromBitmap(int8_t *bih); michael@0: // Calculates the row size in bytes for the AND mask table michael@0: uint32_t CalcAlphaRowSize(); michael@0: // Obtains the number of colors from the BPP, mBPP must be filled in michael@0: uint16_t GetNumColors(); michael@0: michael@0: uint16_t mBPP; // Stores the images BPP michael@0: uint32_t mPos; // Keeps track of the position we have decoded up until michael@0: uint16_t mNumIcons; // Stores the number of icons in the ICO file michael@0: uint16_t mCurrIcon; // Stores the current dir entry index we are processing michael@0: uint32_t mImageOffset; // Stores the offset of the image data we want michael@0: uint8_t *mRow; // Holds one raw line of the image michael@0: int32_t mCurLine; // Line index of the image that's currently being decoded michael@0: uint32_t mRowBytes; // How many bytes of the row were already received michael@0: int32_t mOldLine; // Previous index of the line michael@0: nsAutoPtr mContainedDecoder; // Contains either a BMP or PNG resource michael@0: michael@0: char mDirEntryArray[ICODIRENTRYSIZE]; // Holds the current dir entry buffer michael@0: IconDirEntry mDirEntry; // Holds a decoded dir entry michael@0: // Holds the potential bytes that can be a PNG signature michael@0: char mSignature[PNGSIGNATURESIZE]; michael@0: // Holds the potential bytes for a bitmap information header michael@0: char mBIHraw[40]; michael@0: // Stores whether or not the icon file we are processing has type 1 (icon) michael@0: bool mIsCursor; michael@0: // Stores whether or not the contained resource is a PNG michael@0: bool mIsPNG; michael@0: }; michael@0: michael@0: } // namespace image michael@0: } // namespace mozilla michael@0: michael@0: #endif