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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 setFailed(); | 103 setFailed(); |
104 // If we're done decoding the image, we don't need the BMPImageReader | 104 // If we're done decoding the image, we don't need the BMPImageReader |
105 // anymore. (If we failed, |m_reader| has already been cleared.) | 105 // anymore. (If we failed, |m_reader| has already been cleared.) |
106 else if (!m_frameBufferCache.isEmpty() && (m_frameBufferCache.first().status
() == ImageFrame::FrameComplete)) | 106 else if (!m_frameBufferCache.isEmpty() && (m_frameBufferCache.first().status
() == ImageFrame::FrameComplete)) |
107 m_reader.clear(); | 107 m_reader.clear(); |
108 } | 108 } |
109 | 109 |
110 bool BMPImageDecoder::decodeHelper(bool onlySize) | 110 bool BMPImageDecoder::decodeHelper(bool onlySize) |
111 { | 111 { |
112 size_t imgDataOffset = 0; | 112 size_t imgDataOffset = 0; |
113 if ((m_decodedOffset < sizeOfFileHeader) && !processFileHeader(&imgDataOffse
t)) | 113 if ((m_decodedOffset < sizeOfFileHeader) && !processFileHeader(imgDataOffset
)) |
114 return false; | 114 return false; |
115 | 115 |
116 if (!m_reader) { | 116 if (!m_reader) { |
117 m_reader = adoptPtr(new BMPImageReader(this, m_decodedOffset, imgDataOff
set, false)); | 117 m_reader = adoptPtr(new BMPImageReader(this, m_decodedOffset, imgDataOff
set, false)); |
118 m_reader->setData(m_data.get()); | 118 m_reader->setData(m_data.get()); |
119 } | 119 } |
120 | 120 |
121 if (!m_frameBufferCache.isEmpty()) | 121 if (!m_frameBufferCache.isEmpty()) |
122 m_reader->setBuffer(&m_frameBufferCache.first()); | 122 m_reader->setBuffer(&m_frameBufferCache.first()); |
123 | 123 |
124 return m_reader->decodeBMP(onlySize); | 124 return m_reader->decodeBMP(onlySize); |
125 } | 125 } |
126 | 126 |
127 bool BMPImageDecoder::processFileHeader(size_t* imgDataOffset) | 127 bool BMPImageDecoder::processFileHeader(size_t& imgDataOffset) |
128 { | 128 { |
129 ASSERT(imgDataOffset); | |
130 | |
131 // Read file header. | 129 // Read file header. |
132 ASSERT(!m_decodedOffset); | 130 ASSERT(!m_decodedOffset); |
133 if (m_data->size() < sizeOfFileHeader) | 131 if (m_data->size() < sizeOfFileHeader) |
134 return false; | 132 return false; |
135 const uint16_t fileType = (m_data->data()[0] << 8) | static_cast<uint8_t>(m_
data->data()[1]); | 133 const uint16_t fileType = (m_data->data()[0] << 8) | static_cast<uint8_t>(m_
data->data()[1]); |
136 *imgDataOffset = readUint32(10); | 134 imgDataOffset = readUint32(10); |
137 m_decodedOffset = sizeOfFileHeader; | 135 m_decodedOffset = sizeOfFileHeader; |
138 | 136 |
139 // See if this is a bitmap filetype we understand. | 137 // See if this is a bitmap filetype we understand. |
140 enum { | 138 enum { |
141 BMAP = 0x424D, // "BM" | 139 BMAP = 0x424D, // "BM" |
142 // The following additional OS/2 2.x header values (see | 140 // The following additional OS/2 2.x header values (see |
143 // http://www.fileformat.info/format/os2bmp/egff.htm ) aren't widely | 141 // http://www.fileformat.info/format/os2bmp/egff.htm ) aren't widely |
144 // decoded, and are unlikely to be in much use. | 142 // decoded, and are unlikely to be in much use. |
145 /* | 143 /* |
146 ICON = 0x4943, // "IC" | 144 ICON = 0x4943, // "IC" |
147 POINTER = 0x5054, // "PT" | 145 POINTER = 0x5054, // "PT" |
148 COLORICON = 0x4349, // "CI" | 146 COLORICON = 0x4349, // "CI" |
149 COLORPOINTER = 0x4350, // "CP" | 147 COLORPOINTER = 0x4350, // "CP" |
150 BITMAPARRAY = 0x4241, // "BA" | 148 BITMAPARRAY = 0x4241, // "BA" |
151 */ | 149 */ |
152 }; | 150 }; |
153 return (fileType == BMAP) || setFailed(); | 151 return (fileType == BMAP) || setFailed(); |
154 } | 152 } |
155 | 153 |
156 } // namespace blink | 154 } // namespace blink |
OLD | NEW |