Blender's GPU Accelerated UI, Decoupled from it's original codebase. Supports Rust, Python, JS, React, C & C++. Twice as good as GPUI
output size
Preetham Pemmasanic77be06dec42
diff --git a/kit/intern/image/anim.c b/kit/intern/image/anim.cindex 37302db..0276998 100644--- a/kit/intern/image/anim.c+++ b/kit/intern/image/anim.c@@ -70,7 +70,7 @@ BKImAnim *imb_anim_open(uint8_t *file, size_t size, const BKImageFit *target)a->file = file;a->size = size;a->frames = BK_MAX(1, info.frames);- a->state = codec->open(NULL, file, size, 0, 0, &a->info);+ a->state = codec->open(NULL, file, size, &a->info);if (!a->state || !imb_plan(target, a->info.w, a->info.h, 1, &a->plan)) {imb_anim_free(a); /* frees `file` too */return NULL;@@ -78,32 +78,19 @@ BKImAnim *imb_anim_open(uint8_t *file, size_t size, const BKImageFit *target)return a;}-/* Opens `a`'s streamed codec at its target (the plan's whole-frame size). */-static bool movie_start(BKImAnim *a)+/* A streamed codec decoding at `a`'s target: the whole frame at the plan's+ * size (validated here, at the codec boundary: even-sized NV12 frames). */+static bool movie_output(BKImAnim *a){BKImPlan plan;- if (a->info.src_w > 0 && !imb_plan(&a->target, a->info.src_w, a->info.src_h, 1, &plan)) {- return false; /* nothing of it shows */- }- const int want_w = a->info.src_w > 0 ? plan.fw : a->target.box_w;- const int want_h = a->info.src_h > 0 ? plan.fh : a->target.box_h;- BKImAnimInfo info;- memset(&info, 0, sizeof(info));- void *state = a->codec->open(a->path, NULL, 0, want_w, want_h, &info);- if (!state) {- return false;- }- if (info.w <= 0 || info.h <= 0 || (info.w | info.h) & 1 || info.w > BK_IMB_MAX_SIDE ||- info.h > BK_IMB_MAX_SIDE || info.src_w <= 0 || info.src_h <= 0 ||- !imb_plan(&a->target, info.src_w, info.src_h, 1, &plan))+ BKImAnimInfo info = a->info;+ if (!imb_plan(&a->target, info.src_w, info.src_h, 1, &plan) ||+ !a->codec->output(a->state, plan.fw, plan.fh, &info) || info.w <= 0 || info.h <= 0 ||+ (info.w | info.h) & 1 || info.w > BK_IMB_MAX_SIDE || info.h > BK_IMB_MAX_SIDE ||+ (info.format != BUI_PIXMAP_NV12_BT601 && info.format != BUI_PIXMAP_NV12_BT709)){- a->codec->close(state); /* validated at the codec boundary: frames are even-sized NV12 */return false;}- if (a->state) {- a->codec->close(a->state);- }- a->state = state;a->info = info;a->plan = plan;return true;@@ -128,7 +115,10 @@ BKImAnim *imb_movie_open(const char *path, const BKImageFit *target)memcpy(a->path, path, len + 1);a->ftype = BK_IMAGE_VIDEO;a->stream = imb_new_key();- if (!movie_start(a)) {+ a->state = codec->open(path, NULL, 0, &a->info);+ if (!a->state || a->info.src_w <= 0 || a->info.src_h <= 0 ||+ a->info.src_w > BK_IMB_MAX_SIDE || a->info.src_h > BK_IMB_MAX_SIDE || !movie_output(a))+ {imb_anim_free(a);a = NULL; /* the next backend may read it */}@@ -181,8 +171,8 @@ bool imb_anim_retarget(BKImAnim *a, const BKImageFit *target)return true;}}- else if (movie_start(a)) {- imb_anim_seek(a, a->pts); /* where it was */+ else if (movie_output(a)) {+ imb_anim_seek(a, a->pts); /* where it was (the decoder flushes at the new size) */return true;}a->target = old;diff --git a/kit/intern/image/format_webp.c b/kit/intern/image/format_webp.cindex 41cfcc6..de63780 100644--- a/kit/intern/image/format_webp.c+++ b/kit/intern/image/format_webp.c@@ -95,12 +95,9 @@ static void webp_close(void *state)MEM_freeN(a);}-static void *webp_open(const char *path, const uint8_t *mem, size_t size, int want_w, int want_h,- BKImAnimInfo *r_info)+static void *webp_open(const char *path, const uint8_t *mem, size_t size, BKImAnimInfo *r_info){(void)path;- (void)want_w;- (void)want_h;WebPAnimDecoderOptions opt;if (!WebPAnimDecoderOptionsInit(&opt)) {return NULL;@@ -158,6 +155,6 @@ static size_t webp_bytes(const void *state)return sizeof(*a) + 2 * sizeof(uint32_t) * (size_t)a->w * a->h; /* its canvas and previous */}-const BKImAnimCodec imb_webp_codec = {"webp", false, imb_webp_animated, webp_open, webp_next, webp_seek, webp_bytes, webp_close};+const BKImAnimCodec imb_webp_codec = {"webp", false, imb_webp_animated, webp_open, NULL, webp_next, webp_seek, webp_bytes, webp_close};/** \} */diff --git a/kit/intern/image/format_wuffs.c b/kit/intern/image/format_wuffs.cindex 7acb33a..d1cdd5c 100644--- a/kit/intern/image/format_wuffs.c+++ b/kit/intern/image/format_wuffs.c@@ -272,12 +272,9 @@ static void gif_close(void *state)MEM_freeN(g);}-static void *gif_open(const char *path, const uint8_t *mem, size_t size, int want_w, int want_h,- BKImAnimInfo *r_info)+static void *gif_open(const char *path, const uint8_t *mem, size_t size, BKImAnimInfo *r_info){(void)path;- (void)want_w;- (void)want_h;GifAnim *g = (GifAnim *)MEM_callocN(sizeof(GifAnim), "GifAnim");g->mem = mem;g->size = size;@@ -363,6 +360,6 @@ static size_t gif_bytes(const void *state)return sizeof(*g) + (size_t)g->wl + 2 * sizeof(uint32_t) * (size_t)g->w * g->h;}-const BKImAnimCodec imb_gif_codec = {"gif", false, imb_is_a_gif, gif_open, gif_next, gif_seek, gif_bytes, gif_close};+const BKImAnimCodec imb_gif_codec = {"gif", false, imb_is_a_gif, gif_open, NULL, gif_next, gif_seek, gif_bytes, gif_close};/** \} */diff --git a/kit/intern/image/image.h b/kit/intern/image/image.hindex 992cf4a..57502e4 100644--- a/kit/intern/image/image.h+++ b/kit/intern/image/image.h@@ -142,7 +142,7 @@ uint8_t *imb_read_file(const char *path, size_t max, size_t *r_size);typedef struct BKImAnimInfo {int w, h; /* the frames' size: the canvas (in-memory codecs) or what a- * streamed codec decodes to (about the size asked, even) */+ * streamed codec decodes to (`output`: even, about the size asked) */int src_w, src_h; /* intrinsic (display) size */int format; /* BUI_PIXMAP_* of the frames */int loops; /* plays the file asks for, 0 = forever */@@ -156,11 +156,13 @@ typedef struct BKImAnimCodec {bool streamed;/* The file starts like one this codec reads (a few dozen bytes). */bool (*is_a)(const uint8_t *head, size_t size);- /* `path` (streamed) or `mem` (kept by the caller while open). want_w x- * want_h is the size frames are drawn at: a hint (video scales to it on- * the decoder, in hardware where there is one). */- void *(*open)(const char *path, const uint8_t *mem, size_t size, int want_w, int want_h,- BKImAnimInfo *r_info);+ /* `path` (streamed) or `mem` (kept by the caller while open). Fills the+ * info: a streamed codec its intrinsic size, duration and format. */+ void *(*open)(const char *path, const uint8_t *mem, size_t size, BKImAnimInfo *r_info);+ /* Streamed codecs: decode whole frames at about w x h from now on (the+ * size drawn: video scales on the decoder, in hardware where there is+ * one), setting info->w, h. In-memory codecs: NULL (their canvas). */+ bool (*output)(void *state, int w, int h, BKImAnimInfo *r_info);/* 1 with the next frame in `dst` (the info's size and format), its time* and duration in seconds (pts < 0: unknown, frames follow each other);* 0 past the last; -1 on errors. */diff --git a/kit/intern/image/movie_mf.c b/kit/intern/image/movie_mf.cindex 3cf32a6..502205a 100644--- a/kit/intern/image/movie_mf.c+++ b/kit/intern/image/movie_mf.c@@ -144,6 +144,8 @@ static bool mf_ready(void)typedef struct MFMovie {IMFSourceReader *reader;int w, h; /* output frame (NV12) */+ int src_w, src_h; /* the coded frame */+ bool interlaced;double frame_dur; /* from the frame rate, for samples without a duration */} MFMovie;@@ -223,8 +225,7 @@ static IMFSourceReader *open_reader(const char *path)return reader;}-static void *mf_open(const char *path, const uint8_t *mem, size_t size, int want_w, int want_h,- BKImAnimInfo *r_info)+static void *mf_open(const char *path, const uint8_t *mem, size_t size, BKImAnimInfo *r_info){(void)mem;(void)size;@@ -252,27 +253,14 @@ static void *mf_open(const char *path, const uint8_t *mem, size_t size, int wantIMFMediaType_GetUINT32(native, &MF_MT_YUV_MATRIX, &matrix);IMFMediaType_GetUINT32(native, &MF_MT_INTERLACE_MODE, &interlace);IMFMediaType_Release(native);- int src_w = (int)(fs >> 32), src_h = (int)(fs & 0xFFFFFFFF);+ m->src_w = (int)(fs >> 32);+ m->src_h = (int)(fs & 0xFFFFFFFF);+ int src_w = m->src_w, src_h = m->src_h;const UINT32 pn = (UINT32)(par >> 32), pd = (UINT32)par;if (has_par && pn && pd && pn != pd) {src_w = (int)((double)src_w * pn / pd + 0.5);}- if (src_w <= 0 || src_h <= 0 || src_w > BK_IMB_MAX_SIDE || src_h > BK_IMB_MAX_SIDE) {- mf_close(m);- return NULL;- }- /* decode at the size asked (never above the source), even for NV12 */- int out_w = want_w > 0 ? BK_MIN(want_w, src_w) : src_w;- int out_h = want_h > 0 ? BK_MIN(want_h, src_h) : src_h;- out_w = BK_MAX(2, out_w & ~1);- out_h = BK_MAX(2, out_h & ~1);- const bool interlaced = interlace != MFVideoInterlace_Progressive;- if (!set_output(m, out_w, out_h, interlaced) &&- !set_output(m, BK_MAX(2, src_w & ~1), BK_MAX(2, src_h & ~1), interlaced))- {- mf_close(m); /* no NV12 output: no decoder for this format */- return NULL;- }+ m->interlaced = interlace != MFVideoInterlace_Progressive;const UINT32 rn = (UINT32)(rate >> 32), rd = (UINT32)rate;m->frame_dur = rn && rd ? (double)rd / rn : 1.0 / 30.0;PROPVARIANT dur;@@ -283,8 +271,6 @@ static void *mf_open(const char *path, const uint8_t *mem, size_t size, int wantdur.vt == VT_UI8 ?(double)dur.uhVal.QuadPart / 1e7 :0.0;- r_info->w = m->w;- r_info->h = m->h;r_info->src_w = src_w;r_info->src_h = src_h;r_info->loops = 1;@@ -295,6 +281,23 @@ static void *mf_open(const char *path, const uint8_t *mem, size_t size, int wantreturn m;}+static bool mf_output(void *state, int w, int h, BKImAnimInfo *r_info)+{+ MFMovie *m = (MFMovie *)state;+ /* the size asked (never above the coded frame), even for NV12; the+ * coded size when the video processor can't scale (no NV12 at all: no+ * decoder for this format) */+ const int out_w = BK_MAX(2, BK_MIN(w, m->src_w) & ~1), out_h = BK_MAX(2, BK_MIN(h, m->src_h) & ~1);+ if (!set_output(m, out_w, out_h, m->interlaced) &&+ !set_output(m, BK_MAX(2, m->src_w & ~1), BK_MAX(2, m->src_h & ~1), m->interlaced))+ {+ return false;+ }+ r_info->w = m->w;+ r_info->h = m->h;+ return true;+}+/* The frame's planes into `dst` (NV12, its size). */static bool copy_frame(MFMovie *m, IMFSample *sample, BKImBuf *dst){@@ -413,7 +416,7 @@ static size_t mf_bytes(const void *state)}const BKImAnimCodec imb_movie_mf = {- "mf", true, imb_is_a_movie, mf_open, mf_next, mf_seek, mf_bytes, mf_close};+ "mf", true, imb_is_a_movie, mf_open, mf_output, mf_next, mf_seek, mf_bytes, mf_close};/** \} */