fix gc error
This commit is contained in:
16
aseprite.c
16
aseprite.c
@@ -21,14 +21,16 @@ static JSValue frame_to_js(JSContext *js, ase_frame_t *frame, int width, int hei
|
||||
JS_ROOT(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, obj.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, obj.val, "format", JS_NewString(js, "rgba32"));
|
||||
JSValue fmt_str = JS_NewString(js, "rgba32");
|
||||
JS_SetPropertyStr(js, obj.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, obj.val, "pitch", JS_NewInt32(js, width * 4));
|
||||
JS_SetPropertyStr(js, obj.val, "depth", JS_NewInt32(js, 8));
|
||||
JS_SetPropertyStr(js, obj.val, "hdr", JS_NewBool(js, 0));
|
||||
|
||||
// Copy pixel data
|
||||
size_t pixels_size = width * height * 4;
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", js_new_blob_stoned_copy(js, frame->pixels, pixels_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, frame->pixels, pixels_size);
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", pixels_blob);
|
||||
|
||||
// Add frame duration (in milliseconds)
|
||||
JS_SetPropertyStr(js, obj.val, "duration", JS_NewInt32(js, frame->duration_milliseconds));
|
||||
@@ -66,8 +68,10 @@ JSValue js_aseprite_decode(JSContext *js, JSValue this_val, int argc, JSValueCon
|
||||
// Add palette if present
|
||||
if (ase->palette.entry_count > 0) {
|
||||
JS_ROOT(palette_array, JS_NewArray(js));
|
||||
JSGCRef color = { .val = JS_NULL, .prev = NULL };
|
||||
JS_PushGCRef(js, &color);
|
||||
for (int i = 0; i < ase->palette.entry_count; i++) {
|
||||
JS_ROOT(color, JS_NewObject(js));
|
||||
color.val = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, color.val, "r", JS_NewUint32(js, ase->palette.entries[i].color.r));
|
||||
JS_SetPropertyStr(js, color.val, "g", JS_NewUint32(js, ase->palette.entries[i].color.g));
|
||||
JS_SetPropertyStr(js, color.val, "b", JS_NewUint32(js, ase->palette.entries[i].color.b));
|
||||
@@ -223,9 +227,11 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon
|
||||
JS_SetPropertyStr(js, result.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, result.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, result.val, "frame_count", JS_NewInt32(js, frame_count));
|
||||
JS_SetPropertyStr(js, result.val, "format", JS_NewString(js, "aseprite"));
|
||||
JSValue enc_fmt = JS_NewString(js, "aseprite");
|
||||
JS_SetPropertyStr(js, result.val, "format", enc_fmt);
|
||||
|
||||
JS_SetPropertyStr(js, result.val, "pixels", js_new_blob_stoned_copy(js, out_data, out_len));
|
||||
JSValue encode_blob = js_new_blob_stoned_copy(js, out_data, out_len);
|
||||
JS_SetPropertyStr(js, result.val, "pixels", encode_blob);
|
||||
free(out_data);
|
||||
|
||||
JS_RETURN(result.val);
|
||||
|
||||
6
dxt.c
6
dxt.c
@@ -119,9 +119,11 @@ JSValue js_dxt_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(result, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, result.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, result.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, result.val, "format", JS_NewString(js, get_dxt_format_string(compression_type)));
|
||||
JSValue fmt_str = JS_NewString(js, get_dxt_format_string(compression_type));
|
||||
JS_SetPropertyStr(js, result.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, result.val, "compression", JS_NewInt32(js, compression_type));
|
||||
JS_SetPropertyStr(js, result.val, "pixels", js_new_blob_stoned_copy(js, output, output_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, output, output_size);
|
||||
JS_SetPropertyStr(js, result.val, "pixels", pixels_blob);
|
||||
|
||||
free(output);
|
||||
JS_RETURN(result.val);
|
||||
|
||||
10
gif.c
10
gif.c
@@ -36,15 +36,19 @@ JSValue js_gif_decode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_FRAME(js);
|
||||
JS_ROOT(frames_array, JS_NewArray(js));
|
||||
|
||||
JSGCRef frame = { .val = JS_NULL, .prev = NULL };
|
||||
JS_PushGCRef(js, &frame);
|
||||
for (int i = 0; i < frames_count; i++) {
|
||||
JS_ROOT(frame, JS_NewObject(js));
|
||||
frame.val = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, frame.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, frame.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, frame.val, "format", JS_NewString(js, "rgba32"));
|
||||
JSValue fmt_str = JS_NewString(js, "rgba32");
|
||||
JS_SetPropertyStr(js, frame.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, frame.val, "pitch", JS_NewInt32(js, pitch));
|
||||
|
||||
void *frame_pixels = (unsigned char*)data + (frame_size * i);
|
||||
JS_SetPropertyStr(js, frame.val, "pixels", js_new_blob_stoned_copy(js, frame_pixels, frame_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, frame_pixels, frame_size);
|
||||
JS_SetPropertyStr(js, frame.val, "pixels", pixels_blob);
|
||||
JS_SetPropertyStr(js, frame.val, "depth", JS_NewInt32(js, 8));
|
||||
JS_SetPropertyStr(js, frame.val, "hdr", JS_NewBool(js, 0));
|
||||
|
||||
|
||||
12
jpg.c
12
jpg.c
@@ -29,9 +29,11 @@ JSValue js_jpg_decode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, obj.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, obj.val, "format", JS_NewString(js, "rgba32"));
|
||||
JSValue fmt_str = JS_NewString(js, "rgba32");
|
||||
JS_SetPropertyStr(js, obj.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, obj.val, "pitch", JS_NewInt32(js, pitch));
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", js_new_blob_stoned_copy(js, data, pixels_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, data, pixels_size);
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", pixels_blob);
|
||||
JS_SetPropertyStr(js, obj.val, "depth", JS_NewInt32(js, 8));
|
||||
JS_SetPropertyStr(js, obj.val, "hdr", JS_NewBool(js, 0));
|
||||
|
||||
@@ -105,8 +107,10 @@ JSValue js_jpg_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(result, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, result.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, result.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, result.val, "format", JS_NewString(js, "jpg"));
|
||||
JS_SetPropertyStr(js, result.val, "pixels", js_new_blob_stoned_copy(js, buf.data, buf.size));
|
||||
JSValue enc_fmt = JS_NewString(js, "jpg");
|
||||
JS_SetPropertyStr(js, result.val, "format", enc_fmt);
|
||||
JSValue enc_blob = js_new_blob_stoned_copy(js, buf.data, buf.size);
|
||||
JS_SetPropertyStr(js, result.val, "pixels", enc_blob);
|
||||
|
||||
free(buf.data);
|
||||
JS_RETURN(result.val);
|
||||
|
||||
12
png.c
12
png.c
@@ -29,9 +29,11 @@ JSValue js_png_decode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, obj.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, obj.val, "format", JS_NewString(js, "rgba32"));
|
||||
JSValue fmt_str = JS_NewString(js, "rgba32");
|
||||
JS_SetPropertyStr(js, obj.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, obj.val, "pitch", JS_NewInt32(js, pitch));
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", js_new_blob_stoned_copy(js, data, pixels_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, data, pixels_size);
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", pixels_blob);
|
||||
JS_SetPropertyStr(js, obj.val, "depth", JS_NewInt32(js, 8));
|
||||
JS_SetPropertyStr(js, obj.val, "hdr", JS_NewBool(js, 0));
|
||||
|
||||
@@ -89,8 +91,10 @@ JSValue js_png_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(result, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, result.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, result.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, result.val, "format", JS_NewString(js, "png"));
|
||||
JS_SetPropertyStr(js, result.val, "pixels", js_new_blob_stoned_copy(js, buf.data, buf.size));
|
||||
JSValue enc_fmt = JS_NewString(js, "png");
|
||||
JS_SetPropertyStr(js, result.val, "format", enc_fmt);
|
||||
JSValue enc_blob = js_new_blob_stoned_copy(js, buf.data, buf.size);
|
||||
JS_SetPropertyStr(js, result.val, "pixels", enc_blob);
|
||||
|
||||
free(buf.data);
|
||||
JS_RETURN(result.val);
|
||||
|
||||
6
psd.c
6
psd.c
@@ -29,9 +29,11 @@ JSValue js_psd_decode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, obj.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, obj.val, "format", JS_NewString(js, "rgba32"));
|
||||
JSValue fmt_str = JS_NewString(js, "rgba32");
|
||||
JS_SetPropertyStr(js, obj.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, obj.val, "pitch", JS_NewInt32(js, pitch));
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", js_new_blob_stoned_copy(js, data, pixels_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, data, pixels_size);
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", pixels_blob);
|
||||
JS_SetPropertyStr(js, obj.val, "depth", JS_NewInt32(js, 8));
|
||||
JS_SetPropertyStr(js, obj.val, "hdr", JS_NewBool(js, 0));
|
||||
|
||||
|
||||
12
qoi.c
12
qoi.c
@@ -100,10 +100,12 @@ JSValue js_qoi_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(result, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, result.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, result.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, result.val, "format", JS_NewString(js, "qoi"));
|
||||
JSValue fmt_str = JS_NewString(js, "qoi");
|
||||
JS_SetPropertyStr(js, result.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, result.val, "channels", JS_NewInt32(js, channels));
|
||||
JS_SetPropertyStr(js, result.val, "colorspace", JS_NewInt32(js, colorspace));
|
||||
JS_SetPropertyStr(js, result.val, "pixels", js_new_blob_stoned_copy(js, qoi_data, out_len));
|
||||
JSValue enc_blob = js_new_blob_stoned_copy(js, qoi_data, out_len);
|
||||
JS_SetPropertyStr(js, result.val, "pixels", enc_blob);
|
||||
free(qoi_data);
|
||||
|
||||
JS_RETURN(result.val);
|
||||
@@ -156,9 +158,11 @@ JSValue js_qoi_decode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj.val, "width", JS_NewInt32(js, desc.width));
|
||||
JS_SetPropertyStr(js, obj.val, "height", JS_NewInt32(js, desc.height));
|
||||
JS_SetPropertyStr(js, obj.val, "format", JS_NewString(js, "rgba32"));
|
||||
JSValue dec_fmt = JS_NewString(js, "rgba32");
|
||||
JS_SetPropertyStr(js, obj.val, "format", dec_fmt);
|
||||
JS_SetPropertyStr(js, obj.val, "pitch", JS_NewInt32(js, pitch));
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", js_new_blob_stoned_copy(js, rgba_data, pixels_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, rgba_data, pixels_size);
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", pixels_blob);
|
||||
JS_SetPropertyStr(js, obj.val, "depth", JS_NewInt32(js, 8));
|
||||
JS_SetPropertyStr(js, obj.val, "hdr", JS_NewBool(js, 0));
|
||||
JS_SetPropertyStr(js, obj.val, "colorspace", JS_NewInt32(js, desc.colorspace));
|
||||
|
||||
6
resize.c
6
resize.c
@@ -105,9 +105,11 @@ JSValue js_resize_resize(JSContext *js, JSValue this_val, int argc, JSValueConst
|
||||
JS_ROOT(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj.val, "width", JS_NewInt32(js, dst_width));
|
||||
JS_SetPropertyStr(js, obj.val, "height", JS_NewInt32(js, dst_height));
|
||||
JS_SetPropertyStr(js, obj.val, "format", JS_NewString(js, "rgba32"));
|
||||
JSValue fmt_str = JS_NewString(js, "rgba32");
|
||||
JS_SetPropertyStr(js, obj.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, obj.val, "pitch", JS_NewInt32(js, dst_width * 4));
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", js_new_blob_stoned_copy(js, dst_pixels, dst_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, dst_pixels, dst_size);
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", pixels_blob);
|
||||
JS_SetPropertyStr(js, obj.val, "depth", JS_NewInt32(js, 8));
|
||||
|
||||
free(dst_pixels);
|
||||
|
||||
@@ -53,9 +53,11 @@ JSValue js_##fmt##_decode(JSContext *js, JSValue this_val, int argc, JSValueCons
|
||||
JS_ROOT(obj, JS_NewObject(js)); \
|
||||
JS_SetPropertyStr(js, obj.val, "width", JS_NewInt32(js, width)); \
|
||||
JS_SetPropertyStr(js, obj.val, "height", JS_NewInt32(js, height)); \
|
||||
JS_SetPropertyStr(js, obj.val, "format", JS_NewString(js, "rgba32")); \
|
||||
JSValue fmt_str = JS_NewString(js, "rgba32"); \
|
||||
JS_SetPropertyStr(js, obj.val, "format", fmt_str); \
|
||||
JS_SetPropertyStr(js, obj.val, "pitch", JS_NewInt32(js, pitch)); \
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", js_new_blob_stoned_copy(js, data, pixels_size)); \
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, data, pixels_size); \
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", pixels_blob); \
|
||||
JS_SetPropertyStr(js, obj.val, "depth", JS_NewInt32(js, 8)); \
|
||||
JS_SetPropertyStr(js, obj.val, "hdr", JS_NewBool(js, 0)); \
|
||||
\
|
||||
@@ -114,8 +116,10 @@ JSValue js_##fmt##_encode(JSContext *js, JSValue this_val, int argc, JSValueCons
|
||||
JS_ROOT(result, JS_NewObject(js)); \
|
||||
JS_SetPropertyStr(js, result.val, "width", JS_NewInt32(js, width)); \
|
||||
JS_SetPropertyStr(js, result.val, "height", JS_NewInt32(js, height)); \
|
||||
JS_SetPropertyStr(js, result.val, "format", JS_NewString(js, #fmt)); \
|
||||
JS_SetPropertyStr(js, result.val, "pixels", js_new_blob_stoned_copy(js, buf.data, buf.size)); \
|
||||
JSValue enc_fmt = JS_NewString(js, #fmt); \
|
||||
JS_SetPropertyStr(js, result.val, "format", enc_fmt); \
|
||||
JSValue enc_blob = js_new_blob_stoned_copy(js, buf.data, buf.size); \
|
||||
JS_SetPropertyStr(js, result.val, "pixels", enc_blob); \
|
||||
\
|
||||
free(buf.data); \
|
||||
JS_RETURN(result.val); \
|
||||
|
||||
12
tga.c
12
tga.c
@@ -29,9 +29,11 @@ JSValue js_tga_decode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, obj.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, obj.val, "format", JS_NewString(js, "rgba32"));
|
||||
JSValue fmt_str = JS_NewString(js, "rgba32");
|
||||
JS_SetPropertyStr(js, obj.val, "format", fmt_str);
|
||||
JS_SetPropertyStr(js, obj.val, "pitch", JS_NewInt32(js, pitch));
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", js_new_blob_stoned_copy(js, data, pixels_size));
|
||||
JSValue pixels_blob = js_new_blob_stoned_copy(js, data, pixels_size);
|
||||
JS_SetPropertyStr(js, obj.val, "pixels", pixels_blob);
|
||||
JS_SetPropertyStr(js, obj.val, "depth", JS_NewInt32(js, 8));
|
||||
JS_SetPropertyStr(js, obj.val, "hdr", JS_NewBool(js, 0));
|
||||
|
||||
@@ -90,8 +92,10 @@ JSValue js_tga_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JS_ROOT(result, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, result.val, "width", JS_NewInt32(js, width));
|
||||
JS_SetPropertyStr(js, result.val, "height", JS_NewInt32(js, height));
|
||||
JS_SetPropertyStr(js, result.val, "format", JS_NewString(js, "tga"));
|
||||
JS_SetPropertyStr(js, result.val, "pixels", js_new_blob_stoned_copy(js, buf.data, buf.size));
|
||||
JSValue enc_fmt = JS_NewString(js, "tga");
|
||||
JS_SetPropertyStr(js, result.val, "format", enc_fmt);
|
||||
JSValue enc_blob = js_new_blob_stoned_copy(js, buf.data, buf.size);
|
||||
JS_SetPropertyStr(js, result.val, "pixels", enc_blob);
|
||||
|
||||
free(buf.data);
|
||||
JS_RETURN(result.val);
|
||||
|
||||
Reference in New Issue
Block a user