bool DecodingImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes) { if (NULL == pixels) { return false; } if (fInfo != info) { // The caller has specified a different info. This is an // error for this kind of SkImageGenerator. Use the Options // to change the settings. return false; } if (info.minRowBytes() > rowBytes) { // The caller has specified a bad rowBytes. return false; } SkAssertResult(fStream->rewind()); SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStream)); if (NULL == decoder.get()) { return false; } decoder->setDitherImage(fDitherImage); decoder->setSampleSize(fSampleSize); decoder->setRequireUnpremultipliedColors( info.fAlphaType == kUnpremul_SkAlphaType); SkBitmap bitmap; TargetAllocator allocator(fInfo, pixels, rowBytes); decoder->setAllocator(&allocator); // TODO: need to be able to pass colortype directly to decoder SkBitmap::Config legacyConfig = SkColorTypeToBitmapConfig(info.colorType()); bool success = decoder->decode(fStream, &bitmap, legacyConfig, SkImageDecoder::kDecodePixels_Mode); decoder->setAllocator(NULL); if (!success) { return false; } if (allocator.isReady()) { // Did not use pixels! SkBitmap bm; SkASSERT(bitmap.canCopyTo(info.colorType())); bool copySuccess = bitmap.copyTo(&bm, info.colorType(), &allocator); if (!copySuccess || allocator.isReady()) { SkDEBUGFAIL("bitmap.copyTo(requestedConfig) failed."); // Earlier we checked canCopyto(); we expect consistency. return false; } SkASSERT(check_alpha(info.alphaType(), bm.alphaType())); } else { SkASSERT(check_alpha(info.alphaType(), bitmap.alphaType())); } return true; }
static int check_alnum(int c) { return check_alpha(c) || check_digit(c); }
inline bool check_dist(const char* function, const RealType& alpha, const RealType& beta, RealType* result, const Policy& pol) { // Check both alpha and beta. return check_alpha(function, alpha, result, pol) && check_beta(function, beta, result, pol); } // bool check_dist