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

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: Remove ifdefs - fixes blink_platform_unittests 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..b6db699e85329f2dc06f0205d3f5312841229e58 100644
--- a/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
+++ b/third_party/WebKit/Source/platform/image-decoders/jpeg/JPEGImageDecoder.cpp
@@ -46,12 +46,7 @@
extern "C" {
#include <stdio.h> // jpeglib.h needs stdio FILE.
#include "jpeglib.h"
-#if USE(ICCJPEG)
#include "iccjpeg.h"
-#endif
-#if USE(QCMSLIB)
-#include "qcms.h"
-#endif
#include <setjmp.h>
}
@@ -73,16 +68,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 {
@@ -311,10 +300,9 @@ class JPEGImageReader final {
m_src.pub.term_source = term_source;
m_src.reader = this;
-#if USE(ICCJPEG)
// 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);
}
@@ -457,27 +445,18 @@ class JPEGImageReader final {
// Allow color management of the decoded RGBA pixels if possible.
if (!m_decoder->ignoresGammaAndColorProfile()) {
-#if USE(ICCJPEG)
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 (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)
}
if (overrideColorSpace == JCS_YCbCr) {
m_info.out_color_space = JCS_YCbCr;
@@ -814,6 +793,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 +824,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 +839,17 @@ 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);
+
+ 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);
+ }
}
buffer.setPixelsChanged(true);
@@ -965,13 +950,12 @@ 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);
-#endif
+
+ SkColorSpaceXform* xform = colorTransform();
+ if (xform) {
+ xform->apply(xformColorFormat(), row, xformColorFormat(), row,
+ info->output_width, kOpaque_SkAlphaType);
+ }
}
buffer.setPixelsChanged(true);
return true;

Powered by Google App Engine
This is Rietveld 408576698