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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 | 149 |
150 WEBPImageDecoder::~WEBPImageDecoder() | 150 WEBPImageDecoder::~WEBPImageDecoder() |
151 { | 151 { |
152 clear(); | 152 clear(); |
153 } | 153 } |
154 | 154 |
155 void WEBPImageDecoder::clear() | 155 void WEBPImageDecoder::clear() |
156 { | 156 { |
157 #if USE(QCMSLIB) | 157 #if USE(QCMSLIB) |
158 if (m_transform) | 158 clearColorTransform(); |
159 qcms_transform_release(m_transform); | |
160 m_transform = 0; | |
161 #endif | 159 #endif |
162 WebPDemuxDelete(m_demux); | 160 WebPDemuxDelete(m_demux); |
163 m_demux = 0; | 161 m_demux = 0; |
164 clearDecoder(); | 162 clearDecoder(); |
165 } | 163 } |
166 | 164 |
167 void WEBPImageDecoder::clearDecoder() | 165 void WEBPImageDecoder::clearDecoder() |
168 { | 166 { |
169 WebPIDelete(m_decoder); | 167 WebPIDelete(m_decoder); |
170 m_decoder = 0; | 168 m_decoder = 0; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 399 |
402 void WEBPImageDecoder::clearFrameBuffer(size_t frameIndex) | 400 void WEBPImageDecoder::clearFrameBuffer(size_t frameIndex) |
403 { | 401 { |
404 if (m_demux && m_demuxState >= WEBP_DEMUX_PARSED_HEADER && m_frameBufferCach
e[frameIndex].status() == ImageFrame::FramePartial) { | 402 if (m_demux && m_demuxState >= WEBP_DEMUX_PARSED_HEADER && m_frameBufferCach
e[frameIndex].status() == ImageFrame::FramePartial) { |
405 // Clear the decoder state so that this partial frame can be decoded aga
in when requested. | 403 // Clear the decoder state so that this partial frame can be decoded aga
in when requested. |
406 clearDecoder(); | 404 clearDecoder(); |
407 } | 405 } |
408 ImageDecoder::clearFrameBuffer(frameIndex); | 406 ImageDecoder::clearFrameBuffer(frameIndex); |
409 } | 407 } |
410 | 408 |
| 409 PassRefPtr<ColorSpaceProfile> WEBPImageDecoder::colorProfile() const |
| 410 { |
| 411 #if USE(QCMSLIB) |
| 412 return m_colorProfile; |
| 413 #else |
| 414 return nullptr; |
| 415 #endif |
| 416 } |
| 417 |
411 #if USE(QCMSLIB) | 418 #if USE(QCMSLIB) |
412 | 419 |
413 void WEBPImageDecoder::createColorTransform(const char* data, size_t size) | 420 void WEBPImageDecoder::clearColorTransform() |
414 { | 421 { |
415 if (m_transform) | 422 if (m_transform) |
416 qcms_transform_release(m_transform); | 423 qcms_transform_release(m_transform); |
417 m_transform = 0; | 424 m_transform = 0; |
| 425 } |
418 | 426 |
| 427 bool WEBPImageDecoder::createColorTransform(const char* data, size_t size) |
| 428 { |
| 429 clearColorTransform(); |
| 430 ASSERT(size >= ImageDecoder::iccColorProfileHeaderLength); |
419 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); | 431 qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile(); |
420 if (!deviceProfile) | 432 if (!deviceProfile) |
421 return; | 433 return false; |
422 qcms_profile* inputProfile = qcms_profile_from_memory(data, size); | 434 qcms_profile* inputProfile = qcms_profile_from_memory(data, size); |
423 if (!inputProfile) | 435 if (!inputProfile) |
424 return; | 436 return false; |
425 | |
426 // We currently only support color profiles for RGB profiled images. | 437 // We currently only support color profiles for RGB profiled images. |
427 ASSERT(icSigRgbData == qcms_profile_get_color_space(inputProfile)); | 438 ASSERT(icSigRgbData == qcms_profile_get_color_space(inputProfile)); |
428 // The input image pixels are RGBA format. | 439 // The input image pixels are RGBA format. |
429 qcms_data_type format = QCMS_DATA_RGBA_8; | 440 qcms_data_type format = QCMS_DATA_RGBA_8; |
430 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. | 441 // FIXME: Don't force perceptual intent if the image profile contains an int
ent. |
431 m_transform = qcms_transform_create(inputProfile, format, deviceProfile, QCM
S_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL); | 442 m_transform = qcms_transform_create(inputProfile, format, deviceProfile, QCM
S_DATA_RGBA_8, QCMS_INTENT_PERCEPTUAL); |
432 | |
433 qcms_profile_release(inputProfile); | 443 qcms_profile_release(inputProfile); |
| 444 return true; |
434 } | 445 } |
435 | 446 |
436 void WEBPImageDecoder::readColorProfile() | 447 void WEBPImageDecoder::readColorProfile() |
437 { | 448 { |
438 WebPChunkIterator chunkIterator; | 449 WebPChunkIterator chunkIterator; |
439 if (!WebPDemuxGetChunk(m_demux, "ICCP", 1, &chunkIterator)) { | 450 if (!WebPDemuxGetChunk(m_demux, "ICCP", 1, &chunkIterator)) { |
440 WebPDemuxReleaseChunkIterator(&chunkIterator); | 451 WebPDemuxReleaseChunkIterator(&chunkIterator); |
441 return; | 452 return; |
442 } | 453 } |
443 | 454 |
444 const char* profileData = reinterpret_cast<const char*>(chunkIterator.chunk.
bytes); | 455 const char* profileData = reinterpret_cast<const char*>(chunkIterator.chunk.
bytes); |
445 size_t profileSize = chunkIterator.chunk.size; | 456 size_t profileSize = chunkIterator.chunk.size; |
446 | 457 |
447 // Only accept RGB color profiles from input class devices. | 458 // Only accept RGB color profiles from input class devices. |
448 bool ignoreProfile = false; | 459 bool ignoreProfile = false; |
449 if (profileSize < ImageDecoder::iccColorProfileHeaderLength) | 460 if (profileSize < ImageDecoder::iccColorProfileHeaderLength) |
450 ignoreProfile = true; | 461 ignoreProfile = true; |
451 else if (!ImageDecoder::rgbColorProfile(profileData, profileSize)) | 462 else if (!ImageDecoder::rgbColorProfile(profileData, profileSize)) |
452 ignoreProfile = true; | 463 ignoreProfile = true; |
453 else if (!ImageDecoder::inputDeviceColorProfile(profileData, profileSize)) | 464 else if (!ImageDecoder::inputDeviceColorProfile(profileData, profileSize)) |
454 ignoreProfile = true; | 465 ignoreProfile = true; |
455 | 466 |
456 if (!ignoreProfile) | 467 if (!ignoreProfile && createColorTransform(profileData, profileSize)) { |
457 createColorTransform(profileData, profileSize); | 468 // FIXME: paint-time color correction is assumed here. |
| 469 qcms_profile* profile = qcms_profile_from_memory(profileData, profileSiz
e); |
| 470 RefPtr<ColorSpaceProfile> imageColorProfile = ColorSpaceProfile::create(
profile); |
| 471 m_hasColorProfile = !!imageColorProfile->profile(); |
| 472 m_colorProfile = m_hasColorProfile ? imageColorProfile : nullptr; |
| 473 // Don't color correct decoded frames during decoding. |
| 474 clearColorTransform(); |
| 475 ASSERT(!m_transform); |
| 476 } |
458 | 477 |
459 WebPDemuxReleaseChunkIterator(&chunkIterator); | 478 WebPDemuxReleaseChunkIterator(&chunkIterator); |
460 } | 479 } |
461 | 480 |
462 #endif // USE(QCMSLIB) | 481 #endif // USE(QCMSLIB) |
463 | 482 |
464 void WEBPImageDecoder::applyPostProcessing(size_t frameIndex) | 483 void WEBPImageDecoder::applyPostProcessing(size_t frameIndex) |
465 { | 484 { |
466 ImageFrame& buffer = m_frameBufferCache[frameIndex]; | 485 ImageFrame& buffer = m_frameBufferCache[frameIndex]; |
467 int width; | 486 int width; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 return false; | 623 return false; |
605 } | 624 } |
606 // FALLTHROUGH | 625 // FALLTHROUGH |
607 default: | 626 default: |
608 clear(); | 627 clear(); |
609 return setFailed(); | 628 return setFailed(); |
610 } | 629 } |
611 } | 630 } |
612 | 631 |
613 } // namespace WebCore | 632 } // namespace WebCore |
OLD | NEW |