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 && !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 return false; | 84 dstInfo.height() != getInfo().height()) { |
85 | |
86 if (info.colorType() != getInfo().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; | 85 return false; |
92 } | 86 } |
93 | 87 |
88 if (kN32_SkColorType != dstInfo.colorType()) { | |
89 return false; | |
90 } | |
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 kN32 and decodeColorSpace to the decoder. That is what we can expect | |
98 // output to be. | |
99 sk_sp<SkColorSpace> decodeColorSpace = getInfo().refColorSpace(); | |
100 SkImageInfo decodeInfo = | |
101 dstInfo.makeColorType(kN32_SkColorType).makeColorSpace(decodeColorSpace); | |
scroggo_chromium
2017/04/04 20:52:45
You can drop the makeColorType piece, since it wil
msarett1
2017/04/04 23:02:36
Thanks, removing.
| |
94 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); | 102 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); |
95 bool decoded = m_frameGenerator->decodeAndScale( | 103 bool success = m_frameGenerator->decodeAndScale( |
96 m_data.get(), m_allDataReceived, m_frameIndex, getInfo(), pixels, | 104 m_data.get(), m_allDataReceived, m_frameIndex, decodeInfo, pixels, |
97 rowBytes); | 105 rowBytes); |
98 PlatformInstrumentation::didDecodeLazyPixelRef(); | 106 PlatformInstrumentation::didDecodeLazyPixelRef(); |
99 | 107 |
100 return decoded; | 108 if (!success) { |
109 return false; | |
110 } | |
111 | |
112 if (decodeColorSpace && dstInfo.colorSpace() && | |
113 !SkColorSpace::Equals(decodeColorSpace.get(), dstInfo.colorSpace())) { | |
114 std::unique_ptr<SkColorSpaceXform> xform = | |
115 SkColorSpaceXform::New(decodeColorSpace.get(), dstInfo.colorSpace()); | |
116 | |
117 uint32_t* row = (uint32_t*)pixels; | |
118 for (int y = 0; y < dstInfo.height(); y++) { | |
119 // Any premultiplication by the decoder was in the src color space. Which | |
120 // means that we must start by unpremultiplying in the src color space. | |
121 if (kPremul_SkAlphaType == dstInfo.alphaType()) { | |
122 for (int x = 0; x < dstInfo.width(); x++) { | |
123 row[x] = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(row[x]); | |
124 } | |
125 } | |
126 | |
127 SkColorSpaceXform::ColorFormat format = | |
128 SkColorSpaceXform::kRGBA_8888_ColorFormat; | |
129 if (kN32_SkColorType == kBGRA_8888_SkColorType) { | |
130 format = SkColorSpaceXform::kBGRA_8888_ColorFormat; | |
131 } | |
132 SkAlphaType alphaType = | |
133 dstInfo.isOpaque() ? kOpaque_SkAlphaType : kUnpremul_SkAlphaType; | |
134 bool success = | |
scroggo_chromium
2017/04/04 20:52:45
This shadows a variable in the larger scope, and i
msarett1
2017/04/04 23:02:36
Done.
| |
135 xform->apply(format, row, format, row, dstInfo.width(), alphaType); | |
136 DCHECK(success); | |
137 | |
138 // To be compatible with dst space blending, premultiply in the dst space. | |
139 if (kPremul_SkAlphaType == dstInfo.alphaType()) { | |
140 for (int x = 0; x < dstInfo.width(); x++) { | |
141 row[x] = | |
142 SkPreMultiplyARGB(SkGetPackedA32(row[x]), SkGetPackedR32(row[x]), | |
143 SkGetPackedG32(row[x]), SkGetPackedB32(row[x])); | |
144 } | |
145 } | |
146 | |
147 row = (uint32_t*)(((uint8_t*)row) + rowBytes); | |
148 } | |
149 } | |
150 | |
151 return success; | |
scroggo_chromium
2017/04/04 20:52:45
I think this can be
return true;
If success wa
msarett1
2017/04/04 23:02:36
Done. "return success" gives us "false" on a fail
scroggo_chromium
2017/04/05 19:59:01
I don't think so. The nested variable success gets
msarett1
2017/04/06 22:05:29
Ack. I meant to not redeclare it... I think as i
| |
101 } | 152 } |
102 | 153 |
103 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, | 154 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, |
104 SkYUVColorSpace* colorSpace) const { | 155 SkYUVColorSpace* colorSpace) const { |
105 // YUV decoding does not currently support progressive decoding. See comment | 156 // YUV decoding does not currently support progressive decoding. See comment |
106 // in ImageFrameGenerator.h. | 157 // in ImageFrameGenerator.h. |
107 if (!m_canYUVDecode || !m_allDataReceived) | 158 if (!m_canYUVDecode || !m_allDataReceived) |
108 return false; | 159 return false; |
109 | 160 |
110 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", | 161 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()), | 206 ImageFrameGenerator::create(SkISize::Make(size.width(), size.height()), |
156 false, decoder->colorBehavior()); | 207 false, decoder->colorBehavior()); |
157 if (!frame) | 208 if (!frame) |
158 return nullptr; | 209 return nullptr; |
159 | 210 |
160 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, | 211 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, |
161 0); | 212 0); |
162 } | 213 } |
163 | 214 |
164 } // namespace blink | 215 } // namespace blink |
OLD | NEW |