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 #include "config.h" | 31 #include "config.h" |
32 #include "platform/image-decoders/bmp/BMPImageDecoder.h" | 32 #include "platform/image-decoders/bmp/BMPImageDecoder.h" |
33 | 33 |
| 34 #include "platform/image-decoders/FastSharedBufferReader.h" |
34 #include "wtf/PassOwnPtr.h" | 35 #include "wtf/PassOwnPtr.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 // Number of bits in .BMP used to store the file header (doesn't match | 39 // Number of bits in .BMP used to store the file header (doesn't match |
39 // "sizeof(BMPImageDecoder::BitmapFileHeader)" since we omit some fields and | 40 // "sizeof(BMPImageDecoder::BitmapFileHeader)" since we omit some fields and |
40 // don't pack). | 41 // don't pack). |
41 static const size_t sizeOfFileHeader = 14; | 42 static const size_t sizeOfFileHeader = 14; |
42 | 43 |
43 BMPImageDecoder::BMPImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp
tion colorOptions, size_t maxDecodedBytes) | 44 BMPImageDecoder::BMPImageDecoder(AlphaOption alphaOption, GammaAndColorProfileOp
tion colorOptions, size_t maxDecodedBytes) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 94 |
94 return m_reader->decodeBMP(onlySize); | 95 return m_reader->decodeBMP(onlySize); |
95 } | 96 } |
96 | 97 |
97 bool BMPImageDecoder::processFileHeader(size_t& imgDataOffset) | 98 bool BMPImageDecoder::processFileHeader(size_t& imgDataOffset) |
98 { | 99 { |
99 // Read file header. | 100 // Read file header. |
100 ASSERT(!m_decodedOffset); | 101 ASSERT(!m_decodedOffset); |
101 if (m_data->size() < sizeOfFileHeader) | 102 if (m_data->size() < sizeOfFileHeader) |
102 return false; | 103 return false; |
103 const uint16_t fileType = (m_data->data()[0] << 8) | static_cast<uint8_t>(m_
data->data()[1]); | 104 |
104 imgDataOffset = readUint32(10); | 105 char buffer[sizeOfFileHeader]; |
| 106 FastSharedBufferReader fastReader(m_data); |
| 107 const char* fileHeader = fastReader.getConsecutiveData(0, sizeOfFileHeader,
buffer); |
| 108 const uint16_t fileType = (fileHeader[0] << 8) | static_cast<uint8_t>(fileHe
ader[1]); |
| 109 imgDataOffset = BMPImageReader::readUint32(&fileHeader[10]); |
105 m_decodedOffset = sizeOfFileHeader; | 110 m_decodedOffset = sizeOfFileHeader; |
106 | 111 |
107 // See if this is a bitmap filetype we understand. | 112 // See if this is a bitmap filetype we understand. |
108 enum { | 113 enum { |
109 BMAP = 0x424D, // "BM" | 114 BMAP = 0x424D, // "BM" |
110 // The following additional OS/2 2.x header values (see | 115 // The following additional OS/2 2.x header values (see |
111 // http://www.fileformat.info/format/os2bmp/egff.htm ) aren't widely | 116 // http://www.fileformat.info/format/os2bmp/egff.htm ) aren't widely |
112 // decoded, and are unlikely to be in much use. | 117 // decoded, and are unlikely to be in much use. |
113 /* | 118 /* |
114 ICON = 0x4943, // "IC" | 119 ICON = 0x4943, // "IC" |
115 POINTER = 0x5054, // "PT" | 120 POINTER = 0x5054, // "PT" |
116 COLORICON = 0x4349, // "CI" | 121 COLORICON = 0x4349, // "CI" |
117 COLORPOINTER = 0x4350, // "CP" | 122 COLORPOINTER = 0x4350, // "CP" |
118 BITMAPARRAY = 0x4241, // "BA" | 123 BITMAPARRAY = 0x4241, // "BA" |
119 */ | 124 */ |
120 }; | 125 }; |
121 return (fileType == BMAP) || setFailed(); | 126 return (fileType == BMAP) || setFailed(); |
122 } | 127 } |
123 | 128 |
124 } // namespace blink | 129 } // namespace blink |
OLD | NEW |