本文整理汇总了C++中SkBitmap::getConfig方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::getConfig方法的具体用法?C++ SkBitmap::getConfig怎么用?C++ SkBitmap::getConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::getConfig方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MaybeUnlock
void
SourceSurfaceSkia::DrawTargetWillChange()
{
if (mDrawTarget) {
MaybeUnlock();
mDrawTarget = nullptr;
SkBitmap temp = mBitmap;
mBitmap.reset();
temp.copyTo(&mBitmap, temp.getConfig());
}
}
示例2: setContext
bool SkShader::setContext(const SkBitmap& device,
const SkPaint& paint,
const SkMatrix& matrix) {
SkASSERT(!this->setContextHasBeenCalled());
const SkMatrix* m = &matrix;
SkMatrix total;
fDeviceConfig = SkToU8(device.getConfig());
fPaintAlpha = paint.getAlpha();
if (this->hasLocalMatrix()) {
total.setConcat(matrix, this->getLocalMatrix());
m = &total;
}
if (m->invert(&fTotalInverse)) {
fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse);
SkDEBUGCODE(fInSetContext = true;)
return true;
示例3: setContext
bool SkShader::setContext(const SkBitmap& device,
const SkPaint& paint,
const SkMatrix& matrix) {
const SkMatrix* m = &matrix;
SkMatrix total;
fDeviceConfig = SkToU8(device.getConfig());
fPaintAlpha = paint.getAlpha();
if (fLocalMatrix) {
total.setConcat(matrix, *fLocalMatrix);
m = &total;
}
if (m->invert(&fTotalInverse)) {
fTotalInverseClass = (uint8_t)ComputeMatrixClass(fTotalInverse);
return true;
}
return false;
}
示例4: IntSize
bool
SourceSurfaceSkia::InitWithBitmap(const SkBitmap& aBitmap,
SurfaceFormat aFormat,
DrawTargetSkia* aOwner)
{
mFormat = aFormat;
mSize = IntSize(aBitmap.width(), aBitmap.height());
if (aOwner) {
mBitmap = aBitmap;
mStride = aBitmap.rowBytes();
mDrawTarget = aOwner;
return true;
} else if (aBitmap.copyTo(&mBitmap, aBitmap.getConfig())) {
mStride = mBitmap.rowBytes();
return true;
}
return false;
}
示例5: onEncode
/* Encode bitmaps via CGImageDestination. We setup a DataConsumer which writes
to our SkWStream. Since we don't reference/own the SkWStream, our consumer
must only live for the duration of the onEncode() method.
*/
bool SkImageEncoder_CG::onEncode(SkWStream* stream, const SkBitmap& bm,
int quality) {
// Used for converting a bitmap to 8888.
const SkBitmap* bmPtr = &bm;
SkBitmap bitmap8888;
CFStringRef type;
switch (fType) {
case kJPEG_Type:
type = kUTTypeJPEG;
break;
case kPNG_Type:
// PNG encoding an ARGB_4444 bitmap gives the following errors in GM:
// <Error>: CGImageDestinationAddImage image could not be converted to destination
// format.
// <Error>: CGImageDestinationFinalize image destination does not have enough images
// So instead we copy to 8888.
if (bm.getConfig() == SkBitmap::kARGB_4444_Config) {
bm.copyTo(&bitmap8888, SkBitmap::kARGB_8888_Config);
bmPtr = &bitmap8888;
}
type = kUTTypePNG;
break;
default:
return false;
}
CGImageDestinationRef dst = SkStreamToImageDestination(stream, type);
if (NULL == dst) {
return false;
}
SkAutoTCallVProc<const void, CFRelease> ardst(dst);
CGImageRef image = SkCreateCGImageRef(*bmPtr);
if (NULL == image) {
return false;
}
SkAutoTCallVProc<CGImage, CGImageRelease> agimage(image);
CGImageDestinationAddImage(dst, image, NULL);
return CGImageDestinationFinalize(dst);
}
示例6: updateTextureWithBitmap
void GLUtils::updateTextureWithBitmap(GLuint texture, int x, int y, const SkBitmap& bitmap, GLint filter)
{
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, texture);
GLUtils::checkGlError("glBindTexture");
SkBitmap::Config config = bitmap.getConfig();
int internalformat = getInternalFormat(config);
int type = getType(config);
bitmap.lockPixels();
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, bitmap.width(), bitmap.height(),
internalformat, type, bitmap.getPixels());
bitmap.unlockPixels();
if (GLUtils::checkGlError("glTexSubImage2D")) {
XLOG("GL ERROR: glTexSubImage2D parameters are : bitmap.width() %d, bitmap.height() %d,"
" x %d, y %d, internalformat 0x%x, type 0x%x, bitmap.getPixels() %p",
bitmap.width(), bitmap.height(), x, y, internalformat, type, bitmap.getPixels());
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
}
示例7: getColor
static bool getColor(const SkBitmap& bitmap, int x, int y, SkColor* c) {
switch (bitmap.getConfig()) {
case SkBitmap::kARGB_8888_Config:
*c = SkUnPreMultiply::PMColorToColor(*bitmap.getAddr32(x, y));
break;
case SkBitmap::kRGB_565_Config:
*c = SkPixel16ToPixel32(*bitmap.getAddr16(x, y));
break;
case SkBitmap::kARGB_4444_Config:
*c = SkUnPreMultiply::PMColorToColor(
SkPixel4444ToPixel32(*bitmap.getAddr16(x, y)));
break;
case SkBitmap::kIndex8_Config: {
SkColorTable* ctable = bitmap.getColorTable();
*c = SkUnPreMultiply::PMColorToColor(
(*ctable)[*bitmap.getAddr8(x, y)]);
break;
}
default:
return false;
}
return true;
}
示例8: initTexture
status_t BootAnimation::initTexture(const Animation::Frame& frame)
{
//StopWatch watch("blah");
SkBitmap bitmap;
SkMemoryStream stream(frame.map->getDataPtr(), frame.map->getDataLength());
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
if (codec) {
codec->setDitherImage(false);
codec->decode(&stream, &bitmap,
SkBitmap::kARGB_8888_Config,
SkImageDecoder::kDecodePixels_Mode);
delete codec;
}
// FileMap memory is never released until application exit.
// Release it now as the texture is already loaded and the memory used for
// the packed resource can be released.
frame.map->release();
// ensure we can call getPixels(). No need to call unlock, since the
// bitmap will go out of scope when we return from this method.
bitmap.lockPixels();
const int w = bitmap.width();
const int h = bitmap.height();
const void* p = bitmap.getPixels();
GLint crop[4] = { 0, h, w, -h };
int tw = 1 << (31 - __builtin_clz(w));
int th = 1 << (31 - __builtin_clz(h));
if (tw < w) tw <<= 1;
if (th < h) th <<= 1;
switch (bitmap.getConfig()) {
case SkBitmap::kARGB_8888_Config:
if (tw != w || th != h) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
GL_UNSIGNED_BYTE, 0);
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p);
} else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
GL_UNSIGNED_BYTE, p);
}
break;
case SkBitmap::kRGB_565_Config:
if (tw != w || th != h) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, 0);
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p);
} else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, p);
}
break;
default:
break;
}
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
return NO_ERROR;
}
示例9: initTexture
status_t BootAnimation::initTexture(void* buffer, size_t len)
{
//StopWatch watch("blah");
SkBitmap bitmap;
SkMemoryStream stream(buffer, len);
SkImageDecoder* codec = SkImageDecoder::Factory(&stream);
codec->setDitherImage(false);
if (codec) {
codec->decode(&stream, &bitmap,
SkBitmap::kRGB_565_Config,
SkImageDecoder::kDecodePixels_Mode);
delete codec;
}
// ensure we can call getPixels(). No need to call unlock, since the
// bitmap will go out of scope when we return from this method.
bitmap.lockPixels();
const int w = bitmap.width();
const int h = bitmap.height();
const void* p = bitmap.getPixels();
GLint crop[4] = { 0, h, w, -h };
int tw = 1 << (31 - __builtin_clz(w));
int th = 1 << (31 - __builtin_clz(h));
if (tw < w) tw <<= 1;
if (th < h) th <<= 1;
switch (bitmap.getConfig()) {
case SkBitmap::kARGB_8888_Config:
if (tw != w || th != h) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
GL_UNSIGNED_BYTE, 0);
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p);
} else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA,
GL_UNSIGNED_BYTE, p);
}
break;
case SkBitmap::kRGB_565_Config:
if (tw != w || th != h) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, 0);
glTexSubImage2D(GL_TEXTURE_2D, 0,
0, 0, w, h, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, p);
} else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tw, th, 0, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, p);
}
break;
default:
break;
}
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop);
return NO_ERROR;
}
示例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,
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)) {
//.........这里部分代码省略.........
示例11: 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;
int preferSize = 0;
int postproc = 0;
int postprocflag = 0;
SkImageDecoder::Mode mode = SkImageDecoder::kDecodePixels_Mode;
SkBitmap::Config prefConfig = SkBitmap::kARGB_8888_Config;
bool doDither = true;
bool isMutable = false;
bool isPurgeable = forcePurgeable ||
(allowPurgeable && optionsPurgeable(env, options));
bool preferQualityOverSpeed = false;
jobject javaBitmap = NULL;
if (NULL != options) {
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);
postproc = env->GetBooleanField(options, gOptions_postprocFieldID);
postprocflag = env->GetIntField(options, gOptions_postprocflagFieldID);
javaBitmap = env->GetObjectField(options, gOptions_bitmapFieldID);
}
SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
if (NULL == decoder) {
return nullObjectReturn("SkImageDecoder::Factory returned null");
}
decoder->setSampleSize(sampleSize);
decoder->setDitherImage(doDither);
decoder->setPreferQualityOverSpeed(preferQualityOverSpeed);
decoder->setPreferSize(preferSize);
decoder->setPostProcFlag((postproc | (postprocflag << 4)));
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();
}
Res_png_9patch dummy9Patch;
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 (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, javaBitmap != NULL)) {
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?
//.........这里部分代码省略.........
示例12: image_data_unref
SkPDFImage::SkPDFImage(const SkBitmap& bitmap, const SkPaint& paint) {
SkBitmap::Config config = bitmap.getConfig();
// TODO(vandebo) Handle alpha and alpha only images correctly.
SkASSERT(config == SkBitmap::kRGB_565_Config ||
config == SkBitmap::kARGB_4444_Config ||
config == SkBitmap::kARGB_8888_Config ||
config == SkBitmap::kIndex8_Config ||
config == SkBitmap::kRLE_Index8_Config);
SkMemoryStream* image_data = extractImageData(bitmap);
SkAutoUnref image_data_unref(image_data);
fStream = new SkPDFStream(image_data);
fStream->unref(); // SkRefPtr and new both took a reference.
SkRefPtr<SkPDFName> typeValue = new SkPDFName("XObject");
typeValue->unref(); // SkRefPtr and new both took a reference.
insert("Type", typeValue.get());
SkRefPtr<SkPDFName> subTypeValue = new SkPDFName("Image");
subTypeValue->unref(); // SkRefPtr and new both took a reference.
insert("Subtype", subTypeValue.get());
SkRefPtr<SkPDFInt> widthValue = new SkPDFInt(bitmap.width());
widthValue->unref(); // SkRefPtr and new both took a reference.
insert("Width", widthValue.get());
SkRefPtr<SkPDFInt> heightValue = new SkPDFInt(bitmap.height());
heightValue->unref(); // SkRefPtr and new both took a reference.
insert("Height", heightValue.get());
// if (!image mask) {
SkRefPtr<SkPDFObject> colorSpaceValue;
if (config == SkBitmap::kIndex8_Config ||
config == SkBitmap::kRLE_Index8_Config) {
colorSpaceValue = makeIndexedColorSpace(bitmap.getColorTable());
} else {
colorSpaceValue = new SkPDFName("DeviceRGB");
}
colorSpaceValue->unref(); // SkRefPtr and new both took a reference.
insert("ColorSpace", colorSpaceValue.get());
// }
int bitsPerComp = bitmap.bytesPerPixel() * 2;
if (bitsPerComp == 0) {
SkASSERT(config == SkBitmap::kA1_Config);
bitsPerComp = 1;
} else if (bitsPerComp == 2 ||
(bitsPerComp == 4 && config == SkBitmap::kRGB_565_Config)) {
bitsPerComp = 8;
}
SkRefPtr<SkPDFInt> bitsPerCompValue = new SkPDFInt(bitsPerComp);
bitsPerCompValue->unref(); // SkRefPtr and new both took a reference.
insert("BitsPerComponent", bitsPerCompValue.get());
if (config == SkBitmap::kRGB_565_Config) {
SkRefPtr<SkPDFInt> zeroVal = new SkPDFInt(0);
zeroVal->unref(); // SkRefPtr and new both took a reference.
SkRefPtr<SkPDFScalar> scale5Val = new SkPDFScalar(8.2258); // 255/2^5-1
scale5Val->unref(); // SkRefPtr and new both took a reference.
SkRefPtr<SkPDFScalar> scale6Val = new SkPDFScalar(4.0476); // 255/2^6-1
scale6Val->unref(); // SkRefPtr and new both took a reference.
SkRefPtr<SkPDFArray> decodeValue = new SkPDFArray();
decodeValue->unref(); // SkRefPtr and new both took a reference.
decodeValue->reserve(6);
decodeValue->append(zeroVal.get());
decodeValue->append(scale5Val.get());
decodeValue->append(zeroVal.get());
decodeValue->append(scale6Val.get());
decodeValue->append(zeroVal.get());
decodeValue->append(scale5Val.get());
insert("Decode", decodeValue.get());
}
}