OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef ICOImageDecoder_h | 31 #ifndef ICOImageDecoder_h |
32 #define ICOImageDecoder_h | 32 #define ICOImageDecoder_h |
33 | 33 |
34 #include "platform/image-decoders/FastSharedBufferReader.h" | |
35 #include "platform/image-decoders/bmp/BMPImageReader.h" | 34 #include "platform/image-decoders/bmp/BMPImageReader.h" |
36 | 35 |
37 namespace blink { | 36 namespace blink { |
38 | 37 |
39 class PNGImageDecoder; | 38 class PNGImageDecoder; |
40 | 39 |
41 // This class decodes the ICO and CUR image formats. | 40 // This class decodes the ICO and CUR image formats. |
42 class PLATFORM_EXPORT ICOImageDecoder : public ImageDecoder { | 41 class PLATFORM_EXPORT ICOImageDecoder : public ImageDecoder { |
43 public: | 42 public: |
44 ICOImageDecoder(AlphaOption, GammaAndColorProfileOption, size_t maxDecodedBy
tes); | 43 ICOImageDecoder(AlphaOption, GammaAndColorProfileOption, size_t maxDecodedBy
tes); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 76 |
78 // Returns true if |a| is a preferable icon entry to |b|. | 77 // Returns true if |a| is a preferable icon entry to |b|. |
79 // Larger sizes, or greater bitdepths at the same size, are preferable. | 78 // Larger sizes, or greater bitdepths at the same size, are preferable. |
80 static bool compareEntries(const IconDirectoryEntry& a, const IconDirectoryE
ntry& b); | 79 static bool compareEntries(const IconDirectoryEntry& a, const IconDirectoryE
ntry& b); |
81 | 80 |
82 // ImageDecoder: | 81 // ImageDecoder: |
83 virtual void decodeSize() { decode(0, true); } | 82 virtual void decodeSize() { decode(0, true); } |
84 size_t decodeFrameCount() override; | 83 size_t decodeFrameCount() override; |
85 void decode(size_t index) override { decode(index, false); } | 84 void decode(size_t index) override { decode(index, false); } |
86 | 85 |
87 // TODO (scroggo): These functions are identical to functions in BMPImageRea
der. Share code? | |
88 inline uint8_t readUint8(size_t offset) const | |
89 { | |
90 return m_fastReader.getOneByte(m_decodedOffset + offset); | |
91 } | |
92 | |
93 inline uint16_t readUint16(int offset) const | 86 inline uint16_t readUint16(int offset) const |
94 { | 87 { |
95 char buffer[2]; | 88 // TODO (scroggo): This consolidates the data, meaning unnecessary copie
s. |
96 const char* data = m_fastReader.getConsecutiveData(m_decodedOffset + off
set, 2, buffer); | 89 return BMPImageReader::readUint16(&m_data->data()[m_decodedOffset + offs
et]); |
97 return BMPImageReader::readUint16(data); | |
98 } | 90 } |
99 | 91 |
100 inline uint32_t readUint32(int offset) const | 92 inline uint32_t readUint32(int offset) const |
101 { | 93 { |
102 char buffer[4]; | 94 // TODO (scroggo): This consolidates the data, meaning unnecessary copie
s. |
103 const char* data = m_fastReader.getConsecutiveData(m_decodedOffset + off
set, 4, buffer); | 95 return BMPImageReader::readUint32(&m_data->data()[m_decodedOffset + offs
et]); |
104 return BMPImageReader::readUint32(data); | |
105 } | 96 } |
106 | 97 |
107 // If the desired PNGImageDecoder exists, gives it the appropriate data. | 98 // If the desired PNGImageDecoder exists, gives it the appropriate data. |
108 void setDataForPNGDecoderAtIndex(size_t); | 99 void setDataForPNGDecoderAtIndex(size_t); |
109 | 100 |
110 // Decodes the entry at |index|. If |onlySize| is true, stops decoding | 101 // Decodes the entry at |index|. If |onlySize| is true, stops decoding |
111 // after calculating the image size. If decoding fails but there is no | 102 // after calculating the image size. If decoding fails but there is no |
112 // more data coming, sets the "decode failure" flag. | 103 // more data coming, sets the "decode failure" flag. |
113 void decode(size_t index, bool onlySize); | 104 void decode(size_t index, bool onlySize); |
114 | 105 |
(...skipping 19 matching lines...) Expand all Loading... |
134 bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const; | 125 bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const; |
135 | 126 |
136 // Reads and returns a directory entry from the current offset into | 127 // Reads and returns a directory entry from the current offset into |
137 // |data|. | 128 // |data|. |
138 IconDirectoryEntry readDirectoryEntry(); | 129 IconDirectoryEntry readDirectoryEntry(); |
139 | 130 |
140 // Determines whether the desired entry is a BMP or PNG. Returns true | 131 // Determines whether the desired entry is a BMP or PNG. Returns true |
141 // if the type could be determined. | 132 // if the type could be determined. |
142 ImageType imageTypeAtIndex(size_t); | 133 ImageType imageTypeAtIndex(size_t); |
143 | 134 |
144 FastSharedBufferReader m_fastReader; | |
145 | |
146 // An index into |m_data| representing how much we've already decoded. | 135 // An index into |m_data| representing how much we've already decoded. |
147 // Note that this only tracks data _this_ class decodes; once the | 136 // Note that this only tracks data _this_ class decodes; once the |
148 // BMPImageReader takes over this will not be updated further. | 137 // BMPImageReader takes over this will not be updated further. |
149 size_t m_decodedOffset; | 138 size_t m_decodedOffset; |
150 | 139 |
151 // Which type of file (ICO/CUR) this is. | 140 // Which type of file (ICO/CUR) this is. |
152 FileType m_fileType; | 141 FileType m_fileType; |
153 | 142 |
154 // The headers for the ICO. | 143 // The headers for the ICO. |
155 typedef Vector<IconDirectoryEntry> IconDirectoryEntries; | 144 typedef Vector<IconDirectoryEntry> IconDirectoryEntries; |
156 IconDirectoryEntries m_dirEntries; | 145 IconDirectoryEntries m_dirEntries; |
157 | 146 |
158 // The image decoders for the various frames. | 147 // The image decoders for the various frames. |
159 typedef Vector<OwnPtr<BMPImageReader>> BMPReaders; | 148 typedef Vector<OwnPtr<BMPImageReader>> BMPReaders; |
160 BMPReaders m_bmpReaders; | 149 BMPReaders m_bmpReaders; |
161 typedef Vector<OwnPtr<PNGImageDecoder>> PNGDecoders; | 150 typedef Vector<OwnPtr<PNGImageDecoder>> PNGDecoders; |
162 PNGDecoders m_pngDecoders; | 151 PNGDecoders m_pngDecoders; |
163 | 152 |
164 // Valid only while a BMPImageReader is decoding, this holds the size | 153 // Valid only while a BMPImageReader is decoding, this holds the size |
165 // for the particular entry being decoded. | 154 // for the particular entry being decoded. |
166 IntSize m_frameSize; | 155 IntSize m_frameSize; |
167 }; | 156 }; |
168 | 157 |
169 } // namespace blink | 158 } // namespace blink |
170 | 159 |
171 #endif | 160 #endif |
OLD | NEW |