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

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

Issue 2787053004: Respect colorSpace in DecodingImageGenerator::onGetPixels() (Closed)
Patch Set: Rebase 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/graphics/ImageDecodingStore.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 && !all_data_received_) 64 if (ctx && !all_data_received_)
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 data_->GetAsSkData().release(); 70 return data_->GetAsSkData().release();
71 } 71 }
72 72
73 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& info, 73 static void doColorSpaceXform(const SkImageInfo& dst_info,
74 void* pixels,
75 size_t row_bytes,
76 SkColorSpace* src_color_space) {
77 TRACE_EVENT0("blink", "DecodingImageGenerator::getPixels - apply xform");
78 std::unique_ptr<SkColorSpaceXform> xform =
79 SkColorSpaceXform::New(src_color_space, dst_info.colorSpace());
80
81 uint32_t* row = reinterpret_cast<uint32_t*>(pixels);
82 for (int y = 0; y < dst_info.height(); y++) {
83 SkColorSpaceXform::ColorFormat format =
84 SkColorSpaceXform::kRGBA_8888_ColorFormat;
85 if (kN32_SkColorType == kBGRA_8888_SkColorType) {
86 format = SkColorSpaceXform::kBGRA_8888_ColorFormat;
87 }
88 SkAlphaType alpha_type =
89 dst_info.isOpaque() ? kOpaque_SkAlphaType : kUnpremul_SkAlphaType;
90 bool xformed =
91 xform->apply(format, row, format, row, dst_info.width(), alpha_type);
92 DCHECK(xformed);
93
94 // To be compatible with dst space blending, premultiply in the dst space.
95 if (kPremul_SkAlphaType == dst_info.alphaType()) {
96 for (int x = 0; x < dst_info.width(); x++) {
97 row[x] =
98 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]),
99 SkGetPackedG32(row[x]), SkGetPackedB32(row[x]));
100 }
101 }
102
103 row = reinterpret_cast<uint32_t*>(
104 (reinterpret_cast<uint8_t*>(row) + row_bytes));
105 }
106 }
107
108 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info,
74 void* pixels, 109 void* pixels,
75 size_t row_bytes, 110 size_t row_bytes,
76 SkPMColor table[], 111 SkPMColor*,
77 int* table_count) { 112 int*) {
78 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", 113 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index",
79 static_cast<int>(frame_index_)); 114 static_cast<int>(frame_index_));
80 115
81 // Implementation doesn't support scaling yet, so make sure we're not given a 116 // Implementation doesn't support scaling yet, so make sure we're not given a
82 // different size. 117 // different size.
83 if (info.width() != getInfo().width() || info.height() != getInfo().height()) 118 if (dst_info.dimensions() != getInfo().dimensions()) {
84 return false; 119 return false;
120 }
85 121
86 if (info.colorType() != getInfo().colorType()) { 122 if (dst_info.colorType() != kN32_SkColorType) {
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; 123 return false;
92 } 124 }
93 125
126 // Skip the check for alphaType. blink::ImageFrame may have changed the
127 // owning SkBitmap to kOpaque_SkAlphaType after fully decoding the image
128 // frame, so if we see a request for opaque, that is ok even if our initial
129 // alpha type was not opaque.
130
131 // Pass decodeColorSpace to the decoder. That is what we can expect the
132 // output to be.
133 SkColorSpace* decode_color_space = getInfo().colorSpace();
134 SkImageInfo decode_info =
135 dst_info.makeColorSpace(sk_ref_sp(decode_color_space));
136
137 const bool needs_color_xform =
138 decode_color_space && dst_info.colorSpace() &&
139 !SkColorSpace::Equals(decode_color_space, dst_info.colorSpace());
140 ImageDecoder::AlphaOption alpha_option = ImageDecoder::kAlphaPremultiplied;
141 if (needs_color_xform && !decode_info.isOpaque()) {
142 alpha_option = ImageDecoder::kAlphaNotPremultiplied;
143 decode_info = decode_info.makeAlphaType(kUnpremul_SkAlphaType);
144 }
145
94 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); 146 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID());
95 bool decoded = frame_generator_->DecodeAndScale( 147 bool decoded = frame_generator_->DecodeAndScale(
96 data_.Get(), all_data_received_, frame_index_, getInfo(), pixels, 148 data_.Get(), all_data_received_, frame_index_, decode_info, pixels,
97 row_bytes); 149 row_bytes, alpha_option);
98 PlatformInstrumentation::DidDecodeLazyPixelRef(); 150 PlatformInstrumentation::DidDecodeLazyPixelRef();
99 151
152 if (decoded && needs_color_xform) {
153 doColorSpaceXform(dst_info, pixels, row_bytes, decode_color_space);
154 }
155
100 return decoded; 156 return decoded;
101 } 157 }
102 158
103 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info, 159 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info,
104 SkYUVColorSpace* color_space) const { 160 SkYUVColorSpace* color_space) const {
105 // YUV decoding does not currently support progressive decoding. See comment 161 // YUV decoding does not currently support progressive decoding. See comment
106 // in ImageFrameGenerator.h. 162 // in ImageFrameGenerator.h.
107 if (!can_yuv_decode_ || !all_data_received_) 163 if (!can_yuv_decode_ || !all_data_received_)
108 return false; 164 return false;
109 165
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()), 212 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()),
157 false, decoder->GetColorBehavior()); 213 false, decoder->GetColorBehavior());
158 if (!frame) 214 if (!frame)
159 return nullptr; 215 return nullptr;
160 216
161 return new DecodingImageGenerator(frame, info, segment_reader.Release(), true, 217 return new DecodingImageGenerator(frame, info, segment_reader.Release(), true,
162 0); 218 0);
163 } 219 }
164 220
165 } // namespace blink 221 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/graphics/ImageDecodingStore.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698