fix bug with locking an sdl surface not reading the canvas pixel data properly; fixes #664
This commit is contained in:
Родитель
8a1294ec80
Коммит
05a26d92ef
|
@ -722,16 +722,15 @@ var LibrarySDL = {
|
|||
surfData.locked++;
|
||||
if (surfData.locked > 1) return 0;
|
||||
|
||||
if (!surfData.image) {
|
||||
surfData.image = surfData.ctx.getImageData(0, 0, surfData.width, surfData.height);
|
||||
if (surf == SDL.screen) {
|
||||
var data = surfData.image.data;
|
||||
var num = data.length;
|
||||
for (var i = 0; i < num/4; i++) {
|
||||
data[i*4+3] = 255; // opacity, as canvases blend alpha
|
||||
}
|
||||
surfData.image = surfData.ctx.getImageData(0, 0, surfData.width, surfData.height);
|
||||
if (surf == SDL.screen) {
|
||||
var data = surfData.image.data;
|
||||
var num = data.length;
|
||||
for (var i = 0; i < num/4; i++) {
|
||||
data[i*4+3] = 255; // opacity, as canvases blend alpha
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL.defaults.copyOnLock) {
|
||||
// Copy pixel data to somewhere accessible to 'C/C++'
|
||||
if (surfData.isFlagSet(0x00200000 /* SDL_HWPALETTE */)) {
|
||||
|
|
|
@ -9124,6 +9124,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_canvas_twice(self):
|
||||
self.btest('sdl_canvas_twice.c', reference='sdl_canvas_twice.png')
|
||||
|
||||
def test_sdl_maprgba(self):
|
||||
self.btest('sdl_maprgba.c', reference='sdl_maprgba.png', reference_slack=3)
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#include <SDL/SDL.h>
|
||||
|
||||
#if EMSCRIPTEN
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
SDL_Surface *screen = SDL_SetVideoMode(40, 40, 32, SDL_SWSURFACE);
|
||||
|
||||
SDL_FillRect(screen, NULL, 0xff0000ff);
|
||||
SDL_LockSurface(screen);
|
||||
*((int*)screen->pixels + 95) = 0;
|
||||
SDL_UnlockSurface(screen);
|
||||
|
||||
SDL_FillRect(screen, NULL, 0x00ff00ff); // wipe out previous pixel and fill
|
||||
SDL_LockSurface(screen);
|
||||
*((int*)screen->pixels + 205) = 0;
|
||||
SDL_UnlockSurface(screen);
|
||||
|
||||
SDL_Flip(screen);
|
||||
|
||||
while(1) { SDL_WaitEvent(NULL); }
|
||||
|
||||
return 0;
|
||||
}
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 129 B |
Загрузка…
Ссылка в новой задаче