Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | |
michael@0 | 7 | #ifndef _nsICODecoder_h |
michael@0 | 8 | #define _nsICODecoder_h |
michael@0 | 9 | |
michael@0 | 10 | #include "nsAutoPtr.h" |
michael@0 | 11 | #include "Decoder.h" |
michael@0 | 12 | #include "nsBMPDecoder.h" |
michael@0 | 13 | #include "nsPNGDecoder.h" |
michael@0 | 14 | #include "ICOFileHeaders.h" |
michael@0 | 15 | |
michael@0 | 16 | namespace mozilla { |
michael@0 | 17 | namespace image { |
michael@0 | 18 | |
michael@0 | 19 | class RasterImage; |
michael@0 | 20 | |
michael@0 | 21 | class nsICODecoder : public Decoder |
michael@0 | 22 | { |
michael@0 | 23 | public: |
michael@0 | 24 | |
michael@0 | 25 | nsICODecoder(RasterImage &aImage); |
michael@0 | 26 | virtual ~nsICODecoder(); |
michael@0 | 27 | |
michael@0 | 28 | // Obtains the width of the icon directory entry |
michael@0 | 29 | uint32_t GetRealWidth() const |
michael@0 | 30 | { |
michael@0 | 31 | return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | // Obtains the height of the icon directory entry |
michael@0 | 35 | uint32_t GetRealHeight() const |
michael@0 | 36 | { |
michael@0 | 37 | return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | virtual void WriteInternal(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy); |
michael@0 | 41 | virtual void FinishInternal(); |
michael@0 | 42 | virtual bool NeedsNewFrame() const; |
michael@0 | 43 | virtual nsresult AllocateFrame(); |
michael@0 | 44 | |
michael@0 | 45 | private: |
michael@0 | 46 | // Writes to the contained decoder and sets the appropriate errors |
michael@0 | 47 | // Returns true if there are no errors. |
michael@0 | 48 | bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount, DecodeStrategy aStrategy); |
michael@0 | 49 | |
michael@0 | 50 | // Processes a single dir entry of the icon resource |
michael@0 | 51 | void ProcessDirEntry(IconDirEntry& aTarget); |
michael@0 | 52 | // Sets the hotspot property of if we have a cursor |
michael@0 | 53 | void SetHotSpotIfCursor(); |
michael@0 | 54 | // Creates a bitmap file header buffer, returns true if successful |
michael@0 | 55 | bool FillBitmapFileHeaderBuffer(int8_t *bfh); |
michael@0 | 56 | // Fixes the ICO height to match that of the BIH. |
michael@0 | 57 | // and also fixes the BIH height to be /2 of what it was. |
michael@0 | 58 | // See definition for explanation. |
michael@0 | 59 | // Returns false if invalid information is contained within. |
michael@0 | 60 | bool FixBitmapHeight(int8_t *bih); |
michael@0 | 61 | // Fixes the ICO width to match that of the BIH. |
michael@0 | 62 | // Returns false if invalid information is contained within. |
michael@0 | 63 | bool FixBitmapWidth(int8_t *bih); |
michael@0 | 64 | // Extract bitmap info header size count from BMP information header |
michael@0 | 65 | int32_t ExtractBIHSizeFromBitmap(int8_t *bih); |
michael@0 | 66 | // Extract bit count from BMP information header |
michael@0 | 67 | int32_t ExtractBPPFromBitmap(int8_t *bih); |
michael@0 | 68 | // Calculates the row size in bytes for the AND mask table |
michael@0 | 69 | uint32_t CalcAlphaRowSize(); |
michael@0 | 70 | // Obtains the number of colors from the BPP, mBPP must be filled in |
michael@0 | 71 | uint16_t GetNumColors(); |
michael@0 | 72 | |
michael@0 | 73 | uint16_t mBPP; // Stores the images BPP |
michael@0 | 74 | uint32_t mPos; // Keeps track of the position we have decoded up until |
michael@0 | 75 | uint16_t mNumIcons; // Stores the number of icons in the ICO file |
michael@0 | 76 | uint16_t mCurrIcon; // Stores the current dir entry index we are processing |
michael@0 | 77 | uint32_t mImageOffset; // Stores the offset of the image data we want |
michael@0 | 78 | uint8_t *mRow; // Holds one raw line of the image |
michael@0 | 79 | int32_t mCurLine; // Line index of the image that's currently being decoded |
michael@0 | 80 | uint32_t mRowBytes; // How many bytes of the row were already received |
michael@0 | 81 | int32_t mOldLine; // Previous index of the line |
michael@0 | 82 | nsAutoPtr<Decoder> mContainedDecoder; // Contains either a BMP or PNG resource |
michael@0 | 83 | |
michael@0 | 84 | char mDirEntryArray[ICODIRENTRYSIZE]; // Holds the current dir entry buffer |
michael@0 | 85 | IconDirEntry mDirEntry; // Holds a decoded dir entry |
michael@0 | 86 | // Holds the potential bytes that can be a PNG signature |
michael@0 | 87 | char mSignature[PNGSIGNATURESIZE]; |
michael@0 | 88 | // Holds the potential bytes for a bitmap information header |
michael@0 | 89 | char mBIHraw[40]; |
michael@0 | 90 | // Stores whether or not the icon file we are processing has type 1 (icon) |
michael@0 | 91 | bool mIsCursor; |
michael@0 | 92 | // Stores whether or not the contained resource is a PNG |
michael@0 | 93 | bool mIsPNG; |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | } // namespace image |
michael@0 | 97 | } // namespace mozilla |
michael@0 | 98 | |
michael@0 | 99 | #endif |