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" | |
34 #include "platform/image-decoders/bmp/BMPImageReader.h" | 35 #include "platform/image-decoders/bmp/BMPImageReader.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 class PNGImageDecoder; | 39 class PNGImageDecoder; |
39 | 40 |
40 // This class decodes the ICO and CUR image formats. | 41 // This class decodes the ICO and CUR image formats. |
41 class PLATFORM_EXPORT ICOImageDecoder : public ImageDecoder { | 42 class PLATFORM_EXPORT ICOImageDecoder : public ImageDecoder { |
42 public: | 43 public: |
43 ICOImageDecoder(AlphaOption, GammaAndColorProfileOption, size_t maxDecodedBy tes); | 44 ICOImageDecoder(AlphaOption, GammaAndColorProfileOption, size_t maxDecodedBy tes); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 | 77 |
77 // Returns true if |a| is a preferable icon entry to |b|. | 78 // Returns true if |a| is a preferable icon entry to |b|. |
78 // Larger sizes, or greater bitdepths at the same size, are preferable. | 79 // Larger sizes, or greater bitdepths at the same size, are preferable. |
79 static bool compareEntries(const IconDirectoryEntry& a, const IconDirectoryE ntry& b); | 80 static bool compareEntries(const IconDirectoryEntry& a, const IconDirectoryE ntry& b); |
80 | 81 |
81 // ImageDecoder: | 82 // ImageDecoder: |
82 virtual void decodeSize() { decode(0, true); } | 83 virtual void decodeSize() { decode(0, true); } |
83 size_t decodeFrameCount() override; | 84 size_t decodeFrameCount() override; |
84 void decode(size_t index) override { decode(index, false); } | 85 void decode(size_t index) override { decode(index, false); } |
85 | 86 |
87 // TODO (scroggo): These functions are identical to functions in BMPImageRea der. Share code? | |
Peter Kasting
2015/09/08 20:03:13
Yeah, we should share the code.
This seems like a
scroggo_chromium
2015/09/08 20:52:51
On the other hand, not all of the classes need a F
Peter Kasting
2015/09/08 21:01:05
Well, with PNG and JPEG, we rely on an external de
scroggo_chromium
2015/09/09 14:32:23
Actually, no. JPEG does use an external library, b
| |
88 inline uint8_t readUint8(size_t offset) const | |
89 { | |
90 return m_fastReader.getOneByte(m_decodedOffset + offset); | |
91 } | |
92 | |
86 inline uint16_t readUint16(int offset) const | 93 inline uint16_t readUint16(int offset) const |
87 { | 94 { |
88 // TODO (scroggo): This consolidates the data, meaning unnecessary copie s. | 95 char buffer[2]; |
89 return BMPImageReader::readUint16(&m_data->data()[m_decodedOffset + offs et]); | 96 const char* data = m_fastReader.getConsecutiveData(m_decodedOffset + off set, 2, buffer); |
97 return BMPImageReader::readUint16(data); | |
90 } | 98 } |
91 | 99 |
92 inline uint32_t readUint32(int offset) const | 100 inline uint32_t readUint32(int offset) const |
93 { | 101 { |
94 // TODO (scroggo): This consolidates the data, meaning unnecessary copie s. | 102 char buffer[4]; |
95 return BMPImageReader::readUint32(&m_data->data()[m_decodedOffset + offs et]); | 103 const char* data = m_fastReader.getConsecutiveData(m_decodedOffset + off set, 4, buffer); |
104 return BMPImageReader::readUint32(data); | |
96 } | 105 } |
97 | 106 |
98 // If the desired PNGImageDecoder exists, gives it the appropriate data. | 107 // If the desired PNGImageDecoder exists, gives it the appropriate data. |
99 void setDataForPNGDecoderAtIndex(size_t); | 108 void setDataForPNGDecoderAtIndex(size_t); |
100 | 109 |
101 // Decodes the entry at |index|. If |onlySize| is true, stops decoding | 110 // Decodes the entry at |index|. If |onlySize| is true, stops decoding |
102 // after calculating the image size. If decoding fails but there is no | 111 // after calculating the image size. If decoding fails but there is no |
103 // more data coming, sets the "decode failure" flag. | 112 // more data coming, sets the "decode failure" flag. |
104 void decode(size_t index, bool onlySize); | 113 void decode(size_t index, bool onlySize); |
105 | 114 |
(...skipping 19 matching lines...) Expand all Loading... | |
125 bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const; | 134 bool hotSpotAtIndex(size_t index, IntPoint& hotSpot) const; |
126 | 135 |
127 // Reads and returns a directory entry from the current offset into | 136 // Reads and returns a directory entry from the current offset into |
128 // |data|. | 137 // |data|. |
129 IconDirectoryEntry readDirectoryEntry(); | 138 IconDirectoryEntry readDirectoryEntry(); |
130 | 139 |
131 // Determines whether the desired entry is a BMP or PNG. Returns true | 140 // Determines whether the desired entry is a BMP or PNG. Returns true |
132 // if the type could be determined. | 141 // if the type could be determined. |
133 ImageType imageTypeAtIndex(size_t); | 142 ImageType imageTypeAtIndex(size_t); |
134 | 143 |
144 FastSharedBufferReader m_fastReader; | |
145 | |
135 // An index into |m_data| representing how much we've already decoded. | 146 // An index into |m_data| representing how much we've already decoded. |
136 // Note that this only tracks data _this_ class decodes; once the | 147 // Note that this only tracks data _this_ class decodes; once the |
137 // BMPImageReader takes over this will not be updated further. | 148 // BMPImageReader takes over this will not be updated further. |
138 size_t m_decodedOffset; | 149 size_t m_decodedOffset; |
139 | 150 |
140 // Which type of file (ICO/CUR) this is. | 151 // Which type of file (ICO/CUR) this is. |
141 FileType m_fileType; | 152 FileType m_fileType; |
142 | 153 |
143 // The headers for the ICO. | 154 // The headers for the ICO. |
144 typedef Vector<IconDirectoryEntry> IconDirectoryEntries; | 155 typedef Vector<IconDirectoryEntry> IconDirectoryEntries; |
145 IconDirectoryEntries m_dirEntries; | 156 IconDirectoryEntries m_dirEntries; |
146 | 157 |
147 // The image decoders for the various frames. | 158 // The image decoders for the various frames. |
148 typedef Vector<OwnPtr<BMPImageReader>> BMPReaders; | 159 typedef Vector<OwnPtr<BMPImageReader>> BMPReaders; |
149 BMPReaders m_bmpReaders; | 160 BMPReaders m_bmpReaders; |
150 typedef Vector<OwnPtr<PNGImageDecoder>> PNGDecoders; | 161 typedef Vector<OwnPtr<PNGImageDecoder>> PNGDecoders; |
151 PNGDecoders m_pngDecoders; | 162 PNGDecoders m_pngDecoders; |
152 | 163 |
153 // Valid only while a BMPImageReader is decoding, this holds the size | 164 // Valid only while a BMPImageReader is decoding, this holds the size |
154 // for the particular entry being decoded. | 165 // for the particular entry being decoded. |
155 IntSize m_frameSize; | 166 IntSize m_frameSize; |
156 }; | 167 }; |
157 | 168 |
158 } // namespace blink | 169 } // namespace blink |
159 | 170 |
160 #endif | 171 #endif |
OLD | NEW |