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 10#ifndef SK_SUPPORT_LEGACY_IMAGEGENERATORAPI 11bool SkImageGenerator::getInfo(SkImageInfo* info) { 12 SkImageInfo dummy; 13 if (NULL == info) { 14 info = &dummy; 15 } 16 return this->onGetInfo(info); 17} 18 19bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, 20 SkPMColor ctable[], int* ctableCount) { 21 if (kUnknown_SkColorType == info.colorType()) { 22 return false; 23 } 24 if (NULL == pixels) { 25 return false; 26 } 27 if (rowBytes < info.minRowBytes()) { 28 return false; 29 } 30 31 if (kIndex_8_SkColorType == info.colorType()) { 32 if (NULL == ctable || NULL == ctableCount) { 33 return false; 34 } 35 } else { 36 if (ctableCount) { 37 *ctableCount = 0; 38 } 39 ctableCount = NULL; 40 ctable = NULL; 41 } 42 43 bool success = this->onGetPixels(info, pixels, rowBytes, ctable, ctableCount); 44 45 if (success && ctableCount) { 46 SkASSERT(*ctableCount >= 0 && *ctableCount <= 256); 47 } 48 return success; 49} 50 51bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { 52 SkASSERT(kIndex_8_SkColorType != info.colorType()); 53 if (kIndex_8_SkColorType == info.colorType()) { 54 return false; 55 } 56 return this->getPixels(info, pixels, rowBytes, NULL, NULL); 57} 58#endif 59 60bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], 61 SkYUVColorSpace* colorSpace) { 62#ifdef SK_DEBUG 63 // In all cases, we need the sizes array 64 SkASSERT(sizes); 65 66 bool isValidWithPlanes = (planes) && (rowBytes) && 67 ((planes[0]) && (planes[1]) && (planes[2]) && 68 (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2])); 69 bool isValidWithoutPlanes = 70 ((NULL == planes) || 71 ((NULL == planes[0]) && (NULL == planes[1]) && (NULL == planes[2]))) && 72 ((NULL == rowBytes) || 73 ((0 == rowBytes[0]) && (0 == rowBytes[1]) && (0 == rowBytes[2]))); 74 75 // Either we have all planes and rowBytes information or we have none of it 76 // Having only partial information is not supported 77 SkASSERT(isValidWithPlanes || isValidWithoutPlanes); 78 79 // If we do have planes information, make sure all sizes are non 0 80 // and all rowBytes are valid 81 SkASSERT(!isValidWithPlanes || 82 ((sizes[0].fWidth >= 0) && 83 (sizes[0].fHeight >= 0) && 84 (sizes[1].fWidth >= 0) && 85 (sizes[1].fHeight >= 0) && 86 (sizes[2].fWidth >= 0) && 87 (sizes[2].fHeight >= 0) && 88 (rowBytes[0] >= (size_t)sizes[0].fWidth) && 89 (rowBytes[1] >= (size_t)sizes[1].fWidth) && 90 (rowBytes[2] >= (size_t)sizes[2].fWidth))); 91#endif 92 93 return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); 94} 95 96bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]) { 97 return false; 98} 99 100bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], 101 SkYUVColorSpace* colorSpace) { 102 // In order to maintain compatibility with clients that implemented the original 103 // onGetYUV8Planes interface, we assume that the color space is JPEG. 104 // TODO(rileya): remove this and the old onGetYUV8Planes once clients switch over to 105 // the new interface. 106 if (colorSpace) { 107 *colorSpace = kJPEG_SkYUVColorSpace; 108 } 109 return this->onGetYUV8Planes(sizes, planes, rowBytes); 110} 111 112///////////////////////////////////////////////////////////////////////////////////////////// 113 114SkData* SkImageGenerator::onRefEncodedData() { 115 return NULL; 116} 117 118bool SkImageGenerator::onGetInfo(SkImageInfo*) { 119 return false; 120} 121 122bool SkImageGenerator::onGetPixels(const SkImageInfo&, void*, size_t, SkPMColor*, int*) { 123 return false; 124} 125