| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "platform/image-decoders/webp/WEBPImageDecoder.h" | 30 #include "platform/image-decoders/webp/WEBPImageDecoder.h" |
| 31 | 31 |
| 32 #include "platform/graphics/GraphicsScreen.h" |
| 33 |
| 32 #if USE(QCMSLIB) | 34 #if USE(QCMSLIB) |
| 33 #include "qcms.h" | 35 #include "qcms.h" |
| 34 #endif | 36 #endif |
| 35 | 37 |
| 36 #if CPU(BIG_ENDIAN) || CPU(MIDDLE_ENDIAN) | 38 #if CPU(BIG_ENDIAN) || CPU(MIDDLE_ENDIAN) |
| 37 #error Blink assumes a little-endian target. | 39 #error Blink assumes a little-endian target. |
| 38 #endif | 40 #endif |
| 39 | 41 |
| 40 #if SK_B32_SHIFT // Output little-endian RGBA pixels (Android). | 42 #if SK_B32_SHIFT // Output little-endian RGBA pixels (Android). |
| 41 inline WEBP_CSP_MODE outputMode(bool hasAlpha) { return hasAlpha ? MODE_rgbA : M
ODE_RGBA; } | 43 inline WEBP_CSP_MODE outputMode(bool hasAlpha) { return hasAlpha ? MODE_rgbA : M
ODE_RGBA; } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 311 |
| 310 #if USE(QCMSLIB) | 312 #if USE(QCMSLIB) |
| 311 | 313 |
| 312 void WEBPImageDecoder::clearColorTransform() | 314 void WEBPImageDecoder::clearColorTransform() |
| 313 { | 315 { |
| 314 if (m_transform) | 316 if (m_transform) |
| 315 qcms_transform_release(m_transform); | 317 qcms_transform_release(m_transform); |
| 316 m_transform = 0; | 318 m_transform = 0; |
| 317 } | 319 } |
| 318 | 320 |
| 319 bool WEBPImageDecoder::createColorTransform(const char* data, size_t size) | 321 PassRefPtr<ColorSpaceProfile> WEBPImageDecoder::createColorTransform(const char*
data, size_t size) |
| 320 { | 322 { |
| 321 clearColorTransform(); | 323 clearColorTransform(); |
| 322 | 324 |
| 323 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); | 325 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); |
| 324 if (!deviceProfile) | 326 if (!deviceProfile) |
| 325 return false; | 327 return nullptr; |
| 328 |
| 326 qcms_profile* inputProfile = qcms_profile_from_memory(data, size); | 329 qcms_profile* inputProfile = qcms_profile_from_memory(data, size); |
| 327 if (!inputProfile) | 330 if (!inputProfile) |
| 328 return false; | 331 return nullptr; |
| 329 | 332 |
| 330 // We currently only support color profiles for RGB profiled images. | 333 // We currently only support color profiles for RGB profiled images. |
| 331 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); | 334 ASSERT(rgbData == qcms_profile_get_color_space(inputProfile)); |
| 332 // The input image pixels are RGBA format. | 335 // The input image pixels are RGBA format. |
| 333 qcms_data_type format = QCMS_DATA_RGBA_8; | 336 qcms_data_type format = QCMS_DATA_RGBA_8; |
| 334 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. | 337 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. |
| 335 m_transform = qcms_transform_create(inputProfile, format, deviceProfile, QCM
S_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL); | 338 m_transform = qcms_transform_create(inputProfile, format, deviceProfile, QCM
S_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL); |
| 339 if (m_transform) |
| 340 return ColorSpaceProfile::create(inputProfile); |
| 336 | 341 |
| 337 qcms_profile_release(inputProfile); | 342 qcms_profile_release(inputProfile); |
| 338 return !!m_transform; | 343 return nullptr; |
| 339 } | 344 } |
| 340 | 345 |
| 341 void WEBPImageDecoder::readColorProfile() | 346 void WEBPImageDecoder::readColorProfile() |
| 342 { | 347 { |
| 343 WebPChunkIterator chunkIterator; | 348 WebPChunkIterator chunkIterator; |
| 344 if (!WebPDemuxGetChunk(m_demux, "ICCP", 1, &chunkIterator)) { | 349 if (!WebPDemuxGetChunk(m_demux, "ICCP", 1, &chunkIterator)) { |
| 350 RELEASE_ASSERT(!m_hasColorProfile && !m_transform); |
| 345 WebPDemuxReleaseChunkIterator(&chunkIterator); | 351 WebPDemuxReleaseChunkIterator(&chunkIterator); |
| 346 return; | 352 return; |
| 347 } | 353 } |
| 348 | 354 |
| 349 const char* profileData = reinterpret_cast<const char*>(chunkIterator.chunk.
bytes); | 355 const char* profileData = reinterpret_cast<const char*>(chunkIterator.chunk.
bytes); |
| 350 size_t profileSize = chunkIterator.chunk.size; | 356 size_t profileSize = chunkIterator.chunk.size; |
| 351 | 357 |
| 352 // Only accept RGB color profiles from input class devices. | 358 // Only accept RGB color profiles from input class devices. |
| 353 bool ignoreProfile = false; | 359 bool ignoreProfile = false; |
| 354 if (profileSize < ImageDecoder::iccColorProfileHeaderLength) | 360 if (profileSize < ImageDecoder::iccColorProfileHeaderLength) |
| 355 ignoreProfile = true; | 361 ignoreProfile = true; |
| 356 else if (!ImageDecoder::rgbColorProfile(profileData, profileSize)) | 362 else if (!ImageDecoder::rgbColorProfile(profileData, profileSize)) |
| 357 ignoreProfile = true; | 363 ignoreProfile = true; |
| 358 else if (!ImageDecoder::inputDeviceColorProfile(profileData, profileSize)) | 364 else if (!ImageDecoder::inputDeviceColorProfile(profileData, profileSize)) |
| 359 ignoreProfile = true; | 365 ignoreProfile = true; |
| 360 | 366 |
| 361 if (!ignoreProfile) | 367 if (ignoreProfile) { |
| 362 m_hasColorProfile = createColorTransform(profileData, profileSize); | 368 RELEASE_ASSERT(!m_hasColorProfile && !m_transform); |
| 369 WebPDemuxReleaseChunkIterator(&chunkIterator); |
| 370 return; |
| 371 } |
| 372 |
| 373 RefPtr<ColorSpaceProfile> imageColorProfile = createColorTransform(profileDa
ta, profileSize); |
| 374 m_hasColorProfile = !!imageColorProfile.get(); |
| 375 |
| 376 if (m_hasColorProfile && imageColorProfilesEnabled()) { |
| 377 RELEASE_ASSERT(imageColorProfile->profile()); |
| 378 m_colorProfile = imageColorProfile; |
| 379 // Do not color correct decoded frames during decoding. |
| 380 clearColorTransform(); |
| 381 RELEASE_ASSERT(!m_transform); |
| 382 } |
| 363 | 383 |
| 364 WebPDemuxReleaseChunkIterator(&chunkIterator); | 384 WebPDemuxReleaseChunkIterator(&chunkIterator); |
| 365 } | 385 } |
| 366 | 386 |
| 367 #endif // USE(QCMSLIB) | 387 #endif // USE(QCMSLIB) |
| 368 | 388 |
| 369 void WEBPImageDecoder::applyPostProcessing(size_t frameIndex) | 389 void WEBPImageDecoder::applyPostProcessing(size_t frameIndex) |
| 370 { | 390 { |
| 371 ImageFrame& buffer = m_frameBufferCache[frameIndex]; | 391 ImageFrame& buffer = m_frameBufferCache[frameIndex]; |
| 372 int width; | 392 int width; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 return false; | 571 return false; |
| 552 } | 572 } |
| 553 // FALLTHROUGH | 573 // FALLTHROUGH |
| 554 default: | 574 default: |
| 555 clear(); | 575 clear(); |
| 556 return setFailed(); | 576 return setFailed(); |
| 557 } | 577 } |
| 558 } | 578 } |
| 559 | 579 |
| 560 } // namespace blink | 580 } // namespace blink |
| OLD | NEW |