OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOp
tion alphaOption, GammaAndColorProfileOption colorOptions) | 120 PassOwnPtr<ImageDecoder> ImageDecoder::create(const SegmentReader& data, AlphaOp
tion alphaOption, GammaAndColorProfileOption colorOptions) |
121 { | 121 { |
122 const char* contents; | 122 const char* contents; |
123 const size_t length = data.getSomeData(contents, 0); | 123 const size_t length = data.getSomeData(contents, 0); |
124 return create(contents, length, alphaOption, colorOptions); | 124 return create(contents, length, alphaOption, colorOptions); |
125 } | 125 } |
126 | 126 |
127 size_t ImageDecoder::frameCount() | 127 size_t ImageDecoder::frameCount() |
128 { | 128 { |
| 129 if (m_haveUpdatedFrameCount) |
| 130 return m_frameBufferCache.size(); |
| 131 |
129 const size_t oldSize = m_frameBufferCache.size(); | 132 const size_t oldSize = m_frameBufferCache.size(); |
130 const size_t newSize = decodeFrameCount(); | 133 const size_t newSize = decodeFrameCount(); |
131 if (oldSize != newSize) { | 134 if (oldSize != newSize) { |
132 m_frameBufferCache.resize(newSize); | 135 m_frameBufferCache.resize(newSize); |
133 for (size_t i = oldSize; i < newSize; ++i) { | 136 for (size_t i = oldSize; i < newSize; ++i) { |
134 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); | 137 m_frameBufferCache[i].setPremultiplyAlpha(m_premultiplyAlpha); |
135 initializeNewFrame(i); | 138 initializeNewFrame(i); |
136 } | 139 } |
137 } | 140 } |
| 141 m_haveUpdatedFrameCount = true; |
138 return newSize; | 142 return newSize; |
139 } | 143 } |
140 | 144 |
141 ImageFrame* ImageDecoder::frameBufferAtIndex(size_t index) | 145 ImageFrame* ImageDecoder::frameBufferAtIndex(size_t index) |
142 { | 146 { |
143 if (index >= frameCount()) | 147 if (index >= frameCount()) |
144 return 0; | 148 return 0; |
145 | 149 |
146 ImageFrame* frame = &m_frameBufferCache[index]; | 150 ImageFrame* frame = &m_frameBufferCache[index]; |
147 if (frame->getStatus() != ImageFrame::FrameComplete) { | 151 if (frame->getStatus() != ImageFrame::FrameComplete) { |
148 PlatformInstrumentation::willDecodeImage(filenameExtension()); | 152 PlatformInstrumentation::willDecodeImage(filenameExtension()); |
149 decode(index); | 153 decode(index); |
150 PlatformInstrumentation::didDecodeImage(); | 154 PlatformInstrumentation::didDecodeImage(); |
151 } | 155 } |
152 | 156 |
153 frame->notifyBitmapIfPixelsChanged(); | 157 frame->notifyBitmapIfPixelsChanged(); |
154 return frame; | 158 return frame; |
155 } | 159 } |
156 | 160 |
157 bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const | 161 bool ImageDecoder::frameIsFullyReceivedAtIndex(size_t index) const |
158 { | 162 { |
159 return !frameIsCompleteAtIndex(index) || m_frameBufferCache[index].hasAlpha(
); | 163 DCHECK(m_haveUpdatedFrameCount); |
160 } | 164 return (index < m_frameBufferCache.size()) |
161 | 165 && (m_isAllDataReceived || failed() || m_frameBufferCache[index].getStat
us() == ImageFrame::FrameComplete); |
162 bool ImageDecoder::frameIsCompleteAtIndex(size_t index) const | |
163 { | |
164 return (index < m_frameBufferCache.size()) && | |
165 (m_frameBufferCache[index].getStatus() == ImageFrame::FrameComplete); | |
166 } | 166 } |
167 | 167 |
168 size_t ImageDecoder::frameBytesAtIndex(size_t index) const | 168 size_t ImageDecoder::frameBytesAtIndex(size_t index) const |
169 { | 169 { |
170 if (index >= m_frameBufferCache.size() || m_frameBufferCache[index].getStatu
s() == ImageFrame::FrameEmpty) | 170 if (index >= m_frameBufferCache.size() || m_frameBufferCache[index].getStatu
s() == ImageFrame::FrameEmpty) |
171 return 0; | 171 return 0; |
172 | 172 |
173 struct ImageSize { | 173 struct ImageSize { |
174 | 174 |
175 explicit ImageSize(IntSize size) | 175 explicit ImageSize(IntSize size) |
176 { | 176 { |
177 area = static_cast<uint64_t>(size.width()) * size.height(); | 177 area = static_cast<uint64_t>(size.width()) * size.height(); |
178 } | 178 } |
179 | 179 |
180 uint64_t area; | 180 uint64_t area; |
181 }; | 181 }; |
182 | 182 |
183 return ImageSize(frameSizeAtIndex(index)).area * sizeof(ImageFrame::PixelDat
a); | 183 return ImageSize(frameSizeAtIndex(index)).area * sizeof(ImageFrame::PixelDat
a); |
184 } | 184 } |
185 | 185 |
| 186 bool ImageDecoder::frameHasAlphaAtIndex(size_t index) const |
| 187 { |
| 188 DCHECK(m_haveUpdatedFrameCount); |
| 189 if (m_frameBufferCache.size() == 1) |
| 190 return !frameIsCompleteAtIndex(index) || m_frameBufferCache[index].hasAl
pha(); |
| 191 return !frameIsFullyReceivedAtIndex(index) || m_frameBufferCache[index].hasA
lpha(); |
| 192 } |
| 193 |
186 size_t ImageDecoder::clearCacheExceptFrame(size_t clearExceptFrame) | 194 size_t ImageDecoder::clearCacheExceptFrame(size_t clearExceptFrame) |
187 { | 195 { |
188 // Don't clear if there are no frames or only one frame. | 196 // Don't clear if there are no frames or only one frame. |
189 if (m_frameBufferCache.size() <= 1) | 197 if (m_frameBufferCache.size() <= 1) |
190 return 0; | 198 return 0; |
191 | 199 |
192 size_t frameBytesCleared = 0; | 200 size_t frameBytesCleared = 0; |
193 for (size_t i = 0; i < m_frameBufferCache.size(); ++i) { | 201 for (size_t i = 0; i < m_frameBufferCache.size(); ++i) { |
194 if (i != clearExceptFrame) { | 202 if (i != clearExceptFrame) { |
195 frameBytesCleared += frameBytesAtIndex(i); | 203 frameBytesCleared += frameBytesAtIndex(i); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 371 |
364 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; | 372 qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8; |
365 | 373 |
366 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. | 374 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. |
367 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil
e.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPT
UAL)); | 375 m_sourceToOutputDeviceColorTransform.reset(qcms_transform_create(inputProfil
e.get(), dataFormat, gOutputDeviceProfile, QCMS_DATA_RGBA_8, QCMS_INTENT_PERCEPT
UAL)); |
368 } | 376 } |
369 | 377 |
370 #endif // USE(QCMSLIB) | 378 #endif // USE(QCMSLIB) |
371 | 379 |
372 } // namespace blink | 380 } // namespace blink |
OLD | NEW |