本文整理汇总了C++中SkImageDecoder::setSampleSize方法的典型用法代码示例。如果您正苦于以下问题:C++ SkImageDecoder::setSampleSize方法的具体用法?C++ SkImageDecoder::setSampleSize怎么用?C++ SkImageDecoder::setSampleSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkImageDecoder
的用法示例。
在下文中一共展示了SkImageDecoder::setSampleSize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: prepareBitmap
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;
}
示例2: prepareBitmap
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;
}
示例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: 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;
}
示例5: 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;
}
示例6: setData
void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
{
#ifdef ANDROID_ANIMATED_GIF
// This is only necessary if we allow ourselves to partially decode GIF
bool disabledAnimatedGif = false;
if (m_decoder.m_gifDecoder
&& !m_decoder.m_gifDecoder->failed()) {
m_decoder.m_gifDecoder->setData(data, allDataReceived);
if (!allDataReceived || m_decoder.m_gifDecoder->frameCount() != 1)
return;
disabledAnimatedGif = true;
delete m_decoder.m_gifDecoder;
m_decoder.m_gifDecoder = 0;
}
#endif
if (NULL == m_decoder.m_image
#ifdef ANDROID_ANIMATED_GIF
&& !m_decoder.m_gifDecoder
#endif
) {
SkBitmap tmp;
SkMemoryStream stream(data->data(), data->size(), false);
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
if (!codec)
return;
SkAutoTDelete<SkImageDecoder> ad(codec);
// FOR KITKAT MR2 INTEGRATION
//codec->setPrefConfigTable(gPrefConfigTable);
SkImageDecoder::PrefConfigTable configTable;
configTable.fPrefFor_8Index_NoAlpha_src = gPrefConfigTable[0];
configTable.fPrefFor_8Index_YesAlpha_src = gPrefConfigTable[1];
configTable.fPrefFor_8Gray_src = SkBitmap::kNo_Config;
configTable.fPrefFor_8bpc_NoAlpha_src = gPrefConfigTable[4];
configTable.fPrefFor_8bpc_YesAlpha_src = gPrefConfigTable[5];
codec->setPrefConfigTable(configTable);
// FOR KITKAT MR2 INTEGRATION
if (!codec->decode(&stream, &tmp, SkImageDecoder::kDecodeBounds_Mode))
return;
int origW = tmp.width();
int origH = tmp.height();
#ifdef ANDROID_ANIMATED_GIF
// First, check to see if this is an animated GIF
const char* contents = data->data();
if (data->size() > 3 && strncmp(contents, "GIF8", 4) == 0
&& should_use_animated_gif(origW, origH)
&& !disabledAnimatedGif) {
// This means we are looking at a GIF, so create special
// GIF Decoder
// Need to wait for all data received if we are assigning an
// allocator (which we are not at the moment).
if (!m_decoder.m_gifDecoder /*&& allDataReceived*/)
m_decoder.m_gifDecoder = new GIFImageDecoder(m_alphaOption, m_gammaAndColorProfileOption);
int frameCount = 0;
if (!m_decoder.m_gifDecoder->failed()) {
m_decoder.m_gifDecoder->setData(data, allDataReceived);
if (!allDataReceived)
return;
frameCount = m_decoder.m_gifDecoder->frameCount();
}
if (frameCount != 1)
return;
delete m_decoder.m_gifDecoder;
m_decoder.m_gifDecoder = 0;
}
#endif
int sampleSize = computeSampleSize(tmp);
if (sampleSize > 1) {
codec->setSampleSize(sampleSize);
stream.rewind();
if (!codec->decode(&stream, &tmp,
SkImageDecoder::kDecodeBounds_Mode)) {
return;
}
}
m_decoder.m_image = new PrivateAndroidImageSourceRec(tmp, origW, origH,
sampleSize);
// SkDebugf("----- started: [%d %d] %s\n", origW, origH, m_decoder.m_url.c_str());
}
PrivateAndroidImageSourceRec* decoder = m_decoder.m_image;
if (allDataReceived && decoder && !decoder->fAllDataReceived) {
decoder->fAllDataReceived = true;
SkBitmap* bm = &decoder->bitmap();
// 4.2 Merge BEGIN <<
//Following code removed in 4.2
// SkPixelRef* ref = convertToRLE(bm, data->data(), data->size()); //4.2 Merge : removed in 4.2
// if (ref) {
// bm->setPixelRef(ref)->unref();
// } else {
// 4.2 Merge END >>
//.........这里部分代码省略.........
示例7: decodeBuffer
SkBitmap* MpoDecoder::decodeBuffer(JNIEnv* env, jobject options,
SkStream* stream) {
int sampleSize = 1;
int preferSize = 0;
int postproc = 0;
int postprocflag = 0;
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
SkBitmap::Config prefConfig = SkBitmap::kNo_Config;
bool doDither = true;
bool isPurgeable = options != NULL &&
env->GetBooleanField(options, options_purgeableFieldID);
if (NULL != options) {
sampleSize = env->GetIntField(options, options_sampleSizeFieldID);
//preferSize = env->GetIntField(options, options_preferSizeFieldID);
//postproc = env->GetBooleanField(options, options_postprocFieldID);
//postprocflag = env->GetIntField(options, options_postprocflagFieldID);
if (env->GetBooleanField(options, options_justBoundsFieldID)) {
mode = SkImageDecoder::kDecodeBounds_Mode;
}
// initialize these, in case we fail later on
env->SetIntField(options, options_widthFieldID, -1);
env->SetIntField(options, options_heightFieldID, -1);
env->SetObjectField(options, options_mimeFieldID, 0);
jobject jconfig = env->GetObjectField(options, options_configFieldID);
prefConfig = GraphicsJNI::getNativeBitmapConfig(env, jconfig);
doDither = env->GetBooleanField(options, options_ditherFieldID);
}
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
if (NULL == decoder) {
XLOGE("SkImageDecoder-Factory() returned false");
return NULL;
}
decoder->setSampleSize(sampleSize);
decoder->setDitherImage(doDither);
//decoder->setPreferSize(preferSize);
//decoder->setPostProcFlag((postproc | (postprocflag << 4)));
// To fix the race condition in case "requestCancelDecode"
// happens earlier than AutoDecoderCancel object is added
// to the gAutoDecoderCancelMutex linked list.
if (NULL != options && env->GetBooleanField(options, options_mCancelID)) {
XLOGE("Decoding is cancelled by requestCancelDecode");
return NULL;
}
SkImageDecoder::Mode decodeMode = mode;
if (isPurgeable) {
decodeMode = SkImageDecoder::kDecodeBounds_Mode;
}
SkBitmap* bitmap = new SkBitmap;
if (!decoder->decode(stream, bitmap, prefConfig, decodeMode)) {
XLOGE("SkImageDecoder-decode() returned false");
return NULL;
}
// update options (if any)
if (NULL != options) {
env->SetIntField(options, options_widthFieldID, bitmap->width());
env->SetIntField(options, options_heightFieldID, bitmap->height());
// TODO: set the mimeType field with the data from the codec.
// but how to reuse a set of strings, rather than allocating new one
// each time?
env->SetObjectField(options, options_mimeFieldID,env->NewStringUTF("image/mpo"));
}
// if we're in justBounds mode, return now (skip the java bitmap)
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
delete bitmap;
return NULL;
} else {
return bitmap;
}
}
示例8: doDecode
// since we "may" create a purgeable imageref, we require the stream be ref'able
// i.e. dynamically allocated, since its lifetime may exceed the current stack
// frame.
static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding,
jobject options, bool allowPurgeable, bool forcePurgeable = false) {
int sampleSize = 1;
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
bool doDither = true;
bool isMutable = false;
float scale = 1.0f;
bool isPurgeable = forcePurgeable || (allowPurgeable && optionsPurgeable(env, options));
bool preferQualityOverSpeed = false;
bool requireUnpremultiplied = false;
jobject javaBitmap = NULL;
if (options != NULL) {
sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID);
if (optionsJustBounds(env, options)) {
mode = SkImageDecoder::kDecodeBounds_Mode;
}
// initialize these, in case we fail later on
env->SetIntField(options, gOptions_widthFieldID, -1);
env->SetIntField(options, gOptions_heightFieldID, -1);
env->SetObjectField(options, gOptions_mimeFieldID, 0);
jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
prefConfig = GraphicsJNI::getNativeBitmapConfig(env, jconfig);
isMutable = env->GetBooleanField(options, gOptions_mutableFieldID);
doDither = env->GetBooleanField(options, gOptions_ditherFieldID);
preferQualityOverSpeed = env->GetBooleanField(options,
gOptions_preferQualityOverSpeedFieldID);
requireUnpremultiplied = !env->GetBooleanField(options, gOptions_premultipliedFieldID);
javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID);
if (env->GetBooleanField(options, gOptions_scaledFieldID)) {
const int density = env->GetIntField(options, gOptions_densityFieldID);
const int targetDensity = env->GetIntField(options, gOptions_targetDensityFieldID);
const int screenDensity = env->GetIntField(options, gOptions_screenDensityFieldID);
if (density != 0 && targetDensity != 0 && density != screenDensity) {
scale = (float) targetDensity / density;
}
}
}
const bool willScale = scale != 1.0f;
isPurgeable &= !willScale;
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
if (decoder == NULL) {
return nullObjectReturn("SkImageDecoder::Factory returned null");
}
decoder->setSampleSize(sampleSize);
decoder->setDitherImage(doDither);
decoder->setPreferQualityOverSpeed(preferQualityOverSpeed);
decoder->setRequireUnpremultipliedColors(requireUnpremultiplied);
SkBitmap* outputBitmap = NULL;
unsigned int existingBufferSize = 0;
if (javaBitmap != NULL) {
outputBitmap = (SkBitmap*) env->GetIntField(javaBitmap, gBitmap_nativeBitmapFieldID);
if (outputBitmap->isImmutable()) {
ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
javaBitmap = NULL;
outputBitmap = NULL;
} else {
existingBufferSize = GraphicsJNI::getBitmapAllocationByteCount(env, javaBitmap);
}
}
SkAutoTDelete<SkBitmap> adb(outputBitmap == NULL ? new SkBitmap : NULL);
if (outputBitmap == NULL) outputBitmap = adb.get();
NinePatchPeeker peeker(decoder);
decoder->setPeeker(&peeker);
SkImageDecoder::Mode decodeMode = isPurgeable ? SkImageDecoder::kDecodeBounds_Mode : mode;
JavaPixelAllocator javaAllocator(env);
RecyclingPixelAllocator recyclingAllocator(outputBitmap->pixelRef(), existingBufferSize);
ScaleCheckingAllocator scaleCheckingAllocator(scale, existingBufferSize);
SkBitmap::Allocator* outputAllocator = (javaBitmap != NULL) ?
(SkBitmap::Allocator*)&recyclingAllocator : (SkBitmap::Allocator*)&javaAllocator;
if (decodeMode != SkImageDecoder::kDecodeBounds_Mode) {
if (!willScale) {
// If the java allocator is being used to allocate the pixel memory, the decoder
// need not write zeroes, since the memory is initialized to 0.
decoder->setSkipWritingZeroes(outputAllocator == &javaAllocator);
decoder->setAllocator(outputAllocator);
} else if (javaBitmap != NULL) {
// check for eventual scaled bounds at allocation time, so we don't decode the bitmap
// only to find the scaled result too large to fit in the allocation
decoder->setAllocator(&scaleCheckingAllocator);
}
//.........这里部分代码省略.........
示例9: doDecode
// since we "may" create a purgeable imageref, we require the stream be ref'able
// i.e. dynamically allocated, since its lifetime may exceed the current stack
// frame.
static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
jobject options, bool allowPurgeable, bool forcePurgeable = false,
bool applyScale = false, float scale = 1.0f) {
int sampleSize = 1;
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
bool doDither = true;
bool isMutable = false;
bool willScale = applyScale && scale != 1.0f;
bool isPurgeable = !willScale &&
(forcePurgeable || (allowPurgeable && optionsPurgeable(env, options)));
bool preferQualityOverSpeed = false;
jobject javaBitmap = NULL;
if (options != NULL) {
sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID);
if (optionsJustBounds(env, options)) {
mode = SkImageDecoder::kDecodeBounds_Mode;
}
// initialize these, in case we fail later on
env->SetIntField(options, gOptions_widthFieldID, -1);
env->SetIntField(options, gOptions_heightFieldID, -1);
env->SetObjectField(options, gOptions_mimeFieldID, 0);
jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
prefConfig = GraphicsJNI::getNativeBitmapConfig(env, jconfig);
isMutable = env->GetBooleanField(options, gOptions_mutableFieldID);
doDither = env->GetBooleanField(options, gOptions_ditherFieldID);
preferQualityOverSpeed = env->GetBooleanField(options,
gOptions_preferQualityOverSpeedFieldID);
javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID);
}
if (willScale && javaBitmap != NULL) {
return nullObjectReturn("Cannot pre-scale a reused bitmap");
}
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
if (decoder == NULL) {
return nullObjectReturn("SkImageDecoder::Factory returned null");
}
decoder->setSampleSize(sampleSize);
decoder->setDitherImage(doDither);
decoder->setPreferQualityOverSpeed(preferQualityOverSpeed);
NinePatchPeeker peeker(decoder);
JavaPixelAllocator javaAllocator(env);
SkBitmap* bitmap;
if (javaBitmap == NULL) {
bitmap = new SkBitmap;
} else {
if (sampleSize != 1) {
return nullObjectReturn("SkImageDecoder: Cannot reuse bitmap with sampleSize != 1");
}
bitmap = (SkBitmap*) env->GetIntField(javaBitmap, gBitmap_nativeBitmapFieldID);
// config of supplied bitmap overrules config set in options
prefConfig = bitmap->getConfig();
}
SkAutoTDelete<SkImageDecoder> add(decoder);
SkAutoTDelete<SkBitmap> adb(bitmap, javaBitmap == NULL);
decoder->setPeeker(&peeker);
if (!isPurgeable) {
decoder->setAllocator(&javaAllocator);
}
AutoDecoderCancel adc(options, decoder);
// To fix the race condition in case "requestCancelDecode"
// happens earlier than AutoDecoderCancel object is added
// to the gAutoDecoderCancelMutex linked list.
if (options != NULL && env->GetBooleanField(options, gOptions_mCancelID)) {
return nullObjectReturn("gOptions_mCancelID");
}
SkImageDecoder::Mode decodeMode = mode;
if (isPurgeable) {
decodeMode = SkImageDecoder::kDecodeBounds_Mode;
}
SkBitmap* decoded;
if (willScale) {
decoded = new SkBitmap;
} else {
decoded = bitmap;
}
SkAutoTDelete<SkBitmap> adb2(willScale ? decoded : NULL);
if (!decoder->decode(stream, decoded, prefConfig, decodeMode, javaBitmap != NULL)) {
//.........这里部分代码省略.........
示例10: doDecode
// since we "may" create a purgeable imageref, we require the stream be ref'able
// i.e. dynamically allocated, since its lifetime may exceed the current stack
// frame.
static jobject doDecode(JNIEnv* env, SkStream* stream, jobject padding,
jobject options, bool allowPurgeable,
bool forcePurgeable = false) {
int sampleSize = 1;
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
SkBitmap::Config prefConfig = SkBitmap::kNo_Config;
bool doDither = true;
bool isPurgeable = forcePurgeable ||
(allowPurgeable && optionsPurgeable(env, options));
bool reportSizeToVM = optionsReportSizeToVM(env, options);
bool preferQualityOverSpeed = false;
if (NULL != options) {
sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID);
if (env->GetBooleanField(options, gOptions_justBoundsFieldID)) {
mode = SkImageDecoder::kDecodeBounds_Mode;
}
// initialize these, in case we fail later on
env->SetIntField(options, gOptions_widthFieldID, -1);
env->SetIntField(options, gOptions_heightFieldID, -1);
env->SetObjectField(options, gOptions_mimeFieldID, 0);
jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
prefConfig = GraphicsJNI::getNativeBitmapConfig(env, jconfig);
doDither = env->GetBooleanField(options, gOptions_ditherFieldID);
preferQualityOverSpeed = env->GetBooleanField(options,
gOptions_preferQualityOverSpeedFieldID);
}
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
if (NULL == decoder) {
return nullObjectReturn("SkImageDecoder::Factory returned null");
}
decoder->setSampleSize(sampleSize);
decoder->setDitherImage(doDither);
decoder->setPreferQualityOverSpeed(preferQualityOverSpeed);
NinePatchPeeker peeker(decoder);
JavaPixelAllocator javaAllocator(env, reportSizeToVM);
SkBitmap* bitmap = new SkBitmap;
Res_png_9patch dummy9Patch;
SkAutoTDelete<SkImageDecoder> add(decoder);
SkAutoTDelete<SkBitmap> adb(bitmap);
decoder->setPeeker(&peeker);
if (!isPurgeable) {
decoder->setAllocator(&javaAllocator);
}
AutoDecoderCancel adc(options, decoder);
// To fix the race condition in case "requestCancelDecode"
// happens earlier than AutoDecoderCancel object is added
// to the gAutoDecoderCancelMutex linked list.
if (NULL != options && env->GetBooleanField(options, gOptions_mCancelID)) {
return nullObjectReturn("gOptions_mCancelID");;
}
SkImageDecoder::Mode decodeMode = mode;
if (isPurgeable) {
decodeMode = SkImageDecoder::kDecodeBounds_Mode;
}
if (!decoder->decode(stream, bitmap, prefConfig, decodeMode)) {
return nullObjectReturn("decoder->decode returned false");
}
// update options (if any)
if (NULL != options) {
env->SetIntField(options, gOptions_widthFieldID, bitmap->width());
env->SetIntField(options, gOptions_heightFieldID, bitmap->height());
// TODO: set the mimeType field with the data from the codec.
// but how to reuse a set of strings, rather than allocating new one
// each time?
env->SetObjectField(options, gOptions_mimeFieldID,
getMimeTypeString(env, decoder->getFormat()));
}
// if we're in justBounds mode, return now (skip the java bitmap)
if (SkImageDecoder::kDecodeBounds_Mode == mode) {
return NULL;
}
jbyteArray ninePatchChunk = NULL;
if (peeker.fPatchIsValid) {
size_t ninePatchArraySize = peeker.fPatch->serializedSize();
ninePatchChunk = env->NewByteArray(ninePatchArraySize);
if (NULL == ninePatchChunk) {
return nullObjectReturn("ninePatchChunk == null");
}
jbyte* array = (jbyte*)env->GetPrimitiveArrayCritical(ninePatchChunk,
NULL);
if (NULL == array) {
return nullObjectReturn("primitive array == null");
}
peeker.fPatch->serialize(array);
//.........这里部分代码省略.........
示例11: setData
void ImageSource::setData(SharedBuffer* data, bool allDataReceived)
{
#ifdef ANDROID_ANIMATED_GIF
// This is only necessary if we allow ourselves to partially decode GIF
if (m_decoder.m_gifDecoder
&& !m_decoder.m_gifDecoder->failed()) {
m_decoder.m_gifDecoder->setData(data, allDataReceived);
return;
}
#endif
if (NULL == m_decoder.m_image
#ifdef ANDROID_ANIMATED_GIF
&& !m_decoder.m_gifDecoder
#endif
) {
SkBitmap tmp;
SkMemoryStream stream(data->data(), data->size(), false);
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
SkAutoTDelete<SkImageDecoder> ad(codec);
if (!codec || !codec->decode(&stream, &tmp, SkBitmap::kNo_Config,
SkImageDecoder::kDecodeBounds_Mode)) {
return;
}
int origW = tmp.width();
int origH = tmp.height();
#ifdef ANDROID_ANIMATED_GIF
// First, check to see if this is an animated GIF
const Vector<char>& buffer = data->buffer();
const char* contents = buffer.data();
if (buffer.size() > 3 && strncmp(contents, "GIF8", 4) == 0 &&
should_use_animated_gif(origW, origH)) {
// This means we are looking at a GIF, so create special
// GIF Decoder
// Need to wait for all data received if we are assigning an
// allocator (which we are not at the moment).
if (!m_decoder.m_gifDecoder /*&& allDataReceived*/)
m_decoder.m_gifDecoder = new GIFImageDecoder();
if (!m_decoder.m_gifDecoder->failed())
m_decoder.m_gifDecoder->setData(data, allDataReceived);
return;
}
#endif
int sampleSize = computeSampleSize(tmp);
if (sampleSize > 1) {
codec->setSampleSize(sampleSize);
stream.rewind();
if (!codec->decode(&stream, &tmp, SkBitmap::kNo_Config,
SkImageDecoder::kDecodeBounds_Mode)) {
return;
}
}
m_decoder.m_image = new PrivateAndroidImageSourceRec(tmp, origW, origH,
sampleSize);
// SkDebugf("----- started: [%d %d] %s\n", origW, origH, m_decoder.m_url.c_str());
}
PrivateAndroidImageSourceRec* decoder = m_decoder.m_image;
if (allDataReceived && !decoder->fAllDataReceived) {
decoder->fAllDataReceived = true;
SkBitmap* bm = &decoder->bitmap();
SkPixelRef* ref = convertToRLE(bm, data->data(), data->size());
if (ref) {
bm->setPixelRef(ref)->unref();
} else {
BitmapAllocatorAndroid alloc(data, decoder->fSampleSize);
if (!alloc.allocPixelRef(bm, NULL)) {
return;
}
ref = bm->pixelRef();
}
// we promise to never change the pixels (makes picture recording fast)
ref->setImmutable();
// give it the URL if we have one
ref->setURI(m_decoder.m_url);
}
}
示例12: doDecode
static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding, jobject options) {
int sampleSize = 1;
int preferSize = 0;
int postproc = 0;
int postprocflag = 0;
#ifdef MTK_IMAGE_DC_SUPPORT
void* dc;
bool dcflag = false;
jint* pdynamicCon = NULL;
jintArray dynamicCon;
jsize size = 0;
#endif
SkImageDecoder::Mode decodeMode = SkImageDecoder::kDecodePixels_Mode;
SkColorType prefColorType = kN32_SkColorType;
bool doDither = true;
bool isMutable = false;
float scale = 1.0f;
bool preferQualityOverSpeed = false;
bool requireUnpremultiplied = false;
jobject javaBitmap = NULL;
if (options != NULL) {
sampleSize = env->GetIntField(options, gOptions_sampleSizeFieldID);
if (optionsJustBounds(env, options)) {
decodeMode = SkImageDecoder::kDecodeBounds_Mode;
}
// initialize these, in case we fail later on
env->SetIntField(options, gOptions_widthFieldID, -1);
env->SetIntField(options, gOptions_heightFieldID, -1);
env->SetObjectField(options, gOptions_mimeFieldID, 0);
jobject jconfig = env->GetObjectField(options, gOptions_configFieldID);
prefColorType = GraphicsJNI::getNativeBitmapColorType(env, jconfig);
isMutable = env->GetBooleanField(options, gOptions_mutableFieldID);
doDither = env->GetBooleanField(options, gOptions_ditherFieldID);
preferQualityOverSpeed = env->GetBooleanField(options,
gOptions_preferQualityOverSpeedFieldID);
requireUnpremultiplied = !env->GetBooleanField(options, gOptions_premultipliedFieldID);
javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID);
postproc = env->GetBooleanField(options, gOptions_postprocFieldID);
postprocflag = env->GetIntField(options, gOptions_postprocflagFieldID);
#ifdef MTK_IMAGE_DC_SUPPORT
dcflag = env->GetBooleanField(options, gOptions_dynamicConflagFieldID);
dynamicCon = (jintArray)env->GetObjectField(options, gOptions_dynamicConFieldID);
//pdynamicCon = (unsigned int*)env->GetIntArrayElements(dynamicCon, 0);
pdynamicCon = env->GetIntArrayElements(dynamicCon, NULL);
size = env->GetArrayLength(dynamicCon);
//for (int i=0; i<size; i++)
//{
//ALOGD("pdynamicCon[%d]=%d", i, pdynamicCon[i]);
//}
//ALOGD("BitmapFactory.cpp postproc=%d, postprocflag=%d", postproc, postprocflag);
//ALOGD("BitmapFactory.cpp dcflag=%d", dcflag);
//ALOGD("BitmapFactory.cpp dynamicCon=%p", dynamicCon);
//ALOGD("BitmapFactory.cpp size=%d", size);
#endif
if (env->GetBooleanField(options, gOptions_scaledFieldID)) {
const int density = env->GetIntField(options, gOptions_densityFieldID);
const int targetDensity = env->GetIntField(options, gOptions_targetDensityFieldID);
const int screenDensity = env->GetIntField(options, gOptions_screenDensityFieldID);
if (density != 0 && targetDensity != 0 && density != screenDensity) {
scale = (float) targetDensity / density;
}
}
}
const bool willScale = scale != 1.0f;
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
if (decoder == NULL) {
return nullObjectReturn("SkImageDecoder::Factory returned null");
}
decoder->setSampleSize(sampleSize);
decoder->setDitherImage(doDither);
decoder->setPreferQualityOverSpeed(preferQualityOverSpeed);
decoder->setRequireUnpremultipliedColors(requireUnpremultiplied);
decoder->setPreferSize(preferSize);
decoder->setPostProcFlag((postproc | (postprocflag << 4)));
#ifdef MTK_IMAGE_DC_SUPPORT
if (dcflag == true) {
dc= (void*)pdynamicCon;
int len = (int)size;
decoder->setDynamicCon(dc, len);
} else {
dc = NULL;
decoder->setDynamicCon(dc, 0);
}
// (env)->ReleaseIntArrayElements(dynamicCon, pdynamicCon, 0);
#endif
//.........这里部分代码省略.........