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