FFmpeg
swscale_unscaled.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <inttypes.h>
22 #include <string.h>
23 #include <math.h>
24 #include <stdio.h>
25 #include "config.h"
26 #include "swscale.h"
27 #include "swscale_internal.h"
28 #include "rgb2rgb.h"
29 #include "libavutil/intreadwrite.h"
30 #include "libavutil/avutil.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/mem_internal.h"
33 #include "libavutil/bswap.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/avassert.h"
36 #include "libavutil/avconfig.h"
37 
38 DECLARE_ALIGNED(8, static const uint8_t, dithers)[8][8][8]={
39 {
40  { 0, 1, 0, 1, 0, 1, 0, 1,},
41  { 1, 0, 1, 0, 1, 0, 1, 0,},
42  { 0, 1, 0, 1, 0, 1, 0, 1,},
43  { 1, 0, 1, 0, 1, 0, 1, 0,},
44  { 0, 1, 0, 1, 0, 1, 0, 1,},
45  { 1, 0, 1, 0, 1, 0, 1, 0,},
46  { 0, 1, 0, 1, 0, 1, 0, 1,},
47  { 1, 0, 1, 0, 1, 0, 1, 0,},
48 },{
49  { 1, 2, 1, 2, 1, 2, 1, 2,},
50  { 3, 0, 3, 0, 3, 0, 3, 0,},
51  { 1, 2, 1, 2, 1, 2, 1, 2,},
52  { 3, 0, 3, 0, 3, 0, 3, 0,},
53  { 1, 2, 1, 2, 1, 2, 1, 2,},
54  { 3, 0, 3, 0, 3, 0, 3, 0,},
55  { 1, 2, 1, 2, 1, 2, 1, 2,},
56  { 3, 0, 3, 0, 3, 0, 3, 0,},
57 },{
58  { 2, 4, 3, 5, 2, 4, 3, 5,},
59  { 6, 0, 7, 1, 6, 0, 7, 1,},
60  { 3, 5, 2, 4, 3, 5, 2, 4,},
61  { 7, 1, 6, 0, 7, 1, 6, 0,},
62  { 2, 4, 3, 5, 2, 4, 3, 5,},
63  { 6, 0, 7, 1, 6, 0, 7, 1,},
64  { 3, 5, 2, 4, 3, 5, 2, 4,},
65  { 7, 1, 6, 0, 7, 1, 6, 0,},
66 },{
67  { 4, 8, 7, 11, 4, 8, 7, 11,},
68  { 12, 0, 15, 3, 12, 0, 15, 3,},
69  { 6, 10, 5, 9, 6, 10, 5, 9,},
70  { 14, 2, 13, 1, 14, 2, 13, 1,},
71  { 4, 8, 7, 11, 4, 8, 7, 11,},
72  { 12, 0, 15, 3, 12, 0, 15, 3,},
73  { 6, 10, 5, 9, 6, 10, 5, 9,},
74  { 14, 2, 13, 1, 14, 2, 13, 1,},
75 },{
76  { 9, 17, 15, 23, 8, 16, 14, 22,},
77  { 25, 1, 31, 7, 24, 0, 30, 6,},
78  { 13, 21, 11, 19, 12, 20, 10, 18,},
79  { 29, 5, 27, 3, 28, 4, 26, 2,},
80  { 8, 16, 14, 22, 9, 17, 15, 23,},
81  { 24, 0, 30, 6, 25, 1, 31, 7,},
82  { 12, 20, 10, 18, 13, 21, 11, 19,},
83  { 28, 4, 26, 2, 29, 5, 27, 3,},
84 },{
85  { 18, 34, 30, 46, 17, 33, 29, 45,},
86  { 50, 2, 62, 14, 49, 1, 61, 13,},
87  { 26, 42, 22, 38, 25, 41, 21, 37,},
88  { 58, 10, 54, 6, 57, 9, 53, 5,},
89  { 16, 32, 28, 44, 19, 35, 31, 47,},
90  { 48, 0, 60, 12, 51, 3, 63, 15,},
91  { 24, 40, 20, 36, 27, 43, 23, 39,},
92  { 56, 8, 52, 4, 59, 11, 55, 7,},
93 },{
94  { 18, 34, 30, 46, 17, 33, 29, 45,},
95  { 50, 2, 62, 14, 49, 1, 61, 13,},
96  { 26, 42, 22, 38, 25, 41, 21, 37,},
97  { 58, 10, 54, 6, 57, 9, 53, 5,},
98  { 16, 32, 28, 44, 19, 35, 31, 47,},
99  { 48, 0, 60, 12, 51, 3, 63, 15,},
100  { 24, 40, 20, 36, 27, 43, 23, 39,},
101  { 56, 8, 52, 4, 59, 11, 55, 7,},
102 },{
103  { 36, 68, 60, 92, 34, 66, 58, 90,},
104  { 100, 4,124, 28, 98, 2,122, 26,},
105  { 52, 84, 44, 76, 50, 82, 42, 74,},
106  { 116, 20,108, 12,114, 18,106, 10,},
107  { 32, 64, 56, 88, 38, 70, 62, 94,},
108  { 96, 0,120, 24,102, 6,126, 30,},
109  { 48, 80, 40, 72, 54, 86, 46, 78,},
110  { 112, 16,104, 8,118, 22,110, 14,},
111 }};
112 
113 
114 static void fillPlane(uint8_t *plane, int stride, int width, int height, int y,
115  uint8_t val)
116 {
117  int i;
118  uint8_t *ptr = plane + stride * y;
119  for (i = 0; i < height; i++) {
120  memset(ptr, val, width);
121  ptr += stride;
122  }
123 }
124 
125 void ff_copyPlane(const uint8_t *src, int srcStride,
126  int srcSliceY, int srcSliceH, int width,
127  uint8_t *dst, int dstStride)
128 {
129  dst += dstStride * srcSliceY;
130  if (dstStride == srcStride && srcStride > 0) {
131  memcpy(dst, src, srcSliceH * dstStride);
132  } else {
133  int i;
134  for (i = 0; i < srcSliceH; i++) {
135  memcpy(dst, src, width);
136  src += srcStride;
137  dst += dstStride;
138  }
139  }
140 }
141 
142 static int planarToNv12Wrapper(SwsInternal *c, const uint8_t *const src[],
143  const int srcStride[], int srcSliceY,
144  int srcSliceH, uint8_t *const dstParam[],
145  const int dstStride[])
146 {
147  uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2;
148 
149  ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->opts.src_w,
150  dstParam[0], dstStride[0]);
151 
152  if (c->opts.dst_format == AV_PIX_FMT_NV12)
153  interleaveBytes(src[1], src[2], dst, c->chrSrcW, (srcSliceH + 1) / 2,
154  srcStride[1], srcStride[2], dstStride[1]);
155  else
156  interleaveBytes(src[2], src[1], dst, c->chrSrcW, (srcSliceH + 1) / 2,
157  srcStride[2], srcStride[1], dstStride[1]);
158 
159  return srcSliceH;
160 }
161 
162 static int nv12ToPlanarWrapper(SwsInternal *c, const uint8_t *const src[],
163  const int srcStride[], int srcSliceY,
164  int srcSliceH, uint8_t *const dstParam[],
165  const int dstStride[])
166 {
167  uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
168  uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
169 
170  ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->opts.src_w,
171  dstParam[0], dstStride[0]);
172 
173  if (c->opts.src_format == AV_PIX_FMT_NV12)
174  deinterleaveBytes(src[1], dst1, dst2, c->chrSrcW, (srcSliceH + 1) / 2,
175  srcStride[1], dstStride[1], dstStride[2]);
176  else
177  deinterleaveBytes(src[1], dst2, dst1, c->chrSrcW, (srcSliceH + 1) / 2,
178  srcStride[1], dstStride[2], dstStride[1]);
179 
180  return srcSliceH;
181 }
182 
183 static int planarToNv24Wrapper(SwsInternal *c, const uint8_t *const src[],
184  const int srcStride[], int srcSliceY,
185  int srcSliceH, uint8_t *const dstParam[],
186  const int dstStride[])
187 {
188  uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY;
189 
190  ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->opts.src_w,
191  dstParam[0], dstStride[0]);
192 
193  if (c->opts.dst_format == AV_PIX_FMT_NV24)
194  interleaveBytes(src[1], src[2], dst, c->chrSrcW, srcSliceH,
195  srcStride[1], srcStride[2], dstStride[1]);
196  else
197  interleaveBytes(src[2], src[1], dst, c->chrSrcW, srcSliceH,
198  srcStride[2], srcStride[1], dstStride[1]);
199 
200  return srcSliceH;
201 }
202 
203 static int nv24ToPlanarWrapper(SwsInternal *c, const uint8_t *const src[],
204  const int srcStride[], int srcSliceY,
205  int srcSliceH, uint8_t *const dstParam[],
206  const int dstStride[])
207 {
208  uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY;
209  uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY;
210 
211  ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->opts.src_w,
212  dstParam[0], dstStride[0]);
213 
214  if (c->opts.src_format == AV_PIX_FMT_NV24)
215  deinterleaveBytes(src[1], dst1, dst2, c->chrSrcW, srcSliceH,
216  srcStride[1], dstStride[1], dstStride[2]);
217  else
218  deinterleaveBytes(src[1], dst2, dst1, c->chrSrcW, srcSliceH,
219  srcStride[1], dstStride[2], dstStride[1]);
220 
221  return srcSliceH;
222 }
223 
224 static void nv24_to_yuv420p_chroma(uint8_t *dst1, int dstStride1,
225  uint8_t *dst2, int dstStride2,
226  const uint8_t *src, int srcStride,
227  int w, int h)
228 {
229  const uint8_t *src1 = src;
230  const uint8_t *src2 = src + srcStride;
231  // average 4 pixels into 1 (interleaved U and V)
232  for (int y = 0; y < h; y += 2) {
233  if (y + 1 == h)
234  src2 = src1;
235  for (int x = 0; x < w; x++) {
236  dst1[x] = (src1[4 * x + 0] + src1[4 * x + 2] +
237  src2[4 * x + 0] + src2[4 * x + 2]) >> 2;
238  dst2[x] = (src1[4 * x + 1] + src1[4 * x + 3] +
239  src2[4 * x + 1] + src2[4 * x + 3]) >> 2;
240  }
241  src1 += srcStride * 2;
242  src2 += srcStride * 2;
243  dst1 += dstStride1;
244  dst2 += dstStride2;
245  }
246 }
247 
248 static int nv24ToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[],
249  const int srcStride[], int srcSliceY, int srcSliceH,
250  uint8_t *const dstParam[], const int dstStride[])
251 {
252  uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
253  uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
254 
255  ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->opts.src_w,
256  dstParam[0], dstStride[0]);
257 
258  if (c->opts.src_format == AV_PIX_FMT_NV24)
259  nv24_to_yuv420p_chroma(dst1, dstStride[1], dst2, dstStride[2],
260  src[1], srcStride[1], c->opts.src_w / 2, srcSliceH);
261  else
262  nv24_to_yuv420p_chroma(dst2, dstStride[2], dst1, dstStride[1],
263  src[1], srcStride[1], c->opts.src_w / 2, srcSliceH);
264 
265  return srcSliceH;
266 }
267 
268 static int planarToP01xWrapper(SwsInternal *c, const uint8_t *const src8[],
269  const int srcStride[], int srcSliceY,
270  int srcSliceH, uint8_t *const dstParam8[],
271  const int dstStride[])
272 {
273  const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->opts.src_format);
274  const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->opts.dst_format);
275  const uint16_t **src = (const uint16_t**)src8;
276  uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
277  uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
278  int x, y;
279 
280  /* Calculate net shift required for values. */
281  const int shift[3] = {
282  dst_format->comp[0].depth + dst_format->comp[0].shift -
283  src_format->comp[0].depth - src_format->comp[0].shift,
284  dst_format->comp[1].depth + dst_format->comp[1].shift -
285  src_format->comp[1].depth - src_format->comp[1].shift,
286  dst_format->comp[2].depth + dst_format->comp[2].shift -
287  src_format->comp[2].depth - src_format->comp[2].shift,
288  };
289 
290  av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
291  dstStride[0] % 2 || dstStride[1] % 2));
292 
293  for (y = 0; y < srcSliceH; y++) {
294  uint16_t *tdstY = dstY;
295  const uint16_t *tsrc0 = src[0];
296  for (x = c->opts.src_w; x > 0; x--) {
297  *tdstY++ = *tsrc0++ << shift[0];
298  }
299  src[0] += srcStride[0] / 2;
300  dstY += dstStride[0] / 2;
301 
302  if (!(y & 1)) {
303  uint16_t *tdstUV = dstUV;
304  const uint16_t *tsrc1 = src[1];
305  const uint16_t *tsrc2 = src[2];
306  for (x = c->opts.src_w / 2; x > 0; x--) {
307  *tdstUV++ = *tsrc1++ << shift[1];
308  *tdstUV++ = *tsrc2++ << shift[2];
309  }
310  src[1] += srcStride[1] / 2;
311  src[2] += srcStride[2] / 2;
312  dstUV += dstStride[1] / 2;
313  }
314  }
315 
316  return srcSliceH;
317 }
318 
319 #if AV_HAVE_BIGENDIAN
320 #define output_pixel(p, v) do { \
321  uint16_t *pp = (p); \
322  AV_WL16(pp, (v)); \
323  } while(0)
324 #else
325 #define output_pixel(p, v) (*p) = (v)
326 #endif
327 
328 static int planar8ToP01xleWrapper(SwsInternal *c, const uint8_t *const src[],
329  const int srcStride[], int srcSliceY,
330  int srcSliceH, uint8_t *const dstParam8[],
331  const int dstStride[])
332 {
333  const uint8_t *src0 = src[0], *src1 = src[1], *src2 = src[2];
334  uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
335  uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
336  int x, y, t;
337 
338  av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
339 
340  for (y = 0; y < srcSliceH; y++) {
341  uint16_t *tdstY = dstY;
342  const uint8_t *tsrc0 = src0;
343  for (x = c->opts.src_w; x > 0; x--) {
344  t = *tsrc0++;
345  output_pixel(tdstY++, t << 8);
346  }
347  src0 += srcStride[0];
348  dstY += dstStride[0] / 2;
349 
350  if (!(y & 1)) {
351  uint16_t *tdstUV = dstUV;
352  const uint8_t *tsrc1 = src1;
353  const uint8_t *tsrc2 = src2;
354  for (x = c->opts.src_w / 2; x > 0; x--) {
355  t = *tsrc1++;
356  output_pixel(tdstUV++, t << 8);
357  t = *tsrc2++;
358  output_pixel(tdstUV++, t << 8);
359  }
360  src1 += srcStride[1];
361  src2 += srcStride[2];
362  dstUV += dstStride[1] / 2;
363  }
364  }
365 
366  return srcSliceH;
367 }
368 
369 #undef output_pixel
370 
371 static int planarToYuy2Wrapper(SwsInternal *c, const uint8_t *const src[],
372  const int srcStride[], int srcSliceY, int srcSliceH,
373  uint8_t *const dstParam[], const int dstStride[])
374 {
375  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
376 
377  yv12toyuy2(src[0], src[1], src[2], dst, c->opts.src_w, srcSliceH, srcStride[0],
378  srcStride[1], dstStride[0]);
379 
380  return srcSliceH;
381 }
382 
383 static int planarToUyvyWrapper(SwsInternal *c, const uint8_t *const src[],
384  const int srcStride[], int srcSliceY, int srcSliceH,
385  uint8_t *const dstParam[], const int dstStride[])
386 {
387  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
388 
389  yv12touyvy(src[0], src[1], src[2], dst, c->opts.src_w, srcSliceH, srcStride[0],
390  srcStride[1], dstStride[0]);
391 
392  return srcSliceH;
393 }
394 
395 static int yuv422pToYuy2Wrapper(SwsInternal *c, const uint8_t *const src[],
396  const int srcStride[], int srcSliceY, int srcSliceH,
397  uint8_t *const dstParam[], const int dstStride[])
398 {
399  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
400 
401  yuv422ptoyuy2(src[0], src[1], src[2], dst, c->opts.src_w, srcSliceH, srcStride[0],
402  srcStride[1], dstStride[0]);
403 
404  return srcSliceH;
405 }
406 
407 static int yuv422pToUyvyWrapper(SwsInternal *c, const uint8_t *const src[],
408  const int srcStride[], int srcSliceY, int srcSliceH,
409  uint8_t *const dstParam[], const int dstStride[])
410 {
411  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
412 
413  yuv422ptouyvy(src[0], src[1], src[2], dst, c->opts.src_w, srcSliceH, srcStride[0],
414  srcStride[1], dstStride[0]);
415 
416  return srcSliceH;
417 }
418 
419 static int yuyvToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[],
420  const int srcStride[], int srcSliceY, int srcSliceH,
421  uint8_t *const dstParam[], const int dstStride[])
422 {
423  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
424  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
425  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
426 
427  yuyvtoyuv420(ydst, udst, vdst, src[0], c->opts.src_w, srcSliceH, dstStride[0],
428  dstStride[1], srcStride[0]);
429 
430  if (dstParam[3])
431  fillPlane(dstParam[3], dstStride[3], c->opts.src_w, srcSliceH, srcSliceY, 255);
432 
433  return srcSliceH;
434 }
435 
436 static int yuyvToYuv422Wrapper(SwsInternal *c, const uint8_t *const src[],
437  const int srcStride[], int srcSliceY, int srcSliceH,
438  uint8_t *const dstParam[], const int dstStride[])
439 {
440  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
441  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
442  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
443 
444  yuyvtoyuv422(ydst, udst, vdst, src[0], c->opts.src_w, srcSliceH, dstStride[0],
445  dstStride[1], srcStride[0]);
446 
447  return srcSliceH;
448 }
449 
450 static int uyvyToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[],
451  const int srcStride[], int srcSliceY, int srcSliceH,
452  uint8_t *const dstParam[], const int dstStride[])
453 {
454  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
455  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
456  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
457 
458  uyvytoyuv420(ydst, udst, vdst, src[0], c->opts.src_w, srcSliceH, dstStride[0],
459  dstStride[1], srcStride[0]);
460 
461  if (dstParam[3])
462  fillPlane(dstParam[3], dstStride[3], c->opts.src_w, srcSliceH, srcSliceY, 255);
463 
464  return srcSliceH;
465 }
466 
467 static int uyvyToYuv422Wrapper(SwsInternal *c, const uint8_t *const src[],
468  const int srcStride[], int srcSliceY, int srcSliceH,
469  uint8_t *const dstParam[], const int dstStride[])
470 {
471  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
472  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
473  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
474 
475  uyvytoyuv422(ydst, udst, vdst, src[0], c->opts.src_w, srcSliceH, dstStride[0],
476  dstStride[1], srcStride[0]);
477 
478  return srcSliceH;
479 }
480 
481 static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels,
482  const uint8_t *palette)
483 {
484  int i;
485  for (i = 0; i < num_pixels; i++)
486  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | (src[(i << 1) + 1] << 24);
487 }
488 
489 static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels,
490  const uint8_t *palette)
491 {
492  int i;
493 
494  for (i = 0; i < num_pixels; i++)
495  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | src[(i << 1) + 1];
496 }
497 
498 static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels,
499  const uint8_t *palette)
500 {
501  int i;
502 
503  for (i = 0; i < num_pixels; i++) {
504  //FIXME slow?
505  dst[0] = palette[src[i << 1] * 4 + 0];
506  dst[1] = palette[src[i << 1] * 4 + 1];
507  dst[2] = palette[src[i << 1] * 4 + 2];
508  dst += 3;
509  }
510 }
511 
512 static int bswap_16bpc(SwsInternal *c, const uint8_t *const src[],
513  const int srcStride[], int srcSliceY, int srcSliceH,
514  uint8_t *const dst[], const int dstStride[])
515 {
516  int i, j, p;
517 
518  for (p = 0; p < 4; p++) {
519  int srcstr = srcStride[p] / 2;
520  int dststr = dstStride[p] / 2;
521  uint16_t *dstPtr = (uint16_t *) dst[p];
522  const uint16_t *srcPtr = (const uint16_t *) src[p];
523  int min_stride = FFMIN(FFABS(srcstr), FFABS(dststr));
524  if(!dstPtr || !srcPtr)
525  continue;
526  dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
527  for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
528  for (j = 0; j < min_stride; j++) {
529  dstPtr[j] = av_bswap16(srcPtr[j]);
530  }
531  srcPtr += srcstr;
532  dstPtr += dststr;
533  }
534  }
535 
536  return srcSliceH;
537 }
538 
539 static int bswap_32bpc(SwsInternal *c, const uint8_t *const src[],
540  const int srcStride[], int srcSliceY, int srcSliceH,
541  uint8_t *const dst[], const int dstStride[])
542 {
543  int i, j, p;
544 
545  for (p = 0; p < 4; p++) {
546  int srcstr = srcStride[p] / 4;
547  int dststr = dstStride[p] / 4;
548  uint32_t *dstPtr = (uint32_t *) dst[p];
549  const uint32_t *srcPtr = (const uint32_t *) src[p];
550  int min_stride = FFMIN(FFABS(srcstr), FFABS(dststr));
551  if(!dstPtr || !srcPtr)
552  continue;
553  dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
554  for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
555  for (j = 0; j < min_stride; j++) {
556  dstPtr[j] = av_bswap32(srcPtr[j]);
557  }
558  srcPtr += srcstr;
559  dstPtr += dststr;
560  }
561  }
562 
563  return srcSliceH;
564 }
565 
566 
567 static int palToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[],
568  int srcSliceY, int srcSliceH, uint8_t *const dst[],
569  const int dstStride[])
570 {
571  const enum AVPixelFormat srcFormat = c->opts.src_format;
572  const enum AVPixelFormat dstFormat = c->opts.dst_format;
573  void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels,
574  const uint8_t *palette) = NULL;
575  int i;
576  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
577  const uint8_t *srcPtr = src[0];
578 
579  if (srcFormat == AV_PIX_FMT_YA8) {
580  switch (dstFormat) {
581  case AV_PIX_FMT_RGB32 : conv = gray8aToPacked32; break;
582  case AV_PIX_FMT_BGR32 : conv = gray8aToPacked32; break;
585  case AV_PIX_FMT_RGB24 : conv = gray8aToPacked24; break;
586  case AV_PIX_FMT_BGR24 : conv = gray8aToPacked24; break;
587  }
588  } else if (usePal(srcFormat)) {
589  switch (dstFormat) {
596  }
597  }
598 
599  if (!conv)
600  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
601  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
602  else {
603  for (i = 0; i < srcSliceH; i++) {
604  conv(srcPtr, dstPtr, c->opts.src_w, (uint8_t *) c->pal_rgb);
605  srcPtr += srcStride[0];
606  dstPtr += dstStride[0];
607  }
608  }
609 
610  return srcSliceH;
611 }
612 
613 static void packed16togbra16(const uint8_t *src, int srcStride,
614  uint16_t *dst[], const int dstStride[], int srcSliceH,
615  int src_alpha, int swap, int shift, int width)
616 {
617  int x, h, i;
618  int dst_alpha = dst[3] != NULL;
619  for (h = 0; h < srcSliceH; h++) {
620  uint16_t *src_line = (uint16_t *)(src + srcStride * h);
621  switch (swap) {
622  case 3:
623  if (src_alpha && dst_alpha) {
624  for (x = 0; x < width; x++) {
625  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
626  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
627  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
628  dst[3][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
629  }
630  } else if (dst_alpha) {
631  for (x = 0; x < width; x++) {
632  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
633  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
634  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
635  dst[3][x] = 0xFFFF;
636  }
637  } else if (src_alpha) {
638  for (x = 0; x < width; x++) {
639  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
640  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
641  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
642  src_line++;
643  }
644  } else {
645  for (x = 0; x < width; x++) {
646  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
647  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
648  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
649  }
650  }
651  break;
652  case 2:
653  if (src_alpha && dst_alpha) {
654  for (x = 0; x < width; x++) {
655  dst[0][x] = av_bswap16(*src_line++ >> shift);
656  dst[1][x] = av_bswap16(*src_line++ >> shift);
657  dst[2][x] = av_bswap16(*src_line++ >> shift);
658  dst[3][x] = av_bswap16(*src_line++ >> shift);
659  }
660  } else if (dst_alpha) {
661  for (x = 0; x < width; x++) {
662  dst[0][x] = av_bswap16(*src_line++ >> shift);
663  dst[1][x] = av_bswap16(*src_line++ >> shift);
664  dst[2][x] = av_bswap16(*src_line++ >> shift);
665  dst[3][x] = 0xFFFF;
666  }
667  } else if (src_alpha) {
668  for (x = 0; x < width; x++) {
669  dst[0][x] = av_bswap16(*src_line++ >> shift);
670  dst[1][x] = av_bswap16(*src_line++ >> shift);
671  dst[2][x] = av_bswap16(*src_line++ >> shift);
672  src_line++;
673  }
674  } else {
675  for (x = 0; x < width; x++) {
676  dst[0][x] = av_bswap16(*src_line++ >> shift);
677  dst[1][x] = av_bswap16(*src_line++ >> shift);
678  dst[2][x] = av_bswap16(*src_line++ >> shift);
679  }
680  }
681  break;
682  case 1:
683  if (src_alpha && dst_alpha) {
684  for (x = 0; x < width; x++) {
685  dst[0][x] = av_bswap16(*src_line++) >> shift;
686  dst[1][x] = av_bswap16(*src_line++) >> shift;
687  dst[2][x] = av_bswap16(*src_line++) >> shift;
688  dst[3][x] = av_bswap16(*src_line++) >> shift;
689  }
690  } else if (dst_alpha) {
691  for (x = 0; x < width; x++) {
692  dst[0][x] = av_bswap16(*src_line++) >> shift;
693  dst[1][x] = av_bswap16(*src_line++) >> shift;
694  dst[2][x] = av_bswap16(*src_line++) >> shift;
695  dst[3][x] = 0xFFFF;
696  }
697  } else if (src_alpha) {
698  for (x = 0; x < width; x++) {
699  dst[0][x] = av_bswap16(*src_line++) >> shift;
700  dst[1][x] = av_bswap16(*src_line++) >> shift;
701  dst[2][x] = av_bswap16(*src_line++) >> shift;
702  src_line++;
703  }
704  } else {
705  for (x = 0; x < width; x++) {
706  dst[0][x] = av_bswap16(*src_line++) >> shift;
707  dst[1][x] = av_bswap16(*src_line++) >> shift;
708  dst[2][x] = av_bswap16(*src_line++) >> shift;
709  }
710  }
711  break;
712  default:
713  if (src_alpha && dst_alpha) {
714  for (x = 0; x < width; x++) {
715  dst[0][x] = *src_line++ >> shift;
716  dst[1][x] = *src_line++ >> shift;
717  dst[2][x] = *src_line++ >> shift;
718  dst[3][x] = *src_line++ >> shift;
719  }
720  } else if (dst_alpha) {
721  for (x = 0; x < width; x++) {
722  dst[0][x] = *src_line++ >> shift;
723  dst[1][x] = *src_line++ >> shift;
724  dst[2][x] = *src_line++ >> shift;
725  dst[3][x] = 0xFFFF;
726  }
727  } else if (src_alpha) {
728  for (x = 0; x < width; x++) {
729  dst[0][x] = *src_line++ >> shift;
730  dst[1][x] = *src_line++ >> shift;
731  dst[2][x] = *src_line++ >> shift;
732  src_line++;
733  }
734  } else {
735  for (x = 0; x < width; x++) {
736  dst[0][x] = *src_line++ >> shift;
737  dst[1][x] = *src_line++ >> shift;
738  dst[2][x] = *src_line++ >> shift;
739  }
740  }
741  }
742  for (i = 0; i < 4; i++)
743  dst[i] += dstStride[i] >> 1;
744  }
745 }
746 
747 static void packed30togbra10(const uint8_t *src, int srcStride,
748  uint16_t *dst[], const int dstStride[], int srcSliceH,
749  int swap, int bpc, int width)
750 {
751  int x, h, i;
752  int dst_alpha = dst[3] != NULL;
753  int scale_high = bpc - 10, scale_low = 10 - scale_high;
754  for (h = 0; h < srcSliceH; h++) {
755  uint32_t *src_line = (uint32_t *)(src + srcStride * h);
756  unsigned component;
757 
758  switch (swap) {
759  case 3:
760  case 2:
761  if (dst_alpha) {
762  for (x = 0; x < width; x++) {
763  unsigned p = AV_RL32(src_line);
764  component = (p >> 20) & 0x3FF;
765  dst[0][x] = av_bswap16(component << scale_high | component >> scale_low);
766  component = (p >> 10) & 0x3FF;
767  dst[1][x] = av_bswap16(component << scale_high | component >> scale_low);
768  component = p & 0x3FF;
769  dst[2][x] = av_bswap16(component << scale_high | component >> scale_low);
770  dst[3][x] = 0xFFFF;
771  src_line++;
772  }
773  } else {
774  for (x = 0; x < width; x++) {
775  unsigned p = AV_RL32(src_line);
776  component = (p >> 20) & 0x3FF;
777  dst[0][x] = av_bswap16(component << scale_high | component >> scale_low);
778  component = (p >> 10) & 0x3FF;
779  dst[1][x] = av_bswap16(component << scale_high | component >> scale_low);
780  component = p & 0x3FF;
781  dst[2][x] = av_bswap16(component << scale_high | component >> scale_low);
782  src_line++;
783  }
784  }
785  break;
786  default:
787  if (dst_alpha) {
788  for (x = 0; x < width; x++) {
789  unsigned p = AV_RL32(src_line);
790  component = (p >> 20) & 0x3FF;
791  dst[0][x] = component << scale_high | component >> scale_low;
792  component = (p >> 10) & 0x3FF;
793  dst[1][x] = component << scale_high | component >> scale_low;
794  component = p & 0x3FF;
795  dst[2][x] = component << scale_high | component >> scale_low;
796  dst[3][x] = 0xFFFF;
797  src_line++;
798  }
799  } else {
800  for (x = 0; x < width; x++) {
801  unsigned p = AV_RL32(src_line);
802  component = (p >> 20) & 0x3FF;
803  dst[0][x] = component << scale_high | component >> scale_low;
804  component = (p >> 10) & 0x3FF;
805  dst[1][x] = component << scale_high | component >> scale_low;
806  component = p & 0x3FF;
807  dst[2][x] = component << scale_high | component >> scale_low;
808  src_line++;
809  }
810  }
811  break;
812  }
813  for (i = 0; i < 4; i++)
814  dst[i] += dstStride[i] >> 1;
815  }
816 }
817 
818 static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[],
819  const int srcStride[], int srcSliceY, int srcSliceH,
820  uint8_t *const dst[], const int dstStride[])
821 {
822  uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
823  uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
824  int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
825  int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
826  const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->opts.src_format);
827  const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->opts.dst_format);
828  int bpc = dst_format->comp[0].depth;
829  int alpha = src_format->flags & AV_PIX_FMT_FLAG_ALPHA;
830  int swap = 0;
831  int i;
832 
833  if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
834  !HAVE_BIGENDIAN && src_format->flags & AV_PIX_FMT_FLAG_BE)
835  swap++;
836  if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
837  !HAVE_BIGENDIAN && dst_format->flags & AV_PIX_FMT_FLAG_BE)
838  swap += 2;
839 
840  if ((dst_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
842  av_log(c, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n",
843  src_format->name, dst_format->name);
844  return srcSliceH;
845  }
846 
847  for(i=0; i<4; i++) {
848  dst2013[i] += stride2013[i] * srcSliceY / 2;
849  dst1023[i] += stride1023[i] * srcSliceY / 2;
850  }
851 
852  switch (c->opts.src_format) {
853  case AV_PIX_FMT_RGB48LE:
854  case AV_PIX_FMT_RGB48BE:
855  case AV_PIX_FMT_RGBA64LE:
856  case AV_PIX_FMT_RGBA64BE:
857  packed16togbra16(src[0], srcStride[0],
858  dst2013, stride2013, srcSliceH, alpha, swap,
859  16 - bpc, c->opts.src_w);
860  break;
862  av_assert0(bpc >= 10);
863  packed30togbra10(src[0], srcStride[0],
864  dst2013, stride2013, srcSliceH, swap,
865  bpc, c->opts.src_w);
866  break;
867  case AV_PIX_FMT_BGR48LE:
868  case AV_PIX_FMT_BGR48BE:
869  case AV_PIX_FMT_BGRA64LE:
870  case AV_PIX_FMT_BGRA64BE:
871  packed16togbra16(src[0], srcStride[0],
872  dst1023, stride1023, srcSliceH, alpha, swap,
873  16 - bpc, c->opts.src_w);
874  break;
876  av_assert0(bpc >= 10);
877  packed30togbra10(src[0], srcStride[0],
878  dst1023, stride1023, srcSliceH, swap,
879  bpc, c->opts.src_w);
880  break;
881  default:
883  "unsupported conversion to planar RGB %s -> %s\n",
884  src_format->name, dst_format->name);
885  }
886 
887  return srcSliceH;
888 }
889 
890 static void gbr16ptopacked16(const uint16_t *src[], const int srcStride[],
891  uint8_t *dst, int dstStride, int srcSliceH,
892  int alpha, int swap, int bpp, int width)
893 {
894  int x, h, i;
895  int src_alpha = src[3] != NULL;
896  int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
897  for (h = 0; h < srcSliceH; h++) {
898  uint16_t *dest = (uint16_t *)(dst + dstStride * h);
899  uint16_t component;
900 
901  switch(swap) {
902  case 3:
903  if (alpha && !src_alpha) {
904  for (x = 0; x < width; x++) {
905  component = av_bswap16(src[0][x]);
906  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
907  component = av_bswap16(src[1][x]);
908  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
909  component = av_bswap16(src[2][x]);
910  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
911  *dest++ = 0xffff;
912  }
913  } else if (alpha && src_alpha) {
914  for (x = 0; x < width; x++) {
915  component = av_bswap16(src[0][x]);
916  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
917  component = av_bswap16(src[1][x]);
918  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
919  component = av_bswap16(src[2][x]);
920  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
921  component = av_bswap16(src[3][x]);
922  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
923  }
924  } else {
925  for (x = 0; x < width; x++) {
926  component = av_bswap16(src[0][x]);
927  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
928  component = av_bswap16(src[1][x]);
929  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
930  component = av_bswap16(src[2][x]);
931  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
932  }
933  }
934  break;
935  case 2:
936  if (alpha && !src_alpha) {
937  for (x = 0; x < width; x++) {
938  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
939  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
940  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
941  *dest++ = 0xffff;
942  }
943  } else if (alpha && src_alpha) {
944  for (x = 0; x < width; x++) {
945  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
946  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
947  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
948  *dest++ = av_bswap16(src[3][x] << scale_high | src[3][x] >> scale_low);
949  }
950  } else {
951  for (x = 0; x < width; x++) {
952  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
953  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
954  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
955  }
956  }
957  break;
958  case 1:
959  if (alpha && !src_alpha) {
960  for (x = 0; x < width; x++) {
961  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
962  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
963  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
964  *dest++ = 0xffff;
965  }
966  } else if (alpha && src_alpha) {
967  for (x = 0; x < width; x++) {
968  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
969  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
970  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
971  *dest++ = av_bswap16(src[3][x]) << scale_high | av_bswap16(src[3][x]) >> scale_low;
972  }
973  } else {
974  for (x = 0; x < width; x++) {
975  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
976  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
977  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
978  }
979  }
980  break;
981  default:
982  if (alpha && !src_alpha) {
983  for (x = 0; x < width; x++) {
984  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
985  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
986  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
987  *dest++ = 0xffff;
988  }
989  } else if (alpha && src_alpha) {
990  for (x = 0; x < width; x++) {
991  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
992  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
993  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
994  *dest++ = src[3][x] << scale_high | src[3][x] >> scale_low;
995  }
996  } else {
997  for (x = 0; x < width; x++) {
998  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
999  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
1000  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
1001  }
1002  }
1003  }
1004  for (i = 0; i < 3 + src_alpha; i++)
1005  src[i] += srcStride[i] >> 1;
1006  }
1007 }
1008 
1009 static void gbr16ptopacked30(const uint16_t *src[], const int srcStride[],
1010  uint8_t *dst, int dstStride, int srcSliceH,
1011  int swap, int bpp, int width)
1012 {
1013  int x, h, i;
1014  int shift = bpp - 10;
1015  av_assert0(bpp >= 0);
1016  for (h = 0; h < srcSliceH; h++) {
1017  uint8_t *dest = dst + dstStride * h;
1018 
1019  switch(swap) {
1020  case 3:
1021  case 1:
1022  for (x = 0; x < width; x++) {
1023  unsigned C0 = av_bswap16(src[0][x]) >> shift;
1024  unsigned C1 = av_bswap16(src[1][x]) >> shift;
1025  unsigned C2 = av_bswap16(src[2][x]) >> shift;
1026  AV_WL32(dest + 4 * x, (3U << 30) + (C0 << 20) + (C1 << 10) + C2);
1027  }
1028  break;
1029  default:
1030  for (x = 0; x < width; x++) {
1031  unsigned C0 = src[0][x] >> shift;
1032  unsigned C1 = src[1][x] >> shift;
1033  unsigned C2 = src[2][x] >> shift;
1034  AV_WL32(dest + 4 * x, (3U << 30) + (C0 << 20) + (C1 << 10) + C2);
1035  }
1036  break;
1037  }
1038  for (i = 0; i < 3; i++)
1039  src[i] += srcStride[i] >> 1;
1040  }
1041 }
1042 
1043 
1044 static int planarRgb16ToRgb16Wrapper(SwsInternal *c, const uint8_t *const src[],
1045  const int srcStride[], int srcSliceY, int srcSliceH,
1046  uint8_t *const dst[], const int dstStride[])
1047 {
1048  const uint16_t *src102[] = { (uint16_t *)src[1], (uint16_t *)src[0], (uint16_t *)src[2], (uint16_t *)src[3] };
1049  const uint16_t *src201[] = { (uint16_t *)src[2], (uint16_t *)src[0], (uint16_t *)src[1], (uint16_t *)src[3] };
1050  int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
1051  int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1052  const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->opts.src_format);
1053  const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->opts.dst_format);
1054  int bits_per_sample = src_format->comp[0].depth;
1055  int swap = 0;
1056  if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
1057  !HAVE_BIGENDIAN && src_format->flags & AV_PIX_FMT_FLAG_BE)
1058  swap++;
1059  if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
1060  !HAVE_BIGENDIAN && dst_format->flags & AV_PIX_FMT_FLAG_BE)
1061  swap += 2;
1062 
1063  if ((src_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
1065  bits_per_sample <= 8) {
1066  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
1067  src_format->name, dst_format->name);
1068  return srcSliceH;
1069  }
1070  switch (c->opts.dst_format) {
1071  case AV_PIX_FMT_BGR48LE:
1072  case AV_PIX_FMT_BGR48BE:
1073  gbr16ptopacked16(src102, stride102,
1074  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1075  srcSliceH, 0, swap, bits_per_sample, c->opts.src_w);
1076  break;
1077  case AV_PIX_FMT_RGB48LE:
1078  case AV_PIX_FMT_RGB48BE:
1079  gbr16ptopacked16(src201, stride201,
1080  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1081  srcSliceH, 0, swap, bits_per_sample, c->opts.src_w);
1082  break;
1083  case AV_PIX_FMT_RGBA64LE:
1084  case AV_PIX_FMT_RGBA64BE:
1085  gbr16ptopacked16(src201, stride201,
1086  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1087  srcSliceH, 1, swap, bits_per_sample, c->opts.src_w);
1088  break;
1089  case AV_PIX_FMT_BGRA64LE:
1090  case AV_PIX_FMT_BGRA64BE:
1091  gbr16ptopacked16(src102, stride102,
1092  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1093  srcSliceH, 1, swap, bits_per_sample, c->opts.src_w);
1094  break;
1095  case AV_PIX_FMT_X2RGB10LE:
1096  gbr16ptopacked30(src201, stride201,
1097  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1098  srcSliceH, swap, bits_per_sample, c->opts.src_w);
1099  break;
1100  case AV_PIX_FMT_X2BGR10LE:
1101  gbr16ptopacked30(src102, stride102,
1102  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1103  srcSliceH, swap, bits_per_sample, c->opts.src_w);
1104  break;
1105  default:
1107  "unsupported planar RGB conversion %s -> %s\n",
1108  src_format->name, dst_format->name);
1109  }
1110 
1111  return srcSliceH;
1112 }
1113 
1114 static void gbr24ptopacked24(const uint8_t *src[], const int srcStride[],
1115  uint8_t *dst, int dstStride, int srcSliceH,
1116  int width)
1117 {
1118  int x, h, i;
1119  for (h = 0; h < srcSliceH; h++) {
1120  uint8_t *dest = dst + dstStride * h;
1121  for (x = 0; x < width; x++) {
1122  *dest++ = src[0][x];
1123  *dest++ = src[1][x];
1124  *dest++ = src[2][x];
1125  }
1126 
1127  for (i = 0; i < 3; i++)
1128  src[i] += srcStride[i];
1129  }
1130 }
1131 
1132 static void gbr24ptopacked32(const uint8_t *src[], const int srcStride[],
1133  uint8_t *dst, int dstStride, int srcSliceH,
1134  int alpha_first, int width)
1135 {
1136  int x, h, i;
1137  for (h = 0; h < srcSliceH; h++) {
1138  uint8_t *dest = dst + dstStride * h;
1139 
1140  if (alpha_first) {
1141  for (x = 0; x < width; x++) {
1142  *dest++ = 0xff;
1143  *dest++ = src[0][x];
1144  *dest++ = src[1][x];
1145  *dest++ = src[2][x];
1146  }
1147  } else {
1148  for (x = 0; x < width; x++) {
1149  *dest++ = src[0][x];
1150  *dest++ = src[1][x];
1151  *dest++ = src[2][x];
1152  *dest++ = 0xff;
1153  }
1154  }
1155 
1156  for (i = 0; i < 3; i++)
1157  src[i] += srcStride[i];
1158  }
1159 }
1160 
1161 static void gbraptopacked32(const uint8_t *src[], const int srcStride[],
1162  uint8_t *dst, int dstStride, int srcSliceH,
1163  int alpha_first, int width)
1164 {
1165  int x, h, i;
1166  for (h = 0; h < srcSliceH; h++) {
1167  uint8_t *dest = dst + dstStride * h;
1168 
1169  if (alpha_first) {
1170  for (x = 0; x < width; x++) {
1171  *dest++ = src[3][x];
1172  *dest++ = src[0][x];
1173  *dest++ = src[1][x];
1174  *dest++ = src[2][x];
1175  }
1176  } else {
1177  for (x = 0; x < width; x++) {
1178  *dest++ = src[0][x];
1179  *dest++ = src[1][x];
1180  *dest++ = src[2][x];
1181  *dest++ = src[3][x];
1182  }
1183  }
1184 
1185  for (i = 0; i < 4; i++)
1186  src[i] += srcStride[i];
1187  }
1188 }
1189 
1190 static int planarRgbaToRgbWrapper(SwsInternal *c, const uint8_t *const src[],
1191  const int srcStride[], int srcSliceY, int srcSliceH,
1192  uint8_t *const dst[], const int dstStride[])
1193 {
1194  int alpha_first = 0;
1195  const uint8_t *src102[] = { src[1], src[0], src[2], src[3] };
1196  const uint8_t *src201[] = { src[2], src[0], src[1], src[3] };
1197  int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
1198  int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
1199 
1200  if (c->opts.src_format != AV_PIX_FMT_GBRAP) {
1201  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
1202  av_get_pix_fmt_name(c->opts.src_format),
1203  av_get_pix_fmt_name(c->opts.dst_format));
1204  return srcSliceH;
1205  }
1206 
1207  switch (c->opts.dst_format) {
1208  case AV_PIX_FMT_BGR24:
1209  gbr24ptopacked24(src102, stride102,
1210  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1211  srcSliceH, c->opts.src_w);
1212  break;
1213 
1214  case AV_PIX_FMT_RGB24:
1215  gbr24ptopacked24(src201, stride201,
1216  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1217  srcSliceH, c->opts.src_w);
1218  break;
1219 
1220  case AV_PIX_FMT_ARGB:
1221  alpha_first = 1;
1222  case AV_PIX_FMT_RGBA:
1223  gbraptopacked32(src201, stride201,
1224  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1225  srcSliceH, alpha_first, c->opts.src_w);
1226  break;
1227 
1228  case AV_PIX_FMT_ABGR:
1229  alpha_first = 1;
1230  case AV_PIX_FMT_BGRA:
1231  gbraptopacked32(src102, stride102,
1232  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1233  srcSliceH, alpha_first, c->opts.src_w);
1234  break;
1235 
1236  default:
1238  "unsupported planar RGB conversion %s -> %s\n",
1239  av_get_pix_fmt_name(c->opts.src_format),
1240  av_get_pix_fmt_name(c->opts.dst_format));
1241  }
1242 
1243  return srcSliceH;
1244 }
1245 
1246 static int planarRgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[],
1247  const int srcStride[], int srcSliceY, int srcSliceH,
1248  uint8_t *const dst[], const int dstStride[])
1249 {
1250  int alpha_first = 0;
1251  const uint8_t *src102[] = { src[1], src[0], src[2] };
1252  const uint8_t *src201[] = { src[2], src[0], src[1] };
1253  int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
1254  int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
1255 
1256  if (c->opts.src_format != AV_PIX_FMT_GBRP) {
1257  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
1258  av_get_pix_fmt_name(c->opts.src_format),
1259  av_get_pix_fmt_name(c->opts.dst_format));
1260  return srcSliceH;
1261  }
1262 
1263  switch (c->opts.dst_format) {
1264  case AV_PIX_FMT_BGR24:
1265  gbr24ptopacked24(src102, stride102,
1266  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1267  srcSliceH, c->opts.src_w);
1268  break;
1269 
1270  case AV_PIX_FMT_RGB24:
1271  gbr24ptopacked24(src201, stride201,
1272  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1273  srcSliceH, c->opts.src_w);
1274  break;
1275 
1276  case AV_PIX_FMT_ARGB:
1277  alpha_first = 1;
1278  case AV_PIX_FMT_RGBA:
1279  gbr24ptopacked32(src201, stride201,
1280  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1281  srcSliceH, alpha_first, c->opts.src_w);
1282  break;
1283 
1284  case AV_PIX_FMT_ABGR:
1285  alpha_first = 1;
1286  case AV_PIX_FMT_BGRA:
1287  gbr24ptopacked32(src102, stride102,
1288  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1289  srcSliceH, alpha_first, c->opts.src_w);
1290  break;
1291 
1292  default:
1294  "unsupported planar RGB conversion %s -> %s\n",
1295  av_get_pix_fmt_name(c->opts.src_format),
1296  av_get_pix_fmt_name(c->opts.dst_format));
1297  }
1298 
1299  return srcSliceH;
1300 }
1301 
1303  const uint8_t *const src[], const int srcStride[],
1304  int srcSliceY, int srcSliceH,
1305  uint8_t *const dst[], const int dstStride[])
1306 {
1307  ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->opts.src_w,
1308  dst[0], dstStride[0]);
1309  ff_copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->opts.src_w,
1310  dst[1], dstStride[1]);
1311  ff_copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->opts.src_w,
1312  dst[2], dstStride[2]);
1313  if (dst[3])
1314  fillPlane(dst[3], dstStride[3], c->opts.src_w, srcSliceH, srcSliceY, 255);
1315 
1316  return srcSliceH;
1317 }
1318 
1319 static void packedtogbr24p(const uint8_t *src, int srcStride,
1320  uint8_t *const dst[], const int dstStride[], int srcSliceH,
1321  int alpha_first, int inc_size, int width)
1322 {
1323  uint8_t *dest[3];
1324  int x, h;
1325 
1326  dest[0] = dst[0];
1327  dest[1] = dst[1];
1328  dest[2] = dst[2];
1329 
1330  if (alpha_first)
1331  src++;
1332 
1333  for (h = 0; h < srcSliceH; h++) {
1334  for (x = 0; x < width; x++) {
1335  dest[0][x] = src[0];
1336  dest[1][x] = src[1];
1337  dest[2][x] = src[2];
1338 
1339  src += inc_size;
1340  }
1341  src += srcStride - width * inc_size;
1342  dest[0] += dstStride[0];
1343  dest[1] += dstStride[1];
1344  dest[2] += dstStride[2];
1345  }
1346 }
1347 
1348 static int rgbToPlanarRgbWrapper(SwsInternal *c, const uint8_t *const src[],
1349  const int srcStride[], int srcSliceY, int srcSliceH,
1350  uint8_t *const dst[], const int dstStride[])
1351 {
1352  int alpha_first = 0;
1353  int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1354  int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1355  uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
1356  dst[0] + srcSliceY * dstStride[0],
1357  dst[2] + srcSliceY * dstStride[2] };
1358  uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
1359  dst[0] + srcSliceY * dstStride[0],
1360  dst[1] + srcSliceY * dstStride[1] };
1361 
1362  switch (c->opts.src_format) {
1363  case AV_PIX_FMT_RGB24:
1364  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
1365  stride201, srcSliceH, alpha_first, 3, c->opts.src_w);
1366  break;
1367  case AV_PIX_FMT_BGR24:
1368  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
1369  stride102, srcSliceH, alpha_first, 3, c->opts.src_w);
1370  break;
1371  case AV_PIX_FMT_ARGB:
1372  alpha_first = 1;
1373  case AV_PIX_FMT_RGBA:
1374  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
1375  stride201, srcSliceH, alpha_first, 4, c->opts.src_w);
1376  break;
1377  case AV_PIX_FMT_ABGR:
1378  alpha_first = 1;
1379  case AV_PIX_FMT_BGRA:
1380  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
1381  stride102, srcSliceH, alpha_first, 4, c->opts.src_w);
1382  break;
1383  default:
1385  "unsupported planar RGB conversion %s -> %s\n",
1386  av_get_pix_fmt_name(c->opts.src_format),
1387  av_get_pix_fmt_name(c->opts.dst_format));
1388  }
1389 
1390  return srcSliceH;
1391 }
1392 
1393 static void packed24togbrap(const uint8_t *src, int srcStride,
1394  uint8_t *const dst[], const int dstStride[],
1395  int srcSliceH, int width)
1396 {
1397  uint8_t *dest[4];
1398  int x, h;
1399 
1400  dest[0] = dst[0];
1401  dest[1] = dst[1];
1402  dest[2] = dst[2];
1403  dest[3] = dst[3];
1404 
1405  for (h = 0; h < srcSliceH; h++) {
1406  for (x = 0; x < width; x++) {
1407  dest[0][x] = src[x * 3 + 0];
1408  dest[1][x] = src[x * 3 + 1];
1409  dest[2][x] = src[x * 3 + 2];
1410  dest[3][x] = 0xff;
1411  }
1412  src += srcStride;
1413  dest[0] += dstStride[0];
1414  dest[1] += dstStride[1];
1415  dest[2] += dstStride[2];
1416  dest[3] += dstStride[3];
1417  }
1418 }
1419 
1420 static void packed32togbrap(const uint8_t *src, int srcStride,
1421  uint8_t *const dst[], const int dstStride[],
1422  int srcSliceH, int alpha_first, int width)
1423 {
1424  uint8_t *dest[4];
1425  int x, h;
1426 
1427  dest[0] = dst[0];
1428  dest[1] = dst[1];
1429  dest[2] = dst[2];
1430  dest[3] = dst[3];
1431 
1432  for (h = 0; h < srcSliceH; h++) {
1433  if (alpha_first) {
1434  for (x = 0; x < width; x++) {
1435  dest[0][x] = src[x * 4 + 1];
1436  dest[1][x] = src[x * 4 + 2];
1437  dest[2][x] = src[x * 4 + 3];
1438  dest[3][x] = src[x * 4 + 0];
1439  }
1440  } else {
1441  for (x = 0; x < width; x++) {
1442  dest[0][x] = src[x * 4 + 0];
1443  dest[1][x] = src[x * 4 + 1];
1444  dest[2][x] = src[x * 4 + 2];
1445  dest[3][x] = src[x * 4 + 3];
1446  }
1447  }
1448  src += srcStride;
1449  dest[0] += dstStride[0];
1450  dest[1] += dstStride[1];
1451  dest[2] += dstStride[2];
1452  dest[3] += dstStride[3];
1453  }
1454 }
1455 
1456 static int rgbToPlanarRgbaWrapper(SwsInternal *c, const uint8_t *const src[],
1457  const int srcStride[], int srcSliceY, int srcSliceH,
1458  uint8_t *const dst[], const int dstStride[])
1459 {
1460  int alpha_first = 0;
1461  int stride102[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
1462  int stride201[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
1463  uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
1464  dst[0] + srcSliceY * dstStride[0],
1465  dst[2] + srcSliceY * dstStride[2],
1466  dst[3] + srcSliceY * dstStride[3] };
1467  uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
1468  dst[0] + srcSliceY * dstStride[0],
1469  dst[1] + srcSliceY * dstStride[1],
1470  dst[3] + srcSliceY * dstStride[3] };
1471 
1472  switch (c->opts.src_format) {
1473  case AV_PIX_FMT_RGB24:
1474  packed24togbrap((const uint8_t *) src[0], srcStride[0], dst201,
1475  stride201, srcSliceH, c->opts.src_w);
1476  break;
1477  case AV_PIX_FMT_BGR24:
1478  packed24togbrap((const uint8_t *) src[0], srcStride[0], dst102,
1479  stride102, srcSliceH, c->opts.src_w);
1480  break;
1481  case AV_PIX_FMT_ARGB:
1482  alpha_first = 1;
1483  case AV_PIX_FMT_RGBA:
1484  packed32togbrap((const uint8_t *) src[0], srcStride[0], dst201,
1485  stride201, srcSliceH, alpha_first, c->opts.src_w);
1486  break;
1487  case AV_PIX_FMT_ABGR:
1488  alpha_first = 1;
1489  case AV_PIX_FMT_BGRA:
1490  packed32togbrap((const uint8_t *) src[0], srcStride[0], dst102,
1491  stride102, srcSliceH, alpha_first, c->opts.src_w);
1492  break;
1493  default:
1495  "unsupported planar RGB conversion %s -> %s\n",
1496  av_get_pix_fmt_name(c->opts.src_format),
1497  av_get_pix_fmt_name(c->opts.dst_format));
1498  }
1499 
1500  return srcSliceH;
1501 }
1502 
1503 #define BAYER_GBRG
1504 #define BAYER_8
1505 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1506 #include "bayer_template.c"
1507 
1508 #define BAYER_GBRG
1509 #define BAYER_16LE
1510 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1511 #include "bayer_template.c"
1512 
1513 #define BAYER_GBRG
1514 #define BAYER_16BE
1515 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1516 #include "bayer_template.c"
1517 
1518 #define BAYER_GRBG
1519 #define BAYER_8
1520 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1521 #include "bayer_template.c"
1522 
1523 #define BAYER_GRBG
1524 #define BAYER_16LE
1525 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1526 #include "bayer_template.c"
1527 
1528 #define BAYER_GRBG
1529 #define BAYER_16BE
1530 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1531 #include "bayer_template.c"
1532 
1533 #define BAYER_BGGR
1534 #define BAYER_8
1535 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1536 #include "bayer_template.c"
1537 
1538 #define BAYER_BGGR
1539 #define BAYER_16LE
1540 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1541 #include "bayer_template.c"
1542 
1543 #define BAYER_BGGR
1544 #define BAYER_16BE
1545 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1546 #include "bayer_template.c"
1547 
1548 #define BAYER_RGGB
1549 #define BAYER_8
1550 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1551 #include "bayer_template.c"
1552 
1553 #define BAYER_RGGB
1554 #define BAYER_16LE
1555 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1556 #include "bayer_template.c"
1557 
1558 #define BAYER_RGGB
1559 #define BAYER_16BE
1560 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1561 #include "bayer_template.c"
1562 
1563 static int bayer_to_rgb24_wrapper(SwsInternal *c, const uint8_t *const src[],
1564  const int srcStride[], int srcSliceY, int srcSliceH,
1565  uint8_t *const dst[], const int dstStride[])
1566 {
1567  uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1568  const uint8_t *srcPtr= src[0];
1569  int i;
1570  void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1571  void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1572 
1573  switch(c->opts.src_format) {
1574 #define CASE(pixfmt, prefix) \
1575  case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1576  interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1577  break;
1579  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1580  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1582  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1583  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1585  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1586  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1588  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1589  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1590 #undef CASE
1591  default: return 0;
1592  }
1593 
1594  av_assert0(srcSliceH > 1);
1595 
1596  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->opts.src_w);
1597  srcPtr += 2 * srcStride[0];
1598  dstPtr += 2 * dstStride[0];
1599 
1600  for (i = 2; i < srcSliceH - 2; i += 2) {
1601  interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->opts.src_w);
1602  srcPtr += 2 * srcStride[0];
1603  dstPtr += 2 * dstStride[0];
1604  }
1605 
1606  if (i + 1 == srcSliceH) {
1607  copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->opts.src_w);
1608  } else if (i < srcSliceH)
1609  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->opts.src_w);
1610  return srcSliceH;
1611 }
1612 
1613 static int bayer_to_rgb48_wrapper(SwsInternal *c, const uint8_t *const src[],
1614  const int srcStride[], int srcSliceY, int srcSliceH,
1615  uint8_t *const dst[], const int dstStride[])
1616 {
1617  uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1618  const uint8_t *srcPtr= src[0];
1619  int i;
1620  void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1621  void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1622 
1623  switch(c->opts.src_format) {
1624 #define CASE(pixfmt, prefix) \
1625  case pixfmt: copy = bayer_##prefix##_to_rgb48_copy; \
1626  interpolate = bayer_##prefix##_to_rgb48_interpolate; \
1627  break;
1629  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1630  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1632  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1633  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1635  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1636  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1638  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1639  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1640 #undef CASE
1641  default: return 0;
1642  }
1643 
1644  av_assert0(srcSliceH > 1);
1645 
1646  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->opts.src_w);
1647  srcPtr += 2 * srcStride[0];
1648  dstPtr += 2 * dstStride[0];
1649 
1650  for (i = 2; i < srcSliceH - 2; i += 2) {
1651  interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->opts.src_w);
1652  srcPtr += 2 * srcStride[0];
1653  dstPtr += 2 * dstStride[0];
1654  }
1655 
1656  if (i + 1 == srcSliceH) {
1657  copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->opts.src_w);
1658  } else if (i < srcSliceH)
1659  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->opts.src_w);
1660  return srcSliceH;
1661 }
1662 
1663 static int bayer_to_yv12_wrapper(SwsInternal *c, const uint8_t *const src[],
1664  const int srcStride[], int srcSliceY, int srcSliceH,
1665  uint8_t *const dst[], const int dstStride[])
1666 {
1667  const uint8_t *srcPtr= src[0];
1668  uint8_t *dstY= dst[0] + srcSliceY * dstStride[0];
1669  uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
1670  uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
1671  int i;
1672  void (*copy) (const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, const int32_t *rgb2yuv);
1673  void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, const int32_t *rgb2yuv);
1674 
1675  switch(c->opts.src_format) {
1676 #define CASE(pixfmt, prefix) \
1677  case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1678  interpolate = bayer_##prefix##_to_yv12_interpolate; \
1679  break;
1681  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1682  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1684  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1685  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1687  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1688  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1690  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1691  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1692 #undef CASE
1693  default: return 0;
1694  }
1695 
1696  av_assert0(srcSliceH > 1);
1697 
1698  copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->opts.src_w, c->input_rgb2yuv_table);
1699  srcPtr += 2 * srcStride[0];
1700  dstY += 2 * dstStride[0];
1701  dstU += dstStride[1];
1702  dstV += dstStride[1];
1703 
1704  for (i = 2; i < srcSliceH - 2; i += 2) {
1705  interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->opts.src_w, c->input_rgb2yuv_table);
1706  srcPtr += 2 * srcStride[0];
1707  dstY += 2 * dstStride[0];
1708  dstU += dstStride[1];
1709  dstV += dstStride[1];
1710  }
1711 
1712  if (i + 1 == srcSliceH) {
1713  copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0], c->opts.src_w, c->input_rgb2yuv_table);
1714  } else if (i < srcSliceH)
1715  copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->opts.src_w, c->input_rgb2yuv_table);
1716  return srcSliceH;
1717 }
1718 
1719 #define isRGBA32(x) ( \
1720  (x) == AV_PIX_FMT_ARGB \
1721  || (x) == AV_PIX_FMT_RGBA \
1722  || (x) == AV_PIX_FMT_BGRA \
1723  || (x) == AV_PIX_FMT_ABGR \
1724  )
1725 
1726 #define isRGBA64(x) ( \
1727  (x) == AV_PIX_FMT_RGBA64LE \
1728  || (x) == AV_PIX_FMT_RGBA64BE \
1729  || (x) == AV_PIX_FMT_BGRA64LE \
1730  || (x) == AV_PIX_FMT_BGRA64BE \
1731  )
1732 
1733 #define isRGB48(x) ( \
1734  (x) == AV_PIX_FMT_RGB48LE \
1735  || (x) == AV_PIX_FMT_RGB48BE \
1736  || (x) == AV_PIX_FMT_BGR48LE \
1737  || (x) == AV_PIX_FMT_BGR48BE \
1738  )
1739 
1740 #define isAYUV(x) ( \
1741  (x) == AV_PIX_FMT_AYUV \
1742  || (x) == AV_PIX_FMT_VUYA \
1743  || (x) == AV_PIX_FMT_VUYX \
1744  || (x) == AV_PIX_FMT_UYVA \
1745  )
1746 
1747 #define isX2RGB(x) ( \
1748  (x) == AV_PIX_FMT_X2RGB10LE \
1749  || (x) == AV_PIX_FMT_X2BGR10LE \
1750  )
1751 
1752 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
1753 typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int);
1755 {
1756  const enum AVPixelFormat srcFormat = c->opts.src_format;
1757  const enum AVPixelFormat dstFormat = c->opts.dst_format;
1758  const int srcId = c->srcFormatBpp;
1759  const int dstId = c->dstFormatBpp;
1760  rgbConvFn conv = NULL;
1761 
1762 #define IS_NOT_NE(bpp, desc) \
1763  (((bpp + 7) >> 3) == 2 && \
1764  (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1765 
1766 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1767 
1768  if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) {
1769  if ( CONV_IS(ABGR, RGBA)
1770  || CONV_IS(ARGB, BGRA)
1771  || CONV_IS(BGRA, ARGB)
1772  || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210;
1773  else if (CONV_IS(ABGR, ARGB)
1774  || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321;
1775  else if (CONV_IS(ABGR, BGRA)
1776  || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230;
1777  else if (CONV_IS(BGRA, RGBA)
1778  || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103;
1779  else if (CONV_IS(BGRA, ABGR)
1780  || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012;
1781  } else if (isRGB48(srcFormat) && isRGB48(dstFormat)) {
1782  if (CONV_IS(RGB48LE, BGR48LE)
1783  || CONV_IS(BGR48LE, RGB48LE)
1784  || CONV_IS(RGB48BE, BGR48BE)
1785  || CONV_IS(BGR48BE, RGB48BE)) conv = rgb48tobgr48_nobswap;
1786  else if (CONV_IS(RGB48LE, BGR48BE)
1787  || CONV_IS(BGR48LE, RGB48BE)
1788  || CONV_IS(RGB48BE, BGR48LE)
1789  || CONV_IS(BGR48BE, RGB48LE)) conv = rgb48tobgr48_bswap;
1790  } else if (isRGB48(srcFormat) && isRGBA64(dstFormat)) {
1791  if (CONV_IS(RGB48LE, BGRA64LE)
1792  || CONV_IS(BGR48LE, RGBA64LE)
1793  || CONV_IS(RGB48BE, BGRA64BE)
1794  || CONV_IS(BGR48BE, RGBA64BE)) conv = rgb48tobgr64_nobswap;
1795  else if (CONV_IS(RGB48LE, BGRA64BE)
1796  || CONV_IS(BGR48LE, RGBA64BE)
1797  || CONV_IS(RGB48BE, BGRA64LE)
1798  || CONV_IS(BGR48BE, RGBA64LE)) conv = rgb48tobgr64_bswap;
1799  if (CONV_IS(RGB48LE, RGBA64LE)
1800  || CONV_IS(BGR48LE, BGRA64LE)
1801  || CONV_IS(RGB48BE, RGBA64BE)
1802  || CONV_IS(BGR48BE, BGRA64BE)) conv = rgb48to64_nobswap;
1803  else if (CONV_IS(RGB48LE, RGBA64BE)
1804  || CONV_IS(BGR48LE, BGRA64BE)
1805  || CONV_IS(RGB48BE, RGBA64LE)
1806  || CONV_IS(BGR48BE, BGRA64LE)) conv = rgb48to64_bswap;
1807  } else if (isRGBA64(srcFormat) && isRGB48(dstFormat)) {
1808  if (CONV_IS(RGBA64LE, BGR48LE)
1809  || CONV_IS(BGRA64LE, RGB48LE)
1810  || CONV_IS(RGBA64BE, BGR48BE)
1811  || CONV_IS(BGRA64BE, RGB48BE)) conv = rgb64tobgr48_nobswap;
1812  else if (CONV_IS(RGBA64LE, BGR48BE)
1813  || CONV_IS(BGRA64LE, RGB48BE)
1814  || CONV_IS(RGBA64BE, BGR48LE)
1815  || CONV_IS(BGRA64BE, RGB48LE)) conv = rgb64tobgr48_bswap;
1816  else if (CONV_IS(RGBA64LE, RGB48LE)
1817  || CONV_IS(BGRA64LE, BGR48LE)
1818  || CONV_IS(RGBA64BE, RGB48BE)
1819  || CONV_IS(BGRA64BE, BGR48BE)) conv = rgb64to48_nobswap;
1820  else if (CONV_IS(RGBA64LE, RGB48BE)
1821  || CONV_IS(BGRA64LE, BGR48BE)
1822  || CONV_IS(RGBA64BE, RGB48LE)
1823  || CONV_IS(BGRA64BE, BGR48LE)) conv = rgb64to48_bswap;
1824  } else if (isX2RGB(srcFormat) && isRGB48(dstFormat)) {
1825  if (CONV_IS(X2RGB10LE, RGB48LE)
1826  || CONV_IS(X2BGR10LE, BGR48LE)) conv = HAVE_BIGENDIAN ? x2rgb10to48_bswap
1828  else if (CONV_IS(X2RGB10LE, RGB48BE)
1829  || CONV_IS(X2BGR10LE, BGR48BE)) conv = HAVE_BIGENDIAN ? x2rgb10to48_nobswap
1831  else if (CONV_IS(X2RGB10LE, BGR48LE)
1832  || CONV_IS(X2BGR10LE, RGB48LE)) conv = HAVE_BIGENDIAN ? x2rgb10tobgr48_bswap
1834  else if (CONV_IS(X2RGB10LE, BGR48BE)
1835  || CONV_IS(X2BGR10LE, RGB48BE)) conv = HAVE_BIGENDIAN ? x2rgb10tobgr48_nobswap
1837  else if (CONV_IS(X2RGB10LE, RGBA64LE)
1838  || CONV_IS(X2BGR10LE, BGRA64LE)) conv = HAVE_BIGENDIAN ? x2rgb10to64_bswap
1840  else if (CONV_IS(X2RGB10LE, RGBA64BE)
1841  || CONV_IS(X2BGR10LE, BGRA64BE)) conv = HAVE_BIGENDIAN ? x2rgb10to64_nobswap
1843  else if (CONV_IS(X2RGB10LE, BGRA64LE)
1844  || CONV_IS(X2BGR10LE, RGBA64LE)) conv = HAVE_BIGENDIAN ? x2rgb10tobgr64_bswap
1846  else if (CONV_IS(X2RGB10LE, BGRA64BE)
1847  || CONV_IS(X2BGR10LE, RGBA64BE)) conv = HAVE_BIGENDIAN ? x2rgb10tobgr64_nobswap
1849  } else if (isAYUV(srcFormat) && isAYUV(dstFormat)) {
1850  /* VUYX only for dst, to avoid copying undefined bytes */
1851  if ( CONV_IS(AYUV, VUYA)
1852  || CONV_IS(AYUV, VUYX)
1853  || CONV_IS(VUYA, AYUV)) conv = shuffle_bytes_3210;
1854  else if (CONV_IS(AYUV, UYVA)) conv = shuffle_bytes_2130;
1855  else if (CONV_IS(VUYA, UYVA)) conv = shuffle_bytes_1203;
1856  else if (CONV_IS(UYVA, AYUV)) conv = shuffle_bytes_3102;
1857  else if (CONV_IS(UYVA, VUYA)
1858  || CONV_IS(UYVA, VUYX)) conv = shuffle_bytes_2013;
1859  } else
1860  /* BGR -> BGR */
1861  if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
1862  (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) {
1863  switch (srcId | (dstId << 16)) {
1864  case 0x000F000C: conv = rgb12to15; break;
1865  case 0x000F0010: conv = rgb16to15; break;
1866  case 0x000F0018: conv = rgb24to15; break;
1867  case 0x000F0020: conv = rgb32to15; break;
1868  case 0x0010000F: conv = rgb15to16; break;
1869  case 0x00100018: conv = rgb24to16; break;
1870  case 0x00100020: conv = rgb32to16; break;
1871  case 0x0018000F: conv = rgb15to24; break;
1872  case 0x00180010: conv = rgb16to24; break;
1873  case 0x00180020: conv = rgb32to24; break;
1874  case 0x0020000F: conv = rgb15to32; break;
1875  case 0x00200010: conv = rgb16to32; break;
1876  case 0x00200018: conv = rgb24to32; break;
1877  }
1878  } else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) ||
1879  (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) {
1880  switch (srcId | (dstId << 16)) {
1881  case 0x000C000C: conv = rgb12tobgr12; break;
1882  case 0x000F000F: conv = rgb15tobgr15; break;
1883  case 0x000F0010: conv = rgb16tobgr15; break;
1884  case 0x000F0018: conv = rgb24tobgr15; break;
1885  case 0x000F0020: conv = rgb32tobgr15; break;
1886  case 0x0010000F: conv = rgb15tobgr16; break;
1887  case 0x00100010: conv = rgb16tobgr16; break;
1888  case 0x00100018: conv = rgb24tobgr16; break;
1889  case 0x00100020: conv = rgb32tobgr16; break;
1890  case 0x0018000F: conv = rgb15tobgr24; break;
1891  case 0x00180010: conv = rgb16tobgr24; break;
1892  case 0x00180018: conv = rgb24tobgr24; break;
1893  case 0x00180020: conv = rgb32tobgr24; break;
1894  case 0x0020000F: conv = rgb15tobgr32; break;
1895  case 0x00200010: conv = rgb16tobgr32; break;
1896  case 0x00200018: conv = rgb24tobgr32; break;
1897  }
1898  }
1899 
1900  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) && !isRGBA32(srcFormat) && ALT32_CORR<0)
1901  return NULL;
1902 
1903  // Maintain symmetry between endianness
1904  if (c->opts.flags & SWS_BITEXACT)
1905  if ((dstFormat == AV_PIX_FMT_RGB32 || dstFormat == AV_PIX_FMT_BGR32 ) && !isRGBA32(srcFormat) && ALT32_CORR>0)
1906  return NULL;
1907 
1908  return conv;
1909 }
1910 
1911 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
1912 static int rgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[],
1913  int srcSliceY, int srcSliceH, uint8_t *const dst[],
1914  const int dstStride[])
1915 
1916 {
1917  const enum AVPixelFormat srcFormat = c->opts.src_format;
1918  const enum AVPixelFormat dstFormat = c->opts.dst_format;
1919  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->opts.src_format);
1920  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->opts.dst_format);
1921  const int srcBpp = (c->srcFormatBpp + 7) >> 3;
1922  const int dstBpp = (c->dstFormatBpp + 7) >> 3;
1924 
1925  if (!conv) {
1926  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
1927  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1928  } else {
1929  const uint8_t *srcPtr = src[0];
1930  uint8_t *dstPtr = dst[0];
1931  int src_bswap = IS_NOT_NE(c->srcFormatBpp, desc_src);
1932  int dst_bswap = IS_NOT_NE(c->dstFormatBpp, desc_dst);
1933 
1934  if ((srcFormat == AV_PIX_FMT_RGB32_1 || srcFormat == AV_PIX_FMT_BGR32_1) &&
1935  !isRGBA32(dstFormat))
1936  srcPtr += ALT32_CORR;
1937 
1938  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) &&
1939  !isRGBA32(srcFormat)) {
1940  int i;
1941  av_assert0(ALT32_CORR == 1);
1942  for (i = 0; i < srcSliceH; i++)
1943  dstPtr[dstStride[0] * (srcSliceY + i)] = 255;
1944  dstPtr += ALT32_CORR;
1945  }
1946 
1947  if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1948  !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1949  conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1950  (srcSliceH - 1) * srcStride[0] + c->opts.src_w * srcBpp);
1951  else {
1952  int i, j;
1953  dstPtr += dstStride[0] * srcSliceY;
1954 
1955  for (i = 0; i < srcSliceH; i++) {
1956  if(src_bswap) {
1957  for(j=0; j<c->opts.src_w; j++)
1958  ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]);
1959  conv(c->formatConvBuffer, dstPtr, c->opts.src_w * srcBpp);
1960  }else
1961  conv(srcPtr, dstPtr, c->opts.src_w * srcBpp);
1962  if(dst_bswap)
1963  for(j=0; j<c->opts.src_w; j++)
1964  ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]);
1965  srcPtr += srcStride[0];
1966  dstPtr += dstStride[0];
1967  }
1968  }
1969  }
1970  return srcSliceH;
1971 }
1972 
1973 static int bgr24ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[],
1974  const int srcStride[], int srcSliceY, int srcSliceH,
1975  uint8_t *const dst[], const int dstStride[])
1976 {
1978  src[0],
1979  dst[0] + srcSliceY * dstStride[0],
1980  dst[1] + (srcSliceY >> 1) * dstStride[1],
1981  dst[2] + (srcSliceY >> 1) * dstStride[2],
1982  c->opts.src_w, srcSliceH,
1983  dstStride[0], dstStride[1], srcStride[0],
1984  c->input_rgb2yuv_table);
1985  if (dst[3])
1986  fillPlane(dst[3], dstStride[3], c->opts.src_w, srcSliceH, srcSliceY, 255);
1987  return srcSliceH;
1988 }
1989 
1990 static int yvu9ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[],
1991  const int srcStride[], int srcSliceY, int srcSliceH,
1992  uint8_t *const dst[], const int dstStride[])
1993 {
1994  ff_copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->opts.src_w,
1995  dst[0], dstStride[0]);
1996 
1997  planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW,
1998  srcSliceH >> 2, srcStride[1], dstStride[1]);
1999  planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW,
2000  srcSliceH >> 2, srcStride[2], dstStride[2]);
2001  if (dst[3])
2002  fillPlane(dst[3], dstStride[3], c->opts.src_w, srcSliceH, srcSliceY, 255);
2003  return srcSliceH;
2004 }
2005 
2006 static int uint_y_to_float_y_wrapper(SwsInternal *c, const uint8_t *const src[],
2007  const int srcStride[], int srcSliceY,
2008  int srcSliceH, uint8_t *const dst[], const int dstStride[])
2009 {
2010  int y, x;
2011  ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
2012  const uint8_t *srcPtr = src[0];
2013  float *dstPtr = (float *)(dst[0] + dstStride[0] * srcSliceY);
2014 
2015  for (y = 0; y < srcSliceH; ++y){
2016  for (x = 0; x < c->opts.src_w; ++x){
2017  dstPtr[x] = c->uint2float_lut[srcPtr[x]];
2018  }
2019  srcPtr += srcStride[0];
2020  dstPtr += dstStrideFloat;
2021  }
2022 
2023  return srcSliceH;
2024 }
2025 
2027  const uint8_t *const src[],
2028  const int srcStride[], int srcSliceY,
2029  int srcSliceH, uint8_t *const dst[],
2030  const int dstStride[])
2031 {
2032  int y, x;
2033  ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
2034  const float *srcPtr = (const float *)src[0];
2035  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
2036 
2037  for (y = 0; y < srcSliceH; ++y){
2038  for (x = 0; x < c->opts.src_w; ++x){
2039  dstPtr[x] = av_clip_uint8(lrintf(255.0f * srcPtr[x]));
2040  }
2041  srcPtr += srcStrideFloat;
2042  dstPtr += dstStride[0];
2043  }
2044 
2045  return srcSliceH;
2046 }
2047 
2048 /* unscaled copy like stuff (assumes nearly identical formats) */
2049 static int packedCopyWrapper(SwsInternal *c, const uint8_t *const src[],
2050  const int srcStride[], int srcSliceY, int srcSliceH,
2051  uint8_t *const dst[], const int dstStride[])
2052 {
2053  if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
2054  memcpy(dst[0] + dstStride[0] * srcSliceY, src[0], srcSliceH * dstStride[0]);
2055  else {
2056  int i;
2057  const uint8_t *srcPtr = src[0];
2058  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
2059  int length = 0;
2060 
2061  /* universal length finder */
2062  while (length + c->opts.src_w <= FFABS(dstStride[0]) &&
2063  length + c->opts.src_w <= FFABS(srcStride[0]))
2064  length += c->opts.src_w;
2065  av_assert1(length != 0);
2066 
2067  for (i = 0; i < srcSliceH; i++) {
2068  memcpy(dstPtr, srcPtr, length);
2069  srcPtr += srcStride[0];
2070  dstPtr += dstStride[0];
2071  }
2072  }
2073  return srcSliceH;
2074 }
2075 
2076 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
2077  unsigned shift= src_depth-dst_depth, tmp;\
2078  unsigned bias = 1 << (shift - 1);\
2079  if (c->opts.dither == SWS_DITHER_NONE) {\
2080  for (i = 0; i < height; i++) {\
2081  for (j = 0; j < length-7; j+=8) {\
2082  tmp = (bswap(src[j+0]) + bias)>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
2083  tmp = (bswap(src[j+1]) + bias)>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
2084  tmp = (bswap(src[j+2]) + bias)>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
2085  tmp = (bswap(src[j+3]) + bias)>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
2086  tmp = (bswap(src[j+4]) + bias)>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
2087  tmp = (bswap(src[j+5]) + bias)>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
2088  tmp = (bswap(src[j+6]) + bias)>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
2089  tmp = (bswap(src[j+7]) + bias)>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
2090  }\
2091  for (; j < length; j++) {\
2092  tmp = (bswap(src[j]) + bias)>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
2093  }\
2094  dst += dstStride;\
2095  src += srcStride;\
2096  }\
2097  } else if (shiftonly) {\
2098  for (i = 0; i < height; i++) {\
2099  const uint8_t *dither= dithers[shift-1][i&7];\
2100  for (j = 0; j < length-7; j+=8) {\
2101  tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
2102  tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
2103  tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
2104  tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
2105  tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
2106  tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
2107  tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
2108  tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
2109  }\
2110  for (; j < length; j++) {\
2111  tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
2112  }\
2113  dst += dstStride;\
2114  src += srcStride;\
2115  }\
2116  } else {\
2117  for (i = 0; i < height; i++) {\
2118  const uint8_t *dither= dithers[shift-1][i&7];\
2119  for (j = 0; j < length-7; j+=8) {\
2120  tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
2121  tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
2122  tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
2123  tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
2124  tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
2125  tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
2126  tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
2127  tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
2128  }\
2129  for (; j < length; j++) {\
2130  tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
2131  }\
2132  dst += dstStride;\
2133  src += srcStride;\
2134  }\
2135  }
2136 
2137 static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[],
2138  const int srcStride[], int srcSliceY, int srcSliceH,
2139  uint8_t *const dst[], const int dstStride[])
2140 {
2141  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->opts.src_format);
2142  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->opts.dst_format);
2143  int plane, i, j;
2144  for (plane = 0; plane < 4 && dst[plane] != NULL; plane++) {
2145  int length = (plane == 0 || plane == 3) ? c->opts.src_w : AV_CEIL_RSHIFT(c->opts.src_w, c->chrDstHSubSample);
2146  int y = (plane == 0 || plane == 3) ? srcSliceY: AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
2147  int height = (plane == 0 || plane == 3) ? srcSliceH: AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
2148  const uint8_t *srcPtr = src[plane];
2149  uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
2150  int shiftonly = plane == 1 || plane == 2 || (!c->opts.src_range && plane == 0);
2151  if (plane == 1 && isSemiPlanarYUV(c->opts.dst_format))
2152  length *= 2;
2153 
2154  // ignore palette for GRAY8
2155  if (plane == 1 && desc_dst->nb_components < 3) continue;
2156  if (!src[plane] || (plane == 1 && desc_src->nb_components < 3)) {
2157  if (is16BPS(c->opts.dst_format) || isNBPS(c->opts.dst_format)) {
2158  fillPlane16(dst[plane], dstStride[plane], length, height, y,
2159  plane == 3, desc_dst->comp[plane].depth,
2160  isBE(c->opts.dst_format));
2161  } else {
2162  fillPlane(dst[plane], dstStride[plane], length, height, y,
2163  (plane == 3) ? 255 : 128);
2164  }
2165  } else {
2166  if(isNBPS(c->opts.src_format) || isNBPS(c->opts.dst_format)
2167  || (is16BPS(c->opts.src_format) != is16BPS(c->opts.dst_format))
2168  ) {
2169  const int src_depth = desc_src->comp[plane].depth;
2170  const int dst_depth = desc_dst->comp[plane].depth;
2171  const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
2172  uint16_t *dstPtr2 = (uint16_t*)dstPtr;
2173 
2174  if (dst_depth == 8) {
2175  av_assert1(src_depth > 8);
2176  if(isBE(c->opts.src_format) == HAVE_BIGENDIAN){
2177  DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
2178  } else {
2179  DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, )
2180  }
2181  } else if (src_depth == 8) {
2182  for (i = 0; i < height; i++) {
2183  #define COPY816(w)\
2184  if (shiftonly) {\
2185  for (j = 0; j < length; j++)\
2186  w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
2187  } else {\
2188  for (j = 0; j < length; j++)\
2189  w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
2190  (srcPtr[j]>>(2*8-dst_depth)));\
2191  }
2192  if(isBE(c->opts.dst_format)){
2193  COPY816(AV_WB16)
2194  } else {
2195  COPY816(AV_WL16)
2196  }
2197  dstPtr2 += dstStride[plane]/2;
2198  srcPtr += srcStride[plane];
2199  }
2200  } else if (src_depth <= dst_depth) {
2201  for (i = 0; i < height; i++) {
2202  j = 0;
2203  if(isBE(c->opts.src_format) == HAVE_BIGENDIAN &&
2204  isBE(c->opts.dst_format) == HAVE_BIGENDIAN &&
2205  shiftonly) {
2206  unsigned shift = dst_depth - src_depth;
2207 #if HAVE_FAST_64BIT
2208 #define FAST_COPY_UP(shift) \
2209  for (; j < length - 3; j += 4) { \
2210  uint64_t v = AV_RN64A(srcPtr2 + j); \
2211  AV_WN64A(dstPtr2 + j, v << shift); \
2212  }
2213 #else
2214 #define FAST_COPY_UP(shift) \
2215  for (; j < length - 1; j += 2) { \
2216  uint32_t v = AV_RN32A(srcPtr2 + j); \
2217  AV_WN32A(dstPtr2 + j, v << shift); \
2218  }
2219 #endif
2220  switch (shift)
2221  {
2222  case 6: FAST_COPY_UP(6); break;
2223  case 7: FAST_COPY_UP(7); break;
2224  }
2225  }
2226 #define COPY_UP(r,w) \
2227  if(shiftonly){\
2228  for (; j < length; j++){ \
2229  unsigned int v= r(&srcPtr2[j]);\
2230  w(&dstPtr2[j], v<<(dst_depth-src_depth));\
2231  }\
2232  }else{\
2233  for (; j < length; j++){ \
2234  unsigned int v= r(&srcPtr2[j]);\
2235  w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
2236  (v>>(2*src_depth-dst_depth)));\
2237  }\
2238  }
2239  if(isBE(c->opts.src_format)){
2240  if(isBE(c->opts.dst_format)){
2242  } else {
2244  }
2245  } else {
2246  if(isBE(c->opts.dst_format)){
2248  } else {
2250  }
2251  }
2252  dstPtr2 += dstStride[plane]/2;
2253  srcPtr2 += srcStride[plane]/2;
2254  }
2255  } else { /* src_depth > dst_depth */
2256  if(isBE(c->opts.src_format) == HAVE_BIGENDIAN){
2257  if(isBE(c->opts.dst_format) == HAVE_BIGENDIAN){
2258  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
2259  } else {
2260  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16)
2261  }
2262  }else{
2263  if(isBE(c->opts.dst_format) == HAVE_BIGENDIAN){
2264  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, )
2265  } else {
2266  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16)
2267  }
2268  }
2269  }
2270  } else if (is16BPS(c->opts.src_format) && is16BPS(c->opts.dst_format) &&
2271  isBE(c->opts.src_format) != isBE(c->opts.dst_format)) {
2272 
2273  for (i = 0; i < height; i++) {
2274  for (j = 0; j < length; j++)
2275  ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]);
2276  srcPtr += srcStride[plane];
2277  dstPtr += dstStride[plane];
2278  }
2279  } else if (isFloat(c->opts.src_format) && isFloat(c->opts.dst_format) &&
2280  isBE(c->opts.src_format) != isBE(c->opts.dst_format)) { /* swap float plane */
2281  for (i = 0; i < height; i++) {
2282  for (j = 0; j < length; j++)
2283  ((uint32_t *) dstPtr)[j] = av_bswap32(((const uint32_t *) srcPtr)[j]);
2284  srcPtr += srcStride[plane];
2285  dstPtr += dstStride[plane];
2286  }
2287  } else if (dstStride[plane] == srcStride[plane] &&
2288  srcStride[plane] > 0 && srcStride[plane] == length) {
2289  memcpy(dst[plane] + dstStride[plane] * y, src[plane],
2290  height * dstStride[plane]);
2291  } else {
2292  if (is16BPS(c->opts.src_format) && is16BPS(c->opts.dst_format))
2293  length *= 2;
2294  else if (desc_src->comp[0].depth == 1)
2295  length >>= 3; // monowhite/black
2296  for (i = 0; i < height; i++) {
2297  memcpy(dstPtr, srcPtr, length);
2298  srcPtr += srcStride[plane];
2299  dstPtr += dstStride[plane];
2300  }
2301  }
2302  }
2303  }
2304  return srcSliceH;
2305 }
2306 
2307 
2308 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
2309  ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
2310  (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
2311 
2312 
2314 {
2315  const enum AVPixelFormat srcFormat = c->opts.src_format;
2316  const enum AVPixelFormat dstFormat = c->opts.dst_format;
2317  const int flags = c->opts.flags;
2318  const int dstH = c->opts.dst_h;
2319  const int dstW = c->opts.dst_w;
2320  int needsDither;
2321 
2322  needsDither = isAnyRGB(dstFormat) &&
2323  c->dstFormatBpp < 24 &&
2324  (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat)));
2325 
2326  /* yv12_to_nv12 */
2327  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
2328  (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)) {
2329  c->convert_unscaled = planarToNv12Wrapper;
2330  }
2331  /* yv24_to_nv24 */
2332  if ((srcFormat == AV_PIX_FMT_YUV444P || srcFormat == AV_PIX_FMT_YUVA444P) &&
2333  (dstFormat == AV_PIX_FMT_NV24 || dstFormat == AV_PIX_FMT_NV42)) {
2334  c->convert_unscaled = planarToNv24Wrapper;
2335  }
2336  /* nv12_to_yv12 */
2337  if (dstFormat == AV_PIX_FMT_YUV420P &&
2338  (srcFormat == AV_PIX_FMT_NV12 || srcFormat == AV_PIX_FMT_NV21)) {
2339  c->convert_unscaled = nv12ToPlanarWrapper;
2340  }
2341  /* nv24_to_yv24 */
2342  if (dstFormat == AV_PIX_FMT_YUV444P &&
2343  (srcFormat == AV_PIX_FMT_NV24 || srcFormat == AV_PIX_FMT_NV42)) {
2344  c->convert_unscaled = nv24ToPlanarWrapper;
2345  }
2346  /* yuv2bgr */
2347  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P ||
2348  srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) &&
2349  !(flags & SWS_ACCURATE_RND) && (c->opts.dither == SWS_DITHER_BAYER || c->opts.dither == SWS_DITHER_AUTO) && !(dstH & 1)) {
2350  c->convert_unscaled = ff_yuv2rgb_get_func_ptr(c);
2351  c->dst_slice_align = 2;
2352  }
2353  /* yuv420p1x_to_p01x */
2354  if ((srcFormat == AV_PIX_FMT_YUV420P10 || srcFormat == AV_PIX_FMT_YUVA420P10 ||
2355  srcFormat == AV_PIX_FMT_YUV420P12 ||
2356  srcFormat == AV_PIX_FMT_YUV420P14 ||
2357  srcFormat == AV_PIX_FMT_YUV420P16 || srcFormat == AV_PIX_FMT_YUVA420P16) &&
2358  (dstFormat == AV_PIX_FMT_P010 || dstFormat == AV_PIX_FMT_P016)) {
2359  c->convert_unscaled = planarToP01xWrapper;
2360  }
2361  /* yuv420p_to_p01xle */
2362  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
2363  (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P016LE)) {
2364  c->convert_unscaled = planar8ToP01xleWrapper;
2365  }
2366 
2367  if (srcFormat == AV_PIX_FMT_YUV410P && !(dstH & 3) &&
2368  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
2369  !(flags & SWS_BITEXACT)) {
2370  c->convert_unscaled = yvu9ToYv12Wrapper;
2371  c->dst_slice_align = 4;
2372  }
2373 
2374  /* bgr24toYV12 */
2375  if (srcFormat == AV_PIX_FMT_BGR24 &&
2376  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
2377  !(flags & SWS_ACCURATE_RND) && !(dstW&1))
2378  c->convert_unscaled = bgr24ToYv12Wrapper;
2379 
2380  /* AYUV/VUYA/UYVA -> AYUV/VUYA/UYVA */
2381  if (isAYUV(srcFormat) && isAYUV(dstFormat) && findRgbConvFn(c))
2382  c->convert_unscaled = rgbToRgbWrapper;
2383 
2384  /* RGB/BGR -> RGB/BGR (no dither needed forms) */
2385  if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)
2386  && (!needsDither || (c->opts.flags&(SWS_FAST_BILINEAR|SWS_POINT))))
2387  c->convert_unscaled = rgbToRgbWrapper;
2388 
2389  /* RGB to planar RGB */
2390  if ((srcFormat == AV_PIX_FMT_GBRP && dstFormat == AV_PIX_FMT_GBRAP) ||
2391  (srcFormat == AV_PIX_FMT_GBRP10 && dstFormat == AV_PIX_FMT_GBRAP10) ||
2392  (srcFormat == AV_PIX_FMT_GBRP12 && dstFormat == AV_PIX_FMT_GBRAP12) ||
2393  (srcFormat == AV_PIX_FMT_GBRP14 && dstFormat == AV_PIX_FMT_GBRAP14) ||
2394  (srcFormat == AV_PIX_FMT_GBRP16 && dstFormat == AV_PIX_FMT_GBRAP16) ||
2395  (srcFormat == AV_PIX_FMT_GBRAP && dstFormat == AV_PIX_FMT_GBRP) ||
2396  (srcFormat == AV_PIX_FMT_GBRAP10 && dstFormat == AV_PIX_FMT_GBRP10) ||
2397  (srcFormat == AV_PIX_FMT_GBRAP12 && dstFormat == AV_PIX_FMT_GBRP12) ||
2398  (srcFormat == AV_PIX_FMT_GBRAP14 && dstFormat == AV_PIX_FMT_GBRP14) ||
2399  (srcFormat == AV_PIX_FMT_GBRAP16 && dstFormat == AV_PIX_FMT_GBRP16))
2400  c->convert_unscaled = planarRgbToplanarRgbWrapper;
2401 
2402 #define isByteRGB(f) ( \
2403  f == AV_PIX_FMT_RGB32 || \
2404  f == AV_PIX_FMT_RGB32_1 || \
2405  f == AV_PIX_FMT_RGB24 || \
2406  f == AV_PIX_FMT_BGR32 || \
2407  f == AV_PIX_FMT_BGR32_1 || \
2408  f == AV_PIX_FMT_BGR24)
2409 
2410  if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
2411  c->convert_unscaled = planarRgbToRgbWrapper;
2412 
2413  if (srcFormat == AV_PIX_FMT_GBRAP && isByteRGB(dstFormat))
2414  c->convert_unscaled = planarRgbaToRgbWrapper;
2415 
2416  if ((srcFormat == AV_PIX_FMT_RGB48LE || srcFormat == AV_PIX_FMT_RGB48BE ||
2417  srcFormat == AV_PIX_FMT_BGR48LE || srcFormat == AV_PIX_FMT_BGR48BE ||
2418  srcFormat == AV_PIX_FMT_RGBA64LE || srcFormat == AV_PIX_FMT_RGBA64BE ||
2419  srcFormat == AV_PIX_FMT_BGRA64LE || srcFormat == AV_PIX_FMT_BGRA64BE) &&
2420  (dstFormat == AV_PIX_FMT_GBRP9LE || dstFormat == AV_PIX_FMT_GBRP9BE ||
2421  dstFormat == AV_PIX_FMT_GBRP10LE || dstFormat == AV_PIX_FMT_GBRP10BE ||
2422  dstFormat == AV_PIX_FMT_GBRP12LE || dstFormat == AV_PIX_FMT_GBRP12BE ||
2423  dstFormat == AV_PIX_FMT_GBRP14LE || dstFormat == AV_PIX_FMT_GBRP14BE ||
2424  dstFormat == AV_PIX_FMT_GBRP16LE || dstFormat == AV_PIX_FMT_GBRP16BE ||
2425  dstFormat == AV_PIX_FMT_GBRAP10LE || dstFormat == AV_PIX_FMT_GBRAP10BE ||
2426  dstFormat == AV_PIX_FMT_GBRAP12LE || dstFormat == AV_PIX_FMT_GBRAP12BE ||
2427  dstFormat == AV_PIX_FMT_GBRAP14LE || dstFormat == AV_PIX_FMT_GBRAP14BE ||
2428  dstFormat == AV_PIX_FMT_GBRAP16LE || dstFormat == AV_PIX_FMT_GBRAP16BE ))
2429  c->convert_unscaled = Rgb16ToPlanarRgb16Wrapper;
2430 
2431  if (av_pix_fmt_desc_get(dstFormat)->comp[0].depth >= 10 &&
2432  isPlanarRGB(dstFormat) && !isFloat(dstFormat) &&
2433  (srcFormat == AV_PIX_FMT_X2RGB10LE || srcFormat == AV_PIX_FMT_X2BGR10LE))
2434  c->convert_unscaled = Rgb16ToPlanarRgb16Wrapper;
2435 
2436  if ((srcFormat == AV_PIX_FMT_GBRP9LE || srcFormat == AV_PIX_FMT_GBRP9BE ||
2437  srcFormat == AV_PIX_FMT_GBRP16LE || srcFormat == AV_PIX_FMT_GBRP16BE ||
2438  srcFormat == AV_PIX_FMT_GBRP10LE || srcFormat == AV_PIX_FMT_GBRP10BE ||
2439  srcFormat == AV_PIX_FMT_GBRP12LE || srcFormat == AV_PIX_FMT_GBRP12BE ||
2440  srcFormat == AV_PIX_FMT_GBRP14LE || srcFormat == AV_PIX_FMT_GBRP14BE ||
2441  srcFormat == AV_PIX_FMT_GBRAP10LE || srcFormat == AV_PIX_FMT_GBRAP10BE ||
2442  srcFormat == AV_PIX_FMT_GBRAP12LE || srcFormat == AV_PIX_FMT_GBRAP12BE ||
2443  srcFormat == AV_PIX_FMT_GBRAP14LE || srcFormat == AV_PIX_FMT_GBRAP14BE ||
2444  srcFormat == AV_PIX_FMT_GBRAP16LE || srcFormat == AV_PIX_FMT_GBRAP16BE) &&
2445  (dstFormat == AV_PIX_FMT_RGB48LE || dstFormat == AV_PIX_FMT_RGB48BE ||
2446  dstFormat == AV_PIX_FMT_BGR48LE || dstFormat == AV_PIX_FMT_BGR48BE ||
2447  dstFormat == AV_PIX_FMT_RGBA64LE || dstFormat == AV_PIX_FMT_RGBA64BE ||
2448  dstFormat == AV_PIX_FMT_BGRA64LE || dstFormat == AV_PIX_FMT_BGRA64BE))
2449  c->convert_unscaled = planarRgb16ToRgb16Wrapper;
2450 
2451  if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth >= 10 &&
2452  isPlanarRGB(srcFormat) && !isFloat(srcFormat) &&
2453  (dstFormat == AV_PIX_FMT_X2RGB10LE || dstFormat == AV_PIX_FMT_X2BGR10LE))
2454  c->convert_unscaled = planarRgb16ToRgb16Wrapper;
2455 
2456  if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth == 8 &&
2457  isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRP)
2458  c->convert_unscaled = rgbToPlanarRgbWrapper;
2459 
2460  if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth == 8 &&
2461  isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRAP)
2462  c->convert_unscaled = rgbToPlanarRgbaWrapper;
2463 
2464  if (isBayer(srcFormat)) {
2465  c->dst_slice_align = 2;
2466  if (dstFormat == AV_PIX_FMT_RGB24)
2467  c->convert_unscaled = bayer_to_rgb24_wrapper;
2468  else if (dstFormat == AV_PIX_FMT_RGB48)
2469  c->convert_unscaled = bayer_to_rgb48_wrapper;
2470  else if (dstFormat == AV_PIX_FMT_YUV420P)
2471  c->convert_unscaled = bayer_to_yv12_wrapper;
2472  else if (!isBayer(dstFormat)) {
2473  av_log(c, AV_LOG_ERROR, "unsupported bayer conversion\n");
2474  av_assert0(0);
2475  }
2476  }
2477 
2478  /* bswap 16 bits per pixel/component packed formats */
2479  if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_BGGR16) ||
2480  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_RGGB16) ||
2481  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GBRG16) ||
2482  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GRBG16) ||
2483  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR444) ||
2484  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR48) ||
2485  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR555) ||
2486  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR565) ||
2487  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
2488  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY9) ||
2489  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY10) ||
2490  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY12) ||
2491  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY14) ||
2492  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY16) ||
2493  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YA16) ||
2494  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_AYUV64) ||
2495  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP9) ||
2496  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP10) ||
2497  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP12) ||
2498  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP14) ||
2499  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP16) ||
2500  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP10) ||
2501  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP12) ||
2502  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP14) ||
2503  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP16) ||
2504  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB444) ||
2505  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB48) ||
2506  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB555) ||
2507  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB565) ||
2508  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
2509  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XV36) ||
2510  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XV48) ||
2511  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XYZ12) ||
2512  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P9) ||
2513  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P10) ||
2514  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P12) ||
2515  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P14) ||
2516  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P16) ||
2517  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P9) ||
2518  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P10) ||
2519  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P12) ||
2520  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P14) ||
2521  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P16) ||
2522  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P10) ||
2523  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P12) ||
2524  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P9) ||
2525  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P10) ||
2526  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P12) ||
2527  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P14) ||
2528  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P16))
2529  c->convert_unscaled = bswap_16bpc;
2530 
2531  /* bswap 32 bits per pixel/component formats */
2532  if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRPF32) ||
2533  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAPF32))
2534  c->convert_unscaled = bswap_32bpc;
2535 
2536  if (usePal(srcFormat) && isByteRGB(dstFormat))
2537  c->convert_unscaled = palToRgbWrapper;
2538 
2539  if (srcFormat == AV_PIX_FMT_YUV422P) {
2540  if (dstFormat == AV_PIX_FMT_YUYV422)
2541  c->convert_unscaled = yuv422pToYuy2Wrapper;
2542  else if (dstFormat == AV_PIX_FMT_UYVY422)
2543  c->convert_unscaled = yuv422pToUyvyWrapper;
2544  }
2545 
2546  /* uint Y to float Y */
2547  if (srcFormat == AV_PIX_FMT_GRAY8 && dstFormat == AV_PIX_FMT_GRAYF32){
2548  c->convert_unscaled = uint_y_to_float_y_wrapper;
2549  }
2550 
2551  /* float Y to uint Y */
2552  if (srcFormat == AV_PIX_FMT_GRAYF32 && dstFormat == AV_PIX_FMT_GRAY8){
2553  c->convert_unscaled = float_y_to_uint_y_wrapper;
2554  }
2555 
2556  /* LQ converters if -sws 0 or -sws 4*/
2557  if (c->opts.flags&(SWS_FAST_BILINEAR|SWS_POINT)) {
2558  /* yv12_to_yuy2 */
2559  if (srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) {
2560  if (dstFormat == AV_PIX_FMT_YUYV422)
2561  c->convert_unscaled = planarToYuy2Wrapper;
2562  else if (dstFormat == AV_PIX_FMT_UYVY422)
2563  c->convert_unscaled = planarToUyvyWrapper;
2564  }
2565  }
2566  if (srcFormat == AV_PIX_FMT_YUYV422 &&
2567  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
2568  c->convert_unscaled = yuyvToYuv420Wrapper;
2569  if (srcFormat == AV_PIX_FMT_UYVY422 &&
2570  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
2571  c->convert_unscaled = uyvyToYuv420Wrapper;
2572  if (srcFormat == AV_PIX_FMT_YUYV422 && dstFormat == AV_PIX_FMT_YUV422P)
2573  c->convert_unscaled = yuyvToYuv422Wrapper;
2574  if (srcFormat == AV_PIX_FMT_UYVY422 && dstFormat == AV_PIX_FMT_YUV422P)
2575  c->convert_unscaled = uyvyToYuv422Wrapper;
2576  if (dstFormat == AV_PIX_FMT_YUV420P &&
2577  (srcFormat == AV_PIX_FMT_NV24 || srcFormat == AV_PIX_FMT_NV42))
2578  c->convert_unscaled = nv24ToYuv420Wrapper;
2579 
2580 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
2581  /* simple copy */
2582  if ( srcFormat == dstFormat ||
2583  (srcFormat == AV_PIX_FMT_YUVA420P && dstFormat == AV_PIX_FMT_YUV420P) ||
2584  (srcFormat == AV_PIX_FMT_YUV420P && dstFormat == AV_PIX_FMT_YUVA420P) ||
2585  (isFloat(srcFormat) == isFloat(dstFormat)) && ((isPlanarYUV(srcFormat) && isPlanarGray(dstFormat)) ||
2586  (isPlanarYUV(dstFormat) && isPlanarGray(srcFormat)) ||
2587  (isPlanarGray(dstFormat) && isPlanarGray(srcFormat)) ||
2588  (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) &&
2589  c->chrDstHSubSample == c->chrSrcHSubSample &&
2590  c->chrDstVSubSample == c->chrSrcVSubSample &&
2591  isSemiPlanarYUV(srcFormat) == isSemiPlanarYUV(dstFormat))))
2592  {
2593  if (isPacked(c->opts.src_format))
2594  c->convert_unscaled = packedCopyWrapper;
2595  else /* Planar YUV or gray */
2596  c->convert_unscaled = planarCopyWrapper;
2597  }
2598 
2599 #if ARCH_PPC
2601 #elif ARCH_ARM
2603 #elif ARCH_AARCH64
2605 #endif
2606 }
2607 
2608 /* Convert the palette to the same packed 32-bit format as the palette */
2609 void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst,
2610  int num_pixels, const uint8_t *palette)
2611 {
2612  int i;
2613 
2614  for (i = 0; i < num_pixels; i++)
2615  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
2616 }
2617 
2618 /* Palette format: ABCD -> dst format: ABC */
2619 void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst,
2620  int num_pixels, const uint8_t *palette)
2621 {
2622  int i;
2623 
2624  for (i = 0; i < num_pixels; i++) {
2625  //FIXME slow?
2626  dst[0] = palette[src[i] * 4 + 0];
2627  dst[1] = palette[src[i] * 4 + 1];
2628  dst[2] = palette[src[i] * 4 + 2];
2629  dst += 3;
2630  }
2631 }
isBayer
static av_always_inline int isBayer(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:842
rgbToPlanarRgbaWrapper
static int rgbToPlanarRgbaWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1456
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:525
nv24ToPlanarWrapper
static int nv24ToPlanarWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:203
rgb12tobgr12
void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:325
isX2RGB
#define isX2RGB(x)
Definition: swscale_unscaled.c:1747
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AV_PIX_FMT_BAYER_GBRG16LE
@ AV_PIX_FMT_BAYER_GBRG16LE
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:293
AV_PIX_FMT_BGR48LE
@ AV_PIX_FMT_BGR48LE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:146
isPlanarRGB
static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:910
rgb32tobgr24
void(* rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:35
shuffle_bytes_3012
void(* shuffle_bytes_3012)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:57
SWS_DITHER_AUTO
@ SWS_DITHER_AUTO
Definition: swscale.h:81
isPacked
static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:887
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:140
ff_get_unscaled_swscale_ppc
av_cold void ff_get_unscaled_swscale_ppc(SwsInternal *c)
Definition: yuv2yuv_altivec.c:187
AV_PIX_FMT_BGRA64BE
@ AV_PIX_FMT_BGRA64BE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:204
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:422
C2
#define C2
Definition: mpegaudiodsp_template.c:239
mem_internal.h
packedtogbr24p
static void packedtogbr24p(const uint8_t *src, int srcStride, uint8_t *const dst[], const int dstStride[], int srcSliceH, int alpha_first, int inc_size, int width)
Definition: swscale_unscaled.c:1319
gbr24ptopacked24
static void gbr24ptopacked24(const uint8_t *src[], const int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int width)
Definition: swscale_unscaled.c:1114
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:81
AV_PIX_FMT_BGR32
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:477
yv12toyuy2
void(* yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, int width, int height, int lumStride, int chromStride, int dstStride)
Height should be a multiple of 2 and width should be a multiple of 16.
Definition: rgb2rgb.c:65
AV_PIX_FMT_GBRP16BE
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:171
rgb15to24
void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:290
AV_PIX_FMT_GBRP10BE
@ AV_PIX_FMT_GBRP10BE
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:169
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
nv24ToYuv420Wrapper
static int nv24ToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:248
src1
const pixel * src1
Definition: h264pred_template.c:421
C0
#define C0
planarRgbaToRgbWrapper
static int planarRgbaToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1190
pixdesc.h
AV_PIX_FMT_RGBA64BE
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:202
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:545
w
uint8_t w
Definition: llviddspenc.c:38
planarToNv12Wrapper
static int planarToNv12Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:142
rgb16tobgr32
void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:193
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:57
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:540
AVPixFmtDescriptor::name
const char * name
Definition: pixdesc.h:70
SWS_BITEXACT
@ SWS_BITEXACT
Definition: swscale.h:156
CONV_IS
#define CONV_IS(src, dst)
planar8ToP01xleWrapper
static int planar8ToP01xleWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam8[], const int dstStride[])
Definition: swscale_unscaled.c:328
x2rgb10tobgr64_bswap
void x2rgb10tobgr64_bswap(const uint8_t *src, uint8_t *dst, int src_size)
shuffle_bytes_3210
void(* shuffle_bytes_3210)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:58
rgb2yuv
static const char rgb2yuv[]
Definition: vf_scale_vulkan.c:69
rgb48tobgr48_nobswap
void rgb48tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:502
AV_PIX_FMT_RGB32_1
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:476
rgb32tobgr16
void(* rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:36
yuyvtoyuv422
void(* yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride)
Definition: rgb2rgb.c:117
rgbToPlanarRgbWrapper
static int rgbToPlanarRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1348
AV_PIX_FMT_GBRP14BE
@ AV_PIX_FMT_GBRP14BE
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:281
rgb24tobgr16
void(* rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:40
planarToP01xWrapper
static int planarToP01xWrapper(SwsInternal *c, const uint8_t *const src8[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam8[], const int dstStride[])
Definition: swscale_unscaled.c:268
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_BGRA
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:102
rgb15to32
void(* rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:52
mathematics.h
sws_convertPalette8ToPacked24
void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
Convert an 8-bit paletted frame into a frame with a color depth of 24 bits.
Definition: swscale_unscaled.c:2619
AV_PIX_FMT_BAYER_GRBG16BE
@ AV_PIX_FMT_BAYER_GRBG16BE
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian
Definition: pixfmt.h:296
AV_PIX_FMT_BAYER_GRBG16
#define AV_PIX_FMT_BAYER_GRBG16
Definition: pixfmt.h:530
AV_PIX_FMT_GBRAP14BE
@ AV_PIX_FMT_GBRAP14BE
planar GBR 4:4:4:4 56bpp, big-endian
Definition: pixfmt.h:432
yv12touyvy
void(* yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, int width, int height, int lumStride, int chromStride, int dstStride)
Height should be a multiple of 2 and width should be a multiple of 16.
Definition: rgb2rgb.c:69
bayer_template.c
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:482
rgb32to16
void(* rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:45
AV_PIX_FMT_BAYER_GBRG16BE
@ AV_PIX_FMT_BAYER_GBRG16BE
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian
Definition: pixfmt.h:294
x2rgb10tobgr48_nobswap
void x2rgb10tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
AV_PIX_FMT_GBRAP12LE
@ AV_PIX_FMT_GBRAP12LE
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:311
yuyvToYuv420Wrapper
static int yuyvToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:419
SWS_FAST_BILINEAR
@ SWS_FAST_BILINEAR
Scaler selection options.
Definition: swscale.h:98
isRGBA32
#define isRGBA32(x)
Definition: swscale_unscaled.c:1719
is16BPS
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:727
bswap_32bpc
static int bswap_32bpc(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:539
planarToUyvyWrapper
static int planarToUyvyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:383
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:520
shuffle_bytes_2130
void(* shuffle_bytes_2130)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:61
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
isRGBA64
#define isRGBA64(x)
Definition: swscale_unscaled.c:1726
C1
#define C1
Definition: mpegaudiodsp_template.c:238
float_y_to_uint_y_wrapper
static int float_y_to_uint_y_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:2026
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:518
palToRgbWrapper
static int palToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:567
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:500
rgb16tobgr16
void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:248
yuv422pToYuy2Wrapper
static int yuv422pToYuy2Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:395
x2rgb10tobgr48_bswap
void x2rgb10tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
val
static double val(void *priv, double ch)
Definition: aeval.c:77
isNBPS
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:741
AV_PIX_FMT_XV48
#define AV_PIX_FMT_XV48
Definition: pixfmt.h:561
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:486
rgb48tobgr64_bswap
void rgb48tobgr64_bswap(const uint8_t *src, uint8_t *dst, int src_size)
DITHER_COPY
#define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)
Definition: swscale_unscaled.c:2076
bgr24ToYv12Wrapper
static int bgr24ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1973
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:505
isRGB48
#define isRGB48(x)
Definition: swscale_unscaled.c:1733
avassert.h
packed32togbrap
static void packed32togbrap(const uint8_t *src, int srcStride, uint8_t *const dst[], const int dstStride[], int srcSliceH, int alpha_first, int width)
Definition: swscale_unscaled.c:1420
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
AV_PIX_FMT_BAYER_RGGB16BE
@ AV_PIX_FMT_BAYER_RGGB16BE
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, big-endian
Definition: pixfmt.h:292
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:514
gbraptopacked32
static void gbraptopacked32(const uint8_t *src[], const int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int alpha_first, int width)
Definition: swscale_unscaled.c:1161
rgb16tobgr24
void(* rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:42
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:522
AV_PIX_FMT_GBRAP16BE
@ AV_PIX_FMT_GBRAP16BE
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:213
intreadwrite.h
AV_PIX_FMT_GBRP16LE
@ AV_PIX_FMT_GBRP16LE
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:172
AV_PIX_FMT_GBRAP14
#define AV_PIX_FMT_GBRAP14
Definition: pixfmt.h:524
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:523
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
AV_PIX_FMT_BAYER_RGGB16LE
@ AV_PIX_FMT_BAYER_RGGB16LE
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:291
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:515
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
AV_PIX_FMT_BAYER_BGGR8
@ AV_PIX_FMT_BAYER_BGGR8
bayer, BGBG..(odd line), GRGR..(even line), 8-bit samples
Definition: pixfmt.h:285
nv24_to_yuv420p_chroma
static void nv24_to_yuv420p_chroma(uint8_t *dst1, int dstStride1, uint8_t *dst2, int dstStride2, const uint8_t *src, int srcStride, int w, int h)
Definition: swscale_unscaled.c:224
shuffle_bytes_1230
void(* shuffle_bytes_1230)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:56
Rgb16ToPlanarRgb16Wrapper
static int Rgb16ToPlanarRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:818
SWS_DITHER_BAYER
@ SWS_DITHER_BAYER
Definition: swscale.h:82
AV_PIX_FMT_GBRP12LE
@ AV_PIX_FMT_GBRP12LE
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:280
rgb15tobgr24
void(* rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:43
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:499
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:513
AV_PIX_FMT_FLAG_ALPHA
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:147
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:485
isAYUV
#define isAYUV(x)
Definition: swscale_unscaled.c:1740
yuv422ptoyuy2
void(* yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, int width, int height, int lumStride, int chromStride, int dstStride)
Width should be a multiple of 16.
Definition: rgb2rgb.c:73
shuffle_bytes_2103
void(* shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:55
rgb32tobgr15
void(* rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:37
bayer_to_yv12_wrapper
static int bayer_to_yv12_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1663
AV_PIX_FMT_GBRP10LE
@ AV_PIX_FMT_GBRP10LE
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:170
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
rgb48to64_bswap
void rgb48to64_bswap(const uint8_t *src, uint8_t *dst, int src_size)
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:535
AV_PIX_FMT_BGR32_1
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:478
uyvyToYuv420Wrapper
static int uyvyToYuv420Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:450
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
conv
static int conv(int samples, float **pcm, char *buf, int channels)
Definition: libvorbisdec.c:134
AV_PIX_FMT_BAYER_RGGB8
@ AV_PIX_FMT_BAYER_RGGB8
bayer, RGRG..(odd line), GBGB..(even line), 8-bit samples
Definition: pixfmt.h:286
rgb16to24
void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:234
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
AV_PIX_FMT_BAYER_BGGR16
#define AV_PIX_FMT_BAYER_BGGR16
Definition: pixfmt.h:527
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:483
rgb12to15
void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:215
interleaveBytes
void(* interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, int width, int height, int src1Stride, int src2Stride, int dstStride)
Definition: rgb2rgb.c:92
isSemiPlanarYUV
static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:773
AV_PIX_FMT_BAYER_GRBG16LE
@ AV_PIX_FMT_BAYER_GRBG16LE
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:295
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:521
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:492
shuffle_bytes_3102
void(* shuffle_bytes_3102)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:59
packed30togbra10
static void packed30togbra10(const uint8_t *src, int srcStride, uint16_t *dst[], const int dstStride[], int srcSliceH, int swap, int bpc, int width)
Definition: swscale_unscaled.c:747
AV_PIX_FMT_GBRAP12BE
@ AV_PIX_FMT_GBRAP12BE
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:310
AV_PIX_FMT_BGR48
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:493
NULL
#define NULL
Definition: coverity.c:32
rgb16to15
void(* rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:50
yvu9ToYv12Wrapper
static int yvu9ToYv12Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1990
AVPixFmtDescriptor::nb_components
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:401
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:74
uint_y_to_float_y_wrapper
static int uint_y_to_float_y_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:2006
gray8aToPacked24
static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
Definition: swscale_unscaled.c:498
ff_get_unscaled_swscale_aarch64
void ff_get_unscaled_swscale_aarch64(SwsInternal *c)
Definition: swscale_unscaled.c:218
AV_PIX_FMT_RGB48LE
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:110
bayer_to_rgb48_wrapper
static int bayer_to_rgb48_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1613
AV_PIX_FMT_RGBA64LE
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:203
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:504
AV_PIX_FMT_BAYER_GBRG16
#define AV_PIX_FMT_BAYER_GBRG16
Definition: pixfmt.h:529
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:503
rgbConvFn
void(* rgbConvFn)(const uint8_t *, uint8_t *, int)
Definition: swscale_unscaled.c:1753
x2rgb10to64_nobswap
void x2rgb10to64_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
ff_get_unscaled_swscale_arm
void ff_get_unscaled_swscale_arm(SwsInternal *c)
Definition: swscale_unscaled.c:185
COPY816
#define COPY816(w)
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
yuyvtoyuv420
void(* yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride)
Definition: rgb2rgb.c:114
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:517
AVPixFmtDescriptor::flags
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:94
rgb15tobgr16
void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:304
AV_PIX_FMT_ABGR
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:101
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
rgb64tobgr48_bswap
void rgb64tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
planarCopyWrapper
static int planarCopyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:2137
dithers
static const uint8_t dithers[8][8][8]
Definition: swscale_unscaled.c:38
rgb24tobgr32
void(* rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:38
AV_PIX_FMT_X2RGB10LE
@ AV_PIX_FMT_X2RGB10LE
packed RGB 10:10:10, 30bpp, (msb)2X 10R 10G 10B(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:384
rgb64to48_nobswap
void rgb64to48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
isBE
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:748
f
f
Definition: af_crystalizer.c:122
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:186
height
#define height
Definition: dsp.h:85
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:104
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:136
fillPlane16
static void fillPlane16(uint8_t *plane, int stride, int width, int height, int y, int alpha, int bits, const int big_endian)
Definition: swscale_internal.h:1052
shift
static int shift(int a, int b)
Definition: bonk.c:261
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
AV_PIX_FMT_BAYER_BGGR16LE
@ AV_PIX_FMT_BAYER_BGGR16LE
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, little-endian
Definition: pixfmt.h:289
usePal
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:918
av_bswap32
#define av_bswap32
Definition: bswap.h:47
isAnyRGB
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:856
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:532
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:507
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:488
SWS_POINT
@ SWS_POINT
nearest neighbor
Definition: swscale.h:102
AV_PIX_FMT_BGR555
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:495
x2rgb10tobgr64_nobswap
void x2rgb10tobgr64_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:509
gray8aToPacked32_1
static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
Definition: swscale_unscaled.c:489
AV_PIX_FMT_GBRP9BE
@ AV_PIX_FMT_GBRP9BE
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:167
rgb64tobgr48_nobswap
void rgb64tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
AV_PIX_FMT_AYUV64
#define AV_PIX_FMT_AYUV64
Definition: pixfmt.h:551
shuffle_bytes_0321
void(* shuffle_bytes_0321)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:54
IS_DIFFERENT_ENDIANESS
#define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt)
Definition: swscale_unscaled.c:2308
rgb32to24
void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:155
nv12ToPlanarWrapper
static int nv12ToPlanarWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:162
rgb15tobgr15
void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:314
findRgbConvFn
static rgbConvFn findRgbConvFn(SwsInternal *c)
Definition: swscale_unscaled.c:1754
AV_PIX_FMT_GBRP9LE
@ AV_PIX_FMT_GBRP9LE
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:168
AV_WL16
#define AV_WL16(p, v)
Definition: intreadwrite.h:408
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:475
isBGRinInt
static av_always_inline int isBGRinInt(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:820
yuyvToYuv422Wrapper
static int yuyvToYuv422Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:436
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
AV_PIX_FMT_GBRAP10LE
@ AV_PIX_FMT_GBRAP10LE
planar GBR 4:4:4:4 40bpp, little-endian
Definition: pixfmt.h:314
CASE
#define CASE(pixfmt, prefix)
rgb24to16
void(* rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:47
interpolate
static void interpolate(float *out, float v1, float v2, int size)
Definition: twinvq.c:85
bayer_to_rgb24_wrapper
static int bayer_to_rgb24_wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1563
AV_PIX_FMT_ARGB
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:99
AV_PIX_FMT_BGRA64LE
@ AV_PIX_FMT_BGRA64LE
packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:205
uyvytoyuv422
void(* uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride)
Definition: rgb2rgb.c:111
planarToYuy2Wrapper
static int planarToYuy2Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:371
AV_PIX_FMT_XYZ12
#define AV_PIX_FMT_XYZ12
Definition: pixfmt.h:549
AV_PIX_FMT_BGRA64
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:497
AVComponentDescriptor::shift
int shift
Number of least significant bits that must be shifted away to get the value.
Definition: pixdesc.h:52
ff_rgb24toyv12
void(* ff_rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, int width, int height, int lumStride, int chromStride, int srcStride, const int32_t *rgb2yuv)
Height should be a multiple of 2 and width should be a multiple of 2.
Definition: rgb2rgb.c:85
FAST_COPY_UP
#define FAST_COPY_UP(shift)
AV_PIX_FMT_RGB48BE
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:109
ff_copyPlane
void ff_copyPlane(const uint8_t *src, int srcStride, int srcSliceY, int srcSliceH, int width, uint8_t *dst, int dstStride)
Definition: swscale_unscaled.c:125
lrintf
#define lrintf(x)
Definition: libm_mips.h:72
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:487
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
gbr16ptopacked16
static void gbr16ptopacked16(const uint16_t *src[], const int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int alpha, int swap, int bpp, int width)
Definition: swscale_unscaled.c:890
rgb24to15
void(* rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:48
src2
const pixel * src2
Definition: h264pred_template.c:422
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:519
AV_PIX_FMT_NV24
@ AV_PIX_FMT_NV24
planar YUV 4:4:4, 24bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:371
AV_PIX_FMT_BGR444
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:496
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
AV_PIX_FMT_BAYER_GBRG8
@ AV_PIX_FMT_BAYER_GBRG8
bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples
Definition: pixfmt.h:287
AV_PIX_FMT_RGB555
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:490
planarRgb16ToRgb16Wrapper
static int planarRgb16ToRgb16Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1044
rgb32to15
void(* rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:46
rgb48tobgr64_nobswap
void rgb48tobgr64_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
swscale_internal.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_PIX_FMT_FLAG_BE
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:116
yuv422pToUyvyWrapper
static int yuv422pToUyvyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:407
fillPlane
static void fillPlane(uint8_t *plane, int stride, int width, int height, int y, uint8_t val)
Definition: swscale_unscaled.c:114
AV_PIX_FMT_NV21
@ AV_PIX_FMT_NV21
as above, but U and V bytes are swapped
Definition: pixfmt.h:97
AV_PIX_FMT_BGR565
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:494
AV_PIX_FMT_NV42
@ AV_PIX_FMT_NV42
as above, but U and V bytes are swapped
Definition: pixfmt.h:372
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:501
isFloat
static av_always_inline int isFloat(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:864
gbr16ptopacked30
static void gbr16ptopacked30(const uint16_t *src[], const int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int swap, int bpp, int width)
Definition: swscale_unscaled.c:1009
AV_PIX_FMT_P016
#define AV_PIX_FMT_P016
Definition: pixfmt.h:554
AV_PIX_FMT_RGB565
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:489
output_pixel
#define output_pixel(p, v)
Definition: swscale_unscaled.c:325
stride
#define stride
Definition: h264pred_template.c:537
AV_PIX_FMT_GBRAP16LE
@ AV_PIX_FMT_GBRAP16LE
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:214
SwsInternal
Definition: swscale_internal.h:317
bswap.h
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:96
AV_PIX_FMT_BAYER_BGGR16BE
@ AV_PIX_FMT_BAYER_BGGR16BE
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, big-endian
Definition: pixfmt.h:290
AV_PIX_FMT_P016LE
@ AV_PIX_FMT_P016LE
like NV12, with 16bpp per component, little-endian
Definition: pixfmt.h:323
deinterleaveBytes
void(* deinterleaveBytes)(const uint8_t *src, uint8_t *dst1, uint8_t *dst2, int width, int height, int srcStride, int dst1Stride, int dst2Stride)
Definition: rgb2rgb.c:95
isPlanarGray
#define isPlanarGray(x)
x2rgb10to48_bswap
void x2rgb10to48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
rgb48to64_nobswap
void rgb48to64_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
rgb48tobgr48_bswap
void rgb48tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:506
AV_PIX_FMT_GBRP12BE
@ AV_PIX_FMT_GBRP12BE
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:279
AV_PIX_FMT_UYVY422
@ AV_PIX_FMT_UYVY422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:88
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
uyvytoyuv420
void(* uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, int width, int height, int lumStride, int chromStride, int srcStride)
Definition: rgb2rgb.c:108
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:511
rgb16to32
void(* rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:49
gray8aToPacked32
static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
Definition: swscale_unscaled.c:481
uyvyToYuv422Wrapper
static int uyvyToYuv422Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:467
isPackedRGB
static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:903
rgb24to32
void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:173
packed16togbra16
static void packed16togbra16(const uint8_t *src, int srcStride, uint16_t *dst[], const int dstStride[], int srcSliceH, int src_alpha, int swap, int shift, int width)
Definition: swscale_unscaled.c:613
rgb24tobgr15
void(* rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:41
shuffle_bytes_2013
void(* shuffle_bytes_2013)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:60
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:533
rgb15tobgr32
void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:268
rgb15to16
void(* rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:51
shuffle_bytes_1203
void(* shuffle_bytes_1203)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:62
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
COPY_UP
#define COPY_UP(r, w)
yuv422ptouyvy
void(* yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, int width, int height, int lumStride, int chromStride, int dstStride)
Width should be a multiple of 16.
Definition: rgb2rgb.c:77
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:132
x2rgb10to48_nobswap
void x2rgb10to48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
ALT32_CORR
#define ALT32_CORR
Definition: swscale_internal.h:57
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
rgb24tobgr24
void(* rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:39
src0
const pixel *const src0
Definition: h264pred_template.c:420
isPlanarYUV
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
Definition: vf_dnn_processing.c:162
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:552
ff_yuv2rgb_get_func_ptr
SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c)
rgb64to48_bswap
void rgb64to48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
planarRgbToplanarRgbWrapper
static int planarRgbToplanarRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1302
avutil.h
AV_PIX_FMT_X2BGR10LE
@ AV_PIX_FMT_X2BGR10LE
packed BGR 10:10:10, 30bpp, (msb)2X 10B 10G 10R(lsb), little-endian, X=unused/undefined
Definition: pixfmt.h:386
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
AV_PIX_FMT_P010LE
@ AV_PIX_FMT_P010LE
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits,...
Definition: pixfmt.h:307
bswap_16bpc
static int bswap_16bpc(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:512
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
isRGBinInt
static av_always_inline int isRGBinInt(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:798
x2rgb10to64_bswap
void x2rgb10to64_bswap(const uint8_t *src, uint8_t *dst, int src_size)
AV_PIX_FMT_GBRP14LE
@ AV_PIX_FMT_GBRP14LE
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:282
int32_t
int32_t
Definition: audioconvert.c:56
IS_NOT_NE
#define IS_NOT_NE(bpp, desc)
RGBA
#define RGBA(r, g, b, a)
Definition: dvbsubdec.c:42
ff_get_unscaled_swscale
void ff_get_unscaled_swscale(SwsInternal *c)
Set c->convert_unscaled to an unscaled converter if one exists for the specific source and destinatio...
Definition: swscale_unscaled.c:2313
planarToNv24Wrapper
static int planarToNv24Wrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dstParam[], const int dstStride[])
Definition: swscale_unscaled.c:183
AV_PIX_FMT_XV36
#define AV_PIX_FMT_XV36
Definition: pixfmt.h:560
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
planar2x
void(* planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, int srcStride, int dstStride)
Definition: rgb2rgb.c:90
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
planarRgbToRgbWrapper
static int planarRgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1246
AV_PIX_FMT_GBRAP10BE
@ AV_PIX_FMT_GBRAP10BE
planar GBR 4:4:4:4 40bpp, big-endian
Definition: pixfmt.h:313
SWS_ACCURATE_RND
@ SWS_ACCURATE_RND
Force bit-exact output.
Definition: swscale.h:155
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:508
h
h
Definition: vp9dsp_template.c:2070
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:512
isPlanar
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:896
sws_convertPalette8ToPacked32
void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
Convert an 8-bit paletted frame into a frame with a color depth of 32 bits.
Definition: swscale_unscaled.c:2609
gbr24ptopacked32
static void gbr24ptopacked32(const uint8_t *src[], const int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int alpha_first, int width)
Definition: swscale_unscaled.c:1132
width
#define width
Definition: dsp.h:85
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:484
AV_PIX_FMT_BAYER_RGGB16
#define AV_PIX_FMT_BAYER_RGGB16
Definition: pixfmt.h:528
av_bswap16
#define av_bswap16
Definition: bswap.h:28
packed24togbrap
static void packed24togbrap(const uint8_t *src, int srcStride, uint8_t *const dst[], const int dstStride[], int srcSliceH, int width)
Definition: swscale_unscaled.c:1393
rgbToRgbWrapper
static int rgbToRgbWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:1912
AV_PIX_FMT_BAYER_GRBG8
@ AV_PIX_FMT_BAYER_GRBG8
bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples
Definition: pixfmt.h:288
rgb2rgb.h
src
#define src
Definition: vp8dsp.c:248
AV_PIX_FMT_GBRAP14LE
@ AV_PIX_FMT_GBRAP14LE
planar GBR 4:4:4:4 56bpp, little-endian
Definition: pixfmt.h:433
swscale.h
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:510
isByteRGB
#define isByteRGB(f)
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3090
AV_RB16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:98
AV_PIX_FMT_BGR48BE
@ AV_PIX_FMT_BGR48BE
packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:145
rgb16tobgr15
void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:258
packedCopyWrapper
static int packedCopyWrapper(SwsInternal *c, const uint8_t *const src[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
Definition: swscale_unscaled.c:2049
AV_PIX_FMT_RGB444
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:491