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