fix syntax
This commit is contained in:
45
camera.c
45
camera.c
@@ -42,13 +42,14 @@ JSC_CCALL(camera_get_cameras,
|
||||
int count = 0;
|
||||
SDL_CameraID *cameras = SDL_GetCameras(&count);
|
||||
if (!cameras) return JS_NewArray(js);
|
||||
|
||||
JSValue arr = JS_NewArray(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
for (int i = 0; i < count; i++) {
|
||||
JS_SetPropertyUint32(js, arr, i, JS_NewUint32(js, cameras[i]));
|
||||
JS_SetPropertyNumber(js, arr, i, JS_NewUint32(js, cameras[i]));
|
||||
}
|
||||
SDL_free(cameras);
|
||||
return arr;
|
||||
JS_RETURN(arr);
|
||||
)
|
||||
|
||||
// SDL_GetCameraSupportedFormats(id) -> array of format objects
|
||||
@@ -60,19 +61,23 @@ JSC_CCALL(camera_get_supported_formats,
|
||||
SDL_CameraSpec **specs = SDL_GetCameraSupportedFormats(id, &count);
|
||||
if (!specs) return JS_NewArray(js);
|
||||
|
||||
JSValue arr = JS_NewArray(js);
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
JSValue obj = JS_NULL;
|
||||
JSLocalRef obj__lr = {.ptr = &obj};
|
||||
JS_PushLocalRef(_js_ctx, &obj__lr);
|
||||
for (int i = 0; i < count; i++) {
|
||||
SDL_CameraSpec *spec = specs[i];
|
||||
JSValue obj = JS_NewObject(js);
|
||||
obj = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js, obj, "format", SDL_PixelFormat2js(js, spec->format));
|
||||
JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, spec->width));
|
||||
JS_SetPropertyStr(js, obj, "height", JS_NewInt32(js, spec->height));
|
||||
JS_SetPropertyStr(js, obj, "framerate_numerator", JS_NewInt32(js, spec->framerate_numerator));
|
||||
JS_SetPropertyStr(js, obj, "framerate_denominator", JS_NewInt32(js, spec->framerate_denominator));
|
||||
JS_SetPropertyUint32(js, arr, i, obj);
|
||||
JS_SetPropertyNumber(js, arr, i, obj);
|
||||
}
|
||||
SDL_free(specs);
|
||||
return arr;
|
||||
JS_RETURN(arr);
|
||||
)
|
||||
|
||||
// SDL_GetCameraName(id) -> string
|
||||
@@ -129,14 +134,15 @@ JSC_CCALL(camera_get_format,
|
||||
SDL_Camera *camera = js2SDL_Camera(js, self);
|
||||
SDL_CameraSpec spec;
|
||||
if (!SDL_GetCameraFormat(camera, &spec)) return JS_NULL;
|
||||
|
||||
JSValue obj = JS_NewObject(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj, "format", SDL_PixelFormat2js(js, spec.format));
|
||||
JS_SetPropertyStr(js, obj, "width", JS_NewInt32(js, spec.width));
|
||||
JS_SetPropertyStr(js, obj, "height", JS_NewInt32(js, spec.height));
|
||||
JS_SetPropertyStr(js, obj, "framerate_numerator", JS_NewInt32(js, spec.framerate_numerator));
|
||||
JS_SetPropertyStr(js, obj, "framerate_denominator", JS_NewInt32(js, spec.framerate_denominator));
|
||||
return obj;
|
||||
JS_RETURN(obj);
|
||||
)
|
||||
|
||||
JSC_CCALL(camera_acquire_frame,
|
||||
@@ -144,11 +150,12 @@ JSC_CCALL(camera_acquire_frame,
|
||||
Uint64 timestamp;
|
||||
SDL_Surface *surface = SDL_AcquireCameraFrame(camera, ×tamp);
|
||||
if (!surface) return JS_NULL;
|
||||
|
||||
JSValue obj = JS_NewObject(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(obj, JS_NewObject(js));
|
||||
JS_SetPropertyStr(js, obj, "surface", SDL_Surface2js(js, surface));
|
||||
JS_SetPropertyStr(js, obj, "timestamp", JS_NewInt64(js, timestamp));
|
||||
return obj;
|
||||
JS_RETURN(obj);
|
||||
)
|
||||
|
||||
JSC_CCALL(camera_release_frame,
|
||||
@@ -187,9 +194,9 @@ static const JSCFunctionListEntry js_camera_funcs[] = {
|
||||
CELL_USE_INIT(
|
||||
SDL_Init(SDL_INIT_CAMERA);
|
||||
QJSCLASSPREP_FUNCS(SDL_Camera);
|
||||
|
||||
JSValue ret = JS_NewObject(js);
|
||||
JS_SetPropertyFunctionList(js, ret, js_camera_funcs, countof(js_camera_funcs));
|
||||
|
||||
return ret;
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(mod, JS_NewObject(js));
|
||||
JS_SetPropertyFunctionList(js, mod, js_camera_funcs, countof(js_camera_funcs));
|
||||
JS_RETURN(mod);
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user