// A contructor-type function that returns NULL on failure. This // prevents the returned SkImageGenerator from ever being in a bad // state. Called by both Create() functions SkImageGenerator* CreateDecodingImageGenerator( SkData* data, SkStreamRewindable* stream, const SkDecodingImageGenerator::Options& opts) { SkASSERT(stream); SkAutoTUnref<SkStreamRewindable> autoStream(stream); // always unref this. if (opts.fUseRequestedColorType && (kIndex_8_SkColorType == opts.fRequestedColorType)) { // We do not support indexed color with SkImageGenerators, return NULL; } SkAssertResult(autoStream->rewind()); SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(autoStream)); if (NULL == decoder.get()) { return NULL; } SkBitmap bitmap; decoder->setSampleSize(opts.fSampleSize); decoder->setRequireUnpremultipliedColors(opts.fRequireUnpremul); if (!decoder->decode(stream, &bitmap, SkImageDecoder::kDecodeBounds_Mode)) { return NULL; } if (bitmap.config() == SkBitmap::kNo_Config) { return NULL; } SkImageInfo info = bitmap.info(); if (!opts.fUseRequestedColorType) { // Use default if (kIndex_8_SkColorType == bitmap.colorType()) { // We don't support kIndex8 because we don't support // colortables in this workflow. info.fColorType = kN32_SkColorType; } } else { if (!bitmap.canCopyTo(opts.fRequestedColorType)) { SkASSERT(bitmap.colorType() != opts.fRequestedColorType); return NULL; // Can not translate to needed config. } info.fColorType = opts.fRequestedColorType; } if (opts.fRequireUnpremul && info.fAlphaType != kOpaque_SkAlphaType) { info.fAlphaType = kUnpremul_SkAlphaType; } return SkNEW_ARGS(DecodingImageGenerator, (data, autoStream.detach(), info, opts.fSampleSize, opts.fDitherImage)); }
JsonPlugin::JsonPlugin(LPCTSTR lpFileName, LPCBYTE data) : buf(10000), sHostFile(lpFileName), pExtOnGet(sJsonExt) { bChanged = false; { USE_SETTINGS; bKeysAsDirs = settings.Get(sObjectsAsDirs, 1); bBakFiles = settings.Get(sBakFiles, 1); bStartUnsorted = settings.Get(sStartUnsorted, 1); iStartPanelMode = settings.Get(sStartPanelMode, 6) + '0'; } //buf.resize(buf.capacity()); f = _tfopen(lpFileName, _T("r")); if(f == NULL) throw WinExcept(); FileReadStream fs(f, &buf[0], buf.size()); AutoUTFInputStream<unsigned, FileReadStream> autoStream(fs); doc.ParseStream<0, AutoUTF<unsigned>>(autoStream); bSourceHasBOM = autoStream.HasBOM(); sourceUTFType = autoStream.GetType(); curObject = &doc; }