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