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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/DecodingImageGenerator.cpp

Issue 2787053004: Respect colorSpace in DecodingImageGenerator::onGetPixels() (Closed)
Patch Set: Response to comments Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // this. skbug.com/5485 63 // this. skbug.com/5485
64 if (ctx && !m_allDataReceived) 64 if (ctx && !m_allDataReceived)
65 return nullptr; 65 return nullptr;
66 66
67 // Other clients are serializers, which want the data even if it requires 67 // Other clients are serializers, which want the data even if it requires
68 // copying, and even if the data is incomplete. (Otherwise they would 68 // copying, and even if the data is incomplete. (Otherwise they would
69 // potentially need to decode the partial image in order to re-encode it.) 69 // potentially need to decode the partial image in order to re-encode it.)
70 return m_data->getAsSkData().release(); 70 return m_data->getAsSkData().release();
71 } 71 }
72 72
73 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, 73 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dstInfo,
74 void* pixels, 74 void* pixels,
75 size_t rowBytes, 75 size_t rowBytes,
76 SkPMColor table[], 76 SkPMColor*,
77 int* tableCount) { 77 int*) {
78 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", 78 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index",
79 static_cast<int>(m_frameIndex)); 79 static_cast<int>(m_frameIndex));
80 80
81 // Implementation doesn't support scaling yet, so make sure we're not given a 81 // Implementation doesn't support scaling yet, so make sure we're not given a
82 // different size. 82 // different size.
83 if (info.width() != getInfo().width() || info.height() != getInfo().height()) 83 if (dstInfo.width() != getInfo().width() ||
84 dstInfo.height() != getInfo().height()) {
84 return false; 85 return false;
86 }
85 87
86 if (info.colorType() != getInfo().colorType()) { 88 if (kN32_SkColorType != dstInfo.colorType()) {
87 // blink::ImageFrame may have changed the owning SkBitmap to
88 // kOpaque_SkAlphaType after fully decoding the image frame, so if we see a
89 // request for opaque, that is ok even if our initial alpha type was not
90 // opaque.
91 return false; 89 return false;
92 } 90 }
93 91
92 // Skip the check for alphaType. blink::ImageFrame may have changed the
93 // owning SkBitmap to kOpaque_SkAlphaType after fully decoding the image
94 // frame, so if we see a request for opaque, that is ok even if our initial
95 // alpha type was not opaque.
96
97 // Pass decodeColorSpace to the decoder. That is what we can expect the
98 // output to be.
99 sk_sp<SkColorSpace> decodeColorSpace = getInfo().refColorSpace();
100 SkImageInfo decodeInfo = dstInfo.makeColorSpace(decodeColorSpace);
101
102 bool needsColorXform =
scroggo_chromium 2017/04/05 19:59:01 nit: can be const?
msarett1 2017/04/06 22:05:29 Done.
103 decodeColorSpace && dstInfo.colorSpace() &&
104 !SkColorSpace::Equals(decodeColorSpace.get(), dstInfo.colorSpace());
105 if (needsColorXform) {
106 m_frameGenerator->setAlphaOption(ImageDecoder::AlphaNotPremultiplied);
scroggo_chromium 2017/04/05 19:59:01 I think you can move this inside if (!decodeInfo.i
msarett1 2017/04/06 22:05:29 Thanks, of course.
107 if (!decodeInfo.isOpaque()) {
108 decodeInfo = decodeInfo.makeAlphaType(kUnpremul_SkAlphaType);
109 }
110 }
111
94 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); 112 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID());
95 bool decoded = m_frameGenerator->decodeAndScale( 113 bool decoded = m_frameGenerator->decodeAndScale(
96 m_data.get(), m_allDataReceived, m_frameIndex, getInfo(), pixels, 114 m_data.get(), m_allDataReceived, m_frameIndex, decodeInfo, pixels,
97 rowBytes); 115 rowBytes);
98 PlatformInstrumentation::didDecodeLazyPixelRef(); 116 PlatformInstrumentation::didDecodeLazyPixelRef();
99 117
100 return decoded; 118 if (!decoded) {
119 return false;
120 }
121
122 if (needsColorXform) {
123 std::unique_ptr<SkColorSpaceXform> xform =
124 SkColorSpaceXform::New(decodeColorSpace.get(), dstInfo.colorSpace());
125
126 uint32_t* row = (uint32_t*)pixels;
127 for (int y = 0; y < dstInfo.height(); y++) {
128 SkColorSpaceXform::ColorFormat format =
129 SkColorSpaceXform::kRGBA_8888_ColorFormat;
130 if (kN32_SkColorType == kBGRA_8888_SkColorType) {
131 format = SkColorSpaceXform::kBGRA_8888_ColorFormat;
132 }
133 SkAlphaType alphaType =
134 dstInfo.isOpaque() ? kOpaque_SkAlphaType : kUnpremul_SkAlphaType;
135 bool xformed =
136 xform->apply(format, row, format, row, dstInfo.width(), alphaType);
137 DCHECK(xformed);
138
139 // To be compatible with dst space blending, premultiply in the dst space.
140 if (kPremul_SkAlphaType == dstInfo.alphaType()) {
141 for (int x = 0; x < dstInfo.width(); x++) {
142 row[x] =
143 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]),
144 SkGetPackedG32(row[x]), SkGetPackedB32(row[x]));
145 }
146 }
147
148 row = (uint32_t*)(((uint8_t*)row) + rowBytes);
149 }
150 }
151
152 return true;
101 } 153 }
102 154
103 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, 155 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo,
104 SkYUVColorSpace* colorSpace) const { 156 SkYUVColorSpace* colorSpace) const {
105 // YUV decoding does not currently support progressive decoding. See comment 157 // YUV decoding does not currently support progressive decoding. See comment
106 // in ImageFrameGenerator.h. 158 // in ImageFrameGenerator.h.
107 if (!m_canYUVDecode || !m_allDataReceived) 159 if (!m_canYUVDecode || !m_allDataReceived)
108 return false; 160 return false;
109 161
110 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", 162 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes",
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 ImageFrameGenerator::create(SkISize::Make(size.width(), size.height()), 207 ImageFrameGenerator::create(SkISize::Make(size.width(), size.height()),
156 false, decoder->colorBehavior()); 208 false, decoder->colorBehavior());
157 if (!frame) 209 if (!frame)
158 return nullptr; 210 return nullptr;
159 211
160 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, 212 return new DecodingImageGenerator(frame, info, segmentReader.release(), true,
161 0); 213 0);
162 } 214 }
163 215
164 } // namespace blink 216 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698