fix blob usage errors
Some checks failed
Build and Deploy / build-macos (push) Failing after 8s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
Some checks failed
Build and Deploy / build-macos (push) Failing after 8s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled
This commit is contained in:
@@ -16,7 +16,6 @@ console.log(myblob.toString())
|
|||||||
console.log(myblob)
|
console.log(myblob)
|
||||||
console.log(myblob.length)
|
console.log(myblob.length)
|
||||||
|
|
||||||
|
|
||||||
var input = use('input')
|
var input = use('input')
|
||||||
|
|
||||||
input.watch($_)
|
input.watch($_)
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ $_.receiver(function(msg) {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
response = {error: e.toString()};
|
response = {error: e.toString()};
|
||||||
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send response back
|
|
||||||
send(msg, response);
|
send(msg, response);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -432,18 +432,22 @@ function handle_renderer(msg) {
|
|||||||
return {id: surf_id};
|
return {id: surf_id};
|
||||||
|
|
||||||
case 'loadTexture':
|
case 'loadTexture':
|
||||||
if (!msg.data) return {error: "Missing data"};
|
if (!msg.data) throw new Error("Missing data")
|
||||||
|
|
||||||
var tex;
|
var tex;
|
||||||
// Direct surface data
|
// Direct surface data
|
||||||
|
console.log(json.encode(msg.data))
|
||||||
var surf = new surface(msg.data)
|
var surf = new surface(msg.data)
|
||||||
|
|
||||||
|
console.log("GOT DATA")
|
||||||
|
console.log(json.encode(msg.data))
|
||||||
|
|
||||||
if (!surf)
|
if (!surf)
|
||||||
return {error: "Must provide surface_id or surface data"};
|
throw new Error("Must provide surface_id or surface data")
|
||||||
|
|
||||||
tex = ren.load_texture(surf);
|
tex = ren.load_texture(surf);
|
||||||
|
|
||||||
if (!tex) return {error: "Failed to load texture"};
|
if (!tex) throw new Error("Failed to load texture")
|
||||||
var tex_id = allocate_id();
|
var tex_id = allocate_id();
|
||||||
resources.texture[tex_id] = tex;
|
resources.texture[tex_id] = tex;
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -41,14 +41,17 @@ Object.defineProperties(graphics.Image.prototype, {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Send message to load texture
|
// Send message to load texture
|
||||||
|
console.log("LOADING")
|
||||||
send(renderer_actor, {
|
send(renderer_actor, {
|
||||||
kind: "renderer",
|
kind: "renderer",
|
||||||
id: renderer_id,
|
id: renderer_id,
|
||||||
op: "loadTexture",
|
op: "loadTexture",
|
||||||
data: this[CPU]
|
data: this[CPU]
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
|
console.log("GOT MSG")
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
console.error("Failed to load texture:", response.error)
|
console.error("Failed to load texture:")
|
||||||
|
console.error(response.error)
|
||||||
self[LOADING] = false;
|
self[LOADING] = false;
|
||||||
} else {
|
} else {
|
||||||
self[GPU] = response;
|
self[GPU] = response;
|
||||||
@@ -156,13 +159,14 @@ function decode_image(bytes, ext)
|
|||||||
function create_image(path){
|
function create_image(path){
|
||||||
try{
|
try{
|
||||||
const bytes = io.slurpbytes(path);
|
const bytes = io.slurpbytes(path);
|
||||||
console.log(bytes)
|
|
||||||
console.log(bytes.length)
|
|
||||||
let raw = decode_image(bytes, path.ext());
|
let raw = decode_image(bytes, path.ext());
|
||||||
|
|
||||||
/* ── Case A: static image ─────────────────────────────────── */
|
/* ── Case A: static image ─────────────────────────────────── */
|
||||||
if(raw.surface)
|
if(raw.surface) {
|
||||||
return make_handle(raw.surface);
|
var gg = new graphics.Image(raw.surface)
|
||||||
|
return gg
|
||||||
|
}
|
||||||
|
|
||||||
/* ── Case B: GIF helpers returned array [surf, …] ─────────── */
|
/* ── Case B: GIF helpers returned array [surf, …] ─────────── */
|
||||||
if(Array.isArray(raw))
|
if(Array.isArray(raw))
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ send(video_actor, {
|
|||||||
|
|
||||||
render = e.id
|
render = e.id
|
||||||
graphics = use('graphics', video_actor, e.id)
|
graphics = use('graphics', video_actor, e.id)
|
||||||
|
|
||||||
console.log(`Created window and renderer id ${render}`)
|
console.log(`Created window and renderer id ${render}`)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -388,6 +388,22 @@ int blob_write_text(blob *b, const char *text) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int blob_write_bytes(blob *b, void *data, size_t length) {
|
||||||
|
if (!b || !data || b->is_stone) return -1;
|
||||||
|
|
||||||
|
// Write each byte as 8 bits
|
||||||
|
uint8_t *bytes = (uint8_t *)data;
|
||||||
|
for (size_t i = 0; i < length; i++) {
|
||||||
|
for (int j = 0; j < 8; j++) {
|
||||||
|
if (blob_write_bit(b, (bytes[i] >> j) & 1) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int blob_read_bit(const blob *b, size_t pos, int *out_bit) {
|
int blob_read_bit(const blob *b, size_t pos, int *out_bit) {
|
||||||
if (!b || !b->is_stone || !out_bit) return -1;
|
if (!b || !b->is_stone || !out_bit) return -1;
|
||||||
if (pos >= b->bit_length) return -1;
|
if (pos >= b->bit_length) return -1;
|
||||||
|
|||||||
@@ -1019,6 +1019,8 @@ JSC_CCALL(os_make_texture,
|
|||||||
int pitch = width*4;
|
int pitch = width*4;
|
||||||
size_t pixels_size = pitch * height;
|
size_t pixels_size = pitch * height;
|
||||||
|
|
||||||
|
printf("making surface from blob %p of %u bytes\n", raw, len);
|
||||||
|
|
||||||
// Create JS object with surface data
|
// Create JS object with surface data
|
||||||
JSValue obj = JS_NewObject(js);
|
JSValue obj = JS_NewObject(js);
|
||||||
JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, width));
|
JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, width));
|
||||||
|
|||||||
@@ -605,6 +605,7 @@ JSValue js_new_blob_stoned_copy(JSContext *js, void *data, size_t bytes)
|
|||||||
printf("Making blob from %p with %u bytes\n", data, bytes);
|
printf("Making blob from %p with %u bytes\n", data, bytes);
|
||||||
blob *b = blob_new(bytes*8);
|
blob *b = blob_new(bytes*8);
|
||||||
memcpy(b->data, data, bytes);
|
memcpy(b->data, data, bytes);
|
||||||
|
b->bit_length = bytes * 8; // Set the actual length in bits
|
||||||
blob_make_stone(b);
|
blob_make_stone(b);
|
||||||
|
|
||||||
return blob2js(js, b);
|
return blob2js(js, b);
|
||||||
@@ -616,7 +617,7 @@ void *js_get_blob_data(JSContext *js, size_t *size, JSValue v)
|
|||||||
if (!b || !b->is_stone)
|
if (!b || !b->is_stone)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
*size = b->bit_capacity/8;
|
*size = (b->bit_length + 7) / 8; // Return actual byte size based on bit length
|
||||||
return b->data;
|
return b->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -295,6 +295,7 @@ SDL_PixelFormat str2pixelformat(const char *str) {
|
|||||||
if (!strcmp(str, "nv12")) return SDL_PIXELFORMAT_NV12;
|
if (!strcmp(str, "nv12")) return SDL_PIXELFORMAT_NV12;
|
||||||
if (!strcmp(str, "nv21")) return SDL_PIXELFORMAT_NV21;
|
if (!strcmp(str, "nv21")) return SDL_PIXELFORMAT_NV21;
|
||||||
if (!strcmp(str, "p010")) return SDL_PIXELFORMAT_P010;
|
if (!strcmp(str, "p010")) return SDL_PIXELFORMAT_P010;
|
||||||
|
if (!strcmp(str, "rgba32")) return SDL_PIXELFORMAT_RGBA32;
|
||||||
return SDL_PIXELFORMAT_UNKNOWN;
|
return SDL_PIXELFORMAT_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ JSValue pixelformat2js(JSContext *js, SDL_PixelFormat fmt)
|
|||||||
return JS_NewString(js, str);
|
return JS_NewString(js, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v)
|
SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v)
|
||||||
{
|
{
|
||||||
if (JS_IsUndefined(v)) return SDL_PIXELFORMAT_UNKNOWN;
|
if (JS_IsUndefined(v)) return SDL_PIXELFORMAT_UNKNOWN;
|
||||||
const char *s = JS_ToCString(js, v);
|
const char *s = JS_ToCString(js, v);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <SDL3/SDL_properties.h>
|
#include <SDL3/SDL_properties.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "qjs_sdl.h"
|
||||||
|
|
||||||
// External function declarations
|
// External function declarations
|
||||||
extern prosperon_rt *create_actor(int argc, char **argv, void (*hook)(JSContext *));
|
extern prosperon_rt *create_actor(int argc, char **argv, void (*hook)(JSContext *));
|
||||||
@@ -1455,27 +1456,6 @@ static SDL_BlendMode js2blendmode(JSContext *js, JSValue v) {
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert pixel format string to SDL_PixelFormat
|
|
||||||
static SDL_PixelFormat js2pixelformat(JSContext *js, JSValue v) {
|
|
||||||
if (JS_IsNumber(v)) {
|
|
||||||
return js2number(js, v);
|
|
||||||
}
|
|
||||||
const char *str = JS_ToCString(js, v);
|
|
||||||
SDL_PixelFormat fmt = SDL_PIXELFORMAT_RGBA8888;
|
|
||||||
if (str) {
|
|
||||||
if (strcmp(str, "rgba8888") == 0) fmt = SDL_PIXELFORMAT_RGBA8888;
|
|
||||||
else if (strcmp(str, "bgra8888") == 0) fmt = SDL_PIXELFORMAT_BGRA8888;
|
|
||||||
else if (strcmp(str, "argb8888") == 0) fmt = SDL_PIXELFORMAT_ARGB8888;
|
|
||||||
else if (strcmp(str, "abgr8888") == 0) fmt = SDL_PIXELFORMAT_ABGR8888;
|
|
||||||
else if (strcmp(str, "rgba32") == 0) fmt = SDL_PIXELFORMAT_RGBA32;
|
|
||||||
else if (strcmp(str, "bgra32") == 0) fmt = SDL_PIXELFORMAT_BGRA32;
|
|
||||||
else if (strcmp(str, "argb32") == 0) fmt = SDL_PIXELFORMAT_ARGB32;
|
|
||||||
else if (strcmp(str, "abgr32") == 0) fmt = SDL_PIXELFORMAT_ABGR32;
|
|
||||||
JS_FreeCString(js, str);
|
|
||||||
}
|
|
||||||
return fmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Texture constructor
|
// Texture constructor
|
||||||
static JSValue js_texture_constructor(JSContext *js, JSValueConst new_target, int argc, JSValueConst *argv)
|
static JSValue js_texture_constructor(JSContext *js, JSValueConst new_target, int argc, JSValueConst *argv)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user