Mercurial > sdl-ios-xcode
diff src/video/SDL_renderer_sw.c @ 1681:80a5e6a4e1e2 SDL-1.3
Working on paletted display and texture support (two different issues)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 15 Jun 2006 07:07:07 +0000 |
parents | 9488fca10677 |
children | 396a35389351 |
line wrap: on
line diff
--- a/src/video/SDL_renderer_sw.c Wed Jun 14 08:41:13 2006 +0000 +++ b/src/video/SDL_renderer_sw.c Thu Jun 15 07:07:07 2006 +0000 @@ -34,30 +34,37 @@ SDL_Texture * texture, void **pixels, int *pitch); static int SDL_SW_SetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, + int ncolors); +static int SDL_SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, SDL_Color * colors, int firstcolor, int ncolors); static int SDL_SW_UpdateTexture(SDL_Renderer * renderer, - SDL_Texture * texture, SDL_Rect * rect, + SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch); static int SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Rect * rect, int markDirty, void **pixels, - int *pitch); + const SDL_Rect * rect, int markDirty, + void **pixels, int *pitch); static void SDL_SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void SDL_SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects, - SDL_Rect * rects); + const SDL_Rect * rects); static void SDL_SW_SelectRenderTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static void SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect, +static void SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 color); static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Rect * srcrect, SDL_Rect * dstrect, - int blendMode, int scaleMode); -static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, - void *pixels, int pitch); -static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect, - const void *pixels, int pitch); + const SDL_Rect * srcrect, + const SDL_Rect * dstrect, int blendMode, + int scaleMode); +static int SDL_SW_RenderReadPixels(SDL_Renderer * renderer, + const SDL_Rect * rect, void *pixels, + int pitch); +static int SDL_SW_RenderWritePixels(SDL_Renderer * renderer, + const SDL_Rect * rect, const void *pixels, + int pitch); static void SDL_SW_RenderPresent(SDL_Renderer * renderer); static void SDL_SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); @@ -134,6 +141,7 @@ renderer->CreateTexture = SDL_SW_CreateTexture; renderer->QueryTexturePixels = SDL_SW_QueryTexturePixels; renderer->SetTexturePalette = SDL_SW_SetTexturePalette; + renderer->GetTexturePalette = SDL_SW_GetTexturePalette; renderer->UpdateTexture = SDL_SW_UpdateTexture; renderer->LockTexture = SDL_SW_LockTexture; renderer->UnlockTexture = SDL_SW_UnlockTexture; @@ -235,7 +243,8 @@ static int SDL_SW_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Color * colors, int firstcolor, int ncolors) + const SDL_Color * colors, int firstcolor, + int ncolors) { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; @@ -244,8 +253,19 @@ } static int +SDL_SW_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + SDL_Color * colors, int firstcolor, int ncolors) +{ + SDL_Surface *surface = (SDL_Surface *) texture->driverdata; + + SDL_memcpy(colors, &surface->format->palette->colors[firstcolor], + ncolors * sizeof(*colors)); + return 0; +} + +static int SDL_SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Rect * rect, const void *pixels, int pitch) + const SDL_Rect * rect, const void *pixels, int pitch) { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; Uint8 *src, *dst; @@ -267,7 +287,8 @@ static int SDL_SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Rect * rect, int markDirty, void **pixels, int *pitch) + const SDL_Rect * rect, int markDirty, void **pixels, + int *pitch) { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; @@ -285,7 +306,7 @@ static void SDL_SW_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, - int numrects, SDL_Rect * rects) + int numrects, const SDL_Rect * rects) { } @@ -297,9 +318,11 @@ } static void -SDL_SW_RenderFill(SDL_Renderer * renderer, SDL_Rect * rect, Uint32 color) +SDL_SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 color) { SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; + SDL_Rect real_rect = *rect; Uint8 r, g, b, a; a = (Uint8) ((color >> 24) & 0xFF); @@ -308,16 +331,18 @@ b = (Uint8) (color & 0xFF); color = SDL_MapRGBA(data->target->format, r, g, b, a); - SDL_FillRect(data->target, rect, color); + SDL_FillRect(data->target, &real_rect, color); } static int SDL_SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, - SDL_Rect * srcrect, SDL_Rect * dstrect, int blendMode, - int scaleMode) + const SDL_Rect * srcrect, const SDL_Rect * dstrect, + int blendMode, int scaleMode) { SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; SDL_Surface *surface = (SDL_Surface *) texture->driverdata; + SDL_Rect real_srcrect = *srcrect; + SDL_Rect real_dstrect = *dstrect; if (blendMode & (SDL_TextureBlendMode_Mask | SDL_TextureBlendMode_Blend)) { SDL_SetAlpha(surface, SDL_SRCALPHA, 0); @@ -326,14 +351,16 @@ } if (scaleMode != SDL_TextureScaleMode_None && (srcrect->w != dstrect->w || srcrect->h != dstrect->h)) { - return SDL_SoftStretch(surface, srcrect, data->target, dstrect); + return SDL_SoftStretch(surface, &real_srcrect, data->target, + &real_dstrect); } else { - return SDL_LowerBlit(surface, srcrect, data->target, dstrect); + return SDL_LowerBlit(surface, &real_srcrect, data->target, + &real_dstrect); } } static int -SDL_SW_RenderReadPixels(SDL_Renderer * renderer, SDL_Rect * rect, +SDL_SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, void *pixels, int pitch) { SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata; @@ -356,7 +383,7 @@ } static int -SDL_SW_RenderWritePixels(SDL_Renderer * renderer, SDL_Rect * rect, +SDL_SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, const void *pixels, int pitch) { SDL_SW_RenderData *data = (SDL_SW_RenderData *) renderer->driverdata;