commit-bot@chromium.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 1 | /* |
| 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.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 10 | bool SkImageGenerator::getInfo(SkImageInfo* info) { |
| 11 | SkImageInfo dummy; |
| 12 | if (NULL == info) { |
| 13 | info = &dummy; |
| 14 | } |
| 15 | return this->onGetInfo(info); |
| 16 | } |
| 17 | |
| 18 | bool 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 | |
| 50 | bool 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.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 57 | |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 58 | bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], |
| 59 | SkYUVColorSpace* colorSpace) { |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 60 | #ifdef SK_DEBUG |
| 61 | // In all cases, we need the sizes array |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 62 | SkASSERT(sizes); |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 63 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 64 | bool isValidWithPlanes = (planes) && (rowBytes) && |
| 65 | ((planes[0]) && (planes[1]) && (planes[2]) && |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 66 | (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 | |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 91 | return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); |
sugoi | 518d83d | 2014-07-21 11:37:39 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]) { |
| 95 | return false; |
| 96 | } |
| 97 | |
rileya | abaef86 | 2014-09-12 17:45:58 -0700 | [diff] [blame] | 98 | bool 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.org | 00f8d6c | 2014-05-29 15:57:20 +0000 | [diff] [blame] | 110 | ///////////////////////////////////////////////////////////////////////////////////////////// |
| 111 | |
| 112 | SkData* SkImageGenerator::onRefEncodedData() { |
| 113 | return NULL; |
| 114 | } |
| 115 | |
| 116 | bool SkImageGenerator::onGetInfo(SkImageInfo*) { |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | bool SkImageGenerator::onGetPixels(const SkImageInfo&, void*, size_t, SkPMColor*, int*) { |
| 121 | return false; |
| 122 | } |