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

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

Issue 2426723005: Use SkColorSpaceXform to handle color conversions in decoders (Closed)
Patch Set: Refactor a bit for clarity Created 4 years, 2 months 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 30ace15aed6ab8ed0e44d194417686894ec29771..c8e2c3605b2d26690a95906283d67a1a66d94590 100644
--- a/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
@@ -49,9 +49,6 @@ extern "C" {
#if USE(ICCJPEG)
#include "iccjpeg.h"
#endif
-#if USE(QCMSLIB)
-#include "qcms.h"
-#endif
#include <setjmp.h>
}
@@ -73,16 +70,10 @@ inline J_COLOR_SPACE rgbOutputColorSpace() {
inline bool turboSwizzled(J_COLOR_SPACE colorSpace) {
return colorSpace == JCS_EXT_RGBA || colorSpace == JCS_EXT_BGRA;
}
-inline bool colorSpaceHasAlpha(J_COLOR_SPACE colorSpace) {
- return turboSwizzled(colorSpace);
-}
#else
inline J_COLOR_SPACE rgbOutputColorSpace() {
return JCS_RGB;
}
-inline bool colorSpaceHasAlpha(J_COLOR_SPACE) {
- return false;
-}
#endif
namespace {
@@ -315,6 +306,7 @@ class JPEGImageReader final {
// Retain ICC color profile markers for color management.
setup_read_icc_profile(&m_info);
#endif
+
// Keep APP1 blocks, for obtaining exif data.
jpeg_save_markers(&m_info, exifMarker, 0xFFFF);
}
@@ -461,23 +453,17 @@ class JPEGImageReader final {
JOCTET* profile = nullptr;
unsigned profileLength = 0;
if (read_icc_profile(info(), &profile, &profileLength)) {
- decoder()->setColorProfileAndComputeTransform(
+ decoder()->setColorSpaceAndComputeTransform(
reinterpret_cast<char*>(profile), profileLength,
- colorSpaceHasAlpha(info()->out_color_space),
false /* useSRGB */);
free(profile);
}
#endif // USE(ICCJPEG)
-#if USE(QCMSLIB)
+#if USE(SKCOLORXFORM)
if (decoder()->colorTransform()) {
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)
- m_info.out_color_space = JCS_EXT_RGBA;
-#endif // defined(TURBO_JPEG_RGB_SWIZZLE)
}
-#endif // USE(QCMSLIB)
+#endif // USE(SKCOLORXFORM)
}
if (overrideColorSpace == JCS_YCbCr) {
m_info.out_color_space = JCS_YCbCr;
@@ -814,6 +800,7 @@ void setPixel(ImageFrame& buffer,
ASSERT_NOT_REACHED();
}
+// Used only for debugging with libjpeg (instead of libjpeg-turbo).
template <>
void setPixel<JCS_RGB>(ImageFrame& buffer,
ImageFrame::PixelData* pixel,
@@ -844,6 +831,8 @@ void setPixel<JCS_CMYK>(ImageFrame& buffer,
jsample[2] * k / 255, 255);
}
+// Used only for JCS_CMYK and JCS_RGB output. Note that JCS_RGB is used only
+// for debugging with libjpeg (instead of libjpeg-turbo).
template <J_COLOR_SPACE colorSpace>
bool outputRows(JPEGImageReader* reader, ImageFrame& buffer) {
JSAMPARRAY samples = reader->samples();
@@ -857,14 +846,19 @@ bool outputRows(JPEGImageReader* reader, ImageFrame& buffer) {
// Request one scanline: returns 0 or 1 scanlines.
if (jpeg_read_scanlines(info, samples, 1) != 1)
return false;
-#if USE(QCMSLIB)
- if (reader->decoder()->colorTransform() && colorSpace == JCS_RGB)
- qcms_transform_data(reader->decoder()->colorTransform(), *samples,
- *samples, width);
-#endif
+
ImageFrame::PixelData* pixel = buffer.getAddr(0, y);
for (int x = 0; x < width; ++pixel, ++x)
setPixel<colorSpace>(buffer, pixel, samples, x);
+
+#if USE(SKCOLORXFORM)
+ SkColorSpaceXform* xform = reader->decoder()->colorTransform();
+ if (JCS_RGB == colorSpace && xform) {
+ ImageFrame::PixelData* row = buffer.getAddr(0, y);
+ xform->apply(xformColorFormat(), row, xformColorFormat(), row, width,
+ kOpaque_SkAlphaType);
+ }
+#endif
}
buffer.setPixelsChanged(true);
@@ -965,12 +959,13 @@ bool JPEGImageDecoder::outputScanlines() {
buffer.getAddr(0, info->output_scanline));
if (jpeg_read_scanlines(info, &row, 1) != 1)
return false;
-#if USE(QCMSLIB)
- if (qcms_transform* transform = colorTransform())
- qcms_transform_data_type(transform, row, row, info->output_width,
- rgbOutputColorSpace() == JCS_EXT_BGRA
- ? QCMS_OUTPUT_BGRX
- : QCMS_OUTPUT_RGBX);
+
+#if USE(SKCOLORXFORM)
+ SkColorSpaceXform* xform = colorTransform();
+ if (xform) {
+ xform->apply(xformColorFormat(), row, xformColorFormat(), row,
+ info->output_width, kOpaque_SkAlphaType);
+ }
#endif
}
buffer.setPixelsChanged(true);

Powered by Google App Engine
This is Rietveld 408576698