/src/mozilla-central/image/decoders/nsICODecoder.h
Line | Count | Source (jump to first uncovered line) |
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/. */ |
5 | | |
6 | | |
7 | | #ifndef mozilla_image_decoders_nsICODecoder_h |
8 | | #define mozilla_image_decoders_nsICODecoder_h |
9 | | |
10 | | #include "StreamingLexer.h" |
11 | | #include "Decoder.h" |
12 | | #include "imgFrame.h" |
13 | | #include "mozilla/gfx/2D.h" |
14 | | #include "nsBMPDecoder.h" |
15 | | #include "nsPNGDecoder.h" |
16 | | #include "ICOFileHeaders.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace image { |
20 | | |
21 | | class RasterImage; |
22 | | |
23 | | enum class ICOState |
24 | | { |
25 | | HEADER, |
26 | | DIR_ENTRY, |
27 | | FINISHED_DIR_ENTRY, |
28 | | ITERATE_UNSIZED_DIR_ENTRY, |
29 | | SKIP_TO_RESOURCE, |
30 | | FOUND_RESOURCE, |
31 | | SNIFF_RESOURCE, |
32 | | READ_RESOURCE, |
33 | | PREPARE_FOR_MASK, |
34 | | READ_MASK_ROW, |
35 | | FINISH_MASK, |
36 | | SKIP_MASK, |
37 | | FINISHED_RESOURCE |
38 | | }; |
39 | | |
40 | | class nsICODecoder : public Decoder |
41 | | { |
42 | | public: |
43 | 0 | virtual ~nsICODecoder() { } |
44 | | |
45 | | /// @return The offset from the beginning of the ICO to the first resource. |
46 | | size_t FirstResourceOffset() const; |
47 | | |
48 | 0 | DecoderType GetType() const override { return DecoderType::ICO; } |
49 | | LexerResult DoDecode(SourceBufferIterator& aIterator, |
50 | | IResumable* aOnResume) override; |
51 | | nsresult FinishInternal() override; |
52 | | nsresult FinishWithErrorInternal() override; |
53 | | |
54 | | private: |
55 | | friend class DecoderFactory; |
56 | | |
57 | | // Decoders should only be instantiated via DecoderFactory. |
58 | | explicit nsICODecoder(RasterImage* aImage); |
59 | | |
60 | | // Flushes the contained decoder to read all available data and sets the |
61 | | // appropriate errors. Returns true if there are no errors. |
62 | | bool FlushContainedDecoder(); |
63 | | |
64 | | // Gets decoder state from the contained decoder so it's visible externally. |
65 | | nsresult GetFinalStateFromContainedDecoder(); |
66 | | |
67 | | // Obtains the number of colors from the BPP, mBPP must be filled in |
68 | | uint16_t GetNumColors(); |
69 | | |
70 | | LexerTransition<ICOState> ReadHeader(const char* aData); |
71 | | LexerTransition<ICOState> ReadDirEntry(const char* aData); |
72 | | LexerTransition<ICOState> IterateUnsizedDirEntry(); |
73 | | LexerTransition<ICOState> FinishDirEntry(); |
74 | | LexerTransition<ICOState> SniffResource(const char* aData); |
75 | | LexerTransition<ICOState> ReadResource(); |
76 | | LexerTransition<ICOState> ReadBIH(const char* aData); |
77 | | LexerTransition<ICOState> PrepareForMask(); |
78 | | LexerTransition<ICOState> ReadMaskRow(const char* aData); |
79 | | LexerTransition<ICOState> FinishMask(); |
80 | | LexerTransition<ICOState> FinishResource(); |
81 | | |
82 | | struct IconDirEntryEx : public IconDirEntry { |
83 | | gfx::IntSize mSize; |
84 | | }; |
85 | | |
86 | | StreamingLexer<ICOState, 32> mLexer; // The lexer. |
87 | | RefPtr<Decoder> mContainedDecoder; // Either a BMP or PNG decoder. |
88 | | Maybe<SourceBufferIterator> mReturnIterator; // Iterator to save return point. |
89 | | UniquePtr<uint8_t[]> mMaskBuffer; // A temporary buffer for the alpha mask. |
90 | | nsTArray<IconDirEntryEx> mDirEntries; // Valid dir entries with a size. |
91 | | nsTArray<IconDirEntryEx> mUnsizedDirEntries; // Dir entries without a size. |
92 | | IconDirEntryEx* mDirEntry; // The dir entry for the selected resource. |
93 | | uint16_t mNumIcons; // Stores the number of icons in the ICO file. |
94 | | uint16_t mCurrIcon; // Stores the current dir entry index we are processing. |
95 | | uint16_t mBPP; // The BPP of the resource we're decoding. |
96 | | uint32_t mMaskRowSize; // The size in bytes of each row in the BMP alpha mask. |
97 | | uint32_t mCurrMaskLine; // The line of the BMP alpha mask we're processing. |
98 | | bool mIsCursor; // Is this ICO a cursor? |
99 | | bool mHasMaskAlpha; // Did the BMP alpha mask have any transparency? |
100 | | }; |
101 | | |
102 | | } // namespace image |
103 | | } // namespace mozilla |
104 | | |
105 | | #endif // mozilla_image_decoders_nsICODecoder_h |