save the canvas in preloadedImages, and do canvas blits in IMG_Load etc.
This commit is contained in:
Родитель
809724a0c4
Коммит
406c106b0c
2
emcc
2
emcc
|
@ -899,7 +899,7 @@ try:
|
|||
canvas.height = img.height;
|
||||
var ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(img, 0, 0);
|
||||
preloadedImages['%(filename)s'] = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
preloadedImages['%(filename)s'] = canvas;
|
||||
window.URL.revokeObjectURL(url);
|
||||
removeRunDependency();
|
||||
};
|
||||
|
|
|
@ -442,8 +442,14 @@ mergeInto(LibraryManager.library, {
|
|||
assert(!srcrect && !dstrect); // TODO
|
||||
var srcData = SDL.surfaces[src];
|
||||
var dstData = SDL.surfaces[dst];
|
||||
assert(srcData.width === dstData.width && srcData.height === dstData.height);
|
||||
{{{ makeCopyValues('dstData.buffer', 'srcData.buffer', 'srcData.width*srcData.height*4', 'i8', null, 1) }}}
|
||||
assert(!!srcData.locked == !!dstData.locked); // we support the case of both locked or both not locked
|
||||
if (srcData.locked) {
|
||||
// Just support blitting everything
|
||||
assert(srcData.width === dstData.width && srcData.height === dstData.height);
|
||||
{{{ makeCopyValues('dstData.buffer', 'srcData.buffer', 'srcData.width*srcData.height*4', 'i8', null, 1) }}}
|
||||
} else {
|
||||
dstData.ctx.drawImage(srcData.canvas, 0, 0, srcData.width, srcData.height, 0, 0, dstData.width, dstData.height);
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
|
@ -522,10 +528,8 @@ mergeInto(LibraryManager.library, {
|
|||
var raw = preloadedImages[filename];
|
||||
assert(raw, 'Cannot find preloaded image ' + filename);
|
||||
var surf = SDL.makeSurface(raw.width, raw.height, 0);
|
||||
// XXX Extremely inefficient!
|
||||
for (var i = 0; i < raw.width*raw.height*4; i++) {
|
||||
{{{ makeSetValue('SDL.surfaces[surf].buffer', 'i', 'raw.data[i]', 'i8') }}}
|
||||
}
|
||||
var surfData = SDL.surfaces[surf];
|
||||
surfData.ctx.drawImage(raw, 0, 0, raw.width, raw.height, 0, 0, raw.width, raw.height);
|
||||
return surf;
|
||||
},
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@ int main() {
|
|||
SDL_Init(SDL_INIT_VIDEO);
|
||||
SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_SWSURFACE);
|
||||
|
||||
if (SDL_MUSTLOCK(screen)) SDL_LockSurface(screen);
|
||||
|
||||
SDL_Surface *image = IMG_Load("screenshot.jpg");
|
||||
if (!image)
|
||||
{
|
||||
|
@ -18,7 +16,6 @@ int main() {
|
|||
SDL_BlitSurface (image, NULL, screen, NULL);
|
||||
SDL_FreeSurface (image);
|
||||
|
||||
if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
|
||||
SDL_Flip(screen);
|
||||
|
||||
printf("you should see an image.\n");
|
||||
|
|
Загрузка…
Ссылка в новой задаче