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

Side by Side Diff: src/codec/SkCodecImageGenerator.cpp

Issue 1716523002: Update Skia's YUV API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 9 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
« no previous file with comments | « src/codec/SkCodecImageGenerator.h ('k') | src/codec/SkJpegCodec.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
(...skipping 10 matching lines...) Expand all
21 return info.makeAlphaType(kPremul_SkAlphaType); 21 return info.makeAlphaType(kPremul_SkAlphaType);
22 } 22 }
23 23
24 return info; 24 return info;
25 } 25 }
26 26
27 SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data) 27 SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data)
28 : INHERITED(make_premul(codec->getInfo())) 28 : INHERITED(make_premul(codec->getInfo()))
29 , fCodec(codec) 29 , fCodec(codec)
30 , fData(SkRef(data)) 30 , fData(SkRef(data))
31 , fYWidth(0)
32 , fUWidth(0)
33 , fVWidth(0)
34 {} 31 {}
35 32
36 SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) { 33 SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
37 return SkRef(fData.get()); 34 return SkRef(fData.get());
38 } 35 }
39 36
40 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,
41 SkPMColor ctable[], int* ctableCount) { 38 SkPMColor ctable[], int* ctableCount) {
42 39
43 SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, nullptr, ctable, 40 SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, nullptr, ctable,
44 ctableCount); 41 ctableCount);
45 switch (result) { 42 switch (result) {
46 case SkCodec::kSuccess: 43 case SkCodec::kSuccess:
47 case SkCodec::kIncompleteInput: 44 case SkCodec::kIncompleteInput:
48 return true; 45 return true;
49 default: 46 default:
50 return false; 47 return false;
51 } 48 }
52 } 49 }
53 50
54 bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], s ize_t rowBytes[3], 51 bool SkCodecImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace * colorSpace) const
55 SkYUVColorSpace* colorSpace) { 52 {
56 // TODO (msarett): Change the YUV API in ImageGenerator to match SkCodec. 53 return fCodec->queryYUV8(sizeInfo, colorSpace);
57 // This function is currently a hack to match the implementa tion 54 }
58 // in SkCodec with the old API.
59 SkCodec::YUVSizeInfo sizeInfo;
60 55
61 // If planes is NULL, we just need to return the size. 56 bool SkCodecImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
62 if (nullptr == planes) {
63 bool result = fCodec->queryYUV8(&sizeInfo, colorSpace);
64 if (result) {
65 // Save the true widths
66 fYWidth = sizeInfo.fYSize.width();
67 fUWidth = sizeInfo.fUSize.width();
68 fVWidth = sizeInfo.fVSize.width();
69
70 // Set the sizes so that the client allocates enough memory
71 sizes[0].fWidth = (int) sizeInfo.fYWidthBytes;
72 sizes[0].fHeight = sizeInfo.fYSize.height();
73 sizes[1].fWidth = (int) sizeInfo.fUWidthBytes;
74 sizes[1].fHeight = sizeInfo.fUSize.height();
75 sizes[2].fWidth = (int) sizeInfo.fVWidthBytes;
76 sizes[2].fHeight = sizeInfo.fVSize.height();
77 }
78 return result;
79 }
80
81 // Set the sizeInfo with the true widths and heights
82 SkASSERT(fYWidth != 0 && fUWidth != 0 && fVWidth != 0);
83 sizeInfo.fYSize.set(fYWidth, sizes[0].height());
84 sizeInfo.fUSize.set(fUWidth, sizes[1].height());
85 sizeInfo.fVSize.set(fVWidth, sizes[2].height());
86
87 // Set the sizeInfo with the allocated widths
88 sizeInfo.fYWidthBytes = sizes[0].width();
89 sizeInfo.fUWidthBytes = sizes[1].width();
90 sizeInfo.fVWidthBytes = sizes[2].width();
91 SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes); 57 SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes);
92 if ((result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput) && colorSpace) {
93 *colorSpace = kJPEG_SkYUVColorSpace;
94 }
95 58
96 switch (result) { 59 switch (result) {
97 case SkCodec::kSuccess: 60 case SkCodec::kSuccess:
98 case SkCodec::kIncompleteInput: 61 case SkCodec::kIncompleteInput:
99 return true; 62 return true;
100 default: 63 default:
101 return false; 64 return false;
102 } 65 }
103 } 66 }
OLDNEW
« no previous file with comments | « src/codec/SkCodecImageGenerator.h ('k') | src/codec/SkJpegCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698