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

Unified Diff: src/codec/SkCodecImageGenerator.cpp

Issue 1549473003: Add getYUV8Planes() API to SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add a test to DM Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: src/codec/SkCodecImageGenerator.cpp
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index 2fef381ec1ffa332f5d62c8eb30d6b7eebcbe909..feec96f9ca39f452f5b14abed31916abb5b076a7 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -16,8 +16,16 @@ SkImageGenerator* SkCodecImageGenerator::NewFromEncodedCodec(SkData* data) {
return new SkCodecImageGenerator(codec, data);
}
+static SkImageInfo make_premul(const SkImageInfo& info) {
+ if (kUnpremul_SkAlphaType == info.alphaType()) {
+ return info.makeAlphaType(kPremul_SkAlphaType);
+ }
+
+ return info;
+}
+
SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data)
- : INHERITED(codec->getInfo())
+ : INHERITED(make_premul(codec->getInfo()))
, fCodec(codec)
, fData(SkRef(data))
{}
@@ -42,5 +50,37 @@ bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s
bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
SkYUVColorSpace* colorSpace) {
- return false;
+ // TODO (msarett): Change the YUV API in ImageGenerator to match SkCodec.
+ // This function is currently a hack to match the implementation
msarett 2016/01/15 19:22:03 This hack is unbelievably ugly. Maybe this CL sho
scroggo 2016/01/19 18:37:48 I would leave changing the YUV API to its own CL,
+ // in SkCodec with the old API.
+
+ // If planes is NULL, we just need to return the size.
+ if (nullptr == planes) {
+ SkCodec::YUVPlanesWidthBytes widthBytes;
+ bool result = fCodec->queryYUV8((SkCodec::YUVPlanesSizes*) sizes, &widthBytes, colorSpace);
+ if (result) {
+ // Save the true widths
+ fYWidth = sizes[0].fWidth;
+ fUWidth = sizes[1].fWidth;
+ fVWidth = sizes[2].fWidth;
+
+ // Adjust the widths so the client allocates enough memory
+ sizes[0].fWidth = widthBytes.YWidthBytes;
+ sizes[1].fWidth = widthBytes.UWidthBytes;
+ sizes[2].fWidth = widthBytes.VWidthBytes;
+ }
+ return result;
+ }
+
+ // Restore the true widths
scroggo 2016/01/19 18:37:48 Just to make sure I follow - the old API *requires
msarett 2016/01/19 22:35:27 I can't say that it's *required*. That is how it'
+ sizes[0].fWidth = fYWidth;
+ sizes[1].fWidth = fUWidth;
+ sizes[2].fWidth = fVWidth;
+ bool result = fCodec->getYUV8Planes((const SkCodec::YUVPlanesSizes*)sizes, planes,
+ (const SkCodec::YUVPlanesWidthBytes*) rowBytes);
+ if (result && colorSpace) {
+ *colorSpace = kJPEG_SkYUVColorSpace;
+ }
+
+ return result;
}

Powered by Google App Engine
This is Rietveld 408576698