Mercurial > repos > blastem
comparison render_sdl.c @ 2438:bed4d3db8a3f
More flexible loading of Pico storyware assets
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 11 Feb 2024 11:04:39 -0800 |
parents | da3dc881d3f0 |
children | 09c9d2c6bac0 |
comparison
equal
deleted
inserted
replaced
2437:79a8cccb6ac1 | 2438:bed4d3db8a3f |
---|---|
1528 extra_windows[win_idx] = NULL; | 1528 extra_windows[win_idx] = NULL; |
1529 } | 1529 } |
1530 | 1530 |
1531 SDL_Texture **static_images; | 1531 SDL_Texture **static_images; |
1532 uint8_t num_static; | 1532 uint8_t num_static; |
1533 uint8_t render_static_image(uint8_t window, char *path) | 1533 uint8_t render_static_image(uint8_t window, uint8_t *buffer, uint32_t size) |
1534 { | 1534 { |
1535 uint32_t fsize; | |
1536 uint8_t *buffer; | |
1537 if (is_absolute_path(path)) { | |
1538 FILE *f = fopen(path, "rb"); | |
1539 if (!f) { | |
1540 return 0xFF; | |
1541 } | |
1542 fsize = file_size(f); | |
1543 buffer = calloc(1, fsize); | |
1544 if (fread(buffer, 1, fsize, f) != fsize) { | |
1545 free(buffer); | |
1546 fclose(f); | |
1547 return 0xFF; | |
1548 } | |
1549 fclose(f); | |
1550 } else { | |
1551 buffer = (uint8_t *)read_bundled_file(path, &fsize); | |
1552 } | |
1553 if (!buffer) { | |
1554 return 0xFF; | |
1555 } | |
1556 | 1535 |
1557 uint32_t width, height; | 1536 uint32_t width, height; |
1558 uint32_t *pixels = load_png(buffer, fsize, &width, &height); | 1537 uint32_t *pixels = load_png(buffer, size, &width, &height); |
1559 free(buffer); | |
1560 if (!pixels) { | 1538 if (!pixels) { |
1561 return 0xFF; | 1539 return 0xFF; |
1562 } | 1540 } |
1563 uint8_t img_index = 0; | 1541 uint8_t img_index = 0; |
1564 if (!num_static) { | 1542 if (!num_static) { |