@@ -40,22 +40,56 @@ static int sliced_proc(int id, int index, int jobs, void *cookie)
4040 struct sliced_desc * ctx = ((struct sliced_desc * ) cookie );
4141 int slice_line_start ,
4242 slice_height = mlt_slices_size_slice (jobs , index , ctx -> image -> height , & slice_line_start );
43- int min = ctx -> full_range ? 0 : 16 ;
44- int max_luma = ctx -> full_range ? 255 : 235 ;
45- int max_chroma = ctx -> full_range ? 255 : 240 ;
4643
4744 // Only process if level is something other than 1
48- if (ctx -> level != 1.0 && ctx -> image -> format == mlt_image_yuv422 ) {
45+ if (ctx -> level != 1.0 ) {
4946 int32_t m = ctx -> level * (1 << 16 );
50- int32_t n = 128 * ((1 << 16 ) - m );
51- for (int line = 0 ; line < slice_height ; line ++ ) {
52- uint8_t * p = ctx -> image -> planes [0 ]
53- + ((slice_line_start + line ) * ctx -> image -> strides [0 ]);
54- for (int pixel = 0 ; pixel < ctx -> image -> width ; pixel ++ ) {
55- * p = CLAMP ((* p * m ) >> 16 , min , max_luma );
56- p ++ ;
57- * p = CLAMP ((* p * m + n ) >> 16 , min , max_chroma );
58- p ++ ;
47+ if (ctx -> image -> format == mlt_image_yuv422 ) {
48+ int32_t n = 128 * ((1 << 16 ) - m );
49+ int min = ctx -> full_range ? 0 : 16 ;
50+ int max_luma = ctx -> full_range ? 255 : 235 ;
51+ int max_chroma = ctx -> full_range ? 255 : 240 ;
52+ for (int line = 0 ; line < slice_height ; line ++ ) {
53+ uint8_t * p = ctx -> image -> planes [0 ]
54+ + ((slice_line_start + line ) * ctx -> image -> strides [0 ]);
55+ for (int pixel = 0 ; pixel < ctx -> image -> width ; pixel ++ ) {
56+ p [0 ] = CLAMP ((* p * m ) >> 16 , min , max_luma );
57+ p [0 ] = CLAMP ((* p * m + n ) >> 16 , min , max_chroma );
58+ p += 2 ;
59+ }
60+ }
61+ } else if (ctx -> image -> format == mlt_image_rgba ) {
62+ for (int line = 0 ; line < slice_height ; line ++ ) {
63+ uint8_t * p = ctx -> image -> planes [0 ]
64+ + ((slice_line_start + line ) * ctx -> image -> strides [0 ]);
65+ for (int pixel = 0 ; pixel < ctx -> image -> width ; pixel ++ ) {
66+ p [0 ] = CLAMP ((p [0 ] * m ) >> 16 , 0 , 255 );
67+ p [1 ] = CLAMP ((p [1 ] * m ) >> 16 , 0 , 255 );
68+ p [2 ] = CLAMP ((p [2 ] * m ) >> 16 , 0 , 255 );
69+ p += 4 ;
70+ }
71+ }
72+ } else if (ctx -> image -> format == mlt_image_rgb ) {
73+ for (int line = 0 ; line < slice_height ; line ++ ) {
74+ uint8_t * p = ctx -> image -> planes [0 ]
75+ + ((slice_line_start + line ) * ctx -> image -> strides [0 ]);
76+ for (int pixel = 0 ; pixel < ctx -> image -> width ; pixel ++ ) {
77+ p [0 ] = CLAMP ((p [0 ] * m ) >> 16 , 0 , 255 );
78+ p [1 ] = CLAMP ((p [1 ] * m ) >> 16 , 0 , 255 );
79+ p [2 ] = CLAMP ((p [2 ] * m ) >> 16 , 0 , 255 );
80+ p += 3 ;
81+ }
82+ }
83+ } else if (ctx -> image -> format == mlt_image_rgba64 ) {
84+ for (int row = 0 ; row < slice_height ; row ++ ) {
85+ uint16_t * p = (uint16_t * ) ctx -> image -> planes [0 ]
86+ + ((slice_line_start + row ) * ctx -> image -> strides [0 ] / 2 );
87+ for (int pixel = 0 ; pixel < ctx -> image -> width ; pixel ++ ) {
88+ p [0 ] = CLAMP (round ((double ) p [0 ] * ctx -> level ), 0 , 65535 );
89+ p [1 ] = CLAMP (round ((double ) p [1 ] * ctx -> level ), 0 , 65535 );
90+ p [2 ] = CLAMP (round ((double ) p [2 ] * ctx -> level ), 0 , 65535 );
91+ p += 4 ;
92+ }
5993 }
6094 }
6195 }
@@ -68,25 +102,25 @@ static int sliced_proc(int id, int index, int jobs, void *cookie)
68102 uint8_t * p = ctx -> image -> planes [0 ]
69103 + ((slice_line_start + line ) * ctx -> image -> strides [0 ]) + 3 ;
70104 for (int pixel = 0 ; pixel < ctx -> image -> width ; pixel ++ ) {
71- * p = ( * p * m ) >> 16 ;
105+ * p = CLAMP (( * p * m ) >> 16 , 0 , 255 ) ;
72106 p += 4 ;
73107 }
74108 }
75109 } else if (ctx -> image -> format == mlt_image_rgba64 ) {
76110 for (int row = 0 ; row < slice_height ; row ++ ) {
77111 uint16_t * p = (uint16_t * ) ctx -> image -> planes [0 ]
78- + ((slice_line_start + row ) * ctx -> image -> strides [0 ]) + 3 ;
112+ + ((slice_line_start + row ) * ctx -> image -> strides [0 ] / 2 ) + 3 ;
79113 int components_in_row = ctx -> image -> width * 4 ;
80114 for (int col = 0 ; col < components_in_row ; col += 4 ) {
81- p [col ] = ( p [col ] * m ) >> 16 ;
115+ p [col ] = CLAMP ( round (( double ) p [col ] * ctx -> alpha_level ), 0 , 65535 ) ;
82116 }
83117 }
84- } else {
118+ } else if ( ctx -> image -> planes [ 3 ]) {
85119 for (int line = 0 ; line < slice_height ; line ++ ) {
86120 uint8_t * p = ctx -> image -> planes [3 ]
87121 + ((slice_line_start + line ) * ctx -> image -> strides [3 ]);
88122 for (int pixel = 0 ; pixel < ctx -> image -> width ; pixel ++ ) {
89- * p = ( * p * m ) >> 16 ;
123+ * p = CLAMP (( * p * m ) >> 16 , 0 , 255 ) ;
90124 p ++ ;
91125 }
92126 }
@@ -130,13 +164,35 @@ static int filter_get_image(mlt_frame frame,
130164 }
131165
132166 // Do not cause an image conversion unless there is real work to do.
133- if (level != 1.0 )
134- * format = mlt_image_yuv422 ;
167+ if (level != 1.0 ) {
168+ switch (* format ) {
169+ case mlt_image_rgb :
170+ case mlt_image_rgba :
171+ case mlt_image_rgba64 :
172+ case mlt_image_yuv422 :
173+ break ;
174+ case mlt_image_movit :
175+ case mlt_image_opengl_texture :
176+ * format = mlt_image_rgba ;
177+ break ;
178+ case mlt_image_none :
179+ case mlt_image_invalid :
180+ case mlt_image_yuv420p :
181+ case mlt_image_yuv422p16 :
182+ case mlt_image_yuv420p10 :
183+ case mlt_image_yuv444p10 :
184+ * format = mlt_image_yuv422 ;
185+ break ;
186+ }
187+ }
135188
136189 // Get the image
137190 int error = mlt_frame_get_image (frame , image , format , width , height , 1 );
138191
139- level = (* format == mlt_image_yuv422 ) ? level : 1.0 ;
192+ if (* format != mlt_image_rgb && * format != mlt_image_rgba && * format != mlt_image_rgba64
193+ && * format != mlt_image_yuv422 )
194+ level = 1.0 ;
195+
140196 alpha_level = mlt_properties_get (properties , "alpha" )
141197 ? MIN (mlt_properties_anim_get_double (properties , "alpha" , position , length ),
142198 1.0 )
0 commit comments