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 && !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* dstPixels, |
| 75 size_t rowBytes, | 75 size_t dstRowBytes, |
| 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 sk_sp<SkColorSpace> decodeColorSpace = getInfo().refColorSpace(); | |
| 89 switch (dstInfo.colorType()) { | |
| 90 case kN32_SkColorType: | |
| 91 break; | |
| 92 case kRGBA_F16_SkColorType: | |
| 93 if (!decodeColorSpace || !dstInfo.colorSpace() || | |
| 94 !dstInfo.colorSpace()->gammaIsLinear()) { | |
| 95 return false; | |
| 96 } | |
| 97 break; | |
| 98 default: | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 // Skip the check for alphaType. blink::ImageFrame may have changed the | |
| 103 // owning SkBitmap to kOpaque_SkAlphaType after fully decoding the image | |
| 104 // frame, so if we see a request for opaque, that is ok even if our initial | |
| 105 // alpha type was not opaque. | |
| 106 | |
| 107 void* decodePixels = dstPixels; | |
| 108 size_t decodeRowBytes = dstRowBytes; | |
| 109 std::unique_ptr<uint32_t[]> tmp = nullptr; | |
| 110 if (kRGBA_F16_SkColorType == dstInfo.colorType()) { | |
| 111 // Since the decoder does not support F16, we'll need to decode into a | |
| 112 // temporary buffer, then convert that to F16. | |
| 113 tmp.reset(new uint32_t[dstInfo.width() * dstInfo.height()]); | |
| 114 decodePixels = tmp.get(); | |
| 115 decodeRowBytes = sizeof(uint32_t) * dstInfo.width(); | |
| 116 } | |
| 117 | |
| 118 // Might as well pass kN32 and decodeColorSpace to the decoder. That's what | |
| 119 // the output is always going to be anyway. | |
| 120 SkImageInfo decodeInfo = | |
| 121 dstInfo.makeColorType(kN32_SkColorType).makeColorSpace(decodeColorSpace); | |
| 94 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); | 122 PlatformInstrumentation::willDecodeLazyPixelRef(uniqueID()); |
| 95 bool decoded = m_frameGenerator->decodeAndScale( | 123 bool decoded = m_frameGenerator->decodeAndScale( |
| 96 m_data.get(), m_allDataReceived, m_frameIndex, getInfo(), pixels, | 124 m_data.get(), m_allDataReceived, m_frameIndex, decodeInfo, decodePixels, |
| 97 rowBytes); | 125 decodeRowBytes); |
| 98 PlatformInstrumentation::didDecodeLazyPixelRef(); | 126 PlatformInstrumentation::didDecodeLazyPixelRef(); |
| 99 | 127 |
| 100 return decoded; | 128 if (!decoded) { |
| 129 return false; | |
| 130 } | |
| 131 | |
| 132 if (kRGBA_F16_SkColorType == dstInfo.colorType() || | |
| 133 (decodeColorSpace && dstInfo.colorSpace() && | |
| 134 !SkColorSpace::Equals(decodeColorSpace.get(), dstInfo.colorSpace()))) { | |
|
f(malita)
2017/03/31 19:52:07
It reads a bit strange for this conditional to be
msarett1
2017/03/31 21:47:30
Yeah I can see how this is confusing. I'm droppin
| |
| 135 // FIXME: | |
|
f(malita)
2017/03/31 19:52:07
Nit: Chromium style is // TODO(msarett): ...
msarett1
2017/03/31 21:47:30
Done.
| |
| 136 // Why can't we take this out of the "if" condition and just assert it? | |
| 137 // DCHECK(dstInfo.colorSpace()); | |
| 138 | |
| 139 SkPixmap dst(dstInfo, dstPixels, dstRowBytes); | |
| 140 SkPixmap src(decodeInfo, decodePixels, decodeRowBytes); | |
| 141 | |
| 142 // FIXME: | |
|
f(malita)
2017/03/31 19:52:07
Nit: ditto
msarett1
2017/03/31 21:47:30
Done.
| |
| 143 // In the case of images with alpha, the decoder will premultiply them in | |
| 144 // the |src| color space. In order to do this xform correctly, we will need | |
| 145 // to unpremultiply in |src| color space, and then premultiply again in the | |
| 146 // |dst| color space. The Skia API for this conversion (non-linear | |
|
msarett1
2017/03/31 19:05:28
I'll see if I can make this public.
Regardless, t
ccameron
2017/03/31 19:46:08
Doing (2) may be possible ... I'm looking to see a
msarett1
2017/03/31 19:59:10
I looked at (2) first, then got scared and backed
scroggo_chromium
2017/04/04 20:52:45
FWIW, kUnpremul in ImageDecoder is already support
msarett1
2017/04/04 23:02:36
Thanks for the unpremul tip, not sure how I missed
| |
| 147 // premultiplies and unpremultiplies) is not public. In the use case where | |
| 148 // we want linear blending (which means linear premultiplies), this works | |
| 149 // correctly as is. Of course, it will assume that the premultiply | |
| 150 // performed by the image decoder was linear (which it was not). | |
| 151 bool xformed = src.readPixels(dst); | |
| 152 DCHECK(xformed); | |
|
ccameron
2017/03/31 19:46:08
This DCHECK fires for the test image attached at
h
f(malita)
2017/03/31 19:52:07
Nit: return xformed?
msarett1
2017/03/31 19:59:10
SkPixmap::readPixels() has some restrictions on tr
msarett1
2017/03/31 21:47:30
I still like the DCHECK, but yeah I think so.
| |
| 153 } | |
| 154 | |
| 155 return true; | |
| 101 } | 156 } |
| 102 | 157 |
| 103 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, | 158 bool DecodingImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, |
| 104 SkYUVColorSpace* colorSpace) const { | 159 SkYUVColorSpace* colorSpace) 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 (!m_canYUVDecode || !m_allDataReceived) | 162 if (!m_canYUVDecode || !m_allDataReceived) |
| 108 return false; | 163 return false; |
| 109 | 164 |
| 110 TRACE_EVENT1("blink", "DecodingImageGenerator::queryYUV8", "sizes", | 165 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()), | 210 ImageFrameGenerator::create(SkISize::Make(size.width(), size.height()), |
| 156 false, decoder->colorBehavior()); | 211 false, decoder->colorBehavior()); |
| 157 if (!frame) | 212 if (!frame) |
| 158 return nullptr; | 213 return nullptr; |
| 159 | 214 |
| 160 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, | 215 return new DecodingImageGenerator(frame, info, segmentReader.release(), true, |
| 161 0); | 216 0); |
| 162 } | 217 } |
| 163 | 218 |
| 164 } // namespace blink | 219 } // namespace blink |
| OLD | NEW |