Skip to content

Commit d3a654f

Browse files
committed
Move .bmp files to .png format.
Even adding in lodepng, this is already a reduction in total size, and only more savings as new games are added.
1 parent 335121e commit d3a654f

File tree

15 files changed

+9189
-12
lines changed

15 files changed

+9189
-12
lines changed

CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ target_include_directories(dirksimple-theoraplay PRIVATE
128128
target_compile_definitions(dirksimple-theoraplay PRIVATE "-DTHEORAPLAY_NO_MALLOC_FALLBACK=1")
129129
target_compile_definitions(dirksimple-theoraplay PRIVATE "-DTHEORAPLAY_NO_FOPEN_FALLBACK=1")
130130

131+
add_library(dirksimple-lodepng STATIC
132+
thirdparty/lodepng/lodepng.c
133+
)
134+
set_target_properties(dirksimple-lodepng PROPERTIES POSITION_INDEPENDENT_CODE ON)
135+
131136
add_library(dirksimple-lua STATIC
132137
thirdparty/lua/src/lapi.c
133138
thirdparty/lua/src/ldebug.c
@@ -174,9 +179,10 @@ if(DIRKSIMPLE_SDL)
174179
${SDL2_INCLUDE_DIRS} ${SDL2_INCLUDE_DIR}
175180
thirdparty/lua/src
176181
thirdparty/theoraplay
182+
thirdparty/lodepng
177183
)
178184
target_link_libraries(dirksimple ${SDL2_LIBRARIES} ${SDL2_LIBRARY})
179-
target_link_libraries(dirksimple dirksimple-theoraplay dirksimple-theora dirksimple-vorbis dirksimple-ogg dirksimple-lua)
185+
target_link_libraries(dirksimple dirksimple-theoraplay dirksimple-theora dirksimple-vorbis dirksimple-ogg dirksimple-lodepng dirksimple-lua)
180186
if(USE_PTHREAD)
181187
target_link_libraries(dirksimple pthread)
182188
endif()
@@ -221,9 +227,10 @@ if(DIRKSIMPLE_LIBRETRO)
221227
thirdparty/libretro
222228
thirdparty/lua/src
223229
thirdparty/theoraplay
230+
thirdparty/lodepng
224231
)
225232
set_target_properties(dirksimple_libretro PROPERTIES PREFIX "")
226-
target_link_libraries(dirksimple_libretro dirksimple-theoraplay dirksimple-theora dirksimple-vorbis dirksimple-ogg dirksimple-lua)
233+
target_link_libraries(dirksimple_libretro dirksimple-theoraplay dirksimple-theora dirksimple-vorbis dirksimple-ogg dirksimple-lodepng dirksimple-lua)
227234

228235
if(USE_PTHREAD)
229236
target_link_libraries(dirksimple_libretro pthread)

data/games/cliff/cliffglyphs.bmp

-32.1 KB
Binary file not shown.

data/games/cliff/cliffglyphs.png

621 Bytes
Loading

data/games/cliff/icon.bmp

-768 KB
Binary file not shown.

data/games/cliff/icon.png

17.9 KB
Loading

data/games/cliff/logo.bmp

-50.1 KB
Binary file not shown.

data/games/cliff/logo.png

595 Bytes
Loading

data/icon.bmp

-192 KB
Binary file not shown.

data/icon.png

80.1 KB
Loading

dirksimple.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "dirksimple_platform.h"
1010

1111
#include "theoraplay.h"
12+
#include "lodepng.h"
1213
#include "lua.h"
1314
#include "lauxlib.h"
1415
#include "lualib.h"
@@ -312,11 +313,32 @@ uint8_t *DirkSimple_loadbmp(const char *fname, int *_w, int *_h)
312313
{
313314
long flen = 0;
314315
uint8_t *fbuf = DirkSimple_loadmedia(fname, &flen);
315-
uint8_t *pixels = loadbmp_from_memory(fname, fbuf, flen, _w, _h);
316+
uint8_t *pixels = fbuf ? loadbmp_from_memory(fname, fbuf, flen, _w, _h) : NULL;
316317
DirkSimple_free(fbuf);
317318
return (uint8_t *) pixels;
318319
}
319320

321+
uint8_t *DirkSimple_loadpng(const char *fname, int *_w, int *_h)
322+
{
323+
unsigned char *pixels = NULL;
324+
long flen = 0;
325+
uint8_t *fbuf = DirkSimple_loadmedia(fname, &flen);
326+
if (fbuf) {
327+
unsigned uw = 0;
328+
unsigned uh = 0;
329+
if (lodepng_decode32(&pixels, &uw, &uh, (const unsigned char *) fbuf, (size_t) flen) == 0) {
330+
*_w = (int) uw;
331+
*_h = (int) uh;
332+
} else {
333+
lodepng_free(pixels);
334+
pixels = NULL;
335+
*_w = *_h = 0;
336+
}
337+
DirkSimple_free(fbuf);
338+
}
339+
return (uint8_t *) pixels;
340+
}
341+
320342

321343
// !!! FIXME: we should probably cache all sprites and waves we see in the
322344
// !!! FIXME: game's dir during DirkSimple_startup. There are only a handful
@@ -346,12 +368,18 @@ static DirkSimple_Sprite *get_cached_sprite(const char *name)
346368
}
347369

348370
// not cached yet, load it from disk.
371+
int w, h;
372+
uint8_t *rgba;
373+
349374
const size_t slen = strlen(GGameDir) + strlen(name) + 8;
350375
char *fname = (char *) DirkSimple_xmalloc(slen);
351-
snprintf(fname, slen, "%s%s.bmp", GGameDir, name);
376+
snprintf(fname, slen, "%s%s.png", GGameDir, name);
377+
rgba = DirkSimple_loadpng(fname, &w, &h);
378+
if (!rgba) { // maybe it's a bitmap?
379+
snprintf(fname, slen, "%s%s.bmp", GGameDir, name);
380+
rgba = DirkSimple_loadbmp(fname, &w, &h);
381+
}
352382

353-
int w, h;
354-
uint8_t *rgba = DirkSimple_loadbmp(fname, &w, &h);
355383
if (rgba) {
356384
DirkSimple_log("Loaded sprite '%s': %dx%d, RGBA", fname, w, h);
357385
}

0 commit comments

Comments
 (0)