当前位置: 首页>>代码示例>>C++>>正文


C++ SkImageDecoder类代码示例

本文整理汇总了C++中SkImageDecoder的典型用法代码示例。如果您正苦于以下问题:C++ SkImageDecoder类的具体用法?C++ SkImageDecoder怎么用?C++ SkImageDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SkImageDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doBuildTileIndex

static jobject doBuildTileIndex(JNIEnv* env, SkStream* stream) {
    SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
    int width, height;
    if (NULL == decoder) {
        // fail to get decoder, do not forget to free stream
        stream->unref();
        doThrowIOE(env, "Image format not supported");
        return nullObjectReturn("SkImageDecoder::Factory returned null");
    }

    JavaPixelAllocator *javaAllocator = new JavaPixelAllocator(env);
    decoder->setAllocator(javaAllocator);
    javaAllocator->unref();

    if (!decoder->buildTileIndex(stream, &width, &height)) {
        char msg[100];
        snprintf(msg, sizeof(msg), "Image failed to decode using %s decoder",
                decoder->getFormatName());
        // fail to build tile index, do not forget to free stream
        stream->unref();
        doThrowIOE(env, msg);
        return nullObjectReturn("decoder->buildTileIndex returned false");
    }

    SkBitmapRegionDecoder *bm = new SkBitmapRegionDecoder(decoder, stream, width, height);

    return GraphicsJNI::createBitmapRegionDecoder(env, bm);
}
开发者ID:0xr0ot,项目名称:frameworks_base,代码行数:28,代码来源:BitmapRegionDecoder.cpp

示例2: SkASSERT

bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {
    SkASSERT(&gImageRefMutex == this->mutex());

    if (fErrorInDecoding) {
        return false;
    }

    /*  As soon as we really know our config, we record it, so that on
        subsequent calls to the codec, we are sure we will always get the same
        result.
    */
    if (SkBitmap::kNo_Config != fBitmap.config()) {
        fConfig = fBitmap.config();
    }

    if (NULL != fBitmap.getPixels() ||
            (SkBitmap::kNo_Config != fBitmap.config() &&
             SkImageDecoder::kDecodeBounds_Mode == mode)) {
        return true;
    }

    SkASSERT(fBitmap.getPixels() == NULL);

    fStream->rewind();

    SkImageDecoder* codec;
    if (fFactory) {
        codec = fFactory->newDecoder(fStream);
    } else {
        codec = SkImageDecoder::Factory(fStream);
    }

    if (codec) {
        SkAutoTDelete<SkImageDecoder> ad(codec);

        codec->setSampleSize(fSampleSize);
        codec->setDitherImage(fDoDither);
        if (this->onDecode(codec, fStream, &fBitmap, fConfig, mode)) {
            return true;
        }
    }

#ifdef DUMP_IMAGEREF_LIFECYCLE
    if (NULL == codec) {
        SkDebugf("--- ImageRef: <%s> failed to find codec\n", this->getURI());
    } else {
        SkDebugf("--- ImageRef: <%s> failed in codec for %d mode\n",
                 this->getURI(), mode);
    }
#endif
    fErrorInDecoding = true;
    fBitmap.reset();
    return false;
}
开发者ID:Cue,项目名称:skia,代码行数:54,代码来源:SkImageRef.cpp

示例3: ArcsView

    ArcsView() {
        //testparse();
        fSweep = SkIntToScalar(100);
        this->setBGColor(0xFFDDDDDD);
		SkFILEStream stream("c:/test_ba.png");
		SkImageDecoder* dec = sk_libpng_dfactory(&stream);
		//delete dec;
		SkImageDecoder *coder = SkImageDecoder::Factory(&stream);
		coder->decode(&stream, &fbmp, SkColorType::kRGBA_8888_SkColorType, SkImageDecoder::kDecodePixels_Mode);
		delete dec;
    }
开发者ID:hgl888,项目名称:RuntimeCanvas,代码行数:11,代码来源:SampleArc.cpp

示例4: XLOGE

bool MpoDecoder::decodeBounds()
{
    long bufferSize = mMP_Images[0]->getImageSize() + 2 + 2; //SOI + JPEG + EOI
    mMpoFileStream->rewind();
    if (false == mMpoFileStream->skip(mMP_Images[0]->getOffsetInFile()) ) {
        XLOGE("failed to jump to image data");
        return false;
    }

    char* jpegBuffer = (char*)malloc((unsigned int)bufferSize);
    if (NULL == jpegBuffer) {
        XLOGE("can not allocate memory to hold JPEG data");
        return false;
    }

    if (bufferSize != mMpoFileStream->read(jpegBuffer, bufferSize)) {
        free(jpegBuffer);
        XLOGE("read jpeg data failed");
        return false;
    }
    SkMemoryStream memStream(jpegBuffer, bufferSize);

    int sampleSize = 1;
    int preferSize = 0;
    bool doDither = true;

    SkBitmap* bitmap = new SkBitmap;
    SkBitmap::Config prefConfig = SkBitmap::kNo_Config;
    SkImageDecoder::Mode decodeMode = SkImageDecoder::kDecodeBounds_Mode;
    SkImageDecoder* decoder = SkImageDecoder::Factory(&memStream);
    if (NULL == decoder) {
        XLOGE("SkImageDecoder-Factory() returned false");
        free(jpegBuffer);
        return false;
    }

    decoder->setSampleSize(sampleSize);
    decoder->setDitherImage(doDither);
    //decoder->setPreferSize(preferSize);

    if (!decoder->decode(&memStream, bitmap, prefConfig, decodeMode)) {
        XLOGE("SkImageDecoder-decode() returned false");
        free(jpegBuffer);
        return false;
    }
    //free memory buffer
    free(jpegBuffer);
    mWidth = bitmap->width();
    mHeight = bitmap->height();
    //delete created SkBitmap
    delete bitmap;
    return true;
}
开发者ID:ferhung,项目名称:p201-mediatek,代码行数:53,代码来源:MpoDecoder.cpp

示例5: SkASSERT

bool SkImageRef::prepareBitmap(SkImageDecoder::Mode mode) {

    if (fErrorInDecoding) {
        return false;
    }

    if (NULL != fBitmap.getPixels() ||
            (SkBitmap::kNo_Config != fBitmap.config() &&
             SkImageDecoder::kDecodeBounds_Mode == mode)) {
        return true;
    }

    SkASSERT(fBitmap.getPixels() == NULL);

    if (!fStream->rewind()) {
        SkDEBUGF(("Failed to rewind SkImageRef stream!"));
        return false;
    }

    SkImageDecoder* codec;
    if (fFactory) {
        codec = fFactory->newDecoder(fStream);
    } else {
        codec = SkImageDecoder::Factory(fStream);
    }

    if (codec) {
        SkAutoTDelete<SkImageDecoder> ad(codec);

        codec->setSampleSize(fSampleSize);
        codec->setDitherImage(fDoDither);
        codec->setRequireUnpremultipliedColors(this->info().fAlphaType == kUnpremul_SkAlphaType);
        if (this->onDecode(codec, fStream, &fBitmap, fBitmap.config(), mode)) {
            if (kOpaque_SkAlphaType == fBitmap.alphaType()) {
                this->changeAlphaType(kOpaque_SkAlphaType);
            }
            SkASSERT(this->info() == fBitmap.info());
            return true;
        }
    }

#ifdef DUMP_IMAGEREF_LIFECYCLE
    if (NULL == codec) {
        SkDebugf("--- ImageRef: <%s> failed to find codec\n", this->getURI());
    } else {
        SkDebugf("--- ImageRef: <%s> failed in codec for %d mode\n",
                 this->getURI(), mode);
    }
#endif
    fErrorInDecoding = true;
    fBitmap.reset();
    return false;
}
开发者ID:Jimmy0319,项目名称:skia,代码行数:53,代码来源:SkImageRef.cpp

示例6: DecodeView

	DecodeView() {
        SkFILEStream stream("/skimages/index.png");
        SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
        if (codec) {
            for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
                stream.rewind();
                codec->setDitherImage(gRec[i].fDither);
                codec->decode(&stream, &fBitmap[i], gRec[i].fPrefConfig,
                              SkImageDecoder::kDecodePixels_Mode);
            }
        }
    }
开发者ID:ghub,项目名称:NVprSDK,代码行数:12,代码来源:SampleDecode.cpp

示例7: SkASSERT

bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm,
                                  SkBitmap::Config pref, Mode mode) {
    SkASSERT(stream);
    SkASSERT(bm);

    bool success = false;
    SkImageDecoder* codec = SkImageDecoder::Factory(stream);

    if (NULL != codec) {
        success = codec->decode(stream, bm, pref, mode);
        delete codec;
    }
    return success;
}
开发者ID:edrikL,项目名称:gears,代码行数:14,代码来源:SkImageDecoder.cpp

示例8: onOnceBeforeDraw

 void onOnceBeforeDraw() override {
     SkImageDecoder* codec = nullptr;
     SkString resourcePath = GetResourcePath("mandrill_512.png");
     SkFILEStream stream(resourcePath.c_str());
     if (stream.isValid()) {
         codec = SkImageDecoder::Factory(&stream);
     }
     if (codec) {
         stream.rewind();
         codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
         delete codec;
     } else {
         fBM.allocN32Pixels(1, 1);
         fBM.eraseARGB(255, 255, 0 , 0); // red == bad
     }
 }
开发者ID:YangchenVR,项目名称:skia,代码行数:16,代码来源:pixelxorxfermode.cpp

示例9: makeBitmap

 void makeBitmap() {
     SkImageDecoder* codec = NULL;
     SkString resourcePath = GetResourcePath(fFilename.c_str());
     SkFILEStream stream(resourcePath.c_str());
     if (stream.isValid()) {
         codec = SkImageDecoder::Factory(&stream);
     }
     if (codec) {
         stream.rewind();
         codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
         SkDELETE(codec);
     } else {
         fBM.allocN32Pixels(1, 1);
         *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
     }
     fSize = fBM.height();
 }
开发者ID:guolianzhu,项目名称:skia,代码行数:17,代码来源:filterindiabox.cpp

示例10: nvgCreateImageMem

int ResSkiaImage::ImageDataToSkBitmap(NVGcontext* ctx, const CStdString& src, CStdValVector* data) {
	int bitmap = 0;
	bool bOpaque = false;

// 	if (!data->m_data)
// 		return 0;
//
// 	SkMemoryStream* stream = data->m_data;
// 	return nvgCreateImageMem(ctx, 0, (unsigned char *)stream->getMemoryBase(), stream->getLength());
	return nvgCreateImageMem(ctx, 0, (unsigned char *)data->GetBuffer(), data->GetSize());

#if 0
	if (-1 != src.Find(L".jpg") || -1 != src.Find(L".png")) { // 这里改为不需要后缀,直接通过文件头判断是何图片类型
		bOpaque = true;
		GDIPlusDecoder(data);
	}

	SkMemoryStream* stream = data->m_data; // GDIPlusDecoder可能会更改m_data
	if (!stream)
		return NULL;

	bitmap = new SkBitmap();
	if (BMPImageReader::decode(false, stream, bitmap))
		return bitmap;
	
	delete bitmap;
	return 0;
#endif

#if 0 // 直接用skia的BMP解压器,会发现png转换而成的BMP32,会丢失alpha通道
	SkImageDecoder* coder = SkImageDecoder::Factory(stream);
	if (!coder) 
		return NULL;

	bitmap = new SkBitmap();

	if (!coder->decode(stream, bitmap, SkBitmap::kARGB_8888_Config, SkImageDecoder::kDecodePixels_Mode)) {
		delete bitmap;
		return NULL;
	}

	bitmap->setIsOpaque(bOpaque);
#endif
	return bitmap;
}
开发者ID:henryrao,项目名称:kdguigl,代码行数:45,代码来源:ResSkiaImage.cpp

示例11: stream

SkImageGenerator* SkImageGenerator::NewFromData(SkData* data) {
    if (NULL == data) {
        return NULL;
    }

    SkMemoryStream stream(data->data(), data->size(), false);
    SkImageDecoder* decoder = SkImageDecoder::Factory(&stream);
    if (NULL == decoder) {
        return NULL;
    }

    SkBitmap bm;
    stream.rewind();
    if (!decoder->decode(&stream, &bm, kUnknown_SkColorType, SkImageDecoder::kDecodeBounds_Mode)) {
        SkDELETE(decoder);
        return NULL;
    }

    return SkNEW_ARGS(SkImageDecoderGenerator, (bm.info(), decoder, data));
}
开发者ID:Ashu17,项目名称:blackberry,代码行数:20,代码来源:SkImageGenerator_skia.cpp

示例12: SubpixelTranslateView

 SubpixelTranslateView(const char imageFilename[],
                       float horizontalVelocity,
                       float verticalVelocity)
   : fHorizontalVelocity(horizontalVelocity),
     fVerticalVelocity(verticalVelocity) {
   SkString resourcePath = GetResourcePath(imageFilename);
   SkImageDecoder* codec = NULL;
   SkFILEStream stream(resourcePath.c_str());
   if (stream.isValid()) {
       codec = SkImageDecoder::Factory(&stream);
   }
   if (codec) {
       stream.rewind();
       codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
       delete codec;
   } else {
       fBM.allocN32Pixels(1, 1);
       *(fBM.getAddr32(0,0)) = 0xFF0000FF; // red == bad
   }
   fCurPos = SkPoint::Make(0,0);
   fSize = 200;
 }
开发者ID:webbjiang,项目名称:skia,代码行数:22,代码来源:SampleSubpixelTranslate.cpp

示例13: SkASSERT

bool SkImageDecoder::DecodeStream(SkStreamRewindable* stream, SkBitmap* bm, SkColorType pref,
                                  Mode mode, Format* format) {
    SkASSERT(stream);
    SkASSERT(bm);

    bool success = false;
    SkImageDecoder* codec = SkImageDecoder::Factory(stream);

    if (codec) {
        success = codec->decode(stream, bm, pref, mode) != kFailure;
        if (success && format) {
            *format = codec->getFormat();
            if (kUnknown_Format == *format) {
                if (stream->rewind()) {
                    *format = GetStreamFormat(stream);
                }
            }
        }
        delete codec;
    }
    return success;
}
开发者ID:johnkit,项目名称:skia,代码行数:22,代码来源:SkImageDecoder.cpp

示例14: decodeFile

static bool decodeFile(SkBitmap* bitmap, const char srcPath[]) {
    SkFILEStream stream(srcPath);
    if (!stream.isValid()) {
        SkDebugf("ERROR: bad filename <%s>\n", srcPath);
        return false;
    }

    SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
    if (NULL == codec) {
        SkDebugf("ERROR: no codec found for <%s>\n", srcPath);
        return false;
    }

    SkAutoTDelete<SkImageDecoder> ad(codec);

    stream.rewind();
    if (!codec->decode(&stream, bitmap, SkBitmap::kARGB_8888_Config,
                       SkImageDecoder::kDecodePixels_Mode)) {
        SkDebugf("ERROR: codec failed for <%s>\n", srcPath);
        return false;
    }
    return true;
}
开发者ID:Androtos,项目名称:toolchain_benchmark,代码行数:23,代码来源:skimage_main.cpp

示例15: decodeFileAndWrite

static void decodeFileAndWrite(const char srcPath[]) {
    SkBitmap bitmap;
    SkFILEStream stream(srcPath);
    if (!stream.isValid()) {
        return;
    }

    SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
    if (NULL == codec) {
        return;
    }

    SkAutoTDelete<SkImageDecoder> ad(codec);

    stream.rewind();

    if (!codec->decode(&stream, &bitmap, SkBitmap::kARGB_8888_Config,
                       SkImageDecoder::kDecodePixels_Mode)) {
        return;
    }

    write_bitmap(srcPath, bitmap);
}
开发者ID:andreicoman11,项目名称:OsmAnd-external-skia,代码行数:23,代码来源:chop_transparency_main.cpp


注:本文中的SkImageDecoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。