diff options
author | nandhp <nandhp@gmail.com> | 2012-07-11 10:30:29 -0500 |
---|---|---|
committer | nandhp <nandhp@gmail.com> | 2012-07-11 10:30:29 -0500 |
commit | 81bbbc3de43d3ea898b1b964d7e5fb668fdf8622 (patch) | |
tree | f91bd59e848b749129fb84d6ef400db9fc0e7f9d | |
parent | faebd713187b473fa7090c15169618a7af5cbcc8 (diff) |
Fix SDL_MapRGB and implement SDL_MapRGBA.
Also provide a test case.
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | src/library_sdl.js | 7 | ||||
-rwxr-xr-x | tests/runner.py | 3 | ||||
-rw-r--r-- | tests/sdl_maprgba.c | 33 | ||||
-rw-r--r-- | tests/sdl_maprgba.png | bin | 0 -> 1875 bytes |
5 files changed, 43 insertions, 1 deletions
@@ -24,3 +24,4 @@ under the licensing terms detailed in LICENSE. * Jukka Jylänki <jujjyl@gmail.com> * Aleksander Guryanov <caiiiycuk@gmail.com> * Chad Austin <chad@chadaustin.me> +* nandhp <nandhp@gmail.com> diff --git a/src/library_sdl.js b/src/library_sdl.js index 88649c38..73848502 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -952,7 +952,12 @@ var LibrarySDL = { SDL_MapRGB: function(fmt, r, g, b) { // Canvas screens are always RGBA - return r + (g << 8) + (b << 16); + return 0xff+((b&0xff)<<8)+((g&0xff)<<16)+((r&0xff)<<24) + }, + + SDL_MapRGBA: function(fmt, r, g, b, a) { + // Canvas screens are always RGBA + return (a&0xff)+((b&0xff)<<8)+((g&0xff)<<16)+((r&0xff)<<24) }, SDL_WM_GrabInput: function() {}, diff --git a/tests/runner.py b/tests/runner.py index b23cc9f9..dc6d0fee 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -7912,6 +7912,9 @@ elif 'browser' in str(sys.argv): def test_sdl_canvas_palette(self): self.btest('sdl_canvas_palette.c', reference='sdl_canvas_palette.png') + def test_sdl_maprgba(self): + self.btest('sdl_maprgba.c', reference='sdl_maprgba.png') + def zzztest_sdl_canvas_palette_2(self): # XXX disabled until we have proper automation open(os.path.join(self.get_dir(), 'sdl_canvas_palette_2.c'), 'w').write(self.with_report_result(open(path_from_root('tests', 'sdl_canvas_palette_2.c')).read())) open(os.path.join(self.get_dir(), 'pre.js'), 'w').write('Module[\'preRun\'] = function() { SDL.defaults.copyOnLock = false }') diff --git a/tests/sdl_maprgba.c b/tests/sdl_maprgba.c new file mode 100644 index 00000000..c87c7524 --- /dev/null +++ b/tests/sdl_maprgba.c @@ -0,0 +1,33 @@ +#include <stdio.h> +#include <SDL/SDL.h> +#include <emscripten.h> + +int main() { + Uint32 c; + SDL_Rect rect = {0,0,300,450}; + + SDL_Init(SDL_INIT_VIDEO); + SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); + + c = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00); // OPAQUE RED + SDL_FillRect(screen, &rect, c); + rect.x = 300; + c = SDL_MapRGB(screen->format, 0x7f, 0x7f, 0x00); // OPAQUE MUSTARD + SDL_FillRect(screen, &rect, c); + rect.x = 150; + rect.y = 112; + rect.w = 300; + rect.h = 225; + c = SDL_MapRGBA(screen->format, 0xff, 0xff, 0xff, 0xff); // OPAQUE WHITE + SDL_FillRect(screen, &rect, c); + c = SDL_MapRGBA(screen->format, 0x00, 0x00, 0x00, 0x00); // TRANSPARENT BLACK + SDL_FillRect(screen, &rect, c); + SDL_UpdateRect(screen, 0, 0, 600, 450); + + printf("The left half should be red and the right half mustard.\n"); + printf("There should be a white rectangle in the center.\n"); + + SDL_Quit(); + + return 0; +} diff --git a/tests/sdl_maprgba.png b/tests/sdl_maprgba.png Binary files differnew file mode 100644 index 00000000..4f64c7cd --- /dev/null +++ b/tests/sdl_maprgba.png |