本文整理汇总了C++中SDL_BYTESPERPIXEL函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_BYTESPERPIXEL函数的具体用法?C++ SDL_BYTESPERPIXEL怎么用?C++ SDL_BYTESPERPIXEL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_BYTESPERPIXEL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GL_RenderReadPixels
static int
GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
SDL_Window *window = renderer->window;
Uint32 temp_format = SDL_PIXELFORMAT_ARGB8888;
void *temp_pixels;
int temp_pitch;
GLint internalFormat;
GLenum format, type;
Uint8 *src, *dst, *tmp;
int w, h, length, rows;
int status;
GL_ActivateRenderer(renderer);
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
temp_pixels = SDL_malloc(rect->h * temp_pitch);
if (!temp_pixels) {
SDL_OutOfMemory();
return -1;
}
convert_format(data, temp_format, &internalFormat, &format, &type);
SDL_GetWindowSize(window, &w, &h);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glPixelStorei(GL_PACK_ROW_LENGTH,
(temp_pitch / SDL_BYTESPERPIXEL(temp_format)));
data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
format, type, temp_pixels);
/* Flip the rows to be top-down */
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
dst = (Uint8*)temp_pixels;
tmp = SDL_stack_alloc(Uint8, length);
rows = rect->h / 2;
while (rows--) {
SDL_memcpy(tmp, dst, length);
SDL_memcpy(dst, src, length);
SDL_memcpy(src, tmp, length);
dst += temp_pitch;
src -= temp_pitch;
}
SDL_stack_free(tmp);
status = SDL_ConvertPixels(rect->w, rect->h,
temp_format, temp_pixels, temp_pitch,
pixel_format, pixels, pitch);
SDL_free(temp_pixels);
return status;
}
示例2: GLES_RenderReadPixels
static int
GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch)
{
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
void *temp_pixels;
int temp_pitch;
Uint8 *src, *dst, *tmp;
int w, h, length, rows;
int status;
GLES_ActivateRenderer(renderer);
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
temp_pixels = SDL_malloc(rect->h * temp_pitch);
if (!temp_pixels) {
return SDL_OutOfMemory();
}
SDL_GetRendererOutputSize(renderer, &w, &h);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
/* Flip the rows to be top-down if necessary */
if (!renderer->target) {
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
dst = (Uint8*)temp_pixels;
tmp = SDL_stack_alloc(Uint8, length);
rows = rect->h / 2;
while (rows--) {
SDL_memcpy(tmp, dst, length);
SDL_memcpy(dst, src, length);
SDL_memcpy(src, tmp, length);
dst += temp_pitch;
src -= temp_pitch;
}
SDL_stack_free(tmp);
}
status = SDL_ConvertPixels(rect->w, rect->h,
temp_format, temp_pixels, temp_pitch,
pixel_format, pixels, pitch);
SDL_free(temp_pixels);
return status;
}
示例3: NDS_RenderCopy
static int
NDS_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
{
NDS_RenderData *data = (NDS_RenderData *) renderer->driverdata;
NDS_TextureData *txdat = (NDS_TextureData *) texture->driverdata;
SDL_Window *window = renderer->window;
SDL_VideoDisplay *display = window->display;
int Bpp = SDL_BYTESPERPIXEL(texture->format);
if (txdat->type == NDSTX_BG) {
txdat->scroll.x = dstrect->x;
txdat->scroll.y = dstrect->y;
} else {
/* sprites not fully implemented yet */
printf("NDS_RenderCopy: used sprite!\n");
// SpriteEntry *spr = &(data->oam_copy.spriteBuffer[txdat->hw_index]);
// spr->posX = dstrect->x;
// spr->posY = dstrect->y;
// if (txdat->hw_index < MATRIX_COUNT && spr->isRotoscale) {
// }
}
return 0;
}
示例4: GL_UpdateTexture
static int
GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
GLenum result;
GL_ActivateRenderer(renderer);
renderdata->glGetError();
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
(pitch / SDL_BYTESPERPIXEL(texture->format)));
renderdata->glEnable(data->type);
renderdata->glBindTexture(data->type, data->texture);
renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
rect->h, data->format, data->formattype,
pixels);
if (data->yuv) {
const void *top;
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / 2));
/* Skip to the top of the next texture */
top = (const void*)((const Uint8*)pixels + (texture->h-rect->y) * pitch - rect->x);
/* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)top + (rect->y / 2) * pitch + rect->x / 2);
if (texture->format == SDL_PIXELFORMAT_YV12) {
renderdata->glBindTexture(data->type, data->vtexture);
} else {
renderdata->glBindTexture(data->type, data->utexture);
}
renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
rect->w/2, rect->h/2,
data->format, data->formattype, pixels);
/* Skip to the top of the next texture */
top = (const void*)((const Uint8*)top + (texture->h * pitch)/4);
/* Skip to the correct offset into the next texture */
pixels = (const void*)((const Uint8*)top + (rect->y / 2) * pitch + rect->x / 2);
if (texture->format == SDL_PIXELFORMAT_YV12) {
renderdata->glBindTexture(data->type, data->utexture);
} else {
renderdata->glBindTexture(data->type, data->vtexture);
}
renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
rect->w/2, rect->h/2,
data->format, data->formattype, pixels);
}
renderdata->glDisable(data->type);
result = renderdata->glGetError();
if (result != GL_NO_ERROR) {
GL_SetError("glTexSubImage2D()", result);
return -1;
}
return 0;
}
示例5: DirectFB_RenderReadPixels
static int
DirectFB_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch)
{
Uint32 sdl_format;
unsigned char* laypixels;
int laypitch;
DFBSurfacePixelFormat dfb_format;
DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
IDirectFBSurface *winsurf = data->target;
DirectFB_ActivateRenderer(renderer);
winsurf->GetPixelFormat(winsurf, &dfb_format);
sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format);
winsurf->Lock(winsurf, DSLF_READ, (void **) &laypixels, &laypitch);
laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) );
SDL_ConvertPixels(rect->w, rect->h,
sdl_format, laypixels, laypitch,
format, pixels, pitch);
winsurf->Unlock(winsurf);
return 0;
}
示例6: DirectFB_LockTexture
static int
DirectFB_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty,
void **pixels, int *pitch)
{
DirectFB_TextureData *texturedata =
(DirectFB_TextureData *) texture->driverdata;
DFBResult ret;
if (markDirty) {
SDL_AddDirtyRect(&texturedata->dirty, rect);
}
if (texturedata->display) {
void *fdata;
int fpitch;
SDL_DFB_CHECKERR(texturedata->surface->Lock(texturedata->surface,
DSLF_WRITE | DSLF_READ,
&fdata, &fpitch));
*pitch = fpitch;
*pixels = fdata;
} else {
*pixels =
(void *) ((Uint8 *) texturedata->pixels +
rect->y * texturedata->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = texturedata->pitch;
}
return 0;
error:
return -1;
}
示例7: DirectFB_RenderWritePixels
static int
DirectFB_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch)
{
SDL_Window *window = renderer->window;
SDL_DFB_WINDOWDATA(window);
Uint32 sdl_format;
unsigned char* laypixels;
int laypitch;
DFBSurfacePixelFormat dfb_format;
SDL_DFB_CHECK(windata->surface->GetPixelFormat(windata->surface, &dfb_format));
sdl_format = DirectFB_DFBToSDLPixelFormat(dfb_format);
SDL_DFB_CHECK(windata->surface->Lock(windata->surface, DSLF_WRITE, (void **) &laypixels, &laypitch));
laypixels += (rect->y * laypitch + rect->x * SDL_BYTESPERPIXEL(sdl_format) );
SDL_ConvertPixels(rect->w, rect->h,
format, pixels, pitch,
sdl_format, laypixels, laypitch);
SDL_DFB_CHECK(windata->surface->Unlock(windata->surface));
return 0;
}
示例8: SDL_SetRenderDrawColor
void Case::GetFieldScreenshot(void **ppPngMemory, size_t *pPngSize)
{
gIsSavingScreenshot = true;
gScreenshotWidth = 246;
gScreenshotHeight = 138;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Uint32 targetPixelFormat = SDL_PIXELFORMAT_ABGR8888;
#else
Uint32 targetPixelFormat = SDL_PIXELFORMAT_RGBA8888;
#endif
SDL_SetRenderDrawColor(gpRenderer, 0, 0, 0, 255);
SDL_RenderClear(gpRenderer);
DrawForScreenshot();
Uint8 targetBytesPerPixel = SDL_BYTESPERPIXEL(targetPixelFormat);
int targetPitch = gScreenshotWidth * targetBytesPerPixel;
Uint8 *pPixels = new Uint8[gScreenshotHeight * targetPitch];
SDL_Rect rect = { 0, 0, gScreenshotWidth, gScreenshotHeight };
SDL_RenderReadPixels(gpRenderer, &rect, targetPixelFormat, pPixels, targetPitch);
*ppPngMemory = tdefl_write_image_to_png_file_in_memory(pPixels, gScreenshotWidth, gScreenshotHeight, targetBytesPerPixel, pPngSize);
delete [] pPixels;
gIsSavingScreenshot = false;
}
示例9: MIR_CreateWindowFramebuffer
int
MIR_CreateWindowFramebuffer(_THIS, SDL_Window* window, Uint32* format,
void** pixels, int* pitch)
{
MIR_Data* mir_data = _this->driverdata;
MIR_Window* mir_window;
MirSurfaceParameters surfaceparm;
if (MIR_CreateWindow(_this, window) < 0)
return SDL_SetError("Failed to created a mir window.");
mir_window = window->driverdata;
MIR_mir_surface_get_parameters(mir_window->surface, &surfaceparm);
*format = MIR_GetSDLPixelFormat(surfaceparm.pixel_format);
if (*format == SDL_PIXELFORMAT_UNKNOWN)
return SDL_SetError("Unknown pixel format");
*pitch = (((window->w * SDL_BYTESPERPIXEL(*format)) + 3) & ~3);
*pixels = SDL_malloc(window->h*(*pitch));
if (*pixels == NULL)
return SDL_OutOfMemory();
mir_window->surface = MIR_mir_connection_create_surface_sync(mir_data->connection, &surfaceparm);
if (!MIR_mir_surface_is_valid(mir_window->surface)) {
const char* error = MIR_mir_surface_get_error_message(mir_window->surface);
return SDL_SetError("Failed to created a mir surface: %s", error);
}
return 0;
}
示例10: GDI_LockTexture
static int
GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch)
{
GDI_TextureData *data = (GDI_TextureData *) texture->driverdata;
if (data->yuv) {
return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
pitch);
} else if (data->pixels) {
#ifndef _WIN32_WCE
/* WinCE has no GdiFlush */
GdiFlush();
#endif
*pixels =
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
rect->x * SDL_BYTESPERPIXEL(texture->format));
*pitch = data->pitch;
return 0;
} else {
SDL_SetError("No pixels available");
return -1;
}
}
示例11: GLES_UpdateTexture
static int
GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
Uint8 *blob = NULL;
Uint8 *src;
int srcPitch;
int y;
GLES_ActivateRenderer(renderer);
/* Bail out if we're supposed to update an empty rectangle */
if (rect->w <= 0 || rect->h <= 0)
return 0;
/* Reformat the texture data into a tightly packed array */
srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
src = (Uint8 *)pixels;
if (pitch != srcPitch) {
blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
if (!blob) {
return SDL_OutOfMemory();
}
src = blob;
for (y = 0; y < rect->h; ++y) {
SDL_memcpy(src, pixels, srcPitch);
src += srcPitch;
pixels = (Uint8 *)pixels + pitch;
}
src = blob;
}
/* Create a texture subimage with the supplied data */
renderdata->glGetError();
renderdata->glEnable(data->type);
renderdata->glBindTexture(data->type, data->texture);
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
renderdata->glTexSubImage2D(data->type,
0,
rect->x,
rect->y,
rect->w,
rect->h,
data->format,
data->formattype,
src);
if (blob) {
SDL_free(blob);
}
if (renderdata->glGetError() != GL_NO_ERROR)
{
return SDL_SetError("Failed to update texture");
}
return 0;
}
示例12: GL_RenderReadPixels
static int
GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
SDL_Window *window = renderer->window;
GLint internalFormat;
GLenum format, type;
Uint8 *src, *dst, *tmp;
int w, h, length, rows;
GL_ActivateRenderer(renderer);
if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
/* FIXME: Do a temp copy to a format that is supported */
SDL_SetError("Unsupported pixel format");
return -1;
}
SDL_GetWindowSize(window, &w, &h);
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glPixelStorei(GL_PACK_ROW_LENGTH,
(pitch / SDL_BYTESPERPIXEL(pixel_format)));
data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
format, type, pixels);
/* Flip the rows to be top-down */
length = rect->w * SDL_BYTESPERPIXEL(pixel_format);
src = (Uint8*)pixels + (rect->h-1)*pitch;
dst = (Uint8*)pixels;
tmp = SDL_stack_alloc(Uint8, length);
rows = rect->h / 2;
while (rows--) {
SDL_memcpy(tmp, dst, length);
SDL_memcpy(dst, src, length);
SDL_memcpy(src, tmp, length);
dst += pitch;
src -= pitch;
}
SDL_stack_free(tmp);
return 0;
}
示例13: loop
void
loop()
{
SDL_Event event;
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_RenderSetViewport(renderer, NULL);
displayrect.w = window_w = event.window.data1;
displayrect.h = window_h = event.window.data2;
}
break;
case SDL_MOUSEBUTTONDOWN:
displayrect.x = event.button.x - window_w / 2;
displayrect.y = event.button.y - window_h / 2;
break;
case SDL_MOUSEMOTION:
if (event.motion.state) {
displayrect.x = event.motion.x - window_w / 2;
displayrect.y = event.motion.y - window_h / 2;
}
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_SPACE) {
paused = !paused;
break;
}
if (event.key.keysym.sym != SDLK_ESCAPE) {
break;
}
case SDL_QUIT:
done = SDL_TRUE;
break;
}
}
#ifndef __EMSCRIPTEN__
SDL_Delay(fpsdelay);
#endif
if (!paused) {
i = (i + 1) % MOOSEFRAMES_COUNT;
SDL_UpdateTexture(MooseTexture, NULL, MooseFrame[i], MOOSEPIC_W*SDL_BYTESPERPIXEL(pixel_format));
}
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, MooseTexture, NULL, &displayrect);
SDL_RenderPresent(renderer);
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
}
#endif
}
示例14: SDL_ConvertPixels
/*
* Copy a block of pixels of one format to another format
*/
int SDL_ConvertPixels(int width, int height,
Uint32 src_format, const void * src, int src_pitch,
Uint32 dst_format, void * dst, int dst_pitch)
{
SDL_Surface src_surface, dst_surface;
SDL_PixelFormat src_fmt, dst_fmt;
SDL_BlitMap src_blitmap, dst_blitmap;
SDL_Rect rect;
void *nonconst_src = (void *) src;
/* Check to make sure we are blitting somewhere, so we don't crash */
if (!dst) {
return SDL_InvalidParamError("dst");
}
if (!dst_pitch) {
return SDL_InvalidParamError("dst_pitch");
}
if (SDL_ISPIXELFORMAT_FOURCC(src_format) && SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
return SDL_ConvertPixels_YUV_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
} else if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
return SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
} else if (SDL_ISPIXELFORMAT_FOURCC(dst_format)) {
return SDL_ConvertPixels_RGB_to_YUV(width, height, src_format, src, src_pitch, dst_format, dst, dst_pitch);
}
/* Fast path for same format copy */
if (src_format == dst_format) {
int i;
const int bpp = SDL_BYTESPERPIXEL(src_format);
width *= bpp;
for (i = height; i--;) {
SDL_memcpy(dst, src, width);
src = (const Uint8*)src + src_pitch;
dst = (Uint8*)dst + dst_pitch;
}
return 0;
}
if (!SDL_CreateSurfaceOnStack(width, height, src_format, nonconst_src,
src_pitch,
&src_surface, &src_fmt, &src_blitmap)) {
return -1;
}
if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
&dst_surface, &dst_fmt, &dst_blitmap)) {
return -1;
}
/* Set up the rect and go! */
rect.x = 0;
rect.y = 0;
rect.w = width;
rect.h = height;
return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
}
示例15: SDL_ConvertPixels
/*
* Copy a block of pixels of one format to another format
*/
int SDL_ConvertPixels(int width, int height,
Uint32 src_format, const void * src, int src_pitch,
Uint32 dst_format, void * dst, int dst_pitch)
{
SDL_Surface src_surface, dst_surface;
SDL_PixelFormat src_fmt, dst_fmt;
SDL_BlitMap src_blitmap, dst_blitmap;
SDL_Rect rect;
/* Fast path for same format copy */
if (src_format == dst_format) {
int bpp;
if (SDL_ISPIXELFORMAT_FOURCC(src_format)) {
switch (src_format) {
case SDL_PIXELFORMAT_YV12:
case SDL_PIXELFORMAT_IYUV:
case SDL_PIXELFORMAT_YUY2:
case SDL_PIXELFORMAT_UYVY:
case SDL_PIXELFORMAT_YVYU:
bpp = 2;
default:
SDL_SetError("Unknown FOURCC pixel format");
return -1;
}
} else {
bpp = SDL_BYTESPERPIXEL(src_format);
}
width *= bpp;
while (height-- > 0) {
SDL_memcpy(dst, src, width);
src = (Uint8*)src + src_pitch;
dst = (Uint8*)dst + dst_pitch;
}
return 0;
}
if (!SDL_CreateSurfaceOnStack(width, height, src_format, (void*)src,
src_pitch,
&src_surface, &src_fmt, &src_blitmap)) {
return -1;
}
if (!SDL_CreateSurfaceOnStack(width, height, dst_format, dst, dst_pitch,
&dst_surface, &dst_fmt, &dst_blitmap)) {
return -1;
}
/* Set up the rect and go! */
rect.x = 0;
rect.y = 0;
rect.w = width;
rect.h = height;
return SDL_LowerBlit(&src_surface, &rect, &dst_surface, &rect);
}