| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkImageGenerator.h" | 8 #include "SkImageGenerator.h" |
| 9 | 9 |
| 10 bool SkImageGenerator::getInfo(SkImageInfo* info) { | 10 bool SkImageGenerator::getInfo(SkImageInfo* info) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r
owBytes) { | 50 bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r
owBytes) { |
| 51 SkASSERT(kIndex_8_SkColorType != info.colorType()); | 51 SkASSERT(kIndex_8_SkColorType != info.colorType()); |
| 52 if (kIndex_8_SkColorType == info.colorType()) { | 52 if (kIndex_8_SkColorType == info.colorType()) { |
| 53 return false; | 53 return false; |
| 54 } | 54 } |
| 55 return this->getPixels(info, pixels, rowBytes, NULL, NULL); | 55 return this->getPixels(info, pixels, rowBytes, NULL, NULL); |
| 56 } | 56 } |
| 57 | 57 |
| 58 #ifdef SK_SUPPORT_LEGACY_IMAGEGENERATOR_YUV_API |
| 58 bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t r
owBytes[3], | 59 bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t r
owBytes[3], |
| 59 SkYUVColorSpace* colorSpace) { | 60 SkYUVColorSpace* colorSpace) { |
| 60 #ifdef SK_DEBUG | 61 #ifdef SK_DEBUG |
| 61 // In all cases, we need the sizes array | 62 // In all cases, we need the sizes array |
| 62 SkASSERT(sizes); | 63 SkASSERT(sizes); |
| 63 | 64 |
| 64 bool isValidWithPlanes = (planes) && (rowBytes) && | 65 bool isValidWithPlanes = (planes) && (rowBytes) && |
| 65 ((planes[0]) && (planes[1]) && (planes[2]) && | 66 ((planes[0]) && (planes[1]) && (planes[2]) && |
| 66 (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2])); | 67 (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2])); |
| 67 bool isValidWithoutPlanes = | 68 bool isValidWithoutPlanes = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 (sizes[1].fHeight >= 0) && | 84 (sizes[1].fHeight >= 0) && |
| 84 (sizes[2].fWidth >= 0) && | 85 (sizes[2].fWidth >= 0) && |
| 85 (sizes[2].fHeight >= 0) && | 86 (sizes[2].fHeight >= 0) && |
| 86 (rowBytes[0] >= (size_t)sizes[0].fWidth) && | 87 (rowBytes[0] >= (size_t)sizes[0].fWidth) && |
| 87 (rowBytes[1] >= (size_t)sizes[1].fWidth) && | 88 (rowBytes[1] >= (size_t)sizes[1].fWidth) && |
| 88 (rowBytes[2] >= (size_t)sizes[2].fWidth))); | 89 (rowBytes[2] >= (size_t)sizes[2].fWidth))); |
| 89 #endif | 90 #endif |
| 90 | 91 |
| 91 return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); | 92 return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace); |
| 92 } | 93 } |
| 94 #endif |
| 93 | 95 |
| 94 bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t
rowBytes[3]) { | 96 bool SkImageGenerator::queryYUV8(SkISize logicalSizes[3], SkISize optimalAllocat
ionSizes[3]) { |
| 95 return false; | 97 SkISize logicalStorage[3], optimalStorage[3]; |
| 98 if (!logicalSizes) { |
| 99 logicalSizes = logicalStorage; |
| 100 } |
| 101 if (!optimalAllocationSizes) { |
| 102 optimalAllocationSizes = optimalStorage; |
| 103 } |
| 104 return this->onQueryYUV8(logicalSizes, optimalAllocationSizes); |
| 96 } | 105 } |
| 97 | 106 |
| 98 bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t
rowBytes[3], | 107 bool SkImageGenerator::getYUV8(const SkISize allocationSizes[3], void* planes[3]
, |
| 99 SkYUVColorSpace* colorSpace) { | 108 SkYUVColorSpace* colorSpace) { |
| 100 // In order to maintain compatibility with clients that implemented the orig
inal | 109 SkASSERT(allocationSizes); |
| 101 // onGetYUV8Planes interface, we assume that the color space is JPEG. | 110 SkASSERT(planes); |
| 102 // TODO(rileya): remove this and the old onGetYUV8Planes once clients switch
over to | 111 |
| 103 // the new interface. | 112 for (int i = 0; i < 3; ++i) { |
| 104 if (colorSpace) { | 113 if (allocationSizes[i].width() <= 0 || allocationSizes[i].height() <= 0)
{ |
| 105 *colorSpace = kJPEG_SkYUVColorSpace; | 114 return false; |
| 115 } |
| 116 if (!planes[i]) { |
| 117 return false; |
| 118 } |
| 106 } | 119 } |
| 107 return this->onGetYUV8Planes(sizes, planes, rowBytes); | 120 |
| 121 SkYUVColorSpace colorSpaceStorage; |
| 122 if (!colorSpace) { |
| 123 colorSpace = &colorSpaceStorage; |
| 124 } |
| 125 return this->onGetYUV8(allocationSizes, planes, colorSpace); |
| 108 } | 126 } |
| 109 | 127 |
| 110 ////////////////////////////////////////////////////////////////////////////////
///////////// | 128 ////////////////////////////////////////////////////////////////////////////////
///////////// |
| 111 | 129 |
| 112 SkData* SkImageGenerator::onRefEncodedData() { | 130 SkData* SkImageGenerator::onRefEncodedData() { |
| 113 return NULL; | 131 return NULL; |
| 114 } | 132 } |
| 115 | 133 |
| 116 bool SkImageGenerator::onGetInfo(SkImageInfo*) { | 134 bool SkImageGenerator::onGetInfo(SkImageInfo*) { |
| 117 return false; | 135 return false; |
| 118 } | 136 } |
| 119 | 137 |
| 120 bool SkImageGenerator::onGetPixels(const SkImageInfo&, void*, size_t, SkPMColor*
, int*) { | 138 bool SkImageGenerator::onGetPixels(const SkImageInfo&, void*, size_t, SkPMColor*
, int*) { |
| 121 return false; | 139 return false; |
| 122 } | 140 } |
| 141 |
| 142 bool SkImageGenerator::onQueryYUV8(SkISize logicalSizes[3], SkISize optimalAlloc
ationSizes[3]) { |
| 143 #ifdef SK_SUPPORT_LEGACY_IMAGEGENERATOR_YUV_API |
| 144 if (this->getYUV8Planes(logicalSizes, NULL, NULL, NULL)) { |
| 145 memcpy(optimalAllocationSizes, logicalSizes, sizeof(SkISize) * 3); |
| 146 return true; |
| 147 } |
| 148 #endif |
| 149 return false; |
| 150 } |
| 151 |
| 152 bool SkImageGenerator::onGetYUV8(const SkISize allocationSizes[3], void* planes[
3], |
| 153 SkYUVColorSpace* colorSpace) { |
| 154 #ifdef SK_SUPPORT_LEGACY_IMAGEGENERATOR_YUV_API |
| 155 SkISize tmpSizes[3]; |
| 156 size_t rowBytes[3]; |
| 157 for (int i = 0; i < 3; ++i) { |
| 158 tmpSizes[i] = allocationSizes[i]; |
| 159 rowBytes[i] = allocationSizes[i].width(); |
| 160 } |
| 161 if (this->getYUV8Planes(tmpSizes, planes, rowBytes, colorSpace)) { |
| 162 return true; |
| 163 } |
| 164 #endif |
| 165 return false; |
| 166 } |
| 167 |
| 168 #ifdef SK_SUPPORT_LEGACY_IMAGEGENERATOR_YUV_API |
| 169 bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t
rowBytes[3]) { |
| 170 return false; |
| 171 } |
| 172 |
| 173 bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t
rowBytes[3], |
| 174 SkYUVColorSpace* colorSpace) { |
| 175 // In order to maintain compatibility with clients that implemented the orig
inal |
| 176 // onGetYUV8Planes interface, we assume that the color space is JPEG. |
| 177 // TODO(rileya): remove this and the old onGetYUV8Planes once clients switch
over to |
| 178 // the new interface. |
| 179 if (colorSpace) { |
| 180 *colorSpace = kJPEG_SkYUVColorSpace; |
| 181 } |
| 182 return this->onGetYUV8Planes(sizes, planes, rowBytes); |
| 183 } |
| 184 #endif |
| 185 |
| OLD | NEW |