OLD | NEW |
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 Loading... |
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) |
31 {} | 34 {} |
32 | 35 |
33 SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) { | 36 SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) { |
34 return SkRef(fData.get()); | 37 return SkRef(fData.get()); |
35 } | 38 } |
36 | 39 |
37 bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s
ize_t rowBytes, | 40 bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s
ize_t rowBytes, |
38 SkPMColor ctable[], int* ctableCount) { | 41 SkPMColor ctable[], int* ctableCount) { |
39 | 42 |
40 SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, nullptr,
ctable, | 43 SkCodec::Result result = fCodec->getPixels(info, pixels, rowBytes, nullptr,
ctable, |
41 ctableCount); | 44 ctableCount); |
42 switch (result) { | 45 switch (result) { |
43 case SkCodec::kSuccess: | 46 case SkCodec::kSuccess: |
44 case SkCodec::kIncompleteInput: | 47 case SkCodec::kIncompleteInput: |
45 return true; | 48 return true; |
46 default: | 49 default: |
47 return false; | 50 return false; |
48 } | 51 } |
49 } | 52 } |
50 | 53 |
51 bool SkCodecImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace
* colorSpace) const | 54 bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], s
ize_t rowBytes[3], |
52 { | 55 SkYUVColorSpace* colorSpace) { |
53 return fCodec->queryYUV8(sizeInfo, colorSpace); | 56 // TODO (msarett): Change the YUV API in ImageGenerator to match SkCodec. |
54 } | 57 // This function is currently a hack to match the implementa
tion |
| 58 // in SkCodec with the old API. |
| 59 SkCodec::YUVSizeInfo sizeInfo; |
55 | 60 |
56 bool SkCodecImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void*
planes[3]) { | 61 // If planes is NULL, we just need to return the size. |
| 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(); |
57 SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes); | 91 SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes); |
| 92 if ((result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput) &&
colorSpace) { |
| 93 *colorSpace = kJPEG_SkYUVColorSpace; |
| 94 } |
58 | 95 |
59 switch (result) { | 96 switch (result) { |
60 case SkCodec::kSuccess: | 97 case SkCodec::kSuccess: |
61 case SkCodec::kIncompleteInput: | 98 case SkCodec::kIncompleteInput: |
62 return true; | 99 return true; |
63 default: | 100 default: |
64 return false; | 101 return false; |
65 } | 102 } |
66 } | 103 } |
OLD | NEW |