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 planarToP01xWrapper(SwsContext *c, const uint8_t *src8[],
184  int srcStride[], int srcSliceY,
185  int srcSliceH, uint8_t *dstParam8[],
186  int dstStride[])
187 {
188  const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
189  const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
190  const uint16_t **src = (const uint16_t**)src8;
191  uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
192  uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
193  int x, y;
194 
195  /* Calculate net shift required for values. */
196  const int shift[3] = {
197  dst_format->comp[0].depth + dst_format->comp[0].shift -
198  src_format->comp[0].depth - src_format->comp[0].shift,
199  dst_format->comp[1].depth + dst_format->comp[1].shift -
200  src_format->comp[1].depth - src_format->comp[1].shift,
201  dst_format->comp[2].depth + dst_format->comp[2].shift -
202  src_format->comp[2].depth - src_format->comp[2].shift,
203  };
204 
205  av_assert0(!(srcStride[0] % 2 || srcStride[1] % 2 || srcStride[2] % 2 ||
206  dstStride[0] % 2 || dstStride[1] % 2));
207 
208  for (y = 0; y < srcSliceH; y++) {
209  uint16_t *tdstY = dstY;
210  const uint16_t *tsrc0 = src[0];
211  for (x = c->srcW; x > 0; x--) {
212  *tdstY++ = *tsrc0++ << shift[0];
213  }
214  src[0] += srcStride[0] / 2;
215  dstY += dstStride[0] / 2;
216 
217  if (!(y & 1)) {
218  uint16_t *tdstUV = dstUV;
219  const uint16_t *tsrc1 = src[1];
220  const uint16_t *tsrc2 = src[2];
221  for (x = c->srcW / 2; x > 0; x--) {
222  *tdstUV++ = *tsrc1++ << shift[1];
223  *tdstUV++ = *tsrc2++ << shift[2];
224  }
225  src[1] += srcStride[1] / 2;
226  src[2] += srcStride[2] / 2;
227  dstUV += dstStride[1] / 2;
228  }
229  }
230 
231  return srcSliceH;
232 }
233 
234 #if AV_HAVE_BIGENDIAN
235 #define output_pixel(p, v) do { \
236  uint16_t *pp = (p); \
237  AV_WL16(pp, (v)); \
238  } while(0)
239 #else
240 #define output_pixel(p, v) (*p) = (v)
241 #endif
242 
244  int srcStride[], int srcSliceY,
245  int srcSliceH, uint8_t *dstParam8[],
246  int dstStride[])
247 {
248  uint16_t *dstY = (uint16_t*)(dstParam8[0] + dstStride[0] * srcSliceY);
249  uint16_t *dstUV = (uint16_t*)(dstParam8[1] + dstStride[1] * srcSliceY / 2);
250  int x, y, t;
251 
252  av_assert0(!(dstStride[0] % 2 || dstStride[1] % 2));
253 
254  for (y = 0; y < srcSliceH; y++) {
255  uint16_t *tdstY = dstY;
256  const uint8_t *tsrc0 = src[0];
257  for (x = c->srcW; x > 0; x--) {
258  t = *tsrc0++;
259  output_pixel(tdstY++, t | (t << 8));
260  }
261  src[0] += srcStride[0];
262  dstY += dstStride[0] / 2;
263 
264  if (!(y & 1)) {
265  uint16_t *tdstUV = dstUV;
266  const uint8_t *tsrc1 = src[1];
267  const uint8_t *tsrc2 = src[2];
268  for (x = c->srcW / 2; x > 0; x--) {
269  t = *tsrc1++;
270  output_pixel(tdstUV++, t | (t << 8));
271  t = *tsrc2++;
272  output_pixel(tdstUV++, t | (t << 8));
273  }
274  src[1] += srcStride[1];
275  src[2] += srcStride[2];
276  dstUV += dstStride[1] / 2;
277  }
278  }
279 
280  return srcSliceH;
281 }
282 
283 #undef output_pixel
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  yv12toyuy2(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  yv12touyvy(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  yuv422ptoyuy2(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 *dst = dstParam[0] + dstStride[0] * srcSliceY;
326 
327  yuv422ptouyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
328  srcStride[1], dstStride[0]);
329 
330  return srcSliceH;
331 }
332 
334  int srcStride[], int srcSliceY, int srcSliceH,
335  uint8_t *dstParam[], int dstStride[])
336 {
337  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
338  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
339  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
340 
341  yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
342  dstStride[1], srcStride[0]);
343 
344  if (dstParam[3])
345  fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
346 
347  return srcSliceH;
348 }
349 
351  int srcStride[], int srcSliceY, int srcSliceH,
352  uint8_t *dstParam[], int dstStride[])
353 {
354  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
355  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
356  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
357 
358  yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
359  dstStride[1], srcStride[0]);
360 
361  return srcSliceH;
362 }
363 
365  int srcStride[], int srcSliceY, int srcSliceH,
366  uint8_t *dstParam[], int dstStride[])
367 {
368  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
369  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
370  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
371 
372  uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
373  dstStride[1], srcStride[0]);
374 
375  if (dstParam[3])
376  fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
377 
378  return srcSliceH;
379 }
380 
382  int srcStride[], int srcSliceY, int srcSliceH,
383  uint8_t *dstParam[], int dstStride[])
384 {
385  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
386  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
387  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
388 
389  uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
390  dstStride[1], srcStride[0]);
391 
392  return srcSliceH;
393 }
394 
395 static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels,
396  const uint8_t *palette)
397 {
398  int i;
399  for (i = 0; i < num_pixels; i++)
400  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | (src[(i << 1) + 1] << 24);
401 }
402 
403 static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels,
404  const uint8_t *palette)
405 {
406  int i;
407 
408  for (i = 0; i < num_pixels; i++)
409  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | src[(i << 1) + 1];
410 }
411 
412 static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels,
413  const uint8_t *palette)
414 {
415  int i;
416 
417  for (i = 0; i < num_pixels; i++) {
418  //FIXME slow?
419  dst[0] = palette[src[i << 1] * 4 + 0];
420  dst[1] = palette[src[i << 1] * 4 + 1];
421  dst[2] = palette[src[i << 1] * 4 + 2];
422  dst += 3;
423  }
424 }
425 
426 static int packed_16bpc_bswap(SwsContext *c, const uint8_t *src[],
427  int srcStride[], int srcSliceY, int srcSliceH,
428  uint8_t *dst[], int dstStride[])
429 {
430  int i, j, p;
431 
432  for (p = 0; p < 4; p++) {
433  int srcstr = srcStride[p] / 2;
434  int dststr = dstStride[p] / 2;
435  uint16_t *dstPtr = (uint16_t *) dst[p];
436  const uint16_t *srcPtr = (const uint16_t *) src[p];
437  int min_stride = FFMIN(FFABS(srcstr), FFABS(dststr));
438  if(!dstPtr || !srcPtr)
439  continue;
440  dstPtr += (srcSliceY >> c->chrDstVSubSample) * dststr;
441  for (i = 0; i < (srcSliceH >> c->chrDstVSubSample); i++) {
442  for (j = 0; j < min_stride; j++) {
443  dstPtr[j] = av_bswap16(srcPtr[j]);
444  }
445  srcPtr += srcstr;
446  dstPtr += dststr;
447  }
448  }
449 
450  return srcSliceH;
451 }
452 
453 static int palToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
454  int srcSliceY, int srcSliceH, uint8_t *dst[],
455  int dstStride[])
456 {
457  const enum AVPixelFormat srcFormat = c->srcFormat;
458  const enum AVPixelFormat dstFormat = c->dstFormat;
459  void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels,
460  const uint8_t *palette) = NULL;
461  int i;
462  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
463  const uint8_t *srcPtr = src[0];
464 
465  if (srcFormat == AV_PIX_FMT_YA8) {
466  switch (dstFormat) {
467  case AV_PIX_FMT_RGB32 : conv = gray8aToPacked32; break;
468  case AV_PIX_FMT_BGR32 : conv = gray8aToPacked32; break;
471  case AV_PIX_FMT_RGB24 : conv = gray8aToPacked24; break;
472  case AV_PIX_FMT_BGR24 : conv = gray8aToPacked24; break;
473  }
474  } else if (usePal(srcFormat)) {
475  switch (dstFormat) {
482  }
483  }
484 
485  if (!conv)
486  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
487  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
488  else {
489  for (i = 0; i < srcSliceH; i++) {
490  conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb);
491  srcPtr += srcStride[0];
492  dstPtr += dstStride[0];
493  }
494  }
495 
496  return srcSliceH;
497 }
498 
499 static void packed16togbra16(const uint8_t *src, int srcStride,
500  uint16_t *dst[], int dstStride[], int srcSliceH,
501  int src_alpha, int swap, int shift, int width)
502 {
503  int x, h, i;
504  int dst_alpha = dst[3] != NULL;
505  for (h = 0; h < srcSliceH; h++) {
506  uint16_t *src_line = (uint16_t *)(src + srcStride * h);
507  switch (swap) {
508  case 3:
509  if (src_alpha && dst_alpha) {
510  for (x = 0; x < width; x++) {
511  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
512  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
513  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
514  dst[3][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
515  }
516  } else if (dst_alpha) {
517  for (x = 0; x < width; x++) {
518  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
519  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
520  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
521  dst[3][x] = 0xFFFF;
522  }
523  } else if (src_alpha) {
524  for (x = 0; x < width; x++) {
525  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
526  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
527  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
528  src_line++;
529  }
530  } else {
531  for (x = 0; x < width; x++) {
532  dst[0][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
533  dst[1][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
534  dst[2][x] = av_bswap16(av_bswap16(*src_line++) >> shift);
535  }
536  }
537  break;
538  case 2:
539  if (src_alpha && dst_alpha) {
540  for (x = 0; x < width; x++) {
541  dst[0][x] = av_bswap16(*src_line++ >> shift);
542  dst[1][x] = av_bswap16(*src_line++ >> shift);
543  dst[2][x] = av_bswap16(*src_line++ >> shift);
544  dst[3][x] = av_bswap16(*src_line++ >> shift);
545  }
546  } else if (dst_alpha) {
547  for (x = 0; x < width; x++) {
548  dst[0][x] = av_bswap16(*src_line++ >> shift);
549  dst[1][x] = av_bswap16(*src_line++ >> shift);
550  dst[2][x] = av_bswap16(*src_line++ >> shift);
551  dst[3][x] = 0xFFFF;
552  }
553  } else if (src_alpha) {
554  for (x = 0; x < width; x++) {
555  dst[0][x] = av_bswap16(*src_line++ >> shift);
556  dst[1][x] = av_bswap16(*src_line++ >> shift);
557  dst[2][x] = av_bswap16(*src_line++ >> shift);
558  src_line++;
559  }
560  } else {
561  for (x = 0; x < width; x++) {
562  dst[0][x] = av_bswap16(*src_line++ >> shift);
563  dst[1][x] = av_bswap16(*src_line++ >> shift);
564  dst[2][x] = av_bswap16(*src_line++ >> shift);
565  }
566  }
567  break;
568  case 1:
569  if (src_alpha && dst_alpha) {
570  for (x = 0; x < width; x++) {
571  dst[0][x] = av_bswap16(*src_line++) >> shift;
572  dst[1][x] = av_bswap16(*src_line++) >> shift;
573  dst[2][x] = av_bswap16(*src_line++) >> shift;
574  dst[3][x] = av_bswap16(*src_line++) >> shift;
575  }
576  } else if (dst_alpha) {
577  for (x = 0; x < width; x++) {
578  dst[0][x] = av_bswap16(*src_line++) >> shift;
579  dst[1][x] = av_bswap16(*src_line++) >> shift;
580  dst[2][x] = av_bswap16(*src_line++) >> shift;
581  dst[3][x] = 0xFFFF;
582  }
583  } else if (src_alpha) {
584  for (x = 0; x < width; x++) {
585  dst[0][x] = av_bswap16(*src_line++) >> shift;
586  dst[1][x] = av_bswap16(*src_line++) >> shift;
587  dst[2][x] = av_bswap16(*src_line++) >> shift;
588  src_line++;
589  }
590  } else {
591  for (x = 0; x < width; x++) {
592  dst[0][x] = av_bswap16(*src_line++) >> shift;
593  dst[1][x] = av_bswap16(*src_line++) >> shift;
594  dst[2][x] = av_bswap16(*src_line++) >> shift;
595  }
596  }
597  break;
598  default:
599  if (src_alpha && dst_alpha) {
600  for (x = 0; x < width; x++) {
601  dst[0][x] = *src_line++ >> shift;
602  dst[1][x] = *src_line++ >> shift;
603  dst[2][x] = *src_line++ >> shift;
604  dst[3][x] = *src_line++ >> shift;
605  }
606  } else if (dst_alpha) {
607  for (x = 0; x < width; x++) {
608  dst[0][x] = *src_line++ >> shift;
609  dst[1][x] = *src_line++ >> shift;
610  dst[2][x] = *src_line++ >> shift;
611  dst[3][x] = 0xFFFF;
612  }
613  } else if (src_alpha) {
614  for (x = 0; x < width; x++) {
615  dst[0][x] = *src_line++ >> shift;
616  dst[1][x] = *src_line++ >> shift;
617  dst[2][x] = *src_line++ >> shift;
618  src_line++;
619  }
620  } else {
621  for (x = 0; x < width; x++) {
622  dst[0][x] = *src_line++ >> shift;
623  dst[1][x] = *src_line++ >> shift;
624  dst[2][x] = *src_line++ >> shift;
625  }
626  }
627  }
628  for (i = 0; i < 4; i++)
629  dst[i] += dstStride[i] >> 1;
630  }
631 }
632 
634  int srcStride[], int srcSliceY, int srcSliceH,
635  uint8_t *dst[], int dstStride[])
636 {
637  uint16_t *dst2013[] = { (uint16_t *)dst[2], (uint16_t *)dst[0], (uint16_t *)dst[1], (uint16_t *)dst[3] };
638  uint16_t *dst1023[] = { (uint16_t *)dst[1], (uint16_t *)dst[0], (uint16_t *)dst[2], (uint16_t *)dst[3] };
639  int stride2013[] = { dstStride[2], dstStride[0], dstStride[1], dstStride[3] };
640  int stride1023[] = { dstStride[1], dstStride[0], dstStride[2], dstStride[3] };
641  const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
642  const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
643  int bpc = dst_format->comp[0].depth;
644  int alpha = src_format->flags & AV_PIX_FMT_FLAG_ALPHA;
645  int swap = 0;
646  int i;
647 
648  if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
649  !HAVE_BIGENDIAN && src_format->flags & AV_PIX_FMT_FLAG_BE)
650  swap++;
651  if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
652  !HAVE_BIGENDIAN && dst_format->flags & AV_PIX_FMT_FLAG_BE)
653  swap += 2;
654 
655  if ((dst_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
657  av_log(c, AV_LOG_ERROR, "unsupported conversion to planar RGB %s -> %s\n",
658  src_format->name, dst_format->name);
659  return srcSliceH;
660  }
661 
662  for(i=0; i<4; i++) {
663  dst2013[i] += stride2013[i] * srcSliceY / 2;
664  dst1023[i] += stride1023[i] * srcSliceY / 2;
665  }
666 
667  switch (c->srcFormat) {
668  case AV_PIX_FMT_RGB48LE:
669  case AV_PIX_FMT_RGB48BE:
670  case AV_PIX_FMT_RGBA64LE:
671  case AV_PIX_FMT_RGBA64BE:
672  packed16togbra16(src[0], srcStride[0],
673  dst2013, stride2013, srcSliceH, alpha, swap,
674  16 - bpc, c->srcW);
675  break;
676  case AV_PIX_FMT_BGR48LE:
677  case AV_PIX_FMT_BGR48BE:
678  case AV_PIX_FMT_BGRA64LE:
679  case AV_PIX_FMT_BGRA64BE:
680  packed16togbra16(src[0], srcStride[0],
681  dst1023, stride1023, srcSliceH, alpha, swap,
682  16 - bpc, c->srcW);
683  break;
684  default:
685  av_log(c, AV_LOG_ERROR,
686  "unsupported conversion to planar RGB %s -> %s\n",
687  src_format->name, dst_format->name);
688  }
689 
690  return srcSliceH;
691 }
692 
693 static void gbr16ptopacked16(const uint16_t *src[], int srcStride[],
694  uint8_t *dst, int dstStride, int srcSliceH,
695  int alpha, int swap, int bpp, int width)
696 {
697  int x, h, i;
698  int src_alpha = src[3] != NULL;
699  int scale_high = 16 - bpp, scale_low = (bpp - 8) * 2;
700  for (h = 0; h < srcSliceH; h++) {
701  uint16_t *dest = (uint16_t *)(dst + dstStride * h);
702  uint16_t component;
703 
704  switch(swap) {
705  case 3:
706  if (alpha && !src_alpha) {
707  for (x = 0; x < width; x++) {
708  component = av_bswap16(src[0][x]);
709  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
710  component = av_bswap16(src[1][x]);
711  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
712  component = av_bswap16(src[2][x]);
713  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
714  *dest++ = 0xffff;
715  }
716  } else if (alpha && src_alpha) {
717  for (x = 0; x < width; x++) {
718  component = av_bswap16(src[0][x]);
719  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
720  component = av_bswap16(src[1][x]);
721  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
722  component = av_bswap16(src[2][x]);
723  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
724  component = av_bswap16(src[3][x]);
725  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
726  }
727  } else {
728  for (x = 0; x < width; x++) {
729  component = av_bswap16(src[0][x]);
730  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
731  component = av_bswap16(src[1][x]);
732  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
733  component = av_bswap16(src[2][x]);
734  *dest++ = av_bswap16(component << scale_high | component >> scale_low);
735  }
736  }
737  break;
738  case 2:
739  if (alpha && !src_alpha) {
740  for (x = 0; x < width; x++) {
741  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
742  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
743  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
744  *dest++ = 0xffff;
745  }
746  } else if (alpha && src_alpha) {
747  for (x = 0; x < width; x++) {
748  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
749  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
750  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
751  *dest++ = av_bswap16(src[3][x] << scale_high | src[3][x] >> scale_low);
752  }
753  } else {
754  for (x = 0; x < width; x++) {
755  *dest++ = av_bswap16(src[0][x] << scale_high | src[0][x] >> scale_low);
756  *dest++ = av_bswap16(src[1][x] << scale_high | src[1][x] >> scale_low);
757  *dest++ = av_bswap16(src[2][x] << scale_high | src[2][x] >> scale_low);
758  }
759  }
760  break;
761  case 1:
762  if (alpha && !src_alpha) {
763  for (x = 0; x < width; x++) {
764  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
765  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
766  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
767  *dest++ = 0xffff;
768  }
769  } else if (alpha && src_alpha) {
770  for (x = 0; x < width; x++) {
771  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
772  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
773  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
774  *dest++ = av_bswap16(src[3][x]) << scale_high | av_bswap16(src[3][x]) >> scale_low;
775  }
776  } else {
777  for (x = 0; x < width; x++) {
778  *dest++ = av_bswap16(src[0][x]) << scale_high | av_bswap16(src[0][x]) >> scale_low;
779  *dest++ = av_bswap16(src[1][x]) << scale_high | av_bswap16(src[1][x]) >> scale_low;
780  *dest++ = av_bswap16(src[2][x]) << scale_high | av_bswap16(src[2][x]) >> scale_low;
781  }
782  }
783  break;
784  default:
785  if (alpha && !src_alpha) {
786  for (x = 0; x < width; x++) {
787  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
788  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
789  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
790  *dest++ = 0xffff;
791  }
792  } else if (alpha && src_alpha) {
793  for (x = 0; x < width; x++) {
794  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
795  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
796  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
797  *dest++ = src[3][x] << scale_high | src[3][x] >> scale_low;
798  }
799  } else {
800  for (x = 0; x < width; x++) {
801  *dest++ = src[0][x] << scale_high | src[0][x] >> scale_low;
802  *dest++ = src[1][x] << scale_high | src[1][x] >> scale_low;
803  *dest++ = src[2][x] << scale_high | src[2][x] >> scale_low;
804  }
805  }
806  }
807  for (i = 0; i < 3 + src_alpha; i++)
808  src[i] += srcStride[i] >> 1;
809  }
810 }
811 
813  int srcStride[], int srcSliceY, int srcSliceH,
814  uint8_t *dst[], int dstStride[])
815 {
816  const uint16_t *src102[] = { (uint16_t *)src[1], (uint16_t *)src[0], (uint16_t *)src[2], (uint16_t *)src[3] };
817  const uint16_t *src201[] = { (uint16_t *)src[2], (uint16_t *)src[0], (uint16_t *)src[1], (uint16_t *)src[3] };
818  int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
819  int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
820  const AVPixFmtDescriptor *src_format = av_pix_fmt_desc_get(c->srcFormat);
821  const AVPixFmtDescriptor *dst_format = av_pix_fmt_desc_get(c->dstFormat);
822  int bits_per_sample = src_format->comp[0].depth;
823  int swap = 0;
824  if ( HAVE_BIGENDIAN && !(src_format->flags & AV_PIX_FMT_FLAG_BE) ||
825  !HAVE_BIGENDIAN && src_format->flags & AV_PIX_FMT_FLAG_BE)
826  swap++;
827  if ( HAVE_BIGENDIAN && !(dst_format->flags & AV_PIX_FMT_FLAG_BE) ||
828  !HAVE_BIGENDIAN && dst_format->flags & AV_PIX_FMT_FLAG_BE)
829  swap += 2;
830 
831  if ((src_format->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) !=
833  bits_per_sample <= 8) {
834  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
835  src_format->name, dst_format->name);
836  return srcSliceH;
837  }
838  switch (c->dstFormat) {
839  case AV_PIX_FMT_BGR48LE:
840  case AV_PIX_FMT_BGR48BE:
841  gbr16ptopacked16(src102, stride102,
842  dst[0] + srcSliceY * dstStride[0], dstStride[0],
843  srcSliceH, 0, swap, bits_per_sample, c->srcW);
844  break;
845  case AV_PIX_FMT_RGB48LE:
846  case AV_PIX_FMT_RGB48BE:
847  gbr16ptopacked16(src201, stride201,
848  dst[0] + srcSliceY * dstStride[0], dstStride[0],
849  srcSliceH, 0, swap, bits_per_sample, c->srcW);
850  break;
851  case AV_PIX_FMT_RGBA64LE:
852  case AV_PIX_FMT_RGBA64BE:
853  gbr16ptopacked16(src201, stride201,
854  dst[0] + srcSliceY * dstStride[0], dstStride[0],
855  srcSliceH, 1, swap, bits_per_sample, c->srcW);
856  break;
857  case AV_PIX_FMT_BGRA64LE:
858  case AV_PIX_FMT_BGRA64BE:
859  gbr16ptopacked16(src102, stride102,
860  dst[0] + srcSliceY * dstStride[0], dstStride[0],
861  srcSliceH, 1, swap, bits_per_sample, c->srcW);
862  break;
863  default:
864  av_log(c, AV_LOG_ERROR,
865  "unsupported planar RGB conversion %s -> %s\n",
866  src_format->name, dst_format->name);
867  }
868 
869  return srcSliceH;
870 }
871 
872 static void gbr24ptopacked24(const uint8_t *src[], int srcStride[],
873  uint8_t *dst, int dstStride, int srcSliceH,
874  int width)
875 {
876  int x, h, i;
877  for (h = 0; h < srcSliceH; h++) {
878  uint8_t *dest = dst + dstStride * h;
879  for (x = 0; x < width; x++) {
880  *dest++ = src[0][x];
881  *dest++ = src[1][x];
882  *dest++ = src[2][x];
883  }
884 
885  for (i = 0; i < 3; i++)
886  src[i] += srcStride[i];
887  }
888 }
889 
890 static void gbr24ptopacked32(const uint8_t *src[], int srcStride[],
891  uint8_t *dst, int dstStride, int srcSliceH,
892  int alpha_first, int width)
893 {
894  int x, h, i;
895  for (h = 0; h < srcSliceH; h++) {
896  uint8_t *dest = dst + dstStride * h;
897 
898  if (alpha_first) {
899  for (x = 0; x < width; x++) {
900  *dest++ = 0xff;
901  *dest++ = src[0][x];
902  *dest++ = src[1][x];
903  *dest++ = src[2][x];
904  }
905  } else {
906  for (x = 0; x < width; x++) {
907  *dest++ = src[0][x];
908  *dest++ = src[1][x];
909  *dest++ = src[2][x];
910  *dest++ = 0xff;
911  }
912  }
913 
914  for (i = 0; i < 3; i++)
915  src[i] += srcStride[i];
916  }
917 }
918 
920  int srcStride[], int srcSliceY, int srcSliceH,
921  uint8_t *dst[], int dstStride[])
922 {
923  int alpha_first = 0;
924  const uint8_t *src102[] = { src[1], src[0], src[2] };
925  const uint8_t *src201[] = { src[2], src[0], src[1] };
926  int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
927  int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
928 
929  if (c->srcFormat != AV_PIX_FMT_GBRP) {
930  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
933  return srcSliceH;
934  }
935 
936  switch (c->dstFormat) {
937  case AV_PIX_FMT_BGR24:
938  gbr24ptopacked24(src102, stride102,
939  dst[0] + srcSliceY * dstStride[0], dstStride[0],
940  srcSliceH, c->srcW);
941  break;
942 
943  case AV_PIX_FMT_RGB24:
944  gbr24ptopacked24(src201, stride201,
945  dst[0] + srcSliceY * dstStride[0], dstStride[0],
946  srcSliceH, c->srcW);
947  break;
948 
949  case AV_PIX_FMT_ARGB:
950  alpha_first = 1;
951  case AV_PIX_FMT_RGBA:
952  gbr24ptopacked32(src201, stride201,
953  dst[0] + srcSliceY * dstStride[0], dstStride[0],
954  srcSliceH, alpha_first, c->srcW);
955  break;
956 
957  case AV_PIX_FMT_ABGR:
958  alpha_first = 1;
959  case AV_PIX_FMT_BGRA:
960  gbr24ptopacked32(src102, stride102,
961  dst[0] + srcSliceY * dstStride[0], dstStride[0],
962  srcSliceH, alpha_first, c->srcW);
963  break;
964 
965  default:
966  av_log(c, AV_LOG_ERROR,
967  "unsupported planar RGB conversion %s -> %s\n",
970  }
971 
972  return srcSliceH;
973 }
974 
976  const uint8_t *src[], int srcStride[],
977  int srcSliceY, int srcSliceH,
978  uint8_t *dst[], int dstStride[])
979 {
980  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
981  dst[0], dstStride[0]);
982  copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->srcW,
983  dst[1], dstStride[1]);
984  copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->srcW,
985  dst[2], dstStride[2]);
986  if (dst[3])
987  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
988 
989  return srcSliceH;
990 }
991 
992 static void packedtogbr24p(const uint8_t *src, int srcStride,
993  uint8_t *dst[], int dstStride[], int srcSliceH,
994  int alpha_first, int inc_size, int width)
995 {
996  uint8_t *dest[3];
997  int x, h;
998 
999  dest[0] = dst[0];
1000  dest[1] = dst[1];
1001  dest[2] = dst[2];
1002 
1003  if (alpha_first)
1004  src++;
1005 
1006  for (h = 0; h < srcSliceH; h++) {
1007  for (x = 0; x < width; x++) {
1008  dest[0][x] = src[0];
1009  dest[1][x] = src[1];
1010  dest[2][x] = src[2];
1011 
1012  src += inc_size;
1013  }
1014  src += srcStride - width * inc_size;
1015  dest[0] += dstStride[0];
1016  dest[1] += dstStride[1];
1017  dest[2] += dstStride[2];
1018  }
1019 }
1020 
1022  int srcStride[], int srcSliceY, int srcSliceH,
1023  uint8_t *dst[], int dstStride[])
1024 {
1025  int alpha_first = 0;
1026  int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1027  int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1028  uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
1029  dst[0] + srcSliceY * dstStride[0],
1030  dst[2] + srcSliceY * dstStride[2] };
1031  uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
1032  dst[0] + srcSliceY * dstStride[0],
1033  dst[1] + srcSliceY * dstStride[1] };
1034 
1035  switch (c->srcFormat) {
1036  case AV_PIX_FMT_RGB24:
1037  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
1038  stride201, srcSliceH, alpha_first, 3, c->srcW);
1039  break;
1040  case AV_PIX_FMT_BGR24:
1041  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
1042  stride102, srcSliceH, alpha_first, 3, c->srcW);
1043  break;
1044  case AV_PIX_FMT_ARGB:
1045  alpha_first = 1;
1046  case AV_PIX_FMT_RGBA:
1047  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
1048  stride201, srcSliceH, alpha_first, 4, c->srcW);
1049  break;
1050  case AV_PIX_FMT_ABGR:
1051  alpha_first = 1;
1052  case AV_PIX_FMT_BGRA:
1053  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
1054  stride102, srcSliceH, alpha_first, 4, c->srcW);
1055  break;
1056  default:
1057  av_log(c, AV_LOG_ERROR,
1058  "unsupported planar RGB conversion %s -> %s\n",
1061  }
1062 
1063  return srcSliceH;
1064 }
1065 
1066 #define BAYER_GBRG
1067 #define BAYER_8
1068 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1069 #include "bayer_template.c"
1070 
1071 #define BAYER_GBRG
1072 #define BAYER_16LE
1073 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1074 #include "bayer_template.c"
1075 
1076 #define BAYER_GBRG
1077 #define BAYER_16BE
1078 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1079 #include "bayer_template.c"
1080 
1081 #define BAYER_GRBG
1082 #define BAYER_8
1083 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1084 #include "bayer_template.c"
1085 
1086 #define BAYER_GRBG
1087 #define BAYER_16LE
1088 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1089 #include "bayer_template.c"
1090 
1091 #define BAYER_GRBG
1092 #define BAYER_16BE
1093 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1094 #include "bayer_template.c"
1095 
1096 #define BAYER_BGGR
1097 #define BAYER_8
1098 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1099 #include "bayer_template.c"
1100 
1101 #define BAYER_BGGR
1102 #define BAYER_16LE
1103 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1104 #include "bayer_template.c"
1105 
1106 #define BAYER_BGGR
1107 #define BAYER_16BE
1108 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1109 #include "bayer_template.c"
1110 
1111 #define BAYER_RGGB
1112 #define BAYER_8
1113 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1114 #include "bayer_template.c"
1115 
1116 #define BAYER_RGGB
1117 #define BAYER_16LE
1118 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1119 #include "bayer_template.c"
1120 
1121 #define BAYER_RGGB
1122 #define BAYER_16BE
1123 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1124 #include "bayer_template.c"
1125 
1126 static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
1127  int srcSliceH, uint8_t* dst[], int dstStride[])
1128 {
1129  uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1130  const uint8_t *srcPtr= src[0];
1131  int i;
1132  void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1133  void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1134 
1135  switch(c->srcFormat) {
1136 #define CASE(pixfmt, prefix) \
1137  case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1138  interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1139  break;
1141  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1142  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1144  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1145  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1147  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1148  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1150  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1151  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1152 #undef CASE
1153  default: return 0;
1154  }
1155 
1156  av_assert0(srcSliceH > 1);
1157 
1158  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1159  srcPtr += 2 * srcStride[0];
1160  dstPtr += 2 * dstStride[0];
1161 
1162  for (i = 2; i < srcSliceH - 2; i += 2) {
1163  interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1164  srcPtr += 2 * srcStride[0];
1165  dstPtr += 2 * dstStride[0];
1166  }
1167 
1168  if (i + 1 == srcSliceH) {
1169  copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->srcW);
1170  } else if (i < srcSliceH)
1171  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1172  return srcSliceH;
1173 }
1174 
1175 static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
1176  int srcSliceH, uint8_t* dst[], int dstStride[])
1177 {
1178  const uint8_t *srcPtr= src[0];
1179  uint8_t *dstY= dst[0] + srcSliceY * dstStride[0];
1180  uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
1181  uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
1182  int i;
1183  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);
1184  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);
1185 
1186  switch(c->srcFormat) {
1187 #define CASE(pixfmt, prefix) \
1188  case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1189  interpolate = bayer_##prefix##_to_yv12_interpolate; \
1190  break;
1192  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1193  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1195  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1196  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1198  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1199  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1201  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1202  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1203 #undef CASE
1204  default: return 0;
1205  }
1206 
1207  av_assert0(srcSliceH > 1);
1208 
1209  copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1210  srcPtr += 2 * srcStride[0];
1211  dstY += 2 * dstStride[0];
1212  dstU += dstStride[1];
1213  dstV += dstStride[1];
1214 
1215  for (i = 2; i < srcSliceH - 2; i += 2) {
1216  interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1217  srcPtr += 2 * srcStride[0];
1218  dstY += 2 * dstStride[0];
1219  dstU += dstStride[1];
1220  dstV += dstStride[1];
1221  }
1222 
1223  if (i + 1 == srcSliceH) {
1224  copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0], c->srcW, c->input_rgb2yuv_table);
1225  } else if (i < srcSliceH)
1226  copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1227  return srcSliceH;
1228 }
1229 
1230 #define isRGBA32(x) ( \
1231  (x) == AV_PIX_FMT_ARGB \
1232  || (x) == AV_PIX_FMT_RGBA \
1233  || (x) == AV_PIX_FMT_BGRA \
1234  || (x) == AV_PIX_FMT_ABGR \
1235  )
1236 
1237 #define isRGBA64(x) ( \
1238  (x) == AV_PIX_FMT_RGBA64LE \
1239  || (x) == AV_PIX_FMT_RGBA64BE \
1240  || (x) == AV_PIX_FMT_BGRA64LE \
1241  || (x) == AV_PIX_FMT_BGRA64BE \
1242  )
1243 
1244 #define isRGB48(x) ( \
1245  (x) == AV_PIX_FMT_RGB48LE \
1246  || (x) == AV_PIX_FMT_RGB48BE \
1247  || (x) == AV_PIX_FMT_BGR48LE \
1248  || (x) == AV_PIX_FMT_BGR48BE \
1249  )
1250 
1251 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
1252 typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int);
1254 {
1255  const enum AVPixelFormat srcFormat = c->srcFormat;
1256  const enum AVPixelFormat dstFormat = c->dstFormat;
1257  const int srcId = c->srcFormatBpp;
1258  const int dstId = c->dstFormatBpp;
1259  rgbConvFn conv = NULL;
1260 
1261 #define IS_NOT_NE(bpp, desc) \
1262  (((bpp + 7) >> 3) == 2 && \
1263  (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1264 
1265 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1266 
1267  if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) {
1268  if ( CONV_IS(ABGR, RGBA)
1269  || CONV_IS(ARGB, BGRA)
1270  || CONV_IS(BGRA, ARGB)
1271  || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210;
1272  else if (CONV_IS(ABGR, ARGB)
1273  || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321;
1274  else if (CONV_IS(ABGR, BGRA)
1275  || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230;
1276  else if (CONV_IS(BGRA, RGBA)
1277  || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103;
1278  else if (CONV_IS(BGRA, ABGR)
1279  || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012;
1280  } else if (isRGB48(srcFormat) && isRGB48(dstFormat)) {
1281  if (CONV_IS(RGB48LE, BGR48LE)
1282  || CONV_IS(BGR48LE, RGB48LE)
1283  || CONV_IS(RGB48BE, BGR48BE)
1284  || CONV_IS(BGR48BE, RGB48BE)) conv = rgb48tobgr48_nobswap;
1285  else if (CONV_IS(RGB48LE, BGR48BE)
1286  || CONV_IS(BGR48LE, RGB48BE)
1287  || CONV_IS(RGB48BE, BGR48LE)
1288  || CONV_IS(BGR48BE, RGB48LE)) conv = rgb48tobgr48_bswap;
1289  } else if (isRGB48(srcFormat) && isRGBA64(dstFormat)) {
1290  if (CONV_IS(RGB48LE, BGRA64LE)
1291  || CONV_IS(BGR48LE, RGBA64LE)
1292  || CONV_IS(RGB48BE, BGRA64BE)
1293  || CONV_IS(BGR48BE, RGBA64BE)) conv = rgb48tobgr64_nobswap;
1294  else if (CONV_IS(RGB48LE, BGRA64BE)
1295  || CONV_IS(BGR48LE, RGBA64BE)
1296  || CONV_IS(RGB48BE, BGRA64LE)
1297  || CONV_IS(BGR48BE, RGBA64LE)) conv = rgb48tobgr64_bswap;
1298  if (CONV_IS(RGB48LE, RGBA64LE)
1299  || CONV_IS(BGR48LE, BGRA64LE)
1300  || CONV_IS(RGB48BE, RGBA64BE)
1301  || CONV_IS(BGR48BE, BGRA64BE)) conv = rgb48to64_nobswap;
1302  else if (CONV_IS(RGB48LE, RGBA64BE)
1303  || CONV_IS(BGR48LE, BGRA64BE)
1304  || CONV_IS(RGB48BE, RGBA64LE)
1305  || CONV_IS(BGR48BE, BGRA64LE)) conv = rgb48to64_bswap;
1306  } else if (isRGBA64(srcFormat) && isRGB48(dstFormat)) {
1307  if (CONV_IS(RGBA64LE, BGR48LE)
1308  || CONV_IS(BGRA64LE, RGB48LE)
1309  || CONV_IS(RGBA64BE, BGR48BE)
1310  || CONV_IS(BGRA64BE, RGB48BE)) conv = rgb64tobgr48_nobswap;
1311  else if (CONV_IS(RGBA64LE, BGR48BE)
1312  || CONV_IS(BGRA64LE, RGB48BE)
1313  || CONV_IS(RGBA64BE, BGR48LE)
1314  || CONV_IS(BGRA64BE, RGB48LE)) conv = rgb64tobgr48_bswap;
1315  else if (CONV_IS(RGBA64LE, RGB48LE)
1316  || CONV_IS(BGRA64LE, BGR48LE)
1317  || CONV_IS(RGBA64BE, RGB48BE)
1318  || CONV_IS(BGRA64BE, BGR48BE)) conv = rgb64to48_nobswap;
1319  else if (CONV_IS(RGBA64LE, RGB48BE)
1320  || CONV_IS(BGRA64LE, BGR48BE)
1321  || CONV_IS(RGBA64BE, RGB48LE)
1322  || CONV_IS(BGRA64BE, BGR48LE)) conv = rgb64to48_bswap;
1323  } else
1324  /* BGR -> BGR */
1325  if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
1326  (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) {
1327  switch (srcId | (dstId << 16)) {
1328  case 0x000F000C: conv = rgb12to15; break;
1329  case 0x000F0010: conv = rgb16to15; break;
1330  case 0x000F0018: conv = rgb24to15; break;
1331  case 0x000F0020: conv = rgb32to15; break;
1332  case 0x0010000F: conv = rgb15to16; break;
1333  case 0x00100018: conv = rgb24to16; break;
1334  case 0x00100020: conv = rgb32to16; break;
1335  case 0x0018000F: conv = rgb15to24; break;
1336  case 0x00180010: conv = rgb16to24; break;
1337  case 0x00180020: conv = rgb32to24; break;
1338  case 0x0020000F: conv = rgb15to32; break;
1339  case 0x00200010: conv = rgb16to32; break;
1340  case 0x00200018: conv = rgb24to32; break;
1341  }
1342  } else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) ||
1343  (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) {
1344  switch (srcId | (dstId << 16)) {
1345  case 0x000C000C: conv = rgb12tobgr12; break;
1346  case 0x000F000F: conv = rgb15tobgr15; break;
1347  case 0x000F0010: conv = rgb16tobgr15; break;
1348  case 0x000F0018: conv = rgb24tobgr15; break;
1349  case 0x000F0020: conv = rgb32tobgr15; break;
1350  case 0x0010000F: conv = rgb15tobgr16; break;
1351  case 0x00100010: conv = rgb16tobgr16; break;
1352  case 0x00100018: conv = rgb24tobgr16; break;
1353  case 0x00100020: conv = rgb32tobgr16; break;
1354  case 0x0018000F: conv = rgb15tobgr24; break;
1355  case 0x00180010: conv = rgb16tobgr24; break;
1356  case 0x00180018: conv = rgb24tobgr24; break;
1357  case 0x00180020: conv = rgb32tobgr24; break;
1358  case 0x0020000F: conv = rgb15tobgr32; break;
1359  case 0x00200010: conv = rgb16tobgr32; break;
1360  case 0x00200018: conv = rgb24tobgr32; break;
1361  }
1362  }
1363 
1364  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) && !isRGBA32(srcFormat) && ALT32_CORR<0)
1365  return NULL;
1366 
1367  // Maintain symmetry between endianness
1368  if (c->flags & SWS_BITEXACT)
1369  if ((dstFormat == AV_PIX_FMT_RGB32 || dstFormat == AV_PIX_FMT_BGR32 ) && !isRGBA32(srcFormat) && ALT32_CORR>0)
1370  return NULL;
1371 
1372  return conv;
1373 }
1374 
1375 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
1376 static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
1377  int srcSliceY, int srcSliceH, uint8_t *dst[],
1378  int dstStride[])
1379 
1380 {
1381  const enum AVPixelFormat srcFormat = c->srcFormat;
1382  const enum AVPixelFormat dstFormat = c->dstFormat;
1383  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
1384  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
1385  const int srcBpp = (c->srcFormatBpp + 7) >> 3;
1386  const int dstBpp = (c->dstFormatBpp + 7) >> 3;
1388 
1389  if (!conv) {
1390  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
1391  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1392  } else {
1393  const uint8_t *srcPtr = src[0];
1394  uint8_t *dstPtr = dst[0];
1395  int src_bswap = IS_NOT_NE(c->srcFormatBpp, desc_src);
1396  int dst_bswap = IS_NOT_NE(c->dstFormatBpp, desc_dst);
1397 
1398  if ((srcFormat == AV_PIX_FMT_RGB32_1 || srcFormat == AV_PIX_FMT_BGR32_1) &&
1399  !isRGBA32(dstFormat))
1400  srcPtr += ALT32_CORR;
1401 
1402  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) &&
1403  !isRGBA32(srcFormat)) {
1404  int i;
1405  av_assert0(ALT32_CORR == 1);
1406  for (i = 0; i < srcSliceH; i++)
1407  dstPtr[dstStride[0] * (srcSliceY + i)] = 255;
1408  dstPtr += ALT32_CORR;
1409  }
1410 
1411  if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1412  !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1413  conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1414  (srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp);
1415  else {
1416  int i, j;
1417  dstPtr += dstStride[0] * srcSliceY;
1418 
1419  for (i = 0; i < srcSliceH; i++) {
1420  if(src_bswap) {
1421  for(j=0; j<c->srcW; j++)
1422  ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]);
1423  conv(c->formatConvBuffer, dstPtr, c->srcW * srcBpp);
1424  }else
1425  conv(srcPtr, dstPtr, c->srcW * srcBpp);
1426  if(dst_bswap)
1427  for(j=0; j<c->srcW; j++)
1428  ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]);
1429  srcPtr += srcStride[0];
1430  dstPtr += dstStride[0];
1431  }
1432  }
1433  }
1434  return srcSliceH;
1435 }
1436 
1438  int srcStride[], int srcSliceY, int srcSliceH,
1439  uint8_t *dst[], int dstStride[])
1440 {
1442  src[0],
1443  dst[0] + srcSliceY * dstStride[0],
1444  dst[1] + (srcSliceY >> 1) * dstStride[1],
1445  dst[2] + (srcSliceY >> 1) * dstStride[2],
1446  c->srcW, srcSliceH,
1447  dstStride[0], dstStride[1], srcStride[0],
1448  c->input_rgb2yuv_table);
1449  if (dst[3])
1450  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
1451  return srcSliceH;
1452 }
1453 
1454 static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
1455  int srcStride[], int srcSliceY, int srcSliceH,
1456  uint8_t *dst[], int dstStride[])
1457 {
1458  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
1459  dst[0], dstStride[0]);
1460 
1461  planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW,
1462  srcSliceH >> 2, srcStride[1], dstStride[1]);
1463  planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW,
1464  srcSliceH >> 2, srcStride[2], dstStride[2]);
1465  if (dst[3])
1466  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
1467  return srcSliceH;
1468 }
1469 
1470 /* unscaled copy like stuff (assumes nearly identical formats) */
1471 static int packedCopyWrapper(SwsContext *c, const uint8_t *src[],
1472  int srcStride[], int srcSliceY, int srcSliceH,
1473  uint8_t *dst[], int dstStride[])
1474 {
1475  if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
1476  memcpy(dst[0] + dstStride[0] * srcSliceY, src[0], srcSliceH * dstStride[0]);
1477  else {
1478  int i;
1479  const uint8_t *srcPtr = src[0];
1480  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1481  int length = 0;
1482 
1483  /* universal length finder */
1484  while (length + c->srcW <= FFABS(dstStride[0]) &&
1485  length + c->srcW <= FFABS(srcStride[0]))
1486  length += c->srcW;
1487  av_assert1(length != 0);
1488 
1489  for (i = 0; i < srcSliceH; i++) {
1490  memcpy(dstPtr, srcPtr, length);
1491  srcPtr += srcStride[0];
1492  dstPtr += dstStride[0];
1493  }
1494  }
1495  return srcSliceH;
1496 }
1497 
1498 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
1499  unsigned shift= src_depth-dst_depth, tmp;\
1500  if (c->dither == SWS_DITHER_NONE) {\
1501  for (i = 0; i < height; i++) {\
1502  for (j = 0; j < length-7; j+=8) {\
1503  dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
1504  dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
1505  dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
1506  dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
1507  dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
1508  dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
1509  dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
1510  dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
1511  }\
1512  for (; j < length; j++) {\
1513  dst[j] = dbswap(bswap(src[j])>>shift);\
1514  }\
1515  dst += dstStride;\
1516  src += srcStride;\
1517  }\
1518  } else if (shiftonly) {\
1519  for (i = 0; i < height; i++) {\
1520  const uint8_t *dither= dithers[shift-1][i&7];\
1521  for (j = 0; j < length-7; j+=8) {\
1522  tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
1523  tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
1524  tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
1525  tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
1526  tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
1527  tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
1528  tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
1529  tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
1530  }\
1531  for (; j < length; j++) {\
1532  tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
1533  }\
1534  dst += dstStride;\
1535  src += srcStride;\
1536  }\
1537  } else {\
1538  for (i = 0; i < height; i++) {\
1539  const uint8_t *dither= dithers[shift-1][i&7];\
1540  for (j = 0; j < length-7; j+=8) {\
1541  tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
1542  tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
1543  tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
1544  tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
1545  tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
1546  tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
1547  tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
1548  tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
1549  }\
1550  for (; j < length; j++) {\
1551  tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
1552  }\
1553  dst += dstStride;\
1554  src += srcStride;\
1555  }\
1556  }
1557 
1558 static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
1559  int srcStride[], int srcSliceY, int srcSliceH,
1560  uint8_t *dst[], int dstStride[])
1561 {
1562  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
1563  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
1564  int plane, i, j;
1565  for (plane = 0; plane < 4; plane++) {
1566  int length = (plane == 0 || plane == 3) ? c->srcW : AV_CEIL_RSHIFT(c->srcW, c->chrDstHSubSample);
1567  int y = (plane == 0 || plane == 3) ? srcSliceY: AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
1568  int height = (plane == 0 || plane == 3) ? srcSliceH: AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
1569  const uint8_t *srcPtr = src[plane];
1570  uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
1571  int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0);
1572 
1573  if (!dst[plane])
1574  continue;
1575  // ignore palette for GRAY8
1576  if (plane == 1 && !dst[2]) continue;
1577  if (!src[plane] || (plane == 1 && !src[2])) {
1578  if (is16BPS(c->dstFormat) || isNBPS(c->dstFormat)) {
1579  fillPlane16(dst[plane], dstStride[plane], length, height, y,
1580  plane == 3, desc_dst->comp[plane].depth,
1581  isBE(c->dstFormat));
1582  } else {
1583  fillPlane(dst[plane], dstStride[plane], length, height, y,
1584  (plane == 3) ? 255 : 128);
1585  }
1586  } else {
1587  if(isNBPS(c->srcFormat) || isNBPS(c->dstFormat)
1588  || (is16BPS(c->srcFormat) != is16BPS(c->dstFormat))
1589  ) {
1590  const int src_depth = desc_src->comp[plane].depth;
1591  const int dst_depth = desc_dst->comp[plane].depth;
1592  const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
1593  uint16_t *dstPtr2 = (uint16_t*)dstPtr;
1594 
1595  if (dst_depth == 8) {
1596  if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
1597  DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
1598  } else {
1599  DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, )
1600  }
1601  } else if (src_depth == 8) {
1602  for (i = 0; i < height; i++) {
1603  #define COPY816(w)\
1604  if (shiftonly) {\
1605  for (j = 0; j < length; j++)\
1606  w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
1607  } else {\
1608  for (j = 0; j < length; j++)\
1609  w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
1610  (srcPtr[j]>>(2*8-dst_depth)));\
1611  }
1612  if(isBE(c->dstFormat)){
1613  COPY816(AV_WB16)
1614  } else {
1615  COPY816(AV_WL16)
1616  }
1617  dstPtr2 += dstStride[plane]/2;
1618  srcPtr += srcStride[plane];
1619  }
1620  } else if (src_depth <= dst_depth) {
1621  for (i = 0; i < height; i++) {
1622  j = 0;
1623  if(isBE(c->srcFormat) == HAVE_BIGENDIAN &&
1624  isBE(c->dstFormat) == HAVE_BIGENDIAN &&
1625  shiftonly) {
1626  unsigned shift = dst_depth - src_depth;
1627 #if HAVE_FAST_64BIT
1628 #define FAST_COPY_UP(shift) \
1629  for (; j < length - 3; j += 4) { \
1630  uint64_t v = AV_RN64A(srcPtr2 + j); \
1631  AV_WN64A(dstPtr2 + j, v << shift); \
1632  }
1633 #else
1634 #define FAST_COPY_UP(shift) \
1635  for (; j < length - 1; j += 2) { \
1636  uint32_t v = AV_RN32A(srcPtr2 + j); \
1637  AV_WN32A(dstPtr2 + j, v << shift); \
1638  }
1639 #endif
1640  switch (shift)
1641  {
1642  case 6: FAST_COPY_UP(6); break;
1643  case 7: FAST_COPY_UP(7); break;
1644  }
1645  }
1646 #define COPY_UP(r,w) \
1647  if(shiftonly){\
1648  for (; j < length; j++){ \
1649  unsigned int v= r(&srcPtr2[j]);\
1650  w(&dstPtr2[j], v<<(dst_depth-src_depth));\
1651  }\
1652  }else{\
1653  for (; j < length; j++){ \
1654  unsigned int v= r(&srcPtr2[j]);\
1655  w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
1656  (v>>(2*src_depth-dst_depth)));\
1657  }\
1658  }
1659  if(isBE(c->srcFormat)){
1660  if(isBE(c->dstFormat)){
1662  } else {
1664  }
1665  } else {
1666  if(isBE(c->dstFormat)){
1668  } else {
1670  }
1671  }
1672  dstPtr2 += dstStride[plane]/2;
1673  srcPtr2 += srcStride[plane]/2;
1674  }
1675  } else {
1676  if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
1677  if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
1678  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
1679  } else {
1680  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16)
1681  }
1682  }else{
1683  if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
1684  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, )
1685  } else {
1686  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16)
1687  }
1688  }
1689  }
1690  } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) &&
1691  isBE(c->srcFormat) != isBE(c->dstFormat)) {
1692 
1693  for (i = 0; i < height; i++) {
1694  for (j = 0; j < length; j++)
1695  ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]);
1696  srcPtr += srcStride[plane];
1697  dstPtr += dstStride[plane];
1698  }
1699  } else if (dstStride[plane] == srcStride[plane] &&
1700  srcStride[plane] > 0 && srcStride[plane] == length) {
1701  memcpy(dst[plane] + dstStride[plane] * y, src[plane],
1702  height * dstStride[plane]);
1703  } else {
1704  if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat))
1705  length *= 2;
1706  else if (desc_src->comp[0].depth == 1)
1707  length >>= 3; // monowhite/black
1708  for (i = 0; i < height; i++) {
1709  memcpy(dstPtr, srcPtr, length);
1710  srcPtr += srcStride[plane];
1711  dstPtr += dstStride[plane];
1712  }
1713  }
1714  }
1715  }
1716  return srcSliceH;
1717 }
1718 
1719 
1720 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
1721  ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
1722  (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
1723 
1724 
1726 {
1727  const enum AVPixelFormat srcFormat = c->srcFormat;
1728  const enum AVPixelFormat dstFormat = c->dstFormat;
1729  const int flags = c->flags;
1730  const int dstH = c->dstH;
1731  int needsDither;
1732 
1733  needsDither = isAnyRGB(dstFormat) &&
1734  c->dstFormatBpp < 24 &&
1735  (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat)));
1736 
1737  /* yv12_to_nv12 */
1738  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
1739  (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)) {
1741  }
1742  /* nv12_to_yv12 */
1743  if (dstFormat == AV_PIX_FMT_YUV420P &&
1744  (srcFormat == AV_PIX_FMT_NV12 || srcFormat == AV_PIX_FMT_NV21)) {
1746  }
1747  /* yuv2bgr */
1748  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P ||
1749  srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) &&
1750  !(flags & SWS_ACCURATE_RND) && (c->dither == SWS_DITHER_BAYER || c->dither == SWS_DITHER_AUTO) && !(dstH & 1)) {
1752  }
1753  /* yuv420p1x_to_p01x */
1754  if ((srcFormat == AV_PIX_FMT_YUV420P10 || srcFormat == AV_PIX_FMT_YUVA420P10 ||
1755  srcFormat == AV_PIX_FMT_YUV420P12 ||
1756  srcFormat == AV_PIX_FMT_YUV420P14 ||
1757  srcFormat == AV_PIX_FMT_YUV420P16 || srcFormat == AV_PIX_FMT_YUVA420P16) &&
1758  (dstFormat == AV_PIX_FMT_P010 || dstFormat == AV_PIX_FMT_P016)) {
1760  }
1761  /* yuv420p_to_p01xle */
1762  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
1763  (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P016LE)) {
1765  }
1766 
1767  if (srcFormat == AV_PIX_FMT_YUV410P && !(dstH & 3) &&
1768  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
1769  !(flags & SWS_BITEXACT)) {
1771  }
1772 
1773  /* bgr24toYV12 */
1774  if (srcFormat == AV_PIX_FMT_BGR24 &&
1775  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
1776  !(flags & SWS_ACCURATE_RND))
1778 
1779  /* RGB/BGR -> RGB/BGR (no dither needed forms) */
1780  if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)
1781  && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
1782  c->swscale = rgbToRgbWrapper;
1783 
1784  /* RGB to planar RGB */
1785  if ((srcFormat == AV_PIX_FMT_GBRP && dstFormat == AV_PIX_FMT_GBRAP) ||
1786  (srcFormat == AV_PIX_FMT_GBRAP && dstFormat == AV_PIX_FMT_GBRP))
1788 
1789 #define isByteRGB(f) ( \
1790  f == AV_PIX_FMT_RGB32 || \
1791  f == AV_PIX_FMT_RGB32_1 || \
1792  f == AV_PIX_FMT_RGB24 || \
1793  f == AV_PIX_FMT_BGR32 || \
1794  f == AV_PIX_FMT_BGR32_1 || \
1795  f == AV_PIX_FMT_BGR24)
1796 
1797  if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
1799 
1800  if ((srcFormat == AV_PIX_FMT_RGB48LE || srcFormat == AV_PIX_FMT_RGB48BE ||
1801  srcFormat == AV_PIX_FMT_BGR48LE || srcFormat == AV_PIX_FMT_BGR48BE ||
1802  srcFormat == AV_PIX_FMT_RGBA64LE || srcFormat == AV_PIX_FMT_RGBA64BE ||
1803  srcFormat == AV_PIX_FMT_BGRA64LE || srcFormat == AV_PIX_FMT_BGRA64BE) &&
1804  (dstFormat == AV_PIX_FMT_GBRP9LE || dstFormat == AV_PIX_FMT_GBRP9BE ||
1805  dstFormat == AV_PIX_FMT_GBRP10LE || dstFormat == AV_PIX_FMT_GBRP10BE ||
1806  dstFormat == AV_PIX_FMT_GBRP12LE || dstFormat == AV_PIX_FMT_GBRP12BE ||
1807  dstFormat == AV_PIX_FMT_GBRP14LE || dstFormat == AV_PIX_FMT_GBRP14BE ||
1808  dstFormat == AV_PIX_FMT_GBRP16LE || dstFormat == AV_PIX_FMT_GBRP16BE ||
1809  dstFormat == AV_PIX_FMT_GBRAP12LE || dstFormat == AV_PIX_FMT_GBRAP12BE ||
1810  dstFormat == AV_PIX_FMT_GBRAP16LE || dstFormat == AV_PIX_FMT_GBRAP16BE ))
1812 
1813  if ((srcFormat == AV_PIX_FMT_GBRP9LE || srcFormat == AV_PIX_FMT_GBRP9BE ||
1814  srcFormat == AV_PIX_FMT_GBRP16LE || srcFormat == AV_PIX_FMT_GBRP16BE ||
1815  srcFormat == AV_PIX_FMT_GBRP10LE || srcFormat == AV_PIX_FMT_GBRP10BE ||
1816  srcFormat == AV_PIX_FMT_GBRP12LE || srcFormat == AV_PIX_FMT_GBRP12BE ||
1817  srcFormat == AV_PIX_FMT_GBRP14LE || srcFormat == AV_PIX_FMT_GBRP14BE ||
1818  srcFormat == AV_PIX_FMT_GBRAP12LE || srcFormat == AV_PIX_FMT_GBRAP12BE ||
1819  srcFormat == AV_PIX_FMT_GBRAP16LE || srcFormat == AV_PIX_FMT_GBRAP16BE) &&
1820  (dstFormat == AV_PIX_FMT_RGB48LE || dstFormat == AV_PIX_FMT_RGB48BE ||
1821  dstFormat == AV_PIX_FMT_BGR48LE || dstFormat == AV_PIX_FMT_BGR48BE ||
1822  dstFormat == AV_PIX_FMT_RGBA64LE || dstFormat == AV_PIX_FMT_RGBA64BE ||
1823  dstFormat == AV_PIX_FMT_BGRA64LE || dstFormat == AV_PIX_FMT_BGRA64BE))
1825 
1826  if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth == 8 &&
1827  isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRP)
1829 
1830  if (isBayer(srcFormat)) {
1831  if (dstFormat == AV_PIX_FMT_RGB24)
1833  else if (dstFormat == AV_PIX_FMT_YUV420P)
1835  else if (!isBayer(dstFormat)) {
1836  av_log(c, AV_LOG_ERROR, "unsupported bayer conversion\n");
1837  av_assert0(0);
1838  }
1839  }
1840 
1841  /* bswap 16 bits per pixel/component packed formats */
1842  if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_BGGR16) ||
1843  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_RGGB16) ||
1844  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GBRG16) ||
1845  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GRBG16) ||
1846  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR444) ||
1847  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR48) ||
1848  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
1849  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR555) ||
1850  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR565) ||
1851  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
1852  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY9) ||
1853  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY10) ||
1854  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY12) ||
1855  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY16) ||
1856  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YA16) ||
1857  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_AYUV64) ||
1858  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP9) ||
1859  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP10) ||
1860  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP12) ||
1861  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP14) ||
1862  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP16) ||
1863  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP12) ||
1864  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP16) ||
1865  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB444) ||
1866  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB48) ||
1867  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
1868  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB555) ||
1869  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB565) ||
1870  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
1871  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XYZ12) ||
1872  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P9) ||
1873  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P10) ||
1874  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P12) ||
1875  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P14) ||
1876  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P16) ||
1877  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P9) ||
1878  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P10) ||
1879  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P12) ||
1880  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P14) ||
1881  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P16) ||
1882  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P10) ||
1883  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P12) ||
1884  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P9) ||
1885  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P10) ||
1886  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P12) ||
1887  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P14) ||
1888  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P16))
1890 
1891  if (usePal(srcFormat) && isByteRGB(dstFormat))
1892  c->swscale = palToRgbWrapper;
1893 
1894  if (srcFormat == AV_PIX_FMT_YUV422P) {
1895  if (dstFormat == AV_PIX_FMT_YUYV422)
1897  else if (dstFormat == AV_PIX_FMT_UYVY422)
1899  }
1900 
1901  /* LQ converters if -sws 0 or -sws 4*/
1902  if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) {
1903  /* yv12_to_yuy2 */
1904  if (srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) {
1905  if (dstFormat == AV_PIX_FMT_YUYV422)
1907  else if (dstFormat == AV_PIX_FMT_UYVY422)
1909  }
1910  }
1911  if (srcFormat == AV_PIX_FMT_YUYV422 &&
1912  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
1914  if (srcFormat == AV_PIX_FMT_UYVY422 &&
1915  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
1917  if (srcFormat == AV_PIX_FMT_YUYV422 && dstFormat == AV_PIX_FMT_YUV422P)
1919  if (srcFormat == AV_PIX_FMT_UYVY422 && dstFormat == AV_PIX_FMT_YUV422P)
1921 
1922 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
1923  /* simple copy */
1924  if ( srcFormat == dstFormat ||
1925  (srcFormat == AV_PIX_FMT_YUVA420P && dstFormat == AV_PIX_FMT_YUV420P) ||
1926  (srcFormat == AV_PIX_FMT_YUV420P && dstFormat == AV_PIX_FMT_YUVA420P) ||
1927  (isPlanarYUV(srcFormat) && isPlanarGray(dstFormat)) ||
1928  (isPlanarYUV(dstFormat) && isPlanarGray(srcFormat)) ||
1929  (isPlanarGray(dstFormat) && isPlanarGray(srcFormat)) ||
1930  (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) &&
1933  !isSemiPlanarYUV(srcFormat) && !isSemiPlanarYUV(dstFormat)))
1934  {
1935  if (isPacked(c->srcFormat))
1937  else /* Planar YUV or gray */
1939  }
1940 
1941  if (ARCH_PPC)
1943  if (ARCH_ARM)
1945  if (ARCH_AARCH64)
1947 }
1948 
1949 /* Convert the palette to the same packed 32-bit format as the palette */
1951  int num_pixels, const uint8_t *palette)
1952 {
1953  int i;
1954 
1955  for (i = 0; i < num_pixels; i++)
1956  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
1957 }
1958 
1959 /* Palette format: ABCD -> dst format: ABC */
1961  int num_pixels, const uint8_t *palette)
1962 {
1963  int i;
1964 
1965  for (i = 0; i < num_pixels; i++) {
1966  //FIXME slow?
1967  dst[0] = palette[src[i] * 4 + 0];
1968  dst[1] = palette[src[i] * 4 + 1];
1969  dst[2] = palette[src[i] * 4 + 2];
1970  dst += 3;
1971  }
1972 }
#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
#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:182
uint32_t pal_rgb[256]
void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:314
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:81
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:86
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
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:237
#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:113
#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:73
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
void(* shuffle_bytes_3210)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:58
#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
#define AV_PIX_FMT_P016
Definition: pixfmt.h:414
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:104
#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:107
#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:181
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:69
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:223
#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_PIX_FMT_YUVA420P16
Definition: pixfmt.h:406
#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:65
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:88
static rgbConvFn findRgbConvFn(SwsContext *c)
static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
#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
static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt)
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:88
static const uint8_t dithers[8][8][8]
static int planarToP01xWrapper(SwsContext *c, const uint8_t *src8[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam8[], int dstStride[])
#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:293
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
void(* shuffle_bytes_1230)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:56
#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:204
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
void(* shuffle_bytes_3012)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:57
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:144
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:162
#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)
int shift
Number of least significant bits that must be shifted away to get the value.
Definition: pixdesc.h:53
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:303
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:61
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:110
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)
#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:257
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:91
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:247
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:279