SkImageGenerator.cpp revision 518d83dbc1c899e316e8c896af5defb58b83120f
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#ifdef SK_DEBUG 62 // In all cases, we need the sizes array 63 SkASSERT(NULL != sizes); 64 65 bool isValidWithPlanes = (NULL != planes) && (NULL != rowBytes) && 66 ((NULL != planes[0]) && (NULL != planes[1]) && (NULL != planes[2]) && 67 (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2])); 68 bool isValidWithoutPlanes = 69 ((NULL == planes) || 70 ((NULL == planes[0]) && (NULL == planes[1]) && (NULL == planes[2]))) && 71 ((NULL == rowBytes) || 72 ((0 == rowBytes[0]) && (0 == rowBytes[1]) && (0 == rowBytes[2]))); 73 74 // Either we have all planes and rowBytes information or we have none of it 75 // Having only partial information is not supported 76 SkASSERT(isValidWithPlanes || isValidWithoutPlanes); 77 78 // If we do have planes information, make sure all sizes are non 0 79 // and all rowBytes are valid 80 SkASSERT(!isValidWithPlanes || 81 ((sizes[0].fWidth >= 0) && 82 (sizes[0].fHeight >= 0) && 83 (sizes[1].fWidth >= 0) && 84 (sizes[1].fHeight >= 0) && 85 (sizes[2].fWidth >= 0) && 86 (sizes[2].fHeight >= 0) && 87 (rowBytes[0] >= (size_t)sizes[0].fWidth) && 88 (rowBytes[1] >= (size_t)sizes[1].fWidth) && 89 (rowBytes[2] >= (size_t)sizes[2].fWidth))); 90#endif 91 92 return this->onGetYUV8Planes(sizes, planes, rowBytes); 93} 94 95bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]) { 96 return false; 97} 98 99///////////////////////////////////////////////////////////////////////////////////////////// 100 101SkData* SkImageGenerator::onRefEncodedData() { 102 return NULL; 103} 104 105bool SkImageGenerator::onGetInfo(SkImageInfo*) { 106 return false; 107} 108 109bool SkImageGenerator::onGetPixels(const SkImageInfo&, void*, size_t, SkPMColor*, int*) { 110 return false; 111} 112