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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCodecImageGenerator.h" 8 #include "SkCodecImageGenerator.h"
9 9
10 SkImageGenerator* SkCodecImageGenerator::NewFromEncodedCodec(SkData* data) { 10 SkImageGenerator* SkCodecImageGenerator::NewFromEncodedCodec(SkData* data) {
11 SkCodec* codec = SkCodec::NewFromData(data); 11 SkCodec* codec = SkCodec::NewFromData(data);
12 if (nullptr == codec) { 12 if (nullptr == codec) {
13 return nullptr; 13 return nullptr;
14 } 14 }
15 15
16 return new SkCodecImageGenerator(codec, data); 16 return new SkCodecImageGenerator(codec, data);
17 } 17 }
18 18
19 static SkImageInfo make_premul(const SkImageInfo& info) {
20 if (kUnpremul_SkAlphaType == info.alphaType()) {
21 return info.makeAlphaType(kPremul_SkAlphaType);
22 }
23
24 return info;
25 }
26
19 SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data) 27 SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data)
20 : INHERITED(codec->getInfo()) 28 : INHERITED(make_premul(codec->getInfo()))
21 , fCodec(codec) 29 , fCodec(codec)
22 , fData(SkRef(data)) 30 , fData(SkRef(data))
23 {} 31 {}
24 32
25 SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) { 33 SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
26 return SkRef(fData.get()); 34 return SkRef(fData.get());
27 } 35 }
28 36
29 bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s ize_t rowBytes, 37 bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s ize_t rowBytes,
30 SkPMColor ctable[], int* ctableCount) { 38 SkPMColor ctable[], int* ctableCount) {
31 39
32 SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, nullptr, ctable, 40 SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, nullptr, ctable,
33 ctableCount); 41 ctableCount);
34 switch (result) { 42 switch (result) {
35 case SkCodec::kSuccess: 43 case SkCodec::kSuccess:
36 case SkCodec::kIncompleteInput: 44 case SkCodec::kIncompleteInput:
37 return true; 45 return true;
38 default: 46 default:
39 return false; 47 return false;
40 } 48 }
41 } 49 }
42 50
43 bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], s ize_t rowBytes[3], 51 bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], s ize_t rowBytes[3],
44 SkYUVColorSpace* colorSpace) { 52 SkYUVColorSpace* colorSpace) {
45 return false; 53 // TODO (msarett): Change the YUV API in ImageGenerator to match SkCodec.
54 // This function is currently a hack to match the implementa tion
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,
55 // in SkCodec with the old API.
56
57 // If planes is NULL, we just need to return the size.
58 if (nullptr == planes) {
59 SkCodec::YUVPlanesWidthBytes widthBytes;
60 bool result = fCodec->queryYUV8((SkCodec::YUVPlanesSizes*) sizes, &width Bytes, colorSpace);
61 if (result) {
62 // Save the true widths
63 fYWidth = sizes[0].fWidth;
64 fUWidth = sizes[1].fWidth;
65 fVWidth = sizes[2].fWidth;
66
67 // Adjust the widths so the client allocates enough memory
68 sizes[0].fWidth = widthBytes.YWidthBytes;
69 sizes[1].fWidth = widthBytes.UWidthBytes;
70 sizes[2].fWidth = widthBytes.VWidthBytes;
71 }
72 return result;
73 }
74
75 // 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'
76 sizes[0].fWidth = fYWidth;
77 sizes[1].fWidth = fUWidth;
78 sizes[2].fWidth = fVWidth;
79 bool result = fCodec->getYUV8Planes((const SkCodec::YUVPlanesSizes*)sizes, p lanes,
80 (const SkCodec::YUVPlanesWidthBytes*) rowBytes);
81 if (result && colorSpace) {
82 *colorSpace = kJPEG_SkYUVColorSpace;
83 }
84
85 return result;
46 } 86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698