本文整理汇总了C++中SkImageDecoder::decode方法的典型用法代码示例。如果您正苦于以下问题:C++ SkImageDecoder::decode方法的具体用法?C++ SkImageDecoder::decode怎么用?C++ SkImageDecoder::decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkImageDecoder
的用法示例。
在下文中一共展示了SkImageDecoder::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stream
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;
}
示例2: stream
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);
}
}
}
示例3: decodeBounds
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;
}
示例4: DecodeStream
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;
}
示例5: 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
}
}
示例6: 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();
}
示例7: ImageDataToSkBitmap
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;
}
示例8: decodeAsset
bool RenderSkinNinePatch::decodeAsset(AssetManager* am, const char* filename, NinePatch* ninepatch) {
Asset* asset = am->open(filename, android::Asset::ACCESS_BUFFER);
if (!asset) {
asset = am->openNonAsset(filename, android::Asset::ACCESS_BUFFER);
if (!asset) {
return false;
}
}
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
SkBitmap::Config prefConfig = SkBitmap::kNo_Config;
SkMemoryStream stream(asset->getBuffer(false), asset->getLength());
SkImageDecoder* decoder = SkImageDecoder::Factory(&stream);
if (!decoder) {
asset->close();
ALOGE("RenderSkinNinePatch::Failed to create an image decoder");
return false;
}
decoder->setSampleSize(1);
decoder->setDitherImage(true);
decoder->setPreferQualityOverSpeed(false);
NinePatchPeeker peeker(decoder);
SkAutoTDelete<SkImageDecoder> add(decoder);
decoder->setPeeker(&peeker);
if (!decoder->decode(&stream, &ninepatch->m_bitmap, prefConfig, mode, true)) {
asset->close();
ALOGE("RenderSkinNinePatch::Failed to decode nine patch asset");
return false;
}
asset->close();
if (!peeker.fPatch) {
ALOGE("RenderSkinNinePatch::Patch data not valid");
return false;
}
void** data = &ninepatch->m_serializedPatchData;
*data = malloc(peeker.fPatch->serializedSize());
peeker.fPatch->serialize(*data);
return true;
}
示例9: NewFromData
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));
}
示例10: DecodeStream
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;
}
示例11: stream
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;
}
示例12: 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);
}
示例13: 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;
}
示例14: get_bitmap
bool get_bitmap(SkData* fileBits, DiffResource& resource, SkImageDecoder::Mode mode) {
SkMemoryStream stream(fileBits->data(), fileBits->size());
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
if (NULL == codec) {
SkDebugf("ERROR: no codec found for <%s>\n", resource.fFullPath.c_str());
resource.fStatus = DiffResource::kCouldNotDecode_Status;
return false;
}
// In debug, the DLL will automatically be unloaded when this is deleted,
// but that shouldn't be a problem in release mode.
SkAutoTDelete<SkImageDecoder> ad(codec);
stream.rewind();
if (!codec->decode(&stream, &resource.fBitmap, SkBitmap::kARGB_8888_Config, mode)) {
SkDebugf("ERROR: codec failed for basePath <%s>\n", resource.fFullPath.c_str());
resource.fStatus = DiffResource::kCouldNotDecode_Status;
return false;
}
resource.fStatus = DiffResource::kDecoded_Status;
return true;
}
示例15: add
BitmapGlue*
BitmapFactoryGlue::doDecode(SkStream* stream, Options& options,
bool allowPurgeable, bool forcePurgeable)
{
int sampleSize = 1;
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
bool doDither = true;
bool isMutable = false;
bool isPurgeable = forcePurgeable || (allowPurgeable && options.isPurgeable);
BitmapGlue* javaBitmap = NULL;
sampleSize = options.sampleSize;
if (options.justDecodeBounds)
mode = SkImageDecoder::kDecodeBounds_Mode;
// initialize these, in case we fail later on
options.width = -1;
options.height = -1;
prefConfig = options.config;
isMutable = options.isMutable;
doDither = options.doDither;
javaBitmap = options.bitmap;
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
if (NULL == decoder)
return NULL;
decoder->setSampleSize(sampleSize);
decoder->setDitherImage(doDither);
BitmapGlue* bitmap;
if (javaBitmap == NULL) {
bitmap = new BitmapGlue;
} else {
if (sampleSize != 1) {
return NULL;
}
bitmap = javaBitmap;
// config of supplied bitmap overrules config set in options
prefConfig = bitmap->getConfig();
}
SkAutoTDelete<SkImageDecoder> add(decoder);
SkAutoTDelete<SkBitmap> adb(bitmap, (javaBitmap == NULL));
SkImageDecoder::Mode decodeMode = mode;
if (isPurgeable) {
decodeMode = SkImageDecoder::kDecodeBounds_Mode;
}
if (!decoder->decode(stream, bitmap, prefConfig, decodeMode))
return NULL;
// update options (if any)
options.width = bitmap->width();
options.height = bitmap->height();
// if we're in justBounds mode, return now (skip the java bitmap)
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return NULL;
}
// detach bitmap from its autodeleter, since we want to own it now
adb.detach();
SkPixelRef* pr;
if (isPurgeable) {
pr = installPixelRef(bitmap, stream, sampleSize, doDither);
} else {
// if we get here, we're in kDecodePixels_Mode and will therefore
// already have a pixelref installed.
pr = bitmap->pixelRef();
}
if (!isMutable) {
// promise we will never change our pixels (great for sharing and pictures)
pr->setImmutable();
}
if (javaBitmap != NULL) {
// If a java bitmap was passed in for reuse, pass it back
return javaBitmap;
}
// now create the java bitmap
return bitmap;
}