rm dupavlue and freevalue
This commit is contained in:
12
aseprite.c
12
aseprite.c
@@ -109,15 +109,11 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon
|
||||
JSValue height_val = JS_GetPropertyStr(js, argv[1], "height");
|
||||
if (!JS_IsNull(width_val)) JS_ToInt32(js, &width, width_val);
|
||||
if (!JS_IsNull(height_val)) JS_ToInt32(js, &height, height_val);
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
|
||||
JSValue tile_w_val = JS_GetPropertyStr(js, argv[1], "tile_width");
|
||||
JSValue tile_h_val = JS_GetPropertyStr(js, argv[1], "tile_height");
|
||||
if (!JS_IsNull(tile_w_val)) JS_ToInt32(js, &tile_width, tile_w_val);
|
||||
if (!JS_IsNull(tile_h_val)) JS_ToInt32(js, &tile_height, tile_h_val);
|
||||
JS_FreeValue(js, tile_w_val);
|
||||
JS_FreeValue(js, tile_h_val);
|
||||
}
|
||||
|
||||
// Allocate frames array
|
||||
@@ -135,13 +131,8 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon
|
||||
int frame_w, frame_h;
|
||||
if (JS_ToInt32(js, &frame_w, frame_w_val) < 0 || JS_ToInt32(js, &frame_h, frame_h_val) < 0) {
|
||||
free(frames);
|
||||
JS_FreeValue(js, frame_w_val);
|
||||
JS_FreeValue(js, frame_h_val);
|
||||
JS_FreeValue(js, frame_val);
|
||||
return JS_ThrowTypeError(js, "frame %d has invalid dimensions", i);
|
||||
}
|
||||
JS_FreeValue(js, frame_w_val);
|
||||
JS_FreeValue(js, frame_h_val);
|
||||
|
||||
// Set global dimensions if not specified
|
||||
if (width == 0) width = frame_w;
|
||||
@@ -151,8 +142,6 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon
|
||||
JSValue pixels_val = JS_GetPropertyStr(js, frame_val, "pixels");
|
||||
size_t pixel_len;
|
||||
void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val);
|
||||
JS_FreeValue(js, pixels_val);
|
||||
JS_FreeValue(js, frame_val);
|
||||
|
||||
if (pixel_data == NULL) {
|
||||
free(frames);
|
||||
@@ -177,7 +166,6 @@ JSValue js_aseprite_encode(JSContext *js, JSValue this_val, int argc, JSValueCon
|
||||
if (!JS_IsNull(duration_val)) {
|
||||
JS_ToInt32(js, &duration, duration_val);
|
||||
}
|
||||
JS_FreeValue(js, duration_val);
|
||||
|
||||
// Copy pixel data and set frame info
|
||||
frames[i].pixels = malloc(required_size);
|
||||
|
||||
9
dxt.c
9
dxt.c
@@ -26,19 +26,13 @@ JSValue js_dxt_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue height_val = JS_GetPropertyStr(js, argv[0], "height");
|
||||
|
||||
if (JS_IsNull(width_val) || JS_IsNull(height_val)) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "dxt.encode requires width and height properties");
|
||||
}
|
||||
|
||||
int width, height;
|
||||
if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "width and height must be numbers");
|
||||
}
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
|
||||
if (width < 4 || height < 4)
|
||||
return JS_ThrowRangeError(js, "width and height must be at least 4 for DXT compression");
|
||||
@@ -50,7 +44,6 @@ JSValue js_dxt_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels");
|
||||
size_t pixel_len;
|
||||
void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val);
|
||||
JS_FreeValue(js, pixels_val);
|
||||
|
||||
if (pixel_data == NULL) return JS_EXCEPTION;
|
||||
if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data");
|
||||
@@ -68,13 +61,11 @@ JSValue js_dxt_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
if (!JS_IsNull(type_val)) {
|
||||
JS_ToInt32(js, &compression_type, type_val);
|
||||
}
|
||||
JS_FreeValue(js, type_val);
|
||||
|
||||
JSValue quality_val = JS_GetPropertyStr(js, argv[1], "high_quality");
|
||||
if (!JS_IsNull(quality_val)) {
|
||||
high_quality = JS_ToBool(js, quality_val);
|
||||
}
|
||||
JS_FreeValue(js, quality_val);
|
||||
}
|
||||
|
||||
// Determine alpha mode based on compression type
|
||||
|
||||
8
jpg.c
8
jpg.c
@@ -51,19 +51,13 @@ JSValue js_jpg_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue height_val = JS_GetPropertyStr(js, argv[0], "height");
|
||||
|
||||
if (JS_IsNull(width_val) || JS_IsNull(height_val)) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "jpg.encode requires width and height properties");
|
||||
}
|
||||
|
||||
int width, height;
|
||||
if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "width and height must be numbers");
|
||||
}
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
|
||||
if (width < 1 || height < 1)
|
||||
return JS_ThrowRangeError(js, "width and height must be at least 1");
|
||||
@@ -71,7 +65,6 @@ JSValue js_jpg_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels");
|
||||
size_t pixel_len;
|
||||
void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val);
|
||||
JS_FreeValue(js, pixels_val);
|
||||
|
||||
if (pixel_data == NULL) return JS_EXCEPTION;
|
||||
if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data");
|
||||
@@ -92,7 +85,6 @@ JSValue js_jpg_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
quality = qtmp;
|
||||
}
|
||||
}
|
||||
JS_FreeValue(js, qv);
|
||||
}
|
||||
|
||||
stbi_mem_buf buf = {0};
|
||||
|
||||
7
png.c
7
png.c
@@ -51,19 +51,13 @@ JSValue js_png_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue height_val = JS_GetPropertyStr(js, argv[0], "height");
|
||||
|
||||
if (JS_IsNull(width_val) || JS_IsNull(height_val)) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "png.encode requires width and height properties");
|
||||
}
|
||||
|
||||
int width, height;
|
||||
if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "width and height must be numbers");
|
||||
}
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
|
||||
if (width < 1 || height < 1)
|
||||
return JS_ThrowRangeError(js, "width and height must be at least 1");
|
||||
@@ -71,7 +65,6 @@ JSValue js_png_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels");
|
||||
size_t pixel_len;
|
||||
void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val);
|
||||
JS_FreeValue(js, pixels_val);
|
||||
|
||||
if (pixel_data == NULL) return JS_EXCEPTION;
|
||||
if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data");
|
||||
|
||||
8
qoi.c
8
qoi.c
@@ -25,19 +25,13 @@ JSValue js_qoi_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue height_val = JS_GetPropertyStr(js, argv[0], "height");
|
||||
|
||||
if (JS_IsNull(width_val) || JS_IsNull(height_val)) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "compress_qoi requires width and height properties");
|
||||
}
|
||||
|
||||
int width, height;
|
||||
if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "width and height must be numbers");
|
||||
}
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
|
||||
if (width < 1 || height < 1)
|
||||
return JS_ThrowRangeError(js, "width and height must be at least 1");
|
||||
@@ -45,7 +39,6 @@ JSValue js_qoi_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
// Get pixel format
|
||||
JSValue format_val = JS_GetPropertyStr(js, argv[0], "format");
|
||||
const char *format_str = JS_ToCString(js, format_val);
|
||||
JS_FreeValue(js, format_val);
|
||||
|
||||
if (!format_str)
|
||||
return JS_ThrowTypeError(js, "Invalid or missing pixel format");
|
||||
@@ -60,7 +53,6 @@ JSValue js_qoi_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels");
|
||||
size_t pixel_len;
|
||||
void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val);
|
||||
JS_FreeValue(js, pixels_val);
|
||||
|
||||
if (pixel_data == NULL)
|
||||
return JS_EXCEPTION;
|
||||
|
||||
18
resize.c
18
resize.c
@@ -19,19 +19,13 @@ JSValue js_resize_resize(JSContext *js, JSValue this_val, int argc, JSValueConst
|
||||
JSValue src_height_val = JS_GetPropertyStr(js, argv[0], "height");
|
||||
|
||||
if (JS_IsNull(src_width_val) || JS_IsNull(src_height_val)) {
|
||||
JS_FreeValue(js, src_width_val);
|
||||
JS_FreeValue(js, src_height_val);
|
||||
return JS_ThrowTypeError(js, "resize.resize requires image with width and height properties");
|
||||
}
|
||||
|
||||
int src_width, src_height;
|
||||
if (JS_ToInt32(js, &src_width, src_width_val) < 0 || JS_ToInt32(js, &src_height, src_height_val) < 0) {
|
||||
JS_FreeValue(js, src_width_val);
|
||||
JS_FreeValue(js, src_height_val);
|
||||
return JS_ThrowTypeError(js, "width and height must be numbers");
|
||||
}
|
||||
JS_FreeValue(js, src_width_val);
|
||||
JS_FreeValue(js, src_height_val);
|
||||
|
||||
// Get destination dimensions
|
||||
int dst_width, dst_height;
|
||||
@@ -48,7 +42,6 @@ JSValue js_resize_resize(JSContext *js, JSValue this_val, int argc, JSValueConst
|
||||
JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels");
|
||||
size_t pixel_len;
|
||||
void *src_pixels = js_get_blob_data(js, &pixel_len, pixels_val);
|
||||
JS_FreeValue(js, pixels_val);
|
||||
|
||||
if (src_pixels == NULL) return JS_EXCEPTION;
|
||||
if (!src_pixels) return JS_ThrowTypeError(js, "pixels blob has no data");
|
||||
@@ -75,7 +68,6 @@ JSValue js_resize_resize(JSContext *js, JSValue this_val, int argc, JSValueConst
|
||||
JS_FreeCString(js, filter_str);
|
||||
}
|
||||
}
|
||||
JS_FreeValue(js, filter_val);
|
||||
}
|
||||
|
||||
// Allocate destination buffer
|
||||
@@ -128,12 +120,8 @@ JSValue js_resize_fit(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
|
||||
int src_width, src_height;
|
||||
if (JS_ToInt32(js, &src_width, src_width_val) < 0 || JS_ToInt32(js, &src_height, src_height_val) < 0) {
|
||||
JS_FreeValue(js, src_width_val);
|
||||
JS_FreeValue(js, src_height_val);
|
||||
return JS_ThrowTypeError(js, "image must have width and height");
|
||||
}
|
||||
JS_FreeValue(js, src_width_val);
|
||||
JS_FreeValue(js, src_height_val);
|
||||
|
||||
int max_width, max_height;
|
||||
if (JS_ToInt32(js, &max_width, argv[1]) < 0 || JS_ToInt32(js, &max_height, argv[2]) < 0)
|
||||
@@ -158,9 +146,6 @@ JSValue js_resize_fit(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
|
||||
JSValue result = js_resize_resize(js, this_val, 4, new_args);
|
||||
|
||||
JS_FreeValue(js, new_args[1]);
|
||||
JS_FreeValue(js, new_args[2]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -183,9 +168,6 @@ JSValue js_resize_square(JSContext *js, JSValue this_val, int argc, JSValueConst
|
||||
|
||||
JSValue result = js_resize_resize(js, this_val, 4, new_args);
|
||||
|
||||
JS_FreeValue(js, new_args[1]);
|
||||
JS_FreeValue(js, new_args[2]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,19 +75,17 @@ JSValue js_##fmt##_encode(JSContext *js, JSValue this_val, int argc, JSValueCons
|
||||
JSValue height_val = JS_GetPropertyStr(js, argv[0], "height"); \
|
||||
\
|
||||
if (JS_IsNull(width_val) || JS_IsNull(height_val)) { \
|
||||
JS_FreeValue(js, width_val); \
|
||||
JS_FreeValue(js, height_val); \
|
||||
\
|
||||
\
|
||||
return JS_ThrowTypeError(js, #fmt ".encode requires width and height properties"); \
|
||||
} \
|
||||
\
|
||||
int width, height; \
|
||||
if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) { \
|
||||
JS_FreeValue(js, width_val); \
|
||||
JS_FreeValue(js, height_val); \
|
||||
\
|
||||
\
|
||||
return JS_ThrowTypeError(js, "width and height must be numbers"); \
|
||||
} \
|
||||
JS_FreeValue(js, width_val); \
|
||||
JS_FreeValue(js, height_val); \
|
||||
\
|
||||
if (width < 1 || height < 1) \
|
||||
return JS_ThrowRangeError(js, "width and height must be at least 1"); \
|
||||
@@ -95,7 +93,7 @@ JSValue js_##fmt##_encode(JSContext *js, JSValue this_val, int argc, JSValueCons
|
||||
JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels"); \
|
||||
size_t pixel_len; \
|
||||
void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val); \
|
||||
JS_FreeValue(js, pixels_val); \
|
||||
\
|
||||
\
|
||||
if (pixel_data == NULL) return JS_EXCEPTION; \
|
||||
if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data"); \
|
||||
|
||||
7
tga.c
7
tga.c
@@ -51,19 +51,13 @@ JSValue js_tga_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue height_val = JS_GetPropertyStr(js, argv[0], "height");
|
||||
|
||||
if (JS_IsNull(width_val) || JS_IsNull(height_val)) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "tga.encode requires width and height properties");
|
||||
}
|
||||
|
||||
int width, height;
|
||||
if (JS_ToInt32(js, &width, width_val) < 0 || JS_ToInt32(js, &height, height_val) < 0) {
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
return JS_ThrowTypeError(js, "width and height must be numbers");
|
||||
}
|
||||
JS_FreeValue(js, width_val);
|
||||
JS_FreeValue(js, height_val);
|
||||
|
||||
if (width < 1 || height < 1)
|
||||
return JS_ThrowRangeError(js, "width and height must be at least 1");
|
||||
@@ -71,7 +65,6 @@ JSValue js_tga_encode(JSContext *js, JSValue this_val, int argc, JSValueConst *a
|
||||
JSValue pixels_val = JS_GetPropertyStr(js, argv[0], "pixels");
|
||||
size_t pixel_len;
|
||||
void *pixel_data = js_get_blob_data(js, &pixel_len, pixels_val);
|
||||
JS_FreeValue(js, pixels_val);
|
||||
|
||||
if (pixel_data == NULL) return JS_EXCEPTION;
|
||||
if (!pixel_data) return JS_ThrowTypeError(js, "pixels blob has no data");
|
||||
|
||||
Reference in New Issue
Block a user