From a872bd36421a63b70f6d428dc1886b73ceb607ec Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 26 Jul 2014 13:28:44 -0700 Subject: [PATCH] Remove some ifdefed code by adding a constant for number of bytes per pixel --- src/gba/gba-video.h | 6 ++++++ src/platform/sdl/sw-main.c | 18 +++--------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/gba/gba-video.h b/src/gba/gba-video.h index 2dbfdfa8c..9f22b2412 100644 --- a/src/gba/gba-video.h +++ b/src/gba/gba-video.h @@ -5,6 +5,12 @@ #include "gba-memory.h" +#ifdef COLOR_16_BIT +#define BYTES_PER_PIXEL 2 +#else +#define BYTES_PER_PIXEL 4 +#endif + enum { VIDEO_CYCLES_PER_PIXEL = 4, diff --git a/src/platform/sdl/sw-main.c b/src/platform/sdl/sw-main.c index 99eed9e79..403c9863e 100644 --- a/src/platform/sdl/sw-main.c +++ b/src/platform/sdl/sw-main.c @@ -99,11 +99,7 @@ int main(int argc, char** argv) { #endif SDL_LockTexture(renderer.tex, 0, &renderer.d.outputBuffer, &renderer.d.outputBufferStride); -#ifdef COLOR_16_BIT - renderer.d.outputBufferStride /= 2; -#else - renderer.d.outputBufferStride /= 4; -#endif + renderer.d.outputBufferStride /= BYTES_PER_PIXEL; #else SDL_Surface* surface = SDL_GetVideoSurface(); SDL_LockSurface(surface); @@ -117,11 +113,7 @@ int main(int argc, char** argv) { renderer.d.outputBufferStride = surface->pitch / 4; #endif } else { -#ifdef COLOR_16_BIT - renderer.d.outputBuffer = malloc(240 * 160 * 2); -#else - renderer.d.outputBuffer = malloc(240 * 160 * 4); -#endif + renderer.d.outputBuffer = malloc(240 * 160 * BYTES_PER_PIXEL); renderer.d.outputBufferStride = 240; } #endif @@ -173,11 +165,7 @@ static void _GBASDLRunloop(struct GBAThread* context, struct SoftwareRenderer* r SDL_RenderCopy(renderer->sdlRenderer, renderer->tex, 0, 0); SDL_RenderPresent(renderer->sdlRenderer); SDL_LockTexture(renderer->tex, 0, &renderer->d.outputBuffer, &renderer->d.outputBufferStride); -#ifdef COLOR_16_BIT - renderer->d.outputBufferStride /= 2; -#else - renderer->d.outputBufferStride /= 4; -#endif + renderer->d.outputBufferStride /= BYTES_PER_PIXEL; #else switch (renderer->ratio) { #if defined(__ARM_NEON) && COLOR_16_BIT