Skip to content

Instantly share code, notes, and snippets.

@tyage
Last active August 29, 2015 14:22
Show Gist options
  • Save tyage/df70faab0798b36c3193 to your computer and use it in GitHub Desktop.
Save tyage/df70faab0798b36c3193 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <assert.h>
#include <emscripten.h>
#include <unistd.h>
int testImage(SDL_Surface* screen, const char* fileName) {
SDL_Surface *image = IMG_Load(fileName);
if (!image)
{
printf("IMG_Load: %s\n", IMG_GetError());
return 0;
}
assert(image->format->BitsPerPixel == 32);
assert(image->format->BytesPerPixel == 4);
assert(image->pitch == 4*image->w);
int result = image->w;
SDL_BlitSurface (image, NULL, screen, NULL);
SDL_FreeSurface (image);
return result;
}
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_SWSURFACE);
int result = 0;
result |= testImage(screen, "screenshot.jpg"); // absolute path
assert(result != 0);
SDL_Flip(screen);
printf("you should see an image.\n");
SDL_Quit();
return 0;
}
function _testImage($screen,$fileName) {
$screen = $screen|0;
$fileName = $fileName|0;
var $0 = 0, $1 = 0, $10 = 0, $11 = 0, $12 = 0, $13 = 0, $14 = 0, $15 = 0, $16 = 0, $17 = 0, $18 = 0, $19 = 0, $2 = 0, $20 = 0, $21 = 0, $22 = 0, $23 = 0, $24 = 0, $25 = 0, $26 = 0;
var $27 = 0, $28 = 0, $29 = 0, $3 = 0, $30 = 0, $31 = 0, $32 = 0, $33 = 0, $34 = 0, $35 = 0, $36 = 0, $37 = 0, $4 = 0, $5 = 0, $6 = 0, $7 = 0, $8 = 0, $9 = 0, $image = 0, $result = 0;
var $vararg_buffer = 0, label = 0, sp = 0;
sp = STACKTOP;
STACKTOP = STACKTOP + 32|0; if ((STACKTOP|0) >= (STACK_MAX|0)) abort();
$vararg_buffer = sp;
$1 = $screen;
$2 = $fileName;
$3 = $2;
$4 = (_IMG_Load(($3|0))|0);
$image = $4;
$5 = $image;
$6 = ($5|0)!=(0|0);
if (!($6)) {
$7 = (_SDL_GetError()|0);
HEAP32[$vararg_buffer>>2] = $7;
(_printf((8|0),($vararg_buffer|0))|0);
$0 = 0;
$37 = $0;
STACKTOP = sp;return ($37|0);
}
$8 = $image;
$9 = (($8) + 4|0);
$10 = HEAP32[$9>>2]|0;
$11 = (($10) + 8|0);
$12 = HEAP8[$11>>0]|0;
$13 = $12&255;
$14 = ($13|0)==(32);
if (!($14)) {
___assert_fail((24|0),(64|0),15,(88|0));
// unreachable;
}
$15 = $image;
$16 = (($15) + 4|0);
$17 = HEAP32[$16>>2]|0;
$18 = (($17) + 9|0);
$19 = HEAP8[$18>>0]|0;
$20 = $19&255;
$21 = ($20|0)==(4);
if (!($21)) {
___assert_fail((104|0),(64|0),16,(88|0));
// unreachable;
}
$22 = $image;
$23 = (($22) + 16|0);
$24 = HEAP32[$23>>2]|0;
$25 = $image;
$26 = (($25) + 8|0);
$27 = HEAP32[$26>>2]|0;
$28 = $27<<2;
$29 = ($24|0)==($28|0);
if (!($29)) {
___assert_fail((144|0),(64|0),17,(88|0));
// unreachable;
}
$30 = $image;
$31 = (($30) + 8|0);
$32 = HEAP32[$31>>2]|0;
$result = $32;
$33 = $image;
$34 = $1;
(_SDL_UpperBlit(($33|0),(0|0),($34|0),(0|0))|0);
$35 = $image;
_SDL_FreeSurface(($35|0));
$36 = $result;
$0 = $36;
$37 = $0;
STACKTOP = sp;return ($37|0);
}
function _main() {
var $0 = 0, $1 = 0, $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0, $7 = 0, $8 = 0, $result = 0, $screen = 0, $vararg_buffer = 0, label = 0, sp = 0;
sp = STACKTOP;
STACKTOP = STACKTOP + 16|0; if ((STACKTOP|0) >= (STACK_MAX|0)) abort();
$vararg_buffer = sp;
$0 = 0;
(_SDL_Init(32)|0);
$1 = (_SDL_SetVideoMode(600,450,32,0)|0);
$screen = $1;
$result = 0;
$2 = $screen;
$3 = (_testImage($2,176)|0);
$4 = $result;
$5 = $4 | $3;
$result = $5;
$6 = $result;
$7 = ($6|0)!=(0);
if ($7) {
$8 = $screen;
(_SDL_Flip(($8|0))|0);
(_printf((216|0),($vararg_buffer|0))|0);
_SDL_Quit();
STACKTOP = sp;return 0;
} else {
___assert_fail((192|0),(64|0),33,(208|0));
// unreachable;
}
return (0)|0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment