MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / testImage

Function testImage

test/browser/test_sdl2_image.c:20–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#endif
19
20int testImage(SDL_Renderer* renderer, const char* fileName) {
21 SDL_Surface *image = IMG_Load(fileName);
22 if (!image)
23 {
24 printf("IMG_Load: %s\n", IMG_GetError());
25 return 0;
26 }
27 assert(image->format->BitsPerPixel == BITSPERPIXEL);
28 assert(image->format->BytesPerPixel == BITSPERPIXEL / 8);
29 assert(image->pitch == BITSPERPIXEL / 8 * image->w);
30 int result = image->w;
31
32#ifndef NO_PRELOADED
33 int w, h;
34 char *data = emscripten_get_preloaded_image_data(fileName, &w, &h);
35
36 assert(data);
37 assert(w == image->w);
38 assert(h == image->h);
39#endif
40
41 SDL_Texture *tex = SDL_CreateTextureFromSurface(renderer, image);
42
43 SDL_RenderCopy (renderer, tex, NULL, NULL);
44
45 SDL_DestroyTexture (tex);
46
47 SDL_FreeSurface (image);
48
49#ifndef NO_PRELOADED
50 free(data);
51#endif
52
53 return result;
54}
55
56int main() {
57 SDL_Init(SDL_INIT_VIDEO);

Callers 1

mainFunction · 0.70

Calls 3

printfFunction · 0.85
assertFunction · 0.50
freeFunction · 0.50

Tested by

no test coverage detected