本文整理汇总了C++中SkBitmap::bytesPerPixel方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::bytesPerPixel方法的具体用法?C++ SkBitmap::bytesPerPixel怎么用?C++ SkBitmap::bytesPerPixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::bytesPerPixel方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convertBitmapToXImage
static bool convertBitmapToXImage(XImage& image, const SkBitmap& bitmap) {
sk_bzero(&image, sizeof(image));
int bitsPerPixel = bitmap.bytesPerPixel() * 8;
image.width = bitmap.width();
image.height = bitmap.height();
image.format = ZPixmap;
image.data = (char*) bitmap.getPixels();
image.byte_order = LSBFirst;
image.bitmap_unit = bitsPerPixel;
image.bitmap_bit_order = LSBFirst;
image.bitmap_pad = bitsPerPixel;
image.depth = 24;
image.bytes_per_line = bitmap.rowBytes() - bitmap.width() * bitmap.bytesPerPixel();
image.bits_per_pixel = bitsPerPixel;
return XInitImage(&image);
}
示例2: printf
status_t s3d_image_tnb_test(void)
{
printf("[Unit Test] SurfaceFlinger 3D display test !\n\n");
sp<SurfaceComposerClient> client;
//sp<SurfaceControl> c;
sp<Surface> s;
Surface::SurfaceInfo i;
SkBitmap tab;
// ready the png image file
if (false == SkImageDecoder::DecodeFile("/data/3D_TAB.png", &tab)) {
printf("fail load file");
return INVALID_OPERATION;
}
// create layer env
client = new SurfaceComposerClient();
printf("*** top and bottom test ...\n");
c = client->createSurface(
String8("test-S3D_background"),
0,
DRAW_FHD_W,
DRAW_FHD_H,
PIXEL_FORMAT_RGBA_8888,
ISurfaceComposer::eFXSurfaceDim & ISurfaceComposer::eFXSurfaceMask);
u = client->createSurface(String8("test-S3D_image1"), 0, tab.width(), tab.height(), PIXEL_FORMAT_RGBA_8888);
client->openGlobalTransaction();
{
c->setLayer(200000);
c->setPosition(0, 0);
c->setAlpha(1.0f); // black background
u->setLayer(240000);
u->setPosition(0, 0);
}
client->closeGlobalTransaction();
printf(" set to TAB mode\n");
client->openGlobalTransaction();
{
u->setFlags(ISurfaceComposer::eLayerTopAndBottom, ISurfaceComposer::eLayerS3DMask);
}
client->closeGlobalTransaction();
s = u->getSurface();
s->lock(&i);
{
memcpy(i.bits, tab.getPixels(), tab.width() * tab.height() * tab.bytesPerPixel());
}
s->unlockAndPost();
sleep(1);
client->dispose();
return NO_ERROR;
}
示例3: uploadLoFiTexture
void TextureCache::uploadLoFiTexture(bool resize, const SkBitmap* bitmap,
uint32_t width, uint32_t height) {
SkBitmap rgbaBitmap;
rgbaBitmap.allocPixels(SkImageInfo::MakeN32(width, height, bitmap->alphaType()));
rgbaBitmap.eraseColor(0);
SkCanvas canvas(rgbaBitmap);
canvas.drawBitmap(*bitmap, 0.0f, 0.0f, nullptr);
uploadToTexture(resize, GL_RGBA, rgbaBitmap.rowBytesAsPixels(), rgbaBitmap.bytesPerPixel(),
width, height, GL_UNSIGNED_BYTE, rgbaBitmap.getPixels());
}
示例4: initWithString
bool CCImage::initWithString(
const char * pText,
int nWidth/* = 0*/,
int nHeight/* = 0*/,
ETextAlign eAlignMask/* = kAlignCenter*/,
const char * pFontName/* = nil*/,
int nSize/* = 0*/)
{
bool bRet = false;
do
{
CC_BREAK_IF(! pText);
BitmapDC &dc = sharedBitmapDC();
/* init font with font name and size */
CC_BREAK_IF(! dc.setFont(pFontName, nSize));
/* compute text width and height */
if (nWidth <= 0 || nHeight <= 0)
{
dc.getTextExtentPoint(pText, &nWidth, &nHeight);
}
CC_BREAK_IF(nWidth <= 0 || nHeight <= 0);
bRet = dc.drawText(pText, nWidth, nHeight, eAlignMask);
/*init image information */
SkBitmap *pBitmap = dc.getBitmap();
CC_BREAK_IF(! pBitmap);
int nWidth = pBitmap->width();
int nHeight = pBitmap->height();
CC_BREAK_IF(nWidth <= 0 || nHeight <= 0);
int nDataLen = pBitmap->rowBytes() * pBitmap->height();
m_pData = new unsigned char[nDataLen];
CC_BREAK_IF(! m_pData);
memcpy((void*) m_pData, pBitmap->getPixels(), nDataLen);
m_nWidth = (short)nWidth;
m_nHeight = (short)nHeight;
m_bHasAlpha = true;
m_bPreMulti = true;
m_nBitsPerComponent = pBitmap->bytesPerPixel();
bRet = true;
} while (0);
return bRet;
}
示例5: equal
static bool equal(const SkBitmap& bm1, const SkBitmap& bm2) {
if (bm1.width() != bm2.width() ||
bm1.height() != bm2.height() ||
bm1.config() != bm2.config()) {
return false;
}
size_t pixelBytes = bm1.width() * bm1.bytesPerPixel();
for (int y = 0; y < bm1.height(); y++) {
if (memcmp(bm1.getAddr(0, y), bm2.getAddr(0, y), pixelBytes)) {
return false;
}
}
return true;
}
示例6: jni_eglCreatePixmapSurface
static void jni_eglCreatePixmapSurface(JNIEnv *_env, jobject _this, jobject out_sur,
jobject display, jobject config, jobject native_pixmap,
jintArray attrib_list)
{
if (display == NULL || config == NULL || native_pixmap == NULL
|| !validAttribList(_env, attrib_list)) {
jniThrowException(_env, "java/lang/IllegalArgumentException", NULL);
return;
}
EGLDisplay dpy = getDisplay(_env, display);
EGLConfig cnf = getConfig(_env, config);
jint* base = 0;
SkBitmap nativeBitmap;
GraphicsJNI::getSkBitmap(_env, native_pixmap, &nativeBitmap);
SkPixelRef* ref = nativeBitmap.pixelRef();
if (ref == NULL) {
jniThrowException(_env, "java/lang/IllegalArgumentException", "Bitmap has no PixelRef");
return;
}
SkSafeRef(ref);
ref->lockPixels();
egl_native_pixmap_t pixmap;
pixmap.version = sizeof(pixmap);
pixmap.width = nativeBitmap.width();
pixmap.height = nativeBitmap.height();
pixmap.stride = nativeBitmap.rowBytes() / nativeBitmap.bytesPerPixel();
pixmap.format = convertPixelFormat(nativeBitmap.colorType());
pixmap.data = (uint8_t*)ref->pixels();
base = beginNativeAttribList(_env, attrib_list);
EGLSurface sur = eglCreatePixmapSurface(dpy, cnf, &pixmap, base);
endNativeAttributeList(_env, attrib_list, base);
if (sur != EGL_NO_SURFACE) {
_env->SetLongField(out_sur, gSurface_EGLSurfaceFieldID, reinterpret_cast<jlong>(sur));
_env->SetLongField(out_sur, gSurface_NativePixelRefFieldID, reinterpret_cast<jlong>(ref));
} else {
ref->unlockPixels();
SkSafeUnref(ref);
}
}
示例7: SkCreateCGImageRefWithColorspace
CGImageRef SkCreateCGImageRefWithColorspace(const SkBitmap& bm,
CGColorSpaceRef colorSpace) {
size_t bitsPerComponent SK_INIT_TO_AVOID_WARNING;
CGBitmapInfo info SK_INIT_TO_AVOID_WARNING;
SkBitmap* bitmap = prepareForImageRef(bm, &bitsPerComponent, &info);
if (NULL == bitmap) {
return NULL;
}
const int w = bitmap->width();
const int h = bitmap->height();
const size_t s = bitmap->getSize();
// our provider "owns" the bitmap*, and will take care of deleting it
// we initially lock it, so we can access the pixels. The bitmap will be deleted in the release
// proc, which will in turn unlock the pixels
bitmap->lockPixels();
CGDataProviderRef dataRef = CGDataProviderCreateWithData(bitmap, bitmap->getPixels(), s,
SkBitmap_ReleaseInfo);
bool releaseColorSpace = false;
if (NULL == colorSpace) {
colorSpace = CGColorSpaceCreateDeviceRGB();
releaseColorSpace = true;
}
CGImageRef ref = CGImageCreate(w, h, bitsPerComponent,
bitmap->bytesPerPixel() * 8,
bitmap->rowBytes(), colorSpace, info, dataRef,
NULL, false, kCGRenderingIntentDefault);
if (releaseColorSpace) {
CGColorSpaceRelease(colorSpace);
}
CGDataProviderRelease(dataRef);
return ref;
}
开发者ID:IllusionRom-deprecated,项目名称:android_platform_external_chromium_org_third_party_skia_src,代码行数:38,代码来源:SkCreateCGImageRef.cpp
示例8: setPixel
// Utility function to set value of any pixel in bm.
// bm.getConfig() specifies what format 'val' must be
// converted to, but at present uint32_t can handle all formats.
static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) {
uint16_t val16;
uint8_t val8;
SkAutoLockPixels lock(bm);
void* rawAddr = bm.getAddr(x,y);
switch (bm.bytesPerPixel()) {
case 4:
memcpy(rawAddr, &val, sizeof(uint32_t));
break;
case 2:
val16 = val & 0xFFFF;
memcpy(rawAddr, &val16, sizeof(uint16_t));
break;
case 1:
val8 = val & 0xFF;
memcpy(rawAddr, &val8, sizeof(uint8_t));
break;
default:
// Ignore.
break;
}
}
示例9: lock
// Utility function to read the value of a given pixel in bm. All
// values converted to uint32_t for simplification of comparisons.
static uint32_t getPixel(int x, int y, const SkBitmap& bm) {
uint32_t val = 0;
uint16_t val16;
uint8_t val8;
SkAutoLockPixels lock(bm);
const void* rawAddr = bm.getAddr(x,y);
switch (bm.bytesPerPixel()) {
case 4:
memcpy(&val, rawAddr, sizeof(uint32_t));
break;
case 2:
memcpy(&val16, rawAddr, sizeof(uint16_t));
val = val16;
break;
case 1:
memcpy(&val8, rawAddr, sizeof(uint8_t));
val = val8;
break;
default:
break;
}
return val;
}
示例10: com_android_server_AssetAtlasService_upload
static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject,
jobject graphicBuffer, jlong bitmapHandle) {
SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
// The goal of this method is to copy the bitmap into the GraphicBuffer
// using the GPU to swizzle the texture content
sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer));
if (buffer != NULL) {
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (display == EGL_NO_DISPLAY) return JNI_FALSE;
EGLint major;
EGLint minor;
if (!eglInitialize(display, &major, &minor)) {
ALOGW("Could not initialize EGL");
return JNI_FALSE;
}
// We're going to use a 1x1 pbuffer surface later on
// The configuration doesn't really matter for what we're trying to do
EGLint configAttrs[] = {
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 0,
EGL_DEPTH_SIZE, 0,
EGL_STENCIL_SIZE, 0,
EGL_NONE
};
EGLConfig configs[1];
EGLint configCount;
if (!eglChooseConfig(display, configAttrs, configs, 1, &configCount)) {
ALOGW("Could not select EGL configuration");
eglReleaseThread();
eglTerminate(display);
return JNI_FALSE;
}
if (configCount <= 0) {
ALOGW("Could not find EGL configuration");
eglReleaseThread();
eglTerminate(display);
return JNI_FALSE;
}
// These objects are initialized below but the default "null"
// values are used to cleanup properly at any point in the
// initialization sequence
GLuint texture = 0;
EGLImageKHR image = EGL_NO_IMAGE_KHR;
EGLSurface surface = EGL_NO_SURFACE;
EGLSyncKHR fence = EGL_NO_SYNC_KHR;
EGLint attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
EGLContext context = eglCreateContext(display, configs[0], EGL_NO_CONTEXT, attrs);
if (context == EGL_NO_CONTEXT) {
ALOGW("Could not create EGL context");
CLEANUP_GL_AND_RETURN(JNI_FALSE);
}
// Create the 1x1 pbuffer
EGLint surfaceAttrs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
surface = eglCreatePbufferSurface(display, configs[0], surfaceAttrs);
if (surface == EGL_NO_SURFACE) {
ALOGW("Could not create EGL surface");
CLEANUP_GL_AND_RETURN(JNI_FALSE);
}
if (!eglMakeCurrent(display, surface, surface, context)) {
ALOGW("Could not change current EGL context");
CLEANUP_GL_AND_RETURN(JNI_FALSE);
}
// We use an EGLImage to access the content of the GraphicBuffer
// The EGL image is later bound to a 2D texture
EGLClientBuffer clientBuffer = (EGLClientBuffer) buffer->getNativeBuffer();
EGLint imageAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE };
image = eglCreateImageKHR(display, EGL_NO_CONTEXT,
EGL_NATIVE_BUFFER_ANDROID, clientBuffer, imageAttrs);
if (image == EGL_NO_IMAGE_KHR) {
ALOGW("Could not create EGL image");
CLEANUP_GL_AND_RETURN(JNI_FALSE);
}
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
if (glGetError() != GL_NO_ERROR) {
ALOGW("Could not create/bind texture");
CLEANUP_GL_AND_RETURN(JNI_FALSE);
}
// Upload the content of the bitmap in the GraphicBuffer
glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap->bytesPerPixel());
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap->width(), bitmap->height(),
GL_RGBA, GL_UNSIGNED_BYTE, bitmap->getPixels());
if (glGetError() != GL_NO_ERROR) {
ALOGW("Could not upload to texture");
CLEANUP_GL_AND_RETURN(JNI_FALSE);
//.........这里部分代码省略.........
示例11: WriteBitmapToKTX
bool SkKTXFile::WriteBitmapToKTX(SkWStream* stream, const SkBitmap& bitmap) {
const SkColorType ct = bitmap.colorType();
SkAutoLockPixels alp(bitmap);
const int width = bitmap.width();
const int height = bitmap.width();
const uint8_t* src = reinterpret_cast<uint8_t*>(bitmap.getPixels());
if (NULL == bitmap.getPixels()) {
return false;
}
// First thing's first, write out the magic identifier and endianness...
if (!stream->write(KTX_FILE_IDENTIFIER, KTX_FILE_IDENTIFIER_SIZE) ||
!stream->write(&kKTX_ENDIANNESS_CODE, 4)) {
return false;
}
// Collect our key/value pairs...
SkTArray<KeyValue> kvPairs;
// Next, write the header based on the bitmap's config.
Header hdr;
switch (ct) {
case kIndex_8_SkColorType:
// There is a compressed format for this, but we don't support it yet.
SkDebugf("Writing indexed bitmap to KTX unsupported.\n");
// VVV fall through VVV
default:
case kUnknown_SkColorType:
// Bitmap hasn't been configured.
return false;
case kAlpha_8_SkColorType:
hdr.fGLType = GR_GL_UNSIGNED_BYTE;
hdr.fGLTypeSize = 1;
hdr.fGLFormat = GR_GL_RED;
hdr.fGLInternalFormat = GR_GL_R8;
hdr.fGLBaseInternalFormat = GR_GL_RED;
break;
case kRGB_565_SkColorType:
hdr.fGLType = GR_GL_UNSIGNED_SHORT_5_6_5;
hdr.fGLTypeSize = 2;
hdr.fGLFormat = GR_GL_RGB;
hdr.fGLInternalFormat = GR_GL_RGB;
hdr.fGLBaseInternalFormat = GR_GL_RGB;
break;
case kARGB_4444_SkColorType:
hdr.fGLType = GR_GL_UNSIGNED_SHORT_4_4_4_4;
hdr.fGLTypeSize = 2;
hdr.fGLFormat = GR_GL_RGBA;
hdr.fGLInternalFormat = GR_GL_RGBA4;
hdr.fGLBaseInternalFormat = GR_GL_RGBA;
kvPairs.push_back(CreateKeyValue("KTXPremultipliedAlpha", "True"));
break;
case kN32_SkColorType:
hdr.fGLType = GR_GL_UNSIGNED_BYTE;
hdr.fGLTypeSize = 1;
hdr.fGLFormat = GR_GL_RGBA;
hdr.fGLInternalFormat = GR_GL_RGBA8;
hdr.fGLBaseInternalFormat = GR_GL_RGBA;
kvPairs.push_back(CreateKeyValue("KTXPremultipliedAlpha", "True"));
break;
}
// Everything else in the header is shared.
hdr.fPixelWidth = width;
hdr.fPixelHeight = height;
hdr.fNumberOfArrayElements = 0;
hdr.fNumberOfFaces = 1;
hdr.fNumberOfMipmapLevels = 1;
// Calculate the key value data size
hdr.fBytesOfKeyValueData = 0;
for (KeyValue *kv = kvPairs.begin(); kv != kvPairs.end(); ++kv) {
// Key value size is the size of the key value data,
// four bytes for saying how big the key value size is
// and then additional bytes for padding to four byte boundary
size_t kvsize = kv->size();
kvsize += 4;
kvsize = (kvsize + 3) & ~3;
hdr.fBytesOfKeyValueData = SkToU32(hdr.fBytesOfKeyValueData + kvsize);
}
// Write the header
if (!stream->write(&hdr, sizeof(hdr))) {
return false;
}
// Write out each key value pair
for (KeyValue *kv = kvPairs.begin(); kv != kvPairs.end(); ++kv) {
if (!kv->writeKeyAndValueForKTX(stream)) {
return false;
}
}
// Calculate the size of the data
int bpp = bitmap.bytesPerPixel();
//.........这里部分代码省略.........
示例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());
}
}