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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 if (failed()) | 60 if (failed()) |
61 return; | 61 return; |
62 | 62 |
63 // If we couldn't decode the image but we've received all the data, decoding | 63 // If we couldn't decode the image but we've received all the data, decoding |
64 // has failed. | 64 // has failed. |
65 if (!decodeHelper(onlySize) && isAllDataReceived()) | 65 if (!decodeHelper(onlySize) && isAllDataReceived()) |
66 setFailed(); | 66 setFailed(); |
67 // If we're done decoding the image, we don't need the BMPImageReader | 67 // If we're done decoding the image, we don't need the BMPImageReader |
68 // anymore. (If we failed, |m_reader| has already been cleared.) | 68 // anymore. (If we failed, |m_reader| has already been cleared.) |
69 else if (!m_frameBufferCache.isEmpty() && | 69 else if (!m_frameBufferCache.isEmpty() && |
70 (m_frameBufferCache.first().getStatus() == | 70 (m_frameBufferCache.front().getStatus() == |
71 ImageFrame::FrameComplete)) | 71 ImageFrame::FrameComplete)) |
72 m_reader.reset(); | 72 m_reader.reset(); |
73 } | 73 } |
74 | 74 |
75 bool BMPImageDecoder::decodeHelper(bool onlySize) { | 75 bool BMPImageDecoder::decodeHelper(bool onlySize) { |
76 size_t imgDataOffset = 0; | 76 size_t imgDataOffset = 0; |
77 if ((m_decodedOffset < sizeOfFileHeader) && !processFileHeader(imgDataOffset)) | 77 if ((m_decodedOffset < sizeOfFileHeader) && !processFileHeader(imgDataOffset)) |
78 return false; | 78 return false; |
79 | 79 |
80 if (!m_reader) { | 80 if (!m_reader) { |
81 m_reader = wrapUnique( | 81 m_reader = wrapUnique( |
82 new BMPImageReader(this, m_decodedOffset, imgDataOffset, false)); | 82 new BMPImageReader(this, m_decodedOffset, imgDataOffset, false)); |
83 m_reader->setData(m_data.get()); | 83 m_reader->setData(m_data.get()); |
84 } | 84 } |
85 | 85 |
86 if (!m_frameBufferCache.isEmpty()) | 86 if (!m_frameBufferCache.isEmpty()) |
87 m_reader->setBuffer(&m_frameBufferCache.first()); | 87 m_reader->setBuffer(&m_frameBufferCache.front()); |
88 | 88 |
89 return m_reader->decodeBMP(onlySize); | 89 return m_reader->decodeBMP(onlySize); |
90 } | 90 } |
91 | 91 |
92 bool BMPImageDecoder::processFileHeader(size_t& imgDataOffset) { | 92 bool BMPImageDecoder::processFileHeader(size_t& imgDataOffset) { |
93 // Read file header. | 93 // Read file header. |
94 ASSERT(!m_decodedOffset); | 94 ASSERT(!m_decodedOffset); |
95 if (m_data->size() < sizeOfFileHeader) | 95 if (m_data->size() < sizeOfFileHeader) |
96 return false; | 96 return false; |
97 | 97 |
(...skipping 17 matching lines...) Expand all Loading... |
115 POINTER = 0x5054, // "PT" | 115 POINTER = 0x5054, // "PT" |
116 COLORICON = 0x4349, // "CI" | 116 COLORICON = 0x4349, // "CI" |
117 COLORPOINTER = 0x4350, // "CP" | 117 COLORPOINTER = 0x4350, // "CP" |
118 BITMAPARRAY = 0x4241, // "BA" | 118 BITMAPARRAY = 0x4241, // "BA" |
119 */ | 119 */ |
120 }; | 120 }; |
121 return (fileType == BMAP) || setFailed(); | 121 return (fileType == BMAP) || setFailed(); |
122 } | 122 } |
123 | 123 |
124 } // namespace blink | 124 } // namespace blink |
OLD | NEW |