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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 SkData* DecodingImageGenerator::onRefEncodedData() { | 55 SkData* DecodingImageGenerator::onRefEncodedData() { |
| 56 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); | 56 TRACE_EVENT0("blink", "DecodingImageGenerator::refEncodedData"); |
| 57 | 57 |
| 58 // getAsSkData() may require copying, but the clients of this function are | 58 // getAsSkData() may require copying, but the clients of this function are |
| 59 // serializers, which want the data even if it requires copying, and even | 59 // serializers, which want the data even if it requires copying, and even |
| 60 // if the data is incomplete. (Otherwise they would potentially need to | 60 // if the data is incomplete. (Otherwise they would potentially need to |
| 61 // decode the partial image in order to re-encode it.) | 61 // decode the partial image in order to re-encode it.) |
| 62 return data_->GetAsSkData().release(); | 62 return data_->GetAsSkData().release(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 static void doColorSpaceXform(const SkImageInfo& dst_info, | 65 static void doColorSpaceXform(const SkImageInfo& dst_info, |
|
msarett1
2017/05/16 18:02:46
Now that readPixels() has been ramped up, we shoul
| |
| 66 void* pixels, | 66 void* pixels, |
| 67 size_t row_bytes, | 67 size_t row_bytes, |
| 68 SkColorSpace* src_color_space) { | 68 SkColorSpace* src_color_space, |
| 69 SkTransferFunctionBehavior behavior) { | |
| 69 TRACE_EVENT0("blink", "DecodingImageGenerator::getPixels - apply xform"); | 70 TRACE_EVENT0("blink", "DecodingImageGenerator::getPixels - apply xform"); |
| 70 std::unique_ptr<SkColorSpaceXform> xform = | 71 std::unique_ptr<SkColorSpaceXform> xform = |
| 71 SkColorSpaceXform::New(src_color_space, dst_info.colorSpace()); | 72 SkColorSpaceXform::New(src_color_space, dst_info.colorSpace()); |
| 72 | 73 |
| 74 const bool post_xform_premul = | |
| 75 (dst_info.alphaType() == kPremul_SkAlphaType) && | |
| 76 (behavior == SkTransferFunctionBehavior::kIgnore); | |
| 77 | |
| 73 uint32_t* row = reinterpret_cast<uint32_t*>(pixels); | 78 uint32_t* row = reinterpret_cast<uint32_t*>(pixels); |
| 74 for (int y = 0; y < dst_info.height(); y++) { | 79 for (int y = 0; y < dst_info.height(); y++) { |
| 75 SkColorSpaceXform::ColorFormat format = | 80 SkColorSpaceXform::ColorFormat format = |
| 76 SkColorSpaceXform::kRGBA_8888_ColorFormat; | 81 SkColorSpaceXform::kRGBA_8888_ColorFormat; |
| 77 if (kN32_SkColorType == kBGRA_8888_SkColorType) { | 82 if (kN32_SkColorType == kBGRA_8888_SkColorType) { |
| 78 format = SkColorSpaceXform::kBGRA_8888_ColorFormat; | 83 format = SkColorSpaceXform::kBGRA_8888_ColorFormat; |
| 79 } | 84 } |
| 80 SkAlphaType alpha_type = | 85 SkAlphaType alpha_type = dst_info.alphaType(); |
| 81 dst_info.isOpaque() ? kOpaque_SkAlphaType : kUnpremul_SkAlphaType; | 86 if (post_xform_premul) { |
| 87 alpha_type = kUnpremul_SkAlphaType; | |
|
f(malita)
2017/05/16 18:16:45
uber-nit: i think ternary op would fit better than
msarett1
2017/05/16 18:59:16
Done.
| |
| 88 } | |
| 82 bool xformed = | 89 bool xformed = |
| 83 xform->apply(format, row, format, row, dst_info.width(), alpha_type); | 90 xform->apply(format, row, format, row, dst_info.width(), alpha_type); |
| 84 DCHECK(xformed); | 91 DCHECK(xformed); |
| 85 | 92 |
| 86 // To be compatible with dst space blending, premultiply in the dst space. | 93 // To be compatible with dst space blending, premultiply in the dst space. |
| 87 if (kPremul_SkAlphaType == dst_info.alphaType()) { | 94 if (post_xform_premul) { |
| 88 for (int x = 0; x < dst_info.width(); x++) { | 95 for (int x = 0; x < dst_info.width(); x++) { |
| 89 row[x] = | 96 row[x] = |
| 90 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]), | 97 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]), |
| 91 SkGetPackedG32(row[x]), SkGetPackedB32(row[x])); | 98 SkGetPackedG32(row[x]), SkGetPackedB32(row[x])); |
| 92 } | 99 } |
| 93 } | 100 } |
| 94 | 101 |
| 95 row = reinterpret_cast<uint32_t*>( | 102 row = reinterpret_cast<uint32_t*>( |
| 96 (reinterpret_cast<uint8_t*>(row) + row_bytes)); | 103 (reinterpret_cast<uint8_t*>(row) + row_bytes)); |
| 97 } | 104 } |
| 98 } | 105 } |
| 99 | 106 |
| 100 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info, | 107 bool DecodingImageGenerator::onGetPixels(const SkImageInfo& dst_info, |
| 101 void* pixels, | 108 void* pixels, |
| 102 size_t row_bytes, | 109 size_t row_bytes, |
| 103 SkPMColor*, | 110 const Options& options) { |
| 104 int*) { | |
| 105 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", | 111 TRACE_EVENT1("blink", "DecodingImageGenerator::getPixels", "frame index", |
| 106 static_cast<int>(frame_index_)); | 112 static_cast<int>(frame_index_)); |
| 107 | 113 |
| 108 // Implementation doesn't support scaling yet, so make sure we're not given a | 114 // Implementation doesn't support scaling yet, so make sure we're not given a |
| 109 // different size. | 115 // different size. |
| 110 if (dst_info.dimensions() != getInfo().dimensions()) { | 116 if (dst_info.dimensions() != getInfo().dimensions()) { |
| 111 return false; | 117 return false; |
| 112 } | 118 } |
| 113 | 119 |
| 114 if (dst_info.colorType() != kN32_SkColorType) { | 120 if (dst_info.colorType() != kN32_SkColorType) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 135 decode_info = decode_info.makeAlphaType(kUnpremul_SkAlphaType); | 141 decode_info = decode_info.makeAlphaType(kUnpremul_SkAlphaType); |
| 136 } | 142 } |
| 137 | 143 |
| 138 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); | 144 PlatformInstrumentation::WillDecodeLazyPixelRef(uniqueID()); |
| 139 bool decoded = frame_generator_->DecodeAndScale( | 145 bool decoded = frame_generator_->DecodeAndScale( |
| 140 data_.Get(), all_data_received_, frame_index_, decode_info, pixels, | 146 data_.Get(), all_data_received_, frame_index_, decode_info, pixels, |
| 141 row_bytes, alpha_option); | 147 row_bytes, alpha_option); |
| 142 PlatformInstrumentation::DidDecodeLazyPixelRef(); | 148 PlatformInstrumentation::DidDecodeLazyPixelRef(); |
| 143 | 149 |
| 144 if (decoded && needs_color_xform) { | 150 if (decoded && needs_color_xform) { |
| 145 doColorSpaceXform(dst_info, pixels, row_bytes, decode_color_space); | 151 doColorSpaceXform(dst_info, pixels, row_bytes, decode_color_space, |
| 152 options.fBehavior); | |
| 146 } | 153 } |
| 147 | 154 |
| 148 return decoded; | 155 return decoded; |
| 149 } | 156 } |
| 150 | 157 |
| 151 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info, | 158 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* size_info, |
| 152 SkYUVColorSpace* color_space) const { | 159 SkYUVColorSpace* color_space) const { |
| 153 // YUV decoding does not currently support progressive decoding. See comment | 160 // YUV decoding does not currently support progressive decoding. See comment |
| 154 // in ImageFrameGenerator.h. | 161 // in ImageFrameGenerator.h. |
| 155 if (!can_yuv_decode_ || !all_data_received_) | 162 if (!can_yuv_decode_ || !all_data_received_) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()), | 211 ImageFrameGenerator::Create(SkISize::Make(size.Width(), size.Height()), |
| 205 false, decoder->GetColorBehavior()); | 212 false, decoder->GetColorBehavior()); |
| 206 if (!frame) | 213 if (!frame) |
| 207 return nullptr; | 214 return nullptr; |
| 208 | 215 |
| 209 return new DecodingImageGenerator(frame, info, segment_reader.Release(), true, | 216 return new DecodingImageGenerator(frame, info, segment_reader.Release(), true, |
| 210 0); | 217 0); |
| 211 } | 218 } |
| 212 | 219 |
| 213 } // namespace blink | 220 } // namespace blink |
| OLD | NEW |