Skip to content

Commit 1f542a5

Browse files
committed
Optional PNG
1 parent 68e742d commit 1f542a5

File tree

6 files changed

+26
-9
lines changed

6 files changed

+26
-9
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ if(CMAKE_TOOLCHAIN_FILE MATCHES "Emscripten.cmake")
77
message("[*] Building using Emscripten toolchain")
88
endif()
99

10-
find_package(PNG REQUIRED)
10+
find_package(PNG)
11+
if(PNG_FOUND)
12+
add_compile_definitions(-DENABLE_PNG=1)
13+
endif()
1114

1215
include("./cmake/bundle.cmake")
1316

1417
include_directories(include lib .)
1518

1619
add_subdirectory(lib/tiny-AES-c)
1720

21+
add_compile_options(-g -O0)
22+
1823
option(CAPSTONE_ARCHITECTURE_DEFAULT "" OFF)
1924
option(CAPSTONE_ARM_SUPPORT "" ON)
2025
add_subdirectory(lib/capstone)

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM golang:1.23.2-bookworm AS builder
2-
RUN apt-get update && apt-get install -y wget git gcc-12 g++ make cmake pkg-config libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libopengl-dev libglx-dev libglu1-mesa-dev freeglut3-dev libxxf86vm-dev
2+
RUN apt-get update && apt-get install -y wget git gcc-12 g++ make cmake pkg-config libx11-dev libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev libopengl-dev libglx-dev libglu1-mesa-dev freeglut3-dev libxxf86vm-dev libpng-dev
33

44
WORKDIR /app
55
COPY . .

include/lua.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
#include "pinetime.h"
44

5-
void run_lua(const char *script, size_t script_size, const char *name, pinetime_t *pt);
6-
void run_lua_file(const char *script_path, pinetime_t *pt);
5+
void run_lua(const char *script, size_t script_size, const char *name);
6+
void run_lua_file(const char *script_path);

src/lua.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "util.h"
55

6-
void run_lua(const char *script, size_t script_size, const char *name, pinetime_t *pt)
6+
void run_lua(const char *script, size_t script_size, const char *name)
77
{
88
lua_State *L = luaL_newstate();
99

@@ -19,10 +19,10 @@ void run_lua(const char *script, size_t script_size, const char *name, pinetime_
1919
fprintf(stderr, "Failed to run Lua script: %s\n", lua_tostring(L, -1));
2020
}
2121

22-
lua_close(L);
22+
// lua_close(L);
2323
}
2424

25-
void run_lua_file(const char *script_path, pinetime_t *pt)
25+
void run_lua_file(const char *script_path)
2626
{
2727
size_t script_size;
2828
uint8_t *script = read_file_u8(script_path, &script_size);
@@ -33,7 +33,7 @@ void run_lua_file(const char *script_path, pinetime_t *pt)
3333
return;
3434
}
3535

36-
run_lua((const char *)script, script_size, script_path, pt);
36+
run_lua((const char *)script, script_size, script_path);
3737

3838
free(script);
3939
}

src/lualibs/lua_image.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ typedef struct
1818
#define DATA_TYPE image_t
1919
#include "lualibs/lualibs.h"
2020

21+
#if ENABLE_PNG
2122
#include <png.h>
23+
#endif
2224

2325
void draw_image(image_t *dst, image_t *src, size_t x, size_t y)
2426
{
@@ -128,6 +130,7 @@ DEF_FN(new)
128130

129131
DEF_FN(load)
130132
{
133+
#if ENABLE_PNG
131134
const char *filename = luaL_checkstring(L, 1);
132135

133136
FILE *fp = fopen(filename, "rb");
@@ -192,6 +195,10 @@ DEF_FN(load)
192195
fclose(fp);
193196

194197
return 1;
198+
#else // ENABLE_PNG
199+
luaL_error(L, "PNG support not enabled");
200+
return 0;
201+
#endif // ENABLE_PNG
195202
}
196203

197204
DEF_FN(combine)
@@ -268,6 +275,7 @@ DEF_FN(combine)
268275

269276
DEF_FN(save)
270277
{
278+
#if ENABLE_PNG
271279
image_t *image = lua_getdata(L, 1);
272280

273281
const char *filename = luaL_checkstring(L, 2);
@@ -312,6 +320,10 @@ DEF_FN(save)
312320
png_destroy_write_struct(&png, &info);
313321

314322
return 0;
323+
#else
324+
luaL_error(L, "PNG support not enabled");
325+
return 0;
326+
#endif // ENABLE_PNG
315327
}
316328

317329
DEF_FN(__eq)

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ int main(int argc, char **argv)
8383

8484
if (lua_script_path)
8585
{
86-
run_lua_file(lua_script_path, NULL);
86+
run_lua_file(lua_script_path);
8787
return 0;
8888
}
8989

0 commit comments

Comments
 (0)