Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Unified Diff: third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp

Issue 1309393007: [poc] redecode Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: resetColorProfileForTesting rename Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
diff --git a/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp b/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
index 01b8f3f880c53b73c69c7ec9112396a946a50381..b2aa570e5a00d5cbf06c835e2232ceae3de3f2b0 100644
--- a/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
@@ -39,6 +39,7 @@
#include "platform/image-decoders/jpeg/JPEGImageDecoder.h"
#include "platform/PlatformInstrumentation.h"
+#include "platform/graphics/GraphicsScreen.h"
extern "C" {
#include <stdio.h> // jpeglib.h needs stdio FILE.
@@ -477,16 +478,22 @@ public:
if (!m_decoder->ignoresGammaAndColorProfile()) {
ColorProfile colorProfile;
readColorProfile(info(), colorProfile);
- createColorTransform(colorProfile, colorSpaceHasAlpha(m_info.out_color_space));
- if (m_transform) {
+ bool imageHasAlpha = colorSpaceHasAlpha(m_info.out_color_space);
+ RefPtr<ColorSpaceProfile> imageColorProfile = createColorTransform(colorProfile, imageHasAlpha);
+ m_decoder->setHasColorProfile(!!imageColorProfile.get());
+ if (m_decoder->hasColorProfile()) {
+ // FIXME: allow YUV decoding of color profiled images.
overrideColorSpace = JCS_UNKNOWN;
#if defined(TURBO_JPEG_RGB_SWIZZLE)
// Input RGBA data to qcms. Note: restored to BGRA on output.
- if (m_info.out_color_space == JCS_EXT_BGRA)
+ if (m_transform && m_info.out_color_space == JCS_EXT_BGRA)
m_info.out_color_space = JCS_EXT_RGBA;
#endif
+ if (imageColorProfilesEnabled()) {
+ RELEASE_ASSERT(imageColorProfile->profile());
+ m_decoder->setColorProfile(imageColorProfile);
+ }
}
- m_decoder->setHasColorProfile(!!m_transform);
}
#endif
if (overrideColorSpace == JCS_YCbCr) {
@@ -503,6 +510,8 @@ public:
m_err.num_corrupt_warnings = 0;
}
+ fprintf(stderr, "JPEG decoder %p headerAvailable %dx%d %s\n", m_decoder, m_info.image_width, m_info.image_height, onlySize ? "size-only-decode" : "");
+
if (onlySize) {
// This exits the function while there is still potentially
// data in the buffer. Before this function is called again,
@@ -635,24 +644,50 @@ public:
m_transform = 0;
}
- void createColorTransform(const ColorProfile& colorProfile, bool hasAlpha)
+ PassRefPtr<ColorSpaceProfile> createColorTransform(const ColorProfile& colorProfile, bool hasAlpha)
{
clearColorTransform();
+ fprintf(stderr, "JPEG decoder %p createColorTransform ", m_decoder);
+
+ if (m_decoder->deviceProfile())
+ fprintf(stderr, ": device %p\n", m_decoder->deviceProfile().get());
+ else
+ fprintf(stderr, ": %p\n", nullptr);
+ fprintf(stderr, "image color profiles enabled: %d\n", imageColorProfilesEnabled());
+ fflush(stderr);
+
if (colorProfile.isEmpty())
- return;
+ return nullptr;
+
qcms_profile* deviceProfile = ImageDecoder::qcmsOutputDeviceProfile();
+ if (m_decoder->deviceProfile())
+ deviceProfile = m_decoder->deviceProfile()->profile();
if (!deviceProfile)
- return;
+ return nullptr;
+
qcms_profile* inputProfile = qcms_profile_from_memory(colorProfile.data(), colorProfile.size());
if (!inputProfile)
- return;
+ return nullptr;
+
+ fprintf(stderr, " from source profile [%s]", qcms_profile_get_description(inputProfile));
+ fprintf(stderr, " to [%s]\n", qcms_profile_get_description(deviceProfile));
+ fflush(stderr);
+
+ // There is no need to create a color transform if the color profiles match.
+ if (imageColorProfilesEnabled() && qcms_profile_match(inputProfile, deviceProfile))
+ return ColorSpaceProfile::create(inputProfile);
+
// We currently only support color profiles for RGB profiled images.
ASSERT(rgbData == qcms_profile_get_color_space(inputProfile));
qcms_data_type dataFormat = hasAlpha ? QCMS_DATA_RGBA_8 : QCMS_DATA_RGB_8;
// FIXME: Don't force perceptual intent if the image profile contains an intent.
m_transform = qcms_transform_create(inputProfile, dataFormat, deviceProfile, dataFormat, QCMS_INTENT_PERCEPTUAL);
+ if (m_transform)
+ return ColorSpaceProfile::create(inputProfile);
+
qcms_profile_release(inputProfile);
+ return nullptr;
}
#endif
@@ -763,6 +798,7 @@ JPEGImageDecoder::JPEGImageDecoder(AlphaOption alphaOption, GammaAndColorProfile
: ImageDecoder(alphaOption, colorOptions, maxDecodedBytes)
, m_hasColorProfile(false)
{
+ fprintf(stderr, "JPEG decoder %p created %s\n", this, !isMainThread() ? "impl-side-thread" : "");
}
JPEGImageDecoder::~JPEGImageDecoder()
@@ -1008,10 +1044,21 @@ bool JPEGImageDecoder::outputScanlines()
if (jpeg_read_scanlines(info, &row, 1) != 1)
return false;
#if USE(QCMSLIB)
- if (qcms_transform* transform = m_reader->colorTransform())
+ if (qcms_transform* transform = m_reader->colorTransform()) {
+ if (info->output_scanline <= 3 || info->output_scanline >= info->output_height)
+ fprintf(stderr, "JPEG decoder %p %dx%d color transform row %d\n", this, size().width(), size().height(), info->output_scanline - 1);
qcms_transform_data_type(transform, row, row, info->output_width, rgbOutputColorSpace() == JCS_EXT_BGRA ? QCMS_OUTPUT_BGRX : QCMS_OUTPUT_RGBX);
+ }
#endif
+ if (info->output_scanline <= 3)
+ fprintf(stderr, "JPEG decoder %p %dx%d row %d\n", this, size().width(), size().height(), info->output_scanline - 1);
+
+ if (info->output_scanline >= info->output_height) {
+ fprintf(stderr, "JPEG decoder %p %dx%d row %d\n", this, size().width(), size().height(), info->output_scanline - 1);
+ fflush(stderr);
+ }
}
+
buffer.setPixelsChanged(true);
return true;
}
@@ -1031,6 +1078,8 @@ bool JPEGImageDecoder::outputScanlines()
void JPEGImageDecoder::complete()
{
+ fflush(stderr);
+
if (m_frameBufferCache.isEmpty())
return;

Powered by Google App Engine
This is Rietveld 408576698