FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/cpu.h"
31 #include "libavutil/avutil.h"
32 #include "libavutil/mathematics.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 static void 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 
143  int srcStride[], int srcSliceY,
144  int srcSliceH, uint8_t *dstParam[],
145  int dstStride[])
146 {
147  uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2;
148 
149  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
150  dstParam[0], dstStride[0]);
151 
152  if (c->dstFormat == AV_PIX_FMT_NV12)
153  interleaveBytes(src[1], src[2], dst, c->srcW / 2, srcSliceH / 2,
154  srcStride[1], srcStride[2], dstStride[1]);
155  else
156  interleaveBytes(src[2], src[1], dst, c->srcW / 2, srcSliceH / 2,
157  srcStride[2], srcStride[1], dstStride[1]);
158 
159  return srcSliceH;
160 }
161 
163  int srcStride[], int srcSliceY,
164  int srcSliceH, uint8_t *dstParam[],
165  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  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
171  dstParam[0], dstStride[0]);
172 
173  if (c->srcFormat == AV_PIX_FMT_NV12)
174  deinterleaveBytes(src[1], dst1, dst2,c->srcW / 2, srcSliceH / 2,
175  srcStride[1], dstStride[1], dstStride[2]);
176  else
177  deinterleaveBytes(src[1], dst2, dst1, c->srcW / 2, srcSliceH / 2,
178  srcStride[1], dstStride[2], dstStride[1]);
179 
180  return srcSliceH;
181 }
182 
183 static int planarToP010Wrapper(SwsContext *c, const uint8_t *src8[],
184  int srcStride[], int srcSliceY,
185  int srcSliceH, uint8_t *dstParam8[],
186  int dstStride[])
187 {
188  const uint16_t **src = (const uint16_t**)src8;
189  uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
190  uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
191  int x, y;
192 
193  av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
194  dstStride[0] % 2 || dstStride[1] % 2));
195 
196  for (y = 0; y < srcSliceH; y++) {
197  uint16_t *tdstY = dstY;
198  const uint16_t *tsrc0 = src[0];
199  for (x = c->srcW; x > 0; x--) {
200  *tdstY++ = *tsrc0++ << 6;
201  }
202  src[0] += srcStride[0] / 2;
203  dstY += dstStride[0] / 2;
204 
205  if (!(y & 1)) {
206  uint16_t *tdstUV = dstUV;
207  const uint16_t *tsrc1 = src[1];
208  const uint16_t *tsrc2 = src[2];
209  for (x = c->srcW / 2; x > 0; x--) {
210  *tdstUV++ = *tsrc1++ << 6;
211  *tdstUV++ = *tsrc2++ << 6;
212  }
213  src[1] += srcStride[1] / 2;
214  src[2] += srcStride[2] / 2;
215  dstUV += dstStride[1] / 2;
216  }
217  }
218 
219  return srcSliceH;
220 }
221 
222 #if AV_HAVE_BIGENDIAN
223 #define output_pixel(p, v) do { \
224  uint16_t *pp = (p); \
225  AV_WL16(pp, (v)); \
226  } while(0)
227 #else
228 #define output_pixel(p, v) (*p) = (v)
229 #endif
230 
232  int srcStride[], int srcSliceY,
233  int srcSliceH, uint8_t *dstParam8[],
234  int dstStride[])
235 {
236  uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
237  uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
238  int x, y, t;
239 
240  av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
241 
242  for (y = 0; y < srcSliceH; y++) {
243  uint16_t *tdstY = dstY;
244  const uint8_t *tsrc0 = src[0];
245  for (x = c->srcW; x > 0; x--) {
246  t = *tsrc0++;
247  output_pixel(tdstY++, t | (t << 8));
248  }
249  src[0] += srcStride[0];
250  dstY += dstStride[0] / 2;
251 
252  if (!(y & 1)) {
253  uint16_t *tdstUV = dstUV;
254  const uint8_t *tsrc1 = src[1];
255  const uint8_t *tsrc2 = src[2];
256  for (x = c->srcW / 2; x > 0; x--) {
257  t = *tsrc1++;
258  output_pixel(tdstUV++, t | (t << 8));
259  t = *tsrc2++;
260  output_pixel(tdstUV++, t | (t << 8));
261  }
262  src[1] += srcStride[1];
263  src[2] += srcStride[2];
264  dstUV += dstStride[1] / 2;
265  }
266  }
267 
268  return srcSliceH;
269 }
270 
271 #undef output_pixel
272 
274  int srcStride[], int srcSliceY, int srcSliceH,
275  uint8_t *dstParam[], int dstStride[])
276 {
277  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
278 
279  yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
280  srcStride[1], dstStride[0]);
281 
282  return srcSliceH;
283 }
284 
286  int srcStride[], int srcSliceY, int srcSliceH,
287  uint8_t *dstParam[], int dstStride[])
288 {
289  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
290 
291  yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
292  srcStride[1], dstStride[0]);
293 
294  return srcSliceH;
295 }
296 
298  int srcStride[], int srcSliceY, int srcSliceH,
299  uint8_t *dstParam[], int dstStride[])
300 {
301  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
302 
303  yuv422ptoyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
304  srcStride[1], dstStride[0]);
305 
306  return srcSliceH;
307 }
308 
310  int srcStride[], int srcSliceY, int srcSliceH,
311  uint8_t *dstParam[], int dstStride[])
312 {
313  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
314 
315  yuv422ptouyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
316  srcStride[1], dstStride[0]);
317 
318  return srcSliceH;
319 }
320 
322  int srcStride[], int srcSliceY, int srcSliceH,
323  uint8_t *dstParam[], int dstStride[])
324 {
325  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
326  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
327  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
328 
329  yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
330  dstStride[1], srcStride[0]);
331 
332  if (dstParam[3])
333  fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
334 
335  return srcSliceH;
336 }
337 
339  int srcStride[], int srcSliceY, int srcSliceH,
340  uint8_t *dstParam[], int dstStride[])
341 {
342  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
343  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
344  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
345 
346  yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
347  dstStride[1], srcStride[0]);
348 
349  return srcSliceH;
350 }
351 
353  int srcStride[], int srcSliceY, int srcSliceH,
354  uint8_t *dstParam[], int dstStride[])
355 {
356  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
357  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
358  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
359 
360  uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
361  dstStride[1], srcStride[0]);
362 
363  if (dstParam[3])
364  fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
365 
366  return srcSliceH;
367 }
368 
370  int srcStride[], int srcSliceY, int srcSliceH,
371  uint8_t *dstParam[], int dstStride[])
372 {
373  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
374  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
375  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
376 
377  uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
378  dstStride[1], srcStride[0]);
379 
380  return srcSliceH;
381 }
382 
383 static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels,
384  const uint8_t *palette)
385 {
386  int i;
387  for (i = 0; i < num_pixels; i++)
388  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | (src[(i << 1) + 1] << 24);
389 }
390 
391 static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels,
392  const uint8_t *palette)
393 {
394  int i;
395 
396  for (i = 0; i < num_pixels; i++)
397  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | src[(i << 1) + 1];
398 }
399 
400 static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels,
401  const uint8_t *palette)
402 {
403  int i;
404 
405  for (i = 0; i < num_pixels; i++) {
406  //FIXME slow?
407  dst[0] = palette[src[i << 1] * 4 + 0];
408  dst[1] = palette[src[i << 1] * 4 + 1];
409  dst[2] = palette[src[i << 1] * 4 + 2];
410  dst += 3;
411  }
412 }
413 
414 static int packed_16bpc_bswap(SwsContext *c, const uint8_t *src[],
415  int srcStride[], int srcSliceY, int srcSliceH,
416  uint8_t *dst[], int dstStride[])
417 {
418  int i, j, p;
419 
420  for (p = 0; p < 4; p++) {
421  int srcstr = srcStride[p] / 2;
422  int dststr = dstStride[p] / 2;
423  uint16_t *dstPtr = (uint16_t *) dst[p];
424  const uint16_t *srcPtr = (const uint16_t *) src[p];
425  int min_stride = FFMIN(FFABS(srcstr), FFABS(dststr));
426  if(!dstPtr || !srcPtr)
427  continue;
428  dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
429  for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
430  for (j = 0; j < min_stride; j++) {
431  dstPtr[j] = av_bswap16(srcPtr[j]);
432  }
433  srcPtr += srcstr;
434  dstPtr += dststr;
435  }
436  }
437 
438  return srcSliceH;
439 }
440 
441 static int palToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
442  int srcSliceY, int srcSliceH, uint8_t *dst[],
443  int dstStride[])
444 {
445  const enum AVPixelFormat srcFormat = c->srcFormat;
446  const enum AVPixelFormat dstFormat = c->dstFormat;
447  void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels,
448  const uint8_t *palette) = NULL;
449  int i;
450  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
451  const uint8_t *srcPtr = src[0];
452 
453  if (srcFormat == AV_PIX_FMT_YA8) {
454  switch (dstFormat) {
455  case AV_PIX_FMT_RGB32 : conv = gray8aToPacked32; break;
456  case AV_PIX_FMT_BGR32 : conv = gray8aToPacked32; break;
459  case AV_PIX_FMT_RGB24 : conv = gray8aToPacked24; break;
460  case AV_PIX_FMT_BGR24 : conv = gray8aToPacked24; break;
461  }
462  } else if (usePal(srcFormat)) {
463  switch (dstFormat) {
470  }
471  }
472 
473  if (!conv)
474  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
475  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
476  else {
477  for (i = 0; i < srcSliceH; i++) {
478  conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb);
479  srcPtr += srcStride[0];
480  dstPtr += dstStride[0];
481  }
482  }
483 
484  return srcSliceH;
485 }
486 
487 static void packed16togbra16(const uint8_t *src, int srcStride,
488  uint16_t *dst[], int dstStride[], int srcSliceH,
489  int src_alpha, int swap, int shift, int width)
490 {
491  int x, h, i;
492  int dst_alpha = dst[3] != NULL;
493  for (h = 0; h < srcSliceH; h++) {
494  uint16_t *src_line = (uint16_t *)(src + srcStride * h);
495  switch (swap) {
496  case 3:
497  if (src_alpha && dst_alpha) {
498  for (x = 0; x < width; x++) {
499  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
500  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
501  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
502  dst[3][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
503  }
504  } else if (dst_alpha) {
505  for (x = 0; x < width; x++) {
506  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
507  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
508  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
509  dst[3][x] = 0xFFFF;
510  }
511  } else if (src_alpha) {
512  for (x = 0; x < width; x++) {
513  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
514  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
515  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
516  src_line++;
517  }
518  } else {
519  for (x = 0; x < width; x++) {
520  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
521  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
522  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
523  }
524  }
525  break;
526  case 2:
527  if (src_alpha && dst_alpha) {
528  for (x = 0; x < width; x++) {
529  dst[0][x] = av_bswap16(*src_line++ >> shift);
530  dst[1][x] = av_bswap16(*src_line++ >> shift);
531  dst[2][x] = av_bswap16(*src_line++ >> shift);
532  dst[3][x] = av_bswap16(*src_line++ >> shift);
533  }
534  } else if (dst_alpha) {
535  for (x = 0; x < width; x++) {
536  dst[0][x] = av_bswap16(*src_line++ >> shift);
537  dst[1][x] = av_bswap16(*src_line++ >> shift);
538  dst[2][x] = av_bswap16(*src_line++ >> shift);
539  dst[3][x] = 0xFFFF;
540  }
541  } else if (src_alpha) {
542  for (x = 0; x < width; x++) {
543  dst[0][x] = av_bswap16(*src_line++ >> shift);
544  dst[1][x] = av_bswap16(*src_line++ >> shift);
545  dst[2][x] = av_bswap16(*src_line++ >> shift);
546  src_line++;
547  }
548  } else {
549  for (x = 0; x < width; x++) {
550  dst[0][x] = av_bswap16(*src_line++ >> shift);
551  dst[1][x] = av_bswap16(*src_line++ >> shift);
552  dst[2][x] = av_bswap16(*src_line++ >> shift);
553  }
554  }
555  break;
556  case 1:
557  if (src_alpha && dst_alpha) {
558  for (x = 0; x < width; x++) {
559  dst[0][x] = av_bswap16(*src_line++) >> shift;
560  dst[1][x] = av_bswap16(*src_line++) >> shift;
561  dst[2][x] = av_bswap16(*src_line++) >> shift;
562  dst[3][x] = av_bswap16(*src_line++) >> shift;
563  }
564  } else if (dst_alpha) {
565  for (x = 0; x < width; x++) {
566  dst[0][x] = av_bswap16(*src_line++) >> shift;
567  dst[1][x] = av_bswap16(*src_line++) >> shift;
568  dst[2][x] = av_bswap16(*src_line++) >> shift;
569  dst[3][x] = 0xFFFF;
570  }
571  } else if (src_alpha) {
572  for (x = 0; x < width; x++) {
573  dst[0][x] = av_bswap16(*src_line++) >> shift;
574  dst[1][x] = av_bswap16(*src_line++) >> shift;
575  dst[2][x] = av_bswap16(*src_line++) >> shift;
576  src_line++;
577  }
578  } else {
579  for (x = 0; x < width; x++) {
580  dst[0][x] = av_bswap16(*src_line++) >> shift;
581  dst[1][x] = av_bswap16(*src_line++) >> shift;
582  dst[2][x] = av_bswap16(*src_line++) >> shift;
583  }
584  }
585  break;
586  default:
587  if (src_alpha && dst_alpha) {
588  for (x = 0; x < width; x++) {
589  dst[0][x] = *src_line++ >> shift;
590  dst[1][x] = *src_line++ >> shift;
591  dst[2][x] = *src_line++ >> shift;
592  dst[3][x] = *src_line++ >> shift;
593  }
594  } else if (dst_alpha) {
595  for (x = 0; x < width; x++) {
596  dst[0][x] = *src_line++ >> shift;
597  dst[1][x] = *src_line++ >> shift;
598  dst[2][x] = *src_line++ >> shift;
599  dst[3][x] = 0xFFFF;
600  }
601  } else if (src_alpha) {
602  for (x = 0; x < width; x++) {
603  dst[0][x] = *src_line++ >> shift;
604  dst[1][x] = *src_line++ >> shift;
605  dst[2][x] = *src_line++ >> shift;
606  src_line++;
607  }
608  } else {
609  for (x = 0; x < width; x++) {
610  dst[0][x] = *src_line++ >> shift;
611  dst[1][x] = *src_line++ >> shift;
612  dst[2][x] = *src_line++ >> shift;
613  }
614  }
615  }
616  for (i = 0; i < 4; i++)
617  dst[i] += dstStride[i] >> 1;
618  }
619 }
620 
622  int srcStride[], int srcSliceY, int srcSliceH,
623  uint8_t *dst[], int dstStride[])
624 {
625  uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
626  uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
627  int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
628  int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
629  const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
630  const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
631  int bpc = dst_format->comp[0].depth;
632  int alpha = src_format->flags & AV_PIX_FMT_FLAG_ALPHA;
633  int swap = 0;
634  int i;
635 
636  if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
637  !HAVE_BIGENDIAN && src_format->flags & AV_PIX_FMT_FLAG_BE)
638  swap++;
639  if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
640  !HAVE_BIGENDIAN && dst_format->flags & AV_PIX_FMT_FLAG_BE)
641  swap += 2;
642 
643  if ((dst_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
645  av_log(c, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n",
646  src_format->name, dst_format->name);
647  return srcSliceH;
648  }
649 
650  for(i=0; i<4; i++) {
651  dst2013[i] += stride2013[i] * srcSliceY / 2;
652  dst1023[i] += stride1023[i] * srcSliceY / 2;
653  }
654 
655  switch (c->srcFormat) {
656  case AV_PIX_FMT_RGB48LE:
657  case AV_PIX_FMT_RGB48BE:
658  case AV_PIX_FMT_RGBA64LE:
659  case AV_PIX_FMT_RGBA64BE:
660  packed16togbra16(src[0], srcStride[0],
661  dst2013, stride2013, srcSliceH, alpha, swap,
662  16 - bpc, c->srcW);
663  break;
664  case AV_PIX_FMT_BGR48LE:
665  case AV_PIX_FMT_BGR48BE:
666  case AV_PIX_FMT_BGRA64LE:
667  case AV_PIX_FMT_BGRA64BE:
668  packed16togbra16(src[0], srcStride[0],
669  dst1023, stride1023, srcSliceH, alpha, swap,
670  16 - bpc, c->srcW);
671  break;
672  default:
673  av_log(c, AV_LOG_ERROR,
674  "unsupported conversion to planar RGB %s -> %s\n",
675  src_format->name, dst_format->name);
676  }
677 
678  return srcSliceH;
679 }
680 
681 static void gbr16ptopacked16(const uint16_t *src[], int srcStride[],
682  uint8_t *dst, int dstStride, int srcSliceH,
683  int alpha, int swap, int bpp, int width)
684 {
685  int x, h, i;
686  int src_alpha = src[3] != NULL;
687  int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
688  for (h = 0; h < srcSliceH; h++) {
689  uint16_t *dest = (uint16_t *)(dst + dstStride * h);
690  uint16_t component;
691 
692  switch(swap) {
693  case 3:
694  if (alpha && !src_alpha) {
695  for (x = 0; x < width; x++) {
696  component = av_bswap16(src[0][x]);
697  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
698  component = av_bswap16(src[1][x]);
699  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
700  component = av_bswap16(src[2][x]);
701  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
702  *dest++ = 0xffff;
703  }
704  } else if (alpha && src_alpha) {
705  for (x = 0; x < width; x++) {
706  component = av_bswap16(src[0][x]);
707  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
708  component = av_bswap16(src[1][x]);
709  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
710  component = av_bswap16(src[2][x]);
711  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
712  component = av_bswap16(src[3][x]);
713  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
714  }
715  } else {
716  for (x = 0; x < width; x++) {
717  component = av_bswap16(src[0][x]);
718  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
719  component = av_bswap16(src[1][x]);
720  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
721  component = av_bswap16(src[2][x]);
722  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
723  }
724  }
725  break;
726  case 2:
727  if (alpha && !src_alpha) {
728  for (x = 0; x < width; x++) {
729  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
730  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
731  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
732  *dest++ = 0xffff;
733  }
734  } else if (alpha && src_alpha) {
735  for (x = 0; x < width; x++) {
736  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
737  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
738  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
739  *dest++ = av_bswap16(src[3][x] << scale_high | src[3][x] >> scale_low);
740  }
741  } else {
742  for (x = 0; x < width; x++) {
743  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
744  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
745  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
746  }
747  }
748  break;
749  case 1:
750  if (alpha && !src_alpha) {
751  for (x = 0; x < width; x++) {
752  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
753  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
754  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
755  *dest++ = 0xffff;
756  }
757  } else if (alpha && src_alpha) {
758  for (x = 0; x < width; x++) {
759  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
760  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
761  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
762  *dest++ = av_bswap16(src[3][x]) << scale_high | av_bswap16(src[3][x]) >> scale_low;
763  }
764  } else {
765  for (x = 0; x < width; x++) {
766  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
767  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
768  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
769  }
770  }
771  break;
772  default:
773  if (alpha && !src_alpha) {
774  for (x = 0; x < width; x++) {
775  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
776  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
777  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
778  *dest++ = 0xffff;
779  }
780  } else if (alpha && src_alpha) {
781  for (x = 0; x < width; x++) {
782  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
783  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
784  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
785  *dest++ = src[3][x] << scale_high | src[3][x] >> scale_low;
786  }
787  } else {
788  for (x = 0; x < width; x++) {
789  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
790  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
791  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
792  }
793  }
794  }
795  for (i = 0; i < 3 + src_alpha; i++)
796  src[i] += srcStride[i] >> 1;
797  }
798 }
799 
801  int srcStride[], int srcSliceY, int srcSliceH,
802  uint8_t *dst[], int dstStride[])
803 {
804  const uint16_t *src102[] = { (uint16_t *)src[1], (uint16_t *)src[0], (uint16_t *)src[2], (uint16_t *)src[3] };
805  const uint16_t *src201[] = { (uint16_t *)src[2], (uint16_t *)src[0], (uint16_t *)src[1], (uint16_t *)src[3] };
806  int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
807  int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
808  const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
809  const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
810  int bits_per_sample = src_format->comp[0].depth;
811  int swap = 0;
812  if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
813  !HAVE_BIGENDIAN && src_format->flags & AV_PIX_FMT_FLAG_BE)
814  swap++;
815  if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
816  !HAVE_BIGENDIAN && dst_format->flags & AV_PIX_FMT_FLAG_BE)
817  swap += 2;
818 
819  if ((src_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
821  bits_per_sample <= 8) {
822  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
823  src_format->name, dst_format->name);
824  return srcSliceH;
825  }
826  switch (c->dstFormat) {
827  case AV_PIX_FMT_BGR48LE:
828  case AV_PIX_FMT_BGR48BE:
829  gbr16ptopacked16(src102, stride102,
830  dst[0] + srcSliceY * dstStride[0], dstStride[0],
831  srcSliceH, 0, swap, bits_per_sample, c->srcW);
832  break;
833  case AV_PIX_FMT_RGB48LE:
834  case AV_PIX_FMT_RGB48BE:
835  gbr16ptopacked16(src201, stride201,
836  dst[0] + srcSliceY * dstStride[0], dstStride[0],
837  srcSliceH, 0, swap, bits_per_sample, c->srcW);
838  break;
839  case AV_PIX_FMT_RGBA64LE:
840  case AV_PIX_FMT_RGBA64BE:
841  gbr16ptopacked16(src201, stride201,
842  dst[0] + srcSliceY * dstStride[0], dstStride[0],
843  srcSliceH, 1, swap, bits_per_sample, c->srcW);
844  break;
845  case AV_PIX_FMT_BGRA64LE:
846  case AV_PIX_FMT_BGRA64BE:
847  gbr16ptopacked16(src102, stride102,
848  dst[0] + srcSliceY * dstStride[0], dstStride[0],
849  srcSliceH, 1, swap, bits_per_sample, c->srcW);
850  break;
851  default:
852  av_log(c, AV_LOG_ERROR,
853  "unsupported planar RGB conversion %s -> %s\n",
854  src_format->name, dst_format->name);
855  }
856 
857  return srcSliceH;
858 }
859 
860 static void gbr24ptopacked24(const uint8_t *src[], int srcStride[],
861  uint8_t *dst, int dstStride, int srcSliceH,
862  int width)
863 {
864  int x, h, i;
865  for (h = 0; h < srcSliceH; h++) {
866  uint8_t *dest = dst + dstStride * h;
867  for (x = 0; x < width; x++) {
868  *dest++ = src[0][x];
869  *dest++ = src[1][x];
870  *dest++ = src[2][x];
871  }
872 
873  for (i = 0; i < 3; i++)
874  src[i] += srcStride[i];
875  }
876 }
877 
878 static void gbr24ptopacked32(const uint8_t *src[], int srcStride[],
879  uint8_t *dst, int dstStride, int srcSliceH,
880  int alpha_first, int width)
881 {
882  int x, h, i;
883  for (h = 0; h < srcSliceH; h++) {
884  uint8_t *dest = dst + dstStride * h;
885 
886  if (alpha_first) {
887  for (x = 0; x < width; x++) {
888  *dest++ = 0xff;
889  *dest++ = src[0][x];
890  *dest++ = src[1][x];
891  *dest++ = src[2][x];
892  }
893  } else {
894  for (x = 0; x < width; x++) {
895  *dest++ = src[0][x];
896  *dest++ = src[1][x];
897  *dest++ = src[2][x];
898  *dest++ = 0xff;
899  }
900  }
901 
902  for (i = 0; i < 3; i++)
903  src[i] += srcStride[i];
904  }
905 }
906 
908  int srcStride[], int srcSliceY, int srcSliceH,
909  uint8_t *dst[], int dstStride[])
910 {
911  int alpha_first = 0;
912  const uint8_t *src102[] = { src[1], src[0], src[2] };
913  const uint8_t *src201[] = { src[2], src[0], src[1] };
914  int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
915  int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
916 
917  if (c->srcFormat != AV_PIX_FMT_GBRP) {
918  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
921  return srcSliceH;
922  }
923 
924  switch (c->dstFormat) {
925  case AV_PIX_FMT_BGR24:
926  gbr24ptopacked24(src102, stride102,
927  dst[0] + srcSliceY * dstStride[0], dstStride[0],
928  srcSliceH, c->srcW);
929  break;
930 
931  case AV_PIX_FMT_RGB24:
932  gbr24ptopacked24(src201, stride201,
933  dst[0] + srcSliceY * dstStride[0], dstStride[0],
934  srcSliceH, c->srcW);
935  break;
936 
937  case AV_PIX_FMT_ARGB:
938  alpha_first = 1;
939  case AV_PIX_FMT_RGBA:
940  gbr24ptopacked32(src201, stride201,
941  dst[0] + srcSliceY * dstStride[0], dstStride[0],
942  srcSliceH, alpha_first, c->srcW);
943  break;
944 
945  case AV_PIX_FMT_ABGR:
946  alpha_first = 1;
947  case AV_PIX_FMT_BGRA:
948  gbr24ptopacked32(src102, stride102,
949  dst[0] + srcSliceY * dstStride[0], dstStride[0],
950  srcSliceH, alpha_first, c->srcW);
951  break;
952 
953  default:
954  av_log(c, AV_LOG_ERROR,
955  "unsupported planar RGB conversion %s -> %s\n",
958  }
959 
960  return srcSliceH;
961 }
962 
964  const uint8_t *src[], int srcStride[],
965  int srcSliceY, int srcSliceH,
966  uint8_t *dst[], int dstStride[])
967 {
968  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
969  dst[0], dstStride[0]);
970  copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->srcW,
971  dst[1], dstStride[1]);
972  copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->srcW,
973  dst[2], dstStride[2]);
974  if (dst[3])
975  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
976 
977  return srcSliceH;
978 }
979 
980 static void packedtogbr24p(const uint8_t *src, int srcStride,
981  uint8_t *dst[], int dstStride[], int srcSliceH,
982  int alpha_first, int inc_size, int width)
983 {
984  uint8_t *dest[3];
985  int x, h;
986 
987  dest[0] = dst[0];
988  dest[1] = dst[1];
989  dest[2] = dst[2];
990 
991  if (alpha_first)
992  src++;
993 
994  for (h = 0; h < srcSliceH; h++) {
995  for (x = 0; x < width; x++) {
996  dest[0][x] = src[0];
997  dest[1][x] = src[1];
998  dest[2][x] = src[2];
999 
1000  src += inc_size;
1001  }
1002  src += srcStride - width * inc_size;
1003  dest[0] += dstStride[0];
1004  dest[1] += dstStride[1];
1005  dest[2] += dstStride[2];
1006  }
1007 }
1008 
1010  int srcStride[], int srcSliceY, int srcSliceH,
1011  uint8_t *dst[], int dstStride[])
1012 {
1013  int alpha_first = 0;
1014  int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1015  int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1016  uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
1017  dst[0] + srcSliceY * dstStride[0],
1018  dst[2] + srcSliceY * dstStride[2] };
1019  uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
1020  dst[0] + srcSliceY * dstStride[0],
1021  dst[1] + srcSliceY * dstStride[1] };
1022 
1023  switch (c->srcFormat) {
1024  case AV_PIX_FMT_RGB24:
1025  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
1026  stride201, srcSliceH, alpha_first, 3, c->srcW);
1027  break;
1028  case AV_PIX_FMT_BGR24:
1029  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
1030  stride102, srcSliceH, alpha_first, 3, c->srcW);
1031  break;
1032  case AV_PIX_FMT_ARGB:
1033  alpha_first = 1;
1034  case AV_PIX_FMT_RGBA:
1035  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
1036  stride201, srcSliceH, alpha_first, 4, c->srcW);
1037  break;
1038  case AV_PIX_FMT_ABGR:
1039  alpha_first = 1;
1040  case AV_PIX_FMT_BGRA:
1041  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
1042  stride102, srcSliceH, alpha_first, 4, c->srcW);
1043  break;
1044  default:
1045  av_log(c, AV_LOG_ERROR,
1046  "unsupported planar RGB conversion %s -> %s\n",
1049  }
1050 
1051  return srcSliceH;
1052 }
1053 
1054 #define BAYER_GBRG
1055 #define BAYER_8
1056 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1057 #include "bayer_template.c"
1058 
1059 #define BAYER_GBRG
1060 #define BAYER_16LE
1061 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1062 #include "bayer_template.c"
1063 
1064 #define BAYER_GBRG
1065 #define BAYER_16BE
1066 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1067 #include "bayer_template.c"
1068 
1069 #define BAYER_GRBG
1070 #define BAYER_8
1071 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1072 #include "bayer_template.c"
1073 
1074 #define BAYER_GRBG
1075 #define BAYER_16LE
1076 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1077 #include "bayer_template.c"
1078 
1079 #define BAYER_GRBG
1080 #define BAYER_16BE
1081 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1082 #include "bayer_template.c"
1083 
1084 #define BAYER_BGGR
1085 #define BAYER_8
1086 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1087 #include "bayer_template.c"
1088 
1089 #define BAYER_BGGR
1090 #define BAYER_16LE
1091 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1092 #include "bayer_template.c"
1093 
1094 #define BAYER_BGGR
1095 #define BAYER_16BE
1096 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1097 #include "bayer_template.c"
1098 
1099 #define BAYER_RGGB
1100 #define BAYER_8
1101 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1102 #include "bayer_template.c"
1103 
1104 #define BAYER_RGGB
1105 #define BAYER_16LE
1106 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1107 #include "bayer_template.c"
1108 
1109 #define BAYER_RGGB
1110 #define BAYER_16BE
1111 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1112 #include "bayer_template.c"
1113 
1114 static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
1115  int srcSliceH, uint8_t* dst[], int dstStride[])
1116 {
1117  uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1118  const uint8_t *srcPtr= src[0];
1119  int i;
1120  void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1121  void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1122 
1123  switch(c->srcFormat) {
1124 #define CASE(pixfmt, prefix) \
1125  case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1126  interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1127  break;
1129  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1130  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1132  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1133  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1135  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1136  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1138  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1139  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1140 #undef CASE
1141  default: return 0;
1142  }
1143 
1144  av_assert0(srcSliceH > 1);
1145 
1146  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1147  srcPtr += 2 * srcStride[0];
1148  dstPtr += 2 * dstStride[0];
1149 
1150  for (i = 2; i < srcSliceH - 2; i += 2) {
1151  interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1152  srcPtr += 2 * srcStride[0];
1153  dstPtr += 2 * dstStride[0];
1154  }
1155 
1156  if (i + 1 == srcSliceH) {
1157  copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->srcW);
1158  } else if (i < srcSliceH)
1159  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1160  return srcSliceH;
1161 }
1162 
1163 static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
1164  int srcSliceH, uint8_t* dst[], int dstStride[])
1165 {
1166  const uint8_t *srcPtr= src[0];
1167  uint8_t *dstY= dst[0] + srcSliceY * dstStride[0];
1168  uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
1169  uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
1170  int i;
1171  void (*copy) (const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, int32_t *rgb2yuv);
1172  void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dstY, uint8_t *dstU, uint8_t *dstV, int luma_stride, int width, int32_t *rgb2yuv);
1173 
1174  switch(c->srcFormat) {
1175 #define CASE(pixfmt, prefix) \
1176  case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1177  interpolate = bayer_##prefix##_to_yv12_interpolate; \
1178  break;
1180  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1181  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1183  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1184  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1186  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1187  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1189  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1190  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1191 #undef CASE
1192  default: return 0;
1193  }
1194 
1195  av_assert0(srcSliceH > 1);
1196 
1197  copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1198  srcPtr += 2 * srcStride[0];
1199  dstY += 2 * dstStride[0];
1200  dstU += dstStride[1];
1201  dstV += dstStride[1];
1202 
1203  for (i = 2; i < srcSliceH - 2; i += 2) {
1204  interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1205  srcPtr += 2 * srcStride[0];
1206  dstY += 2 * dstStride[0];
1207  dstU += dstStride[1];
1208  dstV += dstStride[1];
1209  }
1210 
1211  if (i + 1 == srcSliceH) {
1212  copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0], c->srcW, c->input_rgb2yuv_table);
1213  } else if (i < srcSliceH)
1214  copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1215  return srcSliceH;
1216 }
1217 
1218 #define isRGBA32(x) ( \
1219  (x) == AV_PIX_FMT_ARGB \
1220  || (x) == AV_PIX_FMT_RGBA \
1221  || (x) == AV_PIX_FMT_BGRA \
1222  || (x) == AV_PIX_FMT_ABGR \
1223  )
1224 
1225 #define isRGBA64(x) ( \
1226  (x) == AV_PIX_FMT_RGBA64LE \
1227  || (x) == AV_PIX_FMT_RGBA64BE \
1228  || (x) == AV_PIX_FMT_BGRA64LE \
1229  || (x) == AV_PIX_FMT_BGRA64BE \
1230  )
1231 
1232 #define isRGB48(x) ( \
1233  (x) == AV_PIX_FMT_RGB48LE \
1234  || (x) == AV_PIX_FMT_RGB48BE \
1235  || (x) == AV_PIX_FMT_BGR48LE \
1236  || (x) == AV_PIX_FMT_BGR48BE \
1237  )
1238 
1239 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
1240 typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int);
1242 {
1243  const enum AVPixelFormat srcFormat = c->srcFormat;
1244  const enum AVPixelFormat dstFormat = c->dstFormat;
1245  const int srcId = c->srcFormatBpp;
1246  const int dstId = c->dstFormatBpp;
1247  rgbConvFn conv = NULL;
1248 
1249 #define IS_NOT_NE(bpp, desc) \
1250  (((bpp + 7) >> 3) == 2 && \
1251  (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1252 
1253 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1254 
1255  if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) {
1256  if ( CONV_IS(ABGR, RGBA)
1257  || CONV_IS(ARGB, BGRA)
1258  || CONV_IS(BGRA, ARGB)
1259  || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210;
1260  else if (CONV_IS(ABGR, ARGB)
1261  || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321;
1262  else if (CONV_IS(ABGR, BGRA)
1263  || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230;
1264  else if (CONV_IS(BGRA, RGBA)
1265  || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103;
1266  else if (CONV_IS(BGRA, ABGR)
1267  || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012;
1268  } else if (isRGB48(srcFormat) && isRGB48(dstFormat)) {
1269  if (CONV_IS(RGB48LE, BGR48LE)
1270  || CONV_IS(BGR48LE, RGB48LE)
1271  || CONV_IS(RGB48BE, BGR48BE)
1272  || CONV_IS(BGR48BE, RGB48BE)) conv = rgb48tobgr48_nobswap;
1273  else if (CONV_IS(RGB48LE, BGR48BE)
1274  || CONV_IS(BGR48LE, RGB48BE)
1275  || CONV_IS(RGB48BE, BGR48LE)
1276  || CONV_IS(BGR48BE, RGB48LE)) conv = rgb48tobgr48_bswap;
1277  } else if (isRGB48(srcFormat) && isRGBA64(dstFormat)) {
1278  if (CONV_IS(RGB48LE, BGRA64LE)
1279  || CONV_IS(BGR48LE, RGBA64LE)
1280  || CONV_IS(RGB48BE, BGRA64BE)
1281  || CONV_IS(BGR48BE, RGBA64BE)) conv = rgb48tobgr64_nobswap;
1282  else if (CONV_IS(RGB48LE, BGRA64BE)
1283  || CONV_IS(BGR48LE, RGBA64BE)
1284  || CONV_IS(RGB48BE, BGRA64LE)
1285  || CONV_IS(BGR48BE, RGBA64LE)) conv = rgb48tobgr64_bswap;
1286  if (CONV_IS(RGB48LE, RGBA64LE)
1287  || CONV_IS(BGR48LE, BGRA64LE)
1288  || CONV_IS(RGB48BE, RGBA64BE)
1289  || CONV_IS(BGR48BE, BGRA64BE)) conv = rgb48to64_nobswap;
1290  else if (CONV_IS(RGB48LE, RGBA64BE)
1291  || CONV_IS(BGR48LE, BGRA64BE)
1292  || CONV_IS(RGB48BE, RGBA64LE)
1293  || CONV_IS(BGR48BE, BGRA64LE)) conv = rgb48to64_bswap;
1294  } else if (isRGBA64(srcFormat) && isRGB48(dstFormat)) {
1295  if (CONV_IS(RGBA64LE, BGR48LE)
1296  || CONV_IS(BGRA64LE, RGB48LE)
1297  || CONV_IS(RGBA64BE, BGR48BE)
1298  || CONV_IS(BGRA64BE, RGB48BE)) conv = rgb64tobgr48_nobswap;
1299  else if (CONV_IS(RGBA64LE, BGR48BE)
1300  || CONV_IS(BGRA64LE, RGB48BE)
1301  || CONV_IS(RGBA64BE, BGR48LE)
1302  || CONV_IS(BGRA64BE, RGB48LE)) conv = rgb64tobgr48_bswap;
1303  else if (CONV_IS(RGBA64LE, RGB48LE)
1304  || CONV_IS(BGRA64LE, BGR48LE)
1305  || CONV_IS(RGBA64BE, RGB48BE)
1306  || CONV_IS(BGRA64BE, BGR48BE)) conv = rgb64to48_nobswap;
1307  else if (CONV_IS(RGBA64LE, RGB48BE)
1308  || CONV_IS(BGRA64LE, BGR48BE)
1309  || CONV_IS(RGBA64BE, RGB48LE)
1310  || CONV_IS(BGRA64BE, BGR48LE)) conv = rgb64to48_bswap;
1311  } else
1312  /* BGR -> BGR */
1313  if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
1314  (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) {
1315  switch (srcId | (dstId << 16)) {
1316  case 0x000F000C: conv = rgb12to15; break;
1317  case 0x000F0010: conv = rgb16to15; break;
1318  case 0x000F0018: conv = rgb24to15; break;
1319  case 0x000F0020: conv = rgb32to15; break;
1320  case 0x0010000F: conv = rgb15to16; break;
1321  case 0x00100018: conv = rgb24to16; break;
1322  case 0x00100020: conv = rgb32to16; break;
1323  case 0x0018000F: conv = rgb15to24; break;
1324  case 0x00180010: conv = rgb16to24; break;
1325  case 0x00180020: conv = rgb32to24; break;
1326  case 0x0020000F: conv = rgb15to32; break;
1327  case 0x00200010: conv = rgb16to32; break;
1328  case 0x00200018: conv = rgb24to32; break;
1329  }
1330  } else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) ||
1331  (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) {
1332  switch (srcId | (dstId << 16)) {
1333  case 0x000C000C: conv = rgb12tobgr12; break;
1334  case 0x000F000F: conv = rgb15tobgr15; break;
1335  case 0x000F0010: conv = rgb16tobgr15; break;
1336  case 0x000F0018: conv = rgb24tobgr15; break;
1337  case 0x000F0020: conv = rgb32tobgr15; break;
1338  case 0x0010000F: conv = rgb15tobgr16; break;
1339  case 0x00100010: conv = rgb16tobgr16; break;
1340  case 0x00100018: conv = rgb24tobgr16; break;
1341  case 0x00100020: conv = rgb32tobgr16; break;
1342  case 0x0018000F: conv = rgb15tobgr24; break;
1343  case 0x00180010: conv = rgb16tobgr24; break;
1344  case 0x00180018: conv = rgb24tobgr24; break;
1345  case 0x00180020: conv = rgb32tobgr24; break;
1346  case 0x0020000F: conv = rgb15tobgr32; break;
1347  case 0x00200010: conv = rgb16tobgr32; break;
1348  case 0x00200018: conv = rgb24tobgr32; break;
1349  }
1350  }
1351 
1352  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) && !isRGBA32(srcFormat) && ALT32_CORR<0)
1353  return NULL;
1354 
1355  // Maintain symmetry between endianness
1356  if (c->flags & SWS_BITEXACT)
1357  if ((dstFormat == AV_PIX_FMT_RGB32 || dstFormat == AV_PIX_FMT_BGR32 ) && !isRGBA32(srcFormat) && ALT32_CORR>0)
1358  return NULL;
1359 
1360  return conv;
1361 }
1362 
1363 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
1364 static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
1365  int srcSliceY, int srcSliceH, uint8_t *dst[],
1366  int dstStride[])
1367 
1368 {
1369  const enum AVPixelFormat srcFormat = c->srcFormat;
1370  const enum AVPixelFormat dstFormat = c->dstFormat;
1371  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
1372  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
1373  const int srcBpp = (c->srcFormatBpp + 7) >> 3;
1374  const int dstBpp = (c->dstFormatBpp + 7) >> 3;
1376 
1377  if (!conv) {
1378  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
1379  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1380  } else {
1381  const uint8_t *srcPtr = src[0];
1382  uint8_t *dstPtr = dst[0];
1383  int src_bswap = IS_NOT_NE(c->srcFormatBpp, desc_src);
1384  int dst_bswap = IS_NOT_NE(c->dstFormatBpp, desc_dst);
1385 
1386  if ((srcFormat == AV_PIX_FMT_RGB32_1 || srcFormat == AV_PIX_FMT_BGR32_1) &&
1387  !isRGBA32(dstFormat))
1388  srcPtr += ALT32_CORR;
1389 
1390  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) &&
1391  !isRGBA32(srcFormat)) {
1392  int i;
1393  av_assert0(ALT32_CORR == 1);
1394  for (i = 0; i < srcSliceH; i++)
1395  dstPtr[dstStride[0] * (srcSliceY + i)] = 255;
1396  dstPtr += ALT32_CORR;
1397  }
1398 
1399  if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1400  !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1401  conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1402  (srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp);
1403  else {
1404  int i, j;
1405  dstPtr += dstStride[0] * srcSliceY;
1406 
1407  for (i = 0; i < srcSliceH; i++) {
1408  if(src_bswap) {
1409  for(j=0; j<c->srcW; j++)
1410  ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]);
1411  conv(c->formatConvBuffer, dstPtr, c->srcW * srcBpp);
1412  }else
1413  conv(srcPtr, dstPtr, c->srcW * srcBpp);
1414  if(dst_bswap)
1415  for(j=0; j<c->srcW; j++)
1416  ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]);
1417  srcPtr += srcStride[0];
1418  dstPtr += dstStride[0];
1419  }
1420  }
1421  }
1422  return srcSliceH;
1423 }
1424 
1426  int srcStride[], int srcSliceY, int srcSliceH,
1427  uint8_t *dst[], int dstStride[])
1428 {
1430  src[0],
1431  dst[0] + srcSliceY * dstStride[0],
1432  dst[1] + (srcSliceY >> 1) * dstStride[1],
1433  dst[2] + (srcSliceY >> 1) * dstStride[2],
1434  c->srcW, srcSliceH,
1435  dstStride[0], dstStride[1], srcStride[0],
1436  c->input_rgb2yuv_table);
1437  if (dst[3])
1438  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
1439  return srcSliceH;
1440 }
1441 
1442 static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
1443  int srcStride[], int srcSliceY, int srcSliceH,
1444  uint8_t *dst[], int dstStride[])
1445 {
1446  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
1447  dst[0], dstStride[0]);
1448 
1449  planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW,
1450  srcSliceH >> 2, srcStride[1], dstStride[1]);
1451  planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW,
1452  srcSliceH >> 2, srcStride[2], dstStride[2]);
1453  if (dst[3])
1454  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
1455  return srcSliceH;
1456 }
1457 
1458 /* unscaled copy like stuff (assumes nearly identical formats) */
1459 static int packedCopyWrapper(SwsContext *c, const uint8_t *src[],
1460  int srcStride[], int srcSliceY, int srcSliceH,
1461  uint8_t *dst[], int dstStride[])
1462 {
1463  if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
1464  memcpy(dst[0] + dstStride[0] * srcSliceY, src[0], srcSliceH * dstStride[0]);
1465  else {
1466  int i;
1467  const uint8_t *srcPtr = src[0];
1468  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1469  int length = 0;
1470 
1471  /* universal length finder */
1472  while (length + c->srcW <= FFABS(dstStride[0]) &&
1473  length + c->srcW <= FFABS(srcStride[0]))
1474  length += c->srcW;
1475  av_assert1(length != 0);
1476 
1477  for (i = 0; i < srcSliceH; i++) {
1478  memcpy(dstPtr, srcPtr, length);
1479  srcPtr += srcStride[0];
1480  dstPtr += dstStride[0];
1481  }
1482  }
1483  return srcSliceH;
1484 }
1485 
1486 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
1487  unsigned shift= src_depth-dst_depth, tmp;\
1488  if (c->dither == SWS_DITHER_NONE) {\
1489  for (i = 0; i < height; i++) {\
1490  for (j = 0; j < length-7; j+=8) {\
1491  dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
1492  dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
1493  dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
1494  dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
1495  dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
1496  dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
1497  dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
1498  dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
1499  }\
1500  for (; j < length; j++) {\
1501  dst[j] = dbswap(bswap(src[j])>>shift);\
1502  }\
1503  dst += dstStride;\
1504  src += srcStride;\
1505  }\
1506  } else if (shiftonly) {\
1507  for (i = 0; i < height; i++) {\
1508  const uint8_t *dither= dithers[shift-1][i&7];\
1509  for (j = 0; j < length-7; j+=8) {\
1510  tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
1511  tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
1512  tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
1513  tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
1514  tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
1515  tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
1516  tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
1517  tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
1518  }\
1519  for (; j < length; j++) {\
1520  tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
1521  }\
1522  dst += dstStride;\
1523  src += srcStride;\
1524  }\
1525  } else {\
1526  for (i = 0; i < height; i++) {\
1527  const uint8_t *dither= dithers[shift-1][i&7];\
1528  for (j = 0; j < length-7; j+=8) {\
1529  tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
1530  tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
1531  tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
1532  tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
1533  tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
1534  tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
1535  tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
1536  tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
1537  }\
1538  for (; j < length; j++) {\
1539  tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
1540  }\
1541  dst += dstStride;\
1542  src += srcStride;\
1543  }\
1544  }
1545 
1546 static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
1547  int srcStride[], int srcSliceY, int srcSliceH,
1548  uint8_t *dst[], int dstStride[])
1549 {
1550  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
1551  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
1552  int plane, i, j;
1553  for (plane = 0; plane < 4; plane++) {
1554  int length = (plane == 0 || plane == 3) ? c->srcW : AV_CEIL_RSHIFT(c->srcW, c->chrDstHSubSample);
1555  int y = (plane == 0 || plane == 3) ? srcSliceY: AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
1556  int height = (plane == 0 || plane == 3) ? srcSliceH: AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
1557  const uint8_t *srcPtr = src[plane];
1558  uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
1559  int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0);
1560 
1561  if (!dst[plane])
1562  continue;
1563  // ignore palette for GRAY8
1564  if (plane == 1 && !dst[2]) continue;
1565  if (!src[plane] || (plane == 1 && !src[2])) {
1566  if (is16BPS(c->dstFormat) || isNBPS(c->dstFormat)) {
1567  fillPlane16(dst[plane], dstStride[plane], length, height, y,
1568  plane == 3, desc_dst->comp[plane].depth,
1569  isBE(c->dstFormat));
1570  } else {
1571  fillPlane(dst[plane], dstStride[plane], length, height, y,
1572  (plane == 3) ? 255 : 128);
1573  }
1574  } else {
1575  if(isNBPS(c->srcFormat) || isNBPS(c->dstFormat)
1576  || (is16BPS(c->srcFormat) != is16BPS(c->dstFormat))
1577  ) {
1578  const int src_depth = desc_src->comp[plane].depth;
1579  const int dst_depth = desc_dst->comp[plane].depth;
1580  const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
1581  uint16_t *dstPtr2 = (uint16_t*)dstPtr;
1582 
1583  if (dst_depth == 8) {
1584  if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
1585  DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
1586  } else {
1587  DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, )
1588  }
1589  } else if (src_depth == 8) {
1590  for (i = 0; i < height; i++) {
1591  #define COPY816(w)\
1592  if (shiftonly) {\
1593  for (j = 0; j < length; j++)\
1594  w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
1595  } else {\
1596  for (j = 0; j < length; j++)\
1597  w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
1598  (srcPtr[j]>>(2*8-dst_depth)));\
1599  }
1600  if(isBE(c->dstFormat)){
1601  COPY816(AV_WB16)
1602  } else {
1603  COPY816(AV_WL16)
1604  }
1605  dstPtr2 += dstStride[plane]/2;
1606  srcPtr += srcStride[plane];
1607  }
1608  } else if (src_depth <= dst_depth) {
1609  for (i = 0; i < height; i++) {
1610  j = 0;
1611  if(isBE(c->srcFormat) == HAVE_BIGENDIAN &&
1612  isBE(c->dstFormat) == HAVE_BIGENDIAN &&
1613  shiftonly) {
1614  unsigned shift = dst_depth - src_depth;
1615 #if HAVE_FAST_64BIT
1616 #define FAST_COPY_UP(shift) \
1617  for (; j < length - 3; j += 4) { \
1618  uint64_t v = AV_RN64A(srcPtr2 + j); \
1619  AV_WN64A(dstPtr2 + j, v << shift); \
1620  }
1621 #else
1622 #define FAST_COPY_UP(shift) \
1623  for (; j < length - 1; j += 2) { \
1624  uint32_t v = AV_RN32A(srcPtr2 + j); \
1625  AV_WN32A(dstPtr2 + j, v << shift); \
1626  }
1627 #endif
1628  switch (shift)
1629  {
1630  case 6: FAST_COPY_UP(6); break;
1631  case 7: FAST_COPY_UP(7); break;
1632  }
1633  }
1634 #define COPY_UP(r,w) \
1635  if(shiftonly){\
1636  for (; j < length; j++){ \
1637  unsigned int v= r(&srcPtr2[j]);\
1638  w(&dstPtr2[j], v<<(dst_depth-src_depth));\
1639  }\
1640  }else{\
1641  for (; j < length; j++){ \
1642  unsigned int v= r(&srcPtr2[j]);\
1643  w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
1644  (v>>(2*src_depth-dst_depth)));\
1645  }\
1646  }
1647  if(isBE(c->srcFormat)){
1648  if(isBE(c->dstFormat)){
1650  } else {
1652  }
1653  } else {
1654  if(isBE(c->dstFormat)){
1656  } else {
1658  }
1659  }
1660  dstPtr2 += dstStride[plane]/2;
1661  srcPtr2 += srcStride[plane]/2;
1662  }
1663  } else {
1664  if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
1665  if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
1666  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
1667  } else {
1668  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16)
1669  }
1670  }else{
1671  if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
1672  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, )
1673  } else {
1674  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16)
1675  }
1676  }
1677  }
1678  } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) &&
1679  isBE(c->srcFormat) != isBE(c->dstFormat)) {
1680 
1681  for (i = 0; i < height; i++) {
1682  for (j = 0; j < length; j++)
1683  ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]);
1684  srcPtr += srcStride[plane];
1685  dstPtr += dstStride[plane];
1686  }
1687  } else if (dstStride[plane] == srcStride[plane] &&
1688  srcStride[plane] > 0 && srcStride[plane] == length) {
1689  memcpy(dst[plane] + dstStride[plane] * y, src[plane],
1690  height * dstStride[plane]);
1691  } else {
1692  if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat))
1693  length *= 2;
1694  else if (desc_src->comp[0].depth == 1)
1695  length >>= 3; // monowhite/black
1696  for (i = 0; i < height; i++) {
1697  memcpy(dstPtr, srcPtr, length);
1698  srcPtr += srcStride[plane];
1699  dstPtr += dstStride[plane];
1700  }
1701  }
1702  }
1703  }
1704  return srcSliceH;
1705 }
1706 
1707 
1708 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
1709  ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
1710  (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
1711 
1712 
1714 {
1715  const enum AVPixelFormat srcFormat = c->srcFormat;
1716  const enum AVPixelFormat dstFormat = c->dstFormat;
1717  const int flags = c->flags;
1718  const int dstH = c->dstH;
1719  int needsDither;
1720 
1721  needsDither = isAnyRGB(dstFormat) &&
1722  c->dstFormatBpp < 24 &&
1723  (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat)));
1724 
1725  /* yv12_to_nv12 */
1726  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
1727  (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)) {
1729  }
1730  /* nv12_to_yv12 */
1731  if (dstFormat == AV_PIX_FMT_YUV420P &&
1732  (srcFormat == AV_PIX_FMT_NV12 || srcFormat == AV_PIX_FMT_NV21)) {
1734  }
1735  /* yuv2bgr */
1736  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P ||
1737  srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) &&
1738  !(flags & SWS_ACCURATE_RND) && (c->dither == SWS_DITHER_BAYER || c->dither == SWS_DITHER_AUTO) && !(dstH & 1)) {
1740  }
1741  /* yuv420p10_to_p010 */
1742  if ((srcFormat == AV_PIX_FMT_YUV420P10 || srcFormat == AV_PIX_FMT_YUVA420P10) &&
1743  dstFormat == AV_PIX_FMT_P010) {
1745  }
1746  /* yuv420p_to_p010le */
1747  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
1748  dstFormat == AV_PIX_FMT_P010LE) {
1750  }
1751 
1752  if (srcFormat == AV_PIX_FMT_YUV410P && !(dstH & 3) &&
1753  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
1754  !(flags & SWS_BITEXACT)) {
1756  }
1757 
1758  /* bgr24toYV12 */
1759  if (srcFormat == AV_PIX_FMT_BGR24 &&
1760  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
1761  !(flags & SWS_ACCURATE_RND))
1763 
1764  /* RGB/BGR -> RGB/BGR (no dither needed forms) */
1765  if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)
1766  && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
1767  c->swscale = rgbToRgbWrapper;
1768 
1769  /* RGB to planar RGB */
1770  if ((srcFormat == AV_PIX_FMT_GBRP && dstFormat == AV_PIX_FMT_GBRAP) ||
1771  (srcFormat == AV_PIX_FMT_GBRAP && dstFormat == AV_PIX_FMT_GBRP))
1773 
1774 #define isByteRGB(f) ( \
1775  f == AV_PIX_FMT_RGB32 || \
1776  f == AV_PIX_FMT_RGB32_1 || \
1777  f == AV_PIX_FMT_RGB24 || \
1778  f == AV_PIX_FMT_BGR32 || \
1779  f == AV_PIX_FMT_BGR32_1 || \
1780  f == AV_PIX_FMT_BGR24)
1781 
1782  if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
1784 
1785  if ((srcFormat == AV_PIX_FMT_RGB48LE || srcFormat == AV_PIX_FMT_RGB48BE ||
1786  srcFormat == AV_PIX_FMT_BGR48LE || srcFormat == AV_PIX_FMT_BGR48BE ||
1787  srcFormat == AV_PIX_FMT_RGBA64LE || srcFormat == AV_PIX_FMT_RGBA64BE ||
1788  srcFormat == AV_PIX_FMT_BGRA64LE || srcFormat == AV_PIX_FMT_BGRA64BE) &&
1789  (dstFormat == AV_PIX_FMT_GBRP9LE || dstFormat == AV_PIX_FMT_GBRP9BE ||
1790  dstFormat == AV_PIX_FMT_GBRP10LE || dstFormat == AV_PIX_FMT_GBRP10BE ||
1791  dstFormat == AV_PIX_FMT_GBRP12LE || dstFormat == AV_PIX_FMT_GBRP12BE ||
1792  dstFormat == AV_PIX_FMT_GBRP14LE || dstFormat == AV_PIX_FMT_GBRP14BE ||
1793  dstFormat == AV_PIX_FMT_GBRP16LE || dstFormat == AV_PIX_FMT_GBRP16BE ||
1794  dstFormat == AV_PIX_FMT_GBRAP12LE || dstFormat == AV_PIX_FMT_GBRAP12BE ||
1795  dstFormat == AV_PIX_FMT_GBRAP16LE || dstFormat == AV_PIX_FMT_GBRAP16BE ))
1797 
1798  if ((srcFormat == AV_PIX_FMT_GBRP9LE || srcFormat == AV_PIX_FMT_GBRP9BE ||
1799  srcFormat == AV_PIX_FMT_GBRP16LE || srcFormat == AV_PIX_FMT_GBRP16BE ||
1800  srcFormat == AV_PIX_FMT_GBRP10LE || srcFormat == AV_PIX_FMT_GBRP10BE ||
1801  srcFormat == AV_PIX_FMT_GBRP12LE || srcFormat == AV_PIX_FMT_GBRP12BE ||
1802  srcFormat == AV_PIX_FMT_GBRP14LE || srcFormat == AV_PIX_FMT_GBRP14BE ||
1803  srcFormat == AV_PIX_FMT_GBRAP12LE || srcFormat == AV_PIX_FMT_GBRAP12BE ||
1804  srcFormat == AV_PIX_FMT_GBRAP16LE || srcFormat == AV_PIX_FMT_GBRAP16BE) &&
1805  (dstFormat == AV_PIX_FMT_RGB48LE || dstFormat == AV_PIX_FMT_RGB48BE ||
1806  dstFormat == AV_PIX_FMT_BGR48LE || dstFormat == AV_PIX_FMT_BGR48BE ||
1807  dstFormat == AV_PIX_FMT_RGBA64LE || dstFormat == AV_PIX_FMT_RGBA64BE ||
1808  dstFormat == AV_PIX_FMT_BGRA64LE || dstFormat == AV_PIX_FMT_BGRA64BE))
1810 
1811  if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth == 8 &&
1812  isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRP)
1814 
1815  if (isBayer(srcFormat)) {
1816  if (dstFormat == AV_PIX_FMT_RGB24)
1818  else if (dstFormat == AV_PIX_FMT_YUV420P)
1820  else if (!isBayer(dstFormat)) {
1821  av_log(c, AV_LOG_ERROR, "unsupported bayer conversion\n");
1822  av_assert0(0);
1823  }
1824  }
1825 
1826  /* bswap 16 bits per pixel/component packed formats */
1827  if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_BGGR16) ||
1828  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_RGGB16) ||
1829  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GBRG16) ||
1830  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GRBG16) ||
1831  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR444) ||
1832  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR48) ||
1833  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
1834  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR555) ||
1835  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR565) ||
1836  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
1837  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY9) ||
1838  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY10) ||
1839  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY12) ||
1840  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY16) ||
1841  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YA16) ||
1842  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_AYUV64) ||
1843  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP9) ||
1844  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP10) ||
1845  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP12) ||
1846  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP14) ||
1847  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP16) ||
1848  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP12) ||
1849  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP16) ||
1850  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB444) ||
1851  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB48) ||
1852  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
1853  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB555) ||
1854  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB565) ||
1855  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
1856  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XYZ12) ||
1857  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P9) ||
1858  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P10) ||
1859  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P12) ||
1860  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P14) ||
1861  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P16) ||
1862  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P9) ||
1863  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P10) ||
1864  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P12) ||
1865  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P14) ||
1866  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P16) ||
1867  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P10) ||
1868  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P12) ||
1869  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P9) ||
1870  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P10) ||
1871  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P12) ||
1872  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P14) ||
1873  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P16))
1875 
1876  if (usePal(srcFormat) && isByteRGB(dstFormat))
1877  c->swscale = palToRgbWrapper;
1878 
1879  if (srcFormat == AV_PIX_FMT_YUV422P) {
1880  if (dstFormat == AV_PIX_FMT_YUYV422)
1882  else if (dstFormat == AV_PIX_FMT_UYVY422)
1884  }
1885 
1886  /* LQ converters if -sws 0 or -sws 4*/
1887  if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) {
1888  /* yv12_to_yuy2 */
1889  if (srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) {
1890  if (dstFormat == AV_PIX_FMT_YUYV422)
1892  else if (dstFormat == AV_PIX_FMT_UYVY422)
1894  }
1895  }
1896  if (srcFormat == AV_PIX_FMT_YUYV422 &&
1897  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
1899  if (srcFormat == AV_PIX_FMT_UYVY422 &&
1900  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
1902  if (srcFormat == AV_PIX_FMT_YUYV422 && dstFormat == AV_PIX_FMT_YUV422P)
1904  if (srcFormat == AV_PIX_FMT_UYVY422 && dstFormat == AV_PIX_FMT_YUV422P)
1906 
1907 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
1908  /* simple copy */
1909  if ( srcFormat == dstFormat ||
1910  (srcFormat == AV_PIX_FMT_YUVA420P && dstFormat == AV_PIX_FMT_YUV420P) ||
1911  (srcFormat == AV_PIX_FMT_YUV420P && dstFormat == AV_PIX_FMT_YUVA420P) ||
1912  (isPlanarYUV(srcFormat) && isPlanarGray(dstFormat)) ||
1913  (isPlanarYUV(dstFormat) && isPlanarGray(srcFormat)) ||
1914  (isPlanarGray(dstFormat) && isPlanarGray(srcFormat)) ||
1915  (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) &&
1918  dstFormat != AV_PIX_FMT_NV12 && dstFormat != AV_PIX_FMT_NV21 &&
1919  dstFormat != AV_PIX_FMT_P010LE && dstFormat != AV_PIX_FMT_P010BE &&
1920  dstFormat != AV_PIX_FMT_P016LE && dstFormat != AV_PIX_FMT_P016BE &&
1921  srcFormat != AV_PIX_FMT_NV12 && srcFormat != AV_PIX_FMT_NV21 &&
1922  srcFormat != AV_PIX_FMT_P010LE && srcFormat != AV_PIX_FMT_P010BE &&
1923  srcFormat != AV_PIX_FMT_P016LE && srcFormat != AV_PIX_FMT_P016BE))
1924  {
1925  if (isPacked(c->srcFormat))
1927  else /* Planar YUV or gray */
1929  }
1930 
1931  if (ARCH_PPC)
1933  if (ARCH_ARM)
1935  if (ARCH_AARCH64)
1937 }
1938 
1939 /* Convert the palette to the same packed 32-bit format as the palette */
1941  int num_pixels, const uint8_t *palette)
1942 {
1943  int i;
1944 
1945  for (i = 0; i < num_pixels; i++)
1946  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
1947 }
1948 
1949 /* Palette format: ABCD -> dst format: ABC */
1951  int num_pixels, const uint8_t *palette)
1952 {
1953  int i;
1954 
1955  for (i = 0; i < num_pixels; i++) {
1956  //FIXME slow?
1957  dst[0] = palette[src[i] * 4 + 0];
1958  dst[1] = palette[src[i] * 4 + 1];
1959  dst[2] = palette[src[i] * 4 + 2];
1960  dst += 3;
1961  }
1962 }
#define IS_NOT_NE(bpp, desc)
int plane
Definition: avisynth_c.h:422
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:77
void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, int src_size)
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:771
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
static int shift(int a, int b)
Definition: sonic.c:82
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:370
static void copy(const float *p1, float *p2, const int length)
#define COPY816(w)
static float alpha(float a)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2363
static int packed_16bpc_bswap(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define isPlanarGray(x)
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.
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:403
static int conv(int samples, float **pcm, char *buf, int channels)
Definition: libvorbisdec.c:120
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.
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:378
8 bits gray, 8 bits alpha
Definition: pixfmt.h:139
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
static void fn() rgb2yuv(uint8_t *_yuv[3], const ptrdiff_t yuv_stride[3], int16_t *rgb[3], ptrdiff_t s, int w, int h, const int16_t rgb2yuv_coeffs[3][3][8], const int16_t yuv_offset[8])
void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:178
uint32_t pal_rgb[256]
void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:310
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, int32_t *rgb2yuv)
Height should be a multiple of 2 and width should be a multiple of 2.
Definition: rgb2rgb.c:77
void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, int src_size)
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
void(* planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, int srcStride, int dstStride)
Definition: rgb2rgb.c:82
static void packed16togbra16(const uint8_t *src, int srcStride, uint16_t *dst[], int dstStride[], int srcSliceH, int src_alpha, int swap, int shift, int width)
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:358
void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, int src_size)
bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples */
Definition: pixfmt.h:258
bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples */
Definition: pixfmt.h:259
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:164
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:203
void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:233
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:384
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian */
Definition: pixfmt.h:266
static void gbr24ptopacked32(const uint8_t *src[], int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int alpha_first, int width)
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:109
#define av_bswap16
Definition: bswap.h:31
int dstFormatBpp
Number of bits per pixel of the destination pixel format.
void rgb48tobgr64_bswap(const uint8_t *src, uint8_t *dst, int src_size)
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:363
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:69
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
Convenience header that includes libavutil's core.
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:349
#define isRGBA32(x)
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:251
static void gbr24ptopacked24(const uint8_t *src[], int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int width)
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:372
#define RGBA(r, g, b, a)
Definition: dvbsubdec.c:39
int srcRange
0 = MPG YUV range, 1 = JPG YUV range (source image).
bayer, BGBG..(odd line), GRGR..(even line), 8-bit samples */
Definition: pixfmt.h:256
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:87
void(* rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:45
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:357
#define CASE(pixfmt, prefix)
#define src
Definition: vp8dsp.c:254
int dstY
Last destination vertical line output from last slice.
planar GBR 4:4:4 36bpp, big-endian
Definition: pixfmt.h:250
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:87
void rgb48tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:350
void(* rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:50
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:100
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:351
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:103
#define AV_PIX_FMT_P010
Definition: pixfmt.h:413
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:212
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:97
int chrDstVSubSample
Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination i...
static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define isByteRGB(f)
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
Definition: pixdesc.h:173
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:65
static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
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:99
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, little-endian */
Definition: pixfmt.h:264
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian */
Definition: pixfmt.h:265
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:201
void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:219
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:383
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:90
static void interpolate(float *out, float v1, float v2, int size)
Definition: twinvq.c:84
void(* rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:43
#define SWS_FAST_BILINEAR
Definition: swscale.h:58
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
#define height
static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:170
static int flags
Definition: log.c:55
static int planarRgbToplanarRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define AV_PIX_FMT_BGR48
Definition: pixfmt.h:359
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:381
external API header
enum AVPixelFormat dstFormat
Destination pixel format.
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:373
#define AV_WB16(p, v)
Definition: intreadwrite.h:405
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, little-endian */
Definition: pixfmt.h:260
int chrSrcHSubSample
Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source imag...
#define AV_PIX_FMT_BAYER_GRBG16
Definition: pixfmt.h:395
#define av_log(a,...)
#define COPY_UP(r, w)
const char * name
Definition: pixdesc.h:82
void rgb48to64_bswap(const uint8_t *src, uint8_t *dst, int src_size)
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:61
int dstH
Height of destination luma/alpha planes.
void ff_get_unscaled_swscale(SwsContext *c)
Set c->swscale to an unscaled converter if one exists for the specific source and destination formats...
static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
planar GBR 4:4:4 27bpp, big-endian
Definition: pixfmt.h:166
void rgb64to48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
#define CONV_IS(src, dst)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:345
static int planarToNv12Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
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:84
static rgbConvFn findRgbConvFn(SwsContext *c)
static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
like NV12, with 16bpp per component, big-endian
Definition: pixfmt.h:297
#define output_pixel(p, v)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
void(* rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:49
#define FAST_COPY_UP(shift)
static int planarRgb16ToRgb16Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:91
void(* rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:38
void(* rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:48
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:353
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:85
uint16_t width
Definition: gdv.c:47
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:389
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:354
simple assert() macros that are a bit more flexible than ISO C assert().
GLsizei GLsizei * length
Definition: opengl_enc.c:115
like NV12, with 16bpp per component, little-endian
Definition: pixfmt.h:296
static void fillPlane(uint8_t *plane, int stride, int width, int height, int y, uint8_t val)
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:371
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, big-endian
Definition: pixfmt.h:281
static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:88
static const uint8_t dithers[8][8][8]
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:390
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:145
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:89
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
static int uyvyToYuv420Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
static int palToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:366
void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:289
as above, but U and V bytes are swapped
Definition: pixfmt.h:86
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:283
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:387
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:352
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define FFMIN(a, b)
Definition: common.h:96
uint8_t * formatConvBuffer
void(* rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:37
static av_always_inline int isBayer(enum AVPixelFormat pix_fmt)
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
#define isRGBA64(x)
void rgb64tobgr48_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
int32_t
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
void(* rgbConvFn)(const uint8_t *, uint8_t *, int)
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:200
void rgb64tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian
Definition: pixfmt.h:280
#define AV_PIX_FMT_BAYER_BGGR16
Definition: pixfmt.h:392
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:367
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:144
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:386
void ff_get_unscaled_swscale_aarch64(SwsContext *c)
static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:83
planar GBR 4:4:4:4 48bpp, little-endian
Definition: pixfmt.h:284
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:379
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:361
#define AV_PIX_FMT_BAYER_GBRG16
Definition: pixfmt.h:394
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:344
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
void(* rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:52
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:376
void rgb48to64_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
void(* rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:51
static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static int planar8ToP01xleWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam8[], int dstStride[])
#define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt)
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, big-endian */
Definition: pixfmt.h:263
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:168
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian */
Definition: pixfmt.h:267
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:342
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:63
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:253
static void gbr16ptopacked16(const uint16_t *src[], int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int alpha, int swap, int bpp, int width)
void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:140
void(* rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:46
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:368
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
#define AV_PIX_FMT_XYZ12
Definition: pixfmt.h:410
static av_always_inline int isRGBinInt(enum AVPixelFormat pix_fmt)
void(* shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:55
SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
Definition: yuv2rgb.c:678
#define SWS_ACCURATE_RND
Definition: swscale.h:83
byte swapping routines
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:374
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:252
static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:365
void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:158
#define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)
#define SWS_POINT
Definition: swscale.h:62
void(* shuffle_bytes_0321)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:54
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, big-endian */
Definition: pixfmt.h:261
static void fillPlane16(uint8_t *plane, int stride, int width, int height, int y, int alpha, int bits, const int big_endian)
static int Rgb16ToPlanarRgb16Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
static int planarCopyWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:360
#define AV_PIX_FMT_AYUV64
Definition: pixfmt.h:412
void(* rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:41
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:377
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:385
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:369
static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define SWS_BITEXACT
Definition: swscale.h:84
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:375
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian */
Definition: pixfmt.h:262
void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:299
void ff_get_unscaled_swscale_arm(SwsContext *c)
#define AV_PIX_FMT_BAYER_RGGB16
Definition: pixfmt.h:393
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:57
SwsDither dither
int
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
static int nv12ToPlanarWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:211
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:167
static double c[64]
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:98
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:106
void(* rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:40
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:362
#define AV_WL16(p, v)
Definition: intreadwrite.h:412
enum AVPixelFormat srcFormat
Source pixel format.
bayer, RGRG..(odd line), GBGB..(even line), 8-bit samples */
Definition: pixfmt.h:257
static void packedtogbr24p(const uint8_t *src, int srcStride, uint8_t *dst[], int dstStride[], int srcSliceH, int alpha_first, int inc_size, int width)
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:356
void rgb48tobgr48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
static int planarToP010Wrapper(SwsContext *c, const uint8_t *src8[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam8[], int dstStride[])
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:128
static void copyPlane(const uint8_t *src, int srcStride, int srcSliceY, int srcSliceH, int width, uint8_t *dst, int dstStride)
void(* rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:35
SwsFunc swscale
Note that src, dst, srcStride, dstStride will be copied in the sws_scale() wrapper so they can be fre...
void(* rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:47
void(* rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:42
static int planarToUyvyWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
void(* rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:36
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:343
void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:253
static int planarToYuy2Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
static av_always_inline int isBGRinInt(enum AVPixelFormat pix_fmt)
int srcFormatBpp
Number of bits per pixel of the source pixel format.
void rgb48tobgr64_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
void rgb64to48_bswap(const uint8_t *src, uint8_t *dst, int src_size)
av_cold void ff_get_unscaled_swscale_ppc(SwsContext *c)
static int packedCopyWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:355
static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
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:87
int32_t input_rgb2yuv_table[16+40 *4]
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:171
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
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:2279
#define stride
static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
#define ALT32_CORR
int chrDstHSubSample
Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination...
int chrSrcW
Width of source chroma planes.
int depth
Number of bits in the component.
Definition: pixdesc.h:58
#define isRGB48(x)
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:213
int srcW
Width of source luma/alpha planes.
void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:243
int chrSrcVSubSample
Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in source image...
int flags
Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc...
static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:144
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:380
void(* rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:39
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
planar GBR 4:4:4 30bpp, little-endian
Definition: pixfmt.h:169
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
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:275