Mercurial > sdl-ios-xcode
changeset 3459:feea0def118d
Support for RendererReadPixels and RendererWritePixels has been added to photon renderer.
author | Mike Gorchak <lestat@i.com.ua> |
---|---|
date | Thu, 19 Nov 2009 08:44:07 +0000 |
parents | 0aed0755d1f1 |
children | ba48701b0534 |
files | src/video/photon/SDL_photon_render.c |
diffstat | 1 files changed, 77 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/photon/SDL_photon_render.c Thu Nov 19 08:02:00 2009 +0000 +++ b/src/video/photon/SDL_photon_render.c Thu Nov 19 08:44:07 2009 +0000 @@ -82,6 +82,10 @@ 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); @@ -1571,4 +1575,77 @@ } } +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: */