Mercurial > sdl-ios-xcode
diff src/video/SDL_renderer_sw.c @ 3435:9f62f47d989b
You can specify the format for pixel data in SDL_RenderReadPixels() and SDL_RenderWritePixels()
This code still doesn't quite work yet. :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 16 Nov 2009 07:13:07 +0000 |
parents | 36cf454ba065 |
children | 0267b8b1595c |
line wrap: on
line diff
--- a/src/video/SDL_renderer_sw.c Sun Nov 15 09:21:46 2009 +0000 +++ b/src/video/SDL_renderer_sw.c Mon Nov 16 07:13:07 2009 +0000 @@ -66,9 +66,9 @@ static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - void * pixels, int pitch); + Uint32 format, void * pixels, int pitch); static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, - const void * pixels, int pitch); + Uint32 format, const void * pixels, int pitch); static void SW_RenderPresent(SDL_Renderer * renderer); static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void SW_DestroyRenderer(SDL_Renderer * renderer); @@ -736,12 +736,9 @@ static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, - void * pixels, int pitch) + Uint32 format, void * pixels, int pitch) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - const Uint8 *src; - Uint8 *dst; - int src_pitch, dst_pitch, w, h; if (data->renderer->LockTexture(data->renderer, data->texture[data->current_texture], @@ -750,17 +747,9 @@ return -1; } - src = data->surface.pixels; - src_pitch = data->surface.pitch; - dst = pixels; - dst_pitch = pitch; - h = rect->h; - w = rect->w * data->surface.format->BytesPerPixel; - while (h--) { - SDL_memcpy(dst, src, w); - src += src_pitch; - dst += dst_pitch; - } + SDL_ConvertPixels(rect->w, rect->h, + data->format, data->surface.pixels, data->surface.pitch, + format, pixels, pitch); data->renderer->UnlockTexture(data->renderer, data->texture[data->current_texture]); @@ -769,12 +758,9 @@ static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, - const void * pixels, int pitch) + Uint32 format, const void * pixels, int pitch) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - const Uint8 *src; - Uint8 *dst; - int src_pitch, dst_pitch, w, h; if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { SDL_AddDirtyRect(&data->dirty, rect); @@ -787,17 +773,8 @@ return -1; } - src = pixels; - src_pitch = pitch; - dst = data->surface.pixels; - dst_pitch = data->surface.pitch; - h = rect->h; - w = rect->w * data->surface.format->BytesPerPixel; - while (h--) { - SDL_memcpy(dst, src, w); - src += src_pitch; - dst += dst_pitch; - } + SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch, + data->format, data->surface.pixels, data->surface.pitch); data->renderer->UnlockTexture(data->renderer, data->texture[data->current_texture]);