diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-06-18 15:35:50 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-06-18 15:35:50 -0700 |
commit | 6b99a030aa27bb76f8111688c602720886a8d335 (patch) | |
tree | 7ea4e23c96d7bed1600749077ac81dfc1ba552f5 | |
parent | f2e4c9bba1c7c18675ab4db41850aad8eb911c8f (diff) |
handle grayscale images in sdl image loading no-rawData path
-rw-r--r-- | src/library_sdl.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js index 104a0300..68460d73 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -1952,8 +1952,10 @@ var LibrarySDL = { } else { var imageData = surfData.ctx.getImageData(0, 0, surfData.width, surfData.height); if (raw.bpp == 4) { + // rgba imageData.data.set({{{ makeHEAPView('U8', 'raw.data', 'raw.data+raw.size') }}}); } else if (raw.bpp == 3) { + // rgb var pixels = raw.size/3; var data = imageData.data; var sourcePtr = raw.data; @@ -1964,6 +1966,19 @@ var LibrarySDL = { data[destPtr++] = {{{ makeGetValue('sourcePtr++', 0, 'i8', null, 1) }}}; data[destPtr++] = 255; } + } else if (raw.bpp == 1) { + // grayscale + var pixels = raw.size; + var data = imageData.data; + var sourcePtr = raw.data; + var destPtr = 0; + for (var i = 0; i < pixels; i++) { + var value = {{{ makeGetValue('sourcePtr++', 0, 'i8', null, 1) }}}; + data[destPtr++] = value; + data[destPtr++] = value; + data[destPtr++] = value; + data[destPtr++] = 255; + } } else { Module.printErr('cannot handle bpp ' + raw.bpp); return 0; |