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

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

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

Powered by Google App Engine
This is Rietveld 408576698