Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Support for RendererReadPixels and RendererWritePixels has been added…
Browse files Browse the repository at this point in the history
… to photon renderer.
  • Loading branch information
llmike committed Nov 19, 2009
1 parent d467ef7 commit a8e65a3
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions src/video/photon/SDL_photon_render.c
Expand Up @@ -82,6 +82,10 @@ static int photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect);
static int photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect);
static int photon_renderreadpixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch);
static int photon_renderwritepixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch);
static void photon_renderpresent(SDL_Renderer * renderer);
static void photon_destroytexture(SDL_Renderer * renderer,
SDL_Texture * texture);
Expand Down Expand Up @@ -1571,4 +1575,77 @@ photon_destroyrenderer(SDL_Renderer * renderer)
}
}

static int
photon_renderreadpixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch)
{
SDL_RenderData *rdata = (SDL_RenderData *)renderer->driverdata;
Uint32 sformat=0;
uint8_t* spixels=NULL;
unsigned int spitch=0;

switch (rdata->surfaces_type)
{
case SDL_PHOTON_SURFTYPE_OFFSCREEN:
sformat=photon_image_to_sdl_pixelformat(rdata->osurfaces[rdata->surface_visible_idx]->format);
spixels=(uint8_t*)PdGetOffscreenContextPtr(rdata->osurfaces[rdata->surface_visible_idx]);
spitch=rdata->osurfaces[rdata->surface_visible_idx]->pitch;
break;
case SDL_PHOTON_SURFTYPE_PHIMAGE:
sformat=photon_image_to_sdl_pixelformat(rdata->psurfaces[rdata->surface_visible_idx]->type);
spixels=(uint8_t*)rdata->psurfaces[rdata->surface_visible_idx]->image;
spitch=rdata->psurfaces[rdata->surface_visible_idx]->bpl;
break;
case SDL_PHOTON_SURFTYPE_UNKNOWN:
default:
SDL_SetError("Photon: surfaces are not initialized");
return -1;
}

/* Adjust surface pixels pointer to the rectangle coordinates */
spixels+=rect->y*spitch + rect->x*SDL_BYTESPERPIXEL(sformat);

SDL_ConvertPixels(rect->w, rect->h,
sformat, spixels, spitch,
format, pixels, pitch);

return 0;
}

static int
photon_renderwritepixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch)
{
SDL_RenderData *rdata = (SDL_RenderData *)renderer->driverdata;
Uint32 sformat=0;
uint8_t* spixels=NULL;
unsigned int spitch=0;

switch (rdata->surfaces_type)
{
case SDL_PHOTON_SURFTYPE_OFFSCREEN:
sformat=photon_image_to_sdl_pixelformat(rdata->osurfaces[rdata->surface_visible_idx]->format);
spixels=(uint8_t*)PdGetOffscreenContextPtr(rdata->osurfaces[rdata->surface_visible_idx]);
spitch=rdata->osurfaces[rdata->surface_visible_idx]->pitch;
break;
case SDL_PHOTON_SURFTYPE_PHIMAGE:
sformat=photon_image_to_sdl_pixelformat(rdata->psurfaces[rdata->surface_visible_idx]->type);
spixels=(uint8_t*)rdata->psurfaces[rdata->surface_visible_idx]->image;
spitch=rdata->psurfaces[rdata->surface_visible_idx]->bpl;
break;
case SDL_PHOTON_SURFTYPE_UNKNOWN:
default:
SDL_SetError("Photon: surfaces are not initialized");
return -1;
}

/* Adjust surface pixels pointer to the rectangle coordinates */
spixels+=rect->y*spitch + rect->x*SDL_BYTESPERPIXEL(sformat);

SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch,
sformat, spixels, spitch);

return 0;
}

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit a8e65a3

Please sign in to comment.