Skip to content

Commit ce99364

Browse files
committed
Add placebo.convert filter
- Introduced new `mlt_image_private` format for module internal use. - Improved placebo texture reuse across filters.
1 parent 3b112bb commit ce99364

20 files changed

Lines changed: 352 additions & 202 deletions

src/framework/mlt_frame.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ static int generate_test_image(mlt_properties properties,
448448
case mlt_image_none:
449449
case mlt_image_movit:
450450
case mlt_image_opengl_texture:
451+
case mlt_image_private:
451452
*format = mlt_image_yuv422;
452453
break;
453454
case mlt_image_invalid:
@@ -1113,15 +1114,13 @@ mlt_frame mlt_frame_clone(mlt_frame self, int is_deep)
11131114
}
11141115
size = 0;
11151116
data = mlt_properties_get_data(properties, "image", &size);
1116-
if (data && mlt_image_movit != mlt_properties_get_int(properties, "format")) {
1117+
mlt_image_format format = mlt_properties_get_int(properties, "format");
1118+
if (data && format != mlt_image_movit && format != mlt_image_private) {
11171119
int width = mlt_properties_get_int(properties, "width");
11181120
int height = mlt_properties_get_int(properties, "height");
11191121

11201122
if (!size)
1121-
size = mlt_image_format_size(mlt_properties_get_int(properties, "format"),
1122-
width,
1123-
height,
1124-
NULL);
1123+
size = mlt_image_format_size(format, width, height, NULL);
11251124
copy = mlt_pool_alloc(size);
11261125
memcpy(copy, data, size);
11271126
mlt_properties_set_data(new_props, "image", copy, size, mlt_pool_release, NULL);
@@ -1255,15 +1254,13 @@ mlt_frame mlt_frame_clone_image(mlt_frame self, int is_deep)
12551254

12561255
if (is_deep) {
12571256
data = mlt_properties_get_data(properties, "image", &size);
1258-
if (data && mlt_image_movit != mlt_properties_get_int(properties, "format")) {
1257+
mlt_image_format format = mlt_properties_get_int(properties, "format");
1258+
if (data && format != mlt_image_movit && format != mlt_image_private) {
12591259
int width = mlt_properties_get_int(properties, "width");
12601260
int height = mlt_properties_get_int(properties, "height");
12611261

12621262
if (!size)
1263-
size = mlt_image_format_size(mlt_properties_get_int(properties, "format"),
1264-
width,
1265-
height,
1266-
NULL);
1263+
size = mlt_image_format_size(format, width, height, NULL);
12671264
copy = mlt_pool_alloc(size);
12681265
memcpy(copy, data, size);
12691266
mlt_properties_set_data(new_props, "image", copy, size, mlt_pool_release, NULL);

src/framework/mlt_image.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ int mlt_image_calculate_size(mlt_image self)
188188
return self->width * self->height * 3 / 2;
189189
case mlt_image_movit:
190190
case mlt_image_opengl_texture:
191-
return 4;
191+
case mlt_image_private:
192+
return sizeof(void *);
192193
case mlt_image_yuv422p16:
193194
return self->width * self->height * 4;
194195
case mlt_image_yuv420p10:
@@ -228,6 +229,8 @@ const char *mlt_image_format_name(mlt_image_format format)
228229
return "glsl";
229230
case mlt_image_opengl_texture:
230231
return "opengl_texture";
232+
case mlt_image_private:
233+
return "private";
231234
case mlt_image_yuv422p16:
232235
return "yuv422p16";
233236
case mlt_image_yuv420p10:
@@ -489,6 +492,7 @@ mlt_colorspace mlt_image_default_colorspace(mlt_image_format format, int height)
489492
case mlt_image_rgba64:
490493
case mlt_image_movit:
491494
case mlt_image_opengl_texture:
495+
case mlt_image_private:
492496
colorspace = mlt_colorspace_rgb;
493497
break;
494498
case mlt_image_yuv422:
@@ -605,6 +609,7 @@ void mlt_image_fill_black(mlt_image self)
605609
case mlt_image_none:
606610
case mlt_image_movit:
607611
case mlt_image_opengl_texture:
612+
case mlt_image_private:
608613
return;
609614
case mlt_image_rgb:
610615
case mlt_image_rgba:
@@ -693,6 +698,7 @@ void mlt_image_fill_checkerboard(mlt_image self, double sample_aspect_ratio)
693698
case mlt_image_none:
694699
case mlt_image_movit:
695700
case mlt_image_opengl_texture:
701+
case mlt_image_private:
696702
return;
697703
case mlt_image_rgb:
698704
case mlt_image_rgba: {
@@ -798,6 +804,7 @@ void mlt_image_fill_white(mlt_image self, int full_range)
798804
case mlt_image_none:
799805
case mlt_image_movit:
800806
case mlt_image_opengl_texture:
807+
case mlt_image_private:
801808
return;
802809
case mlt_image_rgb:
803810
case mlt_image_rgba:
@@ -952,9 +959,10 @@ int mlt_image_format_size(mlt_image_format format, int width, int height, int *b
952959
return width * height * 3 / 2;
953960
case mlt_image_movit:
954961
case mlt_image_opengl_texture:
962+
case mlt_image_private:
955963
if (bpp)
956964
*bpp = 0;
957-
return 4;
965+
return sizeof(void *);
958966
case mlt_image_yuv422p16:
959967
if (bpp)
960968
*bpp = 4;

src/framework/mlt_types.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* \file mlt_types.h
33
* \brief Provides forward definitions of all public types
44
*
5-
* Copyright (C) 2003-2025 Meltytech, LLC
5+
* Copyright (C) 2003-2026 Meltytech, LLC
66
*
77
* This library is free software; you can redistribute it and/or
88
* modify it under the terms of the GNU Lesser General Public
@@ -49,7 +49,8 @@ typedef enum {
4949
mlt_image_yuv420p10, /**< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian */
5050
mlt_image_yuv444p10, /**< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian */
5151
mlt_image_rgba64, /**< 16-bit RGB with alpha channel */
52-
mlt_image_invalid
52+
mlt_image_invalid,
53+
mlt_image_private /**< for module internal use only */
5354
} mlt_image_format;
5455

5556
/** The set of supported audio formats */

src/modules/avformat/common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ int mlt_to_av_image_format(mlt_image_format format)
322322
return AV_PIX_FMT_RGBA64LE;
323323
case mlt_image_movit:
324324
case mlt_image_opengl_texture:
325+
case mlt_image_private:
325326
case mlt_image_invalid:
326327
mlt_log_error(NULL,
327328
"[filter_avfilter] Unexpected image format: %s\n",
@@ -339,6 +340,7 @@ mlt_image_format mlt_get_supported_image_format(mlt_image_format format)
339340
case mlt_image_none:
340341
case mlt_image_movit:
341342
case mlt_image_opengl_texture:
343+
case mlt_image_private:
342344
case mlt_image_rgba:
343345
return mlt_image_rgba;
344346
case mlt_image_rgb:

src/modules/avformat/filter_avcolour_space.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ static int convert_image(mlt_frame frame,
153153
mlt_properties_clear(properties, "convert_image_height");
154154

155155
if (*format != output_format || out_width) {
156+
if (*format == mlt_image_none || *format == mlt_image_movit
157+
|| *format == mlt_image_opengl_texture || *format == mlt_image_private
158+
|| *format == mlt_image_invalid || output_format == mlt_image_none
159+
|| output_format == mlt_image_movit || output_format == mlt_image_opengl_texture
160+
|| output_format == mlt_image_private || output_format == mlt_image_invalid) {
161+
return 1;
162+
}
163+
156164
mlt_profile profile = mlt_service_profile(
157165
MLT_PRODUCER_SERVICE(mlt_frame_get_original_producer(frame)));
158166
int width = mlt_properties_get_int(properties, "width");

src/modules/avformat/filter_sws_colortransform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int filter_get_image(mlt_frame frame,
5454

5555
// Only process if we have a valid image
5656
if (!*image || *format == mlt_image_none || *format == mlt_image_movit
57-
|| *format == mlt_image_opengl_texture)
57+
|| *format == mlt_image_opengl_texture || *format == mlt_image_private)
5858
return 0;
5959

6060
// Get the current color transfer characteristics

src/modules/avformat/link_avdeinterlace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static mlt_image_format validate_format(mlt_image_format format)
8282
case mlt_image_none:
8383
case mlt_image_movit:
8484
case mlt_image_opengl_texture:
85+
case mlt_image_private:
8586
case mlt_image_invalid:
8687
ret_format = mlt_image_yuv422;
8788
break;

src/modules/avformat/producer_avformat.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,9 @@ static mlt_image_format pick_image_format(enum AVPixelFormat pix_fmt,
827827
mlt_image_format current_format)
828828
{
829829
if (current_format == mlt_image_none || current_format == mlt_image_movit
830-
|| pix_fmt == AV_PIX_FMT_ARGB || pix_fmt == AV_PIX_FMT_RGBA || pix_fmt == AV_PIX_FMT_ABGR
831-
|| pix_fmt == AV_PIX_FMT_BGRA || pix_fmt == AV_PIX_FMT_GBRAP) {
830+
|| current_format == mlt_image_private || pix_fmt == AV_PIX_FMT_ARGB
831+
|| pix_fmt == AV_PIX_FMT_RGBA || pix_fmt == AV_PIX_FMT_ABGR || pix_fmt == AV_PIX_FMT_BGRA
832+
|| pix_fmt == AV_PIX_FMT_GBRAP) {
832833
switch (pix_fmt) {
833834
case AV_PIX_FMT_ARGB:
834835
case AV_PIX_FMT_RGBA:
@@ -2516,6 +2517,7 @@ static void convert_image(producer_avformat self,
25162517
case mlt_image_yuv422:
25172518
case mlt_image_movit:
25182519
case mlt_image_opengl_texture:
2520+
case mlt_image_private:
25192521
case mlt_image_invalid:
25202522
break;
25212523
}

src/modules/core/filter_brightness.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ static int filter_get_image(mlt_frame frame,
175175
break;
176176
case mlt_image_movit:
177177
case mlt_image_opengl_texture:
178+
case mlt_image_private:
178179
*format = mlt_image_rgba;
179180
break;
180181
case mlt_image_none:

src/modules/core/filter_color_transform.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static void ensure_color_properties(mlt_filter self, mlt_frame frame)
147147
case mlt_image_rgba64:
148148
case mlt_image_movit:
149149
case mlt_image_opengl_texture:
150+
case mlt_image_private:
150151
full_range = 1;
151152
break;
152153
case mlt_image_yuv422:
@@ -182,7 +183,8 @@ static int filter_get_image(mlt_frame frame,
182183
mlt_properties filter_properties = MLT_FILTER_PROPERTIES(self);
183184
mlt_image_format requested_format = *format;
184185
int ret = mlt_frame_get_image(frame, image, format, width, height, writable);
185-
if (ret || requested_format == mlt_image_movit || requested_format == mlt_image_none)
186+
if (ret || requested_format == mlt_image_movit || requested_format == mlt_image_private
187+
|| requested_format == mlt_image_none)
186188
return ret;
187189

188190
const char *out_trc_str = mlt_properties_get(filter_properties, "force_trc");

0 commit comments

Comments
 (0)