本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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
}
}
示例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();
}
示例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;
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}