blob: 0f63db50f637e82633caf9bd6f611979c941ffcb [file] [log] [blame]
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +00001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkImageGenerator.h"
9
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +000010bool SkImageGenerator::getInfo(SkImageInfo* info) {
11 SkImageInfo dummy;
12 if (NULL == info) {
13 info = &dummy;
14 }
15 return this->onGetInfo(info);
16}
17
18bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
19 SkPMColor ctable[], int* ctableCount) {
20 if (kUnknown_SkColorType == info.colorType()) {
21 return false;
22 }
23 if (NULL == pixels) {
24 return false;
25 }
26 if (rowBytes < info.minRowBytes()) {
27 return false;
28 }
29
30 if (kIndex_8_SkColorType == info.colorType()) {
31 if (NULL == ctable || NULL == ctableCount) {
32 return false;
33 }
34 } else {
35 if (ctableCount) {
36 *ctableCount = 0;
37 }
38 ctableCount = NULL;
39 ctable = NULL;
40 }
41
42 bool success = this->onGetPixels(info, pixels, rowBytes, ctable, ctableCount);
43
44 if (success && ctableCount) {
45 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256);
46 }
47 return success;
48}
49
50bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) {
51 SkASSERT(kIndex_8_SkColorType != info.colorType());
52 if (kIndex_8_SkColorType == info.colorType()) {
53 return false;
54 }
55 return this->getPixels(info, pixels, rowBytes, NULL, NULL);
56}
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +000057
rileyaabaef862014-09-12 17:45:58 -070058bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
59 SkYUVColorSpace* colorSpace) {
sugoi518d83d2014-07-21 11:37:39 -070060#ifdef SK_DEBUG
61 // In all cases, we need the sizes array
bsalomon49f085d2014-09-05 13:34:00 -070062 SkASSERT(sizes);
sugoi518d83d2014-07-21 11:37:39 -070063
bsalomon49f085d2014-09-05 13:34:00 -070064 bool isValidWithPlanes = (planes) && (rowBytes) &&
65 ((planes[0]) && (planes[1]) && (planes[2]) &&
sugoi518d83d2014-07-21 11:37:39 -070066 (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2]));
67 bool isValidWithoutPlanes =
68 ((NULL == planes) ||
69 ((NULL == planes[0]) && (NULL == planes[1]) && (NULL == planes[2]))) &&
70 ((NULL == rowBytes) ||
71 ((0 == rowBytes[0]) && (0 == rowBytes[1]) && (0 == rowBytes[2])));
72
73 // Either we have all planes and rowBytes information or we have none of it
74 // Having only partial information is not supported
75 SkASSERT(isValidWithPlanes || isValidWithoutPlanes);
76
77 // If we do have planes information, make sure all sizes are non 0
78 // and all rowBytes are valid
79 SkASSERT(!isValidWithPlanes ||
80 ((sizes[0].fWidth >= 0) &&
81 (sizes[0].fHeight >= 0) &&
82 (sizes[1].fWidth >= 0) &&
83 (sizes[1].fHeight >= 0) &&
84 (sizes[2].fWidth >= 0) &&
85 (sizes[2].fHeight >= 0) &&
86 (rowBytes[0] >= (size_t)sizes[0].fWidth) &&
87 (rowBytes[1] >= (size_t)sizes[1].fWidth) &&
88 (rowBytes[2] >= (size_t)sizes[2].fWidth)));
89#endif
90
rileyaabaef862014-09-12 17:45:58 -070091 return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace);
sugoi518d83d2014-07-21 11:37:39 -070092}
93
94bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]) {
95 return false;
96}
97
rileyaabaef862014-09-12 17:45:58 -070098bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
99 SkYUVColorSpace* colorSpace) {
100 // In order to maintain compatibility with clients that implemented the original
101 // onGetYUV8Planes interface, we assume that the color space is JPEG.
102 // TODO(rileya): remove this and the old onGetYUV8Planes once clients switch over to
103 // the new interface.
104 if (colorSpace) {
105 *colorSpace = kJPEG_SkYUVColorSpace;
106 }
107 return this->onGetYUV8Planes(sizes, planes, rowBytes);
108}
109
commit-bot@chromium.org00f8d6c2014-05-29 15:57:20 +0000110/////////////////////////////////////////////////////////////////////////////////////////////
111
112SkData* SkImageGenerator::onRefEncodedData() {
113 return NULL;
114}
115
116bool SkImageGenerator::onGetInfo(SkImageInfo*) {
117 return false;
118}
119
120bool SkImageGenerator::onGetPixels(const SkImageInfo&, void*, size_t, SkPMColor*, int*) {
121 return false;
122}