/src/gstreamer/subprojects/gst-plugins-base/gst-libs/gst/video/video-converter.c
Line | Count | Source |
1 | | /* GStreamer |
2 | | * Copyright (C) 2010 David Schleef <ds@schleef.org> |
3 | | * Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk> |
4 | | * |
5 | | * This library is free software; you can redistribute it and/or |
6 | | * modify it under the terms of the GNU Library General Public |
7 | | * License as published by the Free Software Foundation; either |
8 | | * version 2 of the License, or (at your option) any later version. |
9 | | * |
10 | | * This library is distributed in the hope that it will be useful, |
11 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | | * Library General Public License for more details. |
14 | | * |
15 | | * You should have received a copy of the GNU Library General Public |
16 | | * License along with this library; if not, write to the |
17 | | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
18 | | * Boston, MA 02110-1301, USA. |
19 | | */ |
20 | | |
21 | | #ifdef HAVE_CONFIG_H |
22 | | #include "config.h" |
23 | | #endif |
24 | | |
25 | | #if 0 |
26 | | #ifdef HAVE_PTHREAD |
27 | | #define _GNU_SOURCE |
28 | | #include <pthread.h> |
29 | | #endif |
30 | | #endif |
31 | | |
32 | | #include "video-converter.h" |
33 | | |
34 | | #include <glib.h> |
35 | | #include <string.h> |
36 | | #include <math.h> |
37 | | #include <gst/base/base.h> |
38 | | |
39 | | #include "video-orc.h" |
40 | | #include "gstvideoutilsprivate.h" |
41 | | |
42 | | /** |
43 | | * SECTION:videoconverter |
44 | | * @title: GstVideoConverter |
45 | | * @short_description: Generic video conversion |
46 | | * |
47 | | * This object is used to convert video frames from one format to another. |
48 | | * The object can perform conversion of: |
49 | | * |
50 | | * * video format |
51 | | * * video colorspace |
52 | | * * chroma-siting |
53 | | * * video size |
54 | | * |
55 | | */ |
56 | | |
57 | | /* |
58 | | * (a) unpack |
59 | | * (b) chroma upsample |
60 | | * (c) (convert Y'CbCr to R'G'B') |
61 | | * (d) gamma decode |
62 | | * (e) downscale |
63 | | * (f) colorspace convert through XYZ |
64 | | * (g) upscale |
65 | | * (h) gamma encode |
66 | | * (i) (convert R'G'B' to Y'CbCr) |
67 | | * (j) chroma downsample |
68 | | * (k) pack |
69 | | * |
70 | | * quality options |
71 | | * |
72 | | * (a) range truncate, range expand |
73 | | * (b) full upsample, 1-1 non-cosited upsample, no upsample |
74 | | * (c) 8 bits, 16 bits |
75 | | * (d) |
76 | | * (e) 8 bits, 16 bits |
77 | | * (f) 8 bits, 16 bits |
78 | | * (g) 8 bits, 16 bits |
79 | | * (h) |
80 | | * (i) 8 bits, 16 bits |
81 | | * (j) 1-1 cosited downsample, no downsample |
82 | | * (k) |
83 | | * |
84 | | * |
85 | | * 1 : a -> -> -> -> e -> f -> g -> -> -> -> k |
86 | | * 2 : a -> -> -> -> e -> f* -> g -> -> -> -> k |
87 | | * 3 : a -> -> -> -> e* -> f* -> g* -> -> -> -> k |
88 | | * 4 : a -> b -> -> -> e -> f -> g -> -> -> j -> k |
89 | | * 5 : a -> b -> -> -> e* -> f* -> g* -> -> -> j -> k |
90 | | * 6 : a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> k |
91 | | * 7 : a -> b -> c -> d -> e* -> f* -> g* -> h -> i -> j -> k |
92 | | * |
93 | | * 8 : a -> b -> c -> d -> e* -> f* -> g* -> h -> i -> j -> k |
94 | | * 9 : a -> b -> c -> d -> e* -> f* -> g* -> h -> i -> j -> k |
95 | | * 10 : a -> b -> c -> d -> e* -> f* -> g* -> h -> i -> j -> k |
96 | | */ |
97 | | |
98 | | #ifndef GST_DISABLE_GST_DEBUG |
99 | | #define GST_CAT_DEFAULT ensure_debug_category() |
100 | | static GstDebugCategory * |
101 | | ensure_debug_category (void) |
102 | 0 | { |
103 | 0 | static gsize cat_gonce = 0; |
104 | |
|
105 | 0 | if (g_once_init_enter (&cat_gonce)) { |
106 | 0 | gsize cat_done; |
107 | |
|
108 | 0 | cat_done = (gsize) _gst_debug_category_new ("video-converter", 0, |
109 | 0 | "video-converter object"); |
110 | |
|
111 | 0 | g_once_init_leave (&cat_gonce, cat_done); |
112 | 0 | } |
113 | |
|
114 | 0 | return (GstDebugCategory *) cat_gonce; |
115 | 0 | } |
116 | | #else |
117 | | #define ensure_debug_category() /* NOOP */ |
118 | | #endif /* GST_DISABLE_GST_DEBUG */ |
119 | | |
120 | | typedef void (*GstParallelizedTaskFunc) (gpointer user_data); |
121 | | |
122 | | typedef struct _GstParallelizedTaskRunner GstParallelizedTaskRunner; |
123 | | typedef struct _GstParallelizedWorkItem GstParallelizedWorkItem; |
124 | | |
125 | | struct _GstParallelizedWorkItem |
126 | | { |
127 | | GstParallelizedTaskRunner *self; |
128 | | GstParallelizedTaskFunc func; |
129 | | gpointer user_data; |
130 | | }; |
131 | | |
132 | | struct _GstParallelizedTaskRunner |
133 | | { |
134 | | GstTaskPool *pool; |
135 | | gboolean own_pool; |
136 | | guint n_threads; |
137 | | |
138 | | GstVecDeque *tasks; |
139 | | GstVecDeque *work_items; |
140 | | |
141 | | GMutex lock; |
142 | | |
143 | | gboolean async_tasks; |
144 | | }; |
145 | | |
146 | | static void |
147 | | gst_parallelized_task_thread_func (gpointer data) |
148 | 0 | { |
149 | 0 | GstParallelizedTaskRunner *runner = data; |
150 | 0 | GstParallelizedWorkItem *work_item; |
151 | |
|
152 | 0 | g_mutex_lock (&runner->lock); |
153 | 0 | work_item = gst_vec_deque_pop_head (runner->work_items); |
154 | 0 | g_mutex_unlock (&runner->lock); |
155 | |
|
156 | 0 | g_assert (work_item != NULL); |
157 | 0 | g_assert (work_item->func != NULL); |
158 | | |
159 | | |
160 | 0 | work_item->func (work_item->user_data); |
161 | 0 | if (runner->async_tasks) |
162 | 0 | g_free (work_item); |
163 | 0 | } |
164 | | |
165 | | static void |
166 | | gst_parallelized_task_runner_join (GstParallelizedTaskRunner * self) |
167 | 4.56k | { |
168 | 4.56k | gboolean joined = FALSE; |
169 | | |
170 | 9.12k | while (!joined) { |
171 | 4.56k | g_mutex_lock (&self->lock); |
172 | 4.56k | if (!(joined = gst_vec_deque_is_empty (self->tasks))) { |
173 | 0 | gpointer task = gst_vec_deque_pop_head (self->tasks); |
174 | 0 | g_mutex_unlock (&self->lock); |
175 | 0 | gst_task_pool_join (self->pool, task); |
176 | 4.56k | } else { |
177 | 4.56k | g_mutex_unlock (&self->lock); |
178 | 4.56k | } |
179 | 4.56k | } |
180 | 4.56k | } |
181 | | |
182 | | static void |
183 | | gst_parallelized_task_runner_free (GstParallelizedTaskRunner * self) |
184 | 2.08k | { |
185 | 2.08k | gst_parallelized_task_runner_join (self); |
186 | | |
187 | 2.08k | gst_vec_deque_free (self->work_items); |
188 | 2.08k | gst_vec_deque_free (self->tasks); |
189 | 2.08k | if (self->own_pool) |
190 | 2.08k | gst_task_pool_cleanup (self->pool); |
191 | 2.08k | gst_object_unref (self->pool); |
192 | 2.08k | g_mutex_clear (&self->lock); |
193 | 2.08k | g_free (self); |
194 | 2.08k | } |
195 | | |
196 | | static GstParallelizedTaskRunner * |
197 | | gst_parallelized_task_runner_new (guint n_threads, GstTaskPool * pool, |
198 | | gboolean async_tasks) |
199 | 2.08k | { |
200 | 2.08k | GstParallelizedTaskRunner *self; |
201 | | |
202 | 2.08k | if (n_threads == 0) |
203 | 0 | n_threads = g_get_num_processors (); |
204 | | |
205 | 2.08k | self = g_new0 (GstParallelizedTaskRunner, 1); |
206 | | |
207 | 2.08k | if (pool) { |
208 | 0 | self->pool = g_object_ref (pool); |
209 | 0 | self->own_pool = FALSE; |
210 | | |
211 | | /* No reason to split up the work between more threads than the |
212 | | * pool can spawn */ |
213 | 0 | if (GST_IS_SHARED_TASK_POOL (pool)) |
214 | 0 | n_threads = |
215 | 0 | MIN (n_threads, |
216 | 0 | gst_shared_task_pool_get_max_threads (GST_SHARED_TASK_POOL (pool))); |
217 | 2.08k | } else { |
218 | 2.08k | self->pool = gst_shared_task_pool_new (); |
219 | 2.08k | self->own_pool = TRUE; |
220 | 2.08k | gst_shared_task_pool_set_max_threads (GST_SHARED_TASK_POOL (self->pool), |
221 | 2.08k | n_threads); |
222 | 2.08k | gst_task_pool_prepare (self->pool, NULL); |
223 | 2.08k | } |
224 | | |
225 | 2.08k | self->tasks = gst_vec_deque_new (n_threads); |
226 | 2.08k | self->work_items = gst_vec_deque_new (n_threads); |
227 | | |
228 | 2.08k | self->n_threads = n_threads; |
229 | | |
230 | 2.08k | g_mutex_init (&self->lock); |
231 | | |
232 | | /* Set when scheduling a job */ |
233 | 2.08k | self->async_tasks = async_tasks; |
234 | | |
235 | 2.08k | return self; |
236 | 2.08k | } |
237 | | |
238 | | static void |
239 | | gst_parallelized_task_runner_finish (GstParallelizedTaskRunner * self) |
240 | 2.47k | { |
241 | 2.47k | gst_parallelized_task_runner_join (self); |
242 | 2.47k | } |
243 | | |
244 | | static void |
245 | | gst_parallelized_task_runner_run (GstParallelizedTaskRunner * self, |
246 | | GstParallelizedTaskFunc func, gpointer * task_data) |
247 | 2.47k | { |
248 | 2.47k | guint n_threads = self->n_threads; |
249 | | |
250 | 2.47k | if (n_threads > 1 || self->async_tasks) { |
251 | 0 | guint i = 0; |
252 | 0 | g_mutex_lock (&self->lock); |
253 | 0 | if (!self->async_tasks) { |
254 | | /* if not async, perform one of the functions in the current thread */ |
255 | 0 | i = 1; |
256 | 0 | } |
257 | 0 | for (; i < n_threads; i++) { |
258 | 0 | gpointer task; |
259 | 0 | GstParallelizedWorkItem *work_item; |
260 | |
|
261 | 0 | if (!self->async_tasks) |
262 | 0 | work_item = g_newa (GstParallelizedWorkItem, 1); |
263 | 0 | else |
264 | 0 | work_item = g_new0 (GstParallelizedWorkItem, 1); |
265 | |
|
266 | 0 | work_item->self = self; |
267 | 0 | work_item->func = func; |
268 | 0 | work_item->user_data = task_data[i]; |
269 | 0 | gst_vec_deque_push_tail (self->work_items, work_item); |
270 | |
|
271 | 0 | task = |
272 | 0 | gst_task_pool_push (self->pool, gst_parallelized_task_thread_func, |
273 | 0 | self, NULL); |
274 | | |
275 | | /* The return value of push() is unfortunately nullable, and we can't deal with that */ |
276 | 0 | g_assert (task != NULL); |
277 | 0 | gst_vec_deque_push_tail (self->tasks, task); |
278 | 0 | } |
279 | 0 | g_mutex_unlock (&self->lock); |
280 | 0 | } |
281 | | |
282 | 2.47k | if (!self->async_tasks) { |
283 | 2.47k | func (task_data[0]); |
284 | | |
285 | 2.47k | gst_parallelized_task_runner_finish (self); |
286 | 2.47k | } |
287 | 2.47k | } |
288 | | |
289 | | typedef struct _GstLineCache GstLineCache; |
290 | | |
291 | 8.34M | #define SCALE (8) |
292 | 3.67k | #define SCALE_F ((float) (1 << SCALE)) |
293 | | |
294 | | typedef struct _MatrixData MatrixData; |
295 | | |
296 | | struct _MatrixData |
297 | | { |
298 | | gdouble dm[4][4]; |
299 | | gint im[4][4]; |
300 | | gint width; |
301 | | guint64 orc_p1; |
302 | | guint64 orc_p2; |
303 | | guint64 orc_p3; |
304 | | guint64 orc_p4; |
305 | | gint64 *t_r; |
306 | | gint64 *t_g; |
307 | | gint64 *t_b; |
308 | | gint64 t_c; |
309 | | void (*matrix_func) (MatrixData * data, gpointer pixels); |
310 | | }; |
311 | | |
312 | | typedef struct _GammaData GammaData; |
313 | | |
314 | | struct _GammaData |
315 | | { |
316 | | gpointer gamma_table; |
317 | | gint width; |
318 | | GstVideoTransferFunction tr_func; |
319 | | void (*gamma_func) (GammaData * data, gpointer dest, gpointer src); |
320 | | }; |
321 | | |
322 | | typedef enum |
323 | | { |
324 | | ALPHA_MODE_NONE = 0, |
325 | | ALPHA_MODE_COPY = (1 << 0), |
326 | | ALPHA_MODE_SET = (1 << 1), |
327 | | ALPHA_MODE_MULT = (1 << 2) |
328 | | } AlphaMode; |
329 | | |
330 | | typedef struct |
331 | | { |
332 | | guint8 *data; |
333 | | guint stride; |
334 | | guint n_lines; |
335 | | guint idx; |
336 | | gpointer user_data; |
337 | | GDestroyNotify notify; |
338 | | } ConverterAlloc; |
339 | | |
340 | | typedef void (*FastConvertFunc) (GstVideoConverter * convert, |
341 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane); |
342 | | |
343 | | struct _GstVideoConverter |
344 | | { |
345 | | gint flags; |
346 | | |
347 | | GstVideoInfo in_info; |
348 | | GstVideoInfo out_info; |
349 | | |
350 | | gint in_x; |
351 | | gint in_y; |
352 | | gint in_width; |
353 | | gint in_height; |
354 | | gint in_maxwidth; |
355 | | gint in_maxheight; |
356 | | gint out_x; |
357 | | gint out_y; |
358 | | gint out_width; |
359 | | gint out_height; |
360 | | gint out_maxwidth; |
361 | | gint out_maxheight; |
362 | | |
363 | | gint current_pstride; |
364 | | gint current_width; |
365 | | gint current_height; |
366 | | GstVideoFormat current_format; |
367 | | gint current_bits; |
368 | | |
369 | | GstStructure *config; |
370 | | |
371 | | GstParallelizedTaskRunner *conversion_runner; |
372 | | |
373 | | guint16 **tmpline; |
374 | | |
375 | | gboolean fill_border; |
376 | | gpointer borderline; |
377 | | guint8 borders[GST_VIDEO_MAX_PLANES][16]; |
378 | | guint32 border_argb; |
379 | | guint32 alpha_value; |
380 | | AlphaMode alpha_mode; |
381 | | |
382 | | void (*convert) (GstVideoConverter * convert, const GstVideoFrame * src, |
383 | | GstVideoFrame * dest); |
384 | | |
385 | | /* data for unpack */ |
386 | | GstLineCache **unpack_lines; |
387 | | GstVideoFormat unpack_format; |
388 | | guint unpack_bits; |
389 | | gboolean unpack_rgb; |
390 | | gboolean identity_unpack; |
391 | | gint unpack_pstride; |
392 | | |
393 | | /* chroma upsample */ |
394 | | GstLineCache **upsample_lines; |
395 | | GstVideoChromaResample **upsample; |
396 | | GstVideoChromaResample **upsample_p; |
397 | | GstVideoChromaResample **upsample_i; |
398 | | guint up_n_lines; |
399 | | gint up_offset; |
400 | | |
401 | | /* to R'G'B */ |
402 | | GstLineCache **to_RGB_lines; |
403 | | MatrixData to_RGB_matrix; |
404 | | /* gamma decode */ |
405 | | GammaData gamma_dec; |
406 | | |
407 | | /* scaling */ |
408 | | GstLineCache **hscale_lines; |
409 | | GstVideoScaler **h_scaler; |
410 | | gint h_scale_format; |
411 | | GstLineCache **vscale_lines; |
412 | | GstVideoScaler **v_scaler; |
413 | | GstVideoScaler **v_scaler_p; |
414 | | GstVideoScaler **v_scaler_i; |
415 | | gint v_scale_width; |
416 | | gint v_scale_format; |
417 | | |
418 | | /* color space conversion */ |
419 | | GstLineCache **convert_lines; |
420 | | MatrixData convert_matrix; |
421 | | gint in_bits; |
422 | | gint out_bits; |
423 | | gboolean convert_in_float; |
424 | | gboolean convert_out_float; |
425 | | |
426 | | /* alpha correction */ |
427 | | GstLineCache **alpha_lines; |
428 | | void (*alpha_func) (GstVideoConverter * convert, gpointer pixels, gint width); |
429 | | |
430 | | /* gamma encode */ |
431 | | GammaData gamma_enc; |
432 | | /* to Y'CbCr */ |
433 | | GstLineCache **to_YUV_lines; |
434 | | MatrixData to_YUV_matrix; |
435 | | |
436 | | /* chroma downsample */ |
437 | | GstLineCache **downsample_lines; |
438 | | GstVideoChromaResample **downsample; |
439 | | GstVideoChromaResample **downsample_p; |
440 | | GstVideoChromaResample **downsample_i; |
441 | | guint down_n_lines; |
442 | | gint down_offset; |
443 | | |
444 | | /* dither */ |
445 | | GstLineCache **dither_lines; |
446 | | GstVideoDither **dither; |
447 | | |
448 | | /* pack */ |
449 | | GstLineCache **pack_lines; |
450 | | guint pack_nlines; |
451 | | GstVideoFormat pack_format; |
452 | | guint pack_bits; |
453 | | gboolean pack_rgb; |
454 | | gboolean identity_pack; |
455 | | gint pack_pstride; |
456 | | gconstpointer pack_pal; |
457 | | gsize pack_palsize; |
458 | | |
459 | | const GstVideoFrame *src; |
460 | | GstVideoFrame *dest; |
461 | | |
462 | | /* fastpath */ |
463 | | GstVideoFormat fformat[4]; |
464 | | gint fin_x[4]; |
465 | | gint fin_y[4]; |
466 | | gint fout_x[4]; |
467 | | gint fout_y[4]; |
468 | | gint fout_width[4]; |
469 | | gint fout_height[4]; |
470 | | gint fsplane[4]; |
471 | | gint ffill[4]; |
472 | | |
473 | | struct |
474 | | { |
475 | | GstVideoScaler **scaler; |
476 | | } fh_scaler[4]; |
477 | | struct |
478 | | { |
479 | | GstVideoScaler **scaler; |
480 | | } fv_scaler[4]; |
481 | | FastConvertFunc fconvert[4]; |
482 | | |
483 | | /* for parallel async running */ |
484 | | gpointer tasks[4]; |
485 | | gpointer tasks_p[4]; |
486 | | }; |
487 | | |
488 | | typedef gpointer (*GstLineCacheAllocLineFunc) (GstLineCache * cache, gint idx, |
489 | | gpointer user_data); |
490 | | typedef gboolean (*GstLineCacheNeedLineFunc) (GstLineCache * cache, gint idx, |
491 | | gint out_line, gint in_line, gpointer user_data); |
492 | | |
493 | | struct _GstLineCache |
494 | | { |
495 | | gint first; |
496 | | gint backlog; |
497 | | GPtrArray *lines; |
498 | | |
499 | | GstLineCache *prev; |
500 | | gboolean write_input; |
501 | | gboolean pass_alloc; |
502 | | gboolean alloc_writable; |
503 | | |
504 | | GstLineCacheNeedLineFunc need_line; |
505 | | gint need_line_idx; |
506 | | gpointer need_line_data; |
507 | | GDestroyNotify need_line_notify; |
508 | | |
509 | | guint n_lines; |
510 | | guint stride; |
511 | | GstLineCacheAllocLineFunc alloc_line; |
512 | | gpointer alloc_line_data; |
513 | | GDestroyNotify alloc_line_notify; |
514 | | }; |
515 | | |
516 | | static GstLineCache * |
517 | | gst_line_cache_new (GstLineCache * prev) |
518 | 3.90k | { |
519 | 3.90k | GstLineCache *result; |
520 | | |
521 | 3.90k | result = g_new0 (GstLineCache, 1); |
522 | 3.90k | result->lines = g_ptr_array_new (); |
523 | 3.90k | result->prev = prev; |
524 | | |
525 | 3.90k | return result; |
526 | 3.90k | } |
527 | | |
528 | | static void |
529 | | gst_line_cache_clear (GstLineCache * cache) |
530 | 4.40k | { |
531 | 4.40k | g_return_if_fail (cache != NULL); |
532 | | |
533 | 4.40k | g_ptr_array_set_size (cache->lines, 0); |
534 | 4.40k | cache->first = 0; |
535 | 4.40k | } |
536 | | |
537 | | static void |
538 | | gst_line_cache_free (GstLineCache * cache) |
539 | 3.90k | { |
540 | 3.90k | if (cache->need_line_notify) |
541 | 0 | cache->need_line_notify (cache->need_line_data); |
542 | 3.90k | if (cache->alloc_line_notify) |
543 | 2.37k | cache->alloc_line_notify (cache->alloc_line_data); |
544 | 3.90k | gst_line_cache_clear (cache); |
545 | 3.90k | g_ptr_array_unref (cache->lines); |
546 | 3.90k | g_free (cache); |
547 | 3.90k | } |
548 | | |
549 | | static void |
550 | | gst_line_cache_set_need_line_func (GstLineCache * cache, |
551 | | GstLineCacheNeedLineFunc need_line, gint idx, gpointer user_data, |
552 | | GDestroyNotify notify) |
553 | 3.90k | { |
554 | 3.90k | cache->need_line = need_line; |
555 | 3.90k | cache->need_line_idx = idx; |
556 | 3.90k | cache->need_line_data = user_data; |
557 | 3.90k | cache->need_line_notify = notify; |
558 | 3.90k | } |
559 | | |
560 | | static void |
561 | | gst_line_cache_set_alloc_line_func (GstLineCache * cache, |
562 | | GstLineCacheAllocLineFunc alloc_line, gpointer user_data, |
563 | | GDestroyNotify notify) |
564 | 3.90k | { |
565 | 3.90k | cache->alloc_line = alloc_line; |
566 | 3.90k | cache->alloc_line_data = user_data; |
567 | 3.90k | cache->alloc_line_notify = notify; |
568 | 3.90k | } |
569 | | |
570 | | /* keep this much backlog for interlaced video */ |
571 | 805 | #define BACKLOG 2 |
572 | | |
573 | | static gpointer * |
574 | | gst_line_cache_get_lines (GstLineCache * cache, gint idx, gint out_line, |
575 | | gint in_line, gint n_lines) |
576 | 282k | { |
577 | 282k | if (cache->first + cache->backlog < in_line) { |
578 | 241k | gint to_remove = |
579 | 241k | MIN (in_line - (cache->first + cache->backlog), cache->lines->len); |
580 | 241k | if (to_remove > 0) { |
581 | 241k | g_ptr_array_remove_range (cache->lines, 0, to_remove); |
582 | 241k | } |
583 | 241k | cache->first += to_remove; |
584 | 241k | } else if (in_line < cache->first) { |
585 | 252 | gst_line_cache_clear (cache); |
586 | 252 | cache->first = in_line; |
587 | 252 | } |
588 | | |
589 | 561k | while (TRUE) { |
590 | 561k | gint oline; |
591 | | |
592 | 561k | if (cache->first <= in_line |
593 | 561k | && in_line + n_lines <= cache->first + (gint) cache->lines->len) { |
594 | 282k | return cache->lines->pdata + (in_line - cache->first); |
595 | 282k | } |
596 | | |
597 | 278k | if (cache->need_line == NULL) |
598 | 0 | break; |
599 | | |
600 | | /* We may be able to skip ahead to the earliest line needed */ |
601 | 278k | if (cache->lines->len == 0 && cache->first + cache->backlog < in_line) |
602 | 33 | cache->first = in_line - cache->backlog; |
603 | | |
604 | 278k | oline = out_line + cache->first + cache->lines->len - in_line; |
605 | | |
606 | 278k | if (!cache->need_line (cache, idx, oline, cache->first + cache->lines->len, |
607 | 278k | cache->need_line_data)) |
608 | 0 | break; |
609 | 278k | } |
610 | 0 | GST_LOG ("no lines"); |
611 | 0 | return NULL; |
612 | 282k | } |
613 | | |
614 | | static void |
615 | | gst_line_cache_add_line (GstLineCache * cache, gint idx, gpointer line) |
616 | 297k | { |
617 | 297k | if (cache->first + cache->lines->len != idx) { |
618 | 252 | gst_line_cache_clear (cache); |
619 | 252 | cache->first = idx; |
620 | 252 | } |
621 | 297k | g_ptr_array_add (cache->lines, line); |
622 | 297k | } |
623 | | |
624 | | static gpointer |
625 | | gst_line_cache_alloc_line (GstLineCache * cache, gint idx) |
626 | 196k | { |
627 | 196k | gpointer res; |
628 | | |
629 | 196k | if (cache->alloc_line) |
630 | 196k | res = cache->alloc_line (cache, idx, cache->alloc_line_data); |
631 | 0 | else |
632 | 0 | res = NULL; |
633 | | |
634 | 196k | return res; |
635 | 196k | } |
636 | | |
637 | | static void video_converter_generic (GstVideoConverter * convert, |
638 | | const GstVideoFrame * src, GstVideoFrame * dest); |
639 | | static gboolean video_converter_lookup_fastpath (GstVideoConverter * convert); |
640 | | static void video_converter_compute_matrix (GstVideoConverter * convert); |
641 | | static void video_converter_compute_resample (GstVideoConverter * convert, |
642 | | gint idx); |
643 | | |
644 | | static gpointer get_dest_line (GstLineCache * cache, gint idx, |
645 | | gpointer user_data); |
646 | | |
647 | | static gboolean do_unpack_lines (GstLineCache * cache, gint idx, gint out_line, |
648 | | gint in_line, gpointer user_data); |
649 | | static gboolean do_downsample_lines (GstLineCache * cache, gint idx, |
650 | | gint out_line, gint in_line, gpointer user_data); |
651 | | static gboolean do_convert_to_RGB_lines (GstLineCache * cache, gint idx, |
652 | | gint out_line, gint in_line, gpointer user_data); |
653 | | static gboolean do_convert_lines (GstLineCache * cache, gint idx, gint out_line, |
654 | | gint in_line, gpointer user_data); |
655 | | static gboolean do_alpha_lines (GstLineCache * cache, gint idx, gint out_line, |
656 | | gint in_line, gpointer user_data); |
657 | | static gboolean do_convert_to_YUV_lines (GstLineCache * cache, gint idx, |
658 | | gint out_line, gint in_line, gpointer user_data); |
659 | | static gboolean do_upsample_lines (GstLineCache * cache, gint idx, |
660 | | gint out_line, gint in_line, gpointer user_data); |
661 | | static gboolean do_vscale_lines (GstLineCache * cache, gint idx, gint out_line, |
662 | | gint in_line, gpointer user_data); |
663 | | static gboolean do_hscale_lines (GstLineCache * cache, gint idx, gint out_line, |
664 | | gint in_line, gpointer user_data); |
665 | | static gboolean do_dither_lines (GstLineCache * cache, gint idx, gint out_line, |
666 | | gint in_line, gpointer user_data); |
667 | | |
668 | | static ConverterAlloc * |
669 | | converter_alloc_new (guint stride, guint n_lines, gpointer user_data, |
670 | | GDestroyNotify notify) |
671 | 3.31k | { |
672 | 3.31k | ConverterAlloc *alloc; |
673 | | |
674 | 3.31k | GST_LOG ("stride %d, n_lines %d", stride, n_lines); |
675 | 3.31k | alloc = g_new0 (ConverterAlloc, 1); |
676 | 3.31k | alloc->data = g_malloc (stride * n_lines); |
677 | 3.31k | alloc->stride = stride; |
678 | 3.31k | alloc->n_lines = n_lines; |
679 | 3.31k | alloc->idx = 0; |
680 | 3.31k | alloc->user_data = user_data; |
681 | 3.31k | alloc->notify = notify; |
682 | | |
683 | 3.31k | return alloc; |
684 | 3.31k | } |
685 | | |
686 | | static void |
687 | | converter_alloc_free (ConverterAlloc * alloc) |
688 | 3.31k | { |
689 | 3.31k | if (alloc->notify) |
690 | 0 | alloc->notify (alloc->user_data); |
691 | 3.31k | g_free (alloc->data); |
692 | 3.31k | g_free (alloc); |
693 | 3.31k | } |
694 | | |
695 | | static void |
696 | | setup_border_alloc (GstVideoConverter * convert, ConverterAlloc * alloc) |
697 | 805 | { |
698 | 805 | gint i; |
699 | | |
700 | 805 | if (convert->borderline) { |
701 | 0 | for (i = 0; i < alloc->n_lines; i++) |
702 | 0 | memcpy (&alloc->data[i * alloc->stride], convert->borderline, |
703 | 0 | alloc->stride); |
704 | 0 | } |
705 | 805 | } |
706 | | |
707 | | static gpointer |
708 | | get_temp_line (GstLineCache * cache, gint idx, gpointer user_data) |
709 | 113k | { |
710 | 113k | ConverterAlloc *alloc = user_data; |
711 | 113k | gpointer tmpline; |
712 | | |
713 | 113k | GST_LOG ("get temp line %d (%p %d)", idx, alloc, alloc->idx); |
714 | 113k | tmpline = &alloc->data[alloc->stride * alloc->idx]; |
715 | 113k | alloc->idx = (alloc->idx + 1) % alloc->n_lines; |
716 | | |
717 | 113k | return tmpline; |
718 | 113k | } |
719 | | |
720 | | static gpointer |
721 | | get_border_temp_line (GstLineCache * cache, gint idx, gpointer user_data) |
722 | 71.2k | { |
723 | 71.2k | ConverterAlloc *alloc = user_data; |
724 | 71.2k | GstVideoConverter *convert = alloc->user_data; |
725 | 71.2k | gpointer tmpline; |
726 | | |
727 | 71.2k | GST_LOG ("get temp line %d (%p %d)", idx, alloc, alloc->idx); |
728 | 71.2k | tmpline = &alloc->data[alloc->stride * alloc->idx] + |
729 | 71.2k | (convert->out_x * convert->pack_pstride); |
730 | 71.2k | alloc->idx = (alloc->idx + 1) % alloc->n_lines; |
731 | | |
732 | 71.2k | return tmpline; |
733 | 71.2k | } |
734 | | |
735 | | static gint |
736 | | get_opt_int (GstVideoConverter * convert, const gchar * opt, gint def) |
737 | 16.6k | { |
738 | 16.6k | gint res; |
739 | 16.6k | if (!gst_structure_get_int (convert->config, opt, &res)) |
740 | 16.6k | res = def; |
741 | 16.6k | return res; |
742 | 16.6k | } |
743 | | |
744 | | static guint |
745 | | get_opt_uint (GstVideoConverter * convert, const gchar * opt, guint def) |
746 | 9.09k | { |
747 | 9.09k | guint res; |
748 | 9.09k | if (!gst_structure_get_uint (convert->config, opt, &res)) |
749 | 9.09k | res = def; |
750 | 9.09k | return res; |
751 | 9.09k | } |
752 | | |
753 | | static gdouble |
754 | | get_opt_double (GstVideoConverter * convert, const gchar * opt, gdouble def) |
755 | 2.52k | { |
756 | 2.52k | gdouble res; |
757 | 2.52k | if (!gst_structure_get_double (convert->config, opt, &res)) |
758 | 2.52k | res = def; |
759 | 2.52k | return res; |
760 | 2.52k | } |
761 | | |
762 | | static gboolean |
763 | | get_opt_bool (GstVideoConverter * convert, const gchar * opt, gboolean def) |
764 | 4.16k | { |
765 | 4.16k | gboolean res; |
766 | 4.16k | if (!gst_structure_get_boolean (convert->config, opt, &res)) |
767 | 4.16k | res = def; |
768 | 4.16k | return res; |
769 | 4.16k | } |
770 | | |
771 | | static gint |
772 | | get_opt_enum (GstVideoConverter * convert, const gchar * opt, GType type, |
773 | | gint def) |
774 | 20.3k | { |
775 | 20.3k | gint res; |
776 | 20.3k | if (!gst_structure_get_enum (convert->config, opt, type, &res)) |
777 | 20.3k | res = def; |
778 | 20.3k | return res; |
779 | 20.3k | } |
780 | | |
781 | 2.08k | #define DEFAULT_OPT_FILL_BORDER TRUE |
782 | 2.52k | #define DEFAULT_OPT_ALPHA_VALUE 1.0 |
783 | | /* options copy, set, mult */ |
784 | 378 | #define DEFAULT_OPT_ALPHA_MODE GST_VIDEO_ALPHA_MODE_COPY |
785 | 2.08k | #define DEFAULT_OPT_BORDER_ARGB 0xff000000 |
786 | | /* options full, input-only, output-only, none */ |
787 | 5.96k | #define DEFAULT_OPT_MATRIX_MODE GST_VIDEO_MATRIX_MODE_FULL |
788 | | /* none, remap */ |
789 | 4.92k | #define DEFAULT_OPT_GAMMA_MODE GST_VIDEO_GAMMA_MODE_NONE |
790 | | /* none, merge-only, fast */ |
791 | 3.02k | #define DEFAULT_OPT_PRIMARIES_MODE GST_VIDEO_PRIMARIES_MODE_NONE |
792 | | /* options full, upsample-only, downsample-only, none */ |
793 | 2.78k | #define DEFAULT_OPT_CHROMA_MODE GST_VIDEO_CHROMA_MODE_FULL |
794 | 1.89k | #define DEFAULT_OPT_RESAMPLER_METHOD GST_VIDEO_RESAMPLER_METHOD_CUBIC |
795 | 452 | #define DEFAULT_OPT_CHROMA_RESAMPLER_METHOD GST_VIDEO_RESAMPLER_METHOD_LINEAR |
796 | 1.89k | #define DEFAULT_OPT_RESAMPLER_TAPS 0 |
797 | 946 | #define DEFAULT_OPT_DITHER_METHOD GST_VIDEO_DITHER_BAYER |
798 | 3.02k | #define DEFAULT_OPT_DITHER_QUANTIZATION 1 |
799 | 2.08k | #define DEFAULT_OPT_ASYNC_TASKS FALSE |
800 | | |
801 | 2.08k | #define GET_OPT_FILL_BORDER(c) get_opt_bool(c, \ |
802 | 2.08k | GST_VIDEO_CONVERTER_OPT_FILL_BORDER, DEFAULT_OPT_FILL_BORDER) |
803 | 2.52k | #define GET_OPT_ALPHA_VALUE(c) get_opt_double(c, \ |
804 | 2.52k | GST_VIDEO_CONVERTER_OPT_ALPHA_VALUE, DEFAULT_OPT_ALPHA_VALUE) |
805 | 378 | #define GET_OPT_ALPHA_MODE(c) get_opt_enum(c, \ |
806 | 378 | GST_VIDEO_CONVERTER_OPT_ALPHA_MODE, GST_TYPE_VIDEO_ALPHA_MODE, DEFAULT_OPT_ALPHA_MODE) |
807 | | #define GET_OPT_BORDER_ARGB(c) get_opt_uint(c, \ |
808 | | GST_VIDEO_CONVERTER_OPT_BORDER_ARGB, DEFAULT_OPT_BORDER_ARGB) |
809 | 5.96k | #define GET_OPT_MATRIX_MODE(c) get_opt_enum(c, \ |
810 | 5.96k | GST_VIDEO_CONVERTER_OPT_MATRIX_MODE, GST_TYPE_VIDEO_MATRIX_MODE, DEFAULT_OPT_MATRIX_MODE) |
811 | 4.92k | #define GET_OPT_GAMMA_MODE(c) get_opt_enum(c, \ |
812 | 4.92k | GST_VIDEO_CONVERTER_OPT_GAMMA_MODE, GST_TYPE_VIDEO_GAMMA_MODE, DEFAULT_OPT_GAMMA_MODE) |
813 | 3.02k | #define GET_OPT_PRIMARIES_MODE(c) get_opt_enum(c, \ |
814 | 3.02k | GST_VIDEO_CONVERTER_OPT_PRIMARIES_MODE, GST_TYPE_VIDEO_PRIMARIES_MODE, DEFAULT_OPT_PRIMARIES_MODE) |
815 | 2.78k | #define GET_OPT_CHROMA_MODE(c) get_opt_enum(c, \ |
816 | 2.78k | GST_VIDEO_CONVERTER_OPT_CHROMA_MODE, GST_TYPE_VIDEO_CHROMA_MODE, DEFAULT_OPT_CHROMA_MODE) |
817 | 1.89k | #define GET_OPT_RESAMPLER_METHOD(c) get_opt_enum(c, \ |
818 | 1.89k | GST_VIDEO_CONVERTER_OPT_RESAMPLER_METHOD, GST_TYPE_VIDEO_RESAMPLER_METHOD, \ |
819 | 1.89k | DEFAULT_OPT_RESAMPLER_METHOD) |
820 | 452 | #define GET_OPT_CHROMA_RESAMPLER_METHOD(c) get_opt_enum(c, \ |
821 | 452 | GST_VIDEO_CONVERTER_OPT_CHROMA_RESAMPLER_METHOD, GST_TYPE_VIDEO_RESAMPLER_METHOD, \ |
822 | 452 | DEFAULT_OPT_CHROMA_RESAMPLER_METHOD) |
823 | 1.89k | #define GET_OPT_RESAMPLER_TAPS(c) get_opt_uint(c, \ |
824 | 1.89k | GST_VIDEO_CONVERTER_OPT_RESAMPLER_TAPS, DEFAULT_OPT_RESAMPLER_TAPS) |
825 | 946 | #define GET_OPT_DITHER_METHOD(c) get_opt_enum(c, \ |
826 | 946 | GST_VIDEO_CONVERTER_OPT_DITHER_METHOD, GST_TYPE_VIDEO_DITHER_METHOD, \ |
827 | 946 | DEFAULT_OPT_DITHER_METHOD) |
828 | 3.02k | #define GET_OPT_DITHER_QUANTIZATION(c) get_opt_uint(c, \ |
829 | 3.02k | GST_VIDEO_CONVERTER_OPT_DITHER_QUANTIZATION, DEFAULT_OPT_DITHER_QUANTIZATION) |
830 | 2.08k | #define GET_OPT_ASYNC_TASKS(c) get_opt_bool(c, \ |
831 | 2.08k | GST_VIDEO_CONVERTER_OPT_ASYNC_TASKS, DEFAULT_OPT_ASYNC_TASKS) |
832 | | |
833 | 378 | #define CHECK_ALPHA_COPY(c) (GET_OPT_ALPHA_MODE(c) == GST_VIDEO_ALPHA_MODE_COPY) |
834 | | #define CHECK_ALPHA_SET(c) (GET_OPT_ALPHA_MODE(c) == GST_VIDEO_ALPHA_MODE_SET) |
835 | 0 | #define CHECK_ALPHA_MULT(c) (GET_OPT_ALPHA_MODE(c) == GST_VIDEO_ALPHA_MODE_MULT) |
836 | | |
837 | | #define CHECK_MATRIX_FULL(c) (GET_OPT_MATRIX_MODE(c) == GST_VIDEO_MATRIX_MODE_FULL) |
838 | 401 | #define CHECK_MATRIX_INPUT(c) (GET_OPT_MATRIX_MODE(c) == GST_VIDEO_MATRIX_MODE_INPUT_ONLY) |
839 | 1.06k | #define CHECK_MATRIX_OUTPUT(c) (GET_OPT_MATRIX_MODE(c) == GST_VIDEO_MATRIX_MODE_OUTPUT_ONLY) |
840 | 4.49k | #define CHECK_MATRIX_NONE(c) (GET_OPT_MATRIX_MODE(c) == GST_VIDEO_MATRIX_MODE_NONE) |
841 | | |
842 | | #define CHECK_GAMMA_NONE(c) (GET_OPT_GAMMA_MODE(c) == GST_VIDEO_GAMMA_MODE_NONE) |
843 | 7.00k | #define CHECK_GAMMA_REMAP(c) (GET_OPT_GAMMA_MODE(c) == GST_VIDEO_GAMMA_MODE_REMAP) |
844 | | |
845 | 3.02k | #define CHECK_PRIMARIES_NONE(c) (GET_OPT_PRIMARIES_MODE(c) == GST_VIDEO_PRIMARIES_MODE_NONE) |
846 | | #define CHECK_PRIMARIES_MERGE(c) (GET_OPT_PRIMARIES_MODE(c) == GST_VIDEO_PRIMARIES_MODE_MERGE_ONLY) |
847 | | #define CHECK_PRIMARIES_FAST(c) (GET_OPT_PRIMARIES_MODE(c) == GST_VIDEO_PRIMARIES_MODE_FAST) |
848 | | |
849 | | #define CHECK_CHROMA_FULL(c) (GET_OPT_CHROMA_MODE(c) == GST_VIDEO_CHROMA_MODE_FULL) |
850 | 918 | #define CHECK_CHROMA_UPSAMPLE(c) (GET_OPT_CHROMA_MODE(c) == GST_VIDEO_CHROMA_MODE_UPSAMPLE_ONLY) |
851 | 918 | #define CHECK_CHROMA_DOWNSAMPLE(c) (GET_OPT_CHROMA_MODE(c) == GST_VIDEO_CHROMA_MODE_DOWNSAMPLE_ONLY) |
852 | 946 | #define CHECK_CHROMA_NONE(c) (GET_OPT_CHROMA_MODE(c) == GST_VIDEO_CHROMA_MODE_NONE) |
853 | | |
854 | | static GstLineCache * |
855 | | chain_unpack_line (GstVideoConverter * convert, gint idx) |
856 | 946 | { |
857 | 946 | GstLineCache *prev; |
858 | 946 | GstVideoInfo *info; |
859 | | |
860 | 946 | info = &convert->in_info; |
861 | | |
862 | 946 | convert->current_format = convert->unpack_format; |
863 | 946 | convert->current_bits = convert->unpack_bits; |
864 | 946 | convert->current_pstride = convert->current_bits >> 1; |
865 | | |
866 | 946 | convert->unpack_pstride = convert->current_pstride; |
867 | 946 | convert->identity_unpack = (convert->current_format == info->finfo->format); |
868 | | |
869 | 946 | GST_LOG ("chain unpack line format %s, pstride %d, identity_unpack %d", |
870 | 946 | gst_video_format_to_string (convert->current_format), |
871 | 946 | convert->current_pstride, convert->identity_unpack); |
872 | | |
873 | 946 | prev = convert->unpack_lines[idx] = gst_line_cache_new (NULL); |
874 | 946 | prev->write_input = FALSE; |
875 | 946 | prev->pass_alloc = FALSE; |
876 | 946 | prev->n_lines = 1; |
877 | 946 | prev->stride = convert->current_pstride * convert->current_width; |
878 | 946 | gst_line_cache_set_need_line_func (prev, do_unpack_lines, idx, convert, NULL); |
879 | | |
880 | 946 | return prev; |
881 | 946 | } |
882 | | |
883 | | static GstLineCache * |
884 | | chain_upsample (GstVideoConverter * convert, GstLineCache * prev, gint idx) |
885 | 946 | { |
886 | 946 | video_converter_compute_resample (convert, idx); |
887 | | |
888 | 946 | if (convert->upsample_p[idx] || convert->upsample_i[idx]) { |
889 | 439 | GST_LOG ("chain upsample"); |
890 | 439 | prev = convert->upsample_lines[idx] = gst_line_cache_new (prev); |
891 | 439 | prev->write_input = TRUE; |
892 | 439 | prev->pass_alloc = TRUE; |
893 | | /* XXX: why this hardcoded value? */ |
894 | 439 | prev->n_lines = 5; |
895 | 439 | prev->stride = convert->current_pstride * convert->current_width; |
896 | 439 | gst_line_cache_set_need_line_func (prev, |
897 | 439 | do_upsample_lines, idx, convert, NULL); |
898 | 439 | } |
899 | 946 | return prev; |
900 | 946 | } |
901 | | |
902 | | static void |
903 | | color_matrix_set_identity (MatrixData * m) |
904 | 7.96k | { |
905 | 7.96k | int i, j; |
906 | | |
907 | 39.8k | for (i = 0; i < 4; i++) { |
908 | 159k | for (j = 0; j < 4; j++) { |
909 | 127k | m->dm[i][j] = (i == j); |
910 | 127k | } |
911 | 31.8k | } |
912 | 7.96k | } |
913 | | |
914 | | static void |
915 | | color_matrix_copy (MatrixData * d, const MatrixData * s) |
916 | 7.94k | { |
917 | 7.94k | gint i, j; |
918 | | |
919 | 39.7k | for (i = 0; i < 4; i++) |
920 | 158k | for (j = 0; j < 4; j++) |
921 | 127k | d->dm[i][j] = s->dm[i][j]; |
922 | 7.94k | } |
923 | | |
924 | | /* Perform 4x4 matrix multiplication: |
925 | | * - @dst@ = @a@ * @b@ |
926 | | * - @dst@ may be a pointer to @a@ andor @b@ |
927 | | */ |
928 | | static void |
929 | | color_matrix_multiply (MatrixData * dst, MatrixData * a, MatrixData * b) |
930 | 7.94k | { |
931 | 7.94k | MatrixData tmp; |
932 | 7.94k | int i, j, k; |
933 | | |
934 | 39.7k | for (i = 0; i < 4; i++) { |
935 | 158k | for (j = 0; j < 4; j++) { |
936 | 127k | double x = 0; |
937 | 635k | for (k = 0; k < 4; k++) { |
938 | 508k | x += a->dm[i][k] * b->dm[k][j]; |
939 | 508k | } |
940 | 127k | tmp.dm[i][j] = x; |
941 | 127k | } |
942 | 31.7k | } |
943 | 7.94k | color_matrix_copy (dst, &tmp); |
944 | 7.94k | } |
945 | | |
946 | | static void |
947 | | color_matrix_invert (MatrixData * d, MatrixData * s) |
948 | 0 | { |
949 | 0 | MatrixData tmp; |
950 | 0 | int i, j; |
951 | 0 | double det; |
952 | |
|
953 | 0 | color_matrix_set_identity (&tmp); |
954 | 0 | for (j = 0; j < 3; j++) { |
955 | 0 | for (i = 0; i < 3; i++) { |
956 | 0 | tmp.dm[j][i] = |
957 | 0 | s->dm[(i + 1) % 3][(j + 1) % 3] * s->dm[(i + 2) % 3][(j + 2) % 3] - |
958 | 0 | s->dm[(i + 1) % 3][(j + 2) % 3] * s->dm[(i + 2) % 3][(j + 1) % 3]; |
959 | 0 | } |
960 | 0 | } |
961 | 0 | det = |
962 | 0 | tmp.dm[0][0] * s->dm[0][0] + tmp.dm[0][1] * s->dm[1][0] + |
963 | 0 | tmp.dm[0][2] * s->dm[2][0]; |
964 | 0 | for (j = 0; j < 3; j++) { |
965 | 0 | for (i = 0; i < 3; i++) { |
966 | 0 | tmp.dm[i][j] /= det; |
967 | 0 | } |
968 | 0 | } |
969 | 0 | color_matrix_copy (d, &tmp); |
970 | 0 | } |
971 | | |
972 | | static void |
973 | | color_matrix_offset_components (MatrixData * m, double a1, double a2, double a3) |
974 | 2.49k | { |
975 | 2.49k | MatrixData a; |
976 | | |
977 | 2.49k | color_matrix_set_identity (&a); |
978 | 2.49k | a.dm[0][3] = a1; |
979 | 2.49k | a.dm[1][3] = a2; |
980 | 2.49k | a.dm[2][3] = a3; |
981 | 2.49k | color_matrix_multiply (m, &a, m); |
982 | 2.49k | } |
983 | | |
984 | | static void |
985 | | color_matrix_scale_components (MatrixData * m, double a1, double a2, double a3) |
986 | 3.98k | { |
987 | 3.98k | MatrixData a; |
988 | | |
989 | 3.98k | color_matrix_set_identity (&a); |
990 | 3.98k | a.dm[0][0] = a1; |
991 | 3.98k | a.dm[1][1] = a2; |
992 | 3.98k | a.dm[2][2] = a3; |
993 | 3.98k | color_matrix_multiply (m, &a, m); |
994 | 3.98k | } |
995 | | |
996 | | static void |
997 | | color_matrix_debug (const MatrixData * s) |
998 | 3.91k | { |
999 | 3.91k | GST_LOG ("[%f %f %f %f]", s->dm[0][0], s->dm[0][1], s->dm[0][2], s->dm[0][3]); |
1000 | 3.91k | GST_LOG ("[%f %f %f %f]", s->dm[1][0], s->dm[1][1], s->dm[1][2], s->dm[1][3]); |
1001 | 3.91k | GST_LOG ("[%f %f %f %f]", s->dm[2][0], s->dm[2][1], s->dm[2][2], s->dm[2][3]); |
1002 | 3.91k | GST_LOG ("[%f %f %f %f]", s->dm[3][0], s->dm[3][1], s->dm[3][2], s->dm[3][3]); |
1003 | 3.91k | } |
1004 | | |
1005 | | static void |
1006 | | color_matrix_convert (MatrixData * s) |
1007 | 1.22k | { |
1008 | 1.22k | gint i, j; |
1009 | | |
1010 | 6.12k | for (i = 0; i < 4; i++) |
1011 | 24.5k | for (j = 0; j < 4; j++) |
1012 | 19.6k | s->im[i][j] = rint (s->dm[i][j]); |
1013 | | |
1014 | 1.22k | GST_LOG ("[%6d %6d %6d %6d]", s->im[0][0], s->im[0][1], s->im[0][2], |
1015 | 1.22k | s->im[0][3]); |
1016 | 1.22k | GST_LOG ("[%6d %6d %6d %6d]", s->im[1][0], s->im[1][1], s->im[1][2], |
1017 | 1.22k | s->im[1][3]); |
1018 | 1.22k | GST_LOG ("[%6d %6d %6d %6d]", s->im[2][0], s->im[2][1], s->im[2][2], |
1019 | 1.22k | s->im[2][3]); |
1020 | 1.22k | GST_LOG ("[%6d %6d %6d %6d]", s->im[3][0], s->im[3][1], s->im[3][2], |
1021 | 1.22k | s->im[3][3]); |
1022 | 1.22k | } |
1023 | | |
1024 | | static void |
1025 | | color_matrix_YCbCr_to_RGB (MatrixData * m, double Kr, double Kb) |
1026 | 1.06k | { |
1027 | 1.06k | double Kg = 1.0 - Kr - Kb; |
1028 | 1.06k | MatrixData k = { |
1029 | 1.06k | { |
1030 | 1.06k | {1., 0., 2 * (1 - Kr), 0.}, |
1031 | 1.06k | {1., -2 * Kb * (1 - Kb) / Kg, -2 * Kr * (1 - Kr) / Kg, 0.}, |
1032 | 1.06k | {1., 2 * (1 - Kb), 0., 0.}, |
1033 | 1.06k | {0., 0., 0., 1.}, |
1034 | 1.06k | } |
1035 | 1.06k | }; |
1036 | | |
1037 | 1.06k | color_matrix_multiply (m, &k, m); |
1038 | 1.06k | } |
1039 | | |
1040 | | static void |
1041 | | color_matrix_RGB_to_YCbCr (MatrixData * m, double Kr, double Kb) |
1042 | 401 | { |
1043 | 401 | double Kg = 1.0 - Kr - Kb; |
1044 | 401 | MatrixData k; |
1045 | 401 | double x; |
1046 | | |
1047 | 401 | k.dm[0][0] = Kr; |
1048 | 401 | k.dm[0][1] = Kg; |
1049 | 401 | k.dm[0][2] = Kb; |
1050 | 401 | k.dm[0][3] = 0; |
1051 | | |
1052 | 401 | x = 1 / (2 * (1 - Kb)); |
1053 | 401 | k.dm[1][0] = -x * Kr; |
1054 | 401 | k.dm[1][1] = -x * Kg; |
1055 | 401 | k.dm[1][2] = x * (1 - Kb); |
1056 | 401 | k.dm[1][3] = 0; |
1057 | | |
1058 | 401 | x = 1 / (2 * (1 - Kr)); |
1059 | 401 | k.dm[2][0] = x * (1 - Kr); |
1060 | 401 | k.dm[2][1] = -x * Kg; |
1061 | 401 | k.dm[2][2] = -x * Kb; |
1062 | 401 | k.dm[2][3] = 0; |
1063 | | |
1064 | 401 | k.dm[3][0] = 0; |
1065 | 401 | k.dm[3][1] = 0; |
1066 | 401 | k.dm[3][2] = 0; |
1067 | 401 | k.dm[3][3] = 1; |
1068 | | |
1069 | 401 | color_matrix_multiply (m, &k, m); |
1070 | 401 | } |
1071 | | |
1072 | | static void |
1073 | | color_matrix_RGB_to_XYZ (MatrixData * dst, double Rx, double Ry, double Gx, |
1074 | | double Gy, double Bx, double By, double Wx, double Wy) |
1075 | 0 | { |
1076 | 0 | MatrixData m, im; |
1077 | 0 | double sx, sy, sz; |
1078 | 0 | double wx, wy, wz; |
1079 | |
|
1080 | 0 | color_matrix_set_identity (&m); |
1081 | |
|
1082 | 0 | m.dm[0][0] = Rx; |
1083 | 0 | m.dm[1][0] = Ry; |
1084 | 0 | m.dm[2][0] = (1.0 - Rx - Ry); |
1085 | 0 | m.dm[0][1] = Gx; |
1086 | 0 | m.dm[1][1] = Gy; |
1087 | 0 | m.dm[2][1] = (1.0 - Gx - Gy); |
1088 | 0 | m.dm[0][2] = Bx; |
1089 | 0 | m.dm[1][2] = By; |
1090 | 0 | m.dm[2][2] = (1.0 - Bx - By); |
1091 | |
|
1092 | 0 | color_matrix_invert (&im, &m); |
1093 | |
|
1094 | 0 | wx = Wx / Wy; |
1095 | 0 | wy = 1.0; |
1096 | 0 | wz = (1.0 - Wx - Wy) / Wy; |
1097 | |
|
1098 | 0 | sx = im.dm[0][0] * wx + im.dm[0][1] * wy + im.dm[0][2] * wz; |
1099 | 0 | sy = im.dm[1][0] * wx + im.dm[1][1] * wy + im.dm[1][2] * wz; |
1100 | 0 | sz = im.dm[2][0] * wx + im.dm[2][1] * wy + im.dm[2][2] * wz; |
1101 | |
|
1102 | 0 | m.dm[0][0] *= sx; |
1103 | 0 | m.dm[1][0] *= sx; |
1104 | 0 | m.dm[2][0] *= sx; |
1105 | 0 | m.dm[0][1] *= sy; |
1106 | 0 | m.dm[1][1] *= sy; |
1107 | 0 | m.dm[2][1] *= sy; |
1108 | 0 | m.dm[0][2] *= sz; |
1109 | 0 | m.dm[1][2] *= sz; |
1110 | 0 | m.dm[2][2] *= sz; |
1111 | |
|
1112 | 0 | color_matrix_copy (dst, &m); |
1113 | 0 | } |
1114 | | |
1115 | | static void |
1116 | | videoconvert_convert_init_tables (MatrixData * data) |
1117 | 129 | { |
1118 | 129 | gint i, j; |
1119 | | |
1120 | 129 | data->t_r = g_new (gint64, 256); |
1121 | 129 | data->t_g = g_new (gint64, 256); |
1122 | 129 | data->t_b = g_new (gint64, 256); |
1123 | | |
1124 | 33.1k | for (i = 0; i < 256; i++) { |
1125 | 33.0k | gint64 r = 0, g = 0, b = 0; |
1126 | | |
1127 | 132k | for (j = 0; j < 3; j++) { |
1128 | 99.0k | r = (r << 16) + data->im[j][0] * i; |
1129 | 99.0k | g = (g << 16) + data->im[j][1] * i; |
1130 | 99.0k | b = (b << 16) + data->im[j][2] * i; |
1131 | 99.0k | } |
1132 | 33.0k | data->t_r[i] = r; |
1133 | 33.0k | data->t_g[i] = g; |
1134 | 33.0k | data->t_b[i] = b; |
1135 | 33.0k | } |
1136 | 129 | data->t_c = ((gint64) data->im[0][3] << 32) |
1137 | 129 | + ((gint64) data->im[1][3] << 16) |
1138 | 129 | + ((gint64) data->im[2][3] << 0); |
1139 | 129 | } |
1140 | | |
1141 | | void |
1142 | | _custom_video_orc_matrix8 (guint8 * ORC_RESTRICT d1, |
1143 | | const guint8 * ORC_RESTRICT s1, orc_int64 p1, orc_int64 p2, orc_int64 p3, |
1144 | | orc_int64 p4, int n) |
1145 | 7.52k | { |
1146 | 7.52k | gint i; |
1147 | 7.52k | gint r, g, b; |
1148 | 7.52k | gint y, u, v; |
1149 | 7.52k | gint a00, a01, a02, a03; |
1150 | 7.52k | gint a10, a11, a12, a13; |
1151 | 7.52k | gint a20, a21, a22, a23; |
1152 | | |
1153 | 7.52k | a00 = (gint16) (p1 >> 16); |
1154 | 7.52k | a01 = (gint16) (p2 >> 16); |
1155 | 7.52k | a02 = (gint16) (p3 >> 16); |
1156 | 7.52k | a03 = (gint16) (p4 >> 16); |
1157 | 7.52k | a10 = (gint16) (p1 >> 32); |
1158 | 7.52k | a11 = (gint16) (p2 >> 32); |
1159 | 7.52k | a12 = (gint16) (p3 >> 32); |
1160 | 7.52k | a13 = (gint16) (p4 >> 32); |
1161 | 7.52k | a20 = (gint16) (p1 >> 48); |
1162 | 7.52k | a21 = (gint16) (p2 >> 48); |
1163 | 7.52k | a22 = (gint16) (p3 >> 48); |
1164 | 7.52k | a23 = (gint16) (p4 >> 48); |
1165 | | |
1166 | 933k | for (i = 0; i < n; i++) { |
1167 | 926k | r = s1[i * 4 + 1]; |
1168 | 926k | g = s1[i * 4 + 2]; |
1169 | 926k | b = s1[i * 4 + 3]; |
1170 | | |
1171 | 926k | y = ((a00 * r + a01 * g + a02 * b) >> SCALE) + a03; |
1172 | 926k | u = ((a10 * r + a11 * g + a12 * b) >> SCALE) + a13; |
1173 | 926k | v = ((a20 * r + a21 * g + a22 * b) >> SCALE) + a23; |
1174 | | |
1175 | 926k | d1[i * 4 + 1] = CLAMP (y, 0, 255); |
1176 | 926k | d1[i * 4 + 2] = CLAMP (u, 0, 255); |
1177 | 926k | d1[i * 4 + 3] = CLAMP (v, 0, 255); |
1178 | 926k | } |
1179 | 7.52k | } |
1180 | | |
1181 | | static void |
1182 | | video_converter_matrix8 (MatrixData * data, gpointer pixels) |
1183 | 7.52k | { |
1184 | 7.52k | gpointer d = pixels; |
1185 | 7.52k | video_orc_matrix8 (d, pixels, data->orc_p1, data->orc_p2, |
1186 | 7.52k | data->orc_p3, data->orc_p4, data->width); |
1187 | 7.52k | } |
1188 | | |
1189 | | static void |
1190 | | video_converter_matrix8_table (MatrixData * data, gpointer pixels) |
1191 | 3.72k | { |
1192 | 3.72k | gint i, width = data->width * 4; |
1193 | 3.72k | guint8 r, g, b; |
1194 | 3.72k | gint64 c = data->t_c; |
1195 | 3.72k | guint8 *p = pixels; |
1196 | 3.72k | gint64 x; |
1197 | | |
1198 | 398k | for (i = 0; i < width; i += 4) { |
1199 | 394k | r = p[i + 1]; |
1200 | 394k | g = p[i + 2]; |
1201 | 394k | b = p[i + 3]; |
1202 | | |
1203 | 394k | x = data->t_r[r] + data->t_g[g] + data->t_b[b] + c; |
1204 | | |
1205 | 394k | p[i + 1] = x >> (32 + SCALE); |
1206 | 394k | p[i + 2] = x >> (16 + SCALE); |
1207 | 394k | p[i + 3] = x >> (0 + SCALE); |
1208 | 394k | } |
1209 | 3.72k | } |
1210 | | |
1211 | | static void |
1212 | | video_converter_matrix8_AYUV_ARGB (MatrixData * data, gpointer pixels) |
1213 | 17.1k | { |
1214 | 17.1k | gpointer d = pixels; |
1215 | | |
1216 | 17.1k | video_orc_convert_AYUV_ARGB (d, 0, pixels, 0, |
1217 | 17.1k | data->im[0][0], data->im[0][2], |
1218 | 17.1k | data->im[2][1], data->im[1][1], data->im[1][2], data->width, 1); |
1219 | 17.1k | } |
1220 | | |
1221 | | static gboolean |
1222 | | is_ayuv_to_rgb_matrix (MatrixData * data) |
1223 | 764 | { |
1224 | 764 | if (data->im[0][0] != data->im[1][0] || data->im[1][0] != data->im[2][0]) |
1225 | 0 | return FALSE; |
1226 | | |
1227 | 764 | if (data->im[0][1] != 0 || data->im[2][2] != 0) |
1228 | 0 | return FALSE; |
1229 | | |
1230 | 764 | return TRUE; |
1231 | 764 | } |
1232 | | |
1233 | | static gboolean |
1234 | | is_identity_matrix (MatrixData * data) |
1235 | 1.22k | { |
1236 | 1.22k | gint i, j; |
1237 | 1.22k | gint c = data->im[0][0]; |
1238 | | |
1239 | | /* not really checking identity because of rounding errors but given |
1240 | | * the conversions we do we just check for anything that looks like: |
1241 | | * |
1242 | | * c 0 0 0 |
1243 | | * 0 c 0 0 |
1244 | | * 0 0 c 0 |
1245 | | * 0 0 0 1 |
1246 | | */ |
1247 | 4.90k | for (i = 0; i < 4; i++) { |
1248 | 23.2k | for (j = 0; j < 4; j++) { |
1249 | 19.6k | if (i == j) { |
1250 | 4.90k | if (i == 3 && data->im[i][j] != 1) |
1251 | 1.22k | return FALSE; |
1252 | 3.67k | else if (data->im[i][j] != c) |
1253 | 0 | return FALSE; |
1254 | 14.7k | } else if (data->im[i][j] != 0) |
1255 | 0 | return FALSE; |
1256 | 19.6k | } |
1257 | 4.90k | } |
1258 | 0 | return TRUE; |
1259 | 1.22k | } |
1260 | | |
1261 | | static gboolean |
1262 | | is_identity_matrix_float (MatrixData * data) |
1263 | 0 | { |
1264 | 0 | gint i, j; |
1265 | |
|
1266 | 0 | for (i = 0; i < 4; i++) { |
1267 | 0 | for (j = 0; j < 4; j++) { |
1268 | 0 | if (data->dm[i][j] != (i == j ? 1.0 : 0.0)) |
1269 | 0 | return FALSE; |
1270 | 0 | } |
1271 | 0 | } |
1272 | | |
1273 | 0 | return TRUE; |
1274 | 0 | } |
1275 | | |
1276 | | static gboolean |
1277 | | is_no_clip_matrix (MatrixData * data) |
1278 | 223 | { |
1279 | 223 | gint i; |
1280 | 223 | static const guint8 test[8][3] = { |
1281 | 223 | {0, 0, 0}, |
1282 | 223 | {0, 0, 255}, |
1283 | 223 | {0, 255, 0}, |
1284 | 223 | {0, 255, 255}, |
1285 | 223 | {255, 0, 0}, |
1286 | 223 | {255, 0, 255}, |
1287 | 223 | {255, 255, 0}, |
1288 | 223 | {255, 255, 255} |
1289 | 223 | }; |
1290 | | |
1291 | 1.25k | for (i = 0; i < 8; i++) { |
1292 | 1.12k | gint r, g, b; |
1293 | 1.12k | gint y, u, v; |
1294 | | |
1295 | 1.12k | r = test[i][0]; |
1296 | 1.12k | g = test[i][1]; |
1297 | 1.12k | b = test[i][2]; |
1298 | | |
1299 | 1.12k | y = (data->im[0][0] * r + data->im[0][1] * g + |
1300 | 1.12k | data->im[0][2] * b + data->im[0][3]) >> SCALE; |
1301 | 1.12k | u = (data->im[1][0] * r + data->im[1][1] * g + |
1302 | 1.12k | data->im[1][2] * b + data->im[1][3]) >> SCALE; |
1303 | 1.12k | v = (data->im[2][0] * r + data->im[2][1] * g + |
1304 | 1.12k | data->im[2][2] * b + data->im[2][3]) >> SCALE; |
1305 | | |
1306 | 1.12k | if (y != CLAMP (y, 0, 255) || u != CLAMP (u, 0, 255) |
1307 | 1.03k | || v != CLAMP (v, 0, 255)) |
1308 | 94 | return FALSE; |
1309 | 1.12k | } |
1310 | 129 | return TRUE; |
1311 | 223 | } |
1312 | | |
1313 | | static void |
1314 | | video_converter_matrix16 (MatrixData * data, gpointer pixels) |
1315 | 13.8k | { |
1316 | 13.8k | int i; |
1317 | 13.8k | int r, g, b; |
1318 | 13.8k | int y, u, v; |
1319 | 13.8k | guint16 *p = pixels; |
1320 | 13.8k | gint width = data->width; |
1321 | | |
1322 | 1.47M | for (i = 0; i < width; i++) { |
1323 | 1.45M | r = p[i * 4 + 1]; |
1324 | 1.45M | g = p[i * 4 + 2]; |
1325 | 1.45M | b = p[i * 4 + 3]; |
1326 | | |
1327 | 1.45M | y = (data->im[0][0] * r + data->im[0][1] * g + |
1328 | 1.45M | data->im[0][2] * b + data->im[0][3]) >> SCALE; |
1329 | 1.45M | u = (data->im[1][0] * r + data->im[1][1] * g + |
1330 | 1.45M | data->im[1][2] * b + data->im[1][3]) >> SCALE; |
1331 | 1.45M | v = (data->im[2][0] * r + data->im[2][1] * g + |
1332 | 1.45M | data->im[2][2] * b + data->im[2][3]) >> SCALE; |
1333 | | |
1334 | 1.45M | p[i * 4 + 1] = CLAMP (y, 0, 65535); |
1335 | 1.45M | p[i * 4 + 2] = CLAMP (u, 0, 65535); |
1336 | 1.45M | p[i * 4 + 3] = CLAMP (v, 0, 65535); |
1337 | 1.45M | } |
1338 | 13.8k | } |
1339 | | |
1340 | | static void |
1341 | | video_converter_matrix_float (MatrixData * data, gpointer pixels) |
1342 | 0 | { |
1343 | 0 | gfloat *p = pixels; |
1344 | 0 | gint i; |
1345 | |
|
1346 | 0 | for (i = 0; i < data->width; i++) { |
1347 | 0 | gdouble r = p[i * 4 + 1]; |
1348 | 0 | gdouble g = p[i * 4 + 2]; |
1349 | 0 | gdouble b = p[i * 4 + 3]; |
1350 | |
|
1351 | 0 | p[i * 4 + 1] = data->dm[0][0] * r + data->dm[0][1] * g + |
1352 | 0 | data->dm[0][2] * b + data->dm[0][3]; |
1353 | 0 | p[i * 4 + 2] = data->dm[1][0] * r + data->dm[1][1] * g + |
1354 | 0 | data->dm[1][2] * b + data->dm[1][3]; |
1355 | 0 | p[i * 4 + 3] = data->dm[2][0] * r + data->dm[2][1] * g + |
1356 | 0 | data->dm[2][2] * b + data->dm[2][3]; |
1357 | 0 | } |
1358 | 0 | } |
1359 | | |
1360 | | static gboolean |
1361 | | is_float_format (GstVideoFormat format) |
1362 | 4.06k | { |
1363 | 4.06k | const GstVideoFormatInfo *finfo = gst_video_format_get_info (format); |
1364 | | |
1365 | 4.06k | return GST_VIDEO_FORMAT_INFO_IS_FLOAT (finfo); |
1366 | 4.06k | } |
1367 | | |
1368 | | static void |
1369 | | prepare_matrix (GstVideoConverter * convert, MatrixData * data) |
1370 | 1.22k | { |
1371 | 1.22k | data->width = convert->current_width; |
1372 | | |
1373 | 1.22k | if (is_float_format (convert->current_format)) { |
1374 | 0 | if (!is_identity_matrix_float (data)) { |
1375 | 0 | GST_LOG ("use float matrix"); |
1376 | 0 | data->matrix_func = video_converter_matrix_float; |
1377 | 0 | } |
1378 | 0 | return; |
1379 | 0 | } |
1380 | | |
1381 | 1.22k | if (is_identity_matrix (data)) |
1382 | 0 | return; |
1383 | | |
1384 | 1.22k | color_matrix_scale_components (data, SCALE_F, SCALE_F, SCALE_F); |
1385 | 1.22k | color_matrix_convert (data); |
1386 | | |
1387 | 1.22k | if (convert->current_bits == 8) { |
1388 | 987 | if (!convert->unpack_rgb && convert->pack_rgb |
1389 | 764 | && is_ayuv_to_rgb_matrix (data)) { |
1390 | 764 | GST_LOG ("use fast AYUV -> RGB matrix"); |
1391 | 764 | data->matrix_func = video_converter_matrix8_AYUV_ARGB; |
1392 | 764 | } else if (is_no_clip_matrix (data)) { |
1393 | 129 | GST_LOG ("use 8bit table"); |
1394 | 129 | data->matrix_func = video_converter_matrix8_table; |
1395 | 129 | videoconvert_convert_init_tables (data); |
1396 | 129 | } else { |
1397 | 94 | gint a03, a13, a23; |
1398 | | |
1399 | 94 | GST_LOG ("use 8bit matrix"); |
1400 | 94 | data->matrix_func = video_converter_matrix8; |
1401 | | |
1402 | 94 | data->orc_p1 = (((guint64) (guint16) data->im[2][0]) << 48) | |
1403 | 94 | (((guint64) (guint16) data->im[1][0]) << 32) | |
1404 | 94 | (((guint64) (guint16) data->im[0][0]) << 16); |
1405 | 94 | data->orc_p2 = (((guint64) (guint16) data->im[2][1]) << 48) | |
1406 | 94 | (((guint64) (guint16) data->im[1][1]) << 32) | |
1407 | 94 | (((guint64) (guint16) data->im[0][1]) << 16); |
1408 | 94 | data->orc_p3 = (((guint64) (guint16) data->im[2][2]) << 48) | |
1409 | 94 | (((guint64) (guint16) data->im[1][2]) << 32) | |
1410 | 94 | (((guint64) (guint16) data->im[0][2]) << 16); |
1411 | | |
1412 | 94 | a03 = data->im[0][3] >> SCALE; |
1413 | 94 | a13 = data->im[1][3] >> SCALE; |
1414 | 94 | a23 = data->im[2][3] >> SCALE; |
1415 | | |
1416 | 94 | data->orc_p4 = (((guint64) (guint16) a23) << 48) | |
1417 | 94 | (((guint64) (guint16) a13) << 32) | (((guint64) (guint16) a03) << 16); |
1418 | 94 | } |
1419 | 987 | } else { |
1420 | 238 | GST_LOG ("use 16bit matrix"); |
1421 | 238 | data->matrix_func = video_converter_matrix16; |
1422 | 238 | } |
1423 | 1.22k | } |
1424 | | |
1425 | | static void |
1426 | | compute_matrix_to_RGB (GstVideoConverter * convert, MatrixData * data) |
1427 | 1.24k | { |
1428 | 1.24k | GstVideoInfo *info; |
1429 | 1.24k | gdouble Kr = 0, Kb = 0; |
1430 | | |
1431 | 1.24k | info = &convert->in_info; |
1432 | | |
1433 | 1.24k | { |
1434 | 1.24k | const GstVideoFormatInfo *uinfo; |
1435 | 1.24k | gdouble offset[4], scale[4]; |
1436 | | |
1437 | 1.24k | uinfo = gst_video_format_get_info (convert->unpack_format); |
1438 | | |
1439 | | /* bring color components to [0..1.0] range */ |
1440 | 1.24k | gst_video_color_range_offsets_full (info->colorimetry.range, |
1441 | 1.24k | uinfo, offset, scale, NULL); |
1442 | | |
1443 | 1.24k | color_matrix_offset_components (data, -offset[0], -offset[1], -offset[2]); |
1444 | 1.24k | color_matrix_scale_components (data, 1 / ((float) scale[0]), |
1445 | 1.24k | 1 / ((float) scale[1]), 1 / ((float) scale[2])); |
1446 | 1.24k | } |
1447 | | |
1448 | 1.24k | if (!convert->unpack_rgb && !CHECK_MATRIX_NONE (convert)) { |
1449 | 1.06k | if (CHECK_MATRIX_OUTPUT (convert)) |
1450 | 0 | info = &convert->out_info; |
1451 | | |
1452 | | /* bring components to R'G'B' space */ |
1453 | 1.06k | if (gst_video_color_matrix_get_Kr_Kb (info->colorimetry.matrix, &Kr, &Kb)) |
1454 | 1.06k | color_matrix_YCbCr_to_RGB (data, Kr, Kb); |
1455 | 1.06k | } |
1456 | 1.24k | color_matrix_debug (data); |
1457 | 1.24k | } |
1458 | | |
1459 | | static void |
1460 | | compute_matrix_to_YUV (GstVideoConverter * convert, MatrixData * data, |
1461 | | gboolean force) |
1462 | 1.24k | { |
1463 | 1.24k | GstVideoInfo *info; |
1464 | 1.24k | gdouble Kr = 0, Kb = 0; |
1465 | | |
1466 | 1.24k | if (force || (!convert->pack_rgb && !CHECK_MATRIX_NONE (convert))) { |
1467 | 401 | if (CHECK_MATRIX_INPUT (convert)) |
1468 | 0 | info = &convert->in_info; |
1469 | 401 | else |
1470 | 401 | info = &convert->out_info; |
1471 | | |
1472 | | /* bring components to YCbCr space */ |
1473 | 401 | if (gst_video_color_matrix_get_Kr_Kb (info->colorimetry.matrix, &Kr, &Kb)) |
1474 | 401 | color_matrix_RGB_to_YCbCr (data, Kr, Kb); |
1475 | 401 | } |
1476 | | |
1477 | 1.24k | info = &convert->out_info; |
1478 | | |
1479 | 1.24k | { |
1480 | 1.24k | const GstVideoFormatInfo *uinfo; |
1481 | 1.24k | gdouble offset[4], scale[4]; |
1482 | | |
1483 | 1.24k | uinfo = gst_video_format_get_info (convert->pack_format); |
1484 | | |
1485 | | /* bring color components to nominal range */ |
1486 | 1.24k | gst_video_color_range_offsets_full (info->colorimetry.range, |
1487 | 1.24k | uinfo, offset, scale, NULL); |
1488 | | |
1489 | 1.24k | color_matrix_scale_components (data, (float) scale[0], (float) scale[1], |
1490 | 1.24k | (float) scale[2]); |
1491 | 1.24k | color_matrix_offset_components (data, offset[0], offset[1], offset[2]); |
1492 | 1.24k | } |
1493 | | |
1494 | 1.24k | color_matrix_debug (data); |
1495 | 1.24k | } |
1496 | | |
1497 | | |
1498 | | static void |
1499 | | gamma_convert_u8_u16 (GammaData * data, gpointer dest, gpointer src) |
1500 | 0 | { |
1501 | 0 | gint i; |
1502 | 0 | guint8 *s = src; |
1503 | 0 | guint16 *d = dest; |
1504 | 0 | guint16 *table = data->gamma_table; |
1505 | 0 | gint width = data->width * 4; |
1506 | |
|
1507 | 0 | for (i = 0; i < width; i += 4) { |
1508 | 0 | d[i + 0] = (s[i] << 8) | s[i]; |
1509 | 0 | d[i + 1] = table[s[i + 1]]; |
1510 | 0 | d[i + 2] = table[s[i + 2]]; |
1511 | 0 | d[i + 3] = table[s[i + 3]]; |
1512 | 0 | } |
1513 | 0 | } |
1514 | | |
1515 | | static void |
1516 | | gamma_convert_u16_u8 (GammaData * data, gpointer dest, gpointer src) |
1517 | 0 | { |
1518 | 0 | gint i; |
1519 | 0 | guint16 *s = src; |
1520 | 0 | guint8 *d = dest; |
1521 | 0 | guint8 *table = data->gamma_table; |
1522 | 0 | gint width = data->width * 4; |
1523 | |
|
1524 | 0 | for (i = 0; i < width; i += 4) { |
1525 | 0 | d[i + 0] = s[i] >> 8; |
1526 | 0 | d[i + 1] = table[s[i + 1]]; |
1527 | 0 | d[i + 2] = table[s[i + 2]]; |
1528 | 0 | d[i + 3] = table[s[i + 3]]; |
1529 | 0 | } |
1530 | 0 | } |
1531 | | |
1532 | | static void |
1533 | | gamma_convert_u16_u16 (GammaData * data, gpointer dest, gpointer src) |
1534 | 0 | { |
1535 | 0 | gint i; |
1536 | 0 | guint16 *s = src; |
1537 | 0 | guint16 *d = dest; |
1538 | 0 | guint16 *table = data->gamma_table; |
1539 | 0 | gint width = data->width * 4; |
1540 | |
|
1541 | 0 | for (i = 0; i < width; i += 4) { |
1542 | 0 | d[i + 0] = s[i]; |
1543 | 0 | d[i + 1] = table[s[i + 1]]; |
1544 | 0 | d[i + 2] = table[s[i + 2]]; |
1545 | 0 | d[i + 3] = table[s[i + 3]]; |
1546 | 0 | } |
1547 | 0 | } |
1548 | | |
1549 | | static inline gdouble |
1550 | | CLAMP_F (gfloat f) |
1551 | 0 | { |
1552 | 0 | return CLAMP (f, 0.0f, 1.0f); |
1553 | 0 | } |
1554 | | |
1555 | | /* float unpack format is already in [0, 1], so we can use |
1556 | | * transfer_function_{decode,encode} directly */ |
1557 | | static void |
1558 | | gamma_decode_float (GammaData * data, gpointer dest, gpointer src) |
1559 | 0 | { |
1560 | 0 | gfloat *s = src; |
1561 | 0 | gfloat *d = dest; |
1562 | 0 | gint i; |
1563 | |
|
1564 | 0 | for (i = 0; i < data->width; i++) { |
1565 | 0 | d[i * 4 + 0] = s[i * 4 + 0]; |
1566 | 0 | d[i * 4 + 1] = |
1567 | 0 | gst_video_transfer_function_decode (data->tr_func, |
1568 | 0 | CLAMP_F (s[i * 4 + 1])); |
1569 | 0 | d[i * 4 + 2] = |
1570 | 0 | gst_video_transfer_function_decode (data->tr_func, |
1571 | 0 | CLAMP_F (s[i * 4 + 2])); |
1572 | 0 | d[i * 4 + 3] = |
1573 | 0 | gst_video_transfer_function_decode (data->tr_func, |
1574 | 0 | CLAMP_F (s[i * 4 + 3])); |
1575 | 0 | } |
1576 | 0 | } |
1577 | | |
1578 | | static void |
1579 | | gamma_encode_float (GammaData * data, gpointer dest, gpointer src) |
1580 | 0 | { |
1581 | 0 | gfloat *s = src; |
1582 | 0 | gfloat *d = dest; |
1583 | 0 | gint i; |
1584 | |
|
1585 | 0 | for (i = 0; i < data->width; i++) { |
1586 | 0 | d[i * 4 + 0] = s[i * 4 + 0]; |
1587 | 0 | d[i * 4 + 1] = |
1588 | 0 | gst_video_transfer_function_encode (data->tr_func, |
1589 | 0 | CLAMP_F (s[i * 4 + 1])); |
1590 | 0 | d[i * 4 + 2] = |
1591 | 0 | gst_video_transfer_function_encode (data->tr_func, |
1592 | 0 | CLAMP_F (s[i * 4 + 2])); |
1593 | 0 | d[i * 4 + 3] = |
1594 | 0 | gst_video_transfer_function_encode (data->tr_func, |
1595 | 0 | CLAMP_F (s[i * 4 + 3])); |
1596 | 0 | } |
1597 | 0 | } |
1598 | | |
1599 | | static void |
1600 | | gamma_encode_float_u8 (GammaData * data, gpointer dest, gpointer src) |
1601 | 0 | { |
1602 | 0 | gfloat *s = src; |
1603 | 0 | guint8 *d = dest; |
1604 | 0 | gint i; |
1605 | |
|
1606 | 0 | for (i = 0; i < data->width; i++) { |
1607 | 0 | gdouble val; |
1608 | |
|
1609 | 0 | val = s[i * 4 + 0] * 255.0; |
1610 | 0 | val = rint (val); |
1611 | 0 | d[i * 4 + 0] = CLAMP (val, 0, 255); |
1612 | |
|
1613 | 0 | val = gst_video_transfer_function_encode (data->tr_func, |
1614 | 0 | CLAMP_F (s[i * 4 + 1])) * 255.0; |
1615 | 0 | val = rint (val); |
1616 | 0 | d[i * 4 + 1] = CLAMP (val, 0, 255); |
1617 | |
|
1618 | 0 | val = gst_video_transfer_function_encode (data->tr_func, |
1619 | 0 | CLAMP_F (s[i * 4 + 2])) * 255.0; |
1620 | 0 | val = rint (val); |
1621 | 0 | d[i * 4 + 2] = CLAMP (val, 0, 255); |
1622 | |
|
1623 | 0 | val = gst_video_transfer_function_encode (data->tr_func, |
1624 | 0 | CLAMP_F (s[i * 4 + 3])) * 255.0; |
1625 | 0 | val = rint (val); |
1626 | 0 | d[i * 4 + 3] = CLAMP (val, 0, 255); |
1627 | 0 | } |
1628 | 0 | } |
1629 | | |
1630 | | static void |
1631 | | gamma_encode_float_u16 (GammaData * data, gpointer dest, gpointer src) |
1632 | 0 | { |
1633 | 0 | gfloat *s = src; |
1634 | 0 | guint16 *d = dest; |
1635 | 0 | gint i; |
1636 | |
|
1637 | 0 | for (i = 0; i < data->width; i++) { |
1638 | 0 | gdouble val; |
1639 | |
|
1640 | 0 | val = CLAMP_F (s[i * 4 + 0]) * 65535.0; |
1641 | 0 | val = rint (val); |
1642 | 0 | d[i * 4 + 0] = CLAMP (val, 0, 65535); |
1643 | |
|
1644 | 0 | val = gst_video_transfer_function_encode (data->tr_func, |
1645 | 0 | CLAMP_F (s[i * 4 + 1])) * 65535.0; |
1646 | 0 | val = rint (val); |
1647 | 0 | d[i * 4 + 1] = CLAMP (val, 0, 65535); |
1648 | |
|
1649 | 0 | val = gst_video_transfer_function_encode (data->tr_func, |
1650 | 0 | CLAMP_F (s[i * 4 + 2])) * 65535.0; |
1651 | 0 | val = rint (val); |
1652 | 0 | d[i * 4 + 2] = CLAMP (val, 0, 65535); |
1653 | |
|
1654 | 0 | val = gst_video_transfer_function_encode (data->tr_func, |
1655 | 0 | CLAMP_F (s[i * 4 + 3])) * 65535.0; |
1656 | 0 | val = rint (val); |
1657 | 0 | d[i * 4 + 3] = CLAMP (val, 0, 65535); |
1658 | 0 | } |
1659 | 0 | } |
1660 | | |
1661 | | /* input is still 16-bit here, so table lookup would be cheaper than doing |
1662 | | * transfer function for each pixel */ |
1663 | | static void |
1664 | | gamma_encode_u16_float (GammaData * data, gpointer dest, gpointer src) |
1665 | 0 | { |
1666 | 0 | guint16 *s = src; |
1667 | 0 | gfloat *d = dest; |
1668 | 0 | gfloat *table = data->gamma_table; |
1669 | 0 | gint i; |
1670 | |
|
1671 | 0 | for (i = 0; i < data->width; i++) { |
1672 | 0 | d[i * 4 + 0] = s[i * 4 + 0] / 65535.0; |
1673 | 0 | d[i * 4 + 1] = table[s[i * 4 + 1]]; |
1674 | 0 | d[i * 4 + 2] = table[s[i * 4 + 2]]; |
1675 | 0 | d[i * 4 + 3] = table[s[i * 4 + 3]]; |
1676 | 0 | } |
1677 | 0 | } |
1678 | | |
1679 | | static void |
1680 | | setup_gamma_decode (GstVideoConverter * convert) |
1681 | 0 | { |
1682 | 0 | GstVideoTransferFunction func; |
1683 | 0 | guint16 *t; |
1684 | 0 | gint i; |
1685 | 0 | gboolean is_float; |
1686 | |
|
1687 | 0 | func = convert->in_info.colorimetry.transfer; |
1688 | 0 | is_float = is_float_format (convert->current_format); |
1689 | |
|
1690 | 0 | convert->gamma_dec.width = convert->current_width; |
1691 | 0 | convert->gamma_dec.tr_func = func; |
1692 | |
|
1693 | 0 | if (convert->gamma_dec.gamma_func) { |
1694 | 0 | GST_LOG ("gamma decode already set up"); |
1695 | 0 | } else if (is_float) { |
1696 | 0 | GST_LOG ("gamma decode float: %d", func); |
1697 | 0 | convert->gamma_dec.gamma_func = gamma_decode_float; |
1698 | 0 | } else if (convert->current_bits == 8) { |
1699 | 0 | GST_LOG ("gamma decode 8->16: %d", func); |
1700 | 0 | convert->gamma_dec.gamma_func = gamma_convert_u8_u16; |
1701 | 0 | t = convert->gamma_dec.gamma_table = g_malloc (sizeof (guint16) * 256); |
1702 | |
|
1703 | 0 | for (i = 0; i < 256; i++) |
1704 | 0 | t[i] = |
1705 | 0 | rint (gst_video_transfer_function_decode (func, i / 255.0) * 65535.0); |
1706 | 0 | } else { |
1707 | 0 | GST_LOG ("gamma decode 16->16: %d", func); |
1708 | 0 | convert->gamma_dec.gamma_func = gamma_convert_u16_u16; |
1709 | 0 | t = convert->gamma_dec.gamma_table = g_malloc (sizeof (guint16) * 65536); |
1710 | |
|
1711 | 0 | for (i = 0; i < 65536; i++) |
1712 | 0 | t[i] = |
1713 | 0 | rint (gst_video_transfer_function_decode (func, |
1714 | 0 | i / 65535.0) * 65535.0); |
1715 | 0 | } |
1716 | | |
1717 | | /* gamma decoded data is still in float domain if input is float. |
1718 | | * And integer path uses ARGB64 as intermediate format |
1719 | | */ |
1720 | 0 | if (is_float) { |
1721 | 0 | convert->current_bits = 32; |
1722 | 0 | convert->current_pstride = 16; |
1723 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB_F32; |
1724 | 0 | } else { |
1725 | 0 | convert->current_bits = 16; |
1726 | 0 | convert->current_pstride = 8; |
1727 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB64; |
1728 | 0 | } |
1729 | 0 | } |
1730 | | |
1731 | | static void |
1732 | | setup_gamma_encode (GstVideoConverter * convert, gint target_bits) |
1733 | 0 | { |
1734 | 0 | GstVideoTransferFunction func; |
1735 | 0 | gboolean src_float, dst_float; |
1736 | 0 | gint i; |
1737 | |
|
1738 | 0 | func = convert->out_info.colorimetry.transfer; |
1739 | |
|
1740 | 0 | src_float = is_float_format (convert->current_format); |
1741 | 0 | dst_float = is_float_format (convert->pack_format); |
1742 | |
|
1743 | 0 | convert->gamma_enc.width = convert->current_width; |
1744 | 0 | convert->gamma_enc.tr_func = func; |
1745 | |
|
1746 | 0 | if (convert->gamma_enc.gamma_func) { |
1747 | 0 | GST_LOG ("gamma encode already set up"); |
1748 | 0 | } else if (src_float) { |
1749 | 0 | if (dst_float) { |
1750 | 0 | GST_LOG ("gamma encode float->float: %d", func); |
1751 | 0 | convert->gamma_enc.gamma_func = gamma_encode_float; |
1752 | 0 | } else if (target_bits == 8) { |
1753 | 0 | GST_LOG ("gamma encode float->8: %d", func); |
1754 | 0 | convert->gamma_enc.gamma_func = gamma_encode_float_u8; |
1755 | 0 | } else { |
1756 | 0 | GST_LOG ("gamma encode float->16: %d", func); |
1757 | 0 | convert->gamma_enc.gamma_func = gamma_encode_float_u16; |
1758 | 0 | } |
1759 | 0 | } else if (dst_float) { |
1760 | 0 | gfloat *t; |
1761 | |
|
1762 | 0 | GST_LOG ("gamma encode 16->float: %d", func); |
1763 | 0 | convert->gamma_enc.gamma_func = gamma_encode_u16_float; |
1764 | |
|
1765 | 0 | t = convert->gamma_enc.gamma_table = g_malloc (sizeof (gfloat) * 65536); |
1766 | 0 | for (i = 0; i < 65536; i++) { |
1767 | 0 | t[i] = gst_video_transfer_function_encode (func, i / 65535.0); |
1768 | 0 | } |
1769 | 0 | } else if (target_bits == 8) { |
1770 | 0 | guint8 *t; |
1771 | |
|
1772 | 0 | GST_LOG ("gamma encode 16->8: %d", func); |
1773 | 0 | convert->gamma_enc.gamma_func = gamma_convert_u16_u8; |
1774 | 0 | t = convert->gamma_enc.gamma_table = g_malloc (sizeof (guint8) * 65536); |
1775 | |
|
1776 | 0 | for (i = 0; i < 65536; i++) |
1777 | 0 | t[i] = |
1778 | 0 | rint (gst_video_transfer_function_encode (func, i / 65535.0) * 255.0); |
1779 | 0 | } else { |
1780 | 0 | guint16 *t; |
1781 | |
|
1782 | 0 | GST_LOG ("gamma encode 16->16: %d", func); |
1783 | 0 | convert->gamma_enc.gamma_func = gamma_convert_u16_u16; |
1784 | 0 | t = convert->gamma_enc.gamma_table = g_malloc (sizeof (guint16) * 65536); |
1785 | |
|
1786 | 0 | for (i = 0; i < 65536; i++) |
1787 | 0 | t[i] = |
1788 | 0 | rint (gst_video_transfer_function_encode (func, |
1789 | 0 | i / 65535.0) * 65535.0); |
1790 | 0 | } |
1791 | |
|
1792 | 0 | if (dst_float) { |
1793 | 0 | convert->current_bits = 32; |
1794 | 0 | convert->current_pstride = 16; |
1795 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB_F32; |
1796 | 0 | } else { |
1797 | 0 | convert->current_bits = target_bits; |
1798 | 0 | convert->current_pstride = target_bits >> 1; |
1799 | |
|
1800 | 0 | if (target_bits == 8) |
1801 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB; |
1802 | 0 | else |
1803 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB64; |
1804 | 0 | } |
1805 | 0 | } |
1806 | | |
1807 | | static GstLineCache * |
1808 | | chain_convert_to_RGB (GstVideoConverter * convert, GstLineCache * prev, |
1809 | | gint idx) |
1810 | 946 | { |
1811 | 946 | gboolean do_gamma; |
1812 | | |
1813 | 946 | do_gamma = CHECK_GAMMA_REMAP (convert); |
1814 | | |
1815 | 946 | if (do_gamma) { |
1816 | 0 | gint scale; |
1817 | | |
1818 | | /* Set up conversion matrices if needed, but only for the first thread */ |
1819 | 0 | if (idx == 0 && !convert->unpack_rgb) { |
1820 | 0 | gboolean is_float = is_float_format (convert->current_format); |
1821 | |
|
1822 | 0 | color_matrix_set_identity (&convert->to_RGB_matrix); |
1823 | 0 | compute_matrix_to_RGB (convert, &convert->to_RGB_matrix); |
1824 | |
|
1825 | 0 | GST_LOG ("chain RGB convert"); |
1826 | 0 | if (!is_float) { |
1827 | | /* matrix is in 0..1 range, scale to current bits */ |
1828 | 0 | scale = 1 << convert->current_bits; |
1829 | 0 | color_matrix_scale_components (&convert->to_RGB_matrix, |
1830 | 0 | (float) scale, (float) scale, (float) scale); |
1831 | 0 | } |
1832 | |
|
1833 | 0 | prepare_matrix (convert, &convert->to_RGB_matrix); |
1834 | |
|
1835 | 0 | if (is_float) { |
1836 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB_F32; |
1837 | 0 | } else if (convert->current_bits == 8) { |
1838 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB; |
1839 | 0 | } else { |
1840 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB64; |
1841 | 0 | } |
1842 | 0 | } |
1843 | |
|
1844 | 0 | prev = convert->to_RGB_lines[idx] = gst_line_cache_new (prev); |
1845 | 0 | prev->write_input = TRUE; |
1846 | 0 | prev->pass_alloc = FALSE; |
1847 | 0 | prev->n_lines = 1; |
1848 | 0 | prev->stride = convert->current_pstride * convert->current_width; |
1849 | 0 | gst_line_cache_set_need_line_func (prev, |
1850 | 0 | do_convert_to_RGB_lines, idx, convert, NULL); |
1851 | |
|
1852 | 0 | GST_LOG ("chain gamma decode"); |
1853 | 0 | setup_gamma_decode (convert); |
1854 | 0 | } |
1855 | 946 | return prev; |
1856 | 946 | } |
1857 | | |
1858 | | static GstLineCache * |
1859 | | chain_hscale (GstVideoConverter * convert, GstLineCache * prev, gint idx) |
1860 | 703 | { |
1861 | 703 | gint method; |
1862 | 703 | guint taps; |
1863 | | |
1864 | 703 | method = GET_OPT_RESAMPLER_METHOD (convert); |
1865 | 703 | taps = GET_OPT_RESAMPLER_TAPS (convert); |
1866 | | |
1867 | 703 | convert->h_scaler[idx] = |
1868 | 703 | gst_video_scaler_new (method, GST_VIDEO_SCALER_FLAG_NONE, taps, |
1869 | 703 | convert->in_width, convert->out_width, convert->config); |
1870 | | |
1871 | 703 | gst_video_scaler_get_coeff (convert->h_scaler[idx], 0, NULL, &taps); |
1872 | | |
1873 | 703 | GST_LOG ("chain hscale %d->%d, taps %d, method %d", |
1874 | 703 | convert->in_width, convert->out_width, taps, method); |
1875 | | |
1876 | 703 | convert->current_width = convert->out_width; |
1877 | 703 | convert->h_scale_format = convert->current_format; |
1878 | | |
1879 | 703 | prev = convert->hscale_lines[idx] = gst_line_cache_new (prev); |
1880 | 703 | prev->write_input = FALSE; |
1881 | 703 | prev->pass_alloc = FALSE; |
1882 | 703 | prev->n_lines = 1; |
1883 | 703 | prev->stride = convert->current_pstride * convert->current_width; |
1884 | 703 | gst_line_cache_set_need_line_func (prev, do_hscale_lines, idx, convert, NULL); |
1885 | | |
1886 | 703 | return prev; |
1887 | 703 | } |
1888 | | |
1889 | | static GstLineCache * |
1890 | | chain_vscale (GstVideoConverter * convert, GstLineCache * prev, gint idx) |
1891 | 740 | { |
1892 | 740 | gint method; |
1893 | 740 | guint taps, taps_i = 0; |
1894 | 740 | gint backlog = 0; |
1895 | | |
1896 | 740 | method = GET_OPT_RESAMPLER_METHOD (convert); |
1897 | 740 | taps = GET_OPT_RESAMPLER_TAPS (convert); |
1898 | | |
1899 | 740 | if (GST_VIDEO_INFO_IS_INTERLACED (&convert->in_info) |
1900 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&convert->in_info) != |
1901 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE)) { |
1902 | 0 | convert->v_scaler_i[idx] = |
1903 | 0 | gst_video_scaler_new (method, GST_VIDEO_SCALER_FLAG_INTERLACED, taps, |
1904 | 0 | convert->in_height, convert->out_height, convert->config); |
1905 | |
|
1906 | 0 | gst_video_scaler_get_coeff (convert->v_scaler_i[idx], 0, NULL, &taps_i); |
1907 | 0 | backlog = taps_i; |
1908 | 0 | } |
1909 | 740 | convert->v_scaler_p[idx] = |
1910 | 740 | gst_video_scaler_new (method, 0, taps, convert->in_height, |
1911 | 740 | convert->out_height, convert->config); |
1912 | 740 | convert->v_scale_width = convert->current_width; |
1913 | 740 | convert->v_scale_format = convert->current_format; |
1914 | 740 | convert->current_height = convert->out_height; |
1915 | | |
1916 | 740 | gst_video_scaler_get_coeff (convert->v_scaler_p[idx], 0, NULL, &taps); |
1917 | | |
1918 | 740 | GST_LOG ("chain vscale %d->%d, taps %d, method %d, backlog %d", |
1919 | 740 | convert->in_height, convert->out_height, taps, method, backlog); |
1920 | | |
1921 | 740 | prev->backlog = backlog; |
1922 | 740 | prev = convert->vscale_lines[idx] = gst_line_cache_new (prev); |
1923 | 740 | prev->pass_alloc = (taps == 1); |
1924 | 740 | prev->write_input = FALSE; |
1925 | 740 | prev->n_lines = MAX (taps_i, taps); |
1926 | 740 | prev->stride = convert->current_pstride * convert->current_width; |
1927 | 740 | gst_line_cache_set_need_line_func (prev, do_vscale_lines, idx, convert, NULL); |
1928 | | |
1929 | 740 | return prev; |
1930 | 740 | } |
1931 | | |
1932 | | static GstLineCache * |
1933 | | chain_scale (GstVideoConverter * convert, GstLineCache * prev, gboolean force, |
1934 | | gint idx) |
1935 | 1.89k | { |
1936 | 1.89k | gint s0, s1, s2, s3; |
1937 | | |
1938 | 1.89k | s0 = convert->current_width * convert->current_height; |
1939 | 1.89k | s3 = convert->out_width * convert->out_height; |
1940 | | |
1941 | 1.89k | GST_LOG ("in pixels %d <> out pixels %d", s0, s3); |
1942 | | |
1943 | 1.89k | if (s3 <= s0 || force) { |
1944 | | /* we are making the image smaller or are forced to resample */ |
1945 | 1.46k | s1 = convert->out_width * convert->current_height; |
1946 | 1.46k | s2 = convert->current_width * convert->out_height; |
1947 | | |
1948 | 1.46k | GST_LOG ("%d <> %d", s1, s2); |
1949 | | |
1950 | 1.46k | if (s1 <= s2) { |
1951 | | /* h scaling first produces less pixels */ |
1952 | 1.07k | if (convert->current_width != convert->out_width) |
1953 | 359 | prev = chain_hscale (convert, prev, idx); |
1954 | 1.07k | if (convert->current_height != convert->out_height) |
1955 | 396 | prev = chain_vscale (convert, prev, idx); |
1956 | 1.07k | } else { |
1957 | | /* v scaling first produces less pixels */ |
1958 | 393 | if (convert->current_height != convert->out_height) |
1959 | 344 | prev = chain_vscale (convert, prev, idx); |
1960 | 393 | if (convert->current_width != convert->out_width) |
1961 | 344 | prev = chain_hscale (convert, prev, idx); |
1962 | 393 | } |
1963 | 1.46k | } |
1964 | 1.89k | return prev; |
1965 | 1.89k | } |
1966 | | |
1967 | | static GstLineCache * |
1968 | | chain_convert (GstVideoConverter * convert, GstLineCache * prev, gint idx) |
1969 | 946 | { |
1970 | 946 | gboolean do_gamma, do_conversion, pass_alloc = FALSE; |
1971 | 946 | gboolean same_matrix, same_primaries, same_bits, same_ranges; |
1972 | 946 | MatrixData p1, p2; |
1973 | | |
1974 | 946 | same_bits = convert->unpack_bits == convert->pack_bits; |
1975 | 946 | if (CHECK_MATRIX_NONE (convert)) { |
1976 | 0 | same_matrix = TRUE; |
1977 | 946 | } else { |
1978 | 946 | same_matrix = |
1979 | 946 | convert->in_info.colorimetry.matrix == |
1980 | 946 | convert->out_info.colorimetry.matrix; |
1981 | 946 | } |
1982 | | |
1983 | 946 | if (CHECK_PRIMARIES_NONE (convert)) { |
1984 | 946 | same_primaries = TRUE; |
1985 | 946 | } else { |
1986 | 0 | same_primaries = |
1987 | 0 | gst_video_color_primaries_is_equivalent (convert->in_info. |
1988 | 0 | colorimetry.primaries, convert->out_info.colorimetry.primaries); |
1989 | 0 | } |
1990 | | |
1991 | 946 | same_ranges = TRUE; |
1992 | | |
1993 | 946 | if (convert->in_info.colorimetry.range != convert->out_info.colorimetry.range) { |
1994 | | // All other combinations are equivalent |
1995 | 478 | if (convert->in_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235 || |
1996 | 478 | convert->out_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
1997 | 478 | same_ranges = FALSE; |
1998 | 478 | } |
1999 | 478 | } |
2000 | | |
2001 | 946 | GST_LOG ("matrix %d -> %d (%d)", convert->in_info.colorimetry.matrix, |
2002 | 946 | convert->out_info.colorimetry.matrix, same_matrix); |
2003 | 946 | GST_LOG ("bits %d -> %d (%d)", convert->unpack_bits, convert->pack_bits, |
2004 | 946 | same_bits); |
2005 | 946 | GST_LOG ("primaries %d -> %d (%d)", convert->in_info.colorimetry.primaries, |
2006 | 946 | convert->out_info.colorimetry.primaries, same_primaries); |
2007 | | |
2008 | 946 | color_matrix_set_identity (&convert->convert_matrix); |
2009 | | |
2010 | 946 | if (!same_primaries) { |
2011 | 0 | const GstVideoColorPrimariesInfo *pi; |
2012 | | |
2013 | | /* Convert from RGB_input to RGB_output via XYZ |
2014 | | * res = XYZ_to_RGB_output ( RGB_to_XYZ_input ( input ) ) |
2015 | | * or in matricial form: |
2016 | | * RGB_output = XYZ_to_RGB_output_matrix * RGB_TO_XYZ_input_matrix * RGB_input |
2017 | | * |
2018 | | * The RGB_input is the pre-existing convert_matrix |
2019 | | * The convert_matrix will become the RGB_output |
2020 | | */ |
2021 | | |
2022 | | /* Convert input RGB to XYZ */ |
2023 | 0 | pi = gst_video_color_primaries_get_info (convert->in_info.colorimetry. |
2024 | 0 | primaries); |
2025 | | /* Get the RGB_TO_XYZ_input_matrix */ |
2026 | 0 | color_matrix_RGB_to_XYZ (&p1, pi->Rx, pi->Ry, pi->Gx, pi->Gy, pi->Bx, |
2027 | 0 | pi->By, pi->Wx, pi->Wy); |
2028 | 0 | GST_LOG ("to XYZ matrix"); |
2029 | 0 | color_matrix_debug (&p1); |
2030 | 0 | GST_LOG ("current matrix"); |
2031 | | /* convert_matrix = RGB_TO_XYZ_input_matrix * input_RGB */ |
2032 | 0 | color_matrix_multiply (&convert->convert_matrix, &convert->convert_matrix, |
2033 | 0 | &p1); |
2034 | 0 | color_matrix_debug (&convert->convert_matrix); |
2035 | | |
2036 | | /* Convert XYZ to output RGB */ |
2037 | 0 | pi = gst_video_color_primaries_get_info (convert->out_info.colorimetry. |
2038 | 0 | primaries); |
2039 | | /* Calculate the XYZ_to_RGB_output_matrix |
2040 | | * * Get the RGB_TO_XYZ_output_matrix |
2041 | | * * invert it |
2042 | | * * store in p2 |
2043 | | */ |
2044 | 0 | color_matrix_RGB_to_XYZ (&p2, pi->Rx, pi->Ry, pi->Gx, pi->Gy, pi->Bx, |
2045 | 0 | pi->By, pi->Wx, pi->Wy); |
2046 | 0 | color_matrix_invert (&p2, &p2); |
2047 | 0 | GST_LOG ("to RGB matrix"); |
2048 | 0 | color_matrix_debug (&p2); |
2049 | | /* Finally: |
2050 | | * convert_matrix = XYZ_to_RGB_output_matrix * RGB_TO_XYZ_input_matrix * RGB_input |
2051 | | * = XYZ_to_RGB_output_matrix * convert_matrix |
2052 | | * = p2 * convert_matrix |
2053 | | */ |
2054 | 0 | color_matrix_multiply (&convert->convert_matrix, &p2, |
2055 | 0 | &convert->convert_matrix); |
2056 | 0 | GST_LOG ("current matrix"); |
2057 | 0 | color_matrix_debug (&convert->convert_matrix); |
2058 | 0 | } |
2059 | | |
2060 | 946 | do_gamma = CHECK_GAMMA_REMAP (convert); |
2061 | 946 | if (!do_gamma) { |
2062 | 946 | gboolean in_float, out_float; |
2063 | 946 | gboolean use_float = FALSE; |
2064 | | |
2065 | 946 | in_float = is_float_format (convert->unpack_format); |
2066 | 946 | out_float = is_float_format (convert->pack_format); |
2067 | 946 | if (in_float || out_float) |
2068 | 0 | use_float = TRUE; |
2069 | | |
2070 | 946 | convert->in_bits = convert->unpack_bits; |
2071 | 946 | convert->out_bits = convert->pack_bits; |
2072 | | |
2073 | | /* These are input/output domain of this conversion stage. With gamma |
2074 | | * conversion they can be different from actual unpack/pack format. */ |
2075 | 946 | convert->convert_in_float = in_float; |
2076 | 946 | convert->convert_out_float = out_float; |
2077 | | |
2078 | 946 | if (!same_bits || !same_matrix || !same_primaries || !same_ranges) { |
2079 | | /* float is already represented in [0, 1], so do not need to do scaling |
2080 | | * below. Matrix conversion below will handle conversion between |
2081 | | * normalized and integer range if needed. */ |
2082 | 710 | if (!use_float && convert->in_bits < convert->out_bits) { |
2083 | | /* no gamma, combine all conversions into 1 */ |
2084 | 135 | gint scale = 1 << (convert->out_bits - convert->in_bits); |
2085 | 135 | color_matrix_scale_components (&convert->convert_matrix, |
2086 | 135 | 1 / (float) scale, 1 / (float) scale, 1 / (float) scale); |
2087 | 135 | } |
2088 | 710 | GST_LOG ("to RGB matrix"); |
2089 | 710 | compute_matrix_to_RGB (convert, &convert->convert_matrix); |
2090 | 710 | GST_LOG ("current matrix"); |
2091 | 710 | color_matrix_debug (&convert->convert_matrix); |
2092 | | |
2093 | 710 | GST_LOG ("to YUV matrix"); |
2094 | 710 | compute_matrix_to_YUV (convert, &convert->convert_matrix, FALSE); |
2095 | 710 | GST_LOG ("current matrix"); |
2096 | 710 | color_matrix_debug (&convert->convert_matrix); |
2097 | 710 | if (!use_float && convert->in_bits > convert->out_bits) { |
2098 | 127 | gint scale = 1 << (convert->in_bits - convert->out_bits); |
2099 | 127 | color_matrix_scale_components (&convert->convert_matrix, |
2100 | 127 | (float) scale, (float) scale, (float) scale); |
2101 | 127 | } |
2102 | | |
2103 | | /* If input and/or output is float, do matrix operation in float domain */ |
2104 | 710 | if (use_float) { |
2105 | 0 | convert->current_bits = 32; |
2106 | 0 | convert->current_pstride = 16; |
2107 | 0 | convert->current_format = GST_VIDEO_FORMAT_ARGB_F32; |
2108 | 710 | } else { |
2109 | 710 | convert->current_bits = MAX (convert->in_bits, convert->out_bits); |
2110 | 710 | } |
2111 | | |
2112 | 710 | do_conversion = TRUE; |
2113 | 710 | if (!same_matrix || !same_primaries || use_float || !same_ranges) { |
2114 | 686 | if (idx == 0) |
2115 | 686 | prepare_matrix (convert, &convert->convert_matrix); |
2116 | 686 | } |
2117 | | |
2118 | 710 | if (!use_float && convert->in_bits == convert->out_bits) |
2119 | 448 | pass_alloc = TRUE; |
2120 | 710 | } else |
2121 | 236 | do_conversion = FALSE; |
2122 | | |
2123 | 946 | convert->current_bits = convert->pack_bits; |
2124 | 946 | convert->current_format = convert->pack_format; |
2125 | 946 | convert->current_pstride = convert->current_bits >> 1; |
2126 | 946 | } else { |
2127 | | /* we did gamma, just do colorspace conversion if needed */ |
2128 | 0 | if (same_primaries) { |
2129 | 0 | do_conversion = FALSE; |
2130 | 0 | } else { |
2131 | 0 | gboolean is_float = is_float_format (convert->current_format); |
2132 | | |
2133 | | /* gamma encode happens later, so primaries conversion stays in same |
2134 | | * intermediate domain on both side here */ |
2135 | 0 | convert->convert_in_float = is_float; |
2136 | 0 | convert->convert_out_float = is_float; |
2137 | |
|
2138 | 0 | if (idx == 0) |
2139 | 0 | prepare_matrix (convert, &convert->convert_matrix); |
2140 | |
|
2141 | 0 | g_assert (convert->current_bits == 16 || convert->current_bits == 32); |
2142 | 0 | convert->in_bits = convert->out_bits = convert->current_bits; |
2143 | 0 | pass_alloc = TRUE; |
2144 | 0 | do_conversion = TRUE; |
2145 | 0 | } |
2146 | 0 | } |
2147 | | |
2148 | 946 | if (do_conversion) { |
2149 | 710 | GST_LOG ("chain conversion"); |
2150 | 710 | prev = convert->convert_lines[idx] = gst_line_cache_new (prev); |
2151 | 710 | prev->write_input = TRUE; |
2152 | 710 | prev->pass_alloc = pass_alloc; |
2153 | 710 | prev->n_lines = 1; |
2154 | 710 | prev->stride = convert->current_pstride * convert->current_width; |
2155 | 710 | gst_line_cache_set_need_line_func (prev, |
2156 | 710 | do_convert_lines, idx, convert, NULL); |
2157 | 710 | } |
2158 | 946 | return prev; |
2159 | 946 | } |
2160 | | |
2161 | | static void |
2162 | | convert_set_alpha_u8 (GstVideoConverter * convert, gpointer pixels, gint width) |
2163 | 0 | { |
2164 | 0 | guint8 *p = pixels; |
2165 | 0 | guint8 alpha = MIN (convert->alpha_value, 255); |
2166 | 0 | int i; |
2167 | |
|
2168 | 0 | for (i = 0; i < width; i++) |
2169 | 0 | p[i * 4] = alpha; |
2170 | 0 | } |
2171 | | |
2172 | | static void |
2173 | | convert_set_alpha_u16 (GstVideoConverter * convert, gpointer pixels, gint width) |
2174 | 0 | { |
2175 | 0 | guint16 *p = pixels; |
2176 | 0 | guint16 alpha; |
2177 | 0 | int i; |
2178 | |
|
2179 | 0 | alpha = MIN (convert->alpha_value, 255); |
2180 | 0 | alpha |= alpha << 8; |
2181 | |
|
2182 | 0 | for (i = 0; i < width; i++) |
2183 | 0 | p[i * 4] = alpha; |
2184 | 0 | } |
2185 | | |
2186 | | static void |
2187 | | convert_set_alpha_float (GstVideoConverter * convert, gpointer pixels, |
2188 | | gint width) |
2189 | 0 | { |
2190 | 0 | gfloat *p = pixels; |
2191 | 0 | gfloat alpha = convert->alpha_value / 255.0f; |
2192 | 0 | gint i; |
2193 | |
|
2194 | 0 | for (i = 0; i < width; i++) |
2195 | 0 | p[i * 4] = alpha; |
2196 | 0 | } |
2197 | | |
2198 | | static void |
2199 | | convert_mult_alpha_u8 (GstVideoConverter * convert, gpointer pixels, gint width) |
2200 | 0 | { |
2201 | 0 | guint8 *p = pixels; |
2202 | 0 | guint alpha = convert->alpha_value; |
2203 | 0 | int i; |
2204 | |
|
2205 | 0 | for (i = 0; i < width; i++) { |
2206 | 0 | gint a = (p[i * 4] * alpha) / 255; |
2207 | 0 | p[i * 4] = CLAMP (a, 0, 255); |
2208 | 0 | } |
2209 | 0 | } |
2210 | | |
2211 | | static void |
2212 | | convert_mult_alpha_u16 (GstVideoConverter * convert, gpointer pixels, |
2213 | | gint width) |
2214 | 0 | { |
2215 | 0 | guint16 *p = pixels; |
2216 | 0 | guint alpha = convert->alpha_value; |
2217 | 0 | int i; |
2218 | |
|
2219 | 0 | for (i = 0; i < width; i++) { |
2220 | 0 | gint a = (p[i * 4] * alpha) / 255; |
2221 | 0 | p[i * 4] = CLAMP (a, 0, 65535); |
2222 | 0 | } |
2223 | 0 | } |
2224 | | |
2225 | | static void |
2226 | | convert_mult_alpha_float (GstVideoConverter * convert, gpointer pixels, |
2227 | | gint width) |
2228 | 0 | { |
2229 | 0 | gfloat *p = pixels; |
2230 | 0 | gfloat alpha = convert->alpha_value / 255.0f; |
2231 | 0 | gint i; |
2232 | |
|
2233 | 0 | for (i = 0; i < width; i++) |
2234 | 0 | p[i * 4] *= alpha; |
2235 | 0 | } |
2236 | | |
2237 | | static GstLineCache * |
2238 | | chain_alpha (GstVideoConverter * convert, GstLineCache * prev, gint idx) |
2239 | 946 | { |
2240 | 946 | switch (convert->alpha_mode) { |
2241 | 914 | case ALPHA_MODE_NONE: |
2242 | 946 | case ALPHA_MODE_COPY: |
2243 | 946 | return prev; |
2244 | | |
2245 | 0 | case ALPHA_MODE_SET: |
2246 | 0 | if (is_float_format (convert->current_format)) |
2247 | 0 | convert->alpha_func = convert_set_alpha_float; |
2248 | 0 | else if (convert->current_bits == 8) |
2249 | 0 | convert->alpha_func = convert_set_alpha_u8; |
2250 | 0 | else |
2251 | 0 | convert->alpha_func = convert_set_alpha_u16; |
2252 | 0 | break; |
2253 | 0 | case ALPHA_MODE_MULT: |
2254 | 0 | if (is_float_format (convert->current_format)) |
2255 | 0 | convert->alpha_func = convert_mult_alpha_float; |
2256 | 0 | else if (convert->current_bits == 8) |
2257 | 0 | convert->alpha_func = convert_mult_alpha_u8; |
2258 | 0 | else |
2259 | 0 | convert->alpha_func = convert_mult_alpha_u16; |
2260 | 0 | break; |
2261 | 946 | } |
2262 | | |
2263 | 0 | GST_LOG ("chain alpha mode %d", convert->alpha_mode); |
2264 | 0 | prev = convert->alpha_lines[idx] = gst_line_cache_new (prev); |
2265 | 0 | prev->write_input = TRUE; |
2266 | 0 | prev->pass_alloc = TRUE; |
2267 | 0 | prev->n_lines = 1; |
2268 | 0 | prev->stride = convert->current_pstride * convert->current_width; |
2269 | 0 | gst_line_cache_set_need_line_func (prev, do_alpha_lines, idx, convert, NULL); |
2270 | |
|
2271 | 0 | return prev; |
2272 | 946 | } |
2273 | | |
2274 | | static GstLineCache * |
2275 | | chain_convert_to_YUV (GstVideoConverter * convert, GstLineCache * prev, |
2276 | | gint idx) |
2277 | 946 | { |
2278 | 946 | gboolean do_gamma; |
2279 | | |
2280 | 946 | do_gamma = CHECK_GAMMA_REMAP (convert); |
2281 | | |
2282 | 946 | if (do_gamma) { |
2283 | 0 | gint scale; |
2284 | |
|
2285 | 0 | GST_LOG ("chain gamma encode"); |
2286 | 0 | setup_gamma_encode (convert, convert->pack_bits); |
2287 | |
|
2288 | 0 | if (idx == 0 && !convert->pack_rgb) { |
2289 | 0 | color_matrix_set_identity (&convert->to_YUV_matrix); |
2290 | | |
2291 | | /* When gamma remap is enabled, we do |
2292 | | * 1) converts to linear RGB |
2293 | | * - if input is 8bits, convert to ARGB and scaled to 16bits with gamma |
2294 | | * decoding at once |
2295 | | * - if input is float, keep float format and gamma decode |
2296 | | * - otherwise converted ARGB64 and gamma decoded |
2297 | | * 2) scale/convert etc, |
2298 | | * 3) and gamma encode |
2299 | | * |
2300 | | * Then, if output unpack format is 8bits, setup_gamma_encode() will scale |
2301 | | * ARGB64 down to ARGB as a part of gamma encoding, float output stays in |
2302 | | * float format, otherwise it's still ARGB64 |
2303 | | * |
2304 | | * Finally this to_YUV_matrix is applied. Since compute_matrix_to_YUV() |
2305 | | * expects [0, 1.0] range RGB as an input, scale down identity matrix |
2306 | | * to expected scale here, otherwise offset of the matrix would be |
2307 | | * very wrong |
2308 | | */ |
2309 | 0 | GST_LOG ("chain YUV convert"); |
2310 | | |
2311 | | /* compute_matrix_to_YUV() expects RGB in [0, 1]. Integer intermediate |
2312 | | * needs scaling here but float is already in the [0, 1] |
2313 | | * |
2314 | | * NOTE: This also needs scaling if non-[0, 1] float range is defined |
2315 | | * later |
2316 | | */ |
2317 | 0 | if (!is_float_format (convert->current_format)) { |
2318 | 0 | scale = 1 << convert->current_bits; |
2319 | 0 | color_matrix_scale_components (&convert->to_YUV_matrix, |
2320 | 0 | 1 / (float) scale, 1 / (float) scale, 1 / (float) scale); |
2321 | 0 | } |
2322 | |
|
2323 | 0 | compute_matrix_to_YUV (convert, &convert->to_YUV_matrix, FALSE); |
2324 | 0 | prepare_matrix (convert, &convert->to_YUV_matrix); |
2325 | 0 | } |
2326 | 0 | convert->current_format = convert->pack_format; |
2327 | |
|
2328 | 0 | prev = convert->to_YUV_lines[idx] = gst_line_cache_new (prev); |
2329 | 0 | prev->write_input = FALSE; |
2330 | 0 | prev->pass_alloc = FALSE; |
2331 | 0 | prev->n_lines = 1; |
2332 | 0 | prev->stride = convert->current_pstride * convert->current_width; |
2333 | 0 | gst_line_cache_set_need_line_func (prev, |
2334 | 0 | do_convert_to_YUV_lines, idx, convert, NULL); |
2335 | 0 | } |
2336 | | |
2337 | 946 | return prev; |
2338 | 946 | } |
2339 | | |
2340 | | static GstLineCache * |
2341 | | chain_downsample (GstVideoConverter * convert, GstLineCache * prev, gint idx) |
2342 | 946 | { |
2343 | 946 | if (convert->downsample_p[idx] || convert->downsample_i[idx]) { |
2344 | 268 | GST_LOG ("chain downsample"); |
2345 | 268 | prev = convert->downsample_lines[idx] = gst_line_cache_new (prev); |
2346 | 268 | prev->write_input = TRUE; |
2347 | 268 | prev->pass_alloc = TRUE; |
2348 | | /* XXX: why this hardcoded value? */ |
2349 | 268 | prev->n_lines = 5; |
2350 | 268 | prev->stride = convert->current_pstride * convert->current_width; |
2351 | 268 | gst_line_cache_set_need_line_func (prev, |
2352 | 268 | do_downsample_lines, idx, convert, NULL); |
2353 | 268 | } |
2354 | 946 | return prev; |
2355 | 946 | } |
2356 | | |
2357 | | static GstLineCache * |
2358 | | chain_dither (GstVideoConverter * convert, GstLineCache * prev, gint idx) |
2359 | 946 | { |
2360 | 946 | gint i; |
2361 | 946 | gboolean do_dither = FALSE; |
2362 | 946 | GstVideoDitherFlags flags = 0; |
2363 | 946 | GstVideoDitherMethod method; |
2364 | 946 | guint quant[4], target_quant; |
2365 | | |
2366 | | /* No need to dither float formats */ |
2367 | 946 | if (is_float_format (convert->current_format)) |
2368 | 0 | return prev; |
2369 | | |
2370 | 946 | method = GET_OPT_DITHER_METHOD (convert); |
2371 | 946 | if (method == GST_VIDEO_DITHER_NONE) |
2372 | 0 | return prev; |
2373 | | |
2374 | 946 | target_quant = GET_OPT_DITHER_QUANTIZATION (convert); |
2375 | 946 | GST_LOG ("method %d, target-quantization %d", method, target_quant); |
2376 | | |
2377 | 946 | if (convert->pack_pal) { |
2378 | 0 | quant[0] = 47; |
2379 | 0 | quant[1] = 47; |
2380 | 0 | quant[2] = 47; |
2381 | 0 | quant[3] = 1; |
2382 | 0 | do_dither = TRUE; |
2383 | 946 | } else { |
2384 | 4.73k | for (i = 0; i < GST_VIDEO_MAX_COMPONENTS; i++) { |
2385 | 3.78k | gint depth; |
2386 | | |
2387 | 3.78k | depth = convert->out_info.finfo->depth[i]; |
2388 | | |
2389 | 3.78k | if (depth == 0) { |
2390 | 1.13k | quant[i] = 0; |
2391 | 1.13k | continue; |
2392 | 1.13k | } |
2393 | | |
2394 | 2.65k | if (convert->current_bits >= depth) { |
2395 | 2.65k | quant[i] = 1 << (convert->current_bits - depth); |
2396 | 2.65k | if (target_quant > quant[i]) { |
2397 | 0 | flags |= GST_VIDEO_DITHER_FLAG_QUANTIZE; |
2398 | 0 | quant[i] = target_quant; |
2399 | 0 | } |
2400 | 2.65k | } else { |
2401 | 0 | quant[i] = 0; |
2402 | 0 | } |
2403 | 2.65k | if (quant[i] > 1) |
2404 | 288 | do_dither = TRUE; |
2405 | 2.65k | } |
2406 | 946 | } |
2407 | | |
2408 | 946 | if (do_dither) { |
2409 | 96 | GST_LOG ("chain dither"); |
2410 | | |
2411 | 96 | convert->dither[idx] = gst_video_dither_new (method, |
2412 | 96 | flags, convert->pack_format, quant, convert->current_width); |
2413 | | |
2414 | 96 | prev = convert->dither_lines[idx] = gst_line_cache_new (prev); |
2415 | 96 | prev->write_input = TRUE; |
2416 | 96 | prev->pass_alloc = TRUE; |
2417 | 96 | prev->n_lines = 1; |
2418 | 96 | prev->stride = convert->current_pstride * convert->current_width; |
2419 | 96 | gst_line_cache_set_need_line_func (prev, do_dither_lines, idx, convert, |
2420 | 96 | NULL); |
2421 | 96 | } |
2422 | 946 | return prev; |
2423 | 946 | } |
2424 | | |
2425 | | static GstLineCache * |
2426 | | chain_pack (GstVideoConverter * convert, GstLineCache * prev, gint idx) |
2427 | 946 | { |
2428 | 946 | convert->pack_nlines = convert->out_info.finfo->pack_lines; |
2429 | 946 | convert->pack_pstride = convert->current_pstride; |
2430 | 946 | convert->identity_pack = |
2431 | 946 | (convert->out_info.finfo->format == |
2432 | 946 | convert->out_info.finfo->unpack_format); |
2433 | 946 | GST_LOG ("chain pack line format %s, pstride %d, identity_pack %d (%d %d)", |
2434 | 946 | gst_video_format_to_string (convert->current_format), |
2435 | 946 | convert->current_pstride, convert->identity_pack, |
2436 | 946 | convert->out_info.finfo->format, convert->out_info.finfo->unpack_format); |
2437 | | |
2438 | 946 | return prev; |
2439 | 946 | } |
2440 | | |
2441 | | static void |
2442 | | setup_allocators (GstVideoConverter * convert) |
2443 | 946 | { |
2444 | 946 | GstLineCache *cache, *prev; |
2445 | 946 | GstLineCacheAllocLineFunc alloc_line; |
2446 | 946 | gboolean alloc_writable; |
2447 | 946 | gpointer user_data; |
2448 | 946 | GDestroyNotify notify; |
2449 | 946 | gint width; |
2450 | 946 | gint i; |
2451 | 946 | gsize alloc_stride; |
2452 | | |
2453 | 946 | width = MAX (convert->in_maxwidth, convert->out_maxwidth); |
2454 | 946 | width += convert->out_x; |
2455 | | |
2456 | 946 | if (convert->unpack_bits > 16 || convert->pack_bits > 16) |
2457 | 0 | alloc_stride = sizeof (guint32) * 4 * width; |
2458 | 946 | else |
2459 | 946 | alloc_stride = sizeof (guint16) * 4 * width; |
2460 | | |
2461 | 1.89k | for (i = 0; i < convert->conversion_runner->n_threads; i++) { |
2462 | | /* start with using dest lines if we can directly write into it */ |
2463 | 946 | if (convert->identity_pack) { |
2464 | 141 | alloc_line = get_dest_line; |
2465 | 141 | alloc_writable = TRUE; |
2466 | 141 | user_data = convert; |
2467 | 141 | notify = NULL; |
2468 | 805 | } else { |
2469 | 805 | user_data = |
2470 | 805 | converter_alloc_new (alloc_stride, 4 + BACKLOG, convert, NULL); |
2471 | 805 | setup_border_alloc (convert, user_data); |
2472 | 805 | notify = (GDestroyNotify) converter_alloc_free; |
2473 | 805 | alloc_line = get_border_temp_line; |
2474 | | /* when we add a border, we need to write */ |
2475 | 805 | alloc_writable = convert->borderline != NULL; |
2476 | 805 | } |
2477 | | |
2478 | | /* First step, try to calculate how many temp lines we need. Go backwards, |
2479 | | * keep track of the maximum number of lines we need for each intermediate |
2480 | | * step. */ |
2481 | 4.84k | for (prev = cache = convert->pack_lines[i]; cache; cache = cache->prev) { |
2482 | 3.90k | GST_LOG ("looking at cache %p, %d lines, %d backlog", cache, |
2483 | 3.90k | cache->n_lines, cache->backlog); |
2484 | 3.90k | prev->n_lines = MAX (prev->n_lines, cache->n_lines); |
2485 | 3.90k | if (!cache->pass_alloc) { |
2486 | 2.51k | GST_LOG ("cache %p, needs %d lines", prev, prev->n_lines); |
2487 | 2.51k | prev = cache; |
2488 | 2.51k | } |
2489 | 3.90k | } |
2490 | | |
2491 | | /* now walk backwards, we try to write into the dest lines directly |
2492 | | * and keep track if the source needs to be writable */ |
2493 | 4.84k | for (cache = convert->pack_lines[i]; cache; cache = cache->prev) { |
2494 | 3.90k | gst_line_cache_set_alloc_line_func (cache, alloc_line, user_data, notify); |
2495 | 3.90k | cache->alloc_writable = alloc_writable; |
2496 | | |
2497 | | /* make sure only one cache frees the allocator */ |
2498 | 3.90k | notify = NULL; |
2499 | | |
2500 | 3.90k | if (!cache->pass_alloc) { |
2501 | | /* can't pass allocator, make new temp line allocator */ |
2502 | 2.51k | user_data = |
2503 | 2.51k | converter_alloc_new (alloc_stride, |
2504 | 2.51k | cache->n_lines + cache->backlog, convert, NULL); |
2505 | 2.51k | notify = (GDestroyNotify) converter_alloc_free; |
2506 | 2.51k | alloc_line = get_temp_line; |
2507 | 2.51k | alloc_writable = FALSE; |
2508 | 2.51k | } |
2509 | | /* if someone writes to the input, we need a writable line from the |
2510 | | * previous cache */ |
2511 | 3.90k | if (cache->write_input) |
2512 | 1.51k | alloc_writable = TRUE; |
2513 | 3.90k | } |
2514 | | /* free leftover allocator */ |
2515 | 946 | if (notify) |
2516 | 946 | notify (user_data); |
2517 | 946 | } |
2518 | 946 | } |
2519 | | |
2520 | | static void |
2521 | | setup_borderline (GstVideoConverter * convert) |
2522 | 946 | { |
2523 | 946 | gint width; |
2524 | | |
2525 | 946 | width = MAX (convert->in_maxwidth, convert->out_maxwidth); |
2526 | 946 | width += convert->out_x; |
2527 | | |
2528 | 946 | if (convert->fill_border && (convert->out_height < convert->out_maxheight || |
2529 | 946 | convert->out_width < convert->out_maxwidth)) { |
2530 | 0 | guint32 border_val; |
2531 | 0 | gint i, w_sub; |
2532 | 0 | const GstVideoFormatInfo *out_finfo; |
2533 | 0 | const GstVideoFormatInfo *out_pack_finfo; |
2534 | 0 | gpointer planes[GST_VIDEO_MAX_PLANES]; |
2535 | 0 | gint strides[GST_VIDEO_MAX_PLANES]; |
2536 | 0 | gsize alloc_stride; |
2537 | 0 | gfloat border_float[4] = { 0, }; |
2538 | |
|
2539 | 0 | if (convert->unpack_bits > 16 || convert->pack_bits > 16) |
2540 | 0 | alloc_stride = sizeof (guint32) * 4 * width; |
2541 | 0 | else |
2542 | 0 | alloc_stride = sizeof (guint16) * 4 * width; |
2543 | |
|
2544 | 0 | convert->borderline = g_malloc0 (alloc_stride); |
2545 | |
|
2546 | 0 | out_finfo = convert->out_info.finfo; |
2547 | 0 | out_pack_finfo = gst_video_format_get_info (convert->pack_format); |
2548 | |
|
2549 | 0 | border_val = GINT32_FROM_BE (convert->border_argb); |
2550 | |
|
2551 | 0 | if (GST_VIDEO_FORMAT_INFO_IS_YUV (out_pack_finfo)) { |
2552 | 0 | MatrixData cm; |
2553 | 0 | gint64 a, r, g, b; |
2554 | |
|
2555 | 0 | b = (0xFF000000 & border_val) >> 24; |
2556 | 0 | g = (0x00FF0000 & border_val) >> 16; |
2557 | 0 | r = (0x0000FF00 & border_val) >> 8; |
2558 | 0 | a = (0x000000FF & border_val); |
2559 | | |
2560 | | /* Get Color matrix. */ |
2561 | 0 | color_matrix_set_identity (&cm); |
2562 | | |
2563 | | /* border_argb is 8-bit RGB, normalize it to [0, 1] */ |
2564 | 0 | color_matrix_scale_components (&cm, |
2565 | 0 | 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0); |
2566 | |
|
2567 | 0 | compute_matrix_to_YUV (convert, &cm, TRUE); |
2568 | |
|
2569 | 0 | if (GST_VIDEO_FORMAT_INFO_IS_FLOAT (out_pack_finfo)) { |
2570 | 0 | border_float[0] = a / 255.0f; |
2571 | 0 | border_float[1] = r * cm.dm[0][0] + g * cm.dm[0][1] + |
2572 | 0 | b * cm.dm[0][2] + cm.dm[0][3]; |
2573 | 0 | border_float[2] = r * cm.dm[1][0] + g * cm.dm[1][1] + |
2574 | 0 | b * cm.dm[1][2] + cm.dm[1][3]; |
2575 | 0 | border_float[3] = r * cm.dm[2][0] + g * cm.dm[2][1] + |
2576 | 0 | b * cm.dm[2][2] + cm.dm[2][3]; |
2577 | 0 | } else { |
2578 | 0 | gint64 y, u, v; |
2579 | | |
2580 | | /* convert to integer scale, same as prepare_matrix() */ |
2581 | 0 | color_matrix_scale_components (&cm, SCALE_F, SCALE_F, SCALE_F); |
2582 | 0 | color_matrix_convert (&cm); |
2583 | |
|
2584 | 0 | y = (r * cm.im[0][0] + g * cm.im[0][1] + b * cm.im[0][2] + |
2585 | 0 | cm.im[0][3]) >> SCALE; |
2586 | 0 | u = (r * cm.im[1][0] + g * cm.im[1][1] + b * cm.im[1][2] + |
2587 | 0 | cm.im[1][3]) >> SCALE; |
2588 | 0 | v = (r * cm.im[2][0] + g * cm.im[2][1] + b * cm.im[2][2] + |
2589 | 0 | cm.im[2][3]) >> SCALE; |
2590 | |
|
2591 | 0 | a = CLAMP (a, 0, 255); |
2592 | 0 | y = CLAMP (y, 0, 255); |
2593 | 0 | u = CLAMP (u, 0, 255); |
2594 | 0 | v = CLAMP (v, 0, 255); |
2595 | |
|
2596 | 0 | border_val = (guint32) (a | (y << 8) | (u << 16) | (v << 24)); |
2597 | 0 | } |
2598 | 0 | } |
2599 | |
|
2600 | 0 | if (convert->pack_bits == 8) { |
2601 | 0 | video_orc_splat_u32 (convert->borderline, border_val, width); |
2602 | 0 | } else if (convert->pack_bits == 16) { |
2603 | 0 | video_orc_splat2_u64 (convert->borderline, border_val, width); |
2604 | 0 | } else if (convert->pack_bits == 32) { |
2605 | 0 | gfloat argb[4]; |
2606 | 0 | guint8 *d = convert->borderline; |
2607 | |
|
2608 | 0 | g_assert (GST_VIDEO_FORMAT_INFO_IS_FLOAT (out_pack_finfo)); |
2609 | | |
2610 | 0 | if (GST_VIDEO_FORMAT_INFO_IS_YUV (out_pack_finfo)) { |
2611 | 0 | memcpy (argb, border_float, sizeof (argb)); |
2612 | 0 | } else { |
2613 | 0 | argb[0] = (border_val & 0xff) / 255.0f; |
2614 | 0 | argb[1] = ((border_val >> 8) & 0xff) / 255.0f; |
2615 | 0 | argb[2] = ((border_val >> 16) & 0xff) / 255.0f; |
2616 | 0 | argb[3] = ((border_val >> 24) & 0xff) / 255.0f; |
2617 | 0 | } |
2618 | |
|
2619 | 0 | for (i = 0; i < width; i++) |
2620 | 0 | memcpy (d + i * sizeof (argb), argb, sizeof (argb)); |
2621 | 0 | } else { |
2622 | 0 | g_assert_not_reached (); |
2623 | 0 | } |
2624 | | |
2625 | | /* convert pixels */ |
2626 | 0 | for (i = 0; i < out_finfo->n_planes; i++) { |
2627 | 0 | planes[i] = convert->borders[i]; |
2628 | 0 | strides[i] = sizeof (convert->borders[i]); |
2629 | 0 | } |
2630 | 0 | w_sub = 0; |
2631 | 0 | if (out_finfo->n_planes == 1) { |
2632 | | /* for packed formats, convert based on subsampling so that we |
2633 | | * get a complete group of pixels */ |
2634 | 0 | for (i = 0; i < out_finfo->n_components; i++) { |
2635 | 0 | w_sub = MAX (w_sub, out_finfo->w_sub[i]); |
2636 | 0 | } |
2637 | 0 | } |
2638 | 0 | out_finfo->pack_func (out_finfo, GST_VIDEO_PACK_FLAG_NONE, |
2639 | 0 | convert->borderline, 0, planes, strides, |
2640 | 0 | GST_VIDEO_CHROMA_SITE_UNKNOWN, 0, 1 << w_sub); |
2641 | 946 | } else { |
2642 | 946 | convert->borderline = NULL; |
2643 | 946 | } |
2644 | 946 | } |
2645 | | |
2646 | | static AlphaMode |
2647 | | convert_get_alpha_mode (GstVideoConverter * convert) |
2648 | 2.08k | { |
2649 | 2.08k | gboolean in_alpha, out_alpha; |
2650 | | |
2651 | 2.08k | in_alpha = GST_VIDEO_INFO_HAS_ALPHA (&convert->in_info); |
2652 | 2.08k | out_alpha = GST_VIDEO_INFO_HAS_ALPHA (&convert->out_info); |
2653 | | |
2654 | | /* no output alpha, do nothing */ |
2655 | 2.08k | if (!out_alpha) |
2656 | 1.26k | return ALPHA_MODE_NONE; |
2657 | | |
2658 | 815 | if (in_alpha) { |
2659 | | /* in and out */ |
2660 | 378 | if (CHECK_ALPHA_COPY (convert)) |
2661 | 378 | return ALPHA_MODE_COPY; |
2662 | | |
2663 | 0 | if (CHECK_ALPHA_MULT (convert)) { |
2664 | 0 | if (GET_OPT_ALPHA_VALUE (convert) == 1.0) |
2665 | 0 | return ALPHA_MODE_COPY; |
2666 | 0 | else |
2667 | 0 | return ALPHA_MODE_MULT; |
2668 | 0 | } |
2669 | 0 | } |
2670 | | /* nothing special, this is what unpack etc does automatically */ |
2671 | 437 | if (GET_OPT_ALPHA_VALUE (convert) == 1.0) |
2672 | 437 | return ALPHA_MODE_NONE; |
2673 | | |
2674 | | /* everything else becomes SET */ |
2675 | 0 | return ALPHA_MODE_SET; |
2676 | 437 | } |
2677 | | |
2678 | | static void |
2679 | | gst_video_converter_init_from_config (GstVideoConverter * convert) |
2680 | 2.08k | { |
2681 | 2.08k | const GstVideoFormatInfo *fin, *fout, *finfo; |
2682 | 2.08k | GstVideoInfo *in_info = &convert->in_info; |
2683 | 2.08k | GstVideoInfo *out_info = &convert->out_info; |
2684 | 2.08k | gdouble alpha_value; |
2685 | | |
2686 | 2.08k | fin = in_info->finfo; |
2687 | 2.08k | fout = out_info->finfo; |
2688 | | |
2689 | 2.08k | convert->in_x = get_opt_int (convert, GST_VIDEO_CONVERTER_OPT_SRC_X, 0); |
2690 | 2.08k | convert->in_y = get_opt_int (convert, GST_VIDEO_CONVERTER_OPT_SRC_Y, 0); |
2691 | 2.08k | convert->in_x &= ~((1 << fin->w_sub[1]) - 1); |
2692 | 2.08k | convert->in_y &= ~((1 << fin->h_sub[1]) - 1); |
2693 | | |
2694 | 2.08k | convert->in_width = get_opt_int (convert, |
2695 | 2.08k | GST_VIDEO_CONVERTER_OPT_SRC_WIDTH, convert->in_maxwidth - convert->in_x); |
2696 | 2.08k | convert->in_height = get_opt_int (convert, |
2697 | 2.08k | GST_VIDEO_CONVERTER_OPT_SRC_HEIGHT, |
2698 | 2.08k | convert->in_maxheight - convert->in_y); |
2699 | | |
2700 | 2.08k | convert->in_width = |
2701 | 2.08k | MIN (convert->in_width, convert->in_maxwidth - convert->in_x); |
2702 | 2.08k | if (convert->in_width + convert->in_x < 0 || |
2703 | 2.08k | convert->in_width + convert->in_x > convert->in_maxwidth) { |
2704 | 0 | convert->in_width = 0; |
2705 | 0 | } |
2706 | | |
2707 | 2.08k | convert->in_height = |
2708 | 2.08k | MIN (convert->in_height, convert->in_maxheight - convert->in_y); |
2709 | 2.08k | if (convert->in_height + convert->in_y < 0 || |
2710 | 2.08k | convert->in_height + convert->in_y > convert->in_maxheight) { |
2711 | 0 | convert->in_height = 0; |
2712 | 0 | } |
2713 | | |
2714 | 2.08k | convert->out_x = get_opt_int (convert, GST_VIDEO_CONVERTER_OPT_DEST_X, 0); |
2715 | 2.08k | convert->out_y = get_opt_int (convert, GST_VIDEO_CONVERTER_OPT_DEST_Y, 0); |
2716 | 2.08k | convert->out_x &= ~((1 << fout->w_sub[1]) - 1); |
2717 | 2.08k | convert->out_y &= ~((1 << fout->h_sub[1]) - 1); |
2718 | | |
2719 | 2.08k | convert->out_width = get_opt_int (convert, |
2720 | 2.08k | GST_VIDEO_CONVERTER_OPT_DEST_WIDTH, |
2721 | 2.08k | convert->out_maxwidth - convert->out_x); |
2722 | 2.08k | convert->out_height = |
2723 | 2.08k | get_opt_int (convert, GST_VIDEO_CONVERTER_OPT_DEST_HEIGHT, |
2724 | 2.08k | convert->out_maxheight - convert->out_y); |
2725 | | |
2726 | 2.08k | if (convert->out_width > convert->out_maxwidth - convert->out_x) |
2727 | 0 | convert->out_width = convert->out_maxwidth - convert->out_x; |
2728 | 2.08k | convert->out_width = CLAMP (convert->out_width, 0, convert->out_maxwidth); |
2729 | | |
2730 | | /* Check if completely outside the framebuffer */ |
2731 | 2.08k | if (convert->out_width + convert->out_x < 0 || |
2732 | 2.08k | convert->out_width + convert->out_x > convert->out_maxwidth) { |
2733 | 0 | convert->out_width = 0; |
2734 | 0 | } |
2735 | | |
2736 | | /* Same for height */ |
2737 | 2.08k | if (convert->out_height > convert->out_maxheight - convert->out_y) |
2738 | 0 | convert->out_height = convert->out_maxheight - convert->out_y; |
2739 | 2.08k | convert->out_height = CLAMP (convert->out_height, 0, convert->out_maxheight); |
2740 | | |
2741 | 2.08k | if (convert->out_height + convert->out_y < 0 || |
2742 | 2.08k | convert->out_height + convert->out_y > convert->out_maxheight) { |
2743 | 0 | convert->out_height = 0; |
2744 | 0 | } |
2745 | | |
2746 | 2.08k | convert->fill_border = GET_OPT_FILL_BORDER (convert); |
2747 | 2.08k | convert->border_argb = get_opt_uint (convert, |
2748 | 2.08k | GST_VIDEO_CONVERTER_OPT_BORDER_ARGB, DEFAULT_OPT_BORDER_ARGB); |
2749 | | |
2750 | 2.08k | alpha_value = GET_OPT_ALPHA_VALUE (convert); |
2751 | 2.08k | convert->alpha_value = 255 * alpha_value; |
2752 | 2.08k | convert->alpha_mode = convert_get_alpha_mode (convert); |
2753 | | |
2754 | 2.08k | convert->unpack_format = in_info->finfo->unpack_format; |
2755 | 2.08k | finfo = gst_video_format_get_info (convert->unpack_format); |
2756 | 2.08k | convert->unpack_bits = GST_VIDEO_FORMAT_INFO_DEPTH (finfo, 0); |
2757 | 2.08k | convert->unpack_rgb = GST_VIDEO_FORMAT_INFO_IS_RGB (finfo); |
2758 | 2.08k | if (convert->unpack_rgb |
2759 | 306 | && in_info->colorimetry.matrix != GST_VIDEO_COLOR_MATRIX_RGB) { |
2760 | | /* force identity matrix for RGB input */ |
2761 | 0 | GST_WARNING ("invalid matrix %d for input RGB format, using RGB", |
2762 | 0 | in_info->colorimetry.matrix); |
2763 | 0 | convert->in_info.colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB; |
2764 | 0 | } |
2765 | | |
2766 | 2.08k | convert->pack_format = out_info->finfo->unpack_format; |
2767 | 2.08k | finfo = gst_video_format_get_info (convert->pack_format); |
2768 | 2.08k | convert->pack_bits = GST_VIDEO_FORMAT_INFO_DEPTH (finfo, 0); |
2769 | 2.08k | convert->pack_rgb = GST_VIDEO_FORMAT_INFO_IS_RGB (finfo); |
2770 | 2.08k | convert->pack_pal = |
2771 | 2.08k | gst_video_format_get_palette (GST_VIDEO_INFO_FORMAT (out_info), |
2772 | 2.08k | &convert->pack_palsize); |
2773 | 2.08k | if (convert->pack_rgb |
2774 | 970 | && out_info->colorimetry.matrix != GST_VIDEO_COLOR_MATRIX_RGB) { |
2775 | | /* force identity matrix for RGB output */ |
2776 | 0 | GST_WARNING ("invalid matrix %d for output RGB format, using RGB", |
2777 | 0 | out_info->colorimetry.matrix); |
2778 | 0 | convert->out_info.colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB; |
2779 | 0 | } |
2780 | 2.08k | } |
2781 | | |
2782 | | /** |
2783 | | * gst_video_converter_new_with_pool: (constructor) (skip) |
2784 | | * @in_info: a #GstVideoInfo |
2785 | | * @out_info: a #GstVideoInfo |
2786 | | * @config: (transfer full): a #GstStructure with configuration options |
2787 | | * @pool: (nullable): a #GstTaskPool to spawn threads from |
2788 | | * |
2789 | | * Create a new converter object to convert between @in_info and @out_info |
2790 | | * with @config. |
2791 | | * |
2792 | | * The optional @pool can be used to spawn threads, this is useful when |
2793 | | * creating new converters rapidly, for example when updating cropping. |
2794 | | * |
2795 | | * If @config is not provided, and a @pool is provided, the number of threads for |
2796 | | * the converter will be set to the maximum number of threads in the pool. |
2797 | | * |
2798 | | * Returns (nullable): a #GstVideoConverter or %NULL if conversion is not possible. |
2799 | | * |
2800 | | * Since: 1.20 |
2801 | | */ |
2802 | | GstVideoConverter * |
2803 | | gst_video_converter_new_with_pool (const GstVideoInfo * in_info, |
2804 | | const GstVideoInfo * out_info, GstStructure * config, GstTaskPool * pool) |
2805 | 2.08k | { |
2806 | 2.08k | GstVideoConverter *convert; |
2807 | 2.08k | GstLineCache *prev; |
2808 | 2.08k | gint n_threads, i; |
2809 | 2.08k | gboolean async_tasks; |
2810 | | |
2811 | 2.08k | g_return_val_if_fail (in_info != NULL, NULL); |
2812 | 2.08k | g_return_val_if_fail (out_info != NULL, NULL); |
2813 | | /* we won't ever do framerate conversion */ |
2814 | 2.08k | g_return_val_if_fail (in_info->fps_n == out_info->fps_n, NULL); |
2815 | 2.08k | g_return_val_if_fail (in_info->fps_d == out_info->fps_d, NULL); |
2816 | | /* we won't ever do deinterlace */ |
2817 | 2.08k | g_return_val_if_fail (in_info->interlace_mode == out_info->interlace_mode, |
2818 | 2.08k | NULL); |
2819 | | |
2820 | 2.08k | convert = g_new0 (GstVideoConverter, 1); |
2821 | | |
2822 | 2.08k | convert->in_info = *in_info; |
2823 | 2.08k | convert->out_info = *out_info; |
2824 | | |
2825 | 2.08k | convert->in_maxwidth = GST_VIDEO_INFO_WIDTH (in_info); |
2826 | 2.08k | convert->in_maxheight = GST_VIDEO_INFO_FIELD_HEIGHT (in_info); |
2827 | 2.08k | convert->out_maxwidth = GST_VIDEO_INFO_WIDTH (out_info); |
2828 | 2.08k | convert->out_maxheight = GST_VIDEO_INFO_FIELD_HEIGHT (out_info); |
2829 | | |
2830 | 2.08k | convert->config = gst_structure_new_static_str_empty ("GstVideoConverter"); |
2831 | 2.08k | if (config) { |
2832 | 0 | gst_video_converter_set_config (convert, config); |
2833 | 0 | n_threads = get_opt_uint (convert, GST_VIDEO_CONVERTER_OPT_THREADS, 1); |
2834 | 2.08k | } else { |
2835 | | /* No config provided. If a pool is available, use its thread count */ |
2836 | 2.08k | gst_video_converter_init_from_config (convert); |
2837 | 2.08k | if (pool && GST_IS_SHARED_TASK_POOL (pool)) { |
2838 | 0 | n_threads = |
2839 | 0 | gst_shared_task_pool_get_max_threads (GST_SHARED_TASK_POOL (pool)); |
2840 | 0 | GST_LOG ("setting n-threads from max threads %d from provided pool", |
2841 | 0 | n_threads); |
2842 | 0 | gst_structure_set (convert->config, |
2843 | 0 | GST_VIDEO_CONVERTER_OPT_THREADS, G_TYPE_UINT, n_threads, NULL); |
2844 | 0 | } else |
2845 | 2.08k | n_threads = get_opt_uint (convert, GST_VIDEO_CONVERTER_OPT_THREADS, 1); |
2846 | 2.08k | } |
2847 | | |
2848 | 2.08k | if (n_threads == 0 || n_threads > g_get_num_processors ()) |
2849 | 0 | n_threads = g_get_num_processors (); |
2850 | | /* Magic number of 200 lines */ |
2851 | 2.08k | if (MAX (convert->out_height, convert->in_height) / n_threads < 200) |
2852 | 1.42k | n_threads = (MAX (convert->out_height, convert->in_height) + 199) / 200; |
2853 | 2.08k | if (n_threads < 1) |
2854 | 0 | n_threads = 1; |
2855 | | |
2856 | 2.08k | async_tasks = GET_OPT_ASYNC_TASKS (convert); |
2857 | 2.08k | convert->conversion_runner = |
2858 | 2.08k | gst_parallelized_task_runner_new (n_threads, pool, async_tasks); |
2859 | | |
2860 | 2.08k | if (video_converter_lookup_fastpath (convert)) |
2861 | 1.13k | goto done; |
2862 | | |
2863 | 946 | if (in_info->finfo->unpack_func == NULL) |
2864 | 0 | goto no_unpack_func; |
2865 | | |
2866 | 946 | if (out_info->finfo->pack_func == NULL) |
2867 | 0 | goto no_pack_func; |
2868 | | |
2869 | 946 | convert->convert = video_converter_generic; |
2870 | | |
2871 | 946 | convert->upsample_p = g_new0 (GstVideoChromaResample *, n_threads); |
2872 | 946 | convert->upsample_i = g_new0 (GstVideoChromaResample *, n_threads); |
2873 | 946 | convert->downsample_p = g_new0 (GstVideoChromaResample *, n_threads); |
2874 | 946 | convert->downsample_i = g_new0 (GstVideoChromaResample *, n_threads); |
2875 | 946 | convert->v_scaler_p = g_new0 (GstVideoScaler *, n_threads); |
2876 | 946 | convert->v_scaler_i = g_new0 (GstVideoScaler *, n_threads); |
2877 | 946 | convert->h_scaler = g_new0 (GstVideoScaler *, n_threads); |
2878 | 946 | convert->unpack_lines = g_new0 (GstLineCache *, n_threads); |
2879 | 946 | convert->pack_lines = g_new0 (GstLineCache *, n_threads); |
2880 | 946 | convert->upsample_lines = g_new0 (GstLineCache *, n_threads); |
2881 | 946 | convert->to_RGB_lines = g_new0 (GstLineCache *, n_threads); |
2882 | 946 | convert->hscale_lines = g_new0 (GstLineCache *, n_threads); |
2883 | 946 | convert->vscale_lines = g_new0 (GstLineCache *, n_threads); |
2884 | 946 | convert->convert_lines = g_new0 (GstLineCache *, n_threads); |
2885 | 946 | convert->alpha_lines = g_new0 (GstLineCache *, n_threads); |
2886 | 946 | convert->to_YUV_lines = g_new0 (GstLineCache *, n_threads); |
2887 | 946 | convert->downsample_lines = g_new0 (GstLineCache *, n_threads); |
2888 | 946 | convert->dither_lines = g_new0 (GstLineCache *, n_threads); |
2889 | 946 | convert->dither = g_new0 (GstVideoDither *, n_threads); |
2890 | | |
2891 | 946 | if (convert->in_width > 0 && convert->out_width > 0 && convert->in_height > 0 |
2892 | 946 | && convert->out_height > 0) { |
2893 | 1.89k | for (i = 0; i < n_threads; i++) { |
2894 | 946 | convert->current_format = GST_VIDEO_INFO_FORMAT (in_info); |
2895 | 946 | convert->current_width = convert->in_width; |
2896 | 946 | convert->current_height = convert->in_height; |
2897 | | |
2898 | | /* unpack */ |
2899 | 946 | prev = chain_unpack_line (convert, i); |
2900 | | /* upsample chroma */ |
2901 | 946 | prev = chain_upsample (convert, prev, i); |
2902 | | /* convert to gamma decoded RGB */ |
2903 | 946 | prev = chain_convert_to_RGB (convert, prev, i); |
2904 | | /* do all downscaling */ |
2905 | 946 | prev = chain_scale (convert, prev, FALSE, i); |
2906 | | /* do conversion between color spaces */ |
2907 | 946 | prev = chain_convert (convert, prev, i); |
2908 | | /* do alpha channels */ |
2909 | 946 | prev = chain_alpha (convert, prev, i); |
2910 | | /* do all remaining (up)scaling */ |
2911 | 946 | prev = chain_scale (convert, prev, TRUE, i); |
2912 | | /* convert to gamma encoded Y'Cb'Cr' */ |
2913 | 946 | prev = chain_convert_to_YUV (convert, prev, i); |
2914 | | /* downsample chroma */ |
2915 | 946 | prev = chain_downsample (convert, prev, i); |
2916 | | /* dither */ |
2917 | 946 | prev = chain_dither (convert, prev, i); |
2918 | | /* pack into final format */ |
2919 | 946 | convert->pack_lines[i] = chain_pack (convert, prev, i); |
2920 | 946 | } |
2921 | 946 | } |
2922 | | |
2923 | 946 | setup_borderline (convert); |
2924 | | /* now figure out allocators */ |
2925 | 946 | setup_allocators (convert); |
2926 | | |
2927 | 2.08k | done: |
2928 | 2.08k | return convert; |
2929 | | |
2930 | | /* ERRORS */ |
2931 | 0 | no_unpack_func: |
2932 | 0 | { |
2933 | 0 | GST_ERROR ("no unpack_func for format %s", |
2934 | 0 | gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (in_info))); |
2935 | 0 | gst_video_converter_free (convert); |
2936 | 0 | return NULL; |
2937 | 946 | } |
2938 | 0 | no_pack_func: |
2939 | 0 | { |
2940 | 0 | GST_ERROR ("no pack_func for format %s", |
2941 | 0 | gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (out_info))); |
2942 | 0 | gst_video_converter_free (convert); |
2943 | 0 | return NULL; |
2944 | 946 | } |
2945 | 946 | } |
2946 | | |
2947 | | /** |
2948 | | * gst_video_converter_new: (constructor) (skip) |
2949 | | * @in_info: a #GstVideoInfo |
2950 | | * @out_info: a #GstVideoInfo |
2951 | | * @config: (transfer full): a #GstStructure with configuration options |
2952 | | * |
2953 | | * Create a new converter object to convert between @in_info and @out_info |
2954 | | * with @config. |
2955 | | * |
2956 | | * Returns (nullable): a #GstVideoConverter or %NULL if conversion is not possible. |
2957 | | * |
2958 | | * Since: 1.6 |
2959 | | */ |
2960 | | GstVideoConverter * |
2961 | | gst_video_converter_new (const GstVideoInfo * in_info, |
2962 | | const GstVideoInfo * out_info, GstStructure * config) |
2963 | 2.08k | { |
2964 | 2.08k | return gst_video_converter_new_with_pool (in_info, out_info, config, NULL); |
2965 | 2.08k | } |
2966 | | |
2967 | | static void |
2968 | | clear_matrix_data (MatrixData * data) |
2969 | 6.24k | { |
2970 | 6.24k | g_free (data->t_r); |
2971 | 6.24k | g_free (data->t_g); |
2972 | 6.24k | g_free (data->t_b); |
2973 | 6.24k | } |
2974 | | |
2975 | | /** |
2976 | | * gst_video_converter_free: |
2977 | | * @convert: a #GstVideoConverter |
2978 | | * |
2979 | | * Free @convert |
2980 | | * |
2981 | | * Since: 1.6 |
2982 | | */ |
2983 | | void |
2984 | | gst_video_converter_free (GstVideoConverter * convert) |
2985 | 2.08k | { |
2986 | 2.08k | guint i, j; |
2987 | | |
2988 | 2.08k | g_return_if_fail (convert != NULL); |
2989 | | |
2990 | 4.16k | for (i = 0; i < convert->conversion_runner->n_threads; i++) { |
2991 | 2.08k | if (convert->upsample_p && convert->upsample_p[i]) |
2992 | 439 | gst_video_chroma_resample_free (convert->upsample_p[i]); |
2993 | 2.08k | if (convert->upsample_i && convert->upsample_i[i]) |
2994 | 0 | gst_video_chroma_resample_free (convert->upsample_i[i]); |
2995 | 2.08k | if (convert->downsample_p && convert->downsample_p[i]) |
2996 | 268 | gst_video_chroma_resample_free (convert->downsample_p[i]); |
2997 | 2.08k | if (convert->downsample_i && convert->downsample_i[i]) |
2998 | 0 | gst_video_chroma_resample_free (convert->downsample_i[i]); |
2999 | 2.08k | if (convert->v_scaler_p && convert->v_scaler_p[i]) |
3000 | 740 | gst_video_scaler_free (convert->v_scaler_p[i]); |
3001 | 2.08k | if (convert->v_scaler_i && convert->v_scaler_i[i]) |
3002 | 0 | gst_video_scaler_free (convert->v_scaler_i[i]); |
3003 | 2.08k | if (convert->h_scaler && convert->h_scaler[i]) |
3004 | 703 | gst_video_scaler_free (convert->h_scaler[i]); |
3005 | 2.08k | if (convert->unpack_lines && convert->unpack_lines[i]) |
3006 | 946 | gst_line_cache_free (convert->unpack_lines[i]); |
3007 | 2.08k | if (convert->upsample_lines && convert->upsample_lines[i]) |
3008 | 439 | gst_line_cache_free (convert->upsample_lines[i]); |
3009 | 2.08k | if (convert->to_RGB_lines && convert->to_RGB_lines[i]) |
3010 | 0 | gst_line_cache_free (convert->to_RGB_lines[i]); |
3011 | 2.08k | if (convert->hscale_lines && convert->hscale_lines[i]) |
3012 | 703 | gst_line_cache_free (convert->hscale_lines[i]); |
3013 | 2.08k | if (convert->vscale_lines && convert->vscale_lines[i]) |
3014 | 740 | gst_line_cache_free (convert->vscale_lines[i]); |
3015 | 2.08k | if (convert->convert_lines && convert->convert_lines[i]) |
3016 | 710 | gst_line_cache_free (convert->convert_lines[i]); |
3017 | 2.08k | if (convert->alpha_lines && convert->alpha_lines[i]) |
3018 | 0 | gst_line_cache_free (convert->alpha_lines[i]); |
3019 | 2.08k | if (convert->to_YUV_lines && convert->to_YUV_lines[i]) |
3020 | 0 | gst_line_cache_free (convert->to_YUV_lines[i]); |
3021 | 2.08k | if (convert->downsample_lines && convert->downsample_lines[i]) |
3022 | 268 | gst_line_cache_free (convert->downsample_lines[i]); |
3023 | 2.08k | if (convert->dither_lines && convert->dither_lines[i]) |
3024 | 96 | gst_line_cache_free (convert->dither_lines[i]); |
3025 | 2.08k | if (convert->dither && convert->dither[i]) |
3026 | 96 | gst_video_dither_free (convert->dither[i]); |
3027 | 2.08k | } |
3028 | 2.08k | g_free (convert->upsample_p); |
3029 | 2.08k | g_free (convert->upsample_i); |
3030 | 2.08k | g_free (convert->downsample_p); |
3031 | 2.08k | g_free (convert->downsample_i); |
3032 | 2.08k | g_free (convert->v_scaler_p); |
3033 | 2.08k | g_free (convert->v_scaler_i); |
3034 | 2.08k | g_free (convert->h_scaler); |
3035 | 2.08k | g_free (convert->unpack_lines); |
3036 | 2.08k | g_free (convert->pack_lines); |
3037 | 2.08k | g_free (convert->upsample_lines); |
3038 | 2.08k | g_free (convert->to_RGB_lines); |
3039 | 2.08k | g_free (convert->hscale_lines); |
3040 | 2.08k | g_free (convert->vscale_lines); |
3041 | 2.08k | g_free (convert->convert_lines); |
3042 | 2.08k | g_free (convert->alpha_lines); |
3043 | 2.08k | g_free (convert->to_YUV_lines); |
3044 | 2.08k | g_free (convert->downsample_lines); |
3045 | 2.08k | g_free (convert->dither_lines); |
3046 | 2.08k | g_free (convert->dither); |
3047 | | |
3048 | 2.08k | g_free (convert->gamma_dec.gamma_table); |
3049 | 2.08k | g_free (convert->gamma_enc.gamma_table); |
3050 | | |
3051 | 2.08k | if (convert->tmpline) { |
3052 | 2.28k | for (i = 0; i < convert->conversion_runner->n_threads; i++) |
3053 | 1.14k | g_free (convert->tmpline[i]); |
3054 | 1.14k | g_free (convert->tmpline); |
3055 | 1.14k | } |
3056 | | |
3057 | 2.08k | g_free (convert->borderline); |
3058 | | |
3059 | 2.08k | if (convert->config) |
3060 | 2.08k | gst_structure_free (convert->config); |
3061 | | |
3062 | 10.4k | for (i = 0; i < 4; i++) { |
3063 | 16.6k | for (j = 0; j < convert->conversion_runner->n_threads; j++) { |
3064 | 8.33k | if (convert->fv_scaler[i].scaler) |
3065 | 588 | gst_video_scaler_free (convert->fv_scaler[i].scaler[j]); |
3066 | 8.33k | if (convert->fh_scaler[i].scaler) |
3067 | 611 | gst_video_scaler_free (convert->fh_scaler[i].scaler[j]); |
3068 | 8.33k | } |
3069 | 8.33k | g_free (convert->fv_scaler[i].scaler); |
3070 | 8.33k | g_free (convert->fh_scaler[i].scaler); |
3071 | 8.33k | } |
3072 | | |
3073 | 2.08k | if (convert->conversion_runner) |
3074 | 2.08k | gst_parallelized_task_runner_free (convert->conversion_runner); |
3075 | | |
3076 | 2.08k | clear_matrix_data (&convert->to_RGB_matrix); |
3077 | 2.08k | clear_matrix_data (&convert->convert_matrix); |
3078 | 2.08k | clear_matrix_data (&convert->to_YUV_matrix); |
3079 | | |
3080 | 10.4k | for (i = 0; i < 4; i++) { |
3081 | 8.33k | g_free (convert->tasks[i]); |
3082 | 8.33k | g_free (convert->tasks_p[i]); |
3083 | 8.33k | } |
3084 | | |
3085 | 2.08k | g_free (convert); |
3086 | 2.08k | } |
3087 | | |
3088 | | static gboolean |
3089 | | copy_config (const GstIdStr * fieldname, const GValue * value, |
3090 | | gpointer user_data) |
3091 | 0 | { |
3092 | 0 | GstVideoConverter *convert = user_data; |
3093 | |
|
3094 | 0 | gst_structure_id_str_set_value (convert->config, fieldname, value); |
3095 | |
|
3096 | 0 | return TRUE; |
3097 | 0 | } |
3098 | | |
3099 | | /** |
3100 | | * gst_video_converter_set_config: |
3101 | | * @convert: a #GstVideoConverter |
3102 | | * @config: (transfer full): a #GstStructure |
3103 | | * |
3104 | | * Set @config as extra configuration for @convert. |
3105 | | * |
3106 | | * If the parameters in @config can not be set exactly, this function returns |
3107 | | * %FALSE and will try to update as much state as possible. The new state can |
3108 | | * then be retrieved and refined with gst_video_converter_get_config(). |
3109 | | * |
3110 | | * Look at the `GST_VIDEO_CONVERTER_OPT_*` fields to check valid configuration |
3111 | | * option and values. |
3112 | | * |
3113 | | * Returns: %TRUE when @config could be set. |
3114 | | * |
3115 | | * Since: 1.6 |
3116 | | */ |
3117 | | gboolean |
3118 | | gst_video_converter_set_config (GstVideoConverter * convert, |
3119 | | GstStructure * config) |
3120 | 0 | { |
3121 | 0 | g_return_val_if_fail (convert != NULL, FALSE); |
3122 | 0 | g_return_val_if_fail (config != NULL, FALSE); |
3123 | | |
3124 | 0 | gst_structure_foreach_id_str (config, copy_config, convert); |
3125 | 0 | gst_structure_free (config); |
3126 | |
|
3127 | 0 | gst_video_converter_init_from_config (convert); |
3128 | |
|
3129 | 0 | return TRUE; |
3130 | 0 | } |
3131 | | |
3132 | | /** |
3133 | | * gst_video_converter_get_config: |
3134 | | * @convert: a #GstVideoConverter |
3135 | | * |
3136 | | * Get the current configuration of @convert. |
3137 | | * |
3138 | | * Returns: a #GstStructure that remains valid for as long as @convert is valid |
3139 | | * or until gst_video_converter_set_config() is called. |
3140 | | */ |
3141 | | const GstStructure * |
3142 | | gst_video_converter_get_config (GstVideoConverter * convert) |
3143 | 0 | { |
3144 | 0 | g_return_val_if_fail (convert != NULL, NULL); |
3145 | | |
3146 | 0 | return convert->config; |
3147 | 0 | } |
3148 | | |
3149 | | /** |
3150 | | * gst_video_converter_frame: |
3151 | | * @convert: a #GstVideoConverter |
3152 | | * @dest: a #GstVideoFrame |
3153 | | * @src: a #GstVideoFrame |
3154 | | * |
3155 | | * Convert the pixels of @src into @dest using @convert. |
3156 | | * |
3157 | | * If #GST_VIDEO_CONVERTER_OPT_ASYNC_TASKS is %TRUE then this function will |
3158 | | * return immediately and needs to be followed by a call to |
3159 | | * gst_video_converter_frame_finish(). |
3160 | | * |
3161 | | * Since: 1.6 |
3162 | | */ |
3163 | | void |
3164 | | gst_video_converter_frame (GstVideoConverter * convert, |
3165 | | const GstVideoFrame * src, GstVideoFrame * dest) |
3166 | 2.08k | { |
3167 | 2.08k | g_return_if_fail (convert != NULL); |
3168 | 2.08k | g_return_if_fail (src != NULL); |
3169 | 2.08k | g_return_if_fail (dest != NULL); |
3170 | | |
3171 | | /* Check the frames we've been passed match the layout |
3172 | | * we were configured for or we might go out of bounds */ |
3173 | 2.08k | if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&convert->in_info) != |
3174 | 2.08k | GST_VIDEO_FRAME_FORMAT (src) |
3175 | 2.08k | || GST_VIDEO_INFO_WIDTH (&convert->in_info) > |
3176 | 2.08k | GST_VIDEO_FRAME_WIDTH (src) |
3177 | 2.08k | || GST_VIDEO_INFO_FIELD_HEIGHT (&convert->in_info) > |
3178 | 2.08k | GST_VIDEO_FRAME_HEIGHT (src))) { |
3179 | 0 | g_critical ("Input video frame does not match configuration"); |
3180 | 0 | return; |
3181 | 0 | } |
3182 | 2.08k | if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&convert->out_info) != |
3183 | 2.08k | GST_VIDEO_FRAME_FORMAT (dest) |
3184 | 2.08k | || GST_VIDEO_INFO_WIDTH (&convert->out_info) > |
3185 | 2.08k | GST_VIDEO_FRAME_WIDTH (dest) |
3186 | 2.08k | || GST_VIDEO_INFO_FIELD_HEIGHT (&convert->out_info) > |
3187 | 2.08k | GST_VIDEO_FRAME_HEIGHT (dest))) { |
3188 | 0 | g_critical ("Output video frame does not match configuration"); |
3189 | 0 | return; |
3190 | 0 | } |
3191 | | |
3192 | 2.08k | if (G_UNLIKELY (convert->in_width == 0 || convert->in_height == 0 || |
3193 | 2.08k | convert->out_width == 0 || convert->out_height == 0)) |
3194 | 0 | return; |
3195 | | |
3196 | 2.08k | convert->convert (convert, src, dest); |
3197 | 2.08k | } |
3198 | | |
3199 | | /** |
3200 | | * gst_video_converter_frame_finish: |
3201 | | * @convert: a #GstVideoConverter |
3202 | | * |
3203 | | * Wait for a previous async conversion performed using |
3204 | | * gst_video_converter_frame() to complete. |
3205 | | * |
3206 | | * Since: 1.20 |
3207 | | */ |
3208 | | void |
3209 | | gst_video_converter_frame_finish (GstVideoConverter * convert) |
3210 | 0 | { |
3211 | 0 | g_return_if_fail (convert); |
3212 | 0 | g_return_if_fail (convert->conversion_runner); |
3213 | 0 | g_return_if_fail (convert->conversion_runner->async_tasks); |
3214 | | |
3215 | 0 | gst_parallelized_task_runner_finish (convert->conversion_runner); |
3216 | 0 | } |
3217 | | |
3218 | | static void |
3219 | | video_converter_compute_matrix (GstVideoConverter * convert) |
3220 | 539 | { |
3221 | 539 | MatrixData *dst = &convert->convert_matrix; |
3222 | | |
3223 | 539 | color_matrix_set_identity (dst); |
3224 | 539 | compute_matrix_to_RGB (convert, dst); |
3225 | 539 | compute_matrix_to_YUV (convert, dst, FALSE); |
3226 | | |
3227 | 539 | convert->current_bits = 8; |
3228 | 539 | prepare_matrix (convert, dst); |
3229 | 539 | } |
3230 | | |
3231 | | static void |
3232 | | video_converter_compute_resample (GstVideoConverter * convert, gint idx) |
3233 | 946 | { |
3234 | 946 | GstVideoInfo *in_info, *out_info; |
3235 | 946 | const GstVideoFormatInfo *sfinfo, *dfinfo; |
3236 | | |
3237 | 946 | if (CHECK_CHROMA_NONE (convert)) |
3238 | 0 | return; |
3239 | | |
3240 | 946 | in_info = &convert->in_info; |
3241 | 946 | out_info = &convert->out_info; |
3242 | | |
3243 | 946 | sfinfo = in_info->finfo; |
3244 | 946 | dfinfo = out_info->finfo; |
3245 | | |
3246 | 946 | GST_LOG ("site: %d->%d, w_sub: %d->%d, h_sub: %d->%d", in_info->chroma_site, |
3247 | 946 | out_info->chroma_site, sfinfo->w_sub[2], dfinfo->w_sub[2], |
3248 | 946 | sfinfo->h_sub[2], dfinfo->h_sub[2]); |
3249 | | |
3250 | 946 | if (sfinfo->w_sub[2] != dfinfo->w_sub[2] || |
3251 | 451 | sfinfo->h_sub[2] != dfinfo->h_sub[2] || |
3252 | 398 | in_info->chroma_site != out_info->chroma_site || |
3253 | 398 | in_info->width != out_info->width || |
3254 | 918 | in_info->height != out_info->height) { |
3255 | 918 | if (GST_VIDEO_INFO_IS_INTERLACED (in_info) |
3256 | 0 | && GST_VIDEO_INFO_INTERLACE_MODE (in_info) != |
3257 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE) { |
3258 | 0 | if (!CHECK_CHROMA_DOWNSAMPLE (convert)) |
3259 | 0 | convert->upsample_i[idx] = gst_video_chroma_resample_new (0, |
3260 | 0 | in_info->chroma_site, GST_VIDEO_CHROMA_FLAG_INTERLACED, |
3261 | 0 | sfinfo->unpack_format, sfinfo->w_sub[2], sfinfo->h_sub[2]); |
3262 | 0 | if (!CHECK_CHROMA_UPSAMPLE (convert)) |
3263 | 0 | convert->downsample_i[idx] = |
3264 | 0 | gst_video_chroma_resample_new (0, out_info->chroma_site, |
3265 | 0 | GST_VIDEO_CHROMA_FLAG_INTERLACED, dfinfo->unpack_format, |
3266 | 0 | -dfinfo->w_sub[2], -dfinfo->h_sub[2]); |
3267 | 0 | } |
3268 | 918 | if (!CHECK_CHROMA_DOWNSAMPLE (convert)) |
3269 | 918 | convert->upsample_p[idx] = gst_video_chroma_resample_new (0, |
3270 | 918 | in_info->chroma_site, 0, sfinfo->unpack_format, sfinfo->w_sub[2], |
3271 | 918 | sfinfo->h_sub[2]); |
3272 | 918 | if (!CHECK_CHROMA_UPSAMPLE (convert)) |
3273 | 918 | convert->downsample_p[idx] = gst_video_chroma_resample_new (0, |
3274 | 918 | out_info->chroma_site, 0, dfinfo->unpack_format, -dfinfo->w_sub[2], |
3275 | 918 | -dfinfo->h_sub[2]); |
3276 | 918 | } |
3277 | 946 | } |
3278 | | |
3279 | | #define FRAME_GET_PLANE_STRIDE(frame, plane) \ |
3280 | 34.8k | GST_VIDEO_FRAME_PLANE_STRIDE (frame, plane) |
3281 | | #define FRAME_GET_PLANE_LINE(frame, plane, line) \ |
3282 | 32.3k | (gpointer)(((guint8*)(GST_VIDEO_FRAME_PLANE_DATA (frame, plane))) + \ |
3283 | 32.3k | FRAME_GET_PLANE_STRIDE (frame, plane) * (line)) |
3284 | | |
3285 | | #define FRAME_GET_COMP_STRIDE(frame, comp) \ |
3286 | 55.2k | GST_VIDEO_FRAME_COMP_STRIDE (frame, comp) |
3287 | | #define FRAME_GET_COMP_LINE(frame, comp, line) \ |
3288 | 55.2k | (gpointer)(((guint8*)(GST_VIDEO_FRAME_COMP_DATA (frame, comp))) + \ |
3289 | 55.2k | FRAME_GET_COMP_STRIDE (frame, comp) * (line)) |
3290 | | |
3291 | 790 | #define FRAME_GET_STRIDE(frame) FRAME_GET_PLANE_STRIDE (frame, 0) |
3292 | 30.5k | #define FRAME_GET_LINE(frame,line) FRAME_GET_PLANE_LINE (frame, 0, line) |
3293 | | |
3294 | 19.8k | #define FRAME_GET_Y_LINE(frame,line) FRAME_GET_COMP_LINE(frame, GST_VIDEO_COMP_Y, line) |
3295 | 16.8k | #define FRAME_GET_U_LINE(frame,line) FRAME_GET_COMP_LINE(frame, GST_VIDEO_COMP_U, line) |
3296 | 16.8k | #define FRAME_GET_V_LINE(frame,line) FRAME_GET_COMP_LINE(frame, GST_VIDEO_COMP_V, line) |
3297 | 0 | #define FRAME_GET_A_LINE(frame,line) FRAME_GET_COMP_LINE(frame, GST_VIDEO_COMP_A, line) |
3298 | | |
3299 | 16 | #define FRAME_GET_Y_STRIDE(frame) FRAME_GET_COMP_STRIDE(frame, GST_VIDEO_COMP_Y) |
3300 | 16 | #define FRAME_GET_U_STRIDE(frame) FRAME_GET_COMP_STRIDE(frame, GST_VIDEO_COMP_U) |
3301 | 16 | #define FRAME_GET_V_STRIDE(frame) FRAME_GET_COMP_STRIDE(frame, GST_VIDEO_COMP_V) |
3302 | | #define FRAME_GET_A_STRIDE(frame) FRAME_GET_COMP_STRIDE(frame, GST_VIDEO_COMP_A) |
3303 | | |
3304 | | |
3305 | | #define UNPACK_FRAME(frame,dest,line,x,width) \ |
3306 | 72.9k | frame->info.finfo->unpack_func (frame->info.finfo, \ |
3307 | 72.9k | (GST_VIDEO_FRAME_IS_INTERLACED (frame) ? \ |
3308 | 72.9k | GST_VIDEO_PACK_FLAG_INTERLACED : \ |
3309 | 72.9k | GST_VIDEO_PACK_FLAG_NONE), \ |
3310 | 72.9k | dest, frame->data, frame->info.stride, x, \ |
3311 | 72.9k | line, width) |
3312 | | #define PACK_FRAME(frame,src,line,width) \ |
3313 | 0 | frame->info.finfo->pack_func (frame->info.finfo, \ |
3314 | 71.1k | (GST_VIDEO_FRAME_IS_INTERLACED (frame) ? \ |
3315 | 0 | GST_VIDEO_PACK_FLAG_INTERLACED : \ |
3316 | 71.1k | GST_VIDEO_PACK_FLAG_NONE), \ |
3317 | 0 | src, 0, frame->data, frame->info.stride, \ |
3318 | 0 | frame->info.chroma_site, line, width); |
3319 | | |
3320 | | static gpointer |
3321 | | get_dest_line (GstLineCache * cache, gint idx, gpointer user_data) |
3322 | 10.8k | { |
3323 | 10.8k | GstVideoConverter *convert = user_data; |
3324 | 10.8k | guint8 *line; |
3325 | 10.8k | gint pstride = convert->pack_pstride; |
3326 | 10.8k | gint out_x = convert->out_x; |
3327 | 10.8k | guint cline; |
3328 | | |
3329 | 10.8k | cline = CLAMP (idx, 0, convert->out_maxheight - 1); |
3330 | | |
3331 | 10.8k | line = FRAME_GET_LINE (convert->dest, cline); |
3332 | 10.8k | GST_LOG ("get dest line %d %p", cline, line); |
3333 | | |
3334 | 10.8k | if (convert->borderline) { |
3335 | 0 | gint r_border = (out_x + convert->out_width) * pstride; |
3336 | 0 | gint rb_width = convert->out_maxwidth * pstride - r_border; |
3337 | 0 | gint lb_width = out_x * pstride; |
3338 | |
|
3339 | 0 | memcpy (line, convert->borderline, lb_width); |
3340 | 0 | memcpy (line + r_border, convert->borderline, rb_width); |
3341 | 0 | } |
3342 | 10.8k | line += out_x * pstride; |
3343 | | |
3344 | 10.8k | return line; |
3345 | 10.8k | } |
3346 | | |
3347 | | static gboolean |
3348 | | do_unpack_lines (GstLineCache * cache, gint idx, gint out_line, gint in_line, |
3349 | | gpointer user_data) |
3350 | 77.4k | { |
3351 | 77.4k | GstVideoConverter *convert = user_data; |
3352 | 77.4k | gpointer tmpline; |
3353 | 77.4k | guint cline; |
3354 | | |
3355 | 77.4k | cline = CLAMP (in_line + convert->in_y, 0, convert->in_maxheight - 1); |
3356 | | |
3357 | 77.4k | if (cache->alloc_writable || !convert->identity_unpack) { |
3358 | 72.8k | tmpline = gst_line_cache_alloc_line (cache, out_line); |
3359 | 72.8k | GST_LOG ("unpack line %d (%u) %p", in_line, cline, tmpline); |
3360 | 72.8k | UNPACK_FRAME (convert->src, tmpline, cline, convert->in_x, |
3361 | 72.8k | convert->in_width); |
3362 | 72.8k | } else { |
3363 | 4.56k | tmpline = ((guint8 *) FRAME_GET_LINE (convert->src, cline)) + |
3364 | 4.56k | convert->in_x * convert->unpack_pstride; |
3365 | 4.56k | GST_LOG ("get src line %d (%u) %p", in_line, cline, tmpline); |
3366 | 4.56k | } |
3367 | 77.4k | gst_line_cache_add_line (cache, in_line, tmpline); |
3368 | | |
3369 | 77.4k | return TRUE; |
3370 | 77.4k | } |
3371 | | |
3372 | | static gboolean |
3373 | | do_upsample_lines (GstLineCache * cache, gint idx, gint out_line, gint in_line, |
3374 | | gpointer user_data) |
3375 | 28.0k | { |
3376 | 28.0k | GstVideoConverter *convert = user_data; |
3377 | 28.0k | gpointer *lines; |
3378 | 28.0k | gint i, start_line, n_lines; |
3379 | | |
3380 | 28.0k | n_lines = convert->up_n_lines; |
3381 | 28.0k | start_line = in_line; |
3382 | 28.0k | if (start_line < n_lines + convert->up_offset) { |
3383 | 430 | start_line += convert->up_offset; |
3384 | 430 | out_line += convert->up_offset; |
3385 | 430 | } |
3386 | | |
3387 | | /* get the lines needed for chroma upsample */ |
3388 | 28.0k | lines = |
3389 | 28.0k | gst_line_cache_get_lines (cache->prev, idx, out_line, start_line, |
3390 | 28.0k | n_lines); |
3391 | | |
3392 | 28.0k | if (convert->upsample[idx]) { |
3393 | 28.0k | GST_LOG ("doing upsample %d-%d %p", start_line, start_line + n_lines - 1, |
3394 | 28.0k | lines[0]); |
3395 | 28.0k | gst_video_chroma_resample (convert->upsample[idx], lines, |
3396 | 28.0k | convert->in_width); |
3397 | 28.0k | } |
3398 | | |
3399 | 68.0k | for (i = 0; i < n_lines; i++) |
3400 | 40.0k | gst_line_cache_add_line (cache, start_line + i, lines[i]); |
3401 | | |
3402 | 28.0k | return TRUE; |
3403 | 28.0k | } |
3404 | | |
3405 | | static gboolean |
3406 | | do_convert_to_RGB_lines (GstLineCache * cache, gint idx, gint out_line, |
3407 | | gint in_line, gpointer user_data) |
3408 | 0 | { |
3409 | 0 | GstVideoConverter *convert = user_data; |
3410 | 0 | MatrixData *data = &convert->to_RGB_matrix; |
3411 | 0 | gpointer *lines, destline; |
3412 | |
|
3413 | 0 | lines = gst_line_cache_get_lines (cache->prev, idx, out_line, in_line, 1); |
3414 | 0 | destline = lines[0]; |
3415 | |
|
3416 | 0 | if (data->matrix_func) { |
3417 | 0 | GST_LOG ("to RGB line %d %p", in_line, destline); |
3418 | 0 | data->matrix_func (data, destline); |
3419 | 0 | } |
3420 | 0 | if (convert->gamma_dec.gamma_func) { |
3421 | 0 | destline = gst_line_cache_alloc_line (cache, out_line); |
3422 | |
|
3423 | 0 | GST_LOG ("gamma decode line %d %p->%p", in_line, lines[0], destline); |
3424 | 0 | convert->gamma_dec.gamma_func (&convert->gamma_dec, destline, lines[0]); |
3425 | 0 | } |
3426 | 0 | gst_line_cache_add_line (cache, in_line, destline); |
3427 | |
|
3428 | 0 | return TRUE; |
3429 | 0 | } |
3430 | | |
3431 | | static gboolean |
3432 | | do_hscale_lines (GstLineCache * cache, gint idx, gint out_line, gint in_line, |
3433 | | gpointer user_data) |
3434 | 43.3k | { |
3435 | 43.3k | GstVideoConverter *convert = user_data; |
3436 | 43.3k | gpointer *lines, destline; |
3437 | | |
3438 | 43.3k | lines = gst_line_cache_get_lines (cache->prev, idx, out_line, in_line, 1); |
3439 | | |
3440 | 43.3k | destline = gst_line_cache_alloc_line (cache, out_line); |
3441 | | |
3442 | 43.3k | GST_LOG ("hresample line %d %p->%p", in_line, lines[0], destline); |
3443 | 43.3k | gst_video_scaler_horizontal (convert->h_scaler[idx], convert->h_scale_format, |
3444 | 43.3k | lines[0], destline, 0, convert->out_width); |
3445 | | |
3446 | 43.3k | gst_line_cache_add_line (cache, in_line, destline); |
3447 | | |
3448 | 43.3k | return TRUE; |
3449 | 43.3k | } |
3450 | | |
3451 | | static gboolean |
3452 | | do_vscale_lines (GstLineCache * cache, gint idx, gint out_line, gint in_line, |
3453 | | gpointer user_data) |
3454 | 65.1k | { |
3455 | 65.1k | GstVideoConverter *convert = user_data; |
3456 | 65.1k | gpointer *lines, destline; |
3457 | 65.1k | guint sline, n_lines; |
3458 | 65.1k | guint cline; |
3459 | | |
3460 | 65.1k | cline = CLAMP (in_line, 0, convert->out_height - 1); |
3461 | | |
3462 | 65.1k | gst_video_scaler_get_coeff (convert->v_scaler[idx], cline, &sline, &n_lines); |
3463 | 65.1k | lines = gst_line_cache_get_lines (cache->prev, idx, out_line, sline, n_lines); |
3464 | | |
3465 | 65.1k | destline = gst_line_cache_alloc_line (cache, out_line); |
3466 | | |
3467 | 65.1k | GST_LOG ("vresample line %d %d-%d %p->%p", in_line, sline, |
3468 | 65.1k | sline + n_lines - 1, lines[0], destline); |
3469 | 65.1k | gst_video_scaler_vertical (convert->v_scaler[idx], convert->v_scale_format, |
3470 | 65.1k | lines, destline, cline, convert->v_scale_width); |
3471 | | |
3472 | 65.1k | gst_line_cache_add_line (cache, in_line, destline); |
3473 | | |
3474 | 65.1k | return TRUE; |
3475 | 65.1k | } |
3476 | | |
3477 | | /* RGB values are kept in integer range here since matrix will normalize |
3478 | | * them later, but alpha is not handled by matrix, so normalize it here */ |
3479 | | static void |
3480 | | convert_u8_float (gfloat * d, const guint8 * s, gint width) |
3481 | 0 | { |
3482 | 0 | gint i; |
3483 | |
|
3484 | 0 | for (i = 0; i < width; i++) { |
3485 | 0 | d[i * 4 + 0] = s[i * 4 + 0] / 255.0f; |
3486 | 0 | d[i * 4 + 1] = s[i * 4 + 1]; |
3487 | 0 | d[i * 4 + 2] = s[i * 4 + 2]; |
3488 | 0 | d[i * 4 + 3] = s[i * 4 + 3]; |
3489 | 0 | } |
3490 | 0 | } |
3491 | | |
3492 | | static void |
3493 | | convert_u16_float (gfloat * d, const guint16 * s, gint width) |
3494 | 0 | { |
3495 | 0 | gint i; |
3496 | |
|
3497 | 0 | for (i = 0; i < width; i++) { |
3498 | 0 | d[i * 4 + 0] = s[i * 4 + 0] / 65535.0f; |
3499 | 0 | d[i * 4 + 1] = s[i * 4 + 1]; |
3500 | 0 | d[i * 4 + 2] = s[i * 4 + 2]; |
3501 | 0 | d[i * 4 + 3] = s[i * 4 + 3]; |
3502 | 0 | } |
3503 | 0 | } |
3504 | | |
3505 | | /* matrix output is already scaled to integer range for RGB, but alpha |
3506 | | * is still in [0, 1]. So scale only alpha here */ |
3507 | | static void |
3508 | | convert_float_u8 (guint8 * d, const gfloat * s, gint width) |
3509 | 0 | { |
3510 | 0 | gint i; |
3511 | |
|
3512 | 0 | for (i = 0; i < width; i++) { |
3513 | 0 | gdouble val; |
3514 | |
|
3515 | 0 | val = rint (s[i * 4 + 0] * 255.0); |
3516 | 0 | d[i * 4 + 0] = CLAMP (val, 0, 255); |
3517 | |
|
3518 | 0 | val = rint (s[i * 4 + 1]); |
3519 | 0 | d[i * 4 + 1] = CLAMP (val, 0, 255); |
3520 | |
|
3521 | 0 | val = rint (s[i * 4 + 2]); |
3522 | 0 | d[i * 4 + 2] = CLAMP (val, 0, 255); |
3523 | |
|
3524 | 0 | val = rint (s[i * 4 + 3]); |
3525 | 0 | d[i * 4 + 3] = CLAMP (val, 0, 255); |
3526 | 0 | } |
3527 | 0 | } |
3528 | | |
3529 | | static void |
3530 | | convert_float_u16 (guint16 * d, const gfloat * s, gint width) |
3531 | 0 | { |
3532 | 0 | gint i; |
3533 | |
|
3534 | 0 | for (i = 0; i < width; i++) { |
3535 | 0 | gdouble val; |
3536 | |
|
3537 | 0 | val = rint (s[i * 4 + 0] * 65535.0); |
3538 | 0 | d[i * 4 + 0] = CLAMP (val, 0, 65535); |
3539 | |
|
3540 | 0 | val = rint (s[i * 4 + 1]); |
3541 | 0 | d[i * 4 + 1] = CLAMP (val, 0, 65535); |
3542 | |
|
3543 | 0 | val = rint (s[i * 4 + 2]); |
3544 | 0 | d[i * 4 + 2] = CLAMP (val, 0, 65535); |
3545 | |
|
3546 | 0 | val = rint (s[i * 4 + 3]); |
3547 | 0 | d[i * 4 + 3] = CLAMP (val, 0, 65535); |
3548 | 0 | } |
3549 | 0 | } |
3550 | | |
3551 | | static gboolean |
3552 | | do_convert_lines (GstLineCache * cache, gint idx, gint out_line, gint in_line, |
3553 | | gpointer user_data) |
3554 | 43.0k | { |
3555 | 43.0k | GstVideoConverter *convert = user_data; |
3556 | 43.0k | MatrixData *data = &convert->convert_matrix; |
3557 | 43.0k | gpointer *lines, destline; |
3558 | 43.0k | guint in_bits, out_bits; |
3559 | 43.0k | gboolean in_float, out_float; |
3560 | 43.0k | gint width; |
3561 | | |
3562 | 43.0k | lines = gst_line_cache_get_lines (cache->prev, idx, out_line, in_line, 1); |
3563 | | |
3564 | 43.0k | destline = lines[0]; |
3565 | | |
3566 | 43.0k | in_bits = convert->in_bits; |
3567 | 43.0k | out_bits = convert->out_bits; |
3568 | | |
3569 | 43.0k | in_float = convert->convert_in_float; |
3570 | 43.0k | out_float = convert->convert_out_float; |
3571 | | |
3572 | 43.0k | width = MIN (convert->in_width, convert->out_width); |
3573 | | |
3574 | 43.0k | if (in_float || out_float) { |
3575 | 0 | if (in_float && out_float) { |
3576 | 0 | if (data->matrix_func) { |
3577 | 0 | GST_LOG ("matrix float line %d %p", in_line, destline); |
3578 | 0 | data->matrix_func (data, destline); |
3579 | 0 | } |
3580 | 0 | } else if (out_float) { |
3581 | | /* convert integer input to float before applying float matrix */ |
3582 | 0 | destline = gst_line_cache_alloc_line (cache, out_line); |
3583 | |
|
3584 | 0 | if (in_bits == 8) { |
3585 | 0 | GST_LOG ("8->float line %d %p->%p", in_line, lines[0], destline); |
3586 | 0 | convert_u8_float (destline, lines[0], width); |
3587 | 0 | } else { |
3588 | 0 | g_assert (in_bits == 16); |
3589 | | |
3590 | 0 | GST_LOG ("16->float line %d %p->%p", in_line, lines[0], destline); |
3591 | 0 | convert_u16_float (destline, lines[0], width); |
3592 | 0 | } |
3593 | | |
3594 | 0 | if (data->matrix_func) { |
3595 | 0 | GST_LOG ("matrix float line %d %p", in_line, destline); |
3596 | 0 | data->matrix_func (data, destline); |
3597 | 0 | } |
3598 | 0 | } else { |
3599 | 0 | gpointer srcline = lines[0]; |
3600 | | |
3601 | | /* apply float matrix first, then convert back to integer */ |
3602 | 0 | if (data->matrix_func) { |
3603 | 0 | GST_LOG ("matrix float line %d %p", in_line, srcline); |
3604 | 0 | data->matrix_func (data, srcline); |
3605 | 0 | } |
3606 | |
|
3607 | 0 | destline = gst_line_cache_alloc_line (cache, out_line); |
3608 | |
|
3609 | 0 | if (out_bits == 8) { |
3610 | 0 | GST_LOG ("float->8 line %d %p->%p", in_line, srcline, destline); |
3611 | 0 | convert_float_u8 (destline, srcline, width); |
3612 | 0 | } else { |
3613 | 0 | g_assert (out_bits == 16); |
3614 | | |
3615 | 0 | GST_LOG ("float->16 line %d %p->%p", in_line, srcline, destline); |
3616 | 0 | convert_float_u16 (destline, srcline, width); |
3617 | 0 | } |
3618 | 0 | } |
3619 | 43.0k | } else if (out_bits == 16 || in_bits == 16) { |
3620 | 14.6k | gpointer srcline = lines[0]; |
3621 | | |
3622 | 14.6k | if (out_bits != in_bits) |
3623 | 14.6k | destline = gst_line_cache_alloc_line (cache, out_line); |
3624 | | |
3625 | | /* FIXME, we can scale in the conversion matrix */ |
3626 | 14.6k | if (in_bits == 8) { |
3627 | 9.38k | GST_LOG ("8->16 line %d %p->%p", in_line, srcline, destline); |
3628 | 9.38k | video_orc_convert_u8_to_u16 (destline, srcline, width * 4); |
3629 | 9.38k | srcline = destline; |
3630 | 9.38k | } |
3631 | | |
3632 | 14.6k | if (data->matrix_func) { |
3633 | 13.8k | GST_LOG ("matrix line %d %p", in_line, srcline); |
3634 | 13.8k | data->matrix_func (data, srcline); |
3635 | 13.8k | } |
3636 | | |
3637 | | /* FIXME, dither here */ |
3638 | 14.6k | if (out_bits == 8) { |
3639 | 5.31k | GST_LOG ("16->8 line %d %p->%p", in_line, srcline, destline); |
3640 | 5.31k | video_orc_convert_u16_to_u8 (destline, srcline, width * 4); |
3641 | 5.31k | } |
3642 | 28.3k | } else { |
3643 | 28.3k | if (data->matrix_func) { |
3644 | 28.3k | GST_LOG ("matrix line %d %p", in_line, destline); |
3645 | 28.3k | data->matrix_func (data, destline); |
3646 | 28.3k | } |
3647 | 28.3k | } |
3648 | 43.0k | gst_line_cache_add_line (cache, in_line, destline); |
3649 | | |
3650 | 43.0k | return TRUE; |
3651 | 43.0k | } |
3652 | | |
3653 | | static gboolean |
3654 | | do_alpha_lines (GstLineCache * cache, gint idx, gint out_line, gint in_line, |
3655 | | gpointer user_data) |
3656 | 0 | { |
3657 | 0 | gpointer *lines, destline; |
3658 | 0 | GstVideoConverter *convert = user_data; |
3659 | 0 | gint width = MIN (convert->in_width, convert->out_width); |
3660 | |
|
3661 | 0 | lines = gst_line_cache_get_lines (cache->prev, idx, out_line, in_line, 1); |
3662 | 0 | destline = lines[0]; |
3663 | |
|
3664 | 0 | GST_LOG ("alpha line %d %p", in_line, destline); |
3665 | 0 | convert->alpha_func (convert, destline, width); |
3666 | |
|
3667 | 0 | gst_line_cache_add_line (cache, in_line, destline); |
3668 | |
|
3669 | 0 | return TRUE; |
3670 | 0 | } |
3671 | | |
3672 | | static gboolean |
3673 | | do_convert_to_YUV_lines (GstLineCache * cache, gint idx, gint out_line, |
3674 | | gint in_line, gpointer user_data) |
3675 | 0 | { |
3676 | 0 | GstVideoConverter *convert = user_data; |
3677 | 0 | MatrixData *data = &convert->to_YUV_matrix; |
3678 | 0 | gpointer *lines, destline; |
3679 | |
|
3680 | 0 | lines = gst_line_cache_get_lines (cache->prev, idx, out_line, in_line, 1); |
3681 | 0 | destline = lines[0]; |
3682 | |
|
3683 | 0 | if (convert->gamma_enc.gamma_func) { |
3684 | 0 | destline = gst_line_cache_alloc_line (cache, out_line); |
3685 | |
|
3686 | 0 | GST_LOG ("gamma encode line %d %p->%p", in_line, lines[0], destline); |
3687 | 0 | convert->gamma_enc.gamma_func (&convert->gamma_enc, destline, lines[0]); |
3688 | 0 | } |
3689 | 0 | if (data->matrix_func) { |
3690 | 0 | GST_LOG ("to YUV line %d %p", in_line, destline); |
3691 | 0 | data->matrix_func (data, destline); |
3692 | 0 | } |
3693 | 0 | gst_line_cache_add_line (cache, in_line, destline); |
3694 | |
|
3695 | 0 | return TRUE; |
3696 | 0 | } |
3697 | | |
3698 | | static gboolean |
3699 | | do_downsample_lines (GstLineCache * cache, gint idx, gint out_line, |
3700 | | gint in_line, gpointer user_data) |
3701 | 10.9k | { |
3702 | 10.9k | GstVideoConverter *convert = user_data; |
3703 | 10.9k | gpointer *lines; |
3704 | 10.9k | gint i, start_line, n_lines; |
3705 | | |
3706 | 10.9k | n_lines = convert->down_n_lines; |
3707 | 10.9k | start_line = in_line; |
3708 | 10.9k | if (start_line < n_lines + convert->down_offset) |
3709 | 268 | start_line += convert->down_offset; |
3710 | | |
3711 | | /* get the lines needed for chroma downsample */ |
3712 | 10.9k | lines = |
3713 | 10.9k | gst_line_cache_get_lines (cache->prev, idx, out_line, start_line, |
3714 | 10.9k | n_lines); |
3715 | | |
3716 | 10.9k | if (convert->downsample[idx]) { |
3717 | 10.9k | GST_LOG ("downsample line %d %d-%d %p", in_line, start_line, |
3718 | 10.9k | start_line + n_lines - 1, lines[0]); |
3719 | 10.9k | gst_video_chroma_resample (convert->downsample[idx], lines, |
3720 | 10.9k | convert->out_width); |
3721 | 10.9k | } |
3722 | | |
3723 | 28.3k | for (i = 0; i < n_lines; i++) |
3724 | 17.4k | gst_line_cache_add_line (cache, start_line + i, lines[i]); |
3725 | | |
3726 | 10.9k | return TRUE; |
3727 | 10.9k | } |
3728 | | |
3729 | | static gboolean |
3730 | | do_dither_lines (GstLineCache * cache, gint idx, gint out_line, gint in_line, |
3731 | | gpointer user_data) |
3732 | 10.6k | { |
3733 | 10.6k | GstVideoConverter *convert = user_data; |
3734 | 10.6k | gpointer *lines, destline; |
3735 | | |
3736 | 10.6k | lines = gst_line_cache_get_lines (cache->prev, idx, out_line, in_line, 1); |
3737 | 10.6k | destline = lines[0]; |
3738 | | |
3739 | 10.6k | if (convert->dither[idx]) { |
3740 | 10.6k | GST_LOG ("Dither line %d %p", in_line, destline); |
3741 | 10.6k | gst_video_dither_line (convert->dither[idx], destline, 0, out_line, |
3742 | 10.6k | convert->out_width); |
3743 | 10.6k | } |
3744 | 10.6k | gst_line_cache_add_line (cache, in_line, destline); |
3745 | | |
3746 | 10.6k | return TRUE; |
3747 | 10.6k | } |
3748 | | |
3749 | | typedef struct |
3750 | | { |
3751 | | GstLineCache *pack_lines; |
3752 | | gint idx; |
3753 | | gint h_0, h_1; |
3754 | | gint pack_lines_count; |
3755 | | gint out_y; |
3756 | | gboolean identity_pack; |
3757 | | gint lb_width, out_maxwidth; |
3758 | | GstVideoFrame *dest; |
3759 | | } ConvertTask; |
3760 | | |
3761 | | static void |
3762 | | convert_generic_task (ConvertTask * task) |
3763 | 946 | { |
3764 | 946 | gint i; |
3765 | | |
3766 | 82.7k | for (i = task->h_0; i < task->h_1; i += task->pack_lines_count) { |
3767 | 81.8k | gpointer *lines; |
3768 | | |
3769 | | /* load the lines needed to pack */ |
3770 | 81.8k | lines = |
3771 | 81.8k | gst_line_cache_get_lines (task->pack_lines, task->idx, i + task->out_y, |
3772 | 81.8k | i, task->pack_lines_count); |
3773 | | |
3774 | 81.8k | if (!task->identity_pack) { |
3775 | | /* take away the border */ |
3776 | 71.0k | guint8 *l = ((guint8 *) lines[0]) - task->lb_width; |
3777 | | /* and pack into destination */ |
3778 | 71.0k | GST_LOG ("pack line %d %p (%p)", i + task->out_y, lines[0], l); |
3779 | 71.0k | PACK_FRAME (task->dest, l, i + task->out_y, task->out_maxwidth); |
3780 | 71.0k | } |
3781 | 81.8k | } |
3782 | 946 | } |
3783 | | |
3784 | | static void |
3785 | | video_converter_generic (GstVideoConverter * convert, const GstVideoFrame * src, |
3786 | | GstVideoFrame * dest) |
3787 | 946 | { |
3788 | 946 | gint i; |
3789 | 946 | gint out_maxwidth, out_maxheight; |
3790 | 946 | gint out_x, out_y, out_height; |
3791 | 946 | gint pack_lines, pstride; |
3792 | 946 | gint lb_width; |
3793 | 946 | ConvertTask *tasks; |
3794 | 946 | ConvertTask **tasks_p; |
3795 | 946 | gint n_threads; |
3796 | 946 | gint lines_per_thread; |
3797 | | |
3798 | 946 | out_height = convert->out_height; |
3799 | 946 | out_maxwidth = convert->out_maxwidth; |
3800 | 946 | out_maxheight = convert->out_maxheight; |
3801 | | |
3802 | 946 | out_x = convert->out_x; |
3803 | 946 | out_y = convert->out_y; |
3804 | | |
3805 | 946 | convert->src = src; |
3806 | 946 | convert->dest = dest; |
3807 | | |
3808 | 946 | if (GST_VIDEO_FRAME_IS_INTERLACED (src)) { |
3809 | 0 | GST_LOG ("setup interlaced frame"); |
3810 | 0 | convert->upsample = convert->upsample_i; |
3811 | 0 | convert->downsample = convert->downsample_i; |
3812 | 0 | convert->v_scaler = convert->v_scaler_i; |
3813 | 946 | } else { |
3814 | 946 | GST_LOG ("setup progressive frame"); |
3815 | 946 | convert->upsample = convert->upsample_p; |
3816 | 946 | convert->downsample = convert->downsample_p; |
3817 | 946 | convert->v_scaler = convert->v_scaler_p; |
3818 | 946 | } |
3819 | 946 | if (convert->upsample[0]) { |
3820 | 439 | gst_video_chroma_resample_get_info (convert->upsample[0], |
3821 | 439 | &convert->up_n_lines, &convert->up_offset); |
3822 | 507 | } else { |
3823 | 507 | convert->up_n_lines = 1; |
3824 | 507 | convert->up_offset = 0; |
3825 | 507 | } |
3826 | 946 | if (convert->downsample[0]) { |
3827 | 268 | gst_video_chroma_resample_get_info (convert->downsample[0], |
3828 | 268 | &convert->down_n_lines, &convert->down_offset); |
3829 | 678 | } else { |
3830 | 678 | convert->down_n_lines = 1; |
3831 | 678 | convert->down_offset = 0; |
3832 | 678 | } |
3833 | | |
3834 | 946 | pack_lines = convert->pack_nlines; /* only 1 for now */ |
3835 | 946 | pstride = convert->pack_pstride; |
3836 | | |
3837 | 946 | lb_width = out_x * pstride; |
3838 | | |
3839 | 946 | if (convert->borderline) { |
3840 | | /* FIXME we should try to avoid PACK_FRAME */ |
3841 | 0 | for (i = 0; i < out_y; i++) |
3842 | 0 | PACK_FRAME (dest, convert->borderline, i, out_maxwidth); |
3843 | 0 | } |
3844 | | |
3845 | 946 | n_threads = convert->conversion_runner->n_threads; |
3846 | 946 | tasks = convert->tasks[0] = |
3847 | 946 | g_renew (ConvertTask, convert->tasks[0], n_threads); |
3848 | 946 | tasks_p = convert->tasks_p[0] = |
3849 | 946 | g_renew (ConvertTask *, convert->tasks_p[0], n_threads); |
3850 | | |
3851 | 946 | lines_per_thread = |
3852 | 946 | GST_ROUND_UP_N ((out_height + n_threads - 1) / n_threads, pack_lines); |
3853 | | |
3854 | 1.89k | for (i = 0; i < n_threads; i++) { |
3855 | 946 | tasks[i].dest = dest; |
3856 | 946 | tasks[i].pack_lines = convert->pack_lines[i]; |
3857 | 946 | tasks[i].idx = i; |
3858 | 946 | tasks[i].pack_lines_count = pack_lines; |
3859 | 946 | tasks[i].out_y = out_y; |
3860 | 946 | tasks[i].identity_pack = convert->identity_pack; |
3861 | 946 | tasks[i].lb_width = lb_width; |
3862 | 946 | tasks[i].out_maxwidth = out_maxwidth; |
3863 | | |
3864 | 946 | tasks[i].h_0 = i * lines_per_thread; |
3865 | 946 | tasks[i].h_1 = MIN ((i + 1) * lines_per_thread, out_height); |
3866 | | |
3867 | 946 | tasks_p[i] = &tasks[i]; |
3868 | 946 | } |
3869 | | |
3870 | 946 | gst_parallelized_task_runner_run (convert->conversion_runner, |
3871 | 946 | (GstParallelizedTaskFunc) convert_generic_task, (gpointer) tasks_p); |
3872 | | |
3873 | 946 | if (convert->borderline) { |
3874 | 0 | for (i = out_y + out_height; i < out_maxheight; i++) |
3875 | 0 | PACK_FRAME (dest, convert->borderline, i, out_maxwidth); |
3876 | 0 | } |
3877 | 946 | if (convert->pack_pal) { |
3878 | 0 | memcpy (GST_VIDEO_FRAME_PLANE_DATA (dest, 1), convert->pack_pal, |
3879 | 0 | convert->pack_palsize); |
3880 | 0 | } |
3881 | 946 | } |
3882 | | |
3883 | | static void convert_fill_border (GstVideoConverter * convert, |
3884 | | GstVideoFrame * dest); |
3885 | | |
3886 | | /* Fast paths */ |
3887 | | |
3888 | | #define GET_LINE_OFFSETS(interlaced,line,l1,l2) \ |
3889 | 3.36k | if (interlaced) { \ |
3890 | 0 | l1 = (line & 2 ? line - 1 : line); \ |
3891 | 0 | l2 = l1 + 2; \ |
3892 | 3.36k | } else { \ |
3893 | 3.36k | l1 = line; \ |
3894 | 3.36k | l2 = l1 + 1; \ |
3895 | 3.36k | } |
3896 | | |
3897 | | typedef struct |
3898 | | { |
3899 | | const GstVideoFrame *src; |
3900 | | GstVideoFrame *dest; |
3901 | | gint height_0, height_1; |
3902 | | |
3903 | | /* parameters */ |
3904 | | gboolean interlaced; |
3905 | | gint width; |
3906 | | gint alpha; |
3907 | | MatrixData *data; |
3908 | | gint in_x, in_y; |
3909 | | gint out_x, out_y; |
3910 | | gpointer tmpline; |
3911 | | } FConvertTask; |
3912 | | |
3913 | | static void |
3914 | | convert_I420_YUY2_task (FConvertTask * task) |
3915 | 18 | { |
3916 | 18 | gint i; |
3917 | 18 | gint l1, l2; |
3918 | | |
3919 | 905 | for (i = task->height_0; i < task->height_1; i += 2) { |
3920 | 887 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
3921 | | |
3922 | 887 | video_orc_convert_I420_YUY2 (FRAME_GET_LINE (task->dest, l1), |
3923 | 887 | FRAME_GET_LINE (task->dest, l2), |
3924 | 887 | FRAME_GET_Y_LINE (task->src, l1), |
3925 | 887 | FRAME_GET_Y_LINE (task->src, l2), |
3926 | 887 | FRAME_GET_U_LINE (task->src, i >> 1), |
3927 | 887 | FRAME_GET_V_LINE (task->src, i >> 1), (task->width + 1) / 2); |
3928 | 887 | } |
3929 | 18 | } |
3930 | | |
3931 | | static void |
3932 | | convert_I420_YUY2 (GstVideoConverter * convert, const GstVideoFrame * src, |
3933 | | GstVideoFrame * dest) |
3934 | 18 | { |
3935 | 18 | int i; |
3936 | 18 | gint width = convert->in_width; |
3937 | 18 | gint height = convert->in_height; |
3938 | 18 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
3939 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
3940 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
3941 | 18 | gint h2; |
3942 | 18 | FConvertTask *tasks; |
3943 | 18 | FConvertTask **tasks_p; |
3944 | 18 | gint n_threads; |
3945 | 18 | gint lines_per_thread; |
3946 | | |
3947 | | /* I420 has half as many chroma lines, as such we have to |
3948 | | * always merge two into one. For non-interlaced these are |
3949 | | * the two next to each other, for interlaced one is skipped |
3950 | | * in between. */ |
3951 | 18 | if (interlaced) |
3952 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
3953 | 18 | else |
3954 | 18 | h2 = GST_ROUND_DOWN_2 (height); |
3955 | | |
3956 | 18 | n_threads = convert->conversion_runner->n_threads; |
3957 | 18 | tasks = convert->tasks[0] = |
3958 | 18 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
3959 | 18 | tasks_p = convert->tasks_p[0] = |
3960 | 18 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
3961 | | |
3962 | 18 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
3963 | | |
3964 | 36 | for (i = 0; i < n_threads; i++) { |
3965 | 18 | tasks[i].src = src; |
3966 | 18 | tasks[i].dest = dest; |
3967 | | |
3968 | 18 | tasks[i].interlaced = interlaced; |
3969 | 18 | tasks[i].width = width; |
3970 | | |
3971 | 18 | tasks[i].height_0 = i * lines_per_thread; |
3972 | 18 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
3973 | 18 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
3974 | | |
3975 | 18 | tasks_p[i] = &tasks[i]; |
3976 | 18 | } |
3977 | | |
3978 | 18 | gst_parallelized_task_runner_run (convert->conversion_runner, |
3979 | 18 | (GstParallelizedTaskFunc) convert_I420_YUY2_task, (gpointer) tasks_p); |
3980 | | |
3981 | | /* now handle last lines. For interlaced these are up to 3 */ |
3982 | 18 | if (h2 != height) { |
3983 | 22 | for (i = h2; i < height; i++) { |
3984 | 11 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
3985 | 11 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
3986 | 11 | } |
3987 | 11 | } |
3988 | 18 | } |
3989 | | |
3990 | | static void |
3991 | | convert_I420_UYVY_task (FConvertTask * task) |
3992 | 18 | { |
3993 | 18 | gint i; |
3994 | 18 | gint l1, l2; |
3995 | | |
3996 | 769 | for (i = task->height_0; i < task->height_1; i += 2) { |
3997 | 751 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
3998 | | |
3999 | 751 | video_orc_convert_I420_UYVY (FRAME_GET_LINE (task->dest, l1), |
4000 | 751 | FRAME_GET_LINE (task->dest, l2), |
4001 | 751 | FRAME_GET_Y_LINE (task->src, l1), |
4002 | 751 | FRAME_GET_Y_LINE (task->src, l2), |
4003 | 751 | FRAME_GET_U_LINE (task->src, i >> 1), |
4004 | 751 | FRAME_GET_V_LINE (task->src, i >> 1), (task->width + 1) / 2); |
4005 | 751 | } |
4006 | 18 | } |
4007 | | |
4008 | | static void |
4009 | | convert_I420_UYVY (GstVideoConverter * convert, const GstVideoFrame * src, |
4010 | | GstVideoFrame * dest) |
4011 | 18 | { |
4012 | 18 | int i; |
4013 | 18 | gint width = convert->in_width; |
4014 | 18 | gint height = convert->in_height; |
4015 | 18 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
4016 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
4017 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
4018 | 18 | gint h2; |
4019 | 18 | FConvertTask *tasks; |
4020 | 18 | FConvertTask **tasks_p; |
4021 | 18 | gint n_threads; |
4022 | 18 | gint lines_per_thread; |
4023 | | |
4024 | | /* I420 has half as many chroma lines, as such we have to |
4025 | | * always merge two into one. For non-interlaced these are |
4026 | | * the two next to each other, for interlaced one is skipped |
4027 | | * in between. */ |
4028 | 18 | if (interlaced) |
4029 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
4030 | 18 | else |
4031 | 18 | h2 = GST_ROUND_DOWN_2 (height); |
4032 | | |
4033 | 18 | n_threads = convert->conversion_runner->n_threads; |
4034 | 18 | tasks = convert->tasks[0] = |
4035 | 18 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
4036 | 18 | tasks_p = convert->tasks_p[0] = |
4037 | 18 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
4038 | | |
4039 | 18 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
4040 | | |
4041 | 36 | for (i = 0; i < n_threads; i++) { |
4042 | 18 | tasks[i].src = src; |
4043 | 18 | tasks[i].dest = dest; |
4044 | | |
4045 | 18 | tasks[i].interlaced = interlaced; |
4046 | 18 | tasks[i].width = width; |
4047 | | |
4048 | 18 | tasks[i].height_0 = i * lines_per_thread; |
4049 | 18 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
4050 | 18 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
4051 | | |
4052 | 18 | tasks_p[i] = &tasks[i]; |
4053 | 18 | } |
4054 | | |
4055 | 18 | gst_parallelized_task_runner_run (convert->conversion_runner, |
4056 | 18 | (GstParallelizedTaskFunc) convert_I420_UYVY_task, (gpointer) tasks_p); |
4057 | | |
4058 | | /* now handle last lines. For interlaced these are up to 3 */ |
4059 | 18 | if (h2 != height) { |
4060 | 16 | for (i = h2; i < height; i++) { |
4061 | 8 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
4062 | 8 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
4063 | 8 | } |
4064 | 8 | } |
4065 | 18 | } |
4066 | | |
4067 | | static void |
4068 | | convert_I420_AYUV_task (FConvertTask * task) |
4069 | 16 | { |
4070 | 16 | gint i; |
4071 | 16 | gint l1, l2; |
4072 | | |
4073 | 706 | for (i = task->height_0; i < task->height_1; i += 2) { |
4074 | 690 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
4075 | | |
4076 | 690 | video_orc_convert_I420_AYUV (FRAME_GET_LINE (task->dest, l1), |
4077 | 690 | FRAME_GET_LINE (task->dest, l2), |
4078 | 690 | FRAME_GET_Y_LINE (task->src, l1), |
4079 | 690 | FRAME_GET_Y_LINE (task->src, l2), |
4080 | 690 | FRAME_GET_U_LINE (task->src, i >> 1), FRAME_GET_V_LINE (task->src, |
4081 | 690 | i >> 1), task->alpha, task->width); |
4082 | 690 | } |
4083 | 16 | } |
4084 | | |
4085 | | static void |
4086 | | convert_I420_AYUV (GstVideoConverter * convert, const GstVideoFrame * src, |
4087 | | GstVideoFrame * dest) |
4088 | 16 | { |
4089 | 16 | int i; |
4090 | 16 | gint width = convert->in_width; |
4091 | 16 | gint height = convert->in_height; |
4092 | 16 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
4093 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
4094 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
4095 | 16 | guint8 alpha = MIN (convert->alpha_value, 255); |
4096 | 16 | gint h2; |
4097 | 16 | FConvertTask *tasks; |
4098 | 16 | FConvertTask **tasks_p; |
4099 | 16 | gint n_threads; |
4100 | 16 | gint lines_per_thread; |
4101 | | |
4102 | | /* I420 has half as many chroma lines, as such we have to |
4103 | | * always merge two into one. For non-interlaced these are |
4104 | | * the two next to each other, for interlaced one is skipped |
4105 | | * in between. */ |
4106 | 16 | if (interlaced) |
4107 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
4108 | 16 | else |
4109 | 16 | h2 = GST_ROUND_DOWN_2 (height); |
4110 | | |
4111 | | |
4112 | 16 | n_threads = convert->conversion_runner->n_threads; |
4113 | 16 | tasks = convert->tasks[0] = |
4114 | 16 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
4115 | 16 | tasks_p = convert->tasks_p[0] = |
4116 | 16 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
4117 | | |
4118 | 16 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
4119 | | |
4120 | 32 | for (i = 0; i < n_threads; i++) { |
4121 | 16 | tasks[i].src = src; |
4122 | 16 | tasks[i].dest = dest; |
4123 | | |
4124 | 16 | tasks[i].interlaced = interlaced; |
4125 | 16 | tasks[i].width = width; |
4126 | 16 | tasks[i].alpha = alpha; |
4127 | | |
4128 | 16 | tasks[i].height_0 = i * lines_per_thread; |
4129 | 16 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
4130 | 16 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
4131 | | |
4132 | 16 | tasks_p[i] = &tasks[i]; |
4133 | 16 | } |
4134 | | |
4135 | 16 | gst_parallelized_task_runner_run (convert->conversion_runner, |
4136 | 16 | (GstParallelizedTaskFunc) convert_I420_AYUV_task, (gpointer) tasks_p); |
4137 | | |
4138 | | /* now handle last lines. For interlaced these are up to 3 */ |
4139 | 16 | if (h2 != height) { |
4140 | 20 | for (i = h2; i < height; i++) { |
4141 | 10 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
4142 | 10 | if (alpha != 0xff) |
4143 | 0 | convert_set_alpha_u8 (convert, convert->tmpline[0], width); |
4144 | 10 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
4145 | 10 | } |
4146 | 10 | } |
4147 | 16 | } |
4148 | | |
4149 | | static void |
4150 | | convert_I420_v210_task (FConvertTask * task) |
4151 | 0 | { |
4152 | 0 | gint i, j; |
4153 | 0 | gint l1, l2; |
4154 | 0 | const guint8 *s_y1, *s_y2, *s_u, *s_v; |
4155 | 0 | guint8 *d1, *d2; |
4156 | 0 | guint32 a0, a1, a2, a3; |
4157 | 0 | guint8 y0_1, y1_1, y2_1, y3_1, y4_1, y5_1; |
4158 | 0 | guint8 u0_1, u2_1, u4_1; |
4159 | 0 | guint8 v0_1, v2_1, v4_1; |
4160 | 0 | guint8 y0_2, y1_2, y2_2, y3_2, y4_2, y5_2; |
4161 | 0 | guint8 u0_2, u2_2, u4_2; |
4162 | 0 | guint8 v0_2, v2_2, v4_2; |
4163 | |
|
4164 | 0 | for (i = task->height_0; i < task->height_1; i += 2) { |
4165 | 0 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
4166 | |
|
4167 | 0 | s_y1 = FRAME_GET_Y_LINE (task->src, l1); |
4168 | 0 | s_y2 = FRAME_GET_Y_LINE (task->src, l2); |
4169 | 0 | s_u = FRAME_GET_U_LINE (task->src, i >> 1); |
4170 | 0 | s_v = FRAME_GET_V_LINE (task->src, i >> 1); |
4171 | |
|
4172 | 0 | d1 = FRAME_GET_LINE (task->dest, l1); |
4173 | 0 | d2 = FRAME_GET_LINE (task->dest, l2); |
4174 | |
|
4175 | 0 | for (j = 0; j < task->width; j += 6) { |
4176 | 0 | y1_1 = y2_1 = y3_1 = y4_1 = y5_1 = 0; |
4177 | 0 | u2_1 = u4_1 = v2_1 = v4_1 = 0; |
4178 | 0 | y1_2 = y2_2 = y3_2 = y4_2 = y5_2 = 0; |
4179 | 0 | u2_2 = u4_2 = v2_2 = v4_2 = 0; |
4180 | |
|
4181 | 0 | y0_1 = s_y1[j]; |
4182 | 0 | y0_2 = s_y2[j]; |
4183 | |
|
4184 | 0 | u0_1 = u0_2 = s_u[j / 2]; |
4185 | 0 | v0_1 = v0_2 = s_v[j / 2]; |
4186 | |
|
4187 | 0 | if (j < task->width - 1) { |
4188 | 0 | y1_1 = s_y1[j + 1]; |
4189 | 0 | y1_2 = s_y2[j + 1]; |
4190 | 0 | } |
4191 | |
|
4192 | 0 | if (j < task->width - 2) { |
4193 | 0 | y2_1 = s_y1[j + 2]; |
4194 | 0 | y2_2 = s_y2[j + 2]; |
4195 | |
|
4196 | 0 | u2_1 = u2_2 = s_u[j / 2 + 1]; |
4197 | 0 | v2_1 = v2_2 = s_v[j / 2 + 1]; |
4198 | 0 | } |
4199 | |
|
4200 | 0 | if (j < task->width - 3) { |
4201 | 0 | y3_1 = s_y1[j + 3]; |
4202 | 0 | y3_2 = s_y2[j + 3]; |
4203 | 0 | } |
4204 | |
|
4205 | 0 | if (j < task->width - 4) { |
4206 | 0 | y4_1 = s_y1[j + 4]; |
4207 | 0 | y4_2 = s_y2[j + 4]; |
4208 | |
|
4209 | 0 | u4_1 = u4_2 = s_u[j / 2 + 2]; |
4210 | 0 | v4_1 = v4_2 = s_v[j / 2 + 2]; |
4211 | 0 | } |
4212 | |
|
4213 | 0 | if (j < task->width - 5) { |
4214 | 0 | y5_1 = s_y1[j + 5]; |
4215 | 0 | y5_2 = s_y2[j + 5]; |
4216 | 0 | } |
4217 | |
|
4218 | 0 | a0 = u0_1 << 2 | (y0_1 << 12) | (v0_1 << 22); |
4219 | 0 | a1 = y1_1 << 2 | (u2_1 << 12) | (y2_1 << 22); |
4220 | 0 | a2 = v2_1 << 2 | (y3_1 << 12) | (u4_1 << 22); |
4221 | 0 | a3 = y4_1 << 2 | (v4_1 << 12) | (y5_1 << 22); |
4222 | |
|
4223 | 0 | GST_WRITE_UINT32_LE (d1 + (j / 6) * 16 + 0, a0); |
4224 | 0 | GST_WRITE_UINT32_LE (d1 + (j / 6) * 16 + 4, a1); |
4225 | 0 | GST_WRITE_UINT32_LE (d1 + (j / 6) * 16 + 8, a2); |
4226 | 0 | GST_WRITE_UINT32_LE (d1 + (j / 6) * 16 + 12, a3); |
4227 | |
|
4228 | 0 | a0 = u0_2 << 2 | (y0_2 << 12) | (v0_2 << 22); |
4229 | 0 | a1 = y1_2 << 2 | (u2_2 << 12) | (y2_2 << 22); |
4230 | 0 | a2 = v2_2 << 2 | (y3_2 << 12) | (u4_2 << 22); |
4231 | 0 | a3 = y4_2 << 2 | (v4_2 << 12) | (y5_2 << 22); |
4232 | |
|
4233 | 0 | GST_WRITE_UINT32_LE (d2 + (j / 6) * 16 + 0, a0); |
4234 | 0 | GST_WRITE_UINT32_LE (d2 + (j / 6) * 16 + 4, a1); |
4235 | 0 | GST_WRITE_UINT32_LE (d2 + (j / 6) * 16 + 8, a2); |
4236 | 0 | GST_WRITE_UINT32_LE (d2 + (j / 6) * 16 + 12, a3); |
4237 | 0 | } |
4238 | 0 | } |
4239 | 0 | } |
4240 | | |
4241 | | static void |
4242 | | convert_I420_v210 (GstVideoConverter * convert, const GstVideoFrame * src, |
4243 | | GstVideoFrame * dest) |
4244 | 0 | { |
4245 | 0 | int i; |
4246 | 0 | gint width = convert->in_width; |
4247 | 0 | gint height = convert->in_height; |
4248 | 0 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
4249 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
4250 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
4251 | 0 | gint h2; |
4252 | 0 | FConvertTask *tasks; |
4253 | 0 | FConvertTask **tasks_p; |
4254 | 0 | gint n_threads; |
4255 | 0 | gint lines_per_thread; |
4256 | 0 | guint8 *tmpline_8; |
4257 | | |
4258 | | /* I420 has half as many chroma lines, as such we have to |
4259 | | * always merge two into one. For non-interlaced these are |
4260 | | * the two next to each other, for interlaced one is skipped |
4261 | | * in between. */ |
4262 | 0 | if (interlaced) |
4263 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
4264 | 0 | else |
4265 | 0 | h2 = GST_ROUND_DOWN_2 (height); |
4266 | |
|
4267 | 0 | n_threads = convert->conversion_runner->n_threads; |
4268 | 0 | tasks = convert->tasks[0] = |
4269 | 0 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
4270 | 0 | tasks_p = convert->tasks_p[0] = |
4271 | 0 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
4272 | |
|
4273 | 0 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
4274 | |
|
4275 | 0 | for (i = 0; i < n_threads; i++) { |
4276 | 0 | tasks[i].src = src; |
4277 | 0 | tasks[i].dest = dest; |
4278 | |
|
4279 | 0 | tasks[i].interlaced = interlaced; |
4280 | 0 | tasks[i].width = width; |
4281 | |
|
4282 | 0 | tasks[i].height_0 = i * lines_per_thread; |
4283 | 0 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
4284 | 0 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
4285 | |
|
4286 | 0 | tasks_p[i] = &tasks[i]; |
4287 | 0 | } |
4288 | |
|
4289 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
4290 | 0 | (GstParallelizedTaskFunc) convert_I420_v210_task, (gpointer) tasks_p); |
4291 | | |
4292 | | /* now handle last lines. For interlaced these are up to 3 */ |
4293 | 0 | if (h2 != height) { |
4294 | 0 | for (i = h2; i < height; i++) { |
4295 | 0 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
4296 | |
|
4297 | 0 | tmpline_8 = (guint8 *) convert->tmpline[0]; |
4298 | 0 | for (int j = width * 4 - 1; j >= 0; j--) { |
4299 | 0 | convert->tmpline[0][j] = tmpline_8[j] << 8; |
4300 | 0 | } |
4301 | |
|
4302 | 0 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
4303 | 0 | } |
4304 | 0 | } |
4305 | 0 | } |
4306 | | |
4307 | | static void |
4308 | | convert_I420_10_v210_task (FConvertTask * task) |
4309 | 0 | { |
4310 | 0 | gint i, j; |
4311 | 0 | gint l1, l2; |
4312 | 0 | const guint16 *s_y1, *s_y2, *s_u, *s_v; |
4313 | 0 | guint8 *d1, *d2; |
4314 | 0 | guint32 a0, a1, a2, a3; |
4315 | 0 | guint16 y0_1, y1_1, y2_1, y3_1, y4_1, y5_1; |
4316 | 0 | guint16 u0_1, u2_1, u4_1; |
4317 | 0 | guint16 v0_1, v2_1, v4_1; |
4318 | 0 | guint16 y0_2, y1_2, y2_2, y3_2, y4_2, y5_2; |
4319 | 0 | guint16 u0_2, u2_2, u4_2; |
4320 | 0 | guint16 v0_2, v2_2, v4_2; |
4321 | |
|
4322 | 0 | for (i = task->height_0; i < task->height_1; i += 2) { |
4323 | 0 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
4324 | |
|
4325 | 0 | s_y1 = FRAME_GET_Y_LINE (task->src, l1); |
4326 | 0 | s_y2 = FRAME_GET_Y_LINE (task->src, l2); |
4327 | 0 | s_u = FRAME_GET_U_LINE (task->src, i >> 1); |
4328 | 0 | s_v = FRAME_GET_V_LINE (task->src, i >> 1); |
4329 | |
|
4330 | 0 | d1 = FRAME_GET_LINE (task->dest, l1); |
4331 | 0 | d2 = FRAME_GET_LINE (task->dest, l2); |
4332 | |
|
4333 | 0 | for (j = 0; j < task->width; j += 6) { |
4334 | 0 | y1_1 = y2_1 = y3_1 = y4_1 = y5_1 = 0; |
4335 | 0 | u2_1 = u4_1 = v2_1 = v4_1 = 0; |
4336 | 0 | y1_2 = y2_2 = y3_2 = y4_2 = y5_2 = 0; |
4337 | 0 | u2_2 = u4_2 = v2_2 = v4_2 = 0; |
4338 | |
|
4339 | 0 | y0_1 = s_y1[j]; |
4340 | 0 | y0_2 = s_y2[j]; |
4341 | |
|
4342 | 0 | u0_1 = u0_2 = s_u[j / 2]; |
4343 | 0 | v0_1 = v0_2 = s_v[j / 2]; |
4344 | |
|
4345 | 0 | if (j < task->width - 1) { |
4346 | 0 | y1_1 = s_y1[j + 1]; |
4347 | 0 | y1_2 = s_y2[j + 1]; |
4348 | 0 | } |
4349 | |
|
4350 | 0 | if (j < task->width - 2) { |
4351 | 0 | y2_1 = s_y1[j + 2]; |
4352 | 0 | y2_2 = s_y2[j + 2]; |
4353 | |
|
4354 | 0 | u2_1 = u2_2 = s_u[j / 2 + 1]; |
4355 | 0 | v2_1 = v2_2 = s_v[j / 2 + 1]; |
4356 | 0 | } |
4357 | |
|
4358 | 0 | if (j < task->width - 3) { |
4359 | 0 | y3_1 = s_y1[j + 3]; |
4360 | 0 | y3_2 = s_y2[j + 3]; |
4361 | 0 | } |
4362 | |
|
4363 | 0 | if (j < task->width - 4) { |
4364 | 0 | y4_1 = s_y1[j + 4]; |
4365 | 0 | y4_2 = s_y2[j + 4]; |
4366 | |
|
4367 | 0 | u4_1 = u4_2 = s_u[j / 2 + 2]; |
4368 | 0 | v4_1 = v4_2 = s_v[j / 2 + 2]; |
4369 | 0 | } |
4370 | |
|
4371 | 0 | if (j < task->width - 5) { |
4372 | 0 | y5_1 = s_y1[j + 5]; |
4373 | 0 | y5_2 = s_y2[j + 5]; |
4374 | 0 | } |
4375 | |
|
4376 | 0 | a0 = u0_1 | (y0_1 << 10) | (v0_1 << 20); |
4377 | 0 | a1 = y1_1 | (u2_1 << 10) | (y2_1 << 20); |
4378 | 0 | a2 = v2_1 | (y3_1 << 10) | (u4_1 << 20); |
4379 | 0 | a3 = y4_1 | (v4_1 << 10) | (y5_1 << 20); |
4380 | |
|
4381 | 0 | GST_WRITE_UINT32_LE (d1 + (j / 6) * 16 + 0, a0); |
4382 | 0 | GST_WRITE_UINT32_LE (d1 + (j / 6) * 16 + 4, a1); |
4383 | 0 | GST_WRITE_UINT32_LE (d1 + (j / 6) * 16 + 8, a2); |
4384 | 0 | GST_WRITE_UINT32_LE (d1 + (j / 6) * 16 + 12, a3); |
4385 | |
|
4386 | 0 | a0 = u0_2 | (y0_2 << 10) | (v0_2 << 20); |
4387 | 0 | a1 = y1_2 | (u2_2 << 10) | (y2_2 << 20); |
4388 | 0 | a2 = v2_2 | (y3_2 << 10) | (u4_2 << 20); |
4389 | 0 | a3 = y4_2 | (v4_2 << 10) | (y5_2 << 20); |
4390 | |
|
4391 | 0 | GST_WRITE_UINT32_LE (d2 + (j / 6) * 16 + 0, a0); |
4392 | 0 | GST_WRITE_UINT32_LE (d2 + (j / 6) * 16 + 4, a1); |
4393 | 0 | GST_WRITE_UINT32_LE (d2 + (j / 6) * 16 + 8, a2); |
4394 | 0 | GST_WRITE_UINT32_LE (d2 + (j / 6) * 16 + 12, a3); |
4395 | 0 | } |
4396 | 0 | } |
4397 | 0 | } |
4398 | | |
4399 | | static void |
4400 | | convert_I420_10_v210 (GstVideoConverter * convert, const GstVideoFrame * src, |
4401 | | GstVideoFrame * dest) |
4402 | 0 | { |
4403 | 0 | int i; |
4404 | 0 | gint width = convert->in_width; |
4405 | 0 | gint height = convert->in_height; |
4406 | 0 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
4407 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
4408 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
4409 | 0 | gint h2; |
4410 | 0 | FConvertTask *tasks; |
4411 | 0 | FConvertTask **tasks_p; |
4412 | 0 | gint n_threads; |
4413 | 0 | gint lines_per_thread; |
4414 | | |
4415 | | /* I420 has half as many chroma lines, as such we have to |
4416 | | * always merge two into one. For non-interlaced these are |
4417 | | * the two next to each other, for interlaced one is skipped |
4418 | | * in between. */ |
4419 | 0 | if (interlaced) |
4420 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
4421 | 0 | else |
4422 | 0 | h2 = GST_ROUND_DOWN_2 (height); |
4423 | |
|
4424 | 0 | n_threads = convert->conversion_runner->n_threads; |
4425 | 0 | tasks = convert->tasks[0] = |
4426 | 0 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
4427 | 0 | tasks_p = convert->tasks_p[0] = |
4428 | 0 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
4429 | |
|
4430 | 0 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
4431 | |
|
4432 | 0 | for (i = 0; i < n_threads; i++) { |
4433 | 0 | tasks[i].src = src; |
4434 | 0 | tasks[i].dest = dest; |
4435 | |
|
4436 | 0 | tasks[i].interlaced = interlaced; |
4437 | 0 | tasks[i].width = width; |
4438 | |
|
4439 | 0 | tasks[i].height_0 = i * lines_per_thread; |
4440 | 0 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
4441 | 0 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
4442 | |
|
4443 | 0 | tasks_p[i] = &tasks[i]; |
4444 | 0 | } |
4445 | |
|
4446 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
4447 | 0 | (GstParallelizedTaskFunc) convert_I420_10_v210_task, (gpointer) tasks_p); |
4448 | | |
4449 | | /* now handle last lines. For interlaced these are up to 3 */ |
4450 | 0 | if (h2 != height) { |
4451 | 0 | for (i = h2; i < height; i++) { |
4452 | 0 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
4453 | 0 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
4454 | 0 | } |
4455 | 0 | } |
4456 | 0 | } |
4457 | | |
4458 | | static void |
4459 | | convert_YUY2_I420_task (FConvertTask * task) |
4460 | 16 | { |
4461 | 16 | gint i; |
4462 | 16 | gint l1, l2; |
4463 | | |
4464 | 633 | for (i = task->height_0; i < task->height_1; i += 2) { |
4465 | 617 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
4466 | | |
4467 | 617 | video_orc_convert_YUY2_I420 (FRAME_GET_Y_LINE (task->dest, l1), |
4468 | 617 | FRAME_GET_Y_LINE (task->dest, l2), |
4469 | 617 | FRAME_GET_U_LINE (task->dest, i >> 1), |
4470 | 617 | FRAME_GET_V_LINE (task->dest, i >> 1), |
4471 | 617 | FRAME_GET_LINE (task->src, l1), FRAME_GET_LINE (task->src, l2), |
4472 | 617 | (task->width + 1) / 2); |
4473 | 617 | } |
4474 | 16 | } |
4475 | | |
4476 | | static void |
4477 | | convert_YUY2_I420 (GstVideoConverter * convert, const GstVideoFrame * src, |
4478 | | GstVideoFrame * dest) |
4479 | 16 | { |
4480 | 16 | int i; |
4481 | 16 | gint width = convert->in_width; |
4482 | 16 | gint height = convert->in_height; |
4483 | 16 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
4484 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
4485 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
4486 | 16 | gint h2; |
4487 | 16 | FConvertTask *tasks; |
4488 | 16 | FConvertTask **tasks_p; |
4489 | 16 | gint n_threads; |
4490 | 16 | gint lines_per_thread; |
4491 | | |
4492 | | /* I420 has half as many chroma lines, as such we have to |
4493 | | * always merge two into one. For non-interlaced these are |
4494 | | * the two next to each other, for interlaced one is skipped |
4495 | | * in between. */ |
4496 | 16 | if (interlaced) |
4497 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
4498 | 16 | else |
4499 | 16 | h2 = GST_ROUND_DOWN_2 (height); |
4500 | | |
4501 | 16 | n_threads = convert->conversion_runner->n_threads; |
4502 | 16 | tasks = convert->tasks[0] = |
4503 | 16 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
4504 | 16 | tasks_p = convert->tasks_p[0] = |
4505 | 16 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
4506 | | |
4507 | 16 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
4508 | | |
4509 | 32 | for (i = 0; i < n_threads; i++) { |
4510 | 16 | tasks[i].src = src; |
4511 | 16 | tasks[i].dest = dest; |
4512 | | |
4513 | 16 | tasks[i].interlaced = interlaced; |
4514 | 16 | tasks[i].width = width; |
4515 | | |
4516 | 16 | tasks[i].height_0 = i * lines_per_thread; |
4517 | 16 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
4518 | 16 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
4519 | | |
4520 | 16 | tasks_p[i] = &tasks[i]; |
4521 | 16 | } |
4522 | | |
4523 | 16 | gst_parallelized_task_runner_run (convert->conversion_runner, |
4524 | 16 | (GstParallelizedTaskFunc) convert_YUY2_I420_task, (gpointer) tasks_p); |
4525 | | |
4526 | | /* now handle last lines. For interlaced these are up to 3 */ |
4527 | 16 | if (h2 != height) { |
4528 | 20 | for (i = h2; i < height; i++) { |
4529 | 10 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
4530 | 10 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
4531 | 10 | } |
4532 | 10 | } |
4533 | 16 | } |
4534 | | |
4535 | | static void |
4536 | | convert_v210_I420_task (FConvertTask * task) |
4537 | 0 | { |
4538 | 0 | gint i, j; |
4539 | 0 | gint l1, l2; |
4540 | 0 | guint8 *d_y1, *d_y2, *d_u, *d_v; |
4541 | 0 | const guint8 *s1, *s2; |
4542 | 0 | guint32 a0, a1, a2, a3; |
4543 | 0 | guint16 y0_1, y1_1, y2_1, y3_1, y4_1, y5_1; |
4544 | 0 | guint16 u0_1, u2_1, u4_1; |
4545 | 0 | guint16 v0_1, v2_1, v4_1; |
4546 | 0 | guint16 y0_2, y1_2, y2_2, y3_2, y4_2, y5_2; |
4547 | 0 | guint16 u0_2, u2_2, u4_2; |
4548 | 0 | guint16 v0_2, v2_2, v4_2; |
4549 | |
|
4550 | 0 | for (i = task->height_0; i < task->height_1; i += 2) { |
4551 | 0 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
4552 | |
|
4553 | 0 | d_y1 = FRAME_GET_Y_LINE (task->dest, l1); |
4554 | 0 | d_y2 = FRAME_GET_Y_LINE (task->dest, l2); |
4555 | 0 | d_u = FRAME_GET_U_LINE (task->dest, i >> 1); |
4556 | 0 | d_v = FRAME_GET_V_LINE (task->dest, i >> 1); |
4557 | |
|
4558 | 0 | s1 = FRAME_GET_LINE (task->src, l1); |
4559 | 0 | s2 = FRAME_GET_LINE (task->src, l2); |
4560 | |
|
4561 | 0 | for (j = 0; j < task->width; j += 6) { |
4562 | 0 | a0 = GST_READ_UINT32_LE (s1 + (j / 6) * 16 + 0); |
4563 | 0 | a1 = GST_READ_UINT32_LE (s1 + (j / 6) * 16 + 4); |
4564 | 0 | a2 = GST_READ_UINT32_LE (s1 + (j / 6) * 16 + 8); |
4565 | 0 | a3 = GST_READ_UINT32_LE (s1 + (j / 6) * 16 + 12); |
4566 | |
|
4567 | 0 | u0_1 = ((a0 >> 0) & 0x3ff) >> 2; |
4568 | 0 | y0_1 = ((a0 >> 10) & 0x3ff) >> 2; |
4569 | 0 | v0_1 = ((a0 >> 20) & 0x3ff) >> 2; |
4570 | 0 | y1_1 = ((a1 >> 0) & 0x3ff) >> 2; |
4571 | |
|
4572 | 0 | u2_1 = ((a1 >> 10) & 0x3ff) >> 2; |
4573 | 0 | y2_1 = ((a1 >> 20) & 0x3ff) >> 2; |
4574 | 0 | v2_1 = ((a2 >> 0) & 0x3ff) >> 2; |
4575 | 0 | y3_1 = ((a2 >> 10) & 0x3ff) >> 2; |
4576 | |
|
4577 | 0 | u4_1 = ((a2 >> 20) & 0x3ff) >> 2; |
4578 | 0 | y4_1 = ((a3 >> 0) & 0x3ff) >> 2; |
4579 | 0 | v4_1 = ((a3 >> 10) & 0x3ff) >> 2; |
4580 | 0 | y5_1 = ((a3 >> 20) & 0x3ff) >> 2; |
4581 | |
|
4582 | 0 | a0 = GST_READ_UINT32_LE (s2 + (j / 6) * 16 + 0); |
4583 | 0 | a1 = GST_READ_UINT32_LE (s2 + (j / 6) * 16 + 4); |
4584 | 0 | a2 = GST_READ_UINT32_LE (s2 + (j / 6) * 16 + 8); |
4585 | 0 | a3 = GST_READ_UINT32_LE (s2 + (j / 6) * 16 + 12); |
4586 | |
|
4587 | 0 | u0_2 = ((a0 >> 0) & 0x3ff) >> 2; |
4588 | 0 | y0_2 = ((a0 >> 10) & 0x3ff) >> 2; |
4589 | 0 | v0_2 = ((a0 >> 20) & 0x3ff) >> 2; |
4590 | 0 | y1_2 = ((a1 >> 0) & 0x3ff) >> 2; |
4591 | |
|
4592 | 0 | u2_2 = ((a1 >> 10) & 0x3ff) >> 2; |
4593 | 0 | y2_2 = ((a1 >> 20) & 0x3ff) >> 2; |
4594 | 0 | v2_2 = ((a2 >> 0) & 0x3ff) >> 2; |
4595 | 0 | y3_2 = ((a2 >> 10) & 0x3ff) >> 2; |
4596 | |
|
4597 | 0 | u4_2 = ((a2 >> 20) & 0x3ff) >> 2; |
4598 | 0 | y4_2 = ((a3 >> 0) & 0x3ff) >> 2; |
4599 | 0 | v4_2 = ((a3 >> 10) & 0x3ff) >> 2; |
4600 | 0 | y5_2 = ((a3 >> 20) & 0x3ff) >> 2; |
4601 | |
|
4602 | 0 | d_y1[j] = y0_1; |
4603 | 0 | d_y2[j] = y0_2; |
4604 | 0 | d_u[j / 2] = (u0_1 + u0_2) / 2; |
4605 | 0 | d_v[j / 2] = (v0_1 + v0_2) / 2; |
4606 | |
|
4607 | 0 | if (j < task->width - 1) { |
4608 | 0 | d_y1[j + 1] = y1_1; |
4609 | 0 | d_y2[j + 1] = y1_2; |
4610 | 0 | } |
4611 | |
|
4612 | 0 | if (j < task->width - 2) { |
4613 | 0 | d_y1[j + 2] = y2_1; |
4614 | 0 | d_y2[j + 2] = y2_2; |
4615 | 0 | d_u[j / 2 + 1] = (u2_1 + u2_2) / 2; |
4616 | 0 | d_v[j / 2 + 1] = (v2_1 + v2_2) / 2; |
4617 | 0 | } |
4618 | |
|
4619 | 0 | if (j < task->width - 3) { |
4620 | 0 | d_y1[j + 3] = y3_1; |
4621 | 0 | d_y2[j + 3] = y3_2; |
4622 | 0 | } |
4623 | |
|
4624 | 0 | if (j < task->width - 4) { |
4625 | 0 | d_y1[j + 4] = y4_1; |
4626 | 0 | d_y2[j + 4] = y4_2; |
4627 | 0 | d_u[j / 2 + 2] = (u4_1 + u4_2) / 2; |
4628 | 0 | d_v[j / 2 + 2] = (v4_1 + v4_2) / 2; |
4629 | 0 | } |
4630 | |
|
4631 | 0 | if (j < task->width - 5) { |
4632 | 0 | d_y1[j + 5] = y5_1; |
4633 | 0 | d_y2[j + 5] = y5_2; |
4634 | 0 | } |
4635 | 0 | } |
4636 | 0 | } |
4637 | 0 | } |
4638 | | |
4639 | | static void |
4640 | | convert_v210_I420 (GstVideoConverter * convert, const GstVideoFrame * src, |
4641 | | GstVideoFrame * dest) |
4642 | 0 | { |
4643 | 0 | int i; |
4644 | 0 | gint width = convert->in_width; |
4645 | 0 | gint height = convert->in_height; |
4646 | 0 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
4647 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
4648 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
4649 | 0 | gint h2; |
4650 | 0 | FConvertTask *tasks; |
4651 | 0 | FConvertTask **tasks_p; |
4652 | 0 | gint n_threads; |
4653 | 0 | gint lines_per_thread; |
4654 | 0 | guint8 *tmpline_8; |
4655 | | |
4656 | | /* I420 has half as many chroma lines, as such we have to |
4657 | | * always merge two into one. For non-interlaced these are |
4658 | | * the two next to each other, for interlaced one is skipped |
4659 | | * in between. */ |
4660 | 0 | if (interlaced) |
4661 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
4662 | 0 | else |
4663 | 0 | h2 = GST_ROUND_DOWN_2 (height); |
4664 | |
|
4665 | 0 | n_threads = convert->conversion_runner->n_threads; |
4666 | 0 | tasks = convert->tasks[0] = |
4667 | 0 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
4668 | 0 | tasks_p = convert->tasks_p[0] = |
4669 | 0 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
4670 | |
|
4671 | 0 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
4672 | |
|
4673 | 0 | for (i = 0; i < n_threads; i++) { |
4674 | 0 | tasks[i].src = src; |
4675 | 0 | tasks[i].dest = dest; |
4676 | |
|
4677 | 0 | tasks[i].interlaced = interlaced; |
4678 | 0 | tasks[i].width = width; |
4679 | |
|
4680 | 0 | tasks[i].height_0 = i * lines_per_thread; |
4681 | 0 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
4682 | 0 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
4683 | |
|
4684 | 0 | tasks_p[i] = &tasks[i]; |
4685 | 0 | } |
4686 | |
|
4687 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
4688 | 0 | (GstParallelizedTaskFunc) convert_v210_I420_task, (gpointer) tasks_p); |
4689 | | |
4690 | | /* now handle last lines. For interlaced these are up to 3 */ |
4691 | 0 | if (h2 != height) { |
4692 | 0 | for (i = h2; i < height; i++) { |
4693 | 0 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
4694 | |
|
4695 | 0 | tmpline_8 = (guint8 *) convert->tmpline[0]; |
4696 | 0 | for (int j = 0; j < width * 4; j++) { |
4697 | 0 | tmpline_8[j] = convert->tmpline[0][j] >> 8; |
4698 | 0 | } |
4699 | |
|
4700 | 0 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
4701 | 0 | } |
4702 | 0 | } |
4703 | 0 | } |
4704 | | |
4705 | | static void |
4706 | | convert_v210_I420_10_task (FConvertTask * task) |
4707 | 0 | { |
4708 | 0 | gint i, j; |
4709 | 0 | gint l1, l2; |
4710 | 0 | guint16 *d_y1, *d_y2, *d_u, *d_v; |
4711 | 0 | const guint8 *s1, *s2; |
4712 | 0 | guint32 a0, a1, a2, a3; |
4713 | 0 | guint16 y0_1, y1_1, y2_1, y3_1, y4_1, y5_1; |
4714 | 0 | guint16 u0_1, u2_1, u4_1; |
4715 | 0 | guint16 v0_1, v2_1, v4_1; |
4716 | 0 | guint16 y0_2, y1_2, y2_2, y3_2, y4_2, y5_2; |
4717 | 0 | guint16 u0_2, u2_2, u4_2; |
4718 | 0 | guint16 v0_2, v2_2, v4_2; |
4719 | |
|
4720 | 0 | for (i = task->height_0; i < task->height_1; i += 2) { |
4721 | 0 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
4722 | |
|
4723 | 0 | d_y1 = FRAME_GET_Y_LINE (task->dest, l1); |
4724 | 0 | d_y2 = FRAME_GET_Y_LINE (task->dest, l2); |
4725 | 0 | d_u = FRAME_GET_U_LINE (task->dest, i >> 1); |
4726 | 0 | d_v = FRAME_GET_V_LINE (task->dest, i >> 1); |
4727 | |
|
4728 | 0 | s1 = FRAME_GET_LINE (task->src, l1); |
4729 | 0 | s2 = FRAME_GET_LINE (task->src, l2); |
4730 | |
|
4731 | 0 | for (j = 0; j < task->width; j += 6) { |
4732 | 0 | a0 = GST_READ_UINT32_LE (s1 + (j / 6) * 16 + 0); |
4733 | 0 | a1 = GST_READ_UINT32_LE (s1 + (j / 6) * 16 + 4); |
4734 | 0 | a2 = GST_READ_UINT32_LE (s1 + (j / 6) * 16 + 8); |
4735 | 0 | a3 = GST_READ_UINT32_LE (s1 + (j / 6) * 16 + 12); |
4736 | |
|
4737 | 0 | u0_1 = ((a0 >> 0) & 0x3ff); |
4738 | 0 | y0_1 = ((a0 >> 10) & 0x3ff); |
4739 | 0 | v0_1 = ((a0 >> 20) & 0x3ff); |
4740 | 0 | y1_1 = ((a1 >> 0) & 0x3ff); |
4741 | |
|
4742 | 0 | u2_1 = ((a1 >> 10) & 0x3ff); |
4743 | 0 | y2_1 = ((a1 >> 20) & 0x3ff); |
4744 | 0 | v2_1 = ((a2 >> 0) & 0x3ff); |
4745 | 0 | y3_1 = ((a2 >> 10) & 0x3ff); |
4746 | |
|
4747 | 0 | u4_1 = ((a2 >> 20) & 0x3ff); |
4748 | 0 | y4_1 = ((a3 >> 0) & 0x3ff); |
4749 | 0 | v4_1 = ((a3 >> 10) & 0x3ff); |
4750 | 0 | y5_1 = ((a3 >> 20) & 0x3ff); |
4751 | |
|
4752 | 0 | a0 = GST_READ_UINT32_LE (s2 + (j / 6) * 16 + 0); |
4753 | 0 | a1 = GST_READ_UINT32_LE (s2 + (j / 6) * 16 + 4); |
4754 | 0 | a2 = GST_READ_UINT32_LE (s2 + (j / 6) * 16 + 8); |
4755 | 0 | a3 = GST_READ_UINT32_LE (s2 + (j / 6) * 16 + 12); |
4756 | |
|
4757 | 0 | u0_2 = ((a0 >> 0) & 0x3ff); |
4758 | 0 | y0_2 = ((a0 >> 10) & 0x3ff); |
4759 | 0 | v0_2 = ((a0 >> 20) & 0x3ff); |
4760 | 0 | y1_2 = ((a1 >> 0) & 0x3ff); |
4761 | |
|
4762 | 0 | u2_2 = ((a1 >> 10) & 0x3ff); |
4763 | 0 | y2_2 = ((a1 >> 20) & 0x3ff); |
4764 | 0 | v2_2 = ((a2 >> 0) & 0x3ff); |
4765 | 0 | y3_2 = ((a2 >> 10) & 0x3ff); |
4766 | |
|
4767 | 0 | u4_2 = ((a2 >> 20) & 0x3ff); |
4768 | 0 | y4_2 = ((a3 >> 0) & 0x3ff); |
4769 | 0 | v4_2 = ((a3 >> 10) & 0x3ff); |
4770 | 0 | y5_2 = ((a3 >> 20) & 0x3ff); |
4771 | |
|
4772 | 0 | d_y1[j] = y0_1; |
4773 | 0 | d_y2[j] = y0_2; |
4774 | 0 | d_u[j / 2] = (u0_1 + u0_2) / 2; |
4775 | 0 | d_v[j / 2] = (v0_1 + v0_2) / 2; |
4776 | |
|
4777 | 0 | if (j < task->width - 1) { |
4778 | 0 | d_y1[j + 1] = y1_1; |
4779 | 0 | d_y2[j + 1] = y1_2; |
4780 | 0 | } |
4781 | |
|
4782 | 0 | if (j < task->width - 2) { |
4783 | 0 | d_y1[j + 2] = y2_1; |
4784 | 0 | d_y2[j + 2] = y2_2; |
4785 | 0 | d_u[j / 2 + 1] = (u2_1 + u2_2) / 2; |
4786 | 0 | d_v[j / 2 + 1] = (v2_1 + v2_2) / 2; |
4787 | 0 | } |
4788 | |
|
4789 | 0 | if (j < task->width - 3) { |
4790 | 0 | d_y1[j + 3] = y3_1; |
4791 | 0 | d_y2[j + 3] = y3_2; |
4792 | 0 | } |
4793 | |
|
4794 | 0 | if (j < task->width - 4) { |
4795 | 0 | d_y1[j + 4] = y4_1; |
4796 | 0 | d_y2[j + 4] = y4_2; |
4797 | 0 | d_u[j / 2 + 2] = (u4_1 + u4_2) / 2; |
4798 | 0 | d_v[j / 2 + 2] = (v4_1 + v4_2) / 2; |
4799 | 0 | } |
4800 | |
|
4801 | 0 | if (j < task->width - 5) { |
4802 | 0 | d_y1[j + 5] = y5_1; |
4803 | 0 | d_y2[j + 5] = y5_2; |
4804 | 0 | } |
4805 | 0 | } |
4806 | 0 | } |
4807 | 0 | } |
4808 | | |
4809 | | static void |
4810 | | convert_v210_I420_10 (GstVideoConverter * convert, const GstVideoFrame * src, |
4811 | | GstVideoFrame * dest) |
4812 | 0 | { |
4813 | 0 | int i; |
4814 | 0 | gint width = convert->in_width; |
4815 | 0 | gint height = convert->in_height; |
4816 | 0 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
4817 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
4818 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
4819 | 0 | gint h2; |
4820 | 0 | FConvertTask *tasks; |
4821 | 0 | FConvertTask **tasks_p; |
4822 | 0 | gint n_threads; |
4823 | 0 | gint lines_per_thread; |
4824 | | |
4825 | | /* I420 has half as many chroma lines, as such we have to |
4826 | | * always merge two into one. For non-interlaced these are |
4827 | | * the two next to each other, for interlaced one is skipped |
4828 | | * in between. */ |
4829 | 0 | if (interlaced) |
4830 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
4831 | 0 | else |
4832 | 0 | h2 = GST_ROUND_DOWN_2 (height); |
4833 | |
|
4834 | 0 | n_threads = convert->conversion_runner->n_threads; |
4835 | 0 | tasks = convert->tasks[0] = |
4836 | 0 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
4837 | 0 | tasks_p = convert->tasks_p[0] = |
4838 | 0 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
4839 | |
|
4840 | 0 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
4841 | |
|
4842 | 0 | for (i = 0; i < n_threads; i++) { |
4843 | 0 | tasks[i].src = src; |
4844 | 0 | tasks[i].dest = dest; |
4845 | |
|
4846 | 0 | tasks[i].interlaced = interlaced; |
4847 | 0 | tasks[i].width = width; |
4848 | |
|
4849 | 0 | tasks[i].height_0 = i * lines_per_thread; |
4850 | 0 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
4851 | 0 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
4852 | |
|
4853 | 0 | tasks_p[i] = &tasks[i]; |
4854 | 0 | } |
4855 | |
|
4856 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
4857 | 0 | (GstParallelizedTaskFunc) convert_v210_I420_10_task, (gpointer) tasks_p); |
4858 | | |
4859 | | /* now handle last lines. For interlaced these are up to 3 */ |
4860 | 0 | if (h2 != height) { |
4861 | 0 | for (i = h2; i < height; i++) { |
4862 | 0 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
4863 | 0 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
4864 | 0 | } |
4865 | 0 | } |
4866 | 0 | } |
4867 | | |
4868 | | |
4869 | | typedef struct |
4870 | | { |
4871 | | const guint8 *s, *s2, *su, *sv; |
4872 | | guint8 *d, *d2, *du, *dv; |
4873 | | gint sstride, sustride, svstride; |
4874 | | gint dstride, dustride, dvstride; |
4875 | | gint width, height; |
4876 | | gint alpha; |
4877 | | MatrixData *data; |
4878 | | } FConvertPlaneTask; |
4879 | | |
4880 | | static void |
4881 | | convert_YUY2_AYUV_task (FConvertPlaneTask * task) |
4882 | 11 | { |
4883 | 11 | video_orc_convert_YUY2_AYUV (task->d, task->dstride, task->s, |
4884 | 11 | task->sstride, task->alpha, (task->width + 1) / 2, task->height); |
4885 | 11 | } |
4886 | | |
4887 | | static void |
4888 | | convert_YUY2_AYUV (GstVideoConverter * convert, const GstVideoFrame * src, |
4889 | | GstVideoFrame * dest) |
4890 | 11 | { |
4891 | 11 | gint width = convert->in_width; |
4892 | 11 | gint height = convert->in_height; |
4893 | 11 | guint8 *s, *d; |
4894 | 11 | guint8 alpha = MIN (convert->alpha_value, 255); |
4895 | 11 | FConvertPlaneTask *tasks; |
4896 | 11 | FConvertPlaneTask **tasks_p; |
4897 | 11 | gint n_threads; |
4898 | 11 | gint lines_per_thread; |
4899 | 11 | gint i; |
4900 | | |
4901 | 11 | s = FRAME_GET_LINE (src, convert->in_y); |
4902 | 11 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
4903 | 11 | d = FRAME_GET_LINE (dest, convert->out_y); |
4904 | 11 | d += (convert->out_x * 4); |
4905 | | |
4906 | 11 | n_threads = convert->conversion_runner->n_threads; |
4907 | 11 | tasks = convert->tasks[0] = |
4908 | 11 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
4909 | 11 | tasks_p = convert->tasks_p[0] = |
4910 | 11 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
4911 | | |
4912 | 11 | lines_per_thread = (height + n_threads - 1) / n_threads; |
4913 | | |
4914 | 22 | for (i = 0; i < n_threads; i++) { |
4915 | 11 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
4916 | 11 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
4917 | 11 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
4918 | 11 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
4919 | | |
4920 | 11 | tasks[i].width = width; |
4921 | 11 | tasks[i].height = (i + 1) * lines_per_thread; |
4922 | 11 | tasks[i].height = MIN (tasks[i].height, height); |
4923 | 11 | tasks[i].height -= i * lines_per_thread; |
4924 | 11 | tasks[i].alpha = alpha; |
4925 | | |
4926 | 11 | tasks_p[i] = &tasks[i]; |
4927 | 11 | } |
4928 | | |
4929 | 11 | gst_parallelized_task_runner_run (convert->conversion_runner, |
4930 | 11 | (GstParallelizedTaskFunc) convert_YUY2_AYUV_task, (gpointer) tasks_p); |
4931 | | |
4932 | 11 | convert_fill_border (convert, dest); |
4933 | 11 | } |
4934 | | |
4935 | | static void |
4936 | | convert_YUY2_v210_task (FConvertPlaneTask * task) |
4937 | 0 | { |
4938 | 0 | gint i, j; |
4939 | 0 | guint8 *d; |
4940 | 0 | const guint8 *s; |
4941 | 0 | guint32 a0, a1, a2, a3; |
4942 | 0 | guint8 y0, y1, y2, y3, y4, y5; |
4943 | 0 | guint8 u0, u2, u4; |
4944 | 0 | guint8 v0, v2, v4; |
4945 | |
|
4946 | 0 | for (i = 0; i < task->height; i++) { |
4947 | 0 | d = task->d + i * task->dstride; |
4948 | 0 | s = task->s + i * task->sstride; |
4949 | |
|
4950 | 0 | for (j = 0; j < task->width; j += 6) { |
4951 | 0 | y1 = y2 = y3 = y4 = y5 = 0; |
4952 | 0 | u2 = u4 = v2 = v4 = 0; |
4953 | |
|
4954 | 0 | y0 = s[2 * j]; |
4955 | 0 | u0 = s[2 * j + 1]; |
4956 | 0 | v0 = s[2 * j + 3]; |
4957 | |
|
4958 | 0 | if (j < task->width - 1) { |
4959 | 0 | y1 = s[2 * j + 2]; |
4960 | 0 | } |
4961 | |
|
4962 | 0 | if (j < task->width - 2) { |
4963 | 0 | y2 = s[2 * j + 4]; |
4964 | 0 | u2 = s[2 * j + 5]; |
4965 | 0 | v2 = s[2 * j + 7]; |
4966 | 0 | } |
4967 | |
|
4968 | 0 | if (j < task->width - 3) { |
4969 | 0 | y3 = s[2 * j + 6]; |
4970 | 0 | } |
4971 | |
|
4972 | 0 | if (j < task->width - 4) { |
4973 | 0 | y4 = s[2 * j + 8]; |
4974 | 0 | u4 = s[2 * j + 9]; |
4975 | 0 | v4 = s[2 * j + 11]; |
4976 | 0 | } |
4977 | |
|
4978 | 0 | if (j < task->width - 5) { |
4979 | 0 | y5 = s[2 * j + 10]; |
4980 | 0 | } |
4981 | |
|
4982 | 0 | a0 = u0 << 2 | (y0 << 12) | (v0 << 22); |
4983 | 0 | a1 = y1 << 2 | (u2 << 12) | (y2 << 22); |
4984 | 0 | a2 = v2 << 2 | (y3 << 12) | (u4 << 22); |
4985 | 0 | a3 = y4 << 2 | (v4 << 12) | (y5 << 22); |
4986 | |
|
4987 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 0, a0); |
4988 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 4, a1); |
4989 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 8, a2); |
4990 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 12, a3); |
4991 | 0 | } |
4992 | 0 | } |
4993 | 0 | } |
4994 | | |
4995 | | static void |
4996 | | convert_YUY2_v210 (GstVideoConverter * convert, const GstVideoFrame * src, |
4997 | | GstVideoFrame * dest) |
4998 | 0 | { |
4999 | 0 | gint width = convert->in_width; |
5000 | 0 | gint height = convert->in_height; |
5001 | 0 | guint8 *s, *d; |
5002 | 0 | FConvertPlaneTask *tasks; |
5003 | 0 | FConvertPlaneTask **tasks_p; |
5004 | 0 | gint n_threads; |
5005 | 0 | gint lines_per_thread; |
5006 | 0 | gint i; |
5007 | |
|
5008 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5009 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5010 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
5011 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
5012 | |
|
5013 | 0 | n_threads = convert->conversion_runner->n_threads; |
5014 | 0 | tasks = convert->tasks[0] = |
5015 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5016 | 0 | tasks_p = convert->tasks_p[0] = |
5017 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5018 | |
|
5019 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5020 | |
|
5021 | 0 | for (i = 0; i < n_threads; i++) { |
5022 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
5023 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5024 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
5025 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5026 | |
|
5027 | 0 | tasks[i].width = width; |
5028 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5029 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5030 | 0 | tasks[i].height -= i * lines_per_thread; |
5031 | |
|
5032 | 0 | tasks_p[i] = &tasks[i]; |
5033 | 0 | } |
5034 | |
|
5035 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5036 | 0 | (GstParallelizedTaskFunc) convert_YUY2_v210_task, (gpointer) tasks_p); |
5037 | |
|
5038 | 0 | convert_fill_border (convert, dest); |
5039 | 0 | } |
5040 | | |
5041 | | static void |
5042 | | convert_YUY2_Y42B_task (FConvertPlaneTask * task) |
5043 | 0 | { |
5044 | 0 | video_orc_convert_YUY2_Y42B (task->d, task->dstride, task->du, |
5045 | 0 | task->dustride, task->dv, task->dvstride, |
5046 | 0 | task->s, task->sstride, (task->width + 1) / 2, task->height); |
5047 | 0 | } |
5048 | | |
5049 | | static void |
5050 | | convert_YUY2_Y42B (GstVideoConverter * convert, const GstVideoFrame * src, |
5051 | | GstVideoFrame * dest) |
5052 | 0 | { |
5053 | 0 | gint width = convert->in_width; |
5054 | 0 | gint height = convert->in_height; |
5055 | 0 | guint8 *s, *dy, *du, *dv; |
5056 | 0 | FConvertPlaneTask *tasks; |
5057 | 0 | FConvertPlaneTask **tasks_p; |
5058 | 0 | gint n_threads; |
5059 | 0 | gint lines_per_thread; |
5060 | 0 | gint i; |
5061 | |
|
5062 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5063 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5064 | |
|
5065 | 0 | dy = FRAME_GET_Y_LINE (dest, convert->out_y); |
5066 | 0 | dy += convert->out_x; |
5067 | 0 | du = FRAME_GET_U_LINE (dest, convert->out_y); |
5068 | 0 | du += convert->out_x >> 1; |
5069 | 0 | dv = FRAME_GET_V_LINE (dest, convert->out_y); |
5070 | 0 | dv += convert->out_x >> 1; |
5071 | |
|
5072 | 0 | n_threads = convert->conversion_runner->n_threads; |
5073 | 0 | tasks = convert->tasks[0] = |
5074 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5075 | 0 | tasks_p = convert->tasks_p[0] = |
5076 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5077 | |
|
5078 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5079 | |
|
5080 | 0 | for (i = 0; i < n_threads; i++) { |
5081 | 0 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
5082 | 0 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
5083 | 0 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
5084 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5085 | 0 | tasks[i].d = dy + i * lines_per_thread * tasks[i].dstride; |
5086 | 0 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride; |
5087 | 0 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride; |
5088 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5089 | |
|
5090 | 0 | tasks[i].width = width; |
5091 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5092 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5093 | 0 | tasks[i].height -= i * lines_per_thread; |
5094 | |
|
5095 | 0 | tasks_p[i] = &tasks[i]; |
5096 | 0 | } |
5097 | |
|
5098 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5099 | 0 | (GstParallelizedTaskFunc) convert_YUY2_Y42B_task, (gpointer) tasks_p); |
5100 | |
|
5101 | 0 | convert_fill_border (convert, dest); |
5102 | 0 | } |
5103 | | |
5104 | | static void |
5105 | | convert_YUY2_Y444_task (FConvertPlaneTask * task) |
5106 | 0 | { |
5107 | 0 | video_orc_convert_YUY2_Y444 (task->d, |
5108 | 0 | task->dstride, task->du, |
5109 | 0 | task->dustride, task->dv, |
5110 | 0 | task->dvstride, task->s, |
5111 | 0 | task->sstride, (task->width + 1) / 2, task->height); |
5112 | 0 | } |
5113 | | |
5114 | | static void |
5115 | | convert_YUY2_Y444 (GstVideoConverter * convert, const GstVideoFrame * src, |
5116 | | GstVideoFrame * dest) |
5117 | 0 | { |
5118 | 0 | gint width = convert->in_width; |
5119 | 0 | gint height = convert->in_height; |
5120 | 0 | guint8 *s, *dy, *du, *dv; |
5121 | 0 | FConvertPlaneTask *tasks; |
5122 | 0 | FConvertPlaneTask **tasks_p; |
5123 | 0 | gint n_threads; |
5124 | 0 | gint lines_per_thread; |
5125 | 0 | gint i; |
5126 | |
|
5127 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5128 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5129 | |
|
5130 | 0 | dy = FRAME_GET_Y_LINE (dest, convert->out_y); |
5131 | 0 | dy += convert->out_x; |
5132 | 0 | du = FRAME_GET_U_LINE (dest, convert->out_y); |
5133 | 0 | du += convert->out_x; |
5134 | 0 | dv = FRAME_GET_V_LINE (dest, convert->out_y); |
5135 | 0 | dv += convert->out_x; |
5136 | |
|
5137 | 0 | n_threads = convert->conversion_runner->n_threads; |
5138 | 0 | tasks = convert->tasks[0] = |
5139 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5140 | 0 | tasks_p = convert->tasks_p[0] = |
5141 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5142 | |
|
5143 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5144 | |
|
5145 | 0 | for (i = 0; i < n_threads; i++) { |
5146 | 0 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
5147 | 0 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
5148 | 0 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
5149 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5150 | 0 | tasks[i].d = dy + i * lines_per_thread * tasks[i].dstride; |
5151 | 0 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride; |
5152 | 0 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride; |
5153 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5154 | |
|
5155 | 0 | tasks[i].width = width; |
5156 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5157 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5158 | 0 | tasks[i].height -= i * lines_per_thread; |
5159 | |
|
5160 | 0 | tasks_p[i] = &tasks[i]; |
5161 | 0 | } |
5162 | |
|
5163 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5164 | 0 | (GstParallelizedTaskFunc) convert_YUY2_Y444_task, (gpointer) tasks_p); |
5165 | |
|
5166 | 0 | convert_fill_border (convert, dest); |
5167 | 0 | } |
5168 | | |
5169 | | static void |
5170 | | convert_v210_Y42B_task (FConvertPlaneTask * task) |
5171 | 0 | { |
5172 | 0 | gint i, j; |
5173 | 0 | guint8 *d_y, *d_u, *d_v; |
5174 | 0 | const guint8 *s; |
5175 | 0 | guint32 a0, a1, a2, a3; |
5176 | 0 | guint16 y0, y1, y2, y3, y4, y5; |
5177 | 0 | guint16 u0, u2, u4; |
5178 | 0 | guint16 v0, v2, v4; |
5179 | |
|
5180 | 0 | for (i = 0; i < task->height; i++) { |
5181 | 0 | d_y = task->d + i * task->dstride; |
5182 | 0 | d_u = task->du + i * task->dustride; |
5183 | 0 | d_v = task->dv + i * task->dvstride; |
5184 | 0 | s = task->s + i * task->sstride; |
5185 | |
|
5186 | 0 | for (j = 0; j < task->width; j += 6) { |
5187 | 0 | a0 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 0); |
5188 | 0 | a1 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 4); |
5189 | 0 | a2 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 8); |
5190 | 0 | a3 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 12); |
5191 | |
|
5192 | 0 | u0 = ((a0 >> 0) & 0x3ff) >> 2; |
5193 | 0 | y0 = ((a0 >> 10) & 0x3ff) >> 2; |
5194 | 0 | v0 = ((a0 >> 20) & 0x3ff) >> 2; |
5195 | 0 | y1 = ((a1 >> 0) & 0x3ff) >> 2; |
5196 | |
|
5197 | 0 | u2 = ((a1 >> 10) & 0x3ff) >> 2; |
5198 | 0 | y2 = ((a1 >> 20) & 0x3ff) >> 2; |
5199 | 0 | v2 = ((a2 >> 0) & 0x3ff) >> 2; |
5200 | 0 | y3 = ((a2 >> 10) & 0x3ff) >> 2; |
5201 | |
|
5202 | 0 | u4 = ((a2 >> 20) & 0x3ff) >> 2; |
5203 | 0 | y4 = ((a3 >> 0) & 0x3ff) >> 2; |
5204 | 0 | v4 = ((a3 >> 10) & 0x3ff) >> 2; |
5205 | 0 | y5 = ((a3 >> 20) & 0x3ff) >> 2; |
5206 | |
|
5207 | 0 | d_y[j] = y0; |
5208 | 0 | d_u[j / 2] = u0; |
5209 | 0 | d_v[j / 2] = v0; |
5210 | |
|
5211 | 0 | if (j < task->width - 1) { |
5212 | 0 | d_y[j + 1] = y1; |
5213 | 0 | } |
5214 | |
|
5215 | 0 | if (j < task->width - 2) { |
5216 | 0 | d_y[j + 2] = y2; |
5217 | 0 | d_u[j / 2 + 1] = u2; |
5218 | 0 | d_v[j / 2 + 1] = v2; |
5219 | 0 | } |
5220 | |
|
5221 | 0 | if (j < task->width - 3) { |
5222 | 0 | d_y[j + 3] = y3; |
5223 | 0 | } |
5224 | |
|
5225 | 0 | if (j < task->width - 4) { |
5226 | 0 | d_y[j + 4] = y4; |
5227 | 0 | d_u[j / 2 + 2] = u4; |
5228 | 0 | d_v[j / 2 + 2] = v4; |
5229 | 0 | } |
5230 | |
|
5231 | 0 | if (j < task->width - 5) { |
5232 | 0 | d_y[j + 5] = y5; |
5233 | 0 | } |
5234 | 0 | } |
5235 | 0 | } |
5236 | 0 | } |
5237 | | |
5238 | | static void |
5239 | | convert_v210_Y42B (GstVideoConverter * convert, const GstVideoFrame * src, |
5240 | | GstVideoFrame * dest) |
5241 | 0 | { |
5242 | 0 | gint width = convert->in_width; |
5243 | 0 | gint height = convert->in_height; |
5244 | 0 | guint8 *s, *dy, *du, *dv; |
5245 | 0 | FConvertPlaneTask *tasks; |
5246 | 0 | FConvertPlaneTask **tasks_p; |
5247 | 0 | gint n_threads; |
5248 | 0 | gint lines_per_thread; |
5249 | 0 | gint i; |
5250 | |
|
5251 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5252 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5253 | |
|
5254 | 0 | dy = FRAME_GET_Y_LINE (dest, convert->out_y); |
5255 | 0 | dy += convert->out_x; |
5256 | 0 | du = FRAME_GET_U_LINE (dest, convert->out_y); |
5257 | 0 | du += convert->out_x >> 1; |
5258 | 0 | dv = FRAME_GET_V_LINE (dest, convert->out_y); |
5259 | 0 | dv += convert->out_x >> 1; |
5260 | |
|
5261 | 0 | n_threads = convert->conversion_runner->n_threads; |
5262 | 0 | tasks = convert->tasks[0] = |
5263 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5264 | 0 | tasks_p = convert->tasks_p[0] = |
5265 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5266 | |
|
5267 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5268 | |
|
5269 | 0 | for (i = 0; i < n_threads; i++) { |
5270 | 0 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
5271 | 0 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
5272 | 0 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
5273 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5274 | 0 | tasks[i].d = dy + i * lines_per_thread * tasks[i].dstride; |
5275 | 0 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride; |
5276 | 0 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride; |
5277 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5278 | |
|
5279 | 0 | tasks[i].width = width; |
5280 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5281 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5282 | 0 | tasks[i].height -= i * lines_per_thread; |
5283 | |
|
5284 | 0 | tasks_p[i] = &tasks[i]; |
5285 | 0 | } |
5286 | |
|
5287 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5288 | 0 | (GstParallelizedTaskFunc) convert_v210_Y42B_task, (gpointer) tasks_p); |
5289 | |
|
5290 | 0 | convert_fill_border (convert, dest); |
5291 | 0 | } |
5292 | | |
5293 | | static void |
5294 | | convert_v210_I422_10_task (FConvertPlaneTask * task) |
5295 | 0 | { |
5296 | 0 | gint i, j; |
5297 | 0 | guint16 *d_y, *d_u, *d_v; |
5298 | 0 | const guint8 *s; |
5299 | 0 | guint32 a0, a1, a2, a3; |
5300 | 0 | guint16 y0, y1, y2, y3, y4, y5; |
5301 | 0 | guint16 u0, u2, u4; |
5302 | 0 | guint16 v0, v2, v4; |
5303 | |
|
5304 | 0 | for (i = 0; i < task->height; i++) { |
5305 | 0 | d_y = (guint16 *) (task->d + i * task->dstride); |
5306 | 0 | d_u = (guint16 *) (task->du + i * task->dustride); |
5307 | 0 | d_v = (guint16 *) (task->dv + i * task->dvstride); |
5308 | 0 | s = task->s + i * task->sstride; |
5309 | |
|
5310 | 0 | for (j = 0; j < task->width; j += 6) { |
5311 | 0 | a0 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 0); |
5312 | 0 | a1 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 4); |
5313 | 0 | a2 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 8); |
5314 | 0 | a3 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 12); |
5315 | |
|
5316 | 0 | u0 = ((a0 >> 0) & 0x3ff); |
5317 | 0 | y0 = ((a0 >> 10) & 0x3ff); |
5318 | 0 | v0 = ((a0 >> 20) & 0x3ff); |
5319 | 0 | y1 = ((a1 >> 0) & 0x3ff); |
5320 | |
|
5321 | 0 | u2 = ((a1 >> 10) & 0x3ff); |
5322 | 0 | y2 = ((a1 >> 20) & 0x3ff); |
5323 | 0 | v2 = ((a2 >> 0) & 0x3ff); |
5324 | 0 | y3 = ((a2 >> 10) & 0x3ff); |
5325 | |
|
5326 | 0 | u4 = ((a2 >> 20) & 0x3ff); |
5327 | 0 | y4 = ((a3 >> 0) & 0x3ff); |
5328 | 0 | v4 = ((a3 >> 10) & 0x3ff); |
5329 | 0 | y5 = ((a3 >> 20) & 0x3ff); |
5330 | |
|
5331 | 0 | d_y[j] = y0; |
5332 | 0 | d_u[j / 2] = u0; |
5333 | 0 | d_v[j / 2] = v0; |
5334 | |
|
5335 | 0 | if (j < task->width - 1) { |
5336 | 0 | d_y[j + 1] = y1; |
5337 | 0 | } |
5338 | |
|
5339 | 0 | if (j < task->width - 2) { |
5340 | 0 | d_y[j + 2] = y2; |
5341 | 0 | d_u[j / 2 + 1] = u2; |
5342 | 0 | d_v[j / 2 + 1] = v2; |
5343 | 0 | } |
5344 | |
|
5345 | 0 | if (j < task->width - 3) { |
5346 | 0 | d_y[j + 3] = y3; |
5347 | 0 | } |
5348 | |
|
5349 | 0 | if (j < task->width - 4) { |
5350 | 0 | d_y[j + 4] = y4; |
5351 | 0 | d_u[j / 2 + 2] = u4; |
5352 | 0 | d_v[j / 2 + 2] = v4; |
5353 | 0 | } |
5354 | |
|
5355 | 0 | if (j < task->width - 5) { |
5356 | 0 | d_y[j + 5] = y5; |
5357 | 0 | } |
5358 | 0 | } |
5359 | 0 | } |
5360 | 0 | } |
5361 | | |
5362 | | static void |
5363 | | convert_v210_I422_10 (GstVideoConverter * convert, const GstVideoFrame * src, |
5364 | | GstVideoFrame * dest) |
5365 | 0 | { |
5366 | 0 | gint width = convert->in_width; |
5367 | 0 | gint height = convert->in_height; |
5368 | 0 | guint8 *s, *dy, *du, *dv; |
5369 | 0 | FConvertPlaneTask *tasks; |
5370 | 0 | FConvertPlaneTask **tasks_p; |
5371 | 0 | gint n_threads; |
5372 | 0 | gint lines_per_thread; |
5373 | 0 | gint i; |
5374 | |
|
5375 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5376 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5377 | |
|
5378 | 0 | dy = FRAME_GET_Y_LINE (dest, convert->out_y); |
5379 | 0 | dy += convert->out_x; |
5380 | 0 | du = FRAME_GET_U_LINE (dest, convert->out_y); |
5381 | 0 | du += convert->out_x >> 1; |
5382 | 0 | dv = FRAME_GET_V_LINE (dest, convert->out_y); |
5383 | 0 | dv += convert->out_x >> 1; |
5384 | |
|
5385 | 0 | n_threads = convert->conversion_runner->n_threads; |
5386 | 0 | tasks = convert->tasks[0] = |
5387 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5388 | 0 | tasks_p = convert->tasks_p[0] = |
5389 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5390 | |
|
5391 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5392 | |
|
5393 | 0 | for (i = 0; i < n_threads; i++) { |
5394 | 0 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
5395 | 0 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
5396 | 0 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
5397 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5398 | 0 | tasks[i].d = dy + i * lines_per_thread * tasks[i].dstride; |
5399 | 0 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride; |
5400 | 0 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride; |
5401 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5402 | |
|
5403 | 0 | tasks[i].width = width; |
5404 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5405 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5406 | 0 | tasks[i].height -= i * lines_per_thread; |
5407 | |
|
5408 | 0 | tasks_p[i] = &tasks[i]; |
5409 | 0 | } |
5410 | |
|
5411 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5412 | 0 | (GstParallelizedTaskFunc) convert_v210_I422_10_task, (gpointer) tasks_p); |
5413 | |
|
5414 | 0 | convert_fill_border (convert, dest); |
5415 | 0 | } |
5416 | | |
5417 | | static void |
5418 | | convert_UYVY_I420_task (FConvertTask * task) |
5419 | 14 | { |
5420 | 14 | gint i; |
5421 | 14 | gint l1, l2; |
5422 | | |
5423 | 437 | for (i = task->height_0; i < task->height_1; i += 2) { |
5424 | 423 | GET_LINE_OFFSETS (task->interlaced, i, l1, l2); |
5425 | | |
5426 | 423 | video_orc_convert_UYVY_I420 (FRAME_GET_COMP_LINE (task->dest, 0, l1), |
5427 | 423 | FRAME_GET_COMP_LINE (task->dest, 0, l2), |
5428 | 423 | FRAME_GET_COMP_LINE (task->dest, 1, i >> 1), |
5429 | 423 | FRAME_GET_COMP_LINE (task->dest, 2, i >> 1), |
5430 | 423 | FRAME_GET_LINE (task->src, l1), FRAME_GET_LINE (task->src, l2), |
5431 | 423 | (task->width + 1) / 2); |
5432 | 423 | } |
5433 | 14 | } |
5434 | | |
5435 | | static void |
5436 | | convert_UYVY_I420 (GstVideoConverter * convert, const GstVideoFrame * src, |
5437 | | GstVideoFrame * dest) |
5438 | 14 | { |
5439 | 14 | int i; |
5440 | 14 | gint width = convert->in_width; |
5441 | 14 | gint height = convert->in_height; |
5442 | 14 | gboolean interlaced = GST_VIDEO_FRAME_IS_INTERLACED (src) |
5443 | 0 | && (GST_VIDEO_INFO_INTERLACE_MODE (&src->info) != |
5444 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE); |
5445 | 14 | gint h2; |
5446 | 14 | FConvertTask *tasks; |
5447 | 14 | FConvertTask **tasks_p; |
5448 | 14 | gint n_threads; |
5449 | 14 | gint lines_per_thread; |
5450 | | |
5451 | | /* I420 has half as many chroma lines, as such we have to |
5452 | | * always merge two into one. For non-interlaced these are |
5453 | | * the two next to each other, for interlaced one is skipped |
5454 | | * in between. */ |
5455 | 14 | if (interlaced) |
5456 | 0 | h2 = GST_ROUND_DOWN_4 (height); |
5457 | 14 | else |
5458 | 14 | h2 = GST_ROUND_DOWN_2 (height); |
5459 | | |
5460 | 14 | n_threads = convert->conversion_runner->n_threads; |
5461 | 14 | tasks = convert->tasks[0] = |
5462 | 14 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
5463 | 14 | tasks_p = convert->tasks_p[0] = |
5464 | 14 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
5465 | | |
5466 | 14 | lines_per_thread = GST_ROUND_UP_2 ((h2 + n_threads - 1) / n_threads); |
5467 | | |
5468 | 28 | for (i = 0; i < n_threads; i++) { |
5469 | 14 | tasks[i].src = src; |
5470 | 14 | tasks[i].dest = dest; |
5471 | | |
5472 | 14 | tasks[i].interlaced = interlaced; |
5473 | 14 | tasks[i].width = width; |
5474 | | |
5475 | 14 | tasks[i].height_0 = i * lines_per_thread; |
5476 | 14 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
5477 | 14 | tasks[i].height_1 = MIN (h2, tasks[i].height_1); |
5478 | | |
5479 | 14 | tasks_p[i] = &tasks[i]; |
5480 | 14 | } |
5481 | | |
5482 | 14 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5483 | 14 | (GstParallelizedTaskFunc) convert_UYVY_I420_task, (gpointer) tasks_p); |
5484 | | |
5485 | | /* now handle last lines. For interlaced these are up to 3 */ |
5486 | 14 | if (h2 != height) { |
5487 | 10 | for (i = h2; i < height; i++) { |
5488 | 5 | UNPACK_FRAME (src, convert->tmpline[0], i, convert->in_x, width); |
5489 | 5 | PACK_FRAME (dest, convert->tmpline[0], i, width); |
5490 | 5 | } |
5491 | 5 | } |
5492 | 14 | } |
5493 | | |
5494 | | static void |
5495 | | convert_UYVY_AYUV_task (FConvertPlaneTask * task) |
5496 | 12 | { |
5497 | 12 | video_orc_convert_UYVY_AYUV (task->d, task->dstride, task->s, |
5498 | 12 | task->sstride, task->alpha, (task->width + 1) / 2, task->height); |
5499 | 12 | } |
5500 | | |
5501 | | static void |
5502 | | convert_UYVY_AYUV (GstVideoConverter * convert, const GstVideoFrame * src, |
5503 | | GstVideoFrame * dest) |
5504 | 12 | { |
5505 | 12 | gint width = convert->in_width; |
5506 | 12 | gint height = convert->in_height; |
5507 | 12 | guint8 *s, *d; |
5508 | 12 | guint8 alpha = MIN (convert->alpha_value, 255); |
5509 | 12 | FConvertPlaneTask *tasks; |
5510 | 12 | FConvertPlaneTask **tasks_p; |
5511 | 12 | gint n_threads; |
5512 | 12 | gint lines_per_thread; |
5513 | 12 | gint i; |
5514 | | |
5515 | 12 | s = FRAME_GET_LINE (src, convert->in_y); |
5516 | 12 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5517 | 12 | d = FRAME_GET_LINE (dest, convert->out_y); |
5518 | 12 | d += (convert->out_x * 4); |
5519 | | |
5520 | 12 | n_threads = convert->conversion_runner->n_threads; |
5521 | 12 | tasks = convert->tasks[0] = |
5522 | 12 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5523 | 12 | tasks_p = convert->tasks_p[0] = |
5524 | 12 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5525 | | |
5526 | 12 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5527 | | |
5528 | 24 | for (i = 0; i < n_threads; i++) { |
5529 | 12 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
5530 | 12 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5531 | 12 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
5532 | 12 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5533 | | |
5534 | 12 | tasks[i].width = width; |
5535 | 12 | tasks[i].height = (i + 1) * lines_per_thread; |
5536 | 12 | tasks[i].height = MIN (tasks[i].height, height); |
5537 | 12 | tasks[i].height -= i * lines_per_thread; |
5538 | 12 | tasks[i].alpha = alpha; |
5539 | | |
5540 | 12 | tasks_p[i] = &tasks[i]; |
5541 | 12 | } |
5542 | | |
5543 | 12 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5544 | 12 | (GstParallelizedTaskFunc) convert_UYVY_AYUV_task, (gpointer) tasks_p); |
5545 | | |
5546 | 12 | convert_fill_border (convert, dest); |
5547 | 12 | } |
5548 | | |
5549 | | static void |
5550 | | convert_UYVY_v210_task (FConvertPlaneTask * task) |
5551 | 0 | { |
5552 | 0 | gint i, j; |
5553 | 0 | guint8 *d; |
5554 | 0 | const guint8 *s; |
5555 | 0 | guint32 a0, a1, a2, a3; |
5556 | 0 | guint8 y0, y1, y2, y3, y4, y5; |
5557 | 0 | guint8 u0, u2, u4; |
5558 | 0 | guint8 v0, v2, v4; |
5559 | |
|
5560 | 0 | for (i = 0; i < task->height; i++) { |
5561 | 0 | d = task->d + i * task->dstride; |
5562 | 0 | s = task->s + i * task->sstride; |
5563 | |
|
5564 | 0 | for (j = 0; j < task->width; j += 6) { |
5565 | 0 | y1 = y2 = y3 = y4 = y5 = 0; |
5566 | 0 | u2 = u4 = v2 = v4 = 0; |
5567 | |
|
5568 | 0 | y0 = s[2 * j + 1]; |
5569 | 0 | u0 = s[2 * j]; |
5570 | 0 | v0 = s[2 * j + 2]; |
5571 | |
|
5572 | 0 | if (j < task->width - 1) { |
5573 | 0 | y1 = s[2 * j + 3]; |
5574 | 0 | } |
5575 | |
|
5576 | 0 | if (j < task->width - 2) { |
5577 | 0 | y2 = s[2 * j + 5]; |
5578 | 0 | u2 = s[2 * j + 4]; |
5579 | 0 | v2 = s[2 * j + 6]; |
5580 | 0 | } |
5581 | |
|
5582 | 0 | if (j < task->width - 3) { |
5583 | 0 | y3 = s[2 * j + 7]; |
5584 | 0 | } |
5585 | |
|
5586 | 0 | if (j < task->width - 4) { |
5587 | 0 | y4 = s[2 * j + 9]; |
5588 | 0 | u4 = s[2 * j + 8]; |
5589 | 0 | v4 = s[2 * j + 10]; |
5590 | 0 | } |
5591 | |
|
5592 | 0 | if (j < task->width - 5) { |
5593 | 0 | y5 = s[2 * j + 11]; |
5594 | 0 | } |
5595 | |
|
5596 | 0 | a0 = u0 << 2 | (y0 << 12) | (v0 << 22); |
5597 | 0 | a1 = y1 << 2 | (u2 << 12) | (y2 << 22); |
5598 | 0 | a2 = v2 << 2 | (y3 << 12) | (u4 << 22); |
5599 | 0 | a3 = y4 << 2 | (v4 << 12) | (y5 << 22); |
5600 | |
|
5601 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 0, a0); |
5602 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 4, a1); |
5603 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 8, a2); |
5604 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 12, a3); |
5605 | 0 | } |
5606 | 0 | } |
5607 | 0 | } |
5608 | | |
5609 | | static void |
5610 | | convert_UYVY_v210 (GstVideoConverter * convert, const GstVideoFrame * src, |
5611 | | GstVideoFrame * dest) |
5612 | 0 | { |
5613 | 0 | gint width = convert->in_width; |
5614 | 0 | gint height = convert->in_height; |
5615 | 0 | guint8 *s, *d; |
5616 | 0 | FConvertPlaneTask *tasks; |
5617 | 0 | FConvertPlaneTask **tasks_p; |
5618 | 0 | gint n_threads; |
5619 | 0 | gint lines_per_thread; |
5620 | 0 | gint i; |
5621 | |
|
5622 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5623 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5624 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
5625 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
5626 | |
|
5627 | 0 | n_threads = convert->conversion_runner->n_threads; |
5628 | 0 | tasks = convert->tasks[0] = |
5629 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5630 | 0 | tasks_p = convert->tasks_p[0] = |
5631 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5632 | |
|
5633 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5634 | |
|
5635 | 0 | for (i = 0; i < n_threads; i++) { |
5636 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
5637 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5638 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
5639 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5640 | |
|
5641 | 0 | tasks[i].width = width; |
5642 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5643 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5644 | 0 | tasks[i].height -= i * lines_per_thread; |
5645 | |
|
5646 | 0 | tasks_p[i] = &tasks[i]; |
5647 | 0 | } |
5648 | |
|
5649 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5650 | 0 | (GstParallelizedTaskFunc) convert_UYVY_v210_task, (gpointer) tasks_p); |
5651 | |
|
5652 | 0 | convert_fill_border (convert, dest); |
5653 | 0 | } |
5654 | | |
5655 | | static void |
5656 | | convert_UYVY_YUY2_task (FConvertPlaneTask * task) |
5657 | 10 | { |
5658 | 10 | video_orc_convert_UYVY_YUY2 (task->d, task->dstride, task->s, |
5659 | 10 | task->sstride, (task->width + 1) / 2, task->height); |
5660 | 10 | } |
5661 | | |
5662 | | static void |
5663 | | convert_UYVY_YUY2 (GstVideoConverter * convert, const GstVideoFrame * src, |
5664 | | GstVideoFrame * dest) |
5665 | 10 | { |
5666 | 10 | gint width = convert->in_width; |
5667 | 10 | gint height = convert->in_height; |
5668 | 10 | guint8 *s, *d; |
5669 | 10 | FConvertPlaneTask *tasks; |
5670 | 10 | FConvertPlaneTask **tasks_p; |
5671 | 10 | gint n_threads; |
5672 | 10 | gint lines_per_thread; |
5673 | 10 | gint i; |
5674 | | |
5675 | 10 | s = FRAME_GET_LINE (src, convert->in_y); |
5676 | 10 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5677 | 10 | d = FRAME_GET_LINE (dest, convert->out_y); |
5678 | 10 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
5679 | | |
5680 | 10 | n_threads = convert->conversion_runner->n_threads; |
5681 | 10 | tasks = convert->tasks[0] = |
5682 | 10 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5683 | 10 | tasks_p = convert->tasks_p[0] = |
5684 | 10 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5685 | | |
5686 | 10 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5687 | | |
5688 | 20 | for (i = 0; i < n_threads; i++) { |
5689 | 10 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
5690 | 10 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5691 | 10 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
5692 | 10 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5693 | | |
5694 | 10 | tasks[i].width = width; |
5695 | 10 | tasks[i].height = (i + 1) * lines_per_thread; |
5696 | 10 | tasks[i].height = MIN (tasks[i].height, height); |
5697 | 10 | tasks[i].height -= i * lines_per_thread; |
5698 | | |
5699 | 10 | tasks_p[i] = &tasks[i]; |
5700 | 10 | } |
5701 | | |
5702 | 10 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5703 | 10 | (GstParallelizedTaskFunc) convert_UYVY_YUY2_task, (gpointer) tasks_p); |
5704 | | |
5705 | 10 | convert_fill_border (convert, dest); |
5706 | 10 | } |
5707 | | |
5708 | | static void |
5709 | | convert_v210_UYVY_task (FConvertPlaneTask * task) |
5710 | 0 | { |
5711 | 0 | gint i, j; |
5712 | 0 | guint8 *d; |
5713 | 0 | const guint8 *s; |
5714 | 0 | guint32 a0, a1, a2, a3; |
5715 | 0 | guint16 y0, y1, y2, y3, y4, y5; |
5716 | 0 | guint16 u0, u2, u4; |
5717 | 0 | guint16 v0, v2, v4; |
5718 | |
|
5719 | 0 | for (i = 0; i < task->height; i++) { |
5720 | 0 | d = task->d + i * task->dstride; |
5721 | 0 | s = task->s + i * task->sstride; |
5722 | |
|
5723 | 0 | for (j = 0; j < task->width; j += 6) { |
5724 | 0 | a0 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 0); |
5725 | 0 | a1 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 4); |
5726 | 0 | a2 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 8); |
5727 | 0 | a3 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 12); |
5728 | |
|
5729 | 0 | u0 = ((a0 >> 0) & 0x3ff) >> 2; |
5730 | 0 | y0 = ((a0 >> 10) & 0x3ff) >> 2; |
5731 | 0 | v0 = ((a0 >> 20) & 0x3ff) >> 2; |
5732 | 0 | y1 = ((a1 >> 0) & 0x3ff) >> 2; |
5733 | |
|
5734 | 0 | u2 = ((a1 >> 10) & 0x3ff) >> 2; |
5735 | 0 | y2 = ((a1 >> 20) & 0x3ff) >> 2; |
5736 | 0 | v2 = ((a2 >> 0) & 0x3ff) >> 2; |
5737 | 0 | y3 = ((a2 >> 10) & 0x3ff) >> 2; |
5738 | |
|
5739 | 0 | u4 = ((a2 >> 20) & 0x3ff) >> 2; |
5740 | 0 | y4 = ((a3 >> 0) & 0x3ff) >> 2; |
5741 | 0 | v4 = ((a3 >> 10) & 0x3ff) >> 2; |
5742 | 0 | y5 = ((a3 >> 20) & 0x3ff) >> 2; |
5743 | |
|
5744 | 0 | d[2 * j + 1] = y0; |
5745 | 0 | d[2 * j] = u0; |
5746 | 0 | d[2 * j + 2] = v0; |
5747 | |
|
5748 | 0 | if (j < task->width - 1) { |
5749 | 0 | d[2 * j + 3] = y1; |
5750 | 0 | } |
5751 | |
|
5752 | 0 | if (j < task->width - 2) { |
5753 | 0 | d[2 * j + 5] = y2; |
5754 | 0 | d[2 * j + 4] = u2; |
5755 | 0 | d[2 * j + 6] = v2; |
5756 | 0 | } |
5757 | |
|
5758 | 0 | if (j < task->width - 3) { |
5759 | 0 | d[2 * j + 7] = y3; |
5760 | 0 | } |
5761 | |
|
5762 | 0 | if (j < task->width - 4) { |
5763 | 0 | d[2 * j + 9] = y4; |
5764 | 0 | d[2 * j + 8] = u4; |
5765 | 0 | d[2 * j + 10] = v4; |
5766 | 0 | } |
5767 | |
|
5768 | 0 | if (j < task->width - 5) { |
5769 | 0 | d[2 * j + 11] = y5; |
5770 | 0 | } |
5771 | 0 | } |
5772 | 0 | } |
5773 | 0 | } |
5774 | | |
5775 | | static void |
5776 | | convert_v210_UYVY (GstVideoConverter * convert, const GstVideoFrame * src, |
5777 | | GstVideoFrame * dest) |
5778 | 0 | { |
5779 | 0 | gint width = convert->in_width; |
5780 | 0 | gint height = convert->in_height; |
5781 | 0 | guint8 *s, *d; |
5782 | 0 | FConvertPlaneTask *tasks; |
5783 | 0 | FConvertPlaneTask **tasks_p; |
5784 | 0 | gint n_threads; |
5785 | 0 | gint lines_per_thread; |
5786 | 0 | gint i; |
5787 | |
|
5788 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5789 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5790 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
5791 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
5792 | |
|
5793 | 0 | n_threads = convert->conversion_runner->n_threads; |
5794 | 0 | tasks = convert->tasks[0] = |
5795 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5796 | 0 | tasks_p = convert->tasks_p[0] = |
5797 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5798 | |
|
5799 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5800 | |
|
5801 | 0 | for (i = 0; i < n_threads; i++) { |
5802 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
5803 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5804 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
5805 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5806 | |
|
5807 | 0 | tasks[i].width = width; |
5808 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5809 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5810 | 0 | tasks[i].height -= i * lines_per_thread; |
5811 | |
|
5812 | 0 | tasks_p[i] = &tasks[i]; |
5813 | 0 | } |
5814 | |
|
5815 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5816 | 0 | (GstParallelizedTaskFunc) convert_v210_UYVY_task, (gpointer) tasks_p); |
5817 | |
|
5818 | 0 | convert_fill_border (convert, dest); |
5819 | 0 | } |
5820 | | |
5821 | | static void |
5822 | | convert_v210_YUY2_task (FConvertPlaneTask * task) |
5823 | 0 | { |
5824 | 0 | gint i, j; |
5825 | 0 | guint8 *d; |
5826 | 0 | const guint8 *s; |
5827 | 0 | guint32 a0, a1, a2, a3; |
5828 | 0 | guint16 y0, y1, y2, y3, y4, y5; |
5829 | 0 | guint16 u0, u2, u4; |
5830 | 0 | guint16 v0, v2, v4; |
5831 | |
|
5832 | 0 | for (i = 0; i < task->height; i++) { |
5833 | 0 | d = task->d + i * task->dstride; |
5834 | 0 | s = task->s + i * task->sstride; |
5835 | |
|
5836 | 0 | for (j = 0; j < task->width; j += 6) { |
5837 | 0 | a0 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 0); |
5838 | 0 | a1 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 4); |
5839 | 0 | a2 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 8); |
5840 | 0 | a3 = GST_READ_UINT32_LE (s + (j / 6) * 16 + 12); |
5841 | |
|
5842 | 0 | u0 = ((a0 >> 0) & 0x3ff) >> 2; |
5843 | 0 | y0 = ((a0 >> 10) & 0x3ff) >> 2; |
5844 | 0 | v0 = ((a0 >> 20) & 0x3ff) >> 2; |
5845 | 0 | y1 = ((a1 >> 0) & 0x3ff) >> 2; |
5846 | |
|
5847 | 0 | u2 = ((a1 >> 10) & 0x3ff) >> 2; |
5848 | 0 | y2 = ((a1 >> 20) & 0x3ff) >> 2; |
5849 | 0 | v2 = ((a2 >> 0) & 0x3ff) >> 2; |
5850 | 0 | y3 = ((a2 >> 10) & 0x3ff) >> 2; |
5851 | |
|
5852 | 0 | u4 = ((a2 >> 20) & 0x3ff) >> 2; |
5853 | 0 | y4 = ((a3 >> 0) & 0x3ff) >> 2; |
5854 | 0 | v4 = ((a3 >> 10) & 0x3ff) >> 2; |
5855 | 0 | y5 = ((a3 >> 20) & 0x3ff) >> 2; |
5856 | |
|
5857 | 0 | d[2 * j] = y0; |
5858 | 0 | d[2 * j + 1] = u0; |
5859 | 0 | d[2 * j + 3] = v0; |
5860 | |
|
5861 | 0 | if (j < task->width - 1) { |
5862 | 0 | d[2 * j + 2] = y1; |
5863 | 0 | } |
5864 | |
|
5865 | 0 | if (j < task->width - 2) { |
5866 | 0 | d[2 * j + 4] = y2; |
5867 | 0 | d[2 * j + 5] = u2; |
5868 | 0 | d[2 * j + 7] = v2; |
5869 | 0 | } |
5870 | |
|
5871 | 0 | if (j < task->width - 3) { |
5872 | 0 | d[2 * j + 6] = y3; |
5873 | 0 | } |
5874 | |
|
5875 | 0 | if (j < task->width - 4) { |
5876 | 0 | d[2 * j + 8] = y4; |
5877 | 0 | d[2 * j + 9] = u4; |
5878 | 0 | d[2 * j + 11] = v4; |
5879 | 0 | } |
5880 | |
|
5881 | 0 | if (j < task->width - 5) { |
5882 | 0 | d[2 * j + 10] = y5; |
5883 | 0 | } |
5884 | 0 | } |
5885 | 0 | } |
5886 | 0 | } |
5887 | | |
5888 | | static void |
5889 | | convert_v210_YUY2 (GstVideoConverter * convert, const GstVideoFrame * src, |
5890 | | GstVideoFrame * dest) |
5891 | 0 | { |
5892 | 0 | gint width = convert->in_width; |
5893 | 0 | gint height = convert->in_height; |
5894 | 0 | guint8 *s, *d; |
5895 | 0 | FConvertPlaneTask *tasks; |
5896 | 0 | FConvertPlaneTask **tasks_p; |
5897 | 0 | gint n_threads; |
5898 | 0 | gint lines_per_thread; |
5899 | 0 | gint i; |
5900 | |
|
5901 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5902 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5903 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
5904 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
5905 | |
|
5906 | 0 | n_threads = convert->conversion_runner->n_threads; |
5907 | 0 | tasks = convert->tasks[0] = |
5908 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5909 | 0 | tasks_p = convert->tasks_p[0] = |
5910 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5911 | |
|
5912 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5913 | |
|
5914 | 0 | for (i = 0; i < n_threads; i++) { |
5915 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
5916 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5917 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
5918 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5919 | |
|
5920 | 0 | tasks[i].width = width; |
5921 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5922 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5923 | 0 | tasks[i].height -= i * lines_per_thread; |
5924 | |
|
5925 | 0 | tasks_p[i] = &tasks[i]; |
5926 | 0 | } |
5927 | |
|
5928 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5929 | 0 | (GstParallelizedTaskFunc) convert_v210_YUY2_task, (gpointer) tasks_p); |
5930 | |
|
5931 | 0 | convert_fill_border (convert, dest); |
5932 | 0 | } |
5933 | | |
5934 | | static void |
5935 | | convert_UYVY_Y42B_task (FConvertPlaneTask * task) |
5936 | 0 | { |
5937 | 0 | video_orc_convert_UYVY_Y42B (task->d, task->dstride, task->du, |
5938 | 0 | task->dustride, task->dv, task->dvstride, |
5939 | 0 | task->s, task->sstride, (task->width + 1) / 2, task->height); |
5940 | 0 | } |
5941 | | |
5942 | | static void |
5943 | | convert_UYVY_Y42B (GstVideoConverter * convert, const GstVideoFrame * src, |
5944 | | GstVideoFrame * dest) |
5945 | 0 | { |
5946 | 0 | gint width = convert->in_width; |
5947 | 0 | gint height = convert->in_height; |
5948 | 0 | guint8 *s, *dy, *du, *dv; |
5949 | 0 | FConvertPlaneTask *tasks; |
5950 | 0 | FConvertPlaneTask **tasks_p; |
5951 | 0 | gint n_threads; |
5952 | 0 | gint lines_per_thread; |
5953 | 0 | gint i; |
5954 | |
|
5955 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
5956 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
5957 | |
|
5958 | 0 | dy = FRAME_GET_Y_LINE (dest, convert->out_y); |
5959 | 0 | dy += convert->out_x; |
5960 | 0 | du = FRAME_GET_U_LINE (dest, convert->out_y); |
5961 | 0 | du += convert->out_x >> 1; |
5962 | 0 | dv = FRAME_GET_V_LINE (dest, convert->out_y); |
5963 | 0 | dv += convert->out_x >> 1; |
5964 | |
|
5965 | 0 | n_threads = convert->conversion_runner->n_threads; |
5966 | 0 | tasks = convert->tasks[0] = |
5967 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
5968 | 0 | tasks_p = convert->tasks_p[0] = |
5969 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
5970 | |
|
5971 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
5972 | |
|
5973 | 0 | for (i = 0; i < n_threads; i++) { |
5974 | 0 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
5975 | 0 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
5976 | 0 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
5977 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
5978 | 0 | tasks[i].d = dy + i * lines_per_thread * tasks[i].dstride; |
5979 | 0 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride; |
5980 | 0 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride; |
5981 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
5982 | |
|
5983 | 0 | tasks[i].width = width; |
5984 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
5985 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
5986 | 0 | tasks[i].height -= i * lines_per_thread; |
5987 | |
|
5988 | 0 | tasks_p[i] = &tasks[i]; |
5989 | 0 | } |
5990 | |
|
5991 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
5992 | 0 | (GstParallelizedTaskFunc) convert_UYVY_Y42B_task, (gpointer) tasks_p); |
5993 | |
|
5994 | 0 | convert_fill_border (convert, dest); |
5995 | 0 | } |
5996 | | |
5997 | | static void |
5998 | | convert_UYVY_Y444_task (FConvertPlaneTask * task) |
5999 | 0 | { |
6000 | 0 | video_orc_convert_UYVY_Y444 (task->d, |
6001 | 0 | task->dstride, task->du, |
6002 | 0 | task->dustride, task->dv, |
6003 | 0 | task->dvstride, task->s, |
6004 | 0 | task->sstride, (task->width + 1) / 2, task->height); |
6005 | 0 | } |
6006 | | |
6007 | | static void |
6008 | | convert_UYVY_Y444 (GstVideoConverter * convert, const GstVideoFrame * src, |
6009 | | GstVideoFrame * dest) |
6010 | 0 | { |
6011 | 0 | gint width = convert->in_width; |
6012 | 0 | gint height = convert->in_height; |
6013 | 0 | guint8 *s, *dy, *du, *dv; |
6014 | 0 | FConvertPlaneTask *tasks; |
6015 | 0 | FConvertPlaneTask **tasks_p; |
6016 | 0 | gint n_threads; |
6017 | 0 | gint lines_per_thread; |
6018 | 0 | gint i; |
6019 | |
|
6020 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
6021 | 0 | s += (GST_ROUND_UP_2 (convert->in_x) * 2); |
6022 | |
|
6023 | 0 | dy = FRAME_GET_Y_LINE (dest, convert->out_y); |
6024 | 0 | dy += convert->out_x; |
6025 | 0 | du = FRAME_GET_U_LINE (dest, convert->out_y); |
6026 | 0 | du += convert->out_x; |
6027 | 0 | dv = FRAME_GET_V_LINE (dest, convert->out_y); |
6028 | 0 | dv += convert->out_x; |
6029 | |
|
6030 | 0 | n_threads = convert->conversion_runner->n_threads; |
6031 | 0 | tasks = convert->tasks[0] = |
6032 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6033 | 0 | tasks_p = convert->tasks_p[0] = |
6034 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6035 | |
|
6036 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6037 | |
|
6038 | 0 | for (i = 0; i < n_threads; i++) { |
6039 | 0 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
6040 | 0 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
6041 | 0 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
6042 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
6043 | 0 | tasks[i].d = dy + i * lines_per_thread * tasks[i].dstride; |
6044 | 0 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride; |
6045 | 0 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride; |
6046 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
6047 | |
|
6048 | 0 | tasks[i].width = width; |
6049 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6050 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6051 | 0 | tasks[i].height -= i * lines_per_thread; |
6052 | |
|
6053 | 0 | tasks_p[i] = &tasks[i]; |
6054 | 0 | } |
6055 | |
|
6056 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6057 | 0 | (GstParallelizedTaskFunc) convert_UYVY_Y444_task, (gpointer) tasks_p); |
6058 | |
|
6059 | 0 | convert_fill_border (convert, dest); |
6060 | 0 | } |
6061 | | |
6062 | | static void |
6063 | | convert_UYVY_GRAY8_task (FConvertPlaneTask * task) |
6064 | 18 | { |
6065 | 18 | video_orc_convert_UYVY_GRAY8 (task->d, task->dstride, (guint16 *) task->s, |
6066 | 18 | task->sstride, task->width, task->height); |
6067 | 18 | } |
6068 | | |
6069 | | static void |
6070 | | convert_UYVY_GRAY8 (GstVideoConverter * convert, const GstVideoFrame * src, |
6071 | | GstVideoFrame * dest) |
6072 | 18 | { |
6073 | 18 | gint width = convert->in_width; |
6074 | 18 | gint height = convert->in_height; |
6075 | 18 | guint8 *s; |
6076 | 18 | guint8 *d; |
6077 | 18 | FConvertPlaneTask *tasks; |
6078 | 18 | FConvertPlaneTask **tasks_p; |
6079 | 18 | gint n_threads; |
6080 | 18 | gint lines_per_thread; |
6081 | 18 | gint i; |
6082 | | |
6083 | 18 | s = GST_VIDEO_FRAME_PLANE_DATA (src, 0); |
6084 | 18 | d = GST_VIDEO_FRAME_PLANE_DATA (dest, 0); |
6085 | | |
6086 | 18 | n_threads = convert->conversion_runner->n_threads; |
6087 | 18 | tasks = convert->tasks[0] = |
6088 | 18 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6089 | 18 | tasks_p = convert->tasks_p[0] = |
6090 | 18 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6091 | | |
6092 | 18 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6093 | | |
6094 | 36 | for (i = 0; i < n_threads; i++) { |
6095 | 18 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6096 | 18 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
6097 | 18 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6098 | 18 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
6099 | | |
6100 | 18 | tasks[i].width = width; |
6101 | 18 | tasks[i].height = (i + 1) * lines_per_thread; |
6102 | 18 | tasks[i].height = MIN (tasks[i].height, height); |
6103 | 18 | tasks[i].height -= i * lines_per_thread; |
6104 | | |
6105 | 18 | tasks_p[i] = &tasks[i]; |
6106 | 18 | } |
6107 | | |
6108 | 18 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6109 | 18 | (GstParallelizedTaskFunc) convert_UYVY_GRAY8_task, (gpointer) tasks_p); |
6110 | | |
6111 | 18 | convert_fill_border (convert, dest); |
6112 | 18 | } |
6113 | | |
6114 | | static void |
6115 | | convert_AYUV_I420_task (FConvertPlaneTask * task) |
6116 | 16 | { |
6117 | 16 | video_orc_convert_AYUV_I420 (task->d, |
6118 | 16 | 2 * task->dstride, task->d2, |
6119 | 16 | 2 * task->dstride, task->du, |
6120 | 16 | task->dustride, task->dv, |
6121 | 16 | task->dvstride, task->s, |
6122 | 16 | 2 * task->sstride, task->s2, |
6123 | 16 | 2 * task->sstride, task->width / 2, task->height / 2); |
6124 | 16 | } |
6125 | | |
6126 | | static void |
6127 | | convert_AYUV_I420 (GstVideoConverter * convert, const GstVideoFrame * src, |
6128 | | GstVideoFrame * dest) |
6129 | 16 | { |
6130 | 16 | gint width = convert->in_width; |
6131 | 16 | gint height = convert->in_height; |
6132 | 16 | guint8 *s1, *s2, *dy1, *dy2, *du, *dv; |
6133 | 16 | FConvertPlaneTask *tasks; |
6134 | 16 | FConvertPlaneTask **tasks_p; |
6135 | 16 | gint n_threads; |
6136 | 16 | gint lines_per_thread; |
6137 | 16 | gint i; |
6138 | | |
6139 | 16 | s1 = FRAME_GET_LINE (src, convert->in_y + 0); |
6140 | 16 | s1 += convert->in_x * 4; |
6141 | 16 | s2 = FRAME_GET_LINE (src, convert->in_y + 1); |
6142 | 16 | s2 += convert->in_x * 4; |
6143 | | |
6144 | 16 | dy1 = FRAME_GET_Y_LINE (dest, convert->out_y + 0); |
6145 | 16 | dy1 += convert->out_x; |
6146 | 16 | dy2 = FRAME_GET_Y_LINE (dest, convert->out_y + 1); |
6147 | 16 | dy2 += convert->out_x; |
6148 | 16 | du = FRAME_GET_U_LINE (dest, convert->out_y >> 1); |
6149 | 16 | du += convert->out_x >> 1; |
6150 | 16 | dv = FRAME_GET_V_LINE (dest, convert->out_y >> 1); |
6151 | 16 | dv += convert->out_x >> 1; |
6152 | | |
6153 | | /* only for even width/height */ |
6154 | | |
6155 | 16 | n_threads = convert->conversion_runner->n_threads; |
6156 | 16 | tasks = convert->tasks[0] = |
6157 | 16 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6158 | 16 | tasks_p = convert->tasks_p[0] = |
6159 | 16 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6160 | | |
6161 | 16 | lines_per_thread = GST_ROUND_UP_2 ((height + n_threads - 1) / n_threads); |
6162 | | |
6163 | 32 | for (i = 0; i < n_threads; i++) { |
6164 | 16 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
6165 | 16 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
6166 | 16 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
6167 | 16 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
6168 | 16 | tasks[i].d = dy1 + i * lines_per_thread * tasks[i].dstride; |
6169 | 16 | tasks[i].d2 = dy2 + i * lines_per_thread * tasks[i].dstride; |
6170 | 16 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride / 2; |
6171 | 16 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride / 2; |
6172 | 16 | tasks[i].s = s1 + i * lines_per_thread * tasks[i].sstride; |
6173 | 16 | tasks[i].s2 = s2 + i * lines_per_thread * tasks[i].sstride; |
6174 | | |
6175 | 16 | tasks[i].width = width; |
6176 | 16 | tasks[i].height = (i + 1) * lines_per_thread; |
6177 | 16 | tasks[i].height = MIN (tasks[i].height, height); |
6178 | 16 | tasks[i].height -= i * lines_per_thread; |
6179 | | |
6180 | 16 | tasks_p[i] = &tasks[i]; |
6181 | 16 | } |
6182 | | |
6183 | 16 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6184 | 16 | (GstParallelizedTaskFunc) convert_AYUV_I420_task, (gpointer) tasks_p); |
6185 | | |
6186 | 16 | convert_fill_border (convert, dest); |
6187 | 16 | } |
6188 | | |
6189 | | static void |
6190 | | convert_AYUV_YUY2_task (FConvertPlaneTask * task) |
6191 | 12 | { |
6192 | 12 | video_orc_convert_AYUV_YUY2 (task->d, task->dstride, task->s, |
6193 | 12 | task->sstride, task->width / 2, task->height); |
6194 | 12 | } |
6195 | | |
6196 | | static void |
6197 | | convert_AYUV_YUY2 (GstVideoConverter * convert, const GstVideoFrame * src, |
6198 | | GstVideoFrame * dest) |
6199 | 12 | { |
6200 | 12 | gint width = convert->in_width; |
6201 | 12 | gint height = convert->in_height; |
6202 | 12 | guint8 *s, *d; |
6203 | 12 | FConvertPlaneTask *tasks; |
6204 | 12 | FConvertPlaneTask **tasks_p; |
6205 | 12 | gint n_threads; |
6206 | 12 | gint lines_per_thread; |
6207 | 12 | gint i; |
6208 | | |
6209 | 12 | s = FRAME_GET_LINE (src, convert->in_y); |
6210 | 12 | s += convert->in_x * 4; |
6211 | 12 | d = FRAME_GET_LINE (dest, convert->out_y); |
6212 | 12 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
6213 | | |
6214 | | /* only for even width */ |
6215 | 12 | n_threads = convert->conversion_runner->n_threads; |
6216 | 12 | tasks = convert->tasks[0] = |
6217 | 12 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6218 | 12 | tasks_p = convert->tasks_p[0] = |
6219 | 12 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6220 | | |
6221 | 12 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6222 | | |
6223 | 24 | for (i = 0; i < n_threads; i++) { |
6224 | 12 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6225 | 12 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
6226 | 12 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6227 | 12 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
6228 | | |
6229 | 12 | tasks[i].width = width; |
6230 | 12 | tasks[i].height = (i + 1) * lines_per_thread; |
6231 | 12 | tasks[i].height = MIN (tasks[i].height, height); |
6232 | 12 | tasks[i].height -= i * lines_per_thread; |
6233 | | |
6234 | 12 | tasks_p[i] = &tasks[i]; |
6235 | 12 | } |
6236 | | |
6237 | 12 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6238 | 12 | (GstParallelizedTaskFunc) convert_AYUV_YUY2_task, (gpointer) tasks_p); |
6239 | | |
6240 | 12 | convert_fill_border (convert, dest); |
6241 | 12 | } |
6242 | | |
6243 | | static void |
6244 | | convert_AYUV_UYVY_task (FConvertPlaneTask * task) |
6245 | 10 | { |
6246 | 10 | video_orc_convert_AYUV_UYVY (task->d, task->dstride, task->s, |
6247 | 10 | task->sstride, task->width / 2, task->height); |
6248 | 10 | } |
6249 | | |
6250 | | static void |
6251 | | convert_AYUV_UYVY (GstVideoConverter * convert, const GstVideoFrame * src, |
6252 | | GstVideoFrame * dest) |
6253 | 10 | { |
6254 | 10 | gint width = convert->in_width; |
6255 | 10 | gint height = convert->in_height; |
6256 | 10 | guint8 *s, *d; |
6257 | 10 | FConvertPlaneTask *tasks; |
6258 | 10 | FConvertPlaneTask **tasks_p; |
6259 | 10 | gint n_threads; |
6260 | 10 | gint lines_per_thread; |
6261 | 10 | gint i; |
6262 | | |
6263 | 10 | s = FRAME_GET_LINE (src, convert->in_y); |
6264 | 10 | s += convert->in_x * 4; |
6265 | 10 | d = FRAME_GET_LINE (dest, convert->out_y); |
6266 | 10 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
6267 | | |
6268 | | /* only for even width */ |
6269 | 10 | n_threads = convert->conversion_runner->n_threads; |
6270 | 10 | tasks = convert->tasks[0] = |
6271 | 10 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6272 | 10 | tasks_p = convert->tasks_p[0] = |
6273 | 10 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6274 | | |
6275 | 10 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6276 | | |
6277 | 20 | for (i = 0; i < n_threads; i++) { |
6278 | 10 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6279 | 10 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
6280 | 10 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6281 | 10 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
6282 | | |
6283 | 10 | tasks[i].width = width; |
6284 | 10 | tasks[i].height = (i + 1) * lines_per_thread; |
6285 | 10 | tasks[i].height = MIN (tasks[i].height, height); |
6286 | 10 | tasks[i].height -= i * lines_per_thread; |
6287 | | |
6288 | 10 | tasks_p[i] = &tasks[i]; |
6289 | 10 | } |
6290 | | |
6291 | 10 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6292 | 10 | (GstParallelizedTaskFunc) convert_AYUV_UYVY_task, (gpointer) tasks_p); |
6293 | | |
6294 | 10 | convert_fill_border (convert, dest); |
6295 | 10 | } |
6296 | | |
6297 | | static void |
6298 | | convert_AYUV_Y42B_task (FConvertPlaneTask * task) |
6299 | 0 | { |
6300 | 0 | video_orc_convert_AYUV_Y42B (task->d, task->dstride, task->du, |
6301 | 0 | task->dustride, task->dv, task->dvstride, |
6302 | 0 | task->s, task->sstride, task->width / 2, task->height); |
6303 | 0 | } |
6304 | | |
6305 | | static void |
6306 | | convert_AYUV_Y42B (GstVideoConverter * convert, const GstVideoFrame * src, |
6307 | | GstVideoFrame * dest) |
6308 | 0 | { |
6309 | 0 | gint width = convert->in_width; |
6310 | 0 | gint height = convert->in_height; |
6311 | 0 | guint8 *s, *dy, *du, *dv; |
6312 | 0 | FConvertPlaneTask *tasks; |
6313 | 0 | FConvertPlaneTask **tasks_p; |
6314 | 0 | gint n_threads; |
6315 | 0 | gint lines_per_thread; |
6316 | 0 | gint i; |
6317 | |
|
6318 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
6319 | 0 | s += convert->in_x * 4; |
6320 | |
|
6321 | 0 | dy = FRAME_GET_Y_LINE (dest, convert->out_y); |
6322 | 0 | dy += convert->out_x; |
6323 | 0 | du = FRAME_GET_U_LINE (dest, convert->out_y); |
6324 | 0 | du += convert->out_x >> 1; |
6325 | 0 | dv = FRAME_GET_V_LINE (dest, convert->out_y); |
6326 | 0 | dv += convert->out_x >> 1; |
6327 | | |
6328 | | /* only works for even width */ |
6329 | 0 | n_threads = convert->conversion_runner->n_threads; |
6330 | 0 | tasks = convert->tasks[0] = |
6331 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6332 | 0 | tasks_p = convert->tasks_p[0] = |
6333 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6334 | |
|
6335 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6336 | |
|
6337 | 0 | for (i = 0; i < n_threads; i++) { |
6338 | 0 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
6339 | 0 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
6340 | 0 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
6341 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
6342 | 0 | tasks[i].d = dy + i * lines_per_thread * tasks[i].dstride; |
6343 | 0 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride; |
6344 | 0 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride; |
6345 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
6346 | |
|
6347 | 0 | tasks[i].width = width; |
6348 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6349 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6350 | 0 | tasks[i].height -= i * lines_per_thread; |
6351 | |
|
6352 | 0 | tasks_p[i] = &tasks[i]; |
6353 | 0 | } |
6354 | |
|
6355 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6356 | 0 | (GstParallelizedTaskFunc) convert_AYUV_Y42B_task, (gpointer) tasks_p); |
6357 | |
|
6358 | 0 | convert_fill_border (convert, dest); |
6359 | 0 | } |
6360 | | |
6361 | | static void |
6362 | | convert_AYUV_Y444_task (FConvertPlaneTask * task) |
6363 | 0 | { |
6364 | 0 | video_orc_convert_AYUV_Y444 (task->d, task->dstride, task->du, |
6365 | 0 | task->dustride, task->dv, task->dvstride, |
6366 | 0 | task->s, task->sstride, task->width, task->height); |
6367 | 0 | } |
6368 | | |
6369 | | static void |
6370 | | convert_AYUV_Y444 (GstVideoConverter * convert, const GstVideoFrame * src, |
6371 | | GstVideoFrame * dest) |
6372 | 0 | { |
6373 | 0 | gint width = convert->in_width; |
6374 | 0 | gint height = convert->in_height; |
6375 | 0 | guint8 *s, *dy, *du, *dv; |
6376 | 0 | FConvertPlaneTask *tasks; |
6377 | 0 | FConvertPlaneTask **tasks_p; |
6378 | 0 | gint n_threads; |
6379 | 0 | gint lines_per_thread; |
6380 | 0 | gint i; |
6381 | |
|
6382 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
6383 | 0 | s += convert->in_x * 4; |
6384 | |
|
6385 | 0 | dy = FRAME_GET_Y_LINE (dest, convert->out_y); |
6386 | 0 | dy += convert->out_x; |
6387 | 0 | du = FRAME_GET_U_LINE (dest, convert->out_y); |
6388 | 0 | du += convert->out_x; |
6389 | 0 | dv = FRAME_GET_V_LINE (dest, convert->out_y); |
6390 | 0 | dv += convert->out_x; |
6391 | |
|
6392 | 0 | n_threads = convert->conversion_runner->n_threads; |
6393 | 0 | tasks = convert->tasks[0] = |
6394 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6395 | 0 | tasks_p = convert->tasks_p[0] = |
6396 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6397 | |
|
6398 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6399 | |
|
6400 | 0 | for (i = 0; i < n_threads; i++) { |
6401 | 0 | tasks[i].dstride = FRAME_GET_Y_STRIDE (dest); |
6402 | 0 | tasks[i].dustride = FRAME_GET_U_STRIDE (dest); |
6403 | 0 | tasks[i].dvstride = FRAME_GET_V_STRIDE (dest); |
6404 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
6405 | 0 | tasks[i].d = dy + i * lines_per_thread * tasks[i].dstride; |
6406 | 0 | tasks[i].du = du + i * lines_per_thread * tasks[i].dustride; |
6407 | 0 | tasks[i].dv = dv + i * lines_per_thread * tasks[i].dvstride; |
6408 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
6409 | |
|
6410 | 0 | tasks[i].width = width; |
6411 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6412 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6413 | 0 | tasks[i].height -= i * lines_per_thread; |
6414 | |
|
6415 | 0 | tasks_p[i] = &tasks[i]; |
6416 | 0 | } |
6417 | |
|
6418 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6419 | 0 | (GstParallelizedTaskFunc) convert_AYUV_Y444_task, (gpointer) tasks_p); |
6420 | 0 | convert_fill_border (convert, dest); |
6421 | 0 | } |
6422 | | |
6423 | | static void |
6424 | | convert_Y42B_YUY2_task (FConvertPlaneTask * task) |
6425 | 0 | { |
6426 | 0 | video_orc_convert_Y42B_YUY2 (task->d, task->dstride, |
6427 | 0 | task->s, task->sstride, |
6428 | 0 | task->su, task->sustride, |
6429 | 0 | task->sv, task->svstride, (task->width + 1) / 2, task->height); |
6430 | 0 | } |
6431 | | |
6432 | | static void |
6433 | | convert_Y42B_YUY2 (GstVideoConverter * convert, const GstVideoFrame * src, |
6434 | | GstVideoFrame * dest) |
6435 | 0 | { |
6436 | 0 | gint width = convert->in_width; |
6437 | 0 | gint height = convert->in_height; |
6438 | 0 | guint8 *sy, *su, *sv, *d; |
6439 | 0 | FConvertPlaneTask *tasks; |
6440 | 0 | FConvertPlaneTask **tasks_p; |
6441 | 0 | gint n_threads; |
6442 | 0 | gint lines_per_thread; |
6443 | 0 | gint i; |
6444 | |
|
6445 | 0 | sy = FRAME_GET_Y_LINE (src, convert->in_y); |
6446 | 0 | sy += convert->in_x; |
6447 | 0 | su = FRAME_GET_U_LINE (src, convert->in_y); |
6448 | 0 | su += convert->in_x >> 1; |
6449 | 0 | sv = FRAME_GET_V_LINE (src, convert->in_y); |
6450 | 0 | sv += convert->in_x >> 1; |
6451 | |
|
6452 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
6453 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
6454 | |
|
6455 | 0 | n_threads = convert->conversion_runner->n_threads; |
6456 | 0 | tasks = convert->tasks[0] = |
6457 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6458 | 0 | tasks_p = convert->tasks_p[0] = |
6459 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6460 | |
|
6461 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6462 | |
|
6463 | 0 | for (i = 0; i < n_threads; i++) { |
6464 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6465 | 0 | tasks[i].sstride = FRAME_GET_Y_STRIDE (src); |
6466 | 0 | tasks[i].sustride = FRAME_GET_U_STRIDE (src); |
6467 | 0 | tasks[i].svstride = FRAME_GET_V_STRIDE (src); |
6468 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6469 | 0 | tasks[i].s = sy + i * lines_per_thread * tasks[i].sstride; |
6470 | 0 | tasks[i].su = su + i * lines_per_thread * tasks[i].sustride; |
6471 | 0 | tasks[i].sv = sv + i * lines_per_thread * tasks[i].svstride; |
6472 | |
|
6473 | 0 | tasks[i].width = width; |
6474 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6475 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6476 | 0 | tasks[i].height -= i * lines_per_thread; |
6477 | |
|
6478 | 0 | tasks_p[i] = &tasks[i]; |
6479 | 0 | } |
6480 | |
|
6481 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6482 | 0 | (GstParallelizedTaskFunc) convert_Y42B_YUY2_task, (gpointer) tasks_p); |
6483 | |
|
6484 | 0 | convert_fill_border (convert, dest); |
6485 | 0 | } |
6486 | | |
6487 | | static void |
6488 | | convert_Y42B_UYVY_task (FConvertPlaneTask * task) |
6489 | 0 | { |
6490 | 0 | video_orc_convert_Y42B_UYVY (task->d, task->dstride, |
6491 | 0 | task->s, task->sstride, |
6492 | 0 | task->su, task->sustride, |
6493 | 0 | task->sv, task->svstride, (task->width + 1) / 2, task->height); |
6494 | 0 | } |
6495 | | |
6496 | | static void |
6497 | | convert_Y42B_UYVY (GstVideoConverter * convert, const GstVideoFrame * src, |
6498 | | GstVideoFrame * dest) |
6499 | 0 | { |
6500 | 0 | gint width = convert->in_width; |
6501 | 0 | gint height = convert->in_height; |
6502 | 0 | guint8 *sy, *su, *sv, *d; |
6503 | 0 | FConvertPlaneTask *tasks; |
6504 | 0 | FConvertPlaneTask **tasks_p; |
6505 | 0 | gint n_threads; |
6506 | 0 | gint lines_per_thread; |
6507 | 0 | gint i; |
6508 | |
|
6509 | 0 | sy = FRAME_GET_Y_LINE (src, convert->in_y); |
6510 | 0 | sy += convert->in_x; |
6511 | 0 | su = FRAME_GET_U_LINE (src, convert->in_y); |
6512 | 0 | su += convert->in_x >> 1; |
6513 | 0 | sv = FRAME_GET_V_LINE (src, convert->in_y); |
6514 | 0 | sv += convert->in_x >> 1; |
6515 | |
|
6516 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
6517 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
6518 | |
|
6519 | 0 | n_threads = convert->conversion_runner->n_threads; |
6520 | 0 | tasks = convert->tasks[0] = |
6521 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6522 | 0 | tasks_p = convert->tasks_p[0] = |
6523 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6524 | |
|
6525 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6526 | |
|
6527 | 0 | for (i = 0; i < n_threads; i++) { |
6528 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6529 | 0 | tasks[i].sstride = FRAME_GET_Y_STRIDE (src); |
6530 | 0 | tasks[i].sustride = FRAME_GET_U_STRIDE (src); |
6531 | 0 | tasks[i].svstride = FRAME_GET_V_STRIDE (src); |
6532 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6533 | 0 | tasks[i].s = sy + i * lines_per_thread * tasks[i].sstride; |
6534 | 0 | tasks[i].su = su + i * lines_per_thread * tasks[i].sustride; |
6535 | 0 | tasks[i].sv = sv + i * lines_per_thread * tasks[i].svstride; |
6536 | |
|
6537 | 0 | tasks[i].width = width; |
6538 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6539 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6540 | 0 | tasks[i].height -= i * lines_per_thread; |
6541 | |
|
6542 | 0 | tasks_p[i] = &tasks[i]; |
6543 | 0 | } |
6544 | |
|
6545 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6546 | 0 | (GstParallelizedTaskFunc) convert_Y42B_UYVY_task, (gpointer) tasks_p); |
6547 | |
|
6548 | 0 | convert_fill_border (convert, dest); |
6549 | 0 | } |
6550 | | |
6551 | | static void |
6552 | | convert_Y42B_AYUV_task (FConvertPlaneTask * task) |
6553 | 0 | { |
6554 | 0 | video_orc_convert_Y42B_AYUV (task->d, task->dstride, task->s, |
6555 | 0 | task->sstride, |
6556 | 0 | task->su, |
6557 | 0 | task->sustride, |
6558 | 0 | task->sv, task->svstride, task->alpha, task->width / 2, task->height); |
6559 | 0 | } |
6560 | | |
6561 | | static void |
6562 | | convert_Y42B_AYUV (GstVideoConverter * convert, const GstVideoFrame * src, |
6563 | | GstVideoFrame * dest) |
6564 | 0 | { |
6565 | 0 | gint width = convert->in_width; |
6566 | 0 | gint height = convert->in_height; |
6567 | 0 | guint8 *sy, *su, *sv, *d; |
6568 | 0 | guint8 alpha = MIN (convert->alpha_value, 255); |
6569 | 0 | FConvertPlaneTask *tasks; |
6570 | 0 | FConvertPlaneTask **tasks_p; |
6571 | 0 | gint n_threads; |
6572 | 0 | gint lines_per_thread; |
6573 | 0 | gint i; |
6574 | |
|
6575 | 0 | sy = FRAME_GET_Y_LINE (src, convert->in_y); |
6576 | 0 | sy += convert->in_x; |
6577 | 0 | su = FRAME_GET_U_LINE (src, convert->in_y); |
6578 | 0 | su += convert->in_x >> 1; |
6579 | 0 | sv = FRAME_GET_V_LINE (src, convert->in_y); |
6580 | 0 | sv += convert->in_x >> 1; |
6581 | |
|
6582 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
6583 | 0 | d += convert->out_x * 4; |
6584 | | |
6585 | | /* only for even width */ |
6586 | 0 | n_threads = convert->conversion_runner->n_threads; |
6587 | 0 | tasks = convert->tasks[0] = |
6588 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6589 | 0 | tasks_p = convert->tasks_p[0] = |
6590 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6591 | |
|
6592 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6593 | |
|
6594 | 0 | for (i = 0; i < n_threads; i++) { |
6595 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6596 | 0 | tasks[i].sstride = FRAME_GET_Y_STRIDE (src); |
6597 | 0 | tasks[i].sustride = FRAME_GET_U_STRIDE (src); |
6598 | 0 | tasks[i].svstride = FRAME_GET_V_STRIDE (src); |
6599 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6600 | 0 | tasks[i].s = sy + i * lines_per_thread * tasks[i].sstride; |
6601 | 0 | tasks[i].su = su + i * lines_per_thread * tasks[i].sustride; |
6602 | 0 | tasks[i].sv = sv + i * lines_per_thread * tasks[i].svstride; |
6603 | |
|
6604 | 0 | tasks[i].width = width; |
6605 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6606 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6607 | 0 | tasks[i].height -= i * lines_per_thread; |
6608 | 0 | tasks[i].alpha = alpha; |
6609 | |
|
6610 | 0 | tasks_p[i] = &tasks[i]; |
6611 | 0 | } |
6612 | |
|
6613 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6614 | 0 | (GstParallelizedTaskFunc) convert_Y42B_AYUV_task, (gpointer) tasks_p); |
6615 | |
|
6616 | 0 | convert_fill_border (convert, dest); |
6617 | 0 | } |
6618 | | |
6619 | | static void |
6620 | | convert_Y42B_v210_task (FConvertPlaneTask * task) |
6621 | 0 | { |
6622 | 0 | gint i, j; |
6623 | 0 | guint8 *d; |
6624 | 0 | const guint8 *s_y, *s_u, *s_v; |
6625 | 0 | guint32 a0, a1, a2, a3; |
6626 | 0 | guint8 y0, y1, y2, y3, y4, y5; |
6627 | 0 | guint8 u0, u2, u4; |
6628 | 0 | guint8 v0, v2, v4; |
6629 | |
|
6630 | 0 | for (i = 0; i < task->height; i++) { |
6631 | 0 | d = task->d + i * task->dstride; |
6632 | 0 | s_y = task->s + i * task->sstride; |
6633 | 0 | s_u = task->su + i * task->sustride; |
6634 | 0 | s_v = task->sv + i * task->svstride; |
6635 | |
|
6636 | 0 | for (j = 0; j < task->width; j += 6) { |
6637 | 0 | y1 = y2 = y3 = y4 = y5 = 0; |
6638 | 0 | u2 = u4 = v2 = v4 = 0; |
6639 | |
|
6640 | 0 | y0 = s_y[j]; |
6641 | 0 | u0 = s_u[j / 2]; |
6642 | 0 | v0 = s_v[j / 2]; |
6643 | |
|
6644 | 0 | if (j < task->width - 1) { |
6645 | 0 | y1 = s_y[j + 1]; |
6646 | 0 | } |
6647 | |
|
6648 | 0 | if (j < task->width - 2) { |
6649 | 0 | y2 = s_y[j + 2]; |
6650 | 0 | u2 = s_u[j / 2 + 1]; |
6651 | 0 | v2 = s_v[j / 2 + 1]; |
6652 | 0 | } |
6653 | |
|
6654 | 0 | if (j < task->width - 3) { |
6655 | 0 | y3 = s_y[j + 3]; |
6656 | 0 | } |
6657 | |
|
6658 | 0 | if (j < task->width - 4) { |
6659 | 0 | y4 = s_y[j + 4]; |
6660 | 0 | u4 = s_u[j / 2 + 2]; |
6661 | 0 | v4 = s_v[j / 2 + 2]; |
6662 | 0 | } |
6663 | |
|
6664 | 0 | if (j < task->width - 5) { |
6665 | 0 | y5 = s_y[j + 5]; |
6666 | 0 | } |
6667 | |
|
6668 | 0 | a0 = u0 << 2 | (y0 << 12) | (v0 << 22); |
6669 | 0 | a1 = y1 << 2 | (u2 << 12) | (y2 << 22); |
6670 | 0 | a2 = v2 << 2 | (y3 << 12) | (u4 << 22); |
6671 | 0 | a3 = y4 << 2 | (v4 << 12) | (y5 << 22); |
6672 | |
|
6673 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 0, a0); |
6674 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 4, a1); |
6675 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 8, a2); |
6676 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 12, a3); |
6677 | 0 | } |
6678 | 0 | } |
6679 | 0 | } |
6680 | | |
6681 | | static void |
6682 | | convert_Y42B_v210 (GstVideoConverter * convert, const GstVideoFrame * src, |
6683 | | GstVideoFrame * dest) |
6684 | 0 | { |
6685 | 0 | gint width = convert->in_width; |
6686 | 0 | gint height = convert->in_height; |
6687 | 0 | guint8 *d, *sy, *su, *sv; |
6688 | 0 | FConvertPlaneTask *tasks; |
6689 | 0 | FConvertPlaneTask **tasks_p; |
6690 | 0 | gint n_threads; |
6691 | 0 | gint lines_per_thread; |
6692 | 0 | gint i; |
6693 | |
|
6694 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
6695 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
6696 | |
|
6697 | 0 | sy = FRAME_GET_Y_LINE (src, convert->in_y); |
6698 | 0 | sy += convert->in_x; |
6699 | 0 | su = FRAME_GET_U_LINE (src, convert->in_y); |
6700 | 0 | su += convert->in_x >> 1; |
6701 | 0 | sv = FRAME_GET_V_LINE (src, convert->in_y); |
6702 | 0 | sv += convert->in_x >> 1; |
6703 | |
|
6704 | 0 | n_threads = convert->conversion_runner->n_threads; |
6705 | 0 | tasks = convert->tasks[0] = |
6706 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6707 | 0 | tasks_p = convert->tasks_p[0] = |
6708 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6709 | |
|
6710 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6711 | |
|
6712 | 0 | for (i = 0; i < n_threads; i++) { |
6713 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6714 | 0 | tasks[i].sstride = FRAME_GET_Y_STRIDE (src); |
6715 | 0 | tasks[i].sustride = FRAME_GET_U_STRIDE (src); |
6716 | 0 | tasks[i].svstride = FRAME_GET_V_STRIDE (src); |
6717 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6718 | 0 | tasks[i].s = sy + i * lines_per_thread * tasks[i].sstride; |
6719 | 0 | tasks[i].su = su + i * lines_per_thread * tasks[i].sustride; |
6720 | 0 | tasks[i].sv = sv + i * lines_per_thread * tasks[i].svstride; |
6721 | |
|
6722 | 0 | tasks[i].width = width; |
6723 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6724 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6725 | 0 | tasks[i].height -= i * lines_per_thread; |
6726 | |
|
6727 | 0 | tasks_p[i] = &tasks[i]; |
6728 | 0 | } |
6729 | |
|
6730 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6731 | 0 | (GstParallelizedTaskFunc) convert_Y42B_v210_task, (gpointer) tasks_p); |
6732 | |
|
6733 | 0 | convert_fill_border (convert, dest); |
6734 | 0 | } |
6735 | | |
6736 | | static void |
6737 | | convert_I422_10_v210_task (FConvertPlaneTask * task) |
6738 | 0 | { |
6739 | 0 | gint i, j; |
6740 | 0 | guint8 *d; |
6741 | 0 | const guint16 *s_y, *s_u, *s_v; |
6742 | 0 | guint32 a0, a1, a2, a3; |
6743 | 0 | guint16 y0, y1, y2, y3, y4, y5; |
6744 | 0 | guint16 u0, u2, u4; |
6745 | 0 | guint16 v0, v2, v4; |
6746 | |
|
6747 | 0 | for (i = 0; i < task->height; i++) { |
6748 | 0 | d = task->d + i * task->dstride; |
6749 | 0 | s_y = (const guint16 *) (task->s + i * task->sstride); |
6750 | 0 | s_u = (const guint16 *) (task->su + i * task->sustride); |
6751 | 0 | s_v = (const guint16 *) (task->sv + i * task->svstride); |
6752 | |
|
6753 | 0 | for (j = 0; j < task->width; j += 6) { |
6754 | 0 | y1 = y2 = y3 = y4 = y5 = 0; |
6755 | 0 | u2 = u4 = v2 = v4 = 0; |
6756 | |
|
6757 | 0 | y0 = s_y[j]; |
6758 | 0 | u0 = s_u[j / 2]; |
6759 | 0 | v0 = s_v[j / 2]; |
6760 | |
|
6761 | 0 | if (j < task->width - 1) { |
6762 | 0 | y1 = s_y[j + 1]; |
6763 | 0 | } |
6764 | |
|
6765 | 0 | if (j < task->width - 2) { |
6766 | 0 | y2 = s_y[j + 2]; |
6767 | 0 | u2 = s_u[j / 2 + 1]; |
6768 | 0 | v2 = s_v[j / 2 + 1]; |
6769 | 0 | } |
6770 | |
|
6771 | 0 | if (j < task->width - 3) { |
6772 | 0 | y3 = s_y[j + 3]; |
6773 | 0 | } |
6774 | |
|
6775 | 0 | if (j < task->width - 4) { |
6776 | 0 | y4 = s_y[j + 4]; |
6777 | 0 | u4 = s_u[j / 2 + 2]; |
6778 | 0 | v4 = s_v[j / 2 + 2]; |
6779 | 0 | } |
6780 | |
|
6781 | 0 | if (j < task->width - 5) { |
6782 | 0 | y5 = s_y[j + 5]; |
6783 | 0 | } |
6784 | |
|
6785 | 0 | a0 = u0 | (y0 << 10) | (v0 << 20); |
6786 | 0 | a1 = y1 | (u2 << 10) | (y2 << 20); |
6787 | 0 | a2 = v2 | (y3 << 10) | (u4 << 20); |
6788 | 0 | a3 = y4 | (v4 << 10) | (y5 << 20); |
6789 | |
|
6790 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 0, a0); |
6791 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 4, a1); |
6792 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 8, a2); |
6793 | 0 | GST_WRITE_UINT32_LE (d + (j / 6) * 16 + 12, a3); |
6794 | 0 | } |
6795 | 0 | } |
6796 | 0 | } |
6797 | | |
6798 | | static void |
6799 | | convert_I422_10_v210 (GstVideoConverter * convert, const GstVideoFrame * src, |
6800 | | GstVideoFrame * dest) |
6801 | 0 | { |
6802 | 0 | gint width = convert->in_width; |
6803 | 0 | gint height = convert->in_height; |
6804 | 0 | guint8 *d, *sy, *su, *sv; |
6805 | 0 | FConvertPlaneTask *tasks; |
6806 | 0 | FConvertPlaneTask **tasks_p; |
6807 | 0 | gint n_threads; |
6808 | 0 | gint lines_per_thread; |
6809 | 0 | gint i; |
6810 | |
|
6811 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
6812 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
6813 | |
|
6814 | 0 | sy = FRAME_GET_Y_LINE (src, convert->in_y); |
6815 | 0 | sy += convert->in_x; |
6816 | 0 | su = FRAME_GET_U_LINE (src, convert->in_y); |
6817 | 0 | su += convert->in_x >> 1; |
6818 | 0 | sv = FRAME_GET_V_LINE (src, convert->in_y); |
6819 | 0 | sv += convert->in_x >> 1; |
6820 | |
|
6821 | 0 | n_threads = convert->conversion_runner->n_threads; |
6822 | 0 | tasks = convert->tasks[0] = |
6823 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6824 | 0 | tasks_p = convert->tasks_p[0] = |
6825 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6826 | |
|
6827 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6828 | |
|
6829 | 0 | for (i = 0; i < n_threads; i++) { |
6830 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6831 | 0 | tasks[i].sstride = FRAME_GET_Y_STRIDE (src); |
6832 | 0 | tasks[i].sustride = FRAME_GET_U_STRIDE (src); |
6833 | 0 | tasks[i].svstride = FRAME_GET_V_STRIDE (src); |
6834 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6835 | 0 | tasks[i].s = sy + i * lines_per_thread * tasks[i].sstride; |
6836 | 0 | tasks[i].su = su + i * lines_per_thread * tasks[i].sustride; |
6837 | 0 | tasks[i].sv = sv + i * lines_per_thread * tasks[i].svstride; |
6838 | |
|
6839 | 0 | tasks[i].width = width; |
6840 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6841 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6842 | 0 | tasks[i].height -= i * lines_per_thread; |
6843 | |
|
6844 | 0 | tasks_p[i] = &tasks[i]; |
6845 | 0 | } |
6846 | |
|
6847 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6848 | 0 | (GstParallelizedTaskFunc) convert_I422_10_v210_task, (gpointer) tasks_p); |
6849 | |
|
6850 | 0 | convert_fill_border (convert, dest); |
6851 | 0 | } |
6852 | | |
6853 | | static void |
6854 | | convert_Y444_YUY2_task (FConvertPlaneTask * task) |
6855 | 0 | { |
6856 | 0 | video_orc_convert_Y444_YUY2 (task->d, task->dstride, task->s, |
6857 | 0 | task->sstride, |
6858 | 0 | task->su, |
6859 | 0 | task->sustride, task->sv, task->svstride, task->width / 2, task->height); |
6860 | 0 | } |
6861 | | |
6862 | | static void |
6863 | | convert_Y444_YUY2 (GstVideoConverter * convert, const GstVideoFrame * src, |
6864 | | GstVideoFrame * dest) |
6865 | 0 | { |
6866 | 0 | gint width = convert->in_width; |
6867 | 0 | gint height = convert->in_height; |
6868 | 0 | guint8 *sy, *su, *sv, *d; |
6869 | 0 | FConvertPlaneTask *tasks; |
6870 | 0 | FConvertPlaneTask **tasks_p; |
6871 | 0 | gint n_threads; |
6872 | 0 | gint lines_per_thread; |
6873 | 0 | gint i; |
6874 | |
|
6875 | 0 | sy = FRAME_GET_Y_LINE (src, convert->in_y); |
6876 | 0 | sy += convert->in_x; |
6877 | 0 | su = FRAME_GET_U_LINE (src, convert->in_y); |
6878 | 0 | su += convert->in_x; |
6879 | 0 | sv = FRAME_GET_V_LINE (src, convert->in_y); |
6880 | 0 | sv += convert->in_x; |
6881 | |
|
6882 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
6883 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
6884 | |
|
6885 | 0 | n_threads = convert->conversion_runner->n_threads; |
6886 | 0 | tasks = convert->tasks[0] = |
6887 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6888 | 0 | tasks_p = convert->tasks_p[0] = |
6889 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6890 | |
|
6891 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6892 | |
|
6893 | 0 | for (i = 0; i < n_threads; i++) { |
6894 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6895 | 0 | tasks[i].sstride = FRAME_GET_Y_STRIDE (src); |
6896 | 0 | tasks[i].sustride = FRAME_GET_U_STRIDE (src); |
6897 | 0 | tasks[i].svstride = FRAME_GET_V_STRIDE (src); |
6898 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6899 | 0 | tasks[i].s = sy + i * lines_per_thread * tasks[i].sstride; |
6900 | 0 | tasks[i].su = su + i * lines_per_thread * tasks[i].sustride; |
6901 | 0 | tasks[i].sv = sv + i * lines_per_thread * tasks[i].svstride; |
6902 | |
|
6903 | 0 | tasks[i].width = width; |
6904 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6905 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6906 | 0 | tasks[i].height -= i * lines_per_thread; |
6907 | |
|
6908 | 0 | tasks_p[i] = &tasks[i]; |
6909 | 0 | } |
6910 | |
|
6911 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6912 | 0 | (GstParallelizedTaskFunc) convert_Y444_YUY2_task, (gpointer) tasks_p); |
6913 | |
|
6914 | 0 | convert_fill_border (convert, dest); |
6915 | 0 | } |
6916 | | |
6917 | | static void |
6918 | | convert_Y444_UYVY_task (FConvertPlaneTask * task) |
6919 | 0 | { |
6920 | 0 | video_orc_convert_Y444_UYVY (task->d, task->dstride, task->s, |
6921 | 0 | task->sstride, |
6922 | 0 | task->su, |
6923 | 0 | task->sustride, task->sv, task->svstride, task->width / 2, task->height); |
6924 | 0 | } |
6925 | | |
6926 | | static void |
6927 | | convert_Y444_UYVY (GstVideoConverter * convert, const GstVideoFrame * src, |
6928 | | GstVideoFrame * dest) |
6929 | 0 | { |
6930 | 0 | gint width = convert->in_width; |
6931 | 0 | gint height = convert->in_height; |
6932 | 0 | guint8 *sy, *su, *sv, *d; |
6933 | 0 | FConvertPlaneTask *tasks; |
6934 | 0 | FConvertPlaneTask **tasks_p; |
6935 | 0 | gint n_threads; |
6936 | 0 | gint lines_per_thread; |
6937 | 0 | gint i; |
6938 | |
|
6939 | 0 | sy = FRAME_GET_Y_LINE (src, convert->in_y); |
6940 | 0 | sy += convert->in_x; |
6941 | 0 | su = FRAME_GET_U_LINE (src, convert->in_y); |
6942 | 0 | su += convert->in_x; |
6943 | 0 | sv = FRAME_GET_V_LINE (src, convert->in_y); |
6944 | 0 | sv += convert->in_x; |
6945 | |
|
6946 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
6947 | 0 | d += (GST_ROUND_UP_2 (convert->out_x) * 2); |
6948 | |
|
6949 | 0 | n_threads = convert->conversion_runner->n_threads; |
6950 | 0 | tasks = convert->tasks[0] = |
6951 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
6952 | 0 | tasks_p = convert->tasks_p[0] = |
6953 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
6954 | |
|
6955 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
6956 | |
|
6957 | 0 | for (i = 0; i < n_threads; i++) { |
6958 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
6959 | 0 | tasks[i].sstride = FRAME_GET_Y_STRIDE (src); |
6960 | 0 | tasks[i].sustride = FRAME_GET_U_STRIDE (src); |
6961 | 0 | tasks[i].svstride = FRAME_GET_V_STRIDE (src); |
6962 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
6963 | 0 | tasks[i].s = sy + i * lines_per_thread * tasks[i].sstride; |
6964 | 0 | tasks[i].su = su + i * lines_per_thread * tasks[i].sustride; |
6965 | 0 | tasks[i].sv = sv + i * lines_per_thread * tasks[i].svstride; |
6966 | |
|
6967 | 0 | tasks[i].width = width; |
6968 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
6969 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
6970 | 0 | tasks[i].height -= i * lines_per_thread; |
6971 | |
|
6972 | 0 | tasks_p[i] = &tasks[i]; |
6973 | 0 | } |
6974 | |
|
6975 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
6976 | 0 | (GstParallelizedTaskFunc) convert_Y444_UYVY_task, (gpointer) tasks_p); |
6977 | |
|
6978 | 0 | convert_fill_border (convert, dest); |
6979 | 0 | } |
6980 | | |
6981 | | static void |
6982 | | convert_Y444_AYUV_task (FConvertPlaneTask * task) |
6983 | 0 | { |
6984 | 0 | video_orc_convert_Y444_AYUV (task->d, task->dstride, task->s, |
6985 | 0 | task->sstride, |
6986 | 0 | task->su, |
6987 | 0 | task->sustride, |
6988 | 0 | task->sv, task->svstride, task->alpha, task->width, task->height); |
6989 | 0 | } |
6990 | | |
6991 | | static void |
6992 | | convert_Y444_AYUV (GstVideoConverter * convert, const GstVideoFrame * src, |
6993 | | GstVideoFrame * dest) |
6994 | 0 | { |
6995 | 0 | gint width = convert->in_width; |
6996 | 0 | gint height = convert->in_height; |
6997 | 0 | guint8 *sy, *su, *sv, *d; |
6998 | 0 | guint8 alpha = MIN (convert->alpha_value, 255); |
6999 | 0 | FConvertPlaneTask *tasks; |
7000 | 0 | FConvertPlaneTask **tasks_p; |
7001 | 0 | gint n_threads; |
7002 | 0 | gint lines_per_thread; |
7003 | 0 | gint i; |
7004 | |
|
7005 | 0 | sy = FRAME_GET_Y_LINE (src, convert->in_y); |
7006 | 0 | sy += convert->in_x; |
7007 | 0 | su = FRAME_GET_U_LINE (src, convert->in_y); |
7008 | 0 | su += convert->in_x; |
7009 | 0 | sv = FRAME_GET_V_LINE (src, convert->in_y); |
7010 | 0 | sv += convert->in_x; |
7011 | |
|
7012 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
7013 | 0 | d += convert->out_x * 4; |
7014 | |
|
7015 | 0 | n_threads = convert->conversion_runner->n_threads; |
7016 | 0 | tasks = convert->tasks[0] = |
7017 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
7018 | 0 | tasks_p = convert->tasks_p[0] = |
7019 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
7020 | |
|
7021 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7022 | |
|
7023 | 0 | for (i = 0; i < n_threads; i++) { |
7024 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
7025 | 0 | tasks[i].sstride = FRAME_GET_Y_STRIDE (src); |
7026 | 0 | tasks[i].sustride = FRAME_GET_U_STRIDE (src); |
7027 | 0 | tasks[i].svstride = FRAME_GET_V_STRIDE (src); |
7028 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
7029 | 0 | tasks[i].s = sy + i * lines_per_thread * tasks[i].sstride; |
7030 | 0 | tasks[i].su = su + i * lines_per_thread * tasks[i].sustride; |
7031 | 0 | tasks[i].sv = sv + i * lines_per_thread * tasks[i].svstride; |
7032 | |
|
7033 | 0 | tasks[i].width = width; |
7034 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
7035 | 0 | tasks[i].height = MIN (tasks[i].height, height); |
7036 | 0 | tasks[i].height -= i * lines_per_thread; |
7037 | 0 | tasks[i].alpha = alpha; |
7038 | |
|
7039 | 0 | tasks_p[i] = &tasks[i]; |
7040 | 0 | } |
7041 | |
|
7042 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7043 | 0 | (GstParallelizedTaskFunc) convert_Y444_AYUV_task, (gpointer) tasks_p); |
7044 | |
|
7045 | 0 | convert_fill_border (convert, dest); |
7046 | 0 | } |
7047 | | |
7048 | | static void |
7049 | | convert_AYUV_ARGB_task (FConvertPlaneTask * task) |
7050 | 9 | { |
7051 | 9 | video_orc_convert_AYUV_ARGB (task->d, task->dstride, task->s, |
7052 | 9 | task->sstride, task->data->im[0][0], task->data->im[0][2], |
7053 | 9 | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7054 | 9 | task->width, task->height); |
7055 | 9 | } |
7056 | | |
7057 | | static void |
7058 | | convert_AYUV_ARGB (GstVideoConverter * convert, const GstVideoFrame * src, |
7059 | | GstVideoFrame * dest) |
7060 | 9 | { |
7061 | 9 | gint width = convert->in_width; |
7062 | 9 | gint height = convert->in_height; |
7063 | 9 | MatrixData *data = &convert->convert_matrix; |
7064 | 9 | guint8 *s, *d; |
7065 | 9 | FConvertPlaneTask *tasks; |
7066 | 9 | FConvertPlaneTask **tasks_p; |
7067 | 9 | gint n_threads; |
7068 | 9 | gint lines_per_thread; |
7069 | 9 | gint i; |
7070 | | |
7071 | 9 | s = FRAME_GET_LINE (src, convert->in_y); |
7072 | 9 | s += (convert->in_x * 4); |
7073 | 9 | d = FRAME_GET_LINE (dest, convert->out_y); |
7074 | 9 | d += (convert->out_x * 4); |
7075 | | |
7076 | 9 | n_threads = convert->conversion_runner->n_threads; |
7077 | 9 | tasks = convert->tasks[0] = |
7078 | 9 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
7079 | 9 | tasks_p = convert->tasks_p[0] = |
7080 | 9 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
7081 | | |
7082 | 9 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7083 | | |
7084 | 18 | for (i = 0; i < n_threads; i++) { |
7085 | 9 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
7086 | 9 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
7087 | 9 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
7088 | 9 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
7089 | | |
7090 | 9 | tasks[i].width = width; |
7091 | 9 | tasks[i].height = (i + 1) * lines_per_thread; |
7092 | 9 | tasks[i].height = MIN (tasks[i].height, height); |
7093 | 9 | tasks[i].height -= i * lines_per_thread; |
7094 | 9 | tasks[i].data = data; |
7095 | | |
7096 | 9 | tasks_p[i] = &tasks[i]; |
7097 | 9 | } |
7098 | | |
7099 | 9 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7100 | 9 | (GstParallelizedTaskFunc) convert_AYUV_ARGB_task, (gpointer) tasks_p); |
7101 | | |
7102 | 9 | convert_fill_border (convert, dest); |
7103 | 9 | } |
7104 | | |
7105 | | static void |
7106 | | convert_AYUV_BGRA_task (FConvertPlaneTask * task) |
7107 | 99 | { |
7108 | 99 | video_orc_convert_AYUV_BGRA (task->d, task->dstride, task->s, |
7109 | 99 | task->sstride, task->data->im[0][0], task->data->im[0][2], |
7110 | 99 | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7111 | 99 | task->width, task->height); |
7112 | 99 | } |
7113 | | |
7114 | | static void |
7115 | | convert_AYUV_BGRA (GstVideoConverter * convert, const GstVideoFrame * src, |
7116 | | GstVideoFrame * dest) |
7117 | 99 | { |
7118 | 99 | gint width = convert->in_width; |
7119 | 99 | gint height = convert->in_height; |
7120 | 99 | MatrixData *data = &convert->convert_matrix; |
7121 | 99 | guint8 *s, *d; |
7122 | 99 | FConvertPlaneTask *tasks; |
7123 | 99 | FConvertPlaneTask **tasks_p; |
7124 | 99 | gint n_threads; |
7125 | 99 | gint lines_per_thread; |
7126 | 99 | gint i; |
7127 | | |
7128 | 99 | s = FRAME_GET_LINE (src, convert->in_y); |
7129 | 99 | s += (convert->in_x * 4); |
7130 | 99 | d = FRAME_GET_LINE (dest, convert->out_y); |
7131 | 99 | d += (convert->out_x * 4); |
7132 | | |
7133 | 99 | n_threads = convert->conversion_runner->n_threads; |
7134 | 99 | tasks = convert->tasks[0] = |
7135 | 99 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
7136 | 99 | tasks_p = convert->tasks_p[0] = |
7137 | 99 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
7138 | | |
7139 | 99 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7140 | | |
7141 | 198 | for (i = 0; i < n_threads; i++) { |
7142 | 99 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
7143 | 99 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
7144 | 99 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
7145 | 99 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
7146 | | |
7147 | 99 | tasks[i].width = width; |
7148 | 99 | tasks[i].height = (i + 1) * lines_per_thread; |
7149 | 99 | tasks[i].height = MIN (tasks[i].height, height); |
7150 | 99 | tasks[i].height -= i * lines_per_thread; |
7151 | 99 | tasks[i].data = data; |
7152 | | |
7153 | 99 | tasks_p[i] = &tasks[i]; |
7154 | 99 | } |
7155 | | |
7156 | 99 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7157 | 99 | (GstParallelizedTaskFunc) convert_AYUV_BGRA_task, (gpointer) tasks_p); |
7158 | | |
7159 | 99 | convert_fill_border (convert, dest); |
7160 | 99 | } |
7161 | | |
7162 | | static void |
7163 | | convert_AYUV_ABGR_task (FConvertPlaneTask * task) |
7164 | 101 | { |
7165 | 101 | video_orc_convert_AYUV_ABGR (task->d, task->dstride, task->s, |
7166 | 101 | task->sstride, task->data->im[0][0], task->data->im[0][2], |
7167 | 101 | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7168 | 101 | task->width, task->height); |
7169 | 101 | } |
7170 | | |
7171 | | static void |
7172 | | convert_AYUV_ABGR (GstVideoConverter * convert, const GstVideoFrame * src, |
7173 | | GstVideoFrame * dest) |
7174 | 101 | { |
7175 | 101 | gint width = convert->in_width; |
7176 | 101 | gint height = convert->in_height; |
7177 | 101 | MatrixData *data = &convert->convert_matrix; |
7178 | 101 | guint8 *s, *d; |
7179 | 101 | FConvertPlaneTask *tasks; |
7180 | 101 | FConvertPlaneTask **tasks_p; |
7181 | 101 | gint n_threads; |
7182 | 101 | gint lines_per_thread; |
7183 | 101 | gint i; |
7184 | | |
7185 | 101 | s = FRAME_GET_LINE (src, convert->in_y); |
7186 | 101 | s += (convert->in_x * 4); |
7187 | 101 | d = FRAME_GET_LINE (dest, convert->out_y); |
7188 | 101 | d += (convert->out_x * 4); |
7189 | | |
7190 | 101 | n_threads = convert->conversion_runner->n_threads; |
7191 | 101 | tasks = convert->tasks[0] = |
7192 | 101 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
7193 | 101 | tasks_p = convert->tasks_p[0] = |
7194 | 101 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
7195 | | |
7196 | 101 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7197 | | |
7198 | 202 | for (i = 0; i < n_threads; i++) { |
7199 | 101 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
7200 | 101 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
7201 | 101 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
7202 | 101 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
7203 | | |
7204 | 101 | tasks[i].width = width; |
7205 | 101 | tasks[i].height = (i + 1) * lines_per_thread; |
7206 | 101 | tasks[i].height = MIN (tasks[i].height, height); |
7207 | 101 | tasks[i].height -= i * lines_per_thread; |
7208 | 101 | tasks[i].data = data; |
7209 | | |
7210 | 101 | tasks_p[i] = &tasks[i]; |
7211 | 101 | } |
7212 | | |
7213 | 101 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7214 | 101 | (GstParallelizedTaskFunc) convert_AYUV_ABGR_task, (gpointer) tasks_p); |
7215 | | |
7216 | 101 | convert_fill_border (convert, dest); |
7217 | 101 | } |
7218 | | |
7219 | | static void |
7220 | | convert_AYUV_RGBA_task (FConvertPlaneTask * task) |
7221 | 105 | { |
7222 | 105 | video_orc_convert_AYUV_RGBA (task->d, task->dstride, task->s, |
7223 | 105 | task->sstride, task->data->im[0][0], task->data->im[0][2], |
7224 | 105 | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7225 | 105 | task->width, task->height); |
7226 | 105 | } |
7227 | | |
7228 | | static void |
7229 | | convert_AYUV_RGBA (GstVideoConverter * convert, const GstVideoFrame * src, |
7230 | | GstVideoFrame * dest) |
7231 | 105 | { |
7232 | 105 | gint width = convert->in_width; |
7233 | 105 | gint height = convert->in_height; |
7234 | 105 | MatrixData *data = &convert->convert_matrix; |
7235 | 105 | guint8 *s, *d; |
7236 | 105 | FConvertPlaneTask *tasks; |
7237 | 105 | FConvertPlaneTask **tasks_p; |
7238 | 105 | gint n_threads; |
7239 | 105 | gint lines_per_thread; |
7240 | 105 | gint i; |
7241 | | |
7242 | 105 | s = FRAME_GET_LINE (src, convert->in_y); |
7243 | 105 | s += (convert->in_x * 4); |
7244 | 105 | d = FRAME_GET_LINE (dest, convert->out_y); |
7245 | 105 | d += (convert->out_x * 4); |
7246 | | |
7247 | 105 | n_threads = convert->conversion_runner->n_threads; |
7248 | 105 | tasks = convert->tasks[0] = |
7249 | 105 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
7250 | 105 | tasks_p = convert->tasks_p[0] = |
7251 | 105 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
7252 | | |
7253 | 105 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7254 | | |
7255 | 210 | for (i = 0; i < n_threads; i++) { |
7256 | 105 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
7257 | 105 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
7258 | 105 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
7259 | 105 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
7260 | | |
7261 | 105 | tasks[i].width = width; |
7262 | 105 | tasks[i].height = (i + 1) * lines_per_thread; |
7263 | 105 | tasks[i].height = MIN (tasks[i].height, height); |
7264 | 105 | tasks[i].height -= i * lines_per_thread; |
7265 | 105 | tasks[i].data = data; |
7266 | | |
7267 | 105 | tasks_p[i] = &tasks[i]; |
7268 | 105 | } |
7269 | | |
7270 | 105 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7271 | 105 | (GstParallelizedTaskFunc) convert_AYUV_RGBA_task, (gpointer) tasks_p); |
7272 | | |
7273 | 105 | convert_fill_border (convert, dest); |
7274 | 105 | } |
7275 | | |
7276 | | static void |
7277 | | convert_I420_BGRA_task (FConvertTask * task) |
7278 | 96 | { |
7279 | 96 | gint i; |
7280 | | |
7281 | 6.14k | for (i = task->height_0; i < task->height_1; i++) { |
7282 | 6.05k | guint8 *sy, *su, *sv, *d; |
7283 | | |
7284 | 6.05k | d = FRAME_GET_LINE (task->dest, i + task->out_y); |
7285 | 6.05k | d += (task->out_x * 4); |
7286 | 6.05k | sy = FRAME_GET_Y_LINE (task->src, i + task->in_y); |
7287 | 6.05k | sy += task->in_x; |
7288 | 6.05k | su = FRAME_GET_U_LINE (task->src, (i + task->in_y) >> 1); |
7289 | 6.05k | su += (task->in_x >> 1); |
7290 | 6.05k | sv = FRAME_GET_V_LINE (task->src, (i + task->in_y) >> 1); |
7291 | 6.05k | sv += (task->in_x >> 1); |
7292 | | |
7293 | 6.05k | video_orc_convert_I420_BGRA (d, sy, su, sv, |
7294 | 6.05k | task->data->im[0][0], task->data->im[0][2], |
7295 | 6.05k | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7296 | 6.05k | task->width); |
7297 | 6.05k | } |
7298 | 96 | } |
7299 | | |
7300 | | static void |
7301 | | convert_I420_BGRA (GstVideoConverter * convert, const GstVideoFrame * src, |
7302 | | GstVideoFrame * dest) |
7303 | 96 | { |
7304 | 96 | int i; |
7305 | 96 | gint width = convert->in_width; |
7306 | 96 | gint height = convert->in_height; |
7307 | 96 | MatrixData *data = &convert->convert_matrix; |
7308 | 96 | FConvertTask *tasks; |
7309 | 96 | FConvertTask **tasks_p; |
7310 | 96 | gint n_threads; |
7311 | 96 | gint lines_per_thread; |
7312 | | |
7313 | 96 | n_threads = convert->conversion_runner->n_threads; |
7314 | 96 | tasks = convert->tasks[0] = |
7315 | 96 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
7316 | 96 | tasks_p = convert->tasks_p[0] = |
7317 | 96 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
7318 | | |
7319 | 96 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7320 | | |
7321 | 192 | for (i = 0; i < n_threads; i++) { |
7322 | 96 | tasks[i].src = src; |
7323 | 96 | tasks[i].dest = dest; |
7324 | | |
7325 | 96 | tasks[i].width = width; |
7326 | 96 | tasks[i].data = data; |
7327 | 96 | tasks[i].in_x = convert->in_x; |
7328 | 96 | tasks[i].in_y = convert->in_y; |
7329 | 96 | tasks[i].out_x = convert->out_x; |
7330 | 96 | tasks[i].out_y = convert->out_y; |
7331 | | |
7332 | 96 | tasks[i].height_0 = i * lines_per_thread; |
7333 | 96 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
7334 | 96 | tasks[i].height_1 = MIN (height, tasks[i].height_1); |
7335 | | |
7336 | 96 | tasks_p[i] = &tasks[i]; |
7337 | 96 | } |
7338 | | |
7339 | 96 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7340 | 96 | (GstParallelizedTaskFunc) convert_I420_BGRA_task, (gpointer) tasks_p); |
7341 | | |
7342 | 96 | convert_fill_border (convert, dest); |
7343 | 96 | } |
7344 | | |
7345 | | static void |
7346 | | convert_I420_ARGB_task (FConvertTask * task) |
7347 | 23 | { |
7348 | 23 | gint i; |
7349 | | |
7350 | 1.58k | for (i = task->height_0; i < task->height_1; i++) { |
7351 | 1.56k | guint8 *sy, *su, *sv, *d; |
7352 | | |
7353 | 1.56k | d = FRAME_GET_LINE (task->dest, i + task->out_y); |
7354 | 1.56k | d += (task->out_x * 4); |
7355 | 1.56k | sy = FRAME_GET_Y_LINE (task->src, i + task->in_y); |
7356 | 1.56k | sy += task->in_x; |
7357 | 1.56k | su = FRAME_GET_U_LINE (task->src, (i + task->in_y) >> 1); |
7358 | 1.56k | su += (task->in_x >> 1); |
7359 | 1.56k | sv = FRAME_GET_V_LINE (task->src, (i + task->in_y) >> 1); |
7360 | 1.56k | sv += (task->in_x >> 1); |
7361 | | |
7362 | 1.56k | video_orc_convert_I420_ARGB (d, sy, su, sv, |
7363 | 1.56k | task->data->im[0][0], task->data->im[0][2], |
7364 | 1.56k | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7365 | 1.56k | task->width); |
7366 | 1.56k | } |
7367 | 23 | } |
7368 | | |
7369 | | static void |
7370 | | convert_I420_ARGB (GstVideoConverter * convert, const GstVideoFrame * src, |
7371 | | GstVideoFrame * dest) |
7372 | 23 | { |
7373 | 23 | int i; |
7374 | 23 | gint width = convert->in_width; |
7375 | 23 | gint height = convert->in_height; |
7376 | 23 | MatrixData *data = &convert->convert_matrix; |
7377 | 23 | FConvertTask *tasks; |
7378 | 23 | FConvertTask **tasks_p; |
7379 | 23 | gint n_threads; |
7380 | 23 | gint lines_per_thread; |
7381 | | |
7382 | 23 | n_threads = convert->conversion_runner->n_threads; |
7383 | 23 | tasks = convert->tasks[0] = |
7384 | 23 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
7385 | 23 | tasks_p = convert->tasks_p[0] = |
7386 | 23 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
7387 | | |
7388 | 23 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7389 | | |
7390 | 46 | for (i = 0; i < n_threads; i++) { |
7391 | 23 | tasks[i].src = src; |
7392 | 23 | tasks[i].dest = dest; |
7393 | | |
7394 | 23 | tasks[i].width = width; |
7395 | 23 | tasks[i].data = data; |
7396 | 23 | tasks[i].in_x = convert->in_x; |
7397 | 23 | tasks[i].in_y = convert->in_y; |
7398 | 23 | tasks[i].out_x = convert->out_x; |
7399 | 23 | tasks[i].out_y = convert->out_y; |
7400 | | |
7401 | 23 | tasks[i].height_0 = i * lines_per_thread; |
7402 | 23 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
7403 | 23 | tasks[i].height_1 = MIN (height, tasks[i].height_1); |
7404 | | |
7405 | 23 | tasks_p[i] = &tasks[i]; |
7406 | 23 | } |
7407 | | |
7408 | 23 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7409 | 23 | (GstParallelizedTaskFunc) convert_I420_ARGB_task, (gpointer) tasks_p); |
7410 | | |
7411 | 23 | convert_fill_border (convert, dest); |
7412 | 23 | } |
7413 | | |
7414 | | static void |
7415 | | convert_I420_pack_ARGB_task (FConvertTask * task) |
7416 | 88 | { |
7417 | 88 | gint i; |
7418 | 88 | gpointer d[GST_VIDEO_MAX_PLANES]; |
7419 | | |
7420 | 88 | d[0] = FRAME_GET_LINE (task->dest, 0); |
7421 | 88 | d[0] = |
7422 | 88 | (guint8 *) d[0] + |
7423 | 88 | task->out_x * GST_VIDEO_FORMAT_INFO_PSTRIDE (task->dest->info.finfo, 0); |
7424 | | |
7425 | 6.36k | for (i = task->height_0; i < task->height_1; i++) { |
7426 | 6.27k | guint8 *sy, *su, *sv; |
7427 | | |
7428 | 6.27k | sy = FRAME_GET_Y_LINE (task->src, i + task->in_y); |
7429 | 6.27k | sy += task->in_x; |
7430 | 6.27k | su = FRAME_GET_U_LINE (task->src, (i + task->in_y) >> 1); |
7431 | 6.27k | su += (task->in_x >> 1); |
7432 | 6.27k | sv = FRAME_GET_V_LINE (task->src, (i + task->in_y) >> 1); |
7433 | 6.27k | sv += (task->in_x >> 1); |
7434 | | |
7435 | 6.27k | video_orc_convert_I420_ARGB (task->tmpline, sy, su, sv, |
7436 | 6.27k | task->data->im[0][0], task->data->im[0][2], |
7437 | 6.27k | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7438 | 6.27k | task->width); |
7439 | 6.27k | task->dest->info.finfo->pack_func (task->dest->info.finfo, |
7440 | 6.27k | (GST_VIDEO_FRAME_IS_INTERLACED (task->dest) ? |
7441 | 0 | GST_VIDEO_PACK_FLAG_INTERLACED : |
7442 | 6.27k | GST_VIDEO_PACK_FLAG_NONE), |
7443 | 6.27k | task->tmpline, 0, d, task->dest->info.stride, |
7444 | 6.27k | task->dest->info.chroma_site, i + task->out_y, task->width); |
7445 | 6.27k | } |
7446 | 88 | } |
7447 | | |
7448 | | static void |
7449 | | convert_I420_pack_ARGB (GstVideoConverter * convert, const GstVideoFrame * src, |
7450 | | GstVideoFrame * dest) |
7451 | 88 | { |
7452 | 88 | int i; |
7453 | 88 | gint width = convert->in_width; |
7454 | 88 | gint height = convert->in_height; |
7455 | 88 | MatrixData *data = &convert->convert_matrix; |
7456 | 88 | FConvertTask *tasks; |
7457 | 88 | FConvertTask **tasks_p; |
7458 | 88 | gint n_threads; |
7459 | 88 | gint lines_per_thread; |
7460 | | |
7461 | 88 | n_threads = convert->conversion_runner->n_threads; |
7462 | 88 | tasks = convert->tasks[0] = |
7463 | 88 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
7464 | 88 | tasks_p = convert->tasks_p[0] = |
7465 | 88 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
7466 | | |
7467 | 88 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7468 | | |
7469 | 176 | for (i = 0; i < n_threads; i++) { |
7470 | 88 | tasks[i].src = src; |
7471 | 88 | tasks[i].dest = dest; |
7472 | | |
7473 | 88 | tasks[i].width = width; |
7474 | 88 | tasks[i].data = data; |
7475 | 88 | tasks[i].in_x = convert->in_x; |
7476 | 88 | tasks[i].in_y = convert->in_y; |
7477 | 88 | tasks[i].out_x = convert->out_x; |
7478 | 88 | tasks[i].out_y = convert->out_y; |
7479 | 88 | tasks[i].tmpline = convert->tmpline[i]; |
7480 | | |
7481 | 88 | tasks[i].height_0 = i * lines_per_thread; |
7482 | 88 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
7483 | 88 | tasks[i].height_1 = MIN (height, tasks[i].height_1); |
7484 | | |
7485 | 88 | tasks_p[i] = &tasks[i]; |
7486 | 88 | } |
7487 | | |
7488 | 88 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7489 | 88 | (GstParallelizedTaskFunc) convert_I420_pack_ARGB_task, |
7490 | 88 | (gpointer) tasks_p); |
7491 | | |
7492 | 88 | convert_fill_border (convert, dest); |
7493 | 88 | } |
7494 | | |
7495 | | static void |
7496 | | convert_A420_pack_ARGB_task (FConvertTask * task) |
7497 | 0 | { |
7498 | 0 | gint i; |
7499 | 0 | gpointer d[GST_VIDEO_MAX_PLANES]; |
7500 | |
|
7501 | 0 | d[0] = FRAME_GET_LINE (task->dest, 0); |
7502 | 0 | d[0] = |
7503 | 0 | (guint8 *) d[0] + |
7504 | 0 | task->out_x * GST_VIDEO_FORMAT_INFO_PSTRIDE (task->dest->info.finfo, 0); |
7505 | |
|
7506 | 0 | for (i = task->height_0; i < task->height_1; i++) { |
7507 | 0 | guint8 *sy, *su, *sv, *sa; |
7508 | |
|
7509 | 0 | sy = FRAME_GET_Y_LINE (task->src, i + task->in_y); |
7510 | 0 | sy += task->in_x; |
7511 | 0 | su = FRAME_GET_U_LINE (task->src, (i + task->in_y) >> 1); |
7512 | 0 | su += (task->in_x >> 1); |
7513 | 0 | sv = FRAME_GET_V_LINE (task->src, (i + task->in_y) >> 1); |
7514 | 0 | sv += (task->in_x >> 1); |
7515 | 0 | sa = FRAME_GET_A_LINE (task->src, i + task->in_y); |
7516 | 0 | sa += task->in_x; |
7517 | |
|
7518 | 0 | video_orc_convert_A420_ARGB (task->tmpline, sy, su, sv, sa, |
7519 | 0 | task->data->im[0][0], task->data->im[0][2], |
7520 | 0 | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7521 | 0 | task->width); |
7522 | |
|
7523 | 0 | task->dest->info.finfo->pack_func (task->dest->info.finfo, |
7524 | 0 | (GST_VIDEO_FRAME_IS_INTERLACED (task->dest) ? |
7525 | 0 | GST_VIDEO_PACK_FLAG_INTERLACED : |
7526 | 0 | GST_VIDEO_PACK_FLAG_NONE), |
7527 | 0 | task->tmpline, 0, d, task->dest->info.stride, |
7528 | 0 | task->dest->info.chroma_site, i + task->out_y, task->width); |
7529 | 0 | } |
7530 | 0 | } |
7531 | | |
7532 | | static void |
7533 | | convert_A420_pack_ARGB (GstVideoConverter * convert, const GstVideoFrame * src, |
7534 | | GstVideoFrame * dest) |
7535 | 0 | { |
7536 | 0 | int i; |
7537 | 0 | gint width = convert->in_width; |
7538 | 0 | gint height = convert->in_height; |
7539 | 0 | MatrixData *data = &convert->convert_matrix; |
7540 | 0 | FConvertTask *tasks; |
7541 | 0 | FConvertTask **tasks_p; |
7542 | 0 | gint n_threads; |
7543 | 0 | gint lines_per_thread; |
7544 | |
|
7545 | 0 | n_threads = convert->conversion_runner->n_threads; |
7546 | 0 | tasks = convert->tasks[0] = |
7547 | 0 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
7548 | 0 | tasks_p = convert->tasks_p[0] = |
7549 | 0 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
7550 | |
|
7551 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7552 | |
|
7553 | 0 | for (i = 0; i < n_threads; i++) { |
7554 | 0 | tasks[i].src = src; |
7555 | 0 | tasks[i].dest = dest; |
7556 | |
|
7557 | 0 | tasks[i].width = width; |
7558 | 0 | tasks[i].data = data; |
7559 | 0 | tasks[i].in_x = convert->in_x; |
7560 | 0 | tasks[i].in_y = convert->in_y; |
7561 | 0 | tasks[i].out_x = convert->out_x; |
7562 | 0 | tasks[i].out_y = convert->out_y; |
7563 | 0 | tasks[i].tmpline = convert->tmpline[i]; |
7564 | |
|
7565 | 0 | tasks[i].height_0 = i * lines_per_thread; |
7566 | 0 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
7567 | 0 | tasks[i].height_1 = MIN (height, tasks[i].height_1); |
7568 | |
|
7569 | 0 | tasks_p[i] = &tasks[i]; |
7570 | 0 | } |
7571 | |
|
7572 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7573 | 0 | (GstParallelizedTaskFunc) convert_A420_pack_ARGB_task, |
7574 | 0 | (gpointer) tasks_p); |
7575 | |
|
7576 | 0 | convert_fill_border (convert, dest); |
7577 | 0 | } |
7578 | | |
7579 | | static void |
7580 | | convert_A420_BGRA_task (FConvertTask * task) |
7581 | 0 | { |
7582 | 0 | gint i; |
7583 | |
|
7584 | 0 | for (i = task->height_0; i < task->height_1; i++) { |
7585 | 0 | guint8 *sy, *su, *sv, *sa, *d; |
7586 | |
|
7587 | 0 | d = FRAME_GET_LINE (task->dest, i + task->out_y); |
7588 | 0 | d += (task->out_x * 4); |
7589 | 0 | sy = FRAME_GET_Y_LINE (task->src, i + task->in_y); |
7590 | 0 | sy += task->in_x; |
7591 | 0 | su = FRAME_GET_U_LINE (task->src, (i + task->in_y) >> 1); |
7592 | 0 | su += (task->in_x >> 1); |
7593 | 0 | sv = FRAME_GET_V_LINE (task->src, (i + task->in_y) >> 1); |
7594 | 0 | sv += (task->in_x >> 1); |
7595 | 0 | sa = FRAME_GET_A_LINE (task->src, i + task->in_y); |
7596 | 0 | sa += task->in_x; |
7597 | |
|
7598 | 0 | video_orc_convert_A420_BGRA (d, sy, su, sv, sa, |
7599 | 0 | task->data->im[0][0], task->data->im[0][2], |
7600 | 0 | task->data->im[2][1], task->data->im[1][1], task->data->im[1][2], |
7601 | 0 | task->width); |
7602 | 0 | } |
7603 | 0 | } |
7604 | | |
7605 | | static void |
7606 | | convert_A420_BGRA (GstVideoConverter * convert, const GstVideoFrame * src, |
7607 | | GstVideoFrame * dest) |
7608 | 0 | { |
7609 | 0 | int i; |
7610 | 0 | gint width = convert->in_width; |
7611 | 0 | gint height = convert->in_height; |
7612 | 0 | MatrixData *data = &convert->convert_matrix; |
7613 | 0 | FConvertTask *tasks; |
7614 | 0 | FConvertTask **tasks_p; |
7615 | 0 | gint n_threads; |
7616 | 0 | gint lines_per_thread; |
7617 | |
|
7618 | 0 | n_threads = convert->conversion_runner->n_threads; |
7619 | 0 | tasks = convert->tasks[0] = |
7620 | 0 | g_renew (FConvertTask, convert->tasks[0], n_threads); |
7621 | 0 | tasks_p = convert->tasks_p[0] = |
7622 | 0 | g_renew (FConvertTask *, convert->tasks_p[0], n_threads); |
7623 | |
|
7624 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
7625 | |
|
7626 | 0 | for (i = 0; i < n_threads; i++) { |
7627 | 0 | tasks[i].src = src; |
7628 | 0 | tasks[i].dest = dest; |
7629 | |
|
7630 | 0 | tasks[i].width = width; |
7631 | 0 | tasks[i].data = data; |
7632 | 0 | tasks[i].in_x = convert->in_x; |
7633 | 0 | tasks[i].in_y = convert->in_y; |
7634 | 0 | tasks[i].out_x = convert->out_x; |
7635 | 0 | tasks[i].out_y = convert->out_y; |
7636 | |
|
7637 | 0 | tasks[i].height_0 = i * lines_per_thread; |
7638 | 0 | tasks[i].height_1 = tasks[i].height_0 + lines_per_thread; |
7639 | 0 | tasks[i].height_1 = MIN (height, tasks[i].height_1); |
7640 | |
|
7641 | 0 | tasks_p[i] = &tasks[i]; |
7642 | 0 | } |
7643 | |
|
7644 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7645 | 0 | (GstParallelizedTaskFunc) convert_A420_BGRA_task, (gpointer) tasks_p); |
7646 | |
|
7647 | 0 | convert_fill_border (convert, dest); |
7648 | 0 | } |
7649 | | |
7650 | | static void |
7651 | | memset_u24 (guint8 * data, guint8 col[3], unsigned int n) |
7652 | 0 | { |
7653 | 0 | unsigned int i; |
7654 | |
|
7655 | 0 | for (i = 0; i < n; i++) { |
7656 | 0 | data[0] = col[0]; |
7657 | 0 | data[1] = col[1]; |
7658 | 0 | data[2] = col[2]; |
7659 | 0 | data += 3; |
7660 | 0 | } |
7661 | 0 | } |
7662 | | |
7663 | | static void |
7664 | | memset_u32_16 (guint8 * data, guint8 col[4], unsigned int n) |
7665 | 0 | { |
7666 | 0 | unsigned int i; |
7667 | |
|
7668 | 0 | for (i = 0; i < n; i += 2) { |
7669 | 0 | data[0] = col[0]; |
7670 | 0 | data[1] = col[1]; |
7671 | 0 | if (i + 1 < n) { |
7672 | 0 | data[2] = col[2]; |
7673 | 0 | data[3] = col[3]; |
7674 | 0 | } |
7675 | 0 | data += 4; |
7676 | 0 | } |
7677 | 0 | } |
7678 | | |
7679 | | static void |
7680 | | memset_u128 (guint8 * data, guint8 col[16], unsigned int n) |
7681 | 0 | { |
7682 | 0 | unsigned int i; |
7683 | |
|
7684 | 0 | for (i = 0; i < n; i++) { |
7685 | 0 | memcpy (data, col, 16); |
7686 | 0 | data += 16; |
7687 | 0 | } |
7688 | 0 | } |
7689 | | |
7690 | | #define MAKE_BORDER_FUNC(func) \ |
7691 | 0 | for (i = 0; i < out_y; i++) \ |
7692 | 0 | func (FRAME_GET_PLANE_LINE (dest, k, i), col, out_maxwidth); \ |
7693 | 0 | if (rb_width || lb_width) { \ |
7694 | 0 | for (i = 0; i < out_height; i++) { \ |
7695 | 0 | guint8 *d = FRAME_GET_PLANE_LINE (dest, k, i + out_y); \ |
7696 | 0 | if (lb_width) \ |
7697 | 0 | func (d, col, lb_width); \ |
7698 | 0 | if (rb_width) \ |
7699 | 0 | func (d + (pstride * r_border), col, rb_width); \ |
7700 | 0 | } \ |
7701 | 0 | } \ |
7702 | 0 | for (i = out_y + out_height; i < out_maxheight; i++) \ |
7703 | 0 | func (FRAME_GET_PLANE_LINE (dest, k, i), col, out_maxwidth); \ |
7704 | | |
7705 | | static void |
7706 | | convert_fill_border (GstVideoConverter * convert, GstVideoFrame * dest) |
7707 | 1.05k | { |
7708 | 1.05k | int k, n_planes; |
7709 | 1.05k | const GstVideoFormatInfo *out_finfo; |
7710 | | |
7711 | 1.05k | if (!convert->fill_border || !convert->borderline) |
7712 | 1.05k | return; |
7713 | | |
7714 | 0 | out_finfo = convert->out_info.finfo; |
7715 | |
|
7716 | 0 | n_planes = GST_VIDEO_FRAME_N_PLANES (dest); |
7717 | |
|
7718 | 0 | for (k = 0; k < n_planes; k++) { |
7719 | 0 | gint comp[GST_VIDEO_MAX_COMPONENTS]; |
7720 | 0 | gint i, out_x, out_y, out_width, out_height, pstride, pgroup; |
7721 | 0 | gint r_border, lb_width, rb_width; |
7722 | 0 | gint out_maxwidth, out_maxheight; |
7723 | 0 | gpointer borders; |
7724 | |
|
7725 | 0 | gst_video_format_info_component (out_finfo, k, comp); |
7726 | 0 | out_x = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (out_finfo, comp[0], |
7727 | 0 | convert->out_x); |
7728 | 0 | out_y = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (out_finfo, comp[0], |
7729 | 0 | convert->out_y); |
7730 | 0 | out_width = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (out_finfo, comp[0], |
7731 | 0 | convert->out_width); |
7732 | 0 | out_height = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (out_finfo, comp[0], |
7733 | 0 | convert->out_height); |
7734 | 0 | out_maxwidth = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (out_finfo, comp[0], |
7735 | 0 | convert->out_maxwidth); |
7736 | 0 | out_maxheight = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (out_finfo, comp[0], |
7737 | 0 | convert->out_maxheight); |
7738 | |
|
7739 | 0 | pstride = GST_VIDEO_FORMAT_INFO_PSTRIDE (out_finfo, comp[0]); |
7740 | |
|
7741 | 0 | switch (GST_VIDEO_FORMAT_INFO_FORMAT (out_finfo)) { |
7742 | 0 | case GST_VIDEO_FORMAT_YUY2: |
7743 | 0 | case GST_VIDEO_FORMAT_YVYU: |
7744 | 0 | case GST_VIDEO_FORMAT_UYVY: |
7745 | 0 | pgroup = 42; |
7746 | 0 | out_maxwidth = GST_ROUND_UP_2 (out_maxwidth); |
7747 | 0 | break; |
7748 | 0 | default: |
7749 | 0 | pgroup = pstride; |
7750 | 0 | break; |
7751 | 0 | } |
7752 | | |
7753 | 0 | r_border = out_x + out_width; |
7754 | 0 | rb_width = out_maxwidth - r_border; |
7755 | 0 | lb_width = out_x; |
7756 | |
|
7757 | 0 | borders = convert->borders[k]; |
7758 | |
|
7759 | 0 | switch (pgroup) { |
7760 | 0 | case 1: |
7761 | 0 | { |
7762 | 0 | guint8 col = ((guint8 *) borders)[0]; |
7763 | 0 | MAKE_BORDER_FUNC (memset); |
7764 | 0 | break; |
7765 | 0 | } |
7766 | 0 | case 2: |
7767 | 0 | { |
7768 | 0 | guint16 col = ((guint16 *) borders)[0]; |
7769 | 0 | MAKE_BORDER_FUNC (video_orc_splat_u16); |
7770 | 0 | break; |
7771 | 0 | } |
7772 | 0 | case 3: |
7773 | 0 | { |
7774 | 0 | guint8 col[3]; |
7775 | 0 | col[0] = ((guint8 *) borders)[0]; |
7776 | 0 | col[1] = ((guint8 *) borders)[1]; |
7777 | 0 | col[2] = ((guint8 *) borders)[2]; |
7778 | 0 | MAKE_BORDER_FUNC (memset_u24); |
7779 | 0 | break; |
7780 | 0 | } |
7781 | 0 | case 4: |
7782 | 0 | { |
7783 | 0 | guint32 col = ((guint32 *) borders)[0]; |
7784 | 0 | MAKE_BORDER_FUNC (video_orc_splat_u32); |
7785 | 0 | break; |
7786 | 0 | } |
7787 | 0 | case 8: |
7788 | 0 | { |
7789 | 0 | guint64 col = ((guint64 *) borders)[0]; |
7790 | 0 | MAKE_BORDER_FUNC (video_orc_splat_u64); |
7791 | 0 | break; |
7792 | 0 | } |
7793 | 0 | case 16: |
7794 | 0 | { |
7795 | 0 | guint8 col[16]; |
7796 | 0 | memcpy (col, borders, sizeof (col)); |
7797 | 0 | MAKE_BORDER_FUNC (memset_u128); |
7798 | 0 | break; |
7799 | 0 | } |
7800 | 0 | case 42: |
7801 | 0 | { |
7802 | 0 | guint8 col[4]; |
7803 | 0 | col[0] = ((guint8 *) borders)[0]; |
7804 | 0 | col[2] = ((guint8 *) borders)[2]; |
7805 | 0 | col[1] = ((guint8 *) borders)[r_border & 1 ? 3 : 1]; |
7806 | 0 | col[3] = ((guint8 *) borders)[r_border & 1 ? 1 : 3]; |
7807 | 0 | MAKE_BORDER_FUNC (memset_u32_16); |
7808 | 0 | break; |
7809 | 0 | } |
7810 | 0 | default: |
7811 | 0 | break; |
7812 | 0 | } |
7813 | 0 | } |
7814 | 0 | } |
7815 | | |
7816 | | typedef struct |
7817 | | { |
7818 | | const guint8 *s, *s2; |
7819 | | guint8 *d, *d2; |
7820 | | gint sstride, dstride; |
7821 | | gint width, height; |
7822 | | gint fill; |
7823 | | } FSimpleScaleTask; |
7824 | | |
7825 | | static void |
7826 | | convert_plane_fill_task (FSimpleScaleTask * task) |
7827 | 0 | { |
7828 | 0 | video_orc_memset_2d (task->d, task->dstride, |
7829 | 0 | task->fill, task->width, task->height); |
7830 | 0 | } |
7831 | | |
7832 | | static void |
7833 | | convert_plane_fill (GstVideoConverter * convert, |
7834 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane) |
7835 | 0 | { |
7836 | 0 | guint8 *d; |
7837 | 0 | FSimpleScaleTask *tasks; |
7838 | 0 | FSimpleScaleTask **tasks_p; |
7839 | 0 | gint n_threads; |
7840 | 0 | gint lines_per_thread; |
7841 | 0 | gint i; |
7842 | |
|
7843 | 0 | d = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane]); |
7844 | 0 | d += convert->fout_x[plane]; |
7845 | |
|
7846 | 0 | n_threads = convert->conversion_runner->n_threads; |
7847 | 0 | tasks = convert->tasks[plane] = |
7848 | 0 | g_renew (FSimpleScaleTask, convert->tasks[plane], n_threads); |
7849 | 0 | tasks_p = convert->tasks_p[plane] = |
7850 | 0 | g_renew (FSimpleScaleTask *, convert->tasks_p[plane], n_threads); |
7851 | 0 | lines_per_thread = (convert->fout_height[plane] + n_threads - 1) / n_threads; |
7852 | |
|
7853 | 0 | for (i = 0; i < n_threads; i++) { |
7854 | 0 | tasks[i].d = d + i * lines_per_thread * convert->fout_width[plane]; |
7855 | |
|
7856 | 0 | tasks[i].fill = convert->ffill[plane]; |
7857 | 0 | tasks[i].width = convert->fout_width[plane]; |
7858 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
7859 | 0 | tasks[i].height = MIN (tasks[i].height, convert->fout_height[plane]); |
7860 | 0 | tasks[i].height -= i * lines_per_thread; |
7861 | 0 | tasks[i].dstride = FRAME_GET_PLANE_STRIDE (dest, plane); |
7862 | |
|
7863 | 0 | tasks_p[i] = &tasks[i]; |
7864 | 0 | } |
7865 | |
|
7866 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7867 | 0 | (GstParallelizedTaskFunc) convert_plane_fill_task, (gpointer) tasks_p); |
7868 | 0 | } |
7869 | | |
7870 | | static void |
7871 | | convert_plane_h_double_task (FSimpleScaleTask * task) |
7872 | 0 | { |
7873 | 0 | video_orc_planar_chroma_422_444 (task->d, |
7874 | 0 | task->dstride, task->s, task->sstride, task->width / 2, task->height); |
7875 | 0 | } |
7876 | | |
7877 | | static void |
7878 | | convert_plane_h_double (GstVideoConverter * convert, |
7879 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane) |
7880 | 0 | { |
7881 | 0 | guint8 *s, *d; |
7882 | 0 | gint splane = convert->fsplane[plane]; |
7883 | 0 | FSimpleScaleTask *tasks; |
7884 | 0 | FSimpleScaleTask **tasks_p; |
7885 | 0 | gint n_threads; |
7886 | 0 | gint lines_per_thread; |
7887 | 0 | gint i; |
7888 | |
|
7889 | 0 | s = FRAME_GET_PLANE_LINE (src, splane, convert->fin_y[splane]); |
7890 | 0 | s += convert->fin_x[splane]; |
7891 | 0 | d = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane]); |
7892 | 0 | d += convert->fout_x[plane]; |
7893 | |
|
7894 | 0 | n_threads = convert->conversion_runner->n_threads; |
7895 | 0 | tasks = convert->tasks[plane] = |
7896 | 0 | g_renew (FSimpleScaleTask, convert->tasks[plane], n_threads); |
7897 | 0 | tasks_p = convert->tasks_p[plane] = |
7898 | 0 | g_renew (FSimpleScaleTask *, convert->tasks_p[plane], n_threads); |
7899 | 0 | lines_per_thread = (convert->fout_height[plane] + n_threads - 1) / n_threads; |
7900 | |
|
7901 | 0 | for (i = 0; i < n_threads; i++) { |
7902 | 0 | tasks[i].dstride = FRAME_GET_PLANE_STRIDE (dest, plane); |
7903 | 0 | tasks[i].sstride = FRAME_GET_PLANE_STRIDE (src, splane); |
7904 | |
|
7905 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
7906 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
7907 | |
|
7908 | 0 | tasks[i].width = convert->fout_width[plane]; |
7909 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
7910 | 0 | tasks[i].height = MIN (tasks[i].height, convert->fout_height[plane]); |
7911 | 0 | tasks[i].height -= i * lines_per_thread; |
7912 | |
|
7913 | 0 | tasks_p[i] = &tasks[i]; |
7914 | 0 | } |
7915 | |
|
7916 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7917 | 0 | (GstParallelizedTaskFunc) convert_plane_h_double_task, |
7918 | 0 | (gpointer) tasks_p); |
7919 | 0 | } |
7920 | | |
7921 | | static void |
7922 | | convert_plane_h_halve_task (FSimpleScaleTask * task) |
7923 | 28 | { |
7924 | 28 | video_orc_planar_chroma_444_422 (task->d, |
7925 | 28 | task->dstride, task->s, task->sstride, task->width, task->height); |
7926 | 28 | } |
7927 | | |
7928 | | static void |
7929 | | convert_plane_h_halve (GstVideoConverter * convert, |
7930 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane) |
7931 | 28 | { |
7932 | 28 | guint8 *s, *d; |
7933 | 28 | gint splane = convert->fsplane[plane]; |
7934 | 28 | FSimpleScaleTask *tasks; |
7935 | 28 | FSimpleScaleTask **tasks_p; |
7936 | 28 | gint n_threads; |
7937 | 28 | gint lines_per_thread; |
7938 | 28 | gint i; |
7939 | | |
7940 | 28 | s = FRAME_GET_PLANE_LINE (src, splane, convert->fin_y[splane]); |
7941 | 28 | s += convert->fin_x[splane]; |
7942 | 28 | d = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane]); |
7943 | 28 | d += convert->fout_x[plane]; |
7944 | | |
7945 | 28 | n_threads = convert->conversion_runner->n_threads; |
7946 | 28 | tasks = convert->tasks[plane] = |
7947 | 28 | g_renew (FSimpleScaleTask, convert->tasks[plane], n_threads); |
7948 | 28 | tasks_p = convert->tasks_p[plane] = |
7949 | 28 | g_renew (FSimpleScaleTask *, convert->tasks_p[plane], n_threads); |
7950 | 28 | lines_per_thread = (convert->fout_height[plane] + n_threads - 1) / n_threads; |
7951 | | |
7952 | 56 | for (i = 0; i < n_threads; i++) { |
7953 | 28 | tasks[i].dstride = FRAME_GET_PLANE_STRIDE (dest, plane); |
7954 | 28 | tasks[i].sstride = FRAME_GET_PLANE_STRIDE (src, splane); |
7955 | | |
7956 | 28 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
7957 | 28 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
7958 | | |
7959 | 28 | tasks[i].width = convert->fout_width[plane]; |
7960 | 28 | tasks[i].height = (i + 1) * lines_per_thread; |
7961 | 28 | tasks[i].height = MIN (tasks[i].height, convert->fout_height[plane]); |
7962 | 28 | tasks[i].height -= i * lines_per_thread; |
7963 | | |
7964 | 28 | tasks_p[i] = &tasks[i]; |
7965 | 28 | } |
7966 | | |
7967 | 28 | gst_parallelized_task_runner_run (convert->conversion_runner, |
7968 | 28 | (GstParallelizedTaskFunc) convert_plane_h_halve_task, (gpointer) tasks_p); |
7969 | 28 | } |
7970 | | |
7971 | | static void |
7972 | | convert_plane_v_double_task (FSimpleScaleTask * task) |
7973 | 0 | { |
7974 | 0 | video_orc_planar_chroma_420_422 (task->d, 2 * task->dstride, task->d2, |
7975 | 0 | 2 * task->dstride, task->s, task->sstride, task->width, task->height / 2); |
7976 | 0 | } |
7977 | | |
7978 | | static void |
7979 | | convert_plane_v_double (GstVideoConverter * convert, |
7980 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane) |
7981 | 0 | { |
7982 | 0 | guint8 *s, *d1, *d2; |
7983 | 0 | gint ds, splane = convert->fsplane[plane]; |
7984 | 0 | FSimpleScaleTask *tasks; |
7985 | 0 | FSimpleScaleTask **tasks_p; |
7986 | 0 | gint n_threads; |
7987 | 0 | gint lines_per_thread; |
7988 | 0 | gint i; |
7989 | |
|
7990 | 0 | s = FRAME_GET_PLANE_LINE (src, splane, convert->fin_y[splane]); |
7991 | 0 | s += convert->fin_x[splane]; |
7992 | 0 | d1 = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane]); |
7993 | 0 | d1 += convert->fout_x[plane]; |
7994 | 0 | d2 = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane] + 1); |
7995 | 0 | d2 += convert->fout_x[plane]; |
7996 | 0 | ds = FRAME_GET_PLANE_STRIDE (dest, plane); |
7997 | |
|
7998 | 0 | n_threads = convert->conversion_runner->n_threads; |
7999 | 0 | tasks = convert->tasks[plane] = |
8000 | 0 | g_renew (FSimpleScaleTask, convert->tasks[plane], n_threads); |
8001 | 0 | tasks_p = convert->tasks_p[plane] = |
8002 | 0 | g_renew (FSimpleScaleTask *, convert->tasks_p[plane], n_threads); |
8003 | 0 | lines_per_thread = |
8004 | 0 | GST_ROUND_UP_2 ((convert->fout_height[plane] + n_threads - |
8005 | 0 | 1) / n_threads); |
8006 | |
|
8007 | 0 | for (i = 0; i < n_threads; i++) { |
8008 | 0 | tasks[i].d = d1 + i * lines_per_thread * ds; |
8009 | 0 | tasks[i].d2 = d2 + i * lines_per_thread * ds; |
8010 | 0 | tasks[i].dstride = ds; |
8011 | 0 | tasks[i].sstride = FRAME_GET_PLANE_STRIDE (src, splane); |
8012 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride / 2; |
8013 | |
|
8014 | 0 | tasks[i].width = convert->fout_width[plane]; |
8015 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
8016 | 0 | tasks[i].height = MIN (tasks[i].height, convert->fout_height[plane]); |
8017 | 0 | tasks[i].height -= i * lines_per_thread; |
8018 | |
|
8019 | 0 | tasks_p[i] = &tasks[i]; |
8020 | 0 | } |
8021 | |
|
8022 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
8023 | 0 | (GstParallelizedTaskFunc) convert_plane_v_double_task, |
8024 | 0 | (gpointer) tasks_p); |
8025 | 0 | } |
8026 | | |
8027 | | static void |
8028 | | convert_plane_v_halve_task (FSimpleScaleTask * task) |
8029 | 32 | { |
8030 | 32 | video_orc_planar_chroma_422_420 (task->d, task->dstride, task->s, |
8031 | 32 | 2 * task->sstride, task->s2, 2 * task->sstride, task->width, |
8032 | 32 | task->height); |
8033 | 32 | } |
8034 | | |
8035 | | static void |
8036 | | convert_plane_v_halve (GstVideoConverter * convert, |
8037 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane) |
8038 | 32 | { |
8039 | 32 | guint8 *s1, *s2, *d; |
8040 | 32 | gint ss, ds, splane = convert->fsplane[plane]; |
8041 | 32 | FSimpleScaleTask *tasks; |
8042 | 32 | FSimpleScaleTask **tasks_p; |
8043 | 32 | gint n_threads; |
8044 | 32 | gint lines_per_thread; |
8045 | 32 | gint i; |
8046 | | |
8047 | 32 | s1 = FRAME_GET_PLANE_LINE (src, splane, convert->fin_y[splane]); |
8048 | 32 | s1 += convert->fin_x[splane]; |
8049 | 32 | s2 = FRAME_GET_PLANE_LINE (src, splane, convert->fin_y[splane] + 1); |
8050 | 32 | s2 += convert->fin_x[splane]; |
8051 | 32 | d = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane]); |
8052 | 32 | d += convert->fout_x[plane]; |
8053 | | |
8054 | 32 | ss = FRAME_GET_PLANE_STRIDE (src, splane); |
8055 | 32 | ds = FRAME_GET_PLANE_STRIDE (dest, plane); |
8056 | | |
8057 | 32 | n_threads = convert->conversion_runner->n_threads; |
8058 | 32 | tasks = convert->tasks[plane] = |
8059 | 32 | g_renew (FSimpleScaleTask, convert->tasks[plane], n_threads); |
8060 | 32 | tasks_p = convert->tasks_p[plane] = |
8061 | 32 | g_renew (FSimpleScaleTask *, convert->tasks_p[plane], n_threads); |
8062 | 32 | lines_per_thread = (convert->fout_height[plane] + n_threads - 1) / n_threads; |
8063 | | |
8064 | 64 | for (i = 0; i < n_threads; i++) { |
8065 | 32 | tasks[i].d = d + i * lines_per_thread * ds; |
8066 | 32 | tasks[i].dstride = ds; |
8067 | 32 | tasks[i].s = s1 + i * lines_per_thread * ss * 2; |
8068 | 32 | tasks[i].s2 = s2 + i * lines_per_thread * ss * 2; |
8069 | 32 | tasks[i].sstride = ss; |
8070 | | |
8071 | 32 | tasks[i].width = convert->fout_width[plane]; |
8072 | 32 | tasks[i].height = (i + 1) * lines_per_thread; |
8073 | 32 | tasks[i].height = MIN (tasks[i].height, convert->fout_height[plane]); |
8074 | 32 | tasks[i].height -= i * lines_per_thread; |
8075 | | |
8076 | 32 | tasks_p[i] = &tasks[i]; |
8077 | 32 | } |
8078 | | |
8079 | 32 | gst_parallelized_task_runner_run (convert->conversion_runner, |
8080 | 32 | (GstParallelizedTaskFunc) convert_plane_v_halve_task, (gpointer) tasks_p); |
8081 | 32 | } |
8082 | | |
8083 | | static void |
8084 | | convert_plane_hv_double_task (FSimpleScaleTask * task) |
8085 | 0 | { |
8086 | 0 | video_orc_planar_chroma_420_444 (task->d, 2 * task->dstride, task->d2, |
8087 | 0 | 2 * task->dstride, task->s, task->sstride, (task->width + 1) / 2, |
8088 | 0 | task->height / 2); |
8089 | 0 | } |
8090 | | |
8091 | | static void |
8092 | | convert_plane_hv_double (GstVideoConverter * convert, |
8093 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane) |
8094 | 0 | { |
8095 | 0 | guint8 *s, *d1, *d2; |
8096 | 0 | gint ss, ds, splane = convert->fsplane[plane]; |
8097 | 0 | FSimpleScaleTask *tasks; |
8098 | 0 | FSimpleScaleTask **tasks_p; |
8099 | 0 | gint n_threads; |
8100 | 0 | gint lines_per_thread; |
8101 | 0 | gint i; |
8102 | |
|
8103 | 0 | s = FRAME_GET_PLANE_LINE (src, splane, convert->fin_y[splane]); |
8104 | 0 | s += convert->fin_x[splane]; |
8105 | 0 | d1 = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane]); |
8106 | 0 | d1 += convert->fout_x[plane]; |
8107 | 0 | d2 = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane] + 1); |
8108 | 0 | d2 += convert->fout_x[plane]; |
8109 | 0 | ss = FRAME_GET_PLANE_STRIDE (src, splane); |
8110 | 0 | ds = FRAME_GET_PLANE_STRIDE (dest, plane); |
8111 | |
|
8112 | 0 | n_threads = convert->conversion_runner->n_threads; |
8113 | 0 | tasks = convert->tasks[plane] = |
8114 | 0 | g_renew (FSimpleScaleTask, convert->tasks[plane], n_threads); |
8115 | 0 | tasks_p = convert->tasks_p[plane] = |
8116 | 0 | g_renew (FSimpleScaleTask *, convert->tasks_p[plane], n_threads); |
8117 | 0 | lines_per_thread = |
8118 | 0 | GST_ROUND_UP_2 ((convert->fout_height[plane] + n_threads - |
8119 | 0 | 1) / n_threads); |
8120 | |
|
8121 | 0 | for (i = 0; i < n_threads; i++) { |
8122 | 0 | tasks[i].d = d1 + i * lines_per_thread * ds; |
8123 | 0 | tasks[i].d2 = d2 + i * lines_per_thread * ds; |
8124 | 0 | tasks[i].dstride = ds; |
8125 | 0 | tasks[i].sstride = ss; |
8126 | 0 | tasks[i].s = s + i * lines_per_thread * ss / 2; |
8127 | |
|
8128 | 0 | tasks[i].width = convert->fout_width[plane]; |
8129 | 0 | tasks[i].height = (i + 1) * lines_per_thread; |
8130 | 0 | tasks[i].height = MIN (tasks[i].height, convert->fout_height[plane]); |
8131 | 0 | tasks[i].height -= i * lines_per_thread; |
8132 | |
|
8133 | 0 | tasks_p[i] = &tasks[i]; |
8134 | 0 | } |
8135 | |
|
8136 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
8137 | 0 | (GstParallelizedTaskFunc) convert_plane_hv_double_task, |
8138 | 0 | (gpointer) tasks_p); |
8139 | 0 | } |
8140 | | |
8141 | | static void |
8142 | | convert_plane_hv_halve_task (FSimpleScaleTask * task) |
8143 | 20 | { |
8144 | 20 | video_orc_planar_chroma_444_420 (task->d, task->dstride, task->s, |
8145 | 20 | 2 * task->sstride, task->s2, 2 * task->sstride, task->width, |
8146 | 20 | task->height); |
8147 | 20 | } |
8148 | | |
8149 | | static void |
8150 | | convert_plane_hv_halve (GstVideoConverter * convert, |
8151 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane) |
8152 | 20 | { |
8153 | 20 | guint8 *s1, *s2, *d; |
8154 | 20 | gint ss, ds, splane = convert->fsplane[plane]; |
8155 | 20 | FSimpleScaleTask *tasks; |
8156 | 20 | FSimpleScaleTask **tasks_p; |
8157 | 20 | gint n_threads; |
8158 | 20 | gint lines_per_thread; |
8159 | 20 | gint i; |
8160 | | |
8161 | 20 | s1 = FRAME_GET_PLANE_LINE (src, splane, convert->fin_y[splane]); |
8162 | 20 | s1 += convert->fin_x[splane]; |
8163 | 20 | s2 = FRAME_GET_PLANE_LINE (src, splane, convert->fin_y[splane] + 1); |
8164 | 20 | s2 += convert->fin_x[splane]; |
8165 | 20 | d = FRAME_GET_PLANE_LINE (dest, plane, convert->fout_y[plane]); |
8166 | 20 | d += convert->fout_x[plane]; |
8167 | 20 | ss = FRAME_GET_PLANE_STRIDE (src, splane); |
8168 | 20 | ds = FRAME_GET_PLANE_STRIDE (dest, plane); |
8169 | | |
8170 | 20 | n_threads = convert->conversion_runner->n_threads; |
8171 | 20 | tasks = convert->tasks[plane] = |
8172 | 20 | g_renew (FSimpleScaleTask, convert->tasks[plane], n_threads); |
8173 | 20 | tasks_p = convert->tasks_p[plane] = |
8174 | 20 | g_renew (FSimpleScaleTask *, convert->tasks_p[plane], n_threads); |
8175 | 20 | lines_per_thread = (convert->fout_height[plane] + n_threads - 1) / n_threads; |
8176 | | |
8177 | 40 | for (i = 0; i < n_threads; i++) { |
8178 | 20 | tasks[i].d = d + i * lines_per_thread * ds; |
8179 | 20 | tasks[i].dstride = ds; |
8180 | 20 | tasks[i].s = s1 + i * lines_per_thread * ss * 2; |
8181 | 20 | tasks[i].s2 = s2 + i * lines_per_thread * ss * 2; |
8182 | 20 | tasks[i].sstride = ss; |
8183 | | |
8184 | 20 | tasks[i].width = convert->fout_width[plane]; |
8185 | 20 | tasks[i].height = (i + 1) * lines_per_thread; |
8186 | 20 | tasks[i].height = MIN (tasks[i].height, convert->fout_height[plane]); |
8187 | 20 | tasks[i].height -= i * lines_per_thread; |
8188 | | |
8189 | 20 | tasks_p[i] = &tasks[i]; |
8190 | 20 | } |
8191 | | |
8192 | 20 | gst_parallelized_task_runner_run (convert->conversion_runner, |
8193 | 20 | (GstParallelizedTaskFunc) convert_plane_hv_halve_task, |
8194 | 20 | (gpointer) tasks_p); |
8195 | 20 | } |
8196 | | |
8197 | | typedef struct |
8198 | | { |
8199 | | GstVideoScaler *h_scaler, *v_scaler; |
8200 | | GstVideoFormat format; |
8201 | | const guint8 *s; |
8202 | | guint8 *d; |
8203 | | gint sstride, dstride; |
8204 | | guint x, y, w, h; |
8205 | | } FScaleTask; |
8206 | | |
8207 | | static void |
8208 | | convert_plane_hv_task (FScaleTask * task) |
8209 | 760 | { |
8210 | 760 | gst_video_scaler_2d (task->h_scaler, task->v_scaler, task->format, |
8211 | 760 | (guint8 *) task->s, task->sstride, |
8212 | 760 | task->d, task->dstride, task->x, task->y, task->w, task->h); |
8213 | 760 | } |
8214 | | |
8215 | | static void |
8216 | | convert_plane_hv (GstVideoConverter * convert, |
8217 | | const GstVideoFrame * src, GstVideoFrame * dest, gint plane) |
8218 | 760 | { |
8219 | 760 | gint in_x, in_y, out_x, out_y, out_width, out_height; |
8220 | 760 | GstVideoFormat format; |
8221 | 760 | gint splane = convert->fsplane[plane]; |
8222 | 760 | guint8 *s, *d; |
8223 | 760 | gint sstride, dstride; |
8224 | 760 | FScaleTask *tasks; |
8225 | 760 | FScaleTask **tasks_p; |
8226 | 760 | gint i, n_threads, lines_per_thread; |
8227 | | |
8228 | 760 | in_x = convert->fin_x[splane]; |
8229 | 760 | in_y = convert->fin_y[splane]; |
8230 | 760 | out_x = convert->fout_x[plane]; |
8231 | 760 | out_y = convert->fout_y[plane]; |
8232 | 760 | out_width = convert->fout_width[plane]; |
8233 | 760 | out_height = convert->fout_height[plane]; |
8234 | 760 | format = convert->fformat[plane]; |
8235 | | |
8236 | 760 | s = FRAME_GET_PLANE_LINE (src, splane, in_y); |
8237 | 760 | s += in_x; |
8238 | 760 | d = FRAME_GET_PLANE_LINE (dest, plane, out_y); |
8239 | 760 | d += out_x; |
8240 | | |
8241 | 760 | sstride = FRAME_GET_PLANE_STRIDE (src, splane); |
8242 | 760 | dstride = FRAME_GET_PLANE_STRIDE (dest, plane); |
8243 | | |
8244 | 760 | n_threads = convert->conversion_runner->n_threads; |
8245 | 760 | tasks = convert->tasks[plane] = |
8246 | 760 | g_renew (FScaleTask, convert->tasks[plane], n_threads); |
8247 | 760 | tasks_p = convert->tasks_p[plane] = |
8248 | 760 | g_renew (FScaleTask *, convert->tasks_p[plane], n_threads); |
8249 | | |
8250 | 760 | lines_per_thread = (out_height + n_threads - 1) / n_threads; |
8251 | | |
8252 | 1.52k | for (i = 0; i < n_threads; i++) { |
8253 | 760 | tasks[i].h_scaler = |
8254 | 760 | convert->fh_scaler[plane].scaler ? convert-> |
8255 | 760 | fh_scaler[plane].scaler[i] : NULL; |
8256 | 760 | tasks[i].v_scaler = |
8257 | 760 | convert->fv_scaler[plane].scaler ? convert-> |
8258 | 760 | fv_scaler[plane].scaler[i] : NULL; |
8259 | 760 | tasks[i].format = format; |
8260 | 760 | tasks[i].s = s; |
8261 | 760 | tasks[i].d = d; |
8262 | 760 | tasks[i].sstride = sstride; |
8263 | 760 | tasks[i].dstride = dstride; |
8264 | | |
8265 | 760 | tasks[i].x = 0; |
8266 | 760 | tasks[i].w = out_width; |
8267 | | |
8268 | 760 | tasks[i].y = i * lines_per_thread; |
8269 | 760 | tasks[i].h = tasks[i].y + lines_per_thread; |
8270 | 760 | tasks[i].h = MIN (out_height, tasks[i].h); |
8271 | | |
8272 | 760 | tasks_p[i] = &tasks[i]; |
8273 | 760 | } |
8274 | | |
8275 | 760 | gst_parallelized_task_runner_run (convert->conversion_runner, |
8276 | 760 | (GstParallelizedTaskFunc) convert_plane_hv_task, (gpointer) tasks_p); |
8277 | 760 | } |
8278 | | |
8279 | | static void |
8280 | | convert_scale_planes (GstVideoConverter * convert, |
8281 | | const GstVideoFrame * src, GstVideoFrame * dest) |
8282 | 445 | { |
8283 | 445 | int i, n_planes; |
8284 | | |
8285 | 445 | n_planes = GST_VIDEO_FRAME_N_PLANES (dest); |
8286 | 1.28k | for (i = 0; i < n_planes; i++) { |
8287 | 840 | if (convert->fconvert[i]) |
8288 | 840 | convert->fconvert[i] (convert, src, dest, i); |
8289 | 840 | } |
8290 | 445 | convert_fill_border (convert, dest); |
8291 | 445 | } |
8292 | | |
8293 | | static GstVideoFormat |
8294 | | get_scale_format (GstVideoFormat format, gint plane) |
8295 | 840 | { |
8296 | 840 | GstVideoFormat res = GST_VIDEO_FORMAT_UNKNOWN; |
8297 | | |
8298 | 840 | switch (format) { |
8299 | 369 | case GST_VIDEO_FORMAT_I420: |
8300 | 510 | case GST_VIDEO_FORMAT_YV12: |
8301 | 510 | case GST_VIDEO_FORMAT_Y41B: |
8302 | 510 | case GST_VIDEO_FORMAT_Y42B: |
8303 | 510 | case GST_VIDEO_FORMAT_Y444: |
8304 | 512 | case GST_VIDEO_FORMAT_GRAY8: |
8305 | 512 | case GST_VIDEO_FORMAT_A420: |
8306 | 512 | case GST_VIDEO_FORMAT_A422: |
8307 | 512 | case GST_VIDEO_FORMAT_A444: |
8308 | 512 | case GST_VIDEO_FORMAT_YUV9: |
8309 | 512 | case GST_VIDEO_FORMAT_YVU9: |
8310 | 512 | case GST_VIDEO_FORMAT_GBR: |
8311 | 512 | case GST_VIDEO_FORMAT_GBRA: |
8312 | 512 | case GST_VIDEO_FORMAT_RGBP: |
8313 | 512 | case GST_VIDEO_FORMAT_BGRP: |
8314 | 512 | res = GST_VIDEO_FORMAT_GRAY8; |
8315 | 512 | break; |
8316 | 0 | case GST_VIDEO_FORMAT_GRAY16_BE: |
8317 | 80 | case GST_VIDEO_FORMAT_GRAY16_LE: |
8318 | 80 | res = GST_VIDEO_FORMAT_GRAY16_BE; |
8319 | 80 | break; |
8320 | 25 | case GST_VIDEO_FORMAT_YUY2: |
8321 | 58 | case GST_VIDEO_FORMAT_UYVY: |
8322 | 58 | case GST_VIDEO_FORMAT_VYUY: |
8323 | 58 | case GST_VIDEO_FORMAT_YVYU: |
8324 | 65 | case GST_VIDEO_FORMAT_AYUV: |
8325 | 65 | case GST_VIDEO_FORMAT_VUYA: |
8326 | 65 | case GST_VIDEO_FORMAT_RGBx: |
8327 | 65 | case GST_VIDEO_FORMAT_BGRx: |
8328 | 65 | case GST_VIDEO_FORMAT_xRGB: |
8329 | 65 | case GST_VIDEO_FORMAT_xBGR: |
8330 | 68 | case GST_VIDEO_FORMAT_RGBA: |
8331 | 82 | case GST_VIDEO_FORMAT_BGRA: |
8332 | 87 | case GST_VIDEO_FORMAT_ARGB: |
8333 | 90 | case GST_VIDEO_FORMAT_ABGR: |
8334 | 108 | case GST_VIDEO_FORMAT_RGB: |
8335 | 138 | case GST_VIDEO_FORMAT_BGR: |
8336 | 138 | case GST_VIDEO_FORMAT_v308: |
8337 | 138 | case GST_VIDEO_FORMAT_IYU2: |
8338 | 138 | case GST_VIDEO_FORMAT_ARGB64: |
8339 | 138 | case GST_VIDEO_FORMAT_ARGB64_LE: |
8340 | 138 | case GST_VIDEO_FORMAT_ARGB64_BE: |
8341 | 138 | case GST_VIDEO_FORMAT_RGBA64_BE: |
8342 | 138 | case GST_VIDEO_FORMAT_RGBA64_LE: |
8343 | 138 | case GST_VIDEO_FORMAT_BGRA64_BE: |
8344 | 138 | case GST_VIDEO_FORMAT_BGRA64_LE: |
8345 | 138 | case GST_VIDEO_FORMAT_ABGR64_BE: |
8346 | 138 | case GST_VIDEO_FORMAT_ABGR64_LE: |
8347 | 138 | case GST_VIDEO_FORMAT_AYUV64: |
8348 | 138 | case GST_VIDEO_FORMAT_RBGA: |
8349 | 138 | res = format; |
8350 | 138 | break; |
8351 | 0 | case GST_VIDEO_FORMAT_RGB15: |
8352 | 0 | case GST_VIDEO_FORMAT_BGR15: |
8353 | 0 | case GST_VIDEO_FORMAT_RGB16: |
8354 | 0 | case GST_VIDEO_FORMAT_BGR16: |
8355 | 0 | res = GST_VIDEO_FORMAT_NV12; |
8356 | 0 | break; |
8357 | 60 | case GST_VIDEO_FORMAT_NV12: |
8358 | 110 | case GST_VIDEO_FORMAT_NV21: |
8359 | 110 | case GST_VIDEO_FORMAT_NV16: |
8360 | 110 | case GST_VIDEO_FORMAT_NV61: |
8361 | 110 | case GST_VIDEO_FORMAT_NV24: |
8362 | 110 | res = plane == 0 ? GST_VIDEO_FORMAT_GRAY8 : GST_VIDEO_FORMAT_NV12; |
8363 | 110 | break; |
8364 | 0 | case GST_VIDEO_FORMAT_AV12: |
8365 | 0 | res = (plane == 0 |
8366 | 0 | || plane == 2) ? GST_VIDEO_FORMAT_GRAY8 : GST_VIDEO_FORMAT_NV12; |
8367 | 0 | break; |
8368 | 0 | case GST_VIDEO_FORMAT_UNKNOWN: |
8369 | 0 | case GST_VIDEO_FORMAT_ENCODED: |
8370 | 0 | case GST_VIDEO_FORMAT_v210: |
8371 | 0 | case GST_VIDEO_FORMAT_v216: |
8372 | 0 | case GST_VIDEO_FORMAT_Y210: |
8373 | 0 | case GST_VIDEO_FORMAT_Y410: |
8374 | 0 | case GST_VIDEO_FORMAT_RGBA_F16LE: |
8375 | 0 | case GST_VIDEO_FORMAT_RGBA_F16BE: |
8376 | 0 | case GST_VIDEO_FORMAT_RGBA_F32LE: |
8377 | 0 | case GST_VIDEO_FORMAT_RGBA_F32BE: |
8378 | 0 | case GST_VIDEO_FORMAT_ARGB_F32: |
8379 | 0 | case GST_VIDEO_FORMAT_UYVP: |
8380 | 0 | case GST_VIDEO_FORMAT_RGB8P: |
8381 | 0 | case GST_VIDEO_FORMAT_IYU1: |
8382 | 0 | case GST_VIDEO_FORMAT_r210: |
8383 | 0 | case GST_VIDEO_FORMAT_I420_10BE: |
8384 | 0 | case GST_VIDEO_FORMAT_I420_10LE: |
8385 | 0 | case GST_VIDEO_FORMAT_I422_10BE: |
8386 | 0 | case GST_VIDEO_FORMAT_I422_10LE: |
8387 | 0 | case GST_VIDEO_FORMAT_Y444_10BE: |
8388 | 0 | case GST_VIDEO_FORMAT_Y444_10LE: |
8389 | 0 | case GST_VIDEO_FORMAT_I420_12BE: |
8390 | 0 | case GST_VIDEO_FORMAT_I420_12LE: |
8391 | 0 | case GST_VIDEO_FORMAT_I422_12BE: |
8392 | 0 | case GST_VIDEO_FORMAT_I422_12LE: |
8393 | 0 | case GST_VIDEO_FORMAT_Y444_12BE: |
8394 | 0 | case GST_VIDEO_FORMAT_Y444_12LE: |
8395 | 0 | case GST_VIDEO_FORMAT_GBR_10BE: |
8396 | 0 | case GST_VIDEO_FORMAT_GBR_10LE: |
8397 | 0 | case GST_VIDEO_FORMAT_GBRA_10BE: |
8398 | 0 | case GST_VIDEO_FORMAT_GBRA_10LE: |
8399 | 0 | case GST_VIDEO_FORMAT_GBR_12BE: |
8400 | 0 | case GST_VIDEO_FORMAT_GBR_12LE: |
8401 | 0 | case GST_VIDEO_FORMAT_GBRA_12BE: |
8402 | 0 | case GST_VIDEO_FORMAT_GBRA_12LE: |
8403 | 0 | case GST_VIDEO_FORMAT_GBR_16BE: |
8404 | 0 | case GST_VIDEO_FORMAT_GBR_16LE: |
8405 | 0 | case GST_VIDEO_FORMAT_NV12_64Z32: |
8406 | 0 | case GST_VIDEO_FORMAT_NV12_4L4: |
8407 | 0 | case GST_VIDEO_FORMAT_NV12_32L32: |
8408 | 0 | case GST_VIDEO_FORMAT_NV12_16L32S: |
8409 | 0 | case GST_VIDEO_FORMAT_A420_10BE: |
8410 | 0 | case GST_VIDEO_FORMAT_A420_10LE: |
8411 | 0 | case GST_VIDEO_FORMAT_A422_10BE: |
8412 | 0 | case GST_VIDEO_FORMAT_A422_10LE: |
8413 | 0 | case GST_VIDEO_FORMAT_A444_10BE: |
8414 | 0 | case GST_VIDEO_FORMAT_A444_10LE: |
8415 | 0 | case GST_VIDEO_FORMAT_A444_12BE: |
8416 | 0 | case GST_VIDEO_FORMAT_A444_12LE: |
8417 | 0 | case GST_VIDEO_FORMAT_A422_12BE: |
8418 | 0 | case GST_VIDEO_FORMAT_A422_12LE: |
8419 | 0 | case GST_VIDEO_FORMAT_A420_12BE: |
8420 | 0 | case GST_VIDEO_FORMAT_A420_12LE: |
8421 | 0 | case GST_VIDEO_FORMAT_A444_16BE: |
8422 | 0 | case GST_VIDEO_FORMAT_A444_16LE: |
8423 | 0 | case GST_VIDEO_FORMAT_A422_16BE: |
8424 | 0 | case GST_VIDEO_FORMAT_A422_16LE: |
8425 | 0 | case GST_VIDEO_FORMAT_A420_16BE: |
8426 | 0 | case GST_VIDEO_FORMAT_A420_16LE: |
8427 | 0 | case GST_VIDEO_FORMAT_P010_10BE: |
8428 | 0 | case GST_VIDEO_FORMAT_P010_10LE: |
8429 | 0 | case GST_VIDEO_FORMAT_GRAY10_LE16: |
8430 | 0 | case GST_VIDEO_FORMAT_GRAY10_LE32: |
8431 | 0 | case GST_VIDEO_FORMAT_NV12_10LE32: |
8432 | 0 | case GST_VIDEO_FORMAT_NV16_10LE32: |
8433 | 0 | case GST_VIDEO_FORMAT_NV12_10LE40: |
8434 | 0 | case GST_VIDEO_FORMAT_NV16_10LE40: |
8435 | 0 | case GST_VIDEO_FORMAT_BGR10A2_LE: |
8436 | 0 | case GST_VIDEO_FORMAT_RGB10A2_LE: |
8437 | 0 | case GST_VIDEO_FORMAT_BGR10x2_LE: |
8438 | 0 | case GST_VIDEO_FORMAT_RGB10x2_LE: |
8439 | 0 | case GST_VIDEO_FORMAT_Y444_16BE: |
8440 | 0 | case GST_VIDEO_FORMAT_Y444_16LE: |
8441 | 0 | case GST_VIDEO_FORMAT_P016_BE: |
8442 | 0 | case GST_VIDEO_FORMAT_P016_LE: |
8443 | 0 | case GST_VIDEO_FORMAT_P012_BE: |
8444 | 0 | case GST_VIDEO_FORMAT_P012_LE: |
8445 | 0 | case GST_VIDEO_FORMAT_Y212_BE: |
8446 | 0 | case GST_VIDEO_FORMAT_Y212_LE: |
8447 | 0 | case GST_VIDEO_FORMAT_Y216_BE: |
8448 | 0 | case GST_VIDEO_FORMAT_Y216_LE: |
8449 | 0 | case GST_VIDEO_FORMAT_Y412_BE: |
8450 | 0 | case GST_VIDEO_FORMAT_Y412_LE: |
8451 | 0 | case GST_VIDEO_FORMAT_Y416_BE: |
8452 | 0 | case GST_VIDEO_FORMAT_Y416_LE: |
8453 | 0 | case GST_VIDEO_FORMAT_NV12_8L128: |
8454 | 0 | case GST_VIDEO_FORMAT_NV12_10BE_8L128: |
8455 | 0 | case GST_VIDEO_FORMAT_NV12_10LE40_4L4: |
8456 | 0 | case GST_VIDEO_FORMAT_DMA_DRM: |
8457 | 0 | case GST_VIDEO_FORMAT_AHARDWARE_BUFFER: |
8458 | 0 | case GST_VIDEO_FORMAT_MT2110T: |
8459 | 0 | case GST_VIDEO_FORMAT_MT2110R: |
8460 | 0 | case GST_VIDEO_FORMAT_RGBP_F16LE: |
8461 | 0 | case GST_VIDEO_FORMAT_RGBP_F16BE: |
8462 | 0 | case GST_VIDEO_FORMAT_RGBP_F32LE: |
8463 | 0 | case GST_VIDEO_FORMAT_RGBP_F32BE: |
8464 | 0 | case GST_VIDEO_FORMAT_RGB_F16LE: |
8465 | 0 | case GST_VIDEO_FORMAT_RGB_F16BE: |
8466 | 0 | case GST_VIDEO_FORMAT_RGB_F32LE: |
8467 | 0 | case GST_VIDEO_FORMAT_RGB_F32BE: |
8468 | 0 | case GST_VIDEO_FORMAT_AYUV_F32: |
8469 | 0 | case GST_VIDEO_FORMAT_GRAY_F16LE: |
8470 | 0 | case GST_VIDEO_FORMAT_GRAY_F16BE: |
8471 | 0 | case GST_VIDEO_FORMAT_GRAY_F32LE: |
8472 | 0 | case GST_VIDEO_FORMAT_GRAY_F32BE: |
8473 | 0 | res = format; |
8474 | 0 | g_assert_not_reached (); |
8475 | 0 | break; |
8476 | 840 | } |
8477 | 840 | return res; |
8478 | 840 | } |
8479 | | |
8480 | | static gboolean |
8481 | | is_merge_yuv (GstVideoInfo * info) |
8482 | 138 | { |
8483 | 138 | switch (GST_VIDEO_INFO_FORMAT (info)) { |
8484 | 25 | case GST_VIDEO_FORMAT_YUY2: |
8485 | 25 | case GST_VIDEO_FORMAT_YVYU: |
8486 | 58 | case GST_VIDEO_FORMAT_UYVY: |
8487 | 58 | case GST_VIDEO_FORMAT_VYUY: |
8488 | 58 | return TRUE; |
8489 | 80 | default: |
8490 | 80 | return FALSE; |
8491 | 138 | } |
8492 | 138 | } |
8493 | | |
8494 | | static gboolean |
8495 | | setup_scale (GstVideoConverter * convert) |
8496 | 452 | { |
8497 | 452 | int i, n_planes; |
8498 | 452 | gint method, cr_method, in_width, in_height, out_width, out_height; |
8499 | 452 | guint taps; |
8500 | 452 | GstVideoInfo *in_info, *out_info; |
8501 | 452 | const GstVideoFormatInfo *in_finfo, *out_finfo; |
8502 | 452 | GstVideoFormat in_format, out_format; |
8503 | 452 | gboolean interlaced; |
8504 | 452 | guint n_threads = convert->conversion_runner->n_threads; |
8505 | | |
8506 | 452 | in_info = &convert->in_info; |
8507 | 452 | out_info = &convert->out_info; |
8508 | | |
8509 | 452 | in_finfo = in_info->finfo; |
8510 | 452 | out_finfo = out_info->finfo; |
8511 | | |
8512 | 452 | n_planes = GST_VIDEO_INFO_N_PLANES (out_info); |
8513 | | |
8514 | 452 | interlaced = GST_VIDEO_INFO_IS_INTERLACED (&convert->in_info) |
8515 | 0 | && GST_VIDEO_INFO_INTERLACE_MODE (&convert->in_info) != |
8516 | 0 | GST_VIDEO_INTERLACE_MODE_ALTERNATE; |
8517 | | |
8518 | 452 | method = GET_OPT_RESAMPLER_METHOD (convert); |
8519 | 452 | if (method == GST_VIDEO_RESAMPLER_METHOD_NEAREST) |
8520 | 0 | cr_method = method; |
8521 | 452 | else |
8522 | 452 | cr_method = GET_OPT_CHROMA_RESAMPLER_METHOD (convert); |
8523 | 452 | taps = GET_OPT_RESAMPLER_TAPS (convert); |
8524 | | |
8525 | 452 | in_format = GST_VIDEO_INFO_FORMAT (in_info); |
8526 | 452 | out_format = GST_VIDEO_INFO_FORMAT (out_info); |
8527 | | |
8528 | 452 | switch (in_format) { |
8529 | 0 | case GST_VIDEO_FORMAT_RGB15: |
8530 | 7 | case GST_VIDEO_FORMAT_RGB16: |
8531 | 7 | case GST_VIDEO_FORMAT_BGR15: |
8532 | 7 | case GST_VIDEO_FORMAT_BGR16: |
8533 | 7 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
8534 | 7 | case GST_VIDEO_FORMAT_GRAY16_BE: |
8535 | | #else |
8536 | | case GST_VIDEO_FORMAT_GRAY16_LE: |
8537 | | #endif |
8538 | 7 | if (method != GST_VIDEO_RESAMPLER_METHOD_NEAREST) { |
8539 | 7 | GST_LOG ("%s only with nearest resampling", |
8540 | 7 | gst_video_format_to_string (in_format)); |
8541 | 7 | return FALSE; |
8542 | 7 | } |
8543 | 0 | break; |
8544 | 445 | default: |
8545 | 445 | break; |
8546 | 452 | } |
8547 | | |
8548 | 445 | in_width = convert->in_width; |
8549 | 445 | in_height = convert->in_height; |
8550 | 445 | out_width = convert->out_width; |
8551 | 445 | out_height = convert->out_height; |
8552 | | |
8553 | 445 | if (n_planes == 1 && !GST_VIDEO_FORMAT_INFO_IS_GRAY (out_finfo)) { |
8554 | 138 | gint pstride; |
8555 | 138 | guint j; |
8556 | | |
8557 | 138 | if (is_merge_yuv (in_info)) { |
8558 | 58 | GstVideoScaler *y_scaler, *uv_scaler; |
8559 | | |
8560 | 58 | if (in_width != out_width) { |
8561 | 55 | convert->fh_scaler[0].scaler = g_new (GstVideoScaler *, n_threads); |
8562 | 110 | for (j = 0; j < n_threads; j++) { |
8563 | 55 | y_scaler = |
8564 | 55 | gst_video_scaler_new (method, GST_VIDEO_SCALER_FLAG_NONE, taps, |
8565 | 55 | GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (in_finfo, GST_VIDEO_COMP_Y, |
8566 | 55 | in_width), GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (out_finfo, |
8567 | 55 | GST_VIDEO_COMP_Y, out_width), convert->config); |
8568 | 55 | uv_scaler = |
8569 | 55 | gst_video_scaler_new (method, GST_VIDEO_SCALER_FLAG_NONE, |
8570 | 55 | gst_video_scaler_get_max_taps (y_scaler), |
8571 | 55 | GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (in_finfo, GST_VIDEO_COMP_U, |
8572 | 55 | in_width), GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (out_finfo, |
8573 | 55 | GST_VIDEO_COMP_U, out_width), convert->config); |
8574 | | |
8575 | 55 | convert->fh_scaler[0].scaler[j] = |
8576 | 55 | gst_video_scaler_combine_packed_YUV (y_scaler, uv_scaler, |
8577 | 55 | in_format, out_format); |
8578 | | |
8579 | 55 | gst_video_scaler_free (y_scaler); |
8580 | 55 | gst_video_scaler_free (uv_scaler); |
8581 | 55 | } |
8582 | 55 | } else { |
8583 | 3 | convert->fh_scaler[0].scaler = NULL; |
8584 | 3 | } |
8585 | | |
8586 | 58 | pstride = GST_VIDEO_FORMAT_INFO_PSTRIDE (out_finfo, GST_VIDEO_COMP_Y); |
8587 | 58 | convert->fin_x[0] = GST_ROUND_UP_2 (convert->in_x) * pstride; |
8588 | 58 | convert->fout_x[0] = GST_ROUND_UP_2 (convert->out_x) * pstride; |
8589 | | |
8590 | 80 | } else { |
8591 | 80 | if (in_width != out_width && in_width != 0 && out_width != 0) { |
8592 | 74 | convert->fh_scaler[0].scaler = g_new (GstVideoScaler *, n_threads); |
8593 | 148 | for (j = 0; j < n_threads; j++) { |
8594 | 74 | convert->fh_scaler[0].scaler[j] = |
8595 | 74 | gst_video_scaler_new (method, GST_VIDEO_SCALER_FLAG_NONE, taps, |
8596 | 74 | in_width, out_width, convert->config); |
8597 | 74 | } |
8598 | 74 | } else { |
8599 | 6 | convert->fh_scaler[0].scaler = NULL; |
8600 | 6 | } |
8601 | | |
8602 | 80 | pstride = GST_VIDEO_FORMAT_INFO_PSTRIDE (out_finfo, GST_VIDEO_COMP_R); |
8603 | 80 | convert->fin_x[0] = convert->in_x * pstride; |
8604 | 80 | convert->fout_x[0] = convert->out_x * pstride; |
8605 | 80 | } |
8606 | | |
8607 | 138 | if (in_height != out_height && in_height != 0 && out_height != 0) { |
8608 | 112 | convert->fv_scaler[0].scaler = g_new (GstVideoScaler *, n_threads); |
8609 | | |
8610 | 224 | for (j = 0; j < n_threads; j++) { |
8611 | 112 | convert->fv_scaler[0].scaler[j] = |
8612 | 112 | gst_video_scaler_new (method, |
8613 | 112 | interlaced ? |
8614 | 112 | GST_VIDEO_SCALER_FLAG_INTERLACED : GST_VIDEO_SCALER_FLAG_NONE, taps, |
8615 | 112 | in_height, out_height, convert->config); |
8616 | 112 | } |
8617 | 112 | } else { |
8618 | 26 | convert->fv_scaler[0].scaler = NULL; |
8619 | 26 | } |
8620 | | |
8621 | 138 | convert->fin_y[0] = convert->in_y; |
8622 | 138 | convert->fout_y[0] = convert->out_y; |
8623 | 138 | convert->fout_width[0] = out_width; |
8624 | 138 | convert->fout_height[0] = out_height; |
8625 | 138 | convert->fconvert[0] = convert_plane_hv; |
8626 | 138 | convert->fformat[0] = get_scale_format (in_format, 0); |
8627 | 138 | convert->fsplane[0] = 0; |
8628 | 307 | } else { |
8629 | 1.00k | for (i = 0; i < n_planes; i++) { |
8630 | 702 | gint out_comp[GST_VIDEO_MAX_COMPONENTS]; |
8631 | 702 | gint comp, j, iw, ih, ow, oh, pstride; |
8632 | 702 | gboolean need_v_scaler, need_h_scaler; |
8633 | 702 | GstStructure *config; |
8634 | 702 | gint resample_method; |
8635 | | |
8636 | 702 | gst_video_format_info_component (out_finfo, i, out_comp); |
8637 | 702 | ow = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (out_finfo, out_comp[0], |
8638 | 702 | out_width); |
8639 | 702 | oh = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (out_finfo, out_comp[0], |
8640 | 702 | out_height); |
8641 | 702 | pstride = GST_VIDEO_FORMAT_INFO_PSTRIDE (out_finfo, out_comp[0]); |
8642 | | |
8643 | | /* find the component in this plane and map it to the plane of |
8644 | | * the source */ |
8645 | 702 | if (out_comp[0] < GST_VIDEO_FORMAT_INFO_N_COMPONENTS (in_finfo)) { |
8646 | 702 | comp = out_comp[0]; |
8647 | 702 | iw = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (in_finfo, comp, in_width); |
8648 | 702 | ih = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (in_finfo, comp, in_height); |
8649 | 702 | convert->fin_x[i] = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (in_finfo, comp, |
8650 | 702 | convert->in_x); |
8651 | 702 | convert->fin_x[i] *= pstride; |
8652 | 702 | convert->fin_y[i] = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (in_finfo, comp, |
8653 | 702 | convert->in_y); |
8654 | 702 | } else { |
8655 | | /* we will use a fill instead, setting the parameters to an invalid |
8656 | | * size to reduce confusion */ |
8657 | 0 | comp = -1; |
8658 | 0 | iw = ih = -1; |
8659 | 0 | convert->fin_x[i] = -1; |
8660 | 0 | convert->fin_y[i] = -1; |
8661 | 0 | } |
8662 | | |
8663 | 702 | convert->fout_width[i] = ow; |
8664 | 702 | convert->fout_height[i] = oh; |
8665 | | |
8666 | 702 | convert->fout_x[i] = GST_VIDEO_FORMAT_INFO_SCALE_WIDTH (out_finfo, |
8667 | 702 | out_comp[0], convert->out_x); |
8668 | 702 | convert->fout_x[i] *= pstride; |
8669 | 702 | convert->fout_y[i] = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (out_finfo, |
8670 | 702 | out_comp[0], convert->out_y); |
8671 | | |
8672 | 702 | GST_LOG ("plane %d: %dx%d -> %dx%d", i, iw, ih, ow, oh); |
8673 | 702 | GST_LOG ("plane %d: pstride %d", i, pstride); |
8674 | 702 | GST_LOG ("plane %d: in_x %d, in_y %d", i, convert->fin_x[i], |
8675 | 702 | convert->fin_y[i]); |
8676 | 702 | GST_LOG ("plane %d: out_x %d, out_y %d", i, convert->fout_x[i], |
8677 | 702 | convert->fout_y[i]); |
8678 | | |
8679 | 702 | if (comp == -1) { |
8680 | 0 | convert->fconvert[i] = convert_plane_fill; |
8681 | 0 | if (GST_VIDEO_INFO_IS_YUV (out_info)) { |
8682 | 0 | if (i == 3) |
8683 | 0 | convert->ffill[i] = convert->alpha_value; |
8684 | 0 | if (i == 0) |
8685 | 0 | convert->ffill[i] = 0x00; |
8686 | 0 | else |
8687 | 0 | convert->ffill[i] = 0x80; |
8688 | 0 | } else { |
8689 | 0 | if (i == 3) |
8690 | 0 | convert->ffill[i] = convert->alpha_value; |
8691 | 0 | else |
8692 | 0 | convert->ffill[i] = 0x00; |
8693 | 0 | } |
8694 | 0 | GST_LOG ("plane %d fill %02x", i, convert->ffill[i]); |
8695 | 0 | continue; |
8696 | 702 | } else { |
8697 | 702 | convert->fsplane[i] = GST_VIDEO_FORMAT_INFO_PLANE (in_finfo, comp); |
8698 | 702 | GST_LOG ("plane %d -> %d (comp %d)", i, convert->fsplane[i], comp); |
8699 | 702 | } |
8700 | | |
8701 | 702 | config = gst_structure_copy (convert->config); |
8702 | | |
8703 | 702 | resample_method = (i == 0 ? method : cr_method); |
8704 | | |
8705 | 702 | need_v_scaler = FALSE; |
8706 | 702 | need_h_scaler = FALSE; |
8707 | 702 | if (iw == ow) { |
8708 | 172 | if (!interlaced && ih == oh) { |
8709 | 58 | convert->fconvert[i] = convert_plane_hv; |
8710 | 58 | GST_LOG ("plane %d: copy", i); |
8711 | 114 | } else if (!interlaced && ih == 2 * oh && pstride == 1 |
8712 | 38 | && resample_method == GST_VIDEO_RESAMPLER_METHOD_LINEAR) { |
8713 | 32 | convert->fconvert[i] = convert_plane_v_halve; |
8714 | 32 | GST_LOG ("plane %d: vertical halve", i); |
8715 | 82 | } else if (!interlaced && 2 * ih == oh && pstride == 1 |
8716 | 7 | && resample_method == GST_VIDEO_RESAMPLER_METHOD_NEAREST) { |
8717 | 0 | convert->fconvert[i] = convert_plane_v_double; |
8718 | 0 | GST_LOG ("plane %d: vertical double", i); |
8719 | 82 | } else { |
8720 | 82 | convert->fconvert[i] = convert_plane_hv; |
8721 | 82 | GST_LOG ("plane %d: vertical scale", i); |
8722 | 82 | need_v_scaler = TRUE; |
8723 | 82 | } |
8724 | 530 | } else if (ih == oh) { |
8725 | 116 | if (!interlaced && iw == 2 * ow && pstride == 1 |
8726 | 32 | && resample_method == GST_VIDEO_RESAMPLER_METHOD_LINEAR) { |
8727 | 28 | convert->fconvert[i] = convert_plane_h_halve; |
8728 | 28 | GST_LOG ("plane %d: horizontal halve", i); |
8729 | 88 | } else if (!interlaced && 2 * iw == ow && pstride == 1 |
8730 | 13 | && resample_method == GST_VIDEO_RESAMPLER_METHOD_NEAREST) { |
8731 | 0 | convert->fconvert[i] = convert_plane_h_double; |
8732 | 0 | GST_LOG ("plane %d: horizontal double", i); |
8733 | 88 | } else { |
8734 | 88 | convert->fconvert[i] = convert_plane_hv; |
8735 | 88 | GST_LOG ("plane %d: horizontal scale", i); |
8736 | 88 | need_h_scaler = TRUE; |
8737 | 88 | } |
8738 | 414 | } else { |
8739 | 414 | if (!interlaced && iw == 2 * ow && ih == 2 * oh && pstride == 1 |
8740 | 23 | && resample_method == GST_VIDEO_RESAMPLER_METHOD_LINEAR) { |
8741 | 20 | convert->fconvert[i] = convert_plane_hv_halve; |
8742 | 20 | GST_LOG ("plane %d: horizontal/vertical halve", i); |
8743 | 394 | } else if (!interlaced && 2 * iw == ow && 2 * ih == oh && pstride == 1 |
8744 | 7 | && resample_method == GST_VIDEO_RESAMPLER_METHOD_NEAREST) { |
8745 | 0 | convert->fconvert[i] = convert_plane_hv_double; |
8746 | 0 | GST_LOG ("plane %d: horizontal/vertical double", i); |
8747 | 394 | } else { |
8748 | 394 | convert->fconvert[i] = convert_plane_hv; |
8749 | 394 | GST_LOG ("plane %d: horizontal/vertical scale", i); |
8750 | 394 | need_v_scaler = TRUE; |
8751 | 394 | need_h_scaler = TRUE; |
8752 | 394 | } |
8753 | 414 | } |
8754 | | |
8755 | 702 | if (need_h_scaler && iw != 0 && ow != 0) { |
8756 | 482 | convert->fh_scaler[i].scaler = g_new (GstVideoScaler *, n_threads); |
8757 | | |
8758 | 964 | for (j = 0; j < n_threads; j++) { |
8759 | 482 | convert->fh_scaler[i].scaler[j] = |
8760 | 482 | gst_video_scaler_new (resample_method, GST_VIDEO_SCALER_FLAG_NONE, |
8761 | 482 | taps, iw, ow, config); |
8762 | 482 | } |
8763 | 482 | } else { |
8764 | 220 | convert->fh_scaler[i].scaler = NULL; |
8765 | 220 | } |
8766 | | |
8767 | 702 | if (need_v_scaler && ih != 0 && oh != 0) { |
8768 | 476 | convert->fv_scaler[i].scaler = g_new (GstVideoScaler *, n_threads); |
8769 | | |
8770 | 952 | for (j = 0; j < n_threads; j++) { |
8771 | 476 | convert->fv_scaler[i].scaler[j] = |
8772 | 476 | gst_video_scaler_new (resample_method, |
8773 | 476 | interlaced ? |
8774 | 476 | GST_VIDEO_SCALER_FLAG_INTERLACED : GST_VIDEO_SCALER_FLAG_NONE, |
8775 | 476 | taps, ih, oh, config); |
8776 | 476 | } |
8777 | 476 | } else { |
8778 | 226 | convert->fv_scaler[i].scaler = NULL; |
8779 | 226 | } |
8780 | | |
8781 | 702 | gst_structure_free (config); |
8782 | 702 | convert->fformat[i] = get_scale_format (in_format, i); |
8783 | 702 | } |
8784 | 307 | } |
8785 | | |
8786 | 445 | return TRUE; |
8787 | 452 | } |
8788 | | |
8789 | | /* RGBA_F16 and RGBA_F32 store the same R, G, B, A component order, so |
8790 | | * converting between them is a per-component half <-> float pass with no colour |
8791 | | * conversion or resampling. Doing it directly keeps the full float precision |
8792 | | * and does not pre-clamp values to [0, 1] the way the generic ARGB64 unpack |
8793 | | * path would. */ |
8794 | | #define MAKE_RGBA_F16_TO_F32_TASK(name, READ_HALF, WRITE_FLOAT) \ |
8795 | | static void \ |
8796 | 0 | name (FConvertPlaneTask * task) \ |
8797 | 0 | { \ |
8798 | 0 | gint i, j; \ |
8799 | 0 | \ |
8800 | 0 | for (i = 0; i < task->height; i++) { \ |
8801 | 0 | const guint8 *s = task->s + i * task->sstride; \ |
8802 | 0 | guint8 *d = task->d + i * task->dstride; \ |
8803 | 0 | \ |
8804 | 0 | for (j = 0; j < task->width * 4; j++) { \ |
8805 | 0 | union { guint32 i; gfloat f; } u; \ |
8806 | 0 | u.f = gst_half_to_float (READ_HALF (s + j * 2)); \ |
8807 | 0 | WRITE_FLOAT (d + j * 4, u.i); \ |
8808 | 0 | } \ |
8809 | 0 | } \ |
8810 | 0 | } Unexecuted instantiation: video-converter.c:convert_RGBA_F16LE_F32_task Unexecuted instantiation: video-converter.c:convert_RGBA_F16BE_F32_task |
8811 | | |
8812 | 0 | MAKE_RGBA_F16_TO_F32_TASK (convert_RGBA_F16LE_F32_task, GST_READ_UINT16_LE, |
8813 | 0 | GST_WRITE_UINT32_LE); |
8814 | 0 | MAKE_RGBA_F16_TO_F32_TASK (convert_RGBA_F16BE_F32_task, GST_READ_UINT16_BE, |
8815 | 0 | GST_WRITE_UINT32_BE); |
8816 | | |
8817 | | #define MAKE_RGBA_F32_TO_F16_TASK(name, READ_FLOAT, WRITE_HALF) \ |
8818 | | static void \ |
8819 | 0 | name (FConvertPlaneTask * task) \ |
8820 | 0 | { \ |
8821 | 0 | gint i, j; \ |
8822 | 0 | \ |
8823 | 0 | for (i = 0; i < task->height; i++) { \ |
8824 | 0 | const guint8 *s = task->s + i * task->sstride; \ |
8825 | 0 | guint8 *d = task->d + i * task->dstride; \ |
8826 | 0 | \ |
8827 | 0 | for (j = 0; j < task->width * 4; j++) { \ |
8828 | 0 | union { guint32 i; gfloat f; } u; \ |
8829 | 0 | u.i = READ_FLOAT (s + j * 4); \ |
8830 | 0 | WRITE_HALF (d + j * 2, gst_float_to_half (u.f)); \ |
8831 | 0 | } \ |
8832 | 0 | } \ |
8833 | 0 | } Unexecuted instantiation: video-converter.c:convert_RGBA_F32LE_F16_task Unexecuted instantiation: video-converter.c:convert_RGBA_F32BE_F16_task |
8834 | 0 | MAKE_RGBA_F32_TO_F16_TASK (convert_RGBA_F32LE_F16_task, GST_READ_UINT32_LE, |
8835 | 0 | GST_WRITE_UINT16_LE); |
8836 | 0 | MAKE_RGBA_F32_TO_F16_TASK (convert_RGBA_F32BE_F16_task, GST_READ_UINT32_BE, |
8837 | 0 | GST_WRITE_UINT16_BE); |
8838 | | |
8839 | | static void |
8840 | | convert_RGBA_F16_F32 (GstVideoConverter * convert, |
8841 | | const GstVideoFrame * src, GstVideoFrame * dest) |
8842 | 0 | { |
8843 | 0 | gint width = convert->in_width; |
8844 | 0 | gint height = convert->in_height; |
8845 | 0 | guint8 *s, *d; |
8846 | 0 | FConvertPlaneTask *tasks; |
8847 | 0 | FConvertPlaneTask **tasks_p; |
8848 | 0 | GstParallelizedTaskFunc task_func; |
8849 | 0 | gint n_threads, lines_per_thread, i; |
8850 | |
|
8851 | 0 | task_func = GST_VIDEO_INFO_FORMAT (&convert->in_info) == |
8852 | 0 | GST_VIDEO_FORMAT_RGBA_F16LE ? |
8853 | 0 | (GstParallelizedTaskFunc) convert_RGBA_F16LE_F32_task : |
8854 | 0 | (GstParallelizedTaskFunc) convert_RGBA_F16BE_F32_task; |
8855 | |
|
8856 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
8857 | 0 | s += convert->in_x * 8; |
8858 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
8859 | 0 | d += convert->out_x * 16; |
8860 | |
|
8861 | 0 | n_threads = convert->conversion_runner->n_threads; |
8862 | 0 | tasks = convert->tasks[0] = |
8863 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
8864 | 0 | tasks_p = convert->tasks_p[0] = |
8865 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
8866 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
8867 | |
|
8868 | 0 | for (i = 0; i < n_threads; i++) { |
8869 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
8870 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
8871 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
8872 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
8873 | 0 | tasks[i].width = width; |
8874 | 0 | tasks[i].height = |
8875 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
8876 | 0 | tasks_p[i] = &tasks[i]; |
8877 | 0 | } |
8878 | |
|
8879 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, task_func, |
8880 | 0 | (gpointer) tasks_p); |
8881 | |
|
8882 | 0 | convert_fill_border (convert, dest); |
8883 | 0 | } |
8884 | | |
8885 | | static void |
8886 | | convert_RGBA_F32_F16 (GstVideoConverter * convert, const GstVideoFrame * src, |
8887 | | GstVideoFrame * dest) |
8888 | 0 | { |
8889 | 0 | gint width = convert->in_width; |
8890 | 0 | gint height = convert->in_height; |
8891 | 0 | guint8 *s, *d; |
8892 | 0 | FConvertPlaneTask *tasks; |
8893 | 0 | FConvertPlaneTask **tasks_p; |
8894 | 0 | GstParallelizedTaskFunc task_func; |
8895 | 0 | gint n_threads, lines_per_thread, i; |
8896 | |
|
8897 | 0 | task_func = GST_VIDEO_INFO_FORMAT (&convert->in_info) == |
8898 | 0 | GST_VIDEO_FORMAT_RGBA_F32LE ? |
8899 | 0 | (GstParallelizedTaskFunc) convert_RGBA_F32LE_F16_task : |
8900 | 0 | (GstParallelizedTaskFunc) convert_RGBA_F32BE_F16_task; |
8901 | |
|
8902 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
8903 | 0 | s += convert->in_x * 16; |
8904 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
8905 | 0 | d += convert->out_x * 8; |
8906 | |
|
8907 | 0 | n_threads = convert->conversion_runner->n_threads; |
8908 | 0 | tasks = convert->tasks[0] = |
8909 | 0 | g_renew (FConvertPlaneTask, convert->tasks[0], n_threads); |
8910 | 0 | tasks_p = convert->tasks_p[0] = |
8911 | 0 | g_renew (FConvertPlaneTask *, convert->tasks_p[0], n_threads); |
8912 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
8913 | |
|
8914 | 0 | for (i = 0; i < n_threads; i++) { |
8915 | 0 | tasks[i].dstride = FRAME_GET_STRIDE (dest); |
8916 | 0 | tasks[i].sstride = FRAME_GET_STRIDE (src); |
8917 | 0 | tasks[i].d = d + i * lines_per_thread * tasks[i].dstride; |
8918 | 0 | tasks[i].s = s + i * lines_per_thread * tasks[i].sstride; |
8919 | 0 | tasks[i].width = width; |
8920 | 0 | tasks[i].height = |
8921 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
8922 | 0 | tasks_p[i] = &tasks[i]; |
8923 | 0 | } |
8924 | |
|
8925 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, task_func, |
8926 | 0 | (gpointer) tasks_p); |
8927 | |
|
8928 | 0 | convert_fill_border (convert, dest); |
8929 | 0 | } |
8930 | | |
8931 | | typedef struct _FConvertFloatTask |
8932 | | { |
8933 | | const guint8 *s[GST_VIDEO_MAX_PLANES]; |
8934 | | guint8 *d[GST_VIDEO_MAX_PLANES]; |
8935 | | gint sstride[GST_VIDEO_MAX_PLANES]; |
8936 | | gint dstride[GST_VIDEO_MAX_PLANES]; |
8937 | | gint width; |
8938 | | gint height; |
8939 | | |
8940 | | gfloat scale; |
8941 | | gfloat offset; |
8942 | | gfloat min; |
8943 | | gfloat max; |
8944 | | } FConvertFloatTask; |
8945 | | |
8946 | | #define MAKE_PACKED_FLOAT_TASK(name, func, src_type, dst_type, n_components) \ |
8947 | | static void \ |
8948 | 0 | name (FConvertFloatTask * task) \ |
8949 | 0 | { \ |
8950 | 0 | gint i; \ |
8951 | 0 | orc_union32 scale, offset, min, max; \ |
8952 | 0 | \ |
8953 | 0 | scale.f = task->scale; \ |
8954 | 0 | offset.f = task->offset; \ |
8955 | 0 | min.f = task->min; \ |
8956 | 0 | max.f = task->max; \ |
8957 | 0 | \ |
8958 | 0 | for (i = 0; i < task->height; i++) { \ |
8959 | 0 | const src_type *s = \ |
8960 | 0 | (const src_type *) (task->s[0] + i * task->sstride[0]); \ |
8961 | 0 | dst_type *d = \ |
8962 | 0 | (dst_type *) (task->d[0] + i * task->dstride[0]); \ |
8963 | 0 | \ |
8964 | 0 | func (d, s, scale.i, offset.i, min.i, max.i, \ |
8965 | 0 | task->width * n_components); \ |
8966 | 0 | } \ |
8967 | 0 | } Unexecuted instantiation: video-converter.c:convert_RGB_RGB_F32_range_swap_task Unexecuted instantiation: video-converter.c:convert_RGB_RGB_F32_range_task Unexecuted instantiation: video-converter.c:convert_RGB_RGB_F32_swap_task Unexecuted instantiation: video-converter.c:convert_RGB_RGB_F32_task Unexecuted instantiation: video-converter.c:convert_RGB_F32_RGB_range_swap_task Unexecuted instantiation: video-converter.c:convert_RGB_F32_RGB_range_task Unexecuted instantiation: video-converter.c:convert_RGB_F32_RGB_swap_task Unexecuted instantiation: video-converter.c:convert_RGB_F32_RGB_task Unexecuted instantiation: video-converter.c:convert_GRAY8_GRAY_F32_range_swap_task Unexecuted instantiation: video-converter.c:convert_GRAY8_GRAY_F32_range_task Unexecuted instantiation: video-converter.c:convert_GRAY8_GRAY_F32_swap_task Unexecuted instantiation: video-converter.c:convert_GRAY8_GRAY_F32_task Unexecuted instantiation: video-converter.c:convert_GRAY_F32_GRAY8_range_swap_task Unexecuted instantiation: video-converter.c:convert_GRAY_F32_GRAY8_range_task Unexecuted instantiation: video-converter.c:convert_GRAY_F32_GRAY8_swap_task Unexecuted instantiation: video-converter.c:convert_GRAY_F32_GRAY8_task Unexecuted instantiation: video-converter.c:convert_RGBA_RGBA_F32_swap_task Unexecuted instantiation: video-converter.c:convert_RGBA_RGBA_F32_task Unexecuted instantiation: video-converter.c:convert_RGBA_F32_RGBA_swap_task Unexecuted instantiation: video-converter.c:convert_RGBA_F32_RGBA_task |
8968 | | |
8969 | | #define MAKE_PLANAR_FLOAT_TASK(name, func, src_type, dst_type, n_planes) \ |
8970 | | static void \ |
8971 | 0 | name (FConvertFloatTask * task) \ |
8972 | 0 | { \ |
8973 | 0 | gint i, j; \ |
8974 | 0 | orc_union32 scale, offset, min, max; \ |
8975 | 0 | \ |
8976 | 0 | scale.f = task->scale; \ |
8977 | 0 | offset.f = task->offset; \ |
8978 | 0 | min.f = task->min; \ |
8979 | 0 | max.f = task->max; \ |
8980 | 0 | \ |
8981 | 0 | for (i = 0; i < task->height; i++) { \ |
8982 | 0 | for (j = 0; j < n_planes; j++) { \ |
8983 | 0 | const src_type *s = \ |
8984 | 0 | (const src_type *) (task->s[j] + i * task->sstride[j]); \ |
8985 | 0 | dst_type *d = \ |
8986 | 0 | (dst_type *) (task->d[j] + i * task->dstride[j]); \ |
8987 | 0 | \ |
8988 | 0 | func (d, s, scale.i, offset.i, min.i, max.i, task->width); \ |
8989 | 0 | } \ |
8990 | 0 | } \ |
8991 | 0 | } Unexecuted instantiation: video-converter.c:convert_RGBP_RGBP_F32_range_swap_task Unexecuted instantiation: video-converter.c:convert_RGBP_RGBP_F32_range_task Unexecuted instantiation: video-converter.c:convert_RGBP_RGBP_F32_swap_task Unexecuted instantiation: video-converter.c:convert_RGBP_RGBP_F32_task Unexecuted instantiation: video-converter.c:convert_RGBP_F32_RGBP_range_swap_task Unexecuted instantiation: video-converter.c:convert_RGBP_F32_RGBP_range_task Unexecuted instantiation: video-converter.c:convert_RGBP_F32_RGBP_swap_task Unexecuted instantiation: video-converter.c:convert_RGBP_F32_RGBP_task |
8992 | | |
8993 | | MAKE_PACKED_FLOAT_TASK (convert_RGB_RGB_F32_task, |
8994 | | video_orc_convert_u8_f32, guint8, gfloat, 3); |
8995 | | MAKE_PACKED_FLOAT_TASK (convert_RGB_RGB_F32_swap_task, |
8996 | | video_orc_convert_u8_f32_swap, guint8, gfloat, 3); |
8997 | | MAKE_PACKED_FLOAT_TASK (convert_RGB_RGB_F32_range_task, |
8998 | | video_orc_convert_u8_f32_range, guint8, gfloat, 3); |
8999 | | MAKE_PACKED_FLOAT_TASK (convert_RGB_RGB_F32_range_swap_task, |
9000 | | video_orc_convert_u8_f32_range_swap, guint8, gfloat, 3); |
9001 | | |
9002 | | static void |
9003 | | convert_RGB_RGB_F32 (GstVideoConverter * convert, |
9004 | | const GstVideoFrame * src, GstVideoFrame * dest) |
9005 | 0 | { |
9006 | 0 | gint width = convert->in_width; |
9007 | 0 | gint height = convert->in_height; |
9008 | 0 | guint8 *s, *d; |
9009 | 0 | FConvertFloatTask *tasks; |
9010 | 0 | FConvertFloatTask **tasks_p; |
9011 | 0 | gint n_threads, lines_per_thread, i; |
9012 | 0 | gfloat scale, offset, min, max; |
9013 | 0 | gboolean swap; |
9014 | 0 | GstParallelizedTaskFunc task_func; |
9015 | |
|
9016 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
9017 | 0 | s += convert->in_x * 3; |
9018 | |
|
9019 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
9020 | 0 | d += convert->out_x * 3 * sizeof (gfloat); |
9021 | |
|
9022 | 0 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
9023 | 0 | swap = GST_VIDEO_FRAME_FORMAT (dest) == GST_VIDEO_FORMAT_RGB_F32BE; |
9024 | | #else |
9025 | | swap = GST_VIDEO_FRAME_FORMAT (dest) == GST_VIDEO_FORMAT_RGB_F32LE; |
9026 | | #endif |
9027 | |
|
9028 | 0 | if (convert->in_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
9029 | 0 | gdouble in_offset[GST_VIDEO_MAX_COMPONENTS]; |
9030 | 0 | gdouble in_scale[GST_VIDEO_MAX_COMPONENTS]; |
9031 | |
|
9032 | 0 | gst_video_color_range_offsets_full (GST_VIDEO_COLOR_RANGE_16_235, |
9033 | 0 | src->info.finfo, in_offset, in_scale, NULL); |
9034 | |
|
9035 | 0 | scale = 1.0f / in_scale[0]; |
9036 | 0 | offset = -in_offset[0] / in_scale[0]; |
9037 | 0 | min = 0.0f; |
9038 | 0 | max = 1.0f; |
9039 | |
|
9040 | 0 | task_func = swap ? |
9041 | 0 | (GstParallelizedTaskFunc) convert_RGB_RGB_F32_range_swap_task : |
9042 | 0 | (GstParallelizedTaskFunc) convert_RGB_RGB_F32_range_task; |
9043 | 0 | } else { |
9044 | 0 | scale = 1.0f / 255.0f; |
9045 | 0 | offset = 0.0f; |
9046 | 0 | min = 0.0f; |
9047 | 0 | max = 1.0f; |
9048 | |
|
9049 | 0 | task_func = swap ? |
9050 | 0 | (GstParallelizedTaskFunc) convert_RGB_RGB_F32_swap_task : |
9051 | 0 | (GstParallelizedTaskFunc) convert_RGB_RGB_F32_task; |
9052 | 0 | } |
9053 | |
|
9054 | 0 | n_threads = convert->conversion_runner->n_threads; |
9055 | |
|
9056 | 0 | tasks = convert->tasks[0] = |
9057 | 0 | g_renew (FConvertFloatTask, convert->tasks[0], n_threads); |
9058 | 0 | tasks_p = convert->tasks_p[0] = |
9059 | 0 | g_renew (FConvertFloatTask *, convert->tasks_p[0], n_threads); |
9060 | |
|
9061 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
9062 | |
|
9063 | 0 | for (i = 0; i < n_threads; i++) { |
9064 | 0 | tasks[i].dstride[0] = FRAME_GET_STRIDE (dest); |
9065 | 0 | tasks[i].sstride[0] = FRAME_GET_STRIDE (src); |
9066 | 0 | tasks[i].d[0] = d + i * lines_per_thread * tasks[i].dstride[0]; |
9067 | 0 | tasks[i].s[0] = s + i * lines_per_thread * tasks[i].sstride[0]; |
9068 | 0 | tasks[i].width = width; |
9069 | 0 | tasks[i].height = |
9070 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
9071 | |
|
9072 | 0 | tasks[i].scale = scale; |
9073 | 0 | tasks[i].offset = offset; |
9074 | 0 | tasks[i].min = min; |
9075 | 0 | tasks[i].max = max; |
9076 | |
|
9077 | 0 | tasks_p[i] = &tasks[i]; |
9078 | 0 | } |
9079 | |
|
9080 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
9081 | 0 | task_func, (gpointer) tasks_p); |
9082 | 0 | } |
9083 | | |
9084 | | MAKE_PACKED_FLOAT_TASK (convert_RGB_F32_RGB_task, |
9085 | | video_orc_convert_f32_u8, gfloat, guint8, 3); |
9086 | | MAKE_PACKED_FLOAT_TASK (convert_RGB_F32_RGB_swap_task, |
9087 | | video_orc_convert_f32_u8_swap, gfloat, guint8, 3); |
9088 | | MAKE_PACKED_FLOAT_TASK (convert_RGB_F32_RGB_range_task, |
9089 | | video_orc_convert_f32_u8_range, gfloat, guint8, 3); |
9090 | | MAKE_PACKED_FLOAT_TASK (convert_RGB_F32_RGB_range_swap_task, |
9091 | | video_orc_convert_f32_u8_range_swap, gfloat, guint8, 3); |
9092 | | |
9093 | | static void |
9094 | | convert_RGB_F32_RGB (GstVideoConverter * convert, |
9095 | | const GstVideoFrame * src, GstVideoFrame * dest) |
9096 | 0 | { |
9097 | 0 | gint width = convert->in_width; |
9098 | 0 | gint height = convert->in_height; |
9099 | 0 | guint8 *s, *d; |
9100 | 0 | FConvertFloatTask *tasks; |
9101 | 0 | FConvertFloatTask **tasks_p; |
9102 | 0 | gint n_threads, lines_per_thread, i; |
9103 | 0 | gfloat scale, offset, min, max; |
9104 | 0 | gboolean swap; |
9105 | 0 | GstParallelizedTaskFunc task_func; |
9106 | |
|
9107 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
9108 | 0 | s += convert->in_x * 3 * sizeof (gfloat); |
9109 | |
|
9110 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
9111 | 0 | d += convert->out_x * 3; |
9112 | |
|
9113 | 0 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
9114 | 0 | swap = GST_VIDEO_FRAME_FORMAT (src) == GST_VIDEO_FORMAT_RGB_F32BE; |
9115 | | #else |
9116 | | swap = GST_VIDEO_FRAME_FORMAT (src) == GST_VIDEO_FORMAT_RGB_F32LE; |
9117 | | #endif |
9118 | |
|
9119 | 0 | if (convert->out_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
9120 | 0 | gdouble out_offset[GST_VIDEO_MAX_COMPONENTS]; |
9121 | 0 | gdouble out_scale[GST_VIDEO_MAX_COMPONENTS]; |
9122 | |
|
9123 | 0 | gst_video_color_range_offsets_full (GST_VIDEO_COLOR_RANGE_16_235, |
9124 | 0 | dest->info.finfo, out_offset, out_scale, NULL); |
9125 | |
|
9126 | 0 | scale = out_scale[0]; |
9127 | 0 | offset = out_offset[0]; |
9128 | 0 | min = 0.0f; |
9129 | 0 | max = 1.0f; |
9130 | |
|
9131 | 0 | task_func = swap ? |
9132 | 0 | (GstParallelizedTaskFunc) convert_RGB_F32_RGB_range_swap_task : |
9133 | 0 | (GstParallelizedTaskFunc) convert_RGB_F32_RGB_range_task; |
9134 | 0 | } else { |
9135 | 0 | scale = 255.0f; |
9136 | 0 | offset = 0.0f; |
9137 | 0 | min = 0.0f; |
9138 | 0 | max = 1.0f; |
9139 | |
|
9140 | 0 | task_func = swap ? |
9141 | 0 | (GstParallelizedTaskFunc) convert_RGB_F32_RGB_swap_task : |
9142 | 0 | (GstParallelizedTaskFunc) convert_RGB_F32_RGB_task; |
9143 | 0 | } |
9144 | |
|
9145 | 0 | n_threads = convert->conversion_runner->n_threads; |
9146 | |
|
9147 | 0 | tasks = convert->tasks[0] = |
9148 | 0 | g_renew (FConvertFloatTask, convert->tasks[0], n_threads); |
9149 | 0 | tasks_p = convert->tasks_p[0] = |
9150 | 0 | g_renew (FConvertFloatTask *, convert->tasks_p[0], n_threads); |
9151 | |
|
9152 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
9153 | |
|
9154 | 0 | for (i = 0; i < n_threads; i++) { |
9155 | 0 | tasks[i].dstride[0] = FRAME_GET_STRIDE (dest); |
9156 | 0 | tasks[i].sstride[0] = FRAME_GET_STRIDE (src); |
9157 | 0 | tasks[i].d[0] = d + i * lines_per_thread * tasks[i].dstride[0]; |
9158 | 0 | tasks[i].s[0] = s + i * lines_per_thread * tasks[i].sstride[0]; |
9159 | 0 | tasks[i].width = width; |
9160 | 0 | tasks[i].height = |
9161 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
9162 | |
|
9163 | 0 | tasks[i].scale = scale; |
9164 | 0 | tasks[i].offset = offset; |
9165 | 0 | tasks[i].min = min; |
9166 | 0 | tasks[i].max = max; |
9167 | |
|
9168 | 0 | tasks_p[i] = &tasks[i]; |
9169 | 0 | } |
9170 | |
|
9171 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
9172 | 0 | task_func, (gpointer) tasks_p); |
9173 | 0 | } |
9174 | | |
9175 | | MAKE_PLANAR_FLOAT_TASK (convert_RGBP_RGBP_F32_task, |
9176 | | video_orc_convert_u8_f32, guint8, gfloat, 3); |
9177 | | MAKE_PLANAR_FLOAT_TASK (convert_RGBP_RGBP_F32_swap_task, |
9178 | | video_orc_convert_u8_f32_swap, guint8, gfloat, 3); |
9179 | | MAKE_PLANAR_FLOAT_TASK (convert_RGBP_RGBP_F32_range_task, |
9180 | | video_orc_convert_u8_f32_range, guint8, gfloat, 3); |
9181 | | MAKE_PLANAR_FLOAT_TASK (convert_RGBP_RGBP_F32_range_swap_task, |
9182 | | video_orc_convert_u8_f32_range_swap, guint8, gfloat, 3); |
9183 | | |
9184 | | static void |
9185 | | convert_RGBP_RGBP_F32 (GstVideoConverter * convert, |
9186 | | const GstVideoFrame * src, GstVideoFrame * dest) |
9187 | 0 | { |
9188 | 0 | gint width = convert->in_width; |
9189 | 0 | gint height = convert->in_height; |
9190 | 0 | FConvertFloatTask *tasks; |
9191 | 0 | FConvertFloatTask **tasks_p; |
9192 | 0 | gint n_threads, lines_per_thread, i, j; |
9193 | 0 | gfloat scale, offset, min, max; |
9194 | 0 | gboolean swap; |
9195 | 0 | GstParallelizedTaskFunc task_func; |
9196 | |
|
9197 | 0 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
9198 | 0 | swap = GST_VIDEO_FRAME_FORMAT (dest) == GST_VIDEO_FORMAT_RGBP_F32BE; |
9199 | | #else |
9200 | | swap = GST_VIDEO_FRAME_FORMAT (dest) == GST_VIDEO_FORMAT_RGBP_F32LE; |
9201 | | #endif |
9202 | |
|
9203 | 0 | if (convert->in_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
9204 | 0 | gdouble in_offset[GST_VIDEO_MAX_COMPONENTS]; |
9205 | 0 | gdouble in_scale[GST_VIDEO_MAX_COMPONENTS]; |
9206 | |
|
9207 | 0 | gst_video_color_range_offsets_full (GST_VIDEO_COLOR_RANGE_16_235, |
9208 | 0 | convert->in_info.finfo, in_offset, in_scale, NULL); |
9209 | |
|
9210 | 0 | scale = 1.0f / in_scale[0]; |
9211 | 0 | offset = -in_offset[0] / in_scale[0]; |
9212 | 0 | min = 0.0f; |
9213 | 0 | max = 1.0f; |
9214 | |
|
9215 | 0 | task_func = swap ? |
9216 | 0 | (GstParallelizedTaskFunc) convert_RGBP_RGBP_F32_range_swap_task : |
9217 | 0 | (GstParallelizedTaskFunc) convert_RGBP_RGBP_F32_range_task; |
9218 | 0 | } else { |
9219 | 0 | scale = 1.0f / 255.0f; |
9220 | 0 | offset = 0.0f; |
9221 | 0 | min = 0.0f; |
9222 | 0 | max = 1.0f; |
9223 | |
|
9224 | 0 | task_func = swap ? |
9225 | 0 | (GstParallelizedTaskFunc) convert_RGBP_RGBP_F32_swap_task : |
9226 | 0 | (GstParallelizedTaskFunc) convert_RGBP_RGBP_F32_task; |
9227 | 0 | } |
9228 | |
|
9229 | 0 | n_threads = convert->conversion_runner->n_threads; |
9230 | |
|
9231 | 0 | tasks = convert->tasks[0] = |
9232 | 0 | g_renew (FConvertFloatTask, convert->tasks[0], n_threads); |
9233 | 0 | tasks_p = convert->tasks_p[0] = |
9234 | 0 | g_renew (FConvertFloatTask *, convert->tasks_p[0], n_threads); |
9235 | |
|
9236 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
9237 | |
|
9238 | 0 | for (i = 0; i < n_threads; i++) { |
9239 | 0 | for (j = 0; j < 3; j++) { |
9240 | 0 | guint8 *s = FRAME_GET_PLANE_LINE (src, j, convert->in_y); |
9241 | 0 | guint8 *d = FRAME_GET_PLANE_LINE (dest, j, convert->out_y); |
9242 | |
|
9243 | 0 | s += convert->in_x; |
9244 | 0 | d += convert->out_x * sizeof (gfloat); |
9245 | |
|
9246 | 0 | tasks[i].sstride[j] = FRAME_GET_PLANE_STRIDE (src, j); |
9247 | 0 | tasks[i].dstride[j] = FRAME_GET_PLANE_STRIDE (dest, j); |
9248 | |
|
9249 | 0 | tasks[i].s[j] = s + i * lines_per_thread * tasks[i].sstride[j]; |
9250 | 0 | tasks[i].d[j] = d + i * lines_per_thread * tasks[i].dstride[j]; |
9251 | 0 | } |
9252 | |
|
9253 | 0 | tasks[i].width = width; |
9254 | 0 | tasks[i].height = |
9255 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
9256 | |
|
9257 | 0 | tasks[i].scale = scale; |
9258 | 0 | tasks[i].offset = offset; |
9259 | 0 | tasks[i].min = min; |
9260 | 0 | tasks[i].max = max; |
9261 | |
|
9262 | 0 | tasks_p[i] = &tasks[i]; |
9263 | 0 | } |
9264 | |
|
9265 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
9266 | 0 | task_func, (gpointer) tasks_p); |
9267 | 0 | } |
9268 | | |
9269 | | MAKE_PLANAR_FLOAT_TASK (convert_RGBP_F32_RGBP_task, |
9270 | | video_orc_convert_f32_u8, gfloat, guint8, 3); |
9271 | | MAKE_PLANAR_FLOAT_TASK (convert_RGBP_F32_RGBP_swap_task, |
9272 | | video_orc_convert_f32_u8_swap, gfloat, guint8, 3); |
9273 | | MAKE_PLANAR_FLOAT_TASK (convert_RGBP_F32_RGBP_range_task, |
9274 | | video_orc_convert_f32_u8_range, gfloat, guint8, 3); |
9275 | | MAKE_PLANAR_FLOAT_TASK (convert_RGBP_F32_RGBP_range_swap_task, |
9276 | | video_orc_convert_f32_u8_range_swap, gfloat, guint8, 3); |
9277 | | |
9278 | | static void |
9279 | | convert_RGBP_F32_RGBP (GstVideoConverter * convert, |
9280 | | const GstVideoFrame * src, GstVideoFrame * dest) |
9281 | 0 | { |
9282 | 0 | gint width = convert->in_width; |
9283 | 0 | gint height = convert->in_height; |
9284 | 0 | FConvertFloatTask *tasks; |
9285 | 0 | FConvertFloatTask **tasks_p; |
9286 | 0 | gint n_threads, lines_per_thread, i, j; |
9287 | 0 | gfloat scale, offset, min, max; |
9288 | 0 | gboolean swap; |
9289 | 0 | GstParallelizedTaskFunc task_func; |
9290 | |
|
9291 | 0 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
9292 | 0 | swap = GST_VIDEO_FRAME_FORMAT (src) == GST_VIDEO_FORMAT_RGBP_F32BE; |
9293 | | #else |
9294 | | swap = GST_VIDEO_FRAME_FORMAT (src) == GST_VIDEO_FORMAT_RGBP_F32LE; |
9295 | | #endif |
9296 | |
|
9297 | 0 | if (convert->out_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
9298 | 0 | gdouble out_offset[GST_VIDEO_MAX_COMPONENTS]; |
9299 | 0 | gdouble out_scale[GST_VIDEO_MAX_COMPONENTS]; |
9300 | |
|
9301 | 0 | gst_video_color_range_offsets_full (GST_VIDEO_COLOR_RANGE_16_235, |
9302 | 0 | convert->out_info.finfo, out_offset, out_scale, NULL); |
9303 | |
|
9304 | 0 | scale = out_scale[0]; |
9305 | 0 | offset = out_offset[0]; |
9306 | 0 | min = 0.0f; |
9307 | 0 | max = 1.0f; |
9308 | |
|
9309 | 0 | task_func = swap ? |
9310 | 0 | (GstParallelizedTaskFunc) convert_RGBP_F32_RGBP_range_swap_task : |
9311 | 0 | (GstParallelizedTaskFunc) convert_RGBP_F32_RGBP_range_task; |
9312 | 0 | } else { |
9313 | 0 | scale = 255.0f; |
9314 | 0 | offset = 0.0f; |
9315 | 0 | min = 0.0f; |
9316 | 0 | max = 1.0f; |
9317 | |
|
9318 | 0 | task_func = swap ? |
9319 | 0 | (GstParallelizedTaskFunc) convert_RGBP_F32_RGBP_swap_task : |
9320 | 0 | (GstParallelizedTaskFunc) convert_RGBP_F32_RGBP_task; |
9321 | 0 | } |
9322 | |
|
9323 | 0 | n_threads = convert->conversion_runner->n_threads; |
9324 | |
|
9325 | 0 | tasks = convert->tasks[0] = |
9326 | 0 | g_renew (FConvertFloatTask, convert->tasks[0], n_threads); |
9327 | 0 | tasks_p = convert->tasks_p[0] = |
9328 | 0 | g_renew (FConvertFloatTask *, convert->tasks_p[0], n_threads); |
9329 | |
|
9330 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
9331 | |
|
9332 | 0 | for (i = 0; i < n_threads; i++) { |
9333 | 0 | for (j = 0; j < 3; j++) { |
9334 | 0 | guint8 *s = FRAME_GET_PLANE_LINE (src, j, convert->in_y); |
9335 | 0 | guint8 *d = FRAME_GET_PLANE_LINE (dest, j, convert->out_y); |
9336 | |
|
9337 | 0 | s += convert->in_x * sizeof (gfloat); |
9338 | 0 | d += convert->out_x; |
9339 | |
|
9340 | 0 | tasks[i].sstride[j] = FRAME_GET_PLANE_STRIDE (src, j); |
9341 | 0 | tasks[i].dstride[j] = FRAME_GET_PLANE_STRIDE (dest, j); |
9342 | |
|
9343 | 0 | tasks[i].s[j] = s + i * lines_per_thread * tasks[i].sstride[j]; |
9344 | 0 | tasks[i].d[j] = d + i * lines_per_thread * tasks[i].dstride[j]; |
9345 | 0 | } |
9346 | |
|
9347 | 0 | tasks[i].width = width; |
9348 | 0 | tasks[i].height = |
9349 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
9350 | |
|
9351 | 0 | tasks[i].scale = scale; |
9352 | 0 | tasks[i].offset = offset; |
9353 | 0 | tasks[i].min = min; |
9354 | 0 | tasks[i].max = max; |
9355 | |
|
9356 | 0 | tasks_p[i] = &tasks[i]; |
9357 | 0 | } |
9358 | |
|
9359 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
9360 | 0 | task_func, (gpointer) tasks_p); |
9361 | 0 | } |
9362 | | |
9363 | | MAKE_PACKED_FLOAT_TASK (convert_GRAY8_GRAY_F32_task, |
9364 | | video_orc_convert_u8_f32, guint8, gfloat, 1); |
9365 | | MAKE_PACKED_FLOAT_TASK (convert_GRAY8_GRAY_F32_swap_task, |
9366 | | video_orc_convert_u8_f32_swap, guint8, gfloat, 1); |
9367 | | MAKE_PACKED_FLOAT_TASK (convert_GRAY8_GRAY_F32_range_task, |
9368 | | video_orc_convert_u8_f32_range, guint8, gfloat, 1); |
9369 | | MAKE_PACKED_FLOAT_TASK (convert_GRAY8_GRAY_F32_range_swap_task, |
9370 | | video_orc_convert_u8_f32_range_swap, guint8, gfloat, 1); |
9371 | | |
9372 | | static void |
9373 | | convert_GRAY8_GRAY_F32 (GstVideoConverter * convert, |
9374 | | const GstVideoFrame * src, GstVideoFrame * dest) |
9375 | 0 | { |
9376 | 0 | gint width = convert->in_width; |
9377 | 0 | gint height = convert->in_height; |
9378 | 0 | guint8 *s, *d; |
9379 | 0 | FConvertFloatTask *tasks; |
9380 | 0 | FConvertFloatTask **tasks_p; |
9381 | 0 | gint n_threads, lines_per_thread, i; |
9382 | 0 | gfloat scale, offset, min, max; |
9383 | 0 | gboolean swap; |
9384 | 0 | GstParallelizedTaskFunc task_func; |
9385 | |
|
9386 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
9387 | 0 | s += convert->in_x; |
9388 | |
|
9389 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
9390 | 0 | d += convert->out_x * sizeof (gfloat); |
9391 | |
|
9392 | 0 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
9393 | 0 | swap = GST_VIDEO_FRAME_FORMAT (dest) == GST_VIDEO_FORMAT_GRAY_F32BE; |
9394 | | #else |
9395 | | swap = GST_VIDEO_FRAME_FORMAT (dest) == GST_VIDEO_FORMAT_GRAY_F32LE; |
9396 | | #endif |
9397 | |
|
9398 | 0 | if (convert->in_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
9399 | 0 | gdouble in_offset[GST_VIDEO_MAX_COMPONENTS]; |
9400 | 0 | gdouble in_scale[GST_VIDEO_MAX_COMPONENTS]; |
9401 | |
|
9402 | 0 | gst_video_color_range_offsets_full (GST_VIDEO_COLOR_RANGE_16_235, |
9403 | 0 | src->info.finfo, in_offset, in_scale, NULL); |
9404 | |
|
9405 | 0 | scale = 1.0f / in_scale[0]; |
9406 | 0 | offset = -in_offset[0] / in_scale[0]; |
9407 | 0 | min = 0.0f; |
9408 | 0 | max = 1.0f; |
9409 | |
|
9410 | 0 | task_func = swap ? |
9411 | 0 | (GstParallelizedTaskFunc) convert_GRAY8_GRAY_F32_range_swap_task : |
9412 | 0 | (GstParallelizedTaskFunc) convert_GRAY8_GRAY_F32_range_task; |
9413 | 0 | } else { |
9414 | 0 | scale = 1.0f / 255.0f; |
9415 | 0 | offset = 0.0f; |
9416 | 0 | min = 0.0f; |
9417 | 0 | max = 1.0f; |
9418 | |
|
9419 | 0 | task_func = swap ? |
9420 | 0 | (GstParallelizedTaskFunc) convert_GRAY8_GRAY_F32_swap_task : |
9421 | 0 | (GstParallelizedTaskFunc) convert_GRAY8_GRAY_F32_task; |
9422 | 0 | } |
9423 | |
|
9424 | 0 | n_threads = convert->conversion_runner->n_threads; |
9425 | |
|
9426 | 0 | tasks = convert->tasks[0] = |
9427 | 0 | g_renew (FConvertFloatTask, convert->tasks[0], n_threads); |
9428 | 0 | tasks_p = convert->tasks_p[0] = |
9429 | 0 | g_renew (FConvertFloatTask *, convert->tasks_p[0], n_threads); |
9430 | |
|
9431 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
9432 | |
|
9433 | 0 | for (i = 0; i < n_threads; i++) { |
9434 | 0 | tasks[i].dstride[0] = FRAME_GET_STRIDE (dest); |
9435 | 0 | tasks[i].sstride[0] = FRAME_GET_STRIDE (src); |
9436 | 0 | tasks[i].d[0] = d + i * lines_per_thread * tasks[i].dstride[0]; |
9437 | 0 | tasks[i].s[0] = s + i * lines_per_thread * tasks[i].sstride[0]; |
9438 | 0 | tasks[i].width = width; |
9439 | 0 | tasks[i].height = |
9440 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
9441 | |
|
9442 | 0 | tasks[i].scale = scale; |
9443 | 0 | tasks[i].offset = offset; |
9444 | 0 | tasks[i].min = min; |
9445 | 0 | tasks[i].max = max; |
9446 | |
|
9447 | 0 | tasks_p[i] = &tasks[i]; |
9448 | 0 | } |
9449 | |
|
9450 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
9451 | 0 | task_func, (gpointer) tasks_p); |
9452 | 0 | } |
9453 | | |
9454 | | MAKE_PACKED_FLOAT_TASK (convert_GRAY_F32_GRAY8_task, |
9455 | | video_orc_convert_f32_u8, gfloat, guint8, 1); |
9456 | | MAKE_PACKED_FLOAT_TASK (convert_GRAY_F32_GRAY8_swap_task, |
9457 | | video_orc_convert_f32_u8_swap, gfloat, guint8, 1); |
9458 | | MAKE_PACKED_FLOAT_TASK (convert_GRAY_F32_GRAY8_range_task, |
9459 | | video_orc_convert_f32_u8_range, gfloat, guint8, 1); |
9460 | | MAKE_PACKED_FLOAT_TASK (convert_GRAY_F32_GRAY8_range_swap_task, |
9461 | | video_orc_convert_f32_u8_range_swap, gfloat, guint8, 1); |
9462 | | |
9463 | | static void |
9464 | | convert_GRAY_F32_GRAY8 (GstVideoConverter * convert, |
9465 | | const GstVideoFrame * src, GstVideoFrame * dest) |
9466 | 0 | { |
9467 | 0 | gint width = convert->in_width; |
9468 | 0 | gint height = convert->in_height; |
9469 | 0 | guint8 *s, *d; |
9470 | 0 | FConvertFloatTask *tasks; |
9471 | 0 | FConvertFloatTask **tasks_p; |
9472 | 0 | gint n_threads, lines_per_thread, i; |
9473 | 0 | gfloat scale, offset, min, max; |
9474 | 0 | gboolean swap; |
9475 | 0 | GstParallelizedTaskFunc task_func; |
9476 | |
|
9477 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
9478 | 0 | s += convert->in_x * sizeof (gfloat); |
9479 | |
|
9480 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
9481 | 0 | d += convert->out_x; |
9482 | |
|
9483 | 0 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
9484 | 0 | swap = GST_VIDEO_FRAME_FORMAT (src) == GST_VIDEO_FORMAT_GRAY_F32BE; |
9485 | | #else |
9486 | | swap = GST_VIDEO_FRAME_FORMAT (src) == GST_VIDEO_FORMAT_GRAY_F32LE; |
9487 | | #endif |
9488 | |
|
9489 | 0 | if (convert->out_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
9490 | 0 | gdouble out_offset[GST_VIDEO_MAX_COMPONENTS]; |
9491 | 0 | gdouble out_scale[GST_VIDEO_MAX_COMPONENTS]; |
9492 | |
|
9493 | 0 | gst_video_color_range_offsets_full (GST_VIDEO_COLOR_RANGE_16_235, |
9494 | 0 | dest->info.finfo, out_offset, out_scale, NULL); |
9495 | |
|
9496 | 0 | scale = out_scale[0]; |
9497 | 0 | offset = out_offset[0]; |
9498 | 0 | min = 0.0f; |
9499 | 0 | max = 1.0f; |
9500 | |
|
9501 | 0 | task_func = swap ? |
9502 | 0 | (GstParallelizedTaskFunc) convert_GRAY_F32_GRAY8_range_swap_task : |
9503 | 0 | (GstParallelizedTaskFunc) convert_GRAY_F32_GRAY8_range_task; |
9504 | 0 | } else { |
9505 | 0 | scale = 255.0f; |
9506 | 0 | offset = 0.0f; |
9507 | 0 | min = 0.0f; |
9508 | 0 | max = 1.0f; |
9509 | |
|
9510 | 0 | task_func = swap ? |
9511 | 0 | (GstParallelizedTaskFunc) convert_GRAY_F32_GRAY8_swap_task : |
9512 | 0 | (GstParallelizedTaskFunc) convert_GRAY_F32_GRAY8_task; |
9513 | 0 | } |
9514 | |
|
9515 | 0 | n_threads = convert->conversion_runner->n_threads; |
9516 | |
|
9517 | 0 | tasks = convert->tasks[0] = |
9518 | 0 | g_renew (FConvertFloatTask, convert->tasks[0], n_threads); |
9519 | 0 | tasks_p = convert->tasks_p[0] = |
9520 | 0 | g_renew (FConvertFloatTask *, convert->tasks_p[0], n_threads); |
9521 | |
|
9522 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
9523 | |
|
9524 | 0 | for (i = 0; i < n_threads; i++) { |
9525 | 0 | tasks[i].dstride[0] = FRAME_GET_STRIDE (dest); |
9526 | 0 | tasks[i].sstride[0] = FRAME_GET_STRIDE (src); |
9527 | 0 | tasks[i].d[0] = d + i * lines_per_thread * tasks[i].dstride[0]; |
9528 | 0 | tasks[i].s[0] = s + i * lines_per_thread * tasks[i].sstride[0]; |
9529 | 0 | tasks[i].width = width; |
9530 | 0 | tasks[i].height = |
9531 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
9532 | |
|
9533 | 0 | tasks[i].scale = scale; |
9534 | 0 | tasks[i].offset = offset; |
9535 | 0 | tasks[i].min = min; |
9536 | 0 | tasks[i].max = max; |
9537 | |
|
9538 | 0 | tasks_p[i] = &tasks[i]; |
9539 | 0 | } |
9540 | |
|
9541 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
9542 | 0 | task_func, (gpointer) tasks_p); |
9543 | 0 | } |
9544 | | |
9545 | | MAKE_PACKED_FLOAT_TASK (convert_RGBA_RGBA_F32_task, |
9546 | | video_orc_convert_u8_f32, guint8, gfloat, 4); |
9547 | | MAKE_PACKED_FLOAT_TASK (convert_RGBA_RGBA_F32_swap_task, |
9548 | | video_orc_convert_u8_f32_swap, guint8, gfloat, 4); |
9549 | | |
9550 | | /* Since scale/offset should not be applied to alpha, above ORC function |
9551 | | * cannot be used here. Use C function in case of range conversion for now */ |
9552 | | static void |
9553 | | convert_RGBA_RGBA_F32_range_task (FConvertFloatTask * task) |
9554 | 0 | { |
9555 | 0 | gint i, j; |
9556 | |
|
9557 | 0 | for (i = 0; i < task->height; i++) { |
9558 | 0 | const guint8 *s = task->s[0] + i * task->sstride[0]; |
9559 | 0 | gfloat *d = (gfloat *) (task->d[0] + i * task->dstride[0]); |
9560 | |
|
9561 | 0 | for (j = 0; j < task->width; j++) { |
9562 | 0 | gfloat r, g, b; |
9563 | |
|
9564 | 0 | r = s[0] * task->scale + task->offset; |
9565 | 0 | g = s[1] * task->scale + task->offset; |
9566 | 0 | b = s[2] * task->scale + task->offset; |
9567 | |
|
9568 | 0 | d[0] = CLAMP (r, task->min, task->max); |
9569 | 0 | d[1] = CLAMP (g, task->min, task->max); |
9570 | 0 | d[2] = CLAMP (b, task->min, task->max); |
9571 | 0 | d[3] = s[3] * (1.0f / 255.0f); |
9572 | |
|
9573 | 0 | s += 4; |
9574 | 0 | d += 4; |
9575 | 0 | } |
9576 | 0 | } |
9577 | 0 | } |
9578 | | |
9579 | | static void |
9580 | | convert_RGBA_RGBA_F32_range_swap_task (FConvertFloatTask * task) |
9581 | 0 | { |
9582 | 0 | gint i, j; |
9583 | |
|
9584 | 0 | for (i = 0; i < task->height; i++) { |
9585 | 0 | const guint8 *s = task->s[0] + i * task->sstride[0]; |
9586 | 0 | guint8 *d = task->d[0] + i * task->dstride[0]; |
9587 | |
|
9588 | 0 | for (j = 0; j < task->width; j++) { |
9589 | 0 | orc_union32 u; |
9590 | 0 | guint32 bits; |
9591 | 0 | gfloat r, g, b, a; |
9592 | |
|
9593 | 0 | r = s[0] * task->scale + task->offset; |
9594 | 0 | g = s[1] * task->scale + task->offset; |
9595 | 0 | b = s[2] * task->scale + task->offset; |
9596 | 0 | a = s[3] * (1.0f / 255.0f); |
9597 | |
|
9598 | 0 | r = CLAMP (r, task->min, task->max); |
9599 | 0 | g = CLAMP (g, task->min, task->max); |
9600 | 0 | b = CLAMP (b, task->min, task->max); |
9601 | |
|
9602 | 0 | u.f = r; |
9603 | 0 | bits = GUINT32_SWAP_LE_BE (u.i); |
9604 | 0 | memcpy (d, &bits, sizeof (bits)); |
9605 | |
|
9606 | 0 | u.f = g; |
9607 | 0 | bits = GUINT32_SWAP_LE_BE (u.i); |
9608 | 0 | memcpy (d + 4, &bits, sizeof (bits)); |
9609 | |
|
9610 | 0 | u.f = b; |
9611 | 0 | bits = GUINT32_SWAP_LE_BE (u.i); |
9612 | 0 | memcpy (d + 8, &bits, sizeof (bits)); |
9613 | |
|
9614 | 0 | u.f = a; |
9615 | 0 | bits = GUINT32_SWAP_LE_BE (u.i); |
9616 | 0 | memcpy (d + 12, &bits, sizeof (bits)); |
9617 | |
|
9618 | 0 | s += 4; |
9619 | 0 | d += 4 * sizeof (gfloat); |
9620 | 0 | } |
9621 | 0 | } |
9622 | 0 | } |
9623 | | |
9624 | | static void |
9625 | | convert_RGBA_RGBA_F32 (GstVideoConverter * convert, |
9626 | | const GstVideoFrame * src, GstVideoFrame * dest) |
9627 | 0 | { |
9628 | 0 | gint width = convert->in_width; |
9629 | 0 | gint height = convert->in_height; |
9630 | 0 | guint8 *s, *d; |
9631 | 0 | FConvertFloatTask *tasks; |
9632 | 0 | FConvertFloatTask **tasks_p; |
9633 | 0 | gint n_threads, lines_per_thread, i; |
9634 | 0 | gfloat scale, offset, min, max; |
9635 | 0 | gboolean swap; |
9636 | 0 | GstParallelizedTaskFunc task_func; |
9637 | |
|
9638 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
9639 | 0 | s += convert->in_x * 4; |
9640 | |
|
9641 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
9642 | 0 | d += convert->out_x * 4 * sizeof (gfloat); |
9643 | |
|
9644 | 0 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
9645 | 0 | swap = GST_VIDEO_FRAME_FORMAT (dest) == GST_VIDEO_FORMAT_RGBA_F32BE; |
9646 | | #else |
9647 | | swap = GST_VIDEO_FRAME_FORMAT (dest) == GST_VIDEO_FORMAT_RGBA_F32LE; |
9648 | | #endif |
9649 | |
|
9650 | 0 | if (convert->in_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
9651 | 0 | gdouble in_offset[GST_VIDEO_MAX_COMPONENTS]; |
9652 | 0 | gdouble in_scale[GST_VIDEO_MAX_COMPONENTS]; |
9653 | |
|
9654 | 0 | gst_video_color_range_offsets_full (GST_VIDEO_COLOR_RANGE_16_235, |
9655 | 0 | convert->in_info.finfo, in_offset, in_scale, NULL); |
9656 | |
|
9657 | 0 | scale = 1.0f / in_scale[0]; |
9658 | 0 | offset = -in_offset[0] / in_scale[0]; |
9659 | 0 | min = 0.0f; |
9660 | 0 | max = 1.0f; |
9661 | |
|
9662 | 0 | task_func = swap ? |
9663 | 0 | (GstParallelizedTaskFunc) convert_RGBA_RGBA_F32_range_swap_task : |
9664 | 0 | (GstParallelizedTaskFunc) convert_RGBA_RGBA_F32_range_task; |
9665 | 0 | } else { |
9666 | 0 | scale = 1.0f / 255.0f; |
9667 | 0 | offset = 0.0f; |
9668 | 0 | min = 0.0f; |
9669 | 0 | max = 1.0f; |
9670 | |
|
9671 | 0 | task_func = swap ? |
9672 | 0 | (GstParallelizedTaskFunc) convert_RGBA_RGBA_F32_swap_task : |
9673 | 0 | (GstParallelizedTaskFunc) convert_RGBA_RGBA_F32_task; |
9674 | 0 | } |
9675 | |
|
9676 | 0 | n_threads = convert->conversion_runner->n_threads; |
9677 | |
|
9678 | 0 | tasks = convert->tasks[0] = |
9679 | 0 | g_renew (FConvertFloatTask, convert->tasks[0], n_threads); |
9680 | 0 | tasks_p = convert->tasks_p[0] = |
9681 | 0 | g_renew (FConvertFloatTask *, convert->tasks_p[0], n_threads); |
9682 | |
|
9683 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
9684 | |
|
9685 | 0 | for (i = 0; i < n_threads; i++) { |
9686 | 0 | tasks[i].sstride[0] = FRAME_GET_STRIDE (src); |
9687 | 0 | tasks[i].dstride[0] = FRAME_GET_STRIDE (dest); |
9688 | |
|
9689 | 0 | tasks[i].s[0] = s + i * lines_per_thread * tasks[i].sstride[0]; |
9690 | 0 | tasks[i].d[0] = d + i * lines_per_thread * tasks[i].dstride[0]; |
9691 | |
|
9692 | 0 | tasks[i].width = width; |
9693 | 0 | tasks[i].height = |
9694 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
9695 | |
|
9696 | 0 | tasks[i].scale = scale; |
9697 | 0 | tasks[i].offset = offset; |
9698 | 0 | tasks[i].min = min; |
9699 | 0 | tasks[i].max = max; |
9700 | |
|
9701 | 0 | tasks_p[i] = &tasks[i]; |
9702 | 0 | } |
9703 | |
|
9704 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
9705 | 0 | task_func, (gpointer) tasks_p); |
9706 | 0 | } |
9707 | | |
9708 | | MAKE_PACKED_FLOAT_TASK (convert_RGBA_F32_RGBA_task, |
9709 | | video_orc_convert_f32_u8, gfloat, guint8, 4); |
9710 | | MAKE_PACKED_FLOAT_TASK (convert_RGBA_F32_RGBA_swap_task, |
9711 | | video_orc_convert_f32_u8_swap, gfloat, guint8, 4); |
9712 | | |
9713 | | /* Since scale/offset should not be applied to alpha, above ORC function |
9714 | | * cannot be used here. Use C function in case of range conversion for now */ |
9715 | | static void |
9716 | | convert_RGBA_F32_RGBA_range_task (FConvertFloatTask * task) |
9717 | 0 | { |
9718 | 0 | gint i, j; |
9719 | |
|
9720 | 0 | for (i = 0; i < task->height; i++) { |
9721 | 0 | const gfloat *s = (const gfloat *) (task->s[0] + i * task->sstride[0]); |
9722 | 0 | guint8 *d = task->d[0] + i * task->dstride[0]; |
9723 | |
|
9724 | 0 | for (j = 0; j < task->width; j++) { |
9725 | 0 | gfloat r, g, b, a; |
9726 | |
|
9727 | 0 | r = CLAMP (s[0], task->min, task->max); |
9728 | 0 | g = CLAMP (s[1], task->min, task->max); |
9729 | 0 | b = CLAMP (s[2], task->min, task->max); |
9730 | 0 | a = CLAMP (s[3], task->min, task->max); |
9731 | |
|
9732 | 0 | d[0] = (guint8) (r * task->scale + task->offset); |
9733 | 0 | d[1] = (guint8) (g * task->scale + task->offset); |
9734 | 0 | d[2] = (guint8) (b * task->scale + task->offset); |
9735 | 0 | d[3] = (guint8) (a * 255.0f); |
9736 | |
|
9737 | 0 | s += 4; |
9738 | 0 | d += 4; |
9739 | 0 | } |
9740 | 0 | } |
9741 | 0 | } |
9742 | | |
9743 | | static void |
9744 | | convert_RGBA_F32_RGBA_range_swap_task (FConvertFloatTask * task) |
9745 | 0 | { |
9746 | 0 | gint i, j; |
9747 | |
|
9748 | 0 | for (i = 0; i < task->height; i++) { |
9749 | 0 | const guint8 *s = task->s[0] + i * task->sstride[0]; |
9750 | 0 | guint8 *d = task->d[0] + i * task->dstride[0]; |
9751 | |
|
9752 | 0 | for (j = 0; j < task->width; j++) { |
9753 | 0 | orc_union32 u; |
9754 | 0 | guint32 bits; |
9755 | 0 | gfloat r, g, b, a; |
9756 | |
|
9757 | 0 | memcpy (&bits, s, sizeof (bits)); |
9758 | 0 | u.i = GUINT32_SWAP_LE_BE (bits); |
9759 | 0 | r = u.f; |
9760 | |
|
9761 | 0 | memcpy (&bits, s + 4, sizeof (bits)); |
9762 | 0 | u.i = GUINT32_SWAP_LE_BE (bits); |
9763 | 0 | g = u.f; |
9764 | |
|
9765 | 0 | memcpy (&bits, s + 8, sizeof (bits)); |
9766 | 0 | u.i = GUINT32_SWAP_LE_BE (bits); |
9767 | 0 | b = u.f; |
9768 | |
|
9769 | 0 | memcpy (&bits, s + 12, sizeof (bits)); |
9770 | 0 | u.i = GUINT32_SWAP_LE_BE (bits); |
9771 | 0 | a = u.f; |
9772 | |
|
9773 | 0 | r = CLAMP (r, task->min, task->max); |
9774 | 0 | g = CLAMP (g, task->min, task->max); |
9775 | 0 | b = CLAMP (b, task->min, task->max); |
9776 | 0 | a = CLAMP (a, task->min, task->max); |
9777 | |
|
9778 | 0 | d[0] = (guint8) (r * task->scale + task->offset); |
9779 | 0 | d[1] = (guint8) (g * task->scale + task->offset); |
9780 | 0 | d[2] = (guint8) (b * task->scale + task->offset); |
9781 | 0 | d[3] = (guint8) (a * 255.0f); |
9782 | |
|
9783 | 0 | s += 4 * sizeof (gfloat); |
9784 | 0 | d += 4; |
9785 | 0 | } |
9786 | 0 | } |
9787 | 0 | } |
9788 | | |
9789 | | static void |
9790 | | convert_RGBA_F32_RGBA (GstVideoConverter * convert, |
9791 | | const GstVideoFrame * src, GstVideoFrame * dest) |
9792 | 0 | { |
9793 | 0 | gint width = convert->in_width; |
9794 | 0 | gint height = convert->in_height; |
9795 | 0 | guint8 *s, *d; |
9796 | 0 | FConvertFloatTask *tasks; |
9797 | 0 | FConvertFloatTask **tasks_p; |
9798 | 0 | gint n_threads, lines_per_thread, i; |
9799 | 0 | gfloat scale, offset, min, max; |
9800 | 0 | gboolean swap; |
9801 | 0 | GstParallelizedTaskFunc task_func; |
9802 | |
|
9803 | 0 | s = FRAME_GET_LINE (src, convert->in_y); |
9804 | 0 | s += convert->in_x * 4 * sizeof (gfloat); |
9805 | |
|
9806 | 0 | d = FRAME_GET_LINE (dest, convert->out_y); |
9807 | 0 | d += convert->out_x * 4; |
9808 | |
|
9809 | 0 | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
9810 | 0 | swap = GST_VIDEO_FRAME_FORMAT (src) == GST_VIDEO_FORMAT_RGBA_F32BE; |
9811 | | #else |
9812 | | swap = GST_VIDEO_FRAME_FORMAT (src) == GST_VIDEO_FORMAT_RGBA_F32LE; |
9813 | | #endif |
9814 | |
|
9815 | 0 | if (convert->out_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
9816 | 0 | gdouble out_offset[GST_VIDEO_MAX_COMPONENTS]; |
9817 | 0 | gdouble out_scale[GST_VIDEO_MAX_COMPONENTS]; |
9818 | |
|
9819 | 0 | gst_video_color_range_offsets_full (GST_VIDEO_COLOR_RANGE_16_235, |
9820 | 0 | convert->out_info.finfo, out_offset, out_scale, NULL); |
9821 | |
|
9822 | 0 | scale = out_scale[0]; |
9823 | 0 | offset = out_offset[0]; |
9824 | 0 | min = 0.0f; |
9825 | 0 | max = 1.0f; |
9826 | |
|
9827 | 0 | task_func = swap ? |
9828 | 0 | (GstParallelizedTaskFunc) convert_RGBA_F32_RGBA_range_swap_task : |
9829 | 0 | (GstParallelizedTaskFunc) convert_RGBA_F32_RGBA_range_task; |
9830 | 0 | } else { |
9831 | 0 | scale = 255.0f; |
9832 | 0 | offset = 0.0f; |
9833 | 0 | min = 0.0f; |
9834 | 0 | max = 1.0f; |
9835 | |
|
9836 | 0 | task_func = swap ? |
9837 | 0 | (GstParallelizedTaskFunc) convert_RGBA_F32_RGBA_swap_task : |
9838 | 0 | (GstParallelizedTaskFunc) convert_RGBA_F32_RGBA_task; |
9839 | 0 | } |
9840 | |
|
9841 | 0 | n_threads = convert->conversion_runner->n_threads; |
9842 | |
|
9843 | 0 | tasks = convert->tasks[0] = |
9844 | 0 | g_renew (FConvertFloatTask, convert->tasks[0], n_threads); |
9845 | 0 | tasks_p = convert->tasks_p[0] = |
9846 | 0 | g_renew (FConvertFloatTask *, convert->tasks_p[0], n_threads); |
9847 | |
|
9848 | 0 | lines_per_thread = (height + n_threads - 1) / n_threads; |
9849 | |
|
9850 | 0 | for (i = 0; i < n_threads; i++) { |
9851 | 0 | tasks[i].sstride[0] = FRAME_GET_STRIDE (src); |
9852 | 0 | tasks[i].dstride[0] = FRAME_GET_STRIDE (dest); |
9853 | 0 | tasks[i].s[0] = s + i * lines_per_thread * tasks[i].sstride[0]; |
9854 | 0 | tasks[i].d[0] = d + i * lines_per_thread * tasks[i].dstride[0]; |
9855 | |
|
9856 | 0 | tasks[i].width = width; |
9857 | 0 | tasks[i].height = |
9858 | 0 | MIN ((i + 1) * lines_per_thread, height) - i * lines_per_thread; |
9859 | |
|
9860 | 0 | tasks[i].scale = scale; |
9861 | 0 | tasks[i].offset = offset; |
9862 | 0 | tasks[i].min = min; |
9863 | 0 | tasks[i].max = max; |
9864 | |
|
9865 | 0 | tasks_p[i] = &tasks[i]; |
9866 | 0 | } |
9867 | |
|
9868 | 0 | gst_parallelized_task_runner_run (convert->conversion_runner, |
9869 | 0 | task_func, (gpointer) tasks_p); |
9870 | 0 | } |
9871 | | |
9872 | | /* Fast paths */ |
9873 | | |
9874 | | typedef struct |
9875 | | { |
9876 | | GstVideoFormat in_format; |
9877 | | GstVideoFormat out_format; |
9878 | | gboolean keeps_interlaced; |
9879 | | gboolean needs_color_matrix; |
9880 | | gboolean keeps_size; |
9881 | | gboolean do_crop; |
9882 | | gboolean do_border; |
9883 | | gboolean alpha_copy; |
9884 | | gboolean alpha_set; |
9885 | | gboolean alpha_mult; |
9886 | | gint width_align, height_align; |
9887 | | void (*convert) (GstVideoConverter * convert, const GstVideoFrame * src, |
9888 | | GstVideoFrame * dest); |
9889 | | } VideoTransform; |
9890 | | |
9891 | | static const VideoTransform transforms[] = { |
9892 | | /* direct half <-> float RGBA conversion (no color conversion, no |
9893 | | * resampling); the convert functions carry the alpha component through, |
9894 | | * so alpha_copy is set */ |
9895 | | {GST_VIDEO_FORMAT_RGBA_F16LE, GST_VIDEO_FORMAT_RGBA_F32LE, TRUE, FALSE, TRUE, |
9896 | | FALSE, FALSE, TRUE, FALSE, FALSE, 0, 0, convert_RGBA_F16_F32}, |
9897 | | {GST_VIDEO_FORMAT_RGBA_F16BE, GST_VIDEO_FORMAT_RGBA_F32BE, TRUE, FALSE, TRUE, |
9898 | | FALSE, FALSE, TRUE, FALSE, FALSE, 0, 0, convert_RGBA_F16_F32}, |
9899 | | {GST_VIDEO_FORMAT_RGBA_F32LE, GST_VIDEO_FORMAT_RGBA_F16LE, TRUE, FALSE, TRUE, |
9900 | | FALSE, FALSE, TRUE, FALSE, FALSE, 0, 0, convert_RGBA_F32_F16}, |
9901 | | {GST_VIDEO_FORMAT_RGBA_F32BE, GST_VIDEO_FORMAT_RGBA_F16BE, TRUE, FALSE, TRUE, |
9902 | | FALSE, FALSE, TRUE, FALSE, FALSE, 0, 0, convert_RGBA_F32_F16}, |
9903 | | |
9904 | | /* planar -> packed */ |
9905 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_YUY2, TRUE, FALSE, TRUE, FALSE, |
9906 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_I420_YUY2}, |
9907 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_UYVY, TRUE, FALSE, TRUE, FALSE, |
9908 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_I420_UYVY}, |
9909 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_AYUV, TRUE, FALSE, TRUE, FALSE, |
9910 | | FALSE, FALSE, TRUE, FALSE, 0, 0, convert_I420_AYUV}, |
9911 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, FALSE, |
9912 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_I420_v210}, |
9913 | | |
9914 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_YUY2, TRUE, FALSE, TRUE, FALSE, |
9915 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_I420_YUY2}, |
9916 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_UYVY, TRUE, FALSE, TRUE, FALSE, |
9917 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_I420_UYVY}, |
9918 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_AYUV, TRUE, FALSE, TRUE, FALSE, |
9919 | | FALSE, FALSE, TRUE, FALSE, 0, 0, convert_I420_AYUV}, |
9920 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, FALSE, |
9921 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_I420_v210}, |
9922 | | |
9923 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_YUY2, TRUE, FALSE, TRUE, TRUE, |
9924 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_Y42B_YUY2}, |
9925 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_UYVY, TRUE, FALSE, TRUE, TRUE, |
9926 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_Y42B_UYVY}, |
9927 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_AYUV, TRUE, FALSE, TRUE, TRUE, |
9928 | | TRUE, FALSE, TRUE, FALSE, 1, 0, convert_Y42B_AYUV}, |
9929 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, TRUE, |
9930 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_Y42B_v210}, |
9931 | | |
9932 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_YUY2, TRUE, FALSE, TRUE, TRUE, |
9933 | | TRUE, FALSE, FALSE, FALSE, 1, 0, convert_Y444_YUY2}, |
9934 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_UYVY, TRUE, FALSE, TRUE, TRUE, |
9935 | | TRUE, FALSE, FALSE, FALSE, 1, 0, convert_Y444_UYVY}, |
9936 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_AYUV, TRUE, FALSE, TRUE, TRUE, |
9937 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_Y444_AYUV}, |
9938 | | |
9939 | | /* packed -> packed */ |
9940 | | {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_YUY2, TRUE, FALSE, FALSE, TRUE, |
9941 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
9942 | | {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_UYVY, TRUE, FALSE, TRUE, TRUE, |
9943 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_UYVY_YUY2}, /* alias */ |
9944 | | {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_AYUV, TRUE, FALSE, TRUE, TRUE, |
9945 | | TRUE, FALSE, TRUE, FALSE, 1, 0, convert_YUY2_AYUV}, |
9946 | | {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, FALSE, |
9947 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_YUY2_v210}, |
9948 | | |
9949 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_UYVY, TRUE, FALSE, FALSE, TRUE, |
9950 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
9951 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_YUY2, TRUE, FALSE, TRUE, TRUE, |
9952 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_UYVY_YUY2}, |
9953 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_AYUV, TRUE, FALSE, TRUE, TRUE, |
9954 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_UYVY_AYUV}, |
9955 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, FALSE, |
9956 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_UYVY_v210}, |
9957 | | |
9958 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_AYUV, TRUE, FALSE, FALSE, TRUE, TRUE, |
9959 | | TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
9960 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_YUY2, TRUE, FALSE, TRUE, TRUE, |
9961 | | TRUE, FALSE, FALSE, FALSE, 1, 0, convert_AYUV_YUY2}, |
9962 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_UYVY, TRUE, FALSE, TRUE, TRUE, |
9963 | | TRUE, FALSE, FALSE, FALSE, 1, 0, convert_AYUV_UYVY}, |
9964 | | |
9965 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_UYVY, TRUE, FALSE, TRUE, FALSE, |
9966 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_v210_UYVY}, |
9967 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_YUY2, TRUE, FALSE, TRUE, FALSE, |
9968 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_v210_YUY2}, |
9969 | | |
9970 | | /* packed -> planar */ |
9971 | | {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_I420, TRUE, FALSE, TRUE, FALSE, |
9972 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_YUY2_I420}, |
9973 | | {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_YV12, TRUE, FALSE, TRUE, FALSE, |
9974 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_YUY2_I420}, |
9975 | | {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_Y42B, TRUE, FALSE, TRUE, TRUE, |
9976 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_YUY2_Y42B}, |
9977 | | {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_Y444, TRUE, FALSE, TRUE, TRUE, |
9978 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_YUY2_Y444}, |
9979 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_GRAY8, TRUE, TRUE, TRUE, TRUE, |
9980 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_UYVY_GRAY8}, |
9981 | | |
9982 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_I420, TRUE, FALSE, TRUE, FALSE, |
9983 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_UYVY_I420}, |
9984 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_YV12, TRUE, FALSE, TRUE, FALSE, |
9985 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_UYVY_I420}, |
9986 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_Y42B, TRUE, FALSE, TRUE, TRUE, |
9987 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_UYVY_Y42B}, |
9988 | | {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_Y444, TRUE, FALSE, TRUE, TRUE, |
9989 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_UYVY_Y444}, |
9990 | | |
9991 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_I420, FALSE, FALSE, TRUE, TRUE, |
9992 | | TRUE, FALSE, FALSE, FALSE, 1, 1, convert_AYUV_I420}, |
9993 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_YV12, FALSE, FALSE, TRUE, TRUE, |
9994 | | TRUE, FALSE, FALSE, FALSE, 1, 1, convert_AYUV_I420}, |
9995 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_Y42B, TRUE, FALSE, TRUE, TRUE, |
9996 | | TRUE, FALSE, FALSE, FALSE, 1, 0, convert_AYUV_Y42B}, |
9997 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_Y444, TRUE, FALSE, TRUE, TRUE, |
9998 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_AYUV_Y444}, |
9999 | | |
10000 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_I420, TRUE, FALSE, TRUE, FALSE, |
10001 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_v210_I420}, |
10002 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_YV12, TRUE, FALSE, TRUE, FALSE, |
10003 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_v210_I420}, |
10004 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_Y42B, TRUE, FALSE, TRUE, FALSE, |
10005 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_v210_Y42B}, |
10006 | | |
10007 | | #if G_BYTE_ORDER == G_LITTLE_ENDIAN |
10008 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_I420_10LE, TRUE, FALSE, TRUE, FALSE, |
10009 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_v210_I420_10}, |
10010 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_I422_10LE, TRUE, FALSE, TRUE, FALSE, |
10011 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_v210_I422_10}, |
10012 | | {GST_VIDEO_FORMAT_I420_10LE, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, FALSE, |
10013 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_I420_10_v210}, |
10014 | | {GST_VIDEO_FORMAT_I422_10LE, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, TRUE, |
10015 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I422_10_v210}, |
10016 | | #else |
10017 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_I420_10BE, TRUE, FALSE, TRUE, FALSE, |
10018 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_v210_I420_10}, |
10019 | | {GST_VIDEO_FORMAT_v210, GST_VIDEO_FORMAT_I422_10BE, TRUE, FALSE, TRUE, FALSE, |
10020 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_v210_I422_10}, |
10021 | | {GST_VIDEO_FORMAT_I420_10BE, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, FALSE, |
10022 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_I420_10_v210}, |
10023 | | {GST_VIDEO_FORMAT_I422_10BE, GST_VIDEO_FORMAT_v210, TRUE, FALSE, TRUE, TRUE, |
10024 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I422_10_v210}, |
10025 | | #endif |
10026 | | |
10027 | | /* planar -> planar */ |
10028 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_I420, TRUE, FALSE, FALSE, TRUE, |
10029 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10030 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_YV12, TRUE, FALSE, FALSE, TRUE, |
10031 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10032 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_Y41B, FALSE, FALSE, FALSE, TRUE, |
10033 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10034 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_Y42B, FALSE, FALSE, FALSE, TRUE, |
10035 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10036 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_Y444, FALSE, FALSE, FALSE, TRUE, |
10037 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10038 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_GRAY8, FALSE, FALSE, FALSE, TRUE, |
10039 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10040 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_A420, FALSE, FALSE, FALSE, TRUE, |
10041 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_scale_planes}, |
10042 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_YUV9, FALSE, FALSE, FALSE, TRUE, |
10043 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10044 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_YVU9, FALSE, FALSE, FALSE, TRUE, |
10045 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10046 | | |
10047 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_I420, TRUE, FALSE, FALSE, TRUE, |
10048 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10049 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_YV12, TRUE, FALSE, FALSE, TRUE, |
10050 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10051 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_Y41B, FALSE, FALSE, FALSE, TRUE, |
10052 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10053 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_Y42B, FALSE, FALSE, FALSE, TRUE, |
10054 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10055 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_Y444, FALSE, FALSE, FALSE, TRUE, |
10056 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10057 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_GRAY8, FALSE, FALSE, FALSE, TRUE, |
10058 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10059 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_A420, FALSE, FALSE, FALSE, TRUE, |
10060 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_scale_planes}, |
10061 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_YUV9, FALSE, FALSE, FALSE, TRUE, |
10062 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10063 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_YVU9, FALSE, FALSE, FALSE, TRUE, |
10064 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10065 | | |
10066 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_I420, FALSE, FALSE, FALSE, TRUE, |
10067 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10068 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_YV12, FALSE, FALSE, FALSE, TRUE, |
10069 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10070 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_Y41B, TRUE, FALSE, FALSE, TRUE, |
10071 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10072 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_Y42B, FALSE, FALSE, FALSE, TRUE, |
10073 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10074 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_Y444, FALSE, FALSE, FALSE, TRUE, |
10075 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10076 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_GRAY8, FALSE, FALSE, FALSE, TRUE, |
10077 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10078 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_A420, FALSE, FALSE, FALSE, TRUE, |
10079 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_scale_planes}, |
10080 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_YUV9, FALSE, FALSE, FALSE, TRUE, |
10081 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10082 | | {GST_VIDEO_FORMAT_Y41B, GST_VIDEO_FORMAT_YVU9, FALSE, FALSE, FALSE, TRUE, |
10083 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10084 | | |
10085 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_I420, FALSE, FALSE, FALSE, TRUE, |
10086 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10087 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_YV12, FALSE, FALSE, FALSE, TRUE, |
10088 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10089 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_Y41B, FALSE, FALSE, FALSE, TRUE, |
10090 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10091 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_Y42B, TRUE, FALSE, FALSE, TRUE, |
10092 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10093 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_Y444, FALSE, FALSE, FALSE, TRUE, |
10094 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10095 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_GRAY8, FALSE, FALSE, FALSE, TRUE, |
10096 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10097 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_A420, FALSE, FALSE, FALSE, TRUE, |
10098 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_scale_planes}, |
10099 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_YUV9, FALSE, FALSE, FALSE, TRUE, |
10100 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10101 | | {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_YVU9, FALSE, FALSE, FALSE, TRUE, |
10102 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10103 | | |
10104 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_I420, FALSE, FALSE, FALSE, TRUE, |
10105 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10106 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_YV12, FALSE, FALSE, FALSE, TRUE, |
10107 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10108 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_Y41B, FALSE, FALSE, FALSE, TRUE, |
10109 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10110 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_Y42B, FALSE, FALSE, FALSE, TRUE, |
10111 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10112 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_Y444, TRUE, FALSE, FALSE, TRUE, |
10113 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10114 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_GRAY8, FALSE, FALSE, FALSE, TRUE, |
10115 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10116 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_A420, FALSE, FALSE, FALSE, TRUE, |
10117 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_scale_planes}, |
10118 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_YUV9, FALSE, FALSE, FALSE, TRUE, |
10119 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10120 | | {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_YVU9, FALSE, FALSE, FALSE, TRUE, |
10121 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10122 | | |
10123 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_I420, FALSE, FALSE, FALSE, TRUE, |
10124 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10125 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_YV12, FALSE, FALSE, FALSE, TRUE, |
10126 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10127 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_Y41B, FALSE, FALSE, FALSE, TRUE, |
10128 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10129 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_Y42B, FALSE, FALSE, FALSE, TRUE, |
10130 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10131 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_Y444, FALSE, FALSE, FALSE, TRUE, |
10132 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10133 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_GRAY8, TRUE, FALSE, FALSE, TRUE, |
10134 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10135 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_A420, FALSE, FALSE, FALSE, TRUE, |
10136 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_scale_planes}, |
10137 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_YUV9, FALSE, FALSE, FALSE, TRUE, |
10138 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10139 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_YVU9, FALSE, FALSE, FALSE, TRUE, |
10140 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10141 | | |
10142 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_I420, FALSE, FALSE, FALSE, TRUE, |
10143 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10144 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_YV12, FALSE, FALSE, FALSE, TRUE, |
10145 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10146 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_Y41B, FALSE, FALSE, FALSE, TRUE, |
10147 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10148 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_Y42B, FALSE, FALSE, FALSE, TRUE, |
10149 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10150 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_Y444, FALSE, FALSE, FALSE, TRUE, |
10151 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10152 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_GRAY8, FALSE, FALSE, FALSE, TRUE, |
10153 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10154 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_A420, TRUE, FALSE, FALSE, TRUE, |
10155 | | TRUE, TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10156 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_YUV9, FALSE, FALSE, FALSE, TRUE, |
10157 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10158 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_YVU9, FALSE, FALSE, FALSE, TRUE, |
10159 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10160 | | |
10161 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_I420, FALSE, FALSE, FALSE, TRUE, |
10162 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10163 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_YV12, FALSE, FALSE, FALSE, TRUE, |
10164 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10165 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_Y41B, FALSE, FALSE, FALSE, TRUE, |
10166 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10167 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_Y42B, FALSE, FALSE, FALSE, TRUE, |
10168 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10169 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_Y444, FALSE, FALSE, FALSE, TRUE, |
10170 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10171 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_GRAY8, FALSE, FALSE, FALSE, TRUE, |
10172 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10173 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_A420, FALSE, FALSE, FALSE, TRUE, |
10174 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_scale_planes}, |
10175 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_YUV9, TRUE, FALSE, FALSE, TRUE, |
10176 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10177 | | {GST_VIDEO_FORMAT_YUV9, GST_VIDEO_FORMAT_YVU9, TRUE, FALSE, FALSE, TRUE, |
10178 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10179 | | |
10180 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_I420, FALSE, FALSE, FALSE, TRUE, |
10181 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10182 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_YV12, FALSE, FALSE, FALSE, TRUE, |
10183 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10184 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_Y41B, FALSE, FALSE, FALSE, TRUE, |
10185 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10186 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_Y42B, FALSE, FALSE, FALSE, TRUE, |
10187 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10188 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_Y444, FALSE, FALSE, FALSE, TRUE, |
10189 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10190 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_GRAY8, FALSE, FALSE, FALSE, TRUE, |
10191 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10192 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_A420, FALSE, FALSE, FALSE, TRUE, |
10193 | | TRUE, FALSE, TRUE, FALSE, 0, 0, convert_scale_planes}, |
10194 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_YUV9, TRUE, FALSE, FALSE, TRUE, |
10195 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10196 | | {GST_VIDEO_FORMAT_YVU9, GST_VIDEO_FORMAT_YVU9, TRUE, FALSE, FALSE, TRUE, |
10197 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10198 | | |
10199 | | /* sempiplanar -> semiplanar */ |
10200 | | {GST_VIDEO_FORMAT_NV12, GST_VIDEO_FORMAT_NV12, TRUE, FALSE, FALSE, TRUE, |
10201 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10202 | | {GST_VIDEO_FORMAT_NV12, GST_VIDEO_FORMAT_NV16, TRUE, FALSE, FALSE, TRUE, |
10203 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10204 | | {GST_VIDEO_FORMAT_NV12, GST_VIDEO_FORMAT_NV24, TRUE, FALSE, FALSE, TRUE, |
10205 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10206 | | |
10207 | | {GST_VIDEO_FORMAT_NV21, GST_VIDEO_FORMAT_NV21, TRUE, FALSE, FALSE, TRUE, |
10208 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10209 | | |
10210 | | {GST_VIDEO_FORMAT_NV16, GST_VIDEO_FORMAT_NV12, TRUE, FALSE, FALSE, TRUE, |
10211 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10212 | | {GST_VIDEO_FORMAT_NV16, GST_VIDEO_FORMAT_NV16, TRUE, FALSE, FALSE, TRUE, |
10213 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10214 | | {GST_VIDEO_FORMAT_NV16, GST_VIDEO_FORMAT_NV24, TRUE, FALSE, FALSE, TRUE, |
10215 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10216 | | |
10217 | | {GST_VIDEO_FORMAT_NV61, GST_VIDEO_FORMAT_NV61, TRUE, FALSE, FALSE, TRUE, |
10218 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10219 | | |
10220 | | {GST_VIDEO_FORMAT_NV24, GST_VIDEO_FORMAT_NV12, TRUE, FALSE, FALSE, TRUE, |
10221 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10222 | | {GST_VIDEO_FORMAT_NV24, GST_VIDEO_FORMAT_NV16, TRUE, FALSE, FALSE, TRUE, |
10223 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10224 | | {GST_VIDEO_FORMAT_NV24, GST_VIDEO_FORMAT_NV24, TRUE, FALSE, FALSE, TRUE, |
10225 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10226 | | |
10227 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_ARGB, TRUE, TRUE, TRUE, TRUE, TRUE, |
10228 | | TRUE, FALSE, FALSE, 0, 0, convert_AYUV_ARGB}, |
10229 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_BGRA, TRUE, TRUE, TRUE, TRUE, TRUE, |
10230 | | TRUE, FALSE, FALSE, 0, 0, convert_AYUV_BGRA}, |
10231 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_xRGB, TRUE, TRUE, TRUE, TRUE, TRUE, |
10232 | | FALSE, FALSE, FALSE, 0, 0, convert_AYUV_ARGB}, /* alias */ |
10233 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_BGRx, TRUE, TRUE, TRUE, TRUE, TRUE, |
10234 | | FALSE, FALSE, FALSE, 0, 0, convert_AYUV_BGRA}, /* alias */ |
10235 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_ABGR, TRUE, TRUE, TRUE, TRUE, TRUE, |
10236 | | TRUE, FALSE, FALSE, 0, 0, convert_AYUV_ABGR}, |
10237 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_RGBA, TRUE, TRUE, TRUE, TRUE, TRUE, |
10238 | | TRUE, FALSE, FALSE, 0, 0, convert_AYUV_RGBA}, |
10239 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_xBGR, TRUE, TRUE, TRUE, TRUE, TRUE, |
10240 | | FALSE, FALSE, FALSE, 0, 0, convert_AYUV_ABGR}, /* alias */ |
10241 | | {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_RGBx, TRUE, TRUE, TRUE, TRUE, TRUE, |
10242 | | FALSE, FALSE, FALSE, 0, 0, convert_AYUV_RGBA}, /* alias */ |
10243 | | |
10244 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_BGRA, FALSE, TRUE, TRUE, TRUE, |
10245 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_BGRA}, |
10246 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_BGRx, FALSE, TRUE, TRUE, TRUE, |
10247 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_BGRA}, |
10248 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_BGRA, FALSE, TRUE, TRUE, TRUE, |
10249 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_BGRA}, |
10250 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_BGRx, FALSE, TRUE, TRUE, TRUE, |
10251 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_BGRA}, |
10252 | | |
10253 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_ARGB, FALSE, TRUE, TRUE, TRUE, |
10254 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_ARGB}, |
10255 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_xRGB, FALSE, TRUE, TRUE, TRUE, |
10256 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_ARGB}, |
10257 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_ARGB, FALSE, TRUE, TRUE, TRUE, |
10258 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_ARGB}, |
10259 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_xRGB, FALSE, TRUE, TRUE, TRUE, |
10260 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_ARGB}, |
10261 | | |
10262 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_ABGR, FALSE, TRUE, TRUE, TRUE, |
10263 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10264 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_xBGR, FALSE, TRUE, TRUE, TRUE, |
10265 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10266 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_RGBA, FALSE, TRUE, TRUE, TRUE, |
10267 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10268 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_RGBx, FALSE, TRUE, TRUE, TRUE, |
10269 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10270 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_RGB, FALSE, TRUE, TRUE, TRUE, |
10271 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10272 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_BGR, FALSE, TRUE, TRUE, TRUE, |
10273 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10274 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_RGB15, FALSE, TRUE, TRUE, TRUE, |
10275 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10276 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_BGR15, FALSE, TRUE, TRUE, TRUE, |
10277 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10278 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_RGB16, FALSE, TRUE, TRUE, TRUE, |
10279 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10280 | | {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_BGR16, FALSE, TRUE, TRUE, TRUE, |
10281 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10282 | | |
10283 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_ABGR, FALSE, TRUE, TRUE, TRUE, |
10284 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10285 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_xBGR, FALSE, TRUE, TRUE, TRUE, |
10286 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10287 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_RGBA, FALSE, TRUE, TRUE, TRUE, |
10288 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10289 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_RGBx, FALSE, TRUE, TRUE, TRUE, |
10290 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10291 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_RGB, FALSE, TRUE, TRUE, TRUE, |
10292 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10293 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_BGR, FALSE, TRUE, TRUE, TRUE, |
10294 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10295 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_RGB15, FALSE, TRUE, TRUE, TRUE, |
10296 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10297 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_BGR15, FALSE, TRUE, TRUE, TRUE, |
10298 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10299 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_RGB16, FALSE, TRUE, TRUE, TRUE, |
10300 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10301 | | {GST_VIDEO_FORMAT_YV12, GST_VIDEO_FORMAT_BGR16, FALSE, TRUE, TRUE, TRUE, |
10302 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10303 | | |
10304 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_ABGR, FALSE, TRUE, TRUE, TRUE, |
10305 | | TRUE, TRUE, FALSE, FALSE, 0, 0, convert_A420_pack_ARGB}, |
10306 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_RGBA, FALSE, TRUE, TRUE, TRUE, |
10307 | | TRUE, TRUE, FALSE, FALSE, 0, 0, convert_A420_pack_ARGB}, |
10308 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_BGRA, FALSE, TRUE, TRUE, TRUE, |
10309 | | TRUE, TRUE, FALSE, FALSE, 0, 0, convert_A420_BGRA}, |
10310 | | /* A420 to non-alpha RGB formats, reuse I420_* method */ |
10311 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_BGRx, FALSE, TRUE, TRUE, TRUE, |
10312 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_BGRA}, |
10313 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_xBGR, FALSE, TRUE, TRUE, TRUE, |
10314 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10315 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_RGBx, FALSE, TRUE, TRUE, TRUE, |
10316 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10317 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_RGB, FALSE, TRUE, TRUE, TRUE, |
10318 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10319 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_BGR, FALSE, TRUE, TRUE, TRUE, |
10320 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10321 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_RGB15, FALSE, TRUE, TRUE, TRUE, |
10322 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10323 | | {GST_VIDEO_FORMAT_A420, GST_VIDEO_FORMAT_BGR16, FALSE, TRUE, TRUE, TRUE, |
10324 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_I420_pack_ARGB}, |
10325 | | |
10326 | | /* scalers */ |
10327 | | {GST_VIDEO_FORMAT_GBR, GST_VIDEO_FORMAT_GBR, TRUE, FALSE, FALSE, TRUE, |
10328 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10329 | | {GST_VIDEO_FORMAT_GBRA, GST_VIDEO_FORMAT_GBRA, TRUE, FALSE, FALSE, TRUE, |
10330 | | TRUE, TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10331 | | {GST_VIDEO_FORMAT_RGBP, GST_VIDEO_FORMAT_RGBP, TRUE, FALSE, FALSE, TRUE, |
10332 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10333 | | {GST_VIDEO_FORMAT_BGRP, GST_VIDEO_FORMAT_BGRP, TRUE, FALSE, FALSE, TRUE, |
10334 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10335 | | |
10336 | | {GST_VIDEO_FORMAT_YVYU, GST_VIDEO_FORMAT_YVYU, TRUE, FALSE, FALSE, TRUE, |
10337 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10338 | | |
10339 | | {GST_VIDEO_FORMAT_RGB15, GST_VIDEO_FORMAT_RGB15, TRUE, FALSE, FALSE, TRUE, |
10340 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10341 | | {GST_VIDEO_FORMAT_RGB16, GST_VIDEO_FORMAT_RGB16, TRUE, FALSE, FALSE, TRUE, |
10342 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10343 | | {GST_VIDEO_FORMAT_BGR15, GST_VIDEO_FORMAT_BGR15, TRUE, FALSE, FALSE, TRUE, |
10344 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10345 | | {GST_VIDEO_FORMAT_BGR16, GST_VIDEO_FORMAT_BGR16, TRUE, FALSE, FALSE, TRUE, |
10346 | | TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10347 | | |
10348 | | {GST_VIDEO_FORMAT_RGB, GST_VIDEO_FORMAT_RGB, TRUE, FALSE, FALSE, TRUE, TRUE, |
10349 | | FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10350 | | {GST_VIDEO_FORMAT_BGR, GST_VIDEO_FORMAT_BGR, TRUE, FALSE, FALSE, TRUE, TRUE, |
10351 | | FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10352 | | {GST_VIDEO_FORMAT_v308, GST_VIDEO_FORMAT_v308, TRUE, FALSE, FALSE, TRUE, TRUE, |
10353 | | FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10354 | | {GST_VIDEO_FORMAT_IYU2, GST_VIDEO_FORMAT_IYU2, TRUE, FALSE, FALSE, TRUE, TRUE, |
10355 | | FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10356 | | |
10357 | | {GST_VIDEO_FORMAT_ARGB, GST_VIDEO_FORMAT_ARGB, TRUE, FALSE, FALSE, TRUE, TRUE, |
10358 | | TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10359 | | {GST_VIDEO_FORMAT_xRGB, GST_VIDEO_FORMAT_xRGB, TRUE, FALSE, FALSE, TRUE, TRUE, |
10360 | | FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10361 | | {GST_VIDEO_FORMAT_ABGR, GST_VIDEO_FORMAT_ABGR, TRUE, FALSE, FALSE, TRUE, TRUE, |
10362 | | TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10363 | | {GST_VIDEO_FORMAT_xBGR, GST_VIDEO_FORMAT_xBGR, TRUE, FALSE, FALSE, TRUE, TRUE, |
10364 | | FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10365 | | {GST_VIDEO_FORMAT_RGBA, GST_VIDEO_FORMAT_RGBA, TRUE, FALSE, FALSE, TRUE, TRUE, |
10366 | | TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10367 | | {GST_VIDEO_FORMAT_RGBx, GST_VIDEO_FORMAT_RGBx, TRUE, FALSE, FALSE, TRUE, TRUE, |
10368 | | FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10369 | | {GST_VIDEO_FORMAT_BGRA, GST_VIDEO_FORMAT_BGRA, TRUE, FALSE, FALSE, TRUE, TRUE, |
10370 | | TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10371 | | {GST_VIDEO_FORMAT_BGRx, GST_VIDEO_FORMAT_BGRx, TRUE, FALSE, FALSE, TRUE, TRUE, |
10372 | | FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10373 | | |
10374 | | {GST_VIDEO_FORMAT_ARGB64, GST_VIDEO_FORMAT_ARGB64, TRUE, FALSE, FALSE, TRUE, |
10375 | | TRUE, TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10376 | | {GST_VIDEO_FORMAT_AYUV64, GST_VIDEO_FORMAT_AYUV64, TRUE, FALSE, FALSE, TRUE, |
10377 | | TRUE, TRUE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10378 | | |
10379 | | {GST_VIDEO_FORMAT_GRAY16_LE, GST_VIDEO_FORMAT_GRAY16_LE, TRUE, FALSE, FALSE, |
10380 | | TRUE, TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10381 | | {GST_VIDEO_FORMAT_GRAY16_BE, GST_VIDEO_FORMAT_GRAY16_BE, TRUE, FALSE, FALSE, |
10382 | | TRUE, TRUE, FALSE, FALSE, FALSE, 0, 0, convert_scale_planes}, |
10383 | | |
10384 | | {GST_VIDEO_FORMAT_RGB, GST_VIDEO_FORMAT_RGB_F32LE, TRUE, FALSE, TRUE, FALSE, |
10385 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_RGB_RGB_F32}, |
10386 | | {GST_VIDEO_FORMAT_RGB, GST_VIDEO_FORMAT_RGB_F32BE, TRUE, FALSE, TRUE, FALSE, |
10387 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_RGB_RGB_F32}, |
10388 | | {GST_VIDEO_FORMAT_RGB_F32LE, GST_VIDEO_FORMAT_RGB, TRUE, FALSE, TRUE, FALSE, |
10389 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_RGB_F32_RGB}, |
10390 | | {GST_VIDEO_FORMAT_RGB_F32BE, GST_VIDEO_FORMAT_RGB, TRUE, FALSE, TRUE, FALSE, |
10391 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_RGB_F32_RGB}, |
10392 | | |
10393 | | {GST_VIDEO_FORMAT_RGBP, GST_VIDEO_FORMAT_RGBP_F32LE, TRUE, FALSE, TRUE, FALSE, |
10394 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_RGBP_RGBP_F32}, |
10395 | | {GST_VIDEO_FORMAT_RGBP, GST_VIDEO_FORMAT_RGBP_F32BE, TRUE, FALSE, TRUE, FALSE, |
10396 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_RGBP_RGBP_F32}, |
10397 | | {GST_VIDEO_FORMAT_RGBP_F32LE, GST_VIDEO_FORMAT_RGBP, TRUE, FALSE, TRUE, FALSE, |
10398 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_RGBP_F32_RGBP}, |
10399 | | {GST_VIDEO_FORMAT_RGBP_F32BE, GST_VIDEO_FORMAT_RGBP, TRUE, FALSE, TRUE, FALSE, |
10400 | | FALSE, FALSE, FALSE, FALSE, 0, 0, convert_RGBP_F32_RGBP}, |
10401 | | |
10402 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_GRAY_F32LE, TRUE, FALSE, TRUE, |
10403 | | FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0, convert_GRAY8_GRAY_F32}, |
10404 | | {GST_VIDEO_FORMAT_GRAY8, GST_VIDEO_FORMAT_GRAY_F32BE, TRUE, FALSE, TRUE, |
10405 | | FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0, convert_GRAY8_GRAY_F32}, |
10406 | | {GST_VIDEO_FORMAT_GRAY_F32LE, GST_VIDEO_FORMAT_GRAY8, TRUE, FALSE, TRUE, |
10407 | | FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0, convert_GRAY_F32_GRAY8}, |
10408 | | {GST_VIDEO_FORMAT_GRAY_F32BE, GST_VIDEO_FORMAT_GRAY8, TRUE, FALSE, TRUE, |
10409 | | FALSE, FALSE, FALSE, FALSE, FALSE, 0, 0, convert_GRAY_F32_GRAY8}, |
10410 | | |
10411 | | {GST_VIDEO_FORMAT_RGBA, GST_VIDEO_FORMAT_RGBA_F32LE, TRUE, FALSE, TRUE, |
10412 | | FALSE, FALSE, TRUE, FALSE, FALSE, 0, 0, convert_RGBA_RGBA_F32}, |
10413 | | {GST_VIDEO_FORMAT_RGBA, GST_VIDEO_FORMAT_RGBA_F32BE, TRUE, FALSE, TRUE, |
10414 | | FALSE, FALSE, TRUE, FALSE, FALSE, 0, 0, convert_RGBA_RGBA_F32}, |
10415 | | {GST_VIDEO_FORMAT_RGBA_F32LE, GST_VIDEO_FORMAT_RGBA, TRUE, FALSE, TRUE, |
10416 | | FALSE, FALSE, TRUE, FALSE, FALSE, 0, 0, convert_RGBA_F32_RGBA}, |
10417 | | {GST_VIDEO_FORMAT_RGBA_F32BE, GST_VIDEO_FORMAT_RGBA, TRUE, FALSE, TRUE, |
10418 | | FALSE, FALSE, TRUE, FALSE, FALSE, 0, 0, convert_RGBA_F32_RGBA}, |
10419 | | }; |
10420 | | |
10421 | | static gboolean |
10422 | | video_converter_lookup_fastpath (GstVideoConverter * convert) |
10423 | 2.08k | { |
10424 | 2.08k | int i; |
10425 | 2.08k | GstVideoFormat in_format, out_format; |
10426 | 2.08k | GstVideoTransferFunction in_transf, out_transf; |
10427 | 2.08k | gboolean interlaced, same_matrix, same_primaries, same_size, same_ranges, |
10428 | 2.08k | crop, border; |
10429 | 2.08k | gboolean need_copy, need_set, need_mult; |
10430 | 2.08k | gint width, height; |
10431 | 2.08k | guint in_bpp, out_bpp; |
10432 | | |
10433 | 2.08k | width = GST_VIDEO_INFO_WIDTH (&convert->in_info); |
10434 | 2.08k | height = GST_VIDEO_INFO_FIELD_HEIGHT (&convert->in_info); |
10435 | | |
10436 | 2.08k | if (GET_OPT_DITHER_QUANTIZATION (convert) != 1) |
10437 | 0 | return FALSE; |
10438 | | |
10439 | 2.08k | in_bpp = convert->in_info.finfo->bits; |
10440 | 2.08k | out_bpp = convert->out_info.finfo->bits; |
10441 | | |
10442 | | /* we don't do gamma conversion in fastpath */ |
10443 | 2.08k | in_transf = convert->in_info.colorimetry.transfer; |
10444 | 2.08k | out_transf = convert->out_info.colorimetry.transfer; |
10445 | | |
10446 | 2.08k | same_size = (width == convert->out_width && height == convert->out_height); |
10447 | | |
10448 | | /* fastpaths don't do gamma */ |
10449 | 2.08k | if (CHECK_GAMMA_REMAP (convert) && (!same_size |
10450 | 0 | || !gst_video_transfer_function_is_equivalent (in_transf, in_bpp, |
10451 | 0 | out_transf, out_bpp))) |
10452 | 0 | return FALSE; |
10453 | | |
10454 | 2.08k | need_copy = (convert->alpha_mode & ALPHA_MODE_COPY) == ALPHA_MODE_COPY; |
10455 | 2.08k | need_set = (convert->alpha_mode & ALPHA_MODE_SET) == ALPHA_MODE_SET; |
10456 | 2.08k | need_mult = (convert->alpha_mode & ALPHA_MODE_MULT) == ALPHA_MODE_MULT; |
10457 | 2.08k | GST_LOG ("alpha copy %d, set %d, mult %d", need_copy, need_set, need_mult); |
10458 | | |
10459 | 2.08k | in_format = GST_VIDEO_INFO_FORMAT (&convert->in_info); |
10460 | 2.08k | out_format = GST_VIDEO_INFO_FORMAT (&convert->out_info); |
10461 | | |
10462 | 2.08k | if (CHECK_MATRIX_NONE (convert)) { |
10463 | 0 | same_matrix = TRUE; |
10464 | 2.08k | } else { |
10465 | 2.08k | GstVideoColorMatrix in_matrix, out_matrix; |
10466 | | |
10467 | 2.08k | in_matrix = convert->in_info.colorimetry.matrix; |
10468 | 2.08k | out_matrix = convert->out_info.colorimetry.matrix; |
10469 | 2.08k | same_matrix = in_matrix == out_matrix; |
10470 | 2.08k | } |
10471 | | |
10472 | 2.08k | if (CHECK_PRIMARIES_NONE (convert)) { |
10473 | 2.08k | same_primaries = TRUE; |
10474 | 2.08k | } else { |
10475 | 0 | GstVideoColorPrimaries in_primaries, out_primaries; |
10476 | |
|
10477 | 0 | in_primaries = convert->in_info.colorimetry.primaries; |
10478 | 0 | out_primaries = convert->out_info.colorimetry.primaries; |
10479 | 0 | same_primaries = gst_video_color_primaries_is_equivalent (in_primaries, |
10480 | 0 | out_primaries); |
10481 | 0 | } |
10482 | | |
10483 | 2.08k | same_ranges = TRUE; |
10484 | | |
10485 | 2.08k | if (convert->in_info.colorimetry.range != convert->out_info.colorimetry.range) { |
10486 | | // All other combinations are equivalent |
10487 | 1.01k | if (convert->in_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235 || |
10488 | 1.01k | convert->out_info.colorimetry.range == GST_VIDEO_COLOR_RANGE_16_235) { |
10489 | 1.01k | same_ranges = FALSE; |
10490 | 1.01k | } |
10491 | 1.01k | } |
10492 | | |
10493 | 2.08k | interlaced = GST_VIDEO_INFO_IS_INTERLACED (&convert->in_info); |
10494 | 2.08k | interlaced |= GST_VIDEO_INFO_IS_INTERLACED (&convert->out_info); |
10495 | | |
10496 | 2.08k | crop = convert->in_x || convert->in_y |
10497 | 2.08k | || convert->in_width < convert->in_maxwidth |
10498 | 2.08k | || convert->in_height < convert->in_maxheight; |
10499 | 2.08k | border = convert->out_x || convert->out_y |
10500 | 2.08k | || convert->out_width < convert->out_maxwidth |
10501 | 2.08k | || convert->out_height < convert->out_maxheight; |
10502 | | |
10503 | 353k | for (i = 0; i < G_N_ELEMENTS (transforms); i++) { |
10504 | 353k | if (transforms[i].in_format == in_format && |
10505 | 16.4k | transforms[i].out_format == out_format && |
10506 | 1.33k | (transforms[i].keeps_interlaced || !interlaced) && |
10507 | 1.33k | (transforms[i].needs_color_matrix || (same_matrix && same_primaries |
10508 | 716 | && same_ranges)) |
10509 | 1.30k | && (!transforms[i].keeps_size || same_size) |
10510 | 1.15k | && (transforms[i].width_align & width) == 0 |
10511 | 1.14k | && (transforms[i].height_align & height) == 0 |
10512 | 1.14k | && (transforms[i].do_crop || !crop) |
10513 | 1.14k | && (transforms[i].do_border || !border) |
10514 | 1.14k | && (transforms[i].alpha_copy || !need_copy) |
10515 | 1.14k | && (transforms[i].alpha_set || !need_set) |
10516 | 1.14k | && (transforms[i].alpha_mult || !need_mult)) { |
10517 | 1.14k | guint j; |
10518 | | |
10519 | 1.14k | GST_LOG ("using fastpath"); |
10520 | 1.14k | if (transforms[i].needs_color_matrix) |
10521 | 539 | video_converter_compute_matrix (convert); |
10522 | 1.14k | convert->convert = transforms[i].convert; |
10523 | | |
10524 | 1.14k | convert->tmpline = |
10525 | 1.14k | g_new (guint16 *, convert->conversion_runner->n_threads); |
10526 | 2.28k | for (j = 0; j < convert->conversion_runner->n_threads; j++) |
10527 | 1.14k | convert->tmpline[j] = g_malloc0 (sizeof (guint16) * (width + 8) * 4); |
10528 | | |
10529 | 1.14k | if (!transforms[i].keeps_size) |
10530 | 452 | if (!setup_scale (convert)) |
10531 | 7 | return FALSE; |
10532 | 1.13k | if (border) |
10533 | 0 | setup_borderline (convert); |
10534 | 1.13k | return TRUE; |
10535 | 1.14k | } |
10536 | 353k | } |
10537 | 939 | GST_LOG ("no fastpath found"); |
10538 | 939 | return FALSE; |
10539 | 2.08k | } |
10540 | | |
10541 | | /** |
10542 | | * gst_video_converter_get_in_info: |
10543 | | * @convert: a #GstVideoConverter |
10544 | | * |
10545 | | * Retrieve the input format of @convert. |
10546 | | * |
10547 | | * Returns: (transfer none): a #GstVideoInfo |
10548 | | * |
10549 | | * Since: 1.22 |
10550 | | */ |
10551 | | const GstVideoInfo * |
10552 | | gst_video_converter_get_in_info (GstVideoConverter * convert) |
10553 | 0 | { |
10554 | 0 | return &convert->in_info; |
10555 | 0 | } |
10556 | | |
10557 | | /** |
10558 | | * gst_video_converter_get_out_info: |
10559 | | * @convert: a #GstVideoConverter |
10560 | | * |
10561 | | * Retrieve the output format of @convert. |
10562 | | * |
10563 | | * Returns: (transfer none): a #GstVideoInfo |
10564 | | * |
10565 | | * Since: 1.22 |
10566 | | */ |
10567 | | const GstVideoInfo * |
10568 | | gst_video_converter_get_out_info (GstVideoConverter * convert) |
10569 | 0 | { |
10570 | 0 | return &convert->out_info; |
10571 | 0 | } |
10572 | | |
10573 | | /** |
10574 | | * gst_video_converter_transform_metas: |
10575 | | * @convert: a #GstVideoConverter |
10576 | | * @dest: a writable #GstBuffer |
10577 | | * @src: a #GstBuffer |
10578 | | * |
10579 | | * Transform the GstMeta of @src into @dest using @convert. |
10580 | | * |
10581 | | * Returns: TRUE if any meta was copied |
10582 | | * |
10583 | | * Since: 1.28 |
10584 | | */ |
10585 | | gboolean |
10586 | | gst_video_converter_transform_metas (GstVideoConverter * convert, |
10587 | | GstBuffer * src, GstBuffer * dest) |
10588 | 0 | { |
10589 | 0 | GstMeta *meta; |
10590 | 0 | gpointer state = NULL; |
10591 | 0 | const gchar *valid_tags[] = { |
10592 | 0 | GST_META_TAG_VIDEO_STR, |
10593 | 0 | GST_META_TAG_VIDEO_ORIENTATION_STR, |
10594 | 0 | GST_META_TAG_VIDEO_SIZE_STR, |
10595 | 0 | GST_META_TAG_VIDEO_COLORSPACE_STR, |
10596 | 0 | NULL |
10597 | 0 | }; |
10598 | 0 | gboolean ret = FALSE; |
10599 | 0 | gboolean crop = convert->in_x || convert->in_y |
10600 | 0 | || convert->in_width != convert->in_maxwidth |
10601 | 0 | || convert->in_height != convert->in_maxheight; |
10602 | 0 | gboolean border = convert->out_x || convert->out_y |
10603 | 0 | || convert->out_width != convert->out_maxwidth |
10604 | 0 | || convert->out_height != convert->out_maxheight; |
10605 | |
|
10606 | 0 | GstVideoMetaTransformMatrix trans_matrix; |
10607 | 0 | const GstVideoRectangle in_rectangle = { convert->in_x, convert->in_y, |
10608 | 0 | convert->in_width, convert->in_height |
10609 | 0 | }; |
10610 | 0 | const GstVideoRectangle out_rectangle = { convert->out_x, convert->out_y, |
10611 | 0 | convert->out_width, convert->out_height |
10612 | 0 | }; |
10613 | 0 | GstVideoMetaTransform trans = { |
10614 | 0 | &convert->in_info, |
10615 | 0 | &convert->out_info, |
10616 | 0 | }; |
10617 | |
|
10618 | 0 | g_return_val_if_fail (gst_buffer_is_writable (dest), FALSE); |
10619 | | |
10620 | 0 | if (G_UNLIKELY ((convert->out_width <= 0) || (convert->out_height <= 0))) |
10621 | 0 | return FALSE; |
10622 | | |
10623 | 0 | gst_video_meta_transform_matrix_init (&trans_matrix, &convert->in_info, |
10624 | 0 | &in_rectangle, &convert->out_info, &out_rectangle); |
10625 | |
|
10626 | 0 | while ((meta = gst_buffer_iterate_meta (src, &state))) { |
10627 | 0 | if (meta->info->transform_func == NULL) |
10628 | 0 | continue; |
10629 | | |
10630 | 0 | if (!gst_meta_api_type_tags_contain_only (meta->info->api, valid_tags)) |
10631 | 0 | continue; |
10632 | | |
10633 | 0 | if (!meta->info->transform_func (dest, meta, src, |
10634 | 0 | gst_video_meta_transform_matrix_get_quark (), &trans_matrix)) { |
10635 | 0 | if (!crop && !border) |
10636 | 0 | ret |= meta->info->transform_func (dest, meta, src, |
10637 | 0 | gst_video_meta_transform_scale_get_quark (), &trans); |
10638 | 0 | } else { |
10639 | 0 | ret = TRUE; |
10640 | 0 | } |
10641 | 0 | } |
10642 | |
|
10643 | 0 | return ret; |
10644 | 0 | } |