Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info, |
| 74 void* pixels, | 74 void* pixels, |
| 75 size_t row_bytes, | 75 size_t row_bytes, |
| 76 SkPMColor table[], | 76 SkPMColor*, |
| 77 int* table_count) { | 77 int*) { |
| 78 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", | 78 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", |
| 79 static_cast<int>(frame_index_)); | 79 static_cast<int>(frame_index_)); |
| 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 (dst_info.dimensions() != getInfo().dimensions()) { |
| 84 return false; | 84 return false; |
| 85 } | |
| 85 | 86 |
| 86 if (info.colorType() != getInfo().colorType()) { | 87 if (kN32_SkColorType != dst_info.colorType()) { |
|
Nico
2017/04/11 15:41:05
no yoda conditionals please
msarett1
2017/04/11 20:52:05
Done.
| |
| 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; | 88 return false; |
| 92 } | 89 } |
| 93 | 90 |
| 91 // Skip the check for alphaType. blink::ImageFrame may have changed the | |
| 92 // owning SkBitmap to kOpaque_SkAlphaType after fully decoding the image | |
| 93 // frame, so if we see a request for opaque, that is ok even if our initial | |
| 94 // alpha type was not opaque. | |
| 95 | |
| 96 // Pass decodeColorSpace to the decoder. That is what we can expect the | |
| 97 // output to be. | |
| 98 SkColorSpace* decode_color_space = getInfo().colorSpace(); | |
| 99 SkImageInfo decode_info = | |
| 100 dst_info.makeColorSpace(sk_ref_sp(decode_color_space)); | |
| 101 | |
| 102 const bool needs_color_xform = | |
| 103 decode_color_space && dst_info.colorSpace() && | |
|
ccameron
2017/04/11 19:03:10
This will have no functional changes because dst_i
Nico
2017/04/11 19:07:48
Pasting this bit from above: """I think the proces
| |
| 104 !SkColorSpace::Equals(decode_color_space, dst_info.colorSpace()); | |
| 105 ImageDecoder::AlphaOption alpha_option = ImageDecoder::kAlphaPremultiplied; | |
| 106 if (needs_color_xform && !decode_info.isOpaque()) { | |
| 107 alpha_option = ImageDecoder::kAlphaNotPremultiplied; | |
| 108 decode_info = decode_info.makeAlphaType(kUnpremul_SkAlphaType); | |
| 109 } | |
| 110 | |
| 94 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); | 111 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); |
| 95 bool decoded = frame_generator_->DecodeAndScale( | 112 bool decoded = frame_generator_->DecodeAndScale( |
| 96 data_.Get(), all_data_received_, frame_index_, getInfo(), pixels, | 113 data_.Get(), all_data_received_, frame_index_, decode_info, pixels, |
| 97 row_bytes); | 114 row_bytes, alpha_option); |
| 98 PlatformInstrumentation::DidDecodeLazyPixelRef(); | 115 PlatformInstrumentation::DidDecodeLazyPixelRef(); |
| 99 | 116 |
| 100 return decoded; | 117 if (!decoded || !needs_color_xform) { |
| 118 return decoded; | |
| 119 } | |
| 120 | |
| 121 std::unique_ptr<SkColorSpaceXform> xform = | |
| 122 SkColorSpaceXform::New(decode_color_space, dst_info.colorSpace()); | |
| 123 | |
| 124 uint32_t* row = reinterpret_cast<uint32_t*>(pixels); | |
| 125 for (int y = 0; y < dst_info.height(); y++) { | |
|
Nico
2017/04/11 15:41:05
This function is getting very long. Consider extra
msarett1
2017/04/11 20:52:05
Done. I think you're right, this works better as
| |
| 126 SkColorSpaceXform::ColorFormat format = | |
| 127 SkColorSpaceXform::kRGBA_8888_ColorFormat; | |
| 128 if (kN32_SkColorType == kBGRA_8888_SkColorType) { | |
| 129 format = SkColorSpaceXform::kBGRA_8888_ColorFormat; | |
| 130 } | |
| 131 SkAlphaType alpha_type = | |
| 132 dst_info.isOpaque() ? kOpaque_SkAlphaType : kUnpremul_SkAlphaType; | |
| 133 bool xformed = | |
| 134 xform->apply(format, row, format, row, dst_info.width(), alpha_type); | |
| 135 DCHECK(xformed); | |
| 136 | |
| 137 // To be compatible with dst space blending, premultiply in the dst space. | |
| 138 if (kPremul_SkAlphaType == dst_info.alphaType()) { | |
| 139 for (int x = 0; x < dst_info.width(); x++) { | |
| 140 row[x] = | |
| 141 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]), | |
| 142 SkGetPackedG32(row[x]), SkGetPackedB32(row[x])); | |
| 143 } | |
| 144 } | |
| 145 | |
| 146 row = reinterpret_cast<uint32_t*>( | |
| 147 (reinterpret_cast<uint8_t*>(row) + row_bytes)); | |
| 148 } | |
| 149 | |
| 150 return true; | |
| 101 } | 151 } |
| 102 | 152 |
| 103 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info, | 153 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info, |
| 104 SkYUVColorSpace* color_space) const { | 154 SkYUVColorSpace* color_space) const { |
| 105 // YUV decoding does not currently support progressive decoding. See comment | 155 // YUV decoding does not currently support progressive decoding. See comment |
| 106 // in ImageFrameGenerator.h. | 156 // in ImageFrameGenerator.h. |
| 107 if (!can_yuv_decode_ || !all_data_received_) | 157 if (!can_yuv_decode_ || !all_data_received_) |
| 108 return false; | 158 return false; |
| 109 | 159 |
| 110 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", | 160 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()), | 205 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()), |
| 156 false, decoder->GetColorBehavior()); | 206 false, decoder->GetColorBehavior()); |
| 157 if (!frame) | 207 if (!frame) |
| 158 return nullptr; | 208 return nullptr; |
| 159 | 209 |
| 160 return new DecodingImageGenerator(frame, info, segment_reader.Release(), true, | 210 return new DecodingImageGenerator(frame, info, segment_reader.Release(), true, |
| 161 0); | 211 0); |
| 162 } | 212 } |
| 163 | 213 |
| 164 } // namespace blink | 214 } // namespace blink |
| OLD | NEW |