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 bswap_16bpc(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 
919 static void gbraptopacked32(const uint8_t *src[], int srcStride[],
920  uint8_t *dst, int dstStride, int srcSliceH,
921  int alpha_first, int width)
922 {
923  int x, h, i;
924  for (h = 0; h < srcSliceH; h++) {
925  uint8_t *dest = dst + dstStride * h;
926 
927  if (alpha_first) {
928  for (x = 0; x < width; x++) {
929  *dest++ = src[3][x];
930  *dest++ = src[0][x];
931  *dest++ = src[1][x];
932  *dest++ = src[2][x];
933  }
934  } else {
935  for (x = 0; x < width; x++) {
936  *dest++ = src[0][x];
937  *dest++ = src[1][x];
938  *dest++ = src[2][x];
939  *dest++ = src[3][x];
940  }
941  }
942 
943  for (i = 0; i < 4; i++)
944  src[i] += srcStride[i];
945  }
946 }
947 
949  int srcStride[], int srcSliceY, int srcSliceH,
950  uint8_t *dst[], int dstStride[])
951 {
952  int alpha_first = 0;
953  const uint8_t *src102[] = { src[1], src[0], src[2], src[3] };
954  const uint8_t *src201[] = { src[2], src[0], src[1], src[3] };
955  int stride102[] = { srcStride[1], srcStride[0], srcStride[2], srcStride[3] };
956  int stride201[] = { srcStride[2], srcStride[0], srcStride[1], srcStride[3] };
957 
958  if (c->srcFormat != AV_PIX_FMT_GBRAP) {
959  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
962  return srcSliceH;
963  }
964 
965  switch (c->dstFormat) {
966  case AV_PIX_FMT_BGR24:
967  gbr24ptopacked24(src102, stride102,
968  dst[0] + srcSliceY * dstStride[0], dstStride[0],
969  srcSliceH, c->srcW);
970  break;
971 
972  case AV_PIX_FMT_RGB24:
973  gbr24ptopacked24(src201, stride201,
974  dst[0] + srcSliceY * dstStride[0], dstStride[0],
975  srcSliceH, c->srcW);
976  break;
977 
978  case AV_PIX_FMT_ARGB:
979  alpha_first = 1;
980  case AV_PIX_FMT_RGBA:
981  gbraptopacked32(src201, stride201,
982  dst[0] + srcSliceY * dstStride[0], dstStride[0],
983  srcSliceH, alpha_first, c->srcW);
984  break;
985 
986  case AV_PIX_FMT_ABGR:
987  alpha_first = 1;
988  case AV_PIX_FMT_BGRA:
989  gbraptopacked32(src102, stride102,
990  dst[0] + srcSliceY * dstStride[0], dstStride[0],
991  srcSliceH, alpha_first, c->srcW);
992  break;
993 
994  default:
995  av_log(c, AV_LOG_ERROR,
996  "unsupported planar RGB conversion %s -> %s\n",
999  }
1000 
1001  return srcSliceH;
1002 }
1003 
1005  int srcStride[], int srcSliceY, int srcSliceH,
1006  uint8_t *dst[], int dstStride[])
1007 {
1008  int alpha_first = 0;
1009  const uint8_t *src102[] = { src[1], src[0], src[2] };
1010  const uint8_t *src201[] = { src[2], src[0], src[1] };
1011  int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
1012  int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
1013 
1014  if (c->srcFormat != AV_PIX_FMT_GBRP) {
1015  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
1018  return srcSliceH;
1019  }
1020 
1021  switch (c->dstFormat) {
1022  case AV_PIX_FMT_BGR24:
1023  gbr24ptopacked24(src102, stride102,
1024  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1025  srcSliceH, c->srcW);
1026  break;
1027 
1028  case AV_PIX_FMT_RGB24:
1029  gbr24ptopacked24(src201, stride201,
1030  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1031  srcSliceH, c->srcW);
1032  break;
1033 
1034  case AV_PIX_FMT_ARGB:
1035  alpha_first = 1;
1036  case AV_PIX_FMT_RGBA:
1037  gbr24ptopacked32(src201, stride201,
1038  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1039  srcSliceH, alpha_first, c->srcW);
1040  break;
1041 
1042  case AV_PIX_FMT_ABGR:
1043  alpha_first = 1;
1044  case AV_PIX_FMT_BGRA:
1045  gbr24ptopacked32(src102, stride102,
1046  dst[0] + srcSliceY * dstStride[0], dstStride[0],
1047  srcSliceH, alpha_first, c->srcW);
1048  break;
1049 
1050  default:
1051  av_log(c, AV_LOG_ERROR,
1052  "unsupported planar RGB conversion %s -> %s\n",
1055  }
1056 
1057  return srcSliceH;
1058 }
1059 
1061  const uint8_t *src[], int srcStride[],
1062  int srcSliceY, int srcSliceH,
1063  uint8_t *dst[], int dstStride[])
1064 {
1065  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
1066  dst[0], dstStride[0]);
1067  copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->srcW,
1068  dst[1], dstStride[1]);
1069  copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->srcW,
1070  dst[2], dstStride[2]);
1071  if (dst[3])
1072  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
1073 
1074  return srcSliceH;
1075 }
1076 
1077 static void packedtogbr24p(const uint8_t *src, int srcStride,
1078  uint8_t *dst[], int dstStride[], int srcSliceH,
1079  int alpha_first, int inc_size, int width)
1080 {
1081  uint8_t *dest[3];
1082  int x, h;
1083 
1084  dest[0] = dst[0];
1085  dest[1] = dst[1];
1086  dest[2] = dst[2];
1087 
1088  if (alpha_first)
1089  src++;
1090 
1091  for (h = 0; h < srcSliceH; h++) {
1092  for (x = 0; x < width; x++) {
1093  dest[0][x] = src[0];
1094  dest[1][x] = src[1];
1095  dest[2][x] = src[2];
1096 
1097  src += inc_size;
1098  }
1099  src += srcStride - width * inc_size;
1100  dest[0] += dstStride[0];
1101  dest[1] += dstStride[1];
1102  dest[2] += dstStride[2];
1103  }
1104 }
1105 
1107  int srcStride[], int srcSliceY, int srcSliceH,
1108  uint8_t *dst[], int dstStride[])
1109 {
1110  int alpha_first = 0;
1111  int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
1112  int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
1113  uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
1114  dst[0] + srcSliceY * dstStride[0],
1115  dst[2] + srcSliceY * dstStride[2] };
1116  uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
1117  dst[0] + srcSliceY * dstStride[0],
1118  dst[1] + srcSliceY * dstStride[1] };
1119 
1120  switch (c->srcFormat) {
1121  case AV_PIX_FMT_RGB24:
1122  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
1123  stride201, srcSliceH, alpha_first, 3, c->srcW);
1124  break;
1125  case AV_PIX_FMT_BGR24:
1126  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
1127  stride102, srcSliceH, alpha_first, 3, c->srcW);
1128  break;
1129  case AV_PIX_FMT_ARGB:
1130  alpha_first = 1;
1131  case AV_PIX_FMT_RGBA:
1132  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
1133  stride201, srcSliceH, alpha_first, 4, c->srcW);
1134  break;
1135  case AV_PIX_FMT_ABGR:
1136  alpha_first = 1;
1137  case AV_PIX_FMT_BGRA:
1138  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
1139  stride102, srcSliceH, alpha_first, 4, c->srcW);
1140  break;
1141  default:
1142  av_log(c, AV_LOG_ERROR,
1143  "unsupported planar RGB conversion %s -> %s\n",
1146  }
1147 
1148  return srcSliceH;
1149 }
1150 
1151 #define BAYER_GBRG
1152 #define BAYER_8
1153 #define BAYER_RENAME(x) bayer_gbrg8_to_##x
1154 #include "bayer_template.c"
1155 
1156 #define BAYER_GBRG
1157 #define BAYER_16LE
1158 #define BAYER_RENAME(x) bayer_gbrg16le_to_##x
1159 #include "bayer_template.c"
1160 
1161 #define BAYER_GBRG
1162 #define BAYER_16BE
1163 #define BAYER_RENAME(x) bayer_gbrg16be_to_##x
1164 #include "bayer_template.c"
1165 
1166 #define BAYER_GRBG
1167 #define BAYER_8
1168 #define BAYER_RENAME(x) bayer_grbg8_to_##x
1169 #include "bayer_template.c"
1170 
1171 #define BAYER_GRBG
1172 #define BAYER_16LE
1173 #define BAYER_RENAME(x) bayer_grbg16le_to_##x
1174 #include "bayer_template.c"
1175 
1176 #define BAYER_GRBG
1177 #define BAYER_16BE
1178 #define BAYER_RENAME(x) bayer_grbg16be_to_##x
1179 #include "bayer_template.c"
1180 
1181 #define BAYER_BGGR
1182 #define BAYER_8
1183 #define BAYER_RENAME(x) bayer_bggr8_to_##x
1184 #include "bayer_template.c"
1185 
1186 #define BAYER_BGGR
1187 #define BAYER_16LE
1188 #define BAYER_RENAME(x) bayer_bggr16le_to_##x
1189 #include "bayer_template.c"
1190 
1191 #define BAYER_BGGR
1192 #define BAYER_16BE
1193 #define BAYER_RENAME(x) bayer_bggr16be_to_##x
1194 #include "bayer_template.c"
1195 
1196 #define BAYER_RGGB
1197 #define BAYER_8
1198 #define BAYER_RENAME(x) bayer_rggb8_to_##x
1199 #include "bayer_template.c"
1200 
1201 #define BAYER_RGGB
1202 #define BAYER_16LE
1203 #define BAYER_RENAME(x) bayer_rggb16le_to_##x
1204 #include "bayer_template.c"
1205 
1206 #define BAYER_RGGB
1207 #define BAYER_16BE
1208 #define BAYER_RENAME(x) bayer_rggb16be_to_##x
1209 #include "bayer_template.c"
1210 
1211 static int bayer_to_rgb24_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
1212  int srcSliceH, uint8_t* dst[], int dstStride[])
1213 {
1214  uint8_t *dstPtr= dst[0] + srcSliceY * dstStride[0];
1215  const uint8_t *srcPtr= src[0];
1216  int i;
1217  void (*copy) (const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1218  void (*interpolate)(const uint8_t *src, int src_stride, uint8_t *dst, int dst_stride, int width);
1219 
1220  switch(c->srcFormat) {
1221 #define CASE(pixfmt, prefix) \
1222  case pixfmt: copy = bayer_##prefix##_to_rgb24_copy; \
1223  interpolate = bayer_##prefix##_to_rgb24_interpolate; \
1224  break;
1226  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1227  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1229  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1230  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1232  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1233  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1235  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1236  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1237 #undef CASE
1238  default: return 0;
1239  }
1240 
1241  av_assert0(srcSliceH > 1);
1242 
1243  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1244  srcPtr += 2 * srcStride[0];
1245  dstPtr += 2 * dstStride[0];
1246 
1247  for (i = 2; i < srcSliceH - 2; i += 2) {
1248  interpolate(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1249  srcPtr += 2 * srcStride[0];
1250  dstPtr += 2 * dstStride[0];
1251  }
1252 
1253  if (i + 1 == srcSliceH) {
1254  copy(srcPtr, -srcStride[0], dstPtr, -dstStride[0], c->srcW);
1255  } else if (i < srcSliceH)
1256  copy(srcPtr, srcStride[0], dstPtr, dstStride[0], c->srcW);
1257  return srcSliceH;
1258 }
1259 
1260 static int bayer_to_yv12_wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY,
1261  int srcSliceH, uint8_t* dst[], int dstStride[])
1262 {
1263  const uint8_t *srcPtr= src[0];
1264  uint8_t *dstY= dst[0] + srcSliceY * dstStride[0];
1265  uint8_t *dstU= dst[1] + srcSliceY * dstStride[1] / 2;
1266  uint8_t *dstV= dst[2] + srcSliceY * dstStride[2] / 2;
1267  int i;
1268  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);
1269  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);
1270 
1271  switch(c->srcFormat) {
1272 #define CASE(pixfmt, prefix) \
1273  case pixfmt: copy = bayer_##prefix##_to_yv12_copy; \
1274  interpolate = bayer_##prefix##_to_yv12_interpolate; \
1275  break;
1277  CASE(AV_PIX_FMT_BAYER_BGGR16LE, bggr16le)
1278  CASE(AV_PIX_FMT_BAYER_BGGR16BE, bggr16be)
1280  CASE(AV_PIX_FMT_BAYER_RGGB16LE, rggb16le)
1281  CASE(AV_PIX_FMT_BAYER_RGGB16BE, rggb16be)
1283  CASE(AV_PIX_FMT_BAYER_GBRG16LE, gbrg16le)
1284  CASE(AV_PIX_FMT_BAYER_GBRG16BE, gbrg16be)
1286  CASE(AV_PIX_FMT_BAYER_GRBG16LE, grbg16le)
1287  CASE(AV_PIX_FMT_BAYER_GRBG16BE, grbg16be)
1288 #undef CASE
1289  default: return 0;
1290  }
1291 
1292  av_assert0(srcSliceH > 1);
1293 
1294  copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1295  srcPtr += 2 * srcStride[0];
1296  dstY += 2 * dstStride[0];
1297  dstU += dstStride[1];
1298  dstV += dstStride[1];
1299 
1300  for (i = 2; i < srcSliceH - 2; i += 2) {
1301  interpolate(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1302  srcPtr += 2 * srcStride[0];
1303  dstY += 2 * dstStride[0];
1304  dstU += dstStride[1];
1305  dstV += dstStride[1];
1306  }
1307 
1308  if (i + 1 == srcSliceH) {
1309  copy(srcPtr, -srcStride[0], dstY, dstU, dstV, -dstStride[0], c->srcW, c->input_rgb2yuv_table);
1310  } else if (i < srcSliceH)
1311  copy(srcPtr, srcStride[0], dstY, dstU, dstV, dstStride[0], c->srcW, c->input_rgb2yuv_table);
1312  return srcSliceH;
1313 }
1314 
1315 #define isRGBA32(x) ( \
1316  (x) == AV_PIX_FMT_ARGB \
1317  || (x) == AV_PIX_FMT_RGBA \
1318  || (x) == AV_PIX_FMT_BGRA \
1319  || (x) == AV_PIX_FMT_ABGR \
1320  )
1321 
1322 #define isRGBA64(x) ( \
1323  (x) == AV_PIX_FMT_RGBA64LE \
1324  || (x) == AV_PIX_FMT_RGBA64BE \
1325  || (x) == AV_PIX_FMT_BGRA64LE \
1326  || (x) == AV_PIX_FMT_BGRA64BE \
1327  )
1328 
1329 #define isRGB48(x) ( \
1330  (x) == AV_PIX_FMT_RGB48LE \
1331  || (x) == AV_PIX_FMT_RGB48BE \
1332  || (x) == AV_PIX_FMT_BGR48LE \
1333  || (x) == AV_PIX_FMT_BGR48BE \
1334  )
1335 
1336 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
1337 typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int);
1339 {
1340  const enum AVPixelFormat srcFormat = c->srcFormat;
1341  const enum AVPixelFormat dstFormat = c->dstFormat;
1342  const int srcId = c->srcFormatBpp;
1343  const int dstId = c->dstFormatBpp;
1344  rgbConvFn conv = NULL;
1345 
1346 #define IS_NOT_NE(bpp, desc) \
1347  (((bpp + 7) >> 3) == 2 && \
1348  (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
1349 
1350 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
1351 
1352  if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) {
1353  if ( CONV_IS(ABGR, RGBA)
1354  || CONV_IS(ARGB, BGRA)
1355  || CONV_IS(BGRA, ARGB)
1356  || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210;
1357  else if (CONV_IS(ABGR, ARGB)
1358  || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321;
1359  else if (CONV_IS(ABGR, BGRA)
1360  || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230;
1361  else if (CONV_IS(BGRA, RGBA)
1362  || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103;
1363  else if (CONV_IS(BGRA, ABGR)
1364  || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012;
1365  } else if (isRGB48(srcFormat) && isRGB48(dstFormat)) {
1366  if (CONV_IS(RGB48LE, BGR48LE)
1367  || CONV_IS(BGR48LE, RGB48LE)
1368  || CONV_IS(RGB48BE, BGR48BE)
1369  || CONV_IS(BGR48BE, RGB48BE)) conv = rgb48tobgr48_nobswap;
1370  else if (CONV_IS(RGB48LE, BGR48BE)
1371  || CONV_IS(BGR48LE, RGB48BE)
1372  || CONV_IS(RGB48BE, BGR48LE)
1373  || CONV_IS(BGR48BE, RGB48LE)) conv = rgb48tobgr48_bswap;
1374  } else if (isRGB48(srcFormat) && isRGBA64(dstFormat)) {
1375  if (CONV_IS(RGB48LE, BGRA64LE)
1376  || CONV_IS(BGR48LE, RGBA64LE)
1377  || CONV_IS(RGB48BE, BGRA64BE)
1378  || CONV_IS(BGR48BE, RGBA64BE)) conv = rgb48tobgr64_nobswap;
1379  else if (CONV_IS(RGB48LE, BGRA64BE)
1380  || CONV_IS(BGR48LE, RGBA64BE)
1381  || CONV_IS(RGB48BE, BGRA64LE)
1382  || CONV_IS(BGR48BE, RGBA64LE)) conv = rgb48tobgr64_bswap;
1383  if (CONV_IS(RGB48LE, RGBA64LE)
1384  || CONV_IS(BGR48LE, BGRA64LE)
1385  || CONV_IS(RGB48BE, RGBA64BE)
1386  || CONV_IS(BGR48BE, BGRA64BE)) conv = rgb48to64_nobswap;
1387  else if (CONV_IS(RGB48LE, RGBA64BE)
1388  || CONV_IS(BGR48LE, BGRA64BE)
1389  || CONV_IS(RGB48BE, RGBA64LE)
1390  || CONV_IS(BGR48BE, BGRA64LE)) conv = rgb48to64_bswap;
1391  } else if (isRGBA64(srcFormat) && isRGB48(dstFormat)) {
1392  if (CONV_IS(RGBA64LE, BGR48LE)
1393  || CONV_IS(BGRA64LE, RGB48LE)
1394  || CONV_IS(RGBA64BE, BGR48BE)
1395  || CONV_IS(BGRA64BE, RGB48BE)) conv = rgb64tobgr48_nobswap;
1396  else if (CONV_IS(RGBA64LE, BGR48BE)
1397  || CONV_IS(BGRA64LE, RGB48BE)
1398  || CONV_IS(RGBA64BE, BGR48LE)
1399  || CONV_IS(BGRA64BE, RGB48LE)) conv = rgb64tobgr48_bswap;
1400  else if (CONV_IS(RGBA64LE, RGB48LE)
1401  || CONV_IS(BGRA64LE, BGR48LE)
1402  || CONV_IS(RGBA64BE, RGB48BE)
1403  || CONV_IS(BGRA64BE, BGR48BE)) conv = rgb64to48_nobswap;
1404  else if (CONV_IS(RGBA64LE, RGB48BE)
1405  || CONV_IS(BGRA64LE, BGR48BE)
1406  || CONV_IS(RGBA64BE, RGB48LE)
1407  || CONV_IS(BGRA64BE, BGR48LE)) conv = rgb64to48_bswap;
1408  } else
1409  /* BGR -> BGR */
1410  if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
1411  (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) {
1412  switch (srcId | (dstId << 16)) {
1413  case 0x000F000C: conv = rgb12to15; break;
1414  case 0x000F0010: conv = rgb16to15; break;
1415  case 0x000F0018: conv = rgb24to15; break;
1416  case 0x000F0020: conv = rgb32to15; break;
1417  case 0x0010000F: conv = rgb15to16; break;
1418  case 0x00100018: conv = rgb24to16; break;
1419  case 0x00100020: conv = rgb32to16; break;
1420  case 0x0018000F: conv = rgb15to24; break;
1421  case 0x00180010: conv = rgb16to24; break;
1422  case 0x00180020: conv = rgb32to24; break;
1423  case 0x0020000F: conv = rgb15to32; break;
1424  case 0x00200010: conv = rgb16to32; break;
1425  case 0x00200018: conv = rgb24to32; break;
1426  }
1427  } else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) ||
1428  (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) {
1429  switch (srcId | (dstId << 16)) {
1430  case 0x000C000C: conv = rgb12tobgr12; break;
1431  case 0x000F000F: conv = rgb15tobgr15; break;
1432  case 0x000F0010: conv = rgb16tobgr15; break;
1433  case 0x000F0018: conv = rgb24tobgr15; break;
1434  case 0x000F0020: conv = rgb32tobgr15; break;
1435  case 0x0010000F: conv = rgb15tobgr16; break;
1436  case 0x00100010: conv = rgb16tobgr16; break;
1437  case 0x00100018: conv = rgb24tobgr16; break;
1438  case 0x00100020: conv = rgb32tobgr16; break;
1439  case 0x0018000F: conv = rgb15tobgr24; break;
1440  case 0x00180010: conv = rgb16tobgr24; break;
1441  case 0x00180018: conv = rgb24tobgr24; break;
1442  case 0x00180020: conv = rgb32tobgr24; break;
1443  case 0x0020000F: conv = rgb15tobgr32; break;
1444  case 0x00200010: conv = rgb16tobgr32; break;
1445  case 0x00200018: conv = rgb24tobgr32; break;
1446  }
1447  }
1448 
1449  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) && !isRGBA32(srcFormat) && ALT32_CORR<0)
1450  return NULL;
1451 
1452  // Maintain symmetry between endianness
1453  if (c->flags & SWS_BITEXACT)
1454  if ((dstFormat == AV_PIX_FMT_RGB32 || dstFormat == AV_PIX_FMT_BGR32 ) && !isRGBA32(srcFormat) && ALT32_CORR>0)
1455  return NULL;
1456 
1457  return conv;
1458 }
1459 
1460 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
1461 static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
1462  int srcSliceY, int srcSliceH, uint8_t *dst[],
1463  int dstStride[])
1464 
1465 {
1466  const enum AVPixelFormat srcFormat = c->srcFormat;
1467  const enum AVPixelFormat dstFormat = c->dstFormat;
1468  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
1469  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
1470  const int srcBpp = (c->srcFormatBpp + 7) >> 3;
1471  const int dstBpp = (c->dstFormatBpp + 7) >> 3;
1473 
1474  if (!conv) {
1475  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
1476  av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat));
1477  } else {
1478  const uint8_t *srcPtr = src[0];
1479  uint8_t *dstPtr = dst[0];
1480  int src_bswap = IS_NOT_NE(c->srcFormatBpp, desc_src);
1481  int dst_bswap = IS_NOT_NE(c->dstFormatBpp, desc_dst);
1482 
1483  if ((srcFormat == AV_PIX_FMT_RGB32_1 || srcFormat == AV_PIX_FMT_BGR32_1) &&
1484  !isRGBA32(dstFormat))
1485  srcPtr += ALT32_CORR;
1486 
1487  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) &&
1488  !isRGBA32(srcFormat)) {
1489  int i;
1490  av_assert0(ALT32_CORR == 1);
1491  for (i = 0; i < srcSliceH; i++)
1492  dstPtr[dstStride[0] * (srcSliceY + i)] = 255;
1493  dstPtr += ALT32_CORR;
1494  }
1495 
1496  if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
1497  !(srcStride[0] % srcBpp) && !dst_bswap && !src_bswap)
1498  conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
1499  (srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp);
1500  else {
1501  int i, j;
1502  dstPtr += dstStride[0] * srcSliceY;
1503 
1504  for (i = 0; i < srcSliceH; i++) {
1505  if(src_bswap) {
1506  for(j=0; j<c->srcW; j++)
1507  ((uint16_t*)c->formatConvBuffer)[j] = av_bswap16(((uint16_t*)srcPtr)[j]);
1508  conv(c->formatConvBuffer, dstPtr, c->srcW * srcBpp);
1509  }else
1510  conv(srcPtr, dstPtr, c->srcW * srcBpp);
1511  if(dst_bswap)
1512  for(j=0; j<c->srcW; j++)
1513  ((uint16_t*)dstPtr)[j] = av_bswap16(((uint16_t*)dstPtr)[j]);
1514  srcPtr += srcStride[0];
1515  dstPtr += dstStride[0];
1516  }
1517  }
1518  }
1519  return srcSliceH;
1520 }
1521 
1523  int srcStride[], int srcSliceY, int srcSliceH,
1524  uint8_t *dst[], int dstStride[])
1525 {
1527  src[0],
1528  dst[0] + srcSliceY * dstStride[0],
1529  dst[1] + (srcSliceY >> 1) * dstStride[1],
1530  dst[2] + (srcSliceY >> 1) * dstStride[2],
1531  c->srcW, srcSliceH,
1532  dstStride[0], dstStride[1], srcStride[0],
1533  c->input_rgb2yuv_table);
1534  if (dst[3])
1535  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
1536  return srcSliceH;
1537 }
1538 
1539 static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
1540  int srcStride[], int srcSliceY, int srcSliceH,
1541  uint8_t *dst[], int dstStride[])
1542 {
1543  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
1544  dst[0], dstStride[0]);
1545 
1546  planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW,
1547  srcSliceH >> 2, srcStride[1], dstStride[1]);
1548  planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW,
1549  srcSliceH >> 2, srcStride[2], dstStride[2]);
1550  if (dst[3])
1551  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
1552  return srcSliceH;
1553 }
1554 
1556  int srcStride[], int srcSliceY,
1557  int srcSliceH, uint8_t *dst[], int dstStride[])
1558 {
1559  int y, x;
1560  ptrdiff_t dstStrideFloat = dstStride[0] >> 2;
1561  const uint8_t *srcPtr = src[0];
1562  float *dstPtr = (float *)(dst[0] + dstStride[0] * srcSliceY);
1563 
1564  for (y = 0; y < srcSliceH; ++y){
1565  for (x = 0; x < c->srcW; ++x){
1566  dstPtr[x] = c->uint2float_lut[srcPtr[x]];
1567  }
1568  srcPtr += srcStride[0];
1569  dstPtr += dstStrideFloat;
1570  }
1571 
1572  return srcSliceH;
1573 }
1574 
1576  int srcStride[], int srcSliceY,
1577  int srcSliceH, uint8_t* dst[], int dstStride[])
1578 {
1579  int y, x;
1580  ptrdiff_t srcStrideFloat = srcStride[0] >> 2;
1581  const float *srcPtr = (const float *)src[0];
1582  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1583 
1584  for (y = 0; y < srcSliceH; ++y){
1585  for (x = 0; x < c->srcW; ++x){
1586  dstPtr[x] = av_clip_uint8(lrintf(255.0f * srcPtr[x]));
1587  }
1588  srcPtr += srcStrideFloat;
1589  dstPtr += dstStride[0];
1590  }
1591 
1592  return srcSliceH;
1593 }
1594 
1595 /* unscaled copy like stuff (assumes nearly identical formats) */
1596 static int packedCopyWrapper(SwsContext *c, const uint8_t *src[],
1597  int srcStride[], int srcSliceY, int srcSliceH,
1598  uint8_t *dst[], int dstStride[])
1599 {
1600  if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
1601  memcpy(dst[0] + dstStride[0] * srcSliceY, src[0], srcSliceH * dstStride[0]);
1602  else {
1603  int i;
1604  const uint8_t *srcPtr = src[0];
1605  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
1606  int length = 0;
1607 
1608  /* universal length finder */
1609  while (length + c->srcW <= FFABS(dstStride[0]) &&
1610  length + c->srcW <= FFABS(srcStride[0]))
1611  length += c->srcW;
1612  av_assert1(length != 0);
1613 
1614  for (i = 0; i < srcSliceH; i++) {
1615  memcpy(dstPtr, srcPtr, length);
1616  srcPtr += srcStride[0];
1617  dstPtr += dstStride[0];
1618  }
1619  }
1620  return srcSliceH;
1621 }
1622 
1623 #define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\
1624  unsigned shift= src_depth-dst_depth, tmp;\
1625  if (c->dither == SWS_DITHER_NONE) {\
1626  for (i = 0; i < height; i++) {\
1627  for (j = 0; j < length-7; j+=8) {\
1628  dst[j+0] = dbswap(bswap(src[j+0])>>shift);\
1629  dst[j+1] = dbswap(bswap(src[j+1])>>shift);\
1630  dst[j+2] = dbswap(bswap(src[j+2])>>shift);\
1631  dst[j+3] = dbswap(bswap(src[j+3])>>shift);\
1632  dst[j+4] = dbswap(bswap(src[j+4])>>shift);\
1633  dst[j+5] = dbswap(bswap(src[j+5])>>shift);\
1634  dst[j+6] = dbswap(bswap(src[j+6])>>shift);\
1635  dst[j+7] = dbswap(bswap(src[j+7])>>shift);\
1636  }\
1637  for (; j < length; j++) {\
1638  dst[j] = dbswap(bswap(src[j])>>shift);\
1639  }\
1640  dst += dstStride;\
1641  src += srcStride;\
1642  }\
1643  } else if (shiftonly) {\
1644  for (i = 0; i < height; i++) {\
1645  const uint8_t *dither= dithers[shift-1][i&7];\
1646  for (j = 0; j < length-7; j+=8) {\
1647  tmp = (bswap(src[j+0]) + dither[0])>>shift; dst[j+0] = dbswap(tmp - (tmp>>dst_depth));\
1648  tmp = (bswap(src[j+1]) + dither[1])>>shift; dst[j+1] = dbswap(tmp - (tmp>>dst_depth));\
1649  tmp = (bswap(src[j+2]) + dither[2])>>shift; dst[j+2] = dbswap(tmp - (tmp>>dst_depth));\
1650  tmp = (bswap(src[j+3]) + dither[3])>>shift; dst[j+3] = dbswap(tmp - (tmp>>dst_depth));\
1651  tmp = (bswap(src[j+4]) + dither[4])>>shift; dst[j+4] = dbswap(tmp - (tmp>>dst_depth));\
1652  tmp = (bswap(src[j+5]) + dither[5])>>shift; dst[j+5] = dbswap(tmp - (tmp>>dst_depth));\
1653  tmp = (bswap(src[j+6]) + dither[6])>>shift; dst[j+6] = dbswap(tmp - (tmp>>dst_depth));\
1654  tmp = (bswap(src[j+7]) + dither[7])>>shift; dst[j+7] = dbswap(tmp - (tmp>>dst_depth));\
1655  }\
1656  for (; j < length; j++) {\
1657  tmp = (bswap(src[j]) + dither[j&7])>>shift; dst[j] = dbswap(tmp - (tmp>>dst_depth));\
1658  }\
1659  dst += dstStride;\
1660  src += srcStride;\
1661  }\
1662  } else {\
1663  for (i = 0; i < height; i++) {\
1664  const uint8_t *dither= dithers[shift-1][i&7];\
1665  for (j = 0; j < length-7; j+=8) {\
1666  tmp = bswap(src[j+0]); dst[j+0] = dbswap((tmp - (tmp>>dst_depth) + dither[0])>>shift);\
1667  tmp = bswap(src[j+1]); dst[j+1] = dbswap((tmp - (tmp>>dst_depth) + dither[1])>>shift);\
1668  tmp = bswap(src[j+2]); dst[j+2] = dbswap((tmp - (tmp>>dst_depth) + dither[2])>>shift);\
1669  tmp = bswap(src[j+3]); dst[j+3] = dbswap((tmp - (tmp>>dst_depth) + dither[3])>>shift);\
1670  tmp = bswap(src[j+4]); dst[j+4] = dbswap((tmp - (tmp>>dst_depth) + dither[4])>>shift);\
1671  tmp = bswap(src[j+5]); dst[j+5] = dbswap((tmp - (tmp>>dst_depth) + dither[5])>>shift);\
1672  tmp = bswap(src[j+6]); dst[j+6] = dbswap((tmp - (tmp>>dst_depth) + dither[6])>>shift);\
1673  tmp = bswap(src[j+7]); dst[j+7] = dbswap((tmp - (tmp>>dst_depth) + dither[7])>>shift);\
1674  }\
1675  for (; j < length; j++) {\
1676  tmp = bswap(src[j]); dst[j] = dbswap((tmp - (tmp>>dst_depth) + dither[j&7])>>shift);\
1677  }\
1678  dst += dstStride;\
1679  src += srcStride;\
1680  }\
1681  }
1682 
1683 static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
1684  int srcStride[], int srcSliceY, int srcSliceH,
1685  uint8_t *dst[], int dstStride[])
1686 {
1687  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
1688  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
1689  int plane, i, j;
1690  for (plane = 0; plane < 4; plane++) {
1691  int length = (plane == 0 || plane == 3) ? c->srcW : AV_CEIL_RSHIFT(c->srcW, c->chrDstHSubSample);
1692  int y = (plane == 0 || plane == 3) ? srcSliceY: AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
1693  int height = (plane == 0 || plane == 3) ? srcSliceH: AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
1694  const uint8_t *srcPtr = src[plane];
1695  uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
1696  int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0);
1697 
1698  if (!dst[plane])
1699  continue;
1700  // ignore palette for GRAY8
1701  if (plane == 1 && !dst[2]) continue;
1702  if (!src[plane] || (plane == 1 && !src[2])) {
1703  if (is16BPS(c->dstFormat) || isNBPS(c->dstFormat)) {
1704  fillPlane16(dst[plane], dstStride[plane], length, height, y,
1705  plane == 3, desc_dst->comp[plane].depth,
1706  isBE(c->dstFormat));
1707  } else {
1708  fillPlane(dst[plane], dstStride[plane], length, height, y,
1709  (plane == 3) ? 255 : 128);
1710  }
1711  } else {
1712  if(isNBPS(c->srcFormat) || isNBPS(c->dstFormat)
1713  || (is16BPS(c->srcFormat) != is16BPS(c->dstFormat))
1714  ) {
1715  const int src_depth = desc_src->comp[plane].depth;
1716  const int dst_depth = desc_dst->comp[plane].depth;
1717  const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
1718  uint16_t *dstPtr2 = (uint16_t*)dstPtr;
1719 
1720  if (dst_depth == 8) {
1721  if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
1722  DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , )
1723  } else {
1724  DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, )
1725  }
1726  } else if (src_depth == 8) {
1727  for (i = 0; i < height; i++) {
1728  #define COPY816(w)\
1729  if (shiftonly) {\
1730  for (j = 0; j < length; j++)\
1731  w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\
1732  } else {\
1733  for (j = 0; j < length; j++)\
1734  w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\
1735  (srcPtr[j]>>(2*8-dst_depth)));\
1736  }
1737  if(isBE(c->dstFormat)){
1738  COPY816(AV_WB16)
1739  } else {
1740  COPY816(AV_WL16)
1741  }
1742  dstPtr2 += dstStride[plane]/2;
1743  srcPtr += srcStride[plane];
1744  }
1745  } else if (src_depth <= dst_depth) {
1746  for (i = 0; i < height; i++) {
1747  j = 0;
1748  if(isBE(c->srcFormat) == HAVE_BIGENDIAN &&
1749  isBE(c->dstFormat) == HAVE_BIGENDIAN &&
1750  shiftonly) {
1751  unsigned shift = dst_depth - src_depth;
1752 #if HAVE_FAST_64BIT
1753 #define FAST_COPY_UP(shift) \
1754  for (; j < length - 3; j += 4) { \
1755  uint64_t v = AV_RN64A(srcPtr2 + j); \
1756  AV_WN64A(dstPtr2 + j, v << shift); \
1757  }
1758 #else
1759 #define FAST_COPY_UP(shift) \
1760  for (; j < length - 1; j += 2) { \
1761  uint32_t v = AV_RN32A(srcPtr2 + j); \
1762  AV_WN32A(dstPtr2 + j, v << shift); \
1763  }
1764 #endif
1765  switch (shift)
1766  {
1767  case 6: FAST_COPY_UP(6); break;
1768  case 7: FAST_COPY_UP(7); break;
1769  }
1770  }
1771 #define COPY_UP(r,w) \
1772  if(shiftonly){\
1773  for (; j < length; j++){ \
1774  unsigned int v= r(&srcPtr2[j]);\
1775  w(&dstPtr2[j], v<<(dst_depth-src_depth));\
1776  }\
1777  }else{\
1778  for (; j < length; j++){ \
1779  unsigned int v= r(&srcPtr2[j]);\
1780  w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \
1781  (v>>(2*src_depth-dst_depth)));\
1782  }\
1783  }
1784  if(isBE(c->srcFormat)){
1785  if(isBE(c->dstFormat)){
1787  } else {
1789  }
1790  } else {
1791  if(isBE(c->dstFormat)){
1793  } else {
1795  }
1796  }
1797  dstPtr2 += dstStride[plane]/2;
1798  srcPtr2 += srcStride[plane]/2;
1799  }
1800  } else {
1801  if(isBE(c->srcFormat) == HAVE_BIGENDIAN){
1802  if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
1803  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , )
1804  } else {
1805  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16)
1806  }
1807  }else{
1808  if(isBE(c->dstFormat) == HAVE_BIGENDIAN){
1809  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, )
1810  } else {
1811  DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16)
1812  }
1813  }
1814  }
1815  } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) &&
1816  isBE(c->srcFormat) != isBE(c->dstFormat)) {
1817 
1818  for (i = 0; i < height; i++) {
1819  for (j = 0; j < length; j++)
1820  ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]);
1821  srcPtr += srcStride[plane];
1822  dstPtr += dstStride[plane];
1823  }
1824  } else if (isFloat(c->srcFormat) && isFloat(c->dstFormat) &&
1825  isBE(c->srcFormat) != isBE(c->dstFormat)) { /* swap float plane */
1826  for (i = 0; i < height; i++) {
1827  for (j = 0; j < length; j++)
1828  ((uint32_t *) dstPtr)[j] = av_bswap32(((const uint32_t *) srcPtr)[j]);
1829  srcPtr += srcStride[plane];
1830  dstPtr += dstStride[plane];
1831  }
1832  } else if (dstStride[plane] == srcStride[plane] &&
1833  srcStride[plane] > 0 && srcStride[plane] == length) {
1834  memcpy(dst[plane] + dstStride[plane] * y, src[plane],
1835  height * dstStride[plane]);
1836  } else {
1837  if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat))
1838  length *= 2;
1839  else if (desc_src->comp[0].depth == 1)
1840  length >>= 3; // monowhite/black
1841  for (i = 0; i < height; i++) {
1842  memcpy(dstPtr, srcPtr, length);
1843  srcPtr += srcStride[plane];
1844  dstPtr += dstStride[plane];
1845  }
1846  }
1847  }
1848  }
1849  return srcSliceH;
1850 }
1851 
1852 
1853 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
1854  ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
1855  (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
1856 
1857 
1859 {
1860  const enum AVPixelFormat srcFormat = c->srcFormat;
1861  const enum AVPixelFormat dstFormat = c->dstFormat;
1862  const int flags = c->flags;
1863  const int dstH = c->dstH;
1864  int needsDither;
1865 
1866  needsDither = isAnyRGB(dstFormat) &&
1867  c->dstFormatBpp < 24 &&
1868  (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat)));
1869 
1870  /* yv12_to_nv12 */
1871  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
1872  (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)) {
1874  }
1875  /* nv12_to_yv12 */
1876  if (dstFormat == AV_PIX_FMT_YUV420P &&
1877  (srcFormat == AV_PIX_FMT_NV12 || srcFormat == AV_PIX_FMT_NV21)) {
1879  }
1880  /* yuv2bgr */
1881  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P ||
1882  srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) &&
1883  !(flags & SWS_ACCURATE_RND) && (c->dither == SWS_DITHER_BAYER || c->dither == SWS_DITHER_AUTO) && !(dstH & 1)) {
1885  }
1886  /* yuv420p1x_to_p01x */
1887  if ((srcFormat == AV_PIX_FMT_YUV420P10 || srcFormat == AV_PIX_FMT_YUVA420P10 ||
1888  srcFormat == AV_PIX_FMT_YUV420P12 ||
1889  srcFormat == AV_PIX_FMT_YUV420P14 ||
1890  srcFormat == AV_PIX_FMT_YUV420P16 || srcFormat == AV_PIX_FMT_YUVA420P16) &&
1891  (dstFormat == AV_PIX_FMT_P010 || dstFormat == AV_PIX_FMT_P016)) {
1893  }
1894  /* yuv420p_to_p01xle */
1895  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
1896  (dstFormat == AV_PIX_FMT_P010LE || dstFormat == AV_PIX_FMT_P016LE)) {
1898  }
1899 
1900  if (srcFormat == AV_PIX_FMT_YUV410P && !(dstH & 3) &&
1901  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
1902  !(flags & SWS_BITEXACT)) {
1904  }
1905 
1906  /* bgr24toYV12 */
1907  if (srcFormat == AV_PIX_FMT_BGR24 &&
1908  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
1909  !(flags & SWS_ACCURATE_RND))
1911 
1912  /* RGB/BGR -> RGB/BGR (no dither needed forms) */
1913  if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)
1914  && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
1915  c->swscale = rgbToRgbWrapper;
1916 
1917  /* RGB to planar RGB */
1918  if ((srcFormat == AV_PIX_FMT_GBRP && dstFormat == AV_PIX_FMT_GBRAP) ||
1919  (srcFormat == AV_PIX_FMT_GBRAP && dstFormat == AV_PIX_FMT_GBRP))
1921 
1922 #define isByteRGB(f) ( \
1923  f == AV_PIX_FMT_RGB32 || \
1924  f == AV_PIX_FMT_RGB32_1 || \
1925  f == AV_PIX_FMT_RGB24 || \
1926  f == AV_PIX_FMT_BGR32 || \
1927  f == AV_PIX_FMT_BGR32_1 || \
1928  f == AV_PIX_FMT_BGR24)
1929 
1930  if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
1932 
1933  if (srcFormat == AV_PIX_FMT_GBRAP && isByteRGB(dstFormat))
1935 
1936  if ((srcFormat == AV_PIX_FMT_RGB48LE || srcFormat == AV_PIX_FMT_RGB48BE ||
1937  srcFormat == AV_PIX_FMT_BGR48LE || srcFormat == AV_PIX_FMT_BGR48BE ||
1938  srcFormat == AV_PIX_FMT_RGBA64LE || srcFormat == AV_PIX_FMT_RGBA64BE ||
1939  srcFormat == AV_PIX_FMT_BGRA64LE || srcFormat == AV_PIX_FMT_BGRA64BE) &&
1940  (dstFormat == AV_PIX_FMT_GBRP9LE || dstFormat == AV_PIX_FMT_GBRP9BE ||
1941  dstFormat == AV_PIX_FMT_GBRP10LE || dstFormat == AV_PIX_FMT_GBRP10BE ||
1942  dstFormat == AV_PIX_FMT_GBRP12LE || dstFormat == AV_PIX_FMT_GBRP12BE ||
1943  dstFormat == AV_PIX_FMT_GBRP14LE || dstFormat == AV_PIX_FMT_GBRP14BE ||
1944  dstFormat == AV_PIX_FMT_GBRP16LE || dstFormat == AV_PIX_FMT_GBRP16BE ||
1945  dstFormat == AV_PIX_FMT_GBRAP12LE || dstFormat == AV_PIX_FMT_GBRAP12BE ||
1946  dstFormat == AV_PIX_FMT_GBRAP16LE || dstFormat == AV_PIX_FMT_GBRAP16BE ))
1948 
1949  if ((srcFormat == AV_PIX_FMT_GBRP9LE || srcFormat == AV_PIX_FMT_GBRP9BE ||
1950  srcFormat == AV_PIX_FMT_GBRP16LE || srcFormat == AV_PIX_FMT_GBRP16BE ||
1951  srcFormat == AV_PIX_FMT_GBRP10LE || srcFormat == AV_PIX_FMT_GBRP10BE ||
1952  srcFormat == AV_PIX_FMT_GBRP12LE || srcFormat == AV_PIX_FMT_GBRP12BE ||
1953  srcFormat == AV_PIX_FMT_GBRP14LE || srcFormat == AV_PIX_FMT_GBRP14BE ||
1954  srcFormat == AV_PIX_FMT_GBRAP12LE || srcFormat == AV_PIX_FMT_GBRAP12BE ||
1955  srcFormat == AV_PIX_FMT_GBRAP16LE || srcFormat == AV_PIX_FMT_GBRAP16BE) &&
1956  (dstFormat == AV_PIX_FMT_RGB48LE || dstFormat == AV_PIX_FMT_RGB48BE ||
1957  dstFormat == AV_PIX_FMT_BGR48LE || dstFormat == AV_PIX_FMT_BGR48BE ||
1958  dstFormat == AV_PIX_FMT_RGBA64LE || dstFormat == AV_PIX_FMT_RGBA64BE ||
1959  dstFormat == AV_PIX_FMT_BGRA64LE || dstFormat == AV_PIX_FMT_BGRA64BE))
1961 
1962  if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth == 8 &&
1963  isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRP)
1965 
1966  if (isBayer(srcFormat)) {
1967  if (dstFormat == AV_PIX_FMT_RGB24)
1969  else if (dstFormat == AV_PIX_FMT_YUV420P)
1971  else if (!isBayer(dstFormat)) {
1972  av_log(c, AV_LOG_ERROR, "unsupported bayer conversion\n");
1973  av_assert0(0);
1974  }
1975  }
1976 
1977  /* bswap 16 bits per pixel/component packed formats */
1978  if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_BGGR16) ||
1979  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_RGGB16) ||
1980  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GBRG16) ||
1981  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BAYER_GRBG16) ||
1982  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR444) ||
1983  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR48) ||
1984  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
1985  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR555) ||
1986  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR565) ||
1987  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
1988  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY9) ||
1989  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY10) ||
1990  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY12) ||
1991  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY14) ||
1992  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY16) ||
1993  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YA16) ||
1994  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_AYUV64) ||
1995  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP9) ||
1996  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP10) ||
1997  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP12) ||
1998  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP14) ||
1999  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRP16) ||
2000  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP12) ||
2001  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP16) ||
2002  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB444) ||
2003  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB48) ||
2004  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
2005  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB555) ||
2006  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB565) ||
2007  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
2008  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XYZ12) ||
2009  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P9) ||
2010  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P10) ||
2011  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P12) ||
2012  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P14) ||
2013  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV420P16) ||
2014  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P9) ||
2015  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P10) ||
2016  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P12) ||
2017  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P14) ||
2018  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV422P16) ||
2019  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P10) ||
2020  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV440P12) ||
2021  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P9) ||
2022  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P10) ||
2023  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P12) ||
2024  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P14) ||
2025  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YUV444P16))
2026  c->swscale = bswap_16bpc;
2027 
2028  if (usePal(srcFormat) && isByteRGB(dstFormat))
2029  c->swscale = palToRgbWrapper;
2030 
2031  if (srcFormat == AV_PIX_FMT_YUV422P) {
2032  if (dstFormat == AV_PIX_FMT_YUYV422)
2034  else if (dstFormat == AV_PIX_FMT_UYVY422)
2036  }
2037 
2038  /* uint Y to float Y */
2039  if (srcFormat == AV_PIX_FMT_GRAY8 && dstFormat == AV_PIX_FMT_GRAYF32){
2041  }
2042 
2043  /* float Y to uint Y */
2044  if (srcFormat == AV_PIX_FMT_GRAYF32 && dstFormat == AV_PIX_FMT_GRAY8){
2046  }
2047 
2048  /* LQ converters if -sws 0 or -sws 4*/
2049  if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) {
2050  /* yv12_to_yuy2 */
2051  if (srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) {
2052  if (dstFormat == AV_PIX_FMT_YUYV422)
2054  else if (dstFormat == AV_PIX_FMT_UYVY422)
2056  }
2057  }
2058  if (srcFormat == AV_PIX_FMT_YUYV422 &&
2059  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
2061  if (srcFormat == AV_PIX_FMT_UYVY422 &&
2062  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
2064  if (srcFormat == AV_PIX_FMT_YUYV422 && dstFormat == AV_PIX_FMT_YUV422P)
2066  if (srcFormat == AV_PIX_FMT_UYVY422 && dstFormat == AV_PIX_FMT_YUV422P)
2068 
2069 #define isPlanarGray(x) (isGray(x) && (x) != AV_PIX_FMT_YA8 && (x) != AV_PIX_FMT_YA16LE && (x) != AV_PIX_FMT_YA16BE)
2070  /* simple copy */
2071  if ( srcFormat == dstFormat ||
2072  (srcFormat == AV_PIX_FMT_YUVA420P && dstFormat == AV_PIX_FMT_YUV420P) ||
2073  (srcFormat == AV_PIX_FMT_YUV420P && dstFormat == AV_PIX_FMT_YUVA420P) ||
2074  (isFloat(srcFormat) == isFloat(dstFormat)) && ((isPlanarYUV(srcFormat) && isPlanarGray(dstFormat)) ||
2075  (isPlanarYUV(dstFormat) && isPlanarGray(srcFormat)) ||
2076  (isPlanarGray(dstFormat) && isPlanarGray(srcFormat)) ||
2077  (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) &&
2080  !isSemiPlanarYUV(srcFormat) && !isSemiPlanarYUV(dstFormat))))
2081  {
2082  if (isPacked(c->srcFormat))
2084  else /* Planar YUV or gray */
2086  }
2087 
2088  if (ARCH_PPC)
2090  if (ARCH_ARM)
2092  if (ARCH_AARCH64)
2094 }
2095 
2096 /* Convert the palette to the same packed 32-bit format as the palette */
2098  int num_pixels, const uint8_t *palette)
2099 {
2100  int i;
2101 
2102  for (i = 0; i < num_pixels; i++)
2103  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
2104 }
2105 
2106 /* Palette format: ABCD -> dst format: ABC */
2108  int num_pixels, const uint8_t *palette)
2109 {
2110  int i;
2111 
2112  for (i = 0; i < num_pixels; i++) {
2113  //FIXME slow?
2114  dst[0] = palette[src[i] * 4 + 0];
2115  dst[1] = palette[src[i] * 4 + 1];
2116  dst[2] = palette[src[i] * 4 + 2];
2117  dst += 3;
2118  }
2119 }
#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:81
#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:381
static void copy(const float *p1, float *p2, const int length)
#define COPY816(w)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2446
#define isPlanarGray(x)
static void gbraptopacked32(const uint8_t *src[], int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int alpha_first, int width)
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:416
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:389
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
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:208
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:68
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:369
bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples */
Definition: pixfmt.h:262
bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples */
Definition: pixfmt.h:263
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
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:207
void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:237
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:395
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian */
Definition: pixfmt.h:270
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:374
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:359
#define isRGBA32(x)
planar GBR 4:4:4 36bpp, little-endian
Definition: pixfmt.h:255
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:383
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:260
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:368
#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:254
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:360
void(* rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:50
#define AV_PIX_FMT_P016
Definition: pixfmt.h:427
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:361
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:426
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:216
#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:101
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:177
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:103
#define f(width, name)
Definition: cbs_vp9.c:255
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, little-endian */
Definition: pixfmt.h:268
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian */
Definition: pixfmt.h:269
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:205
void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:223
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:394
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:94
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:174
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:370
#define lrintf(x)
Definition: libm_mips.h:70
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:392
external API header
enum AVPixelFormat dstFormat
Destination pixel format.
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:384
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:419
#define AV_WB16(p, v)
Definition: intreadwrite.h:405
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, little-endian */
Definition: pixfmt.h:264
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:406
#define av_log(a,...)
float uint2float_lut[256]
#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:170
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:355
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:95
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:364
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:400
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:365
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:300
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:382
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:92
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:401
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:149
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
static int planarRgbaToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
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:377
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:90
planar GBR 4:4:4:4 48bpp, big-endian
Definition: pixfmt.h:287
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:398
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:363
#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
#define width
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:69
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:284
#define AV_PIX_FMT_BAYER_BGGR16
Definition: pixfmt.h:403
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:378
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:148
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:397
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:288
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:390
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:372
#define AV_PIX_FMT_BAYER_GBRG16
Definition: pixfmt.h:405
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:354
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_bswap32
Definition: bswap.h:33
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:387
void rgb48to64_nobswap(const uint8_t *src, uint8_t *dst, int src_size)
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:411
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)
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:362
static const int16_t alpha[]
Definition: ilbcdata.h:55
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, big-endian */
Definition: pixfmt.h:267
planar GBR 4:4:4 30bpp, big-endian
Definition: pixfmt.h:172
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:271
static int uint_y_to_float_y_wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:352
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
planar GBR 4:4:4 42bpp, little-endian
Definition: pixfmt.h:257
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:379
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
#define AV_PIX_FMT_XYZ12
Definition: pixfmt.h:423
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
static int float_y_to_uint_y_wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
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:385
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
planar GBR 4:4:4 42bpp, big-endian
Definition: pixfmt.h:256
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:376
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:265
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:371
#define AV_PIX_FMT_AYUV64
Definition: pixfmt.h:425
void(* rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:41
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:388
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:396
#define flags(name, subs,...)
Definition: cbs_av1.c:596
static int bswap_16bpc(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:380
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:386
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian */
Definition: pixfmt.h:266
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:404
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:66
Y , 8bpp.
Definition: pixfmt.h:74
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
planar GBR 4:4:4 27bpp, little-endian
Definition: pixfmt.h:171
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:102
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:373
#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:261
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:367
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:353
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:366
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:175
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:2362
#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.
static av_always_inline int isFloat(enum AVPixelFormat pix_fmt)
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:217
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:64
#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:391
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:173
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:206
#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