Bumping manifests a=b2g-bump
[gecko.git] / image / decoders / nsICODecoder.h
blob6cc92d2b27afee6730d86c737cf61057de09e6ae
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 "imgFrame.h"
13 #include "nsBMPDecoder.h"
14 #include "nsPNGDecoder.h"
15 #include "ICOFileHeaders.h"
17 namespace mozilla {
18 namespace image {
20 class RasterImage;
22 class nsICODecoder : public Decoder
24 public:
26 explicit nsICODecoder(RasterImage* aImage);
27 virtual ~nsICODecoder();
29 // Obtains the width of the icon directory entry
30 uint32_t GetRealWidth() const
32 return mDirEntry.mWidth == 0 ? 256 : mDirEntry.mWidth;
35 // Obtains the height of the icon directory entry
36 uint32_t GetRealHeight() const
38 return mDirEntry.mHeight == 0 ? 256 : mDirEntry.mHeight;
41 virtual void WriteInternal(const char* aBuffer, uint32_t aCount) MOZ_OVERRIDE;
42 virtual void FinishInternal() MOZ_OVERRIDE;
43 virtual nsresult AllocateFrame(const nsIntSize& aTargetSize
44 /* = nsIntSize() */) MOZ_OVERRIDE;
46 protected:
47 virtual bool NeedsNewFrame() const MOZ_OVERRIDE;
49 private:
50 // Writes to the contained decoder and sets the appropriate errors
51 // Returns true if there are no errors.
52 bool WriteToContainedDecoder(const char* aBuffer, uint32_t aCount);
54 // Processes a single dir entry of the icon resource
55 void ProcessDirEntry(IconDirEntry& aTarget);
56 // Sets the hotspot property of if we have a cursor
57 void SetHotSpotIfCursor();
58 // Creates a bitmap file header buffer, returns true if successful
59 bool FillBitmapFileHeaderBuffer(int8_t *bfh);
60 // Fixes the ICO height to match that of the BIH.
61 // and also fixes the BIH height to be /2 of what it was.
62 // See definition for explanation.
63 // Returns false if invalid information is contained within.
64 bool FixBitmapHeight(int8_t *bih);
65 // Fixes the ICO width to match that of the BIH.
66 // Returns false if invalid information is contained within.
67 bool FixBitmapWidth(int8_t *bih);
68 // Extract bitmap info header size count from BMP information header
69 int32_t ExtractBIHSizeFromBitmap(int8_t *bih);
70 // Extract bit count from BMP information header
71 int32_t ExtractBPPFromBitmap(int8_t *bih);
72 // Calculates the row size in bytes for the AND mask table
73 uint32_t CalcAlphaRowSize();
74 // Obtains the number of colors from the BPP, mBPP must be filled in
75 uint16_t GetNumColors();
77 uint16_t mBPP; // Stores the images BPP
78 uint32_t mPos; // Keeps track of the position we have decoded up until
79 uint16_t mNumIcons; // Stores the number of icons in the ICO file
80 uint16_t mCurrIcon; // Stores the current dir entry index we are processing
81 uint32_t mImageOffset; // Stores the offset of the image data we want
82 uint8_t* mRow; // Holds one raw line of the image
83 int32_t mCurLine; // Line index of the image that's currently being decoded
84 uint32_t mRowBytes; // How many bytes of the row were already received
85 int32_t mOldLine; // Previous index of the line
86 nsRefPtr<Decoder> mContainedDecoder; // Contains either a BMP or PNG resource
87 RawAccessFrameRef mRefForContainedDecoder; // Avoid locking off-main-thread
89 char mDirEntryArray[ICODIRENTRYSIZE]; // Holds the current dir entry buffer
90 IconDirEntry mDirEntry; // Holds a decoded dir entry
91 // Holds the potential bytes that can be a PNG signature
92 char mSignature[PNGSIGNATURESIZE];
93 // Holds the potential bytes for a bitmap information header
94 char mBIHraw[40];
95 // Stores whether or not the icon file we are processing has type 1 (icon)
96 bool mIsCursor;
97 // Stores whether or not the contained resource is a PNG
98 bool mIsPNG;
101 } // namespace image
102 } // namespace mozilla
104 #endif // nsICODecoder_h