Libav
swscale_unscaled.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; 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 <assert.h>
27 #include "swscale.h"
28 #include "swscale_internal.h"
29 #include "rgb2rgb.h"
30 #include "libavutil/intreadwrite.h"
31 #include "libavutil/cpu.h"
32 #include "libavutil/avutil.h"
33 #include "libavutil/mathematics.h"
34 #include "libavutil/bswap.h"
35 #include "libavutil/pixdesc.h"
36 
37 DECLARE_ALIGNED(8, static const uint8_t, dither_8x8_1)[8][8] = {
38  { 0, 1, 0, 1, 0, 1, 0, 1,},
39  { 1, 0, 1, 0, 1, 0, 1, 0,},
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 };
47 DECLARE_ALIGNED(8, static const uint8_t, dither_8x8_3)[8][8] = {
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 DECLARE_ALIGNED(8, static const uint8_t, dither_8x8_64)[8][8] = {
58  { 18, 34, 30, 46, 17, 33, 29, 45,},
59  { 50, 2, 62, 14, 49, 1, 61, 13,},
60  { 26, 42, 22, 38, 25, 41, 21, 37,},
61  { 58, 10, 54, 6, 57, 9, 53, 5,},
62  { 16, 32, 28, 44, 19, 35, 31, 47,},
63  { 48, 0, 60, 12, 51, 3, 63, 15,},
64  { 24, 40, 20, 36, 27, 43, 23, 39,},
65  { 56, 8, 52, 4, 59, 11, 55, 7,},
66 };
67 DECLARE_ALIGNED(8, static const uint8_t, dither_8x8_256)[8][8] = {
68  { 72, 136, 120, 184, 68, 132, 116, 180,},
69  { 200, 8, 248, 56, 196, 4, 244, 52,},
70  { 104, 168, 88, 152, 100, 164, 84, 148,},
71  { 232, 40, 216, 24, 228, 36, 212, 20,},
72  { 64, 128, 102, 176, 76, 140, 124, 188,},
73  { 192, 0, 240, 48, 204, 12, 252, 60,},
74  { 96, 160, 80, 144, 108, 172, 92, 156,},
75  { 224, 32, 208, 16, 236, 44, 220, 28,},
76 };
77 
78 #define RGB2YUV_SHIFT 15
79 #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
80 #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
81 #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
82 #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
83 #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
84 #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
85 #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
86 #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
87 #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
88 
89 static void fillPlane(uint8_t *plane, int stride, int width, int height, int y,
90  uint8_t val)
91 {
92  int i;
93  uint8_t *ptr = plane + stride * y;
94  for (i = 0; i < height; i++) {
95  memset(ptr, val, width);
96  ptr += stride;
97  }
98 }
99 
100 static void fill_plane9or10(uint8_t *plane, int stride, int width,
101  int height, int y, uint8_t val,
102  const int dst_depth, const int big_endian)
103 {
104  int i, j;
105  uint16_t *dst = (uint16_t *) (plane + stride * y);
106 #define FILL8TO9_OR_10(wfunc) \
107  for (i = 0; i < height; i++) { \
108  for (j = 0; j < width; j++) { \
109  wfunc(&dst[j], (val << (dst_depth - 8)) | \
110  (val >> (16 - dst_depth))); \
111  } \
112  dst += stride / 2; \
113  }
114  if (big_endian) {
116  } else {
118  }
119 }
120 
121 static void copyPlane(const uint8_t *src, int srcStride,
122  int srcSliceY, int srcSliceH, int width,
123  uint8_t *dst, int dstStride)
124 {
125  dst += dstStride * srcSliceY;
126  if (dstStride == srcStride && srcStride > 0) {
127  memcpy(dst, src, srcSliceH * dstStride);
128  } else {
129  int i;
130  for (i = 0; i < srcSliceH; i++) {
131  memcpy(dst, src, width);
132  src += srcStride;
133  dst += dstStride;
134  }
135  }
136 }
137 
138 static int planarToNv12Wrapper(SwsContext *c, const uint8_t *src[],
139  int srcStride[], int srcSliceY,
140  int srcSliceH, uint8_t *dstParam[],
141  int dstStride[])
142 {
143  uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2;
144 
145  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
146  dstParam[0], dstStride[0]);
147 
148  if (c->dstFormat == AV_PIX_FMT_NV12)
149  interleaveBytes(src[1], src[2], dst, c->srcW / 2, srcSliceH / 2,
150  srcStride[1], srcStride[2], dstStride[1]);
151  else
152  interleaveBytes(src[2], src[1], dst, c->srcW / 2, srcSliceH / 2,
153  srcStride[2], srcStride[1], dstStride[1]);
154 
155  return srcSliceH;
156 }
157 
158 static int nv12ToPlanarWrapper(SwsContext *c, const uint8_t *src[],
159  int srcStride[], int srcSliceY,
160  int srcSliceH, uint8_t *dstParam[],
161  int dstStride[])
162 {
163  uint8_t *dst1 = dstParam[1] + dstStride[1] * srcSliceY / 2;
164  uint8_t *dst2 = dstParam[2] + dstStride[2] * srcSliceY / 2;
165 
166  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
167  dstParam[0], dstStride[0]);
168 
169  if (c->srcFormat == AV_PIX_FMT_NV12)
170  deinterleaveBytes(src[1], dst1, dst2,c->srcW / 2, srcSliceH / 2,
171  srcStride[1], dstStride[1], dstStride[2]);
172  else
173  deinterleaveBytes(src[1], dst2, dst1, c->srcW / 2, srcSliceH / 2,
174  srcStride[1], dstStride[2], dstStride[1]);
175 
176  return srcSliceH;
177 }
178 
179 static int planarToYuy2Wrapper(SwsContext *c, const uint8_t *src[],
180  int srcStride[], int srcSliceY, int srcSliceH,
181  uint8_t *dstParam[], int dstStride[])
182 {
183  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
184 
185  yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
186  srcStride[1], dstStride[0]);
187 
188  return srcSliceH;
189 }
190 
191 static int planarToUyvyWrapper(SwsContext *c, const uint8_t *src[],
192  int srcStride[], int srcSliceY, int srcSliceH,
193  uint8_t *dstParam[], int dstStride[])
194 {
195  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
196 
197  yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
198  srcStride[1], dstStride[0]);
199 
200  return srcSliceH;
201 }
202 
203 static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *src[],
204  int srcStride[], int srcSliceY, int srcSliceH,
205  uint8_t *dstParam[], int dstStride[])
206 {
207  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
208 
209  yuv422ptoyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
210  srcStride[1], dstStride[0]);
211 
212  return srcSliceH;
213 }
214 
215 static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t *src[],
216  int srcStride[], int srcSliceY, int srcSliceH,
217  uint8_t *dstParam[], int dstStride[])
218 {
219  uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY;
220 
221  yuv422ptouyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0],
222  srcStride[1], dstStride[0]);
223 
224  return srcSliceH;
225 }
226 
227 static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t *src[],
228  int srcStride[], int srcSliceY, int srcSliceH,
229  uint8_t *dstParam[], int dstStride[])
230 {
231  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
232  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
233  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
234 
235  yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
236  dstStride[1], srcStride[0]);
237 
238  if (dstParam[3])
239  fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
240 
241  return srcSliceH;
242 }
243 
244 static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t *src[],
245  int srcStride[], int srcSliceY, int srcSliceH,
246  uint8_t *dstParam[], int dstStride[])
247 {
248  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
249  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
250  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
251 
252  yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
253  dstStride[1], srcStride[0]);
254 
255  return srcSliceH;
256 }
257 
258 static int uyvyToYuv420Wrapper(SwsContext *c, const uint8_t *src[],
259  int srcStride[], int srcSliceY, int srcSliceH,
260  uint8_t *dstParam[], int dstStride[])
261 {
262  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
263  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2;
264  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2;
265 
266  uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
267  dstStride[1], srcStride[0]);
268 
269  if (dstParam[3])
270  fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
271 
272  return srcSliceH;
273 }
274 
275 static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t *src[],
276  int srcStride[], int srcSliceY, int srcSliceH,
277  uint8_t *dstParam[], int dstStride[])
278 {
279  uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY;
280  uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY;
281  uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY;
282 
283  uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0],
284  dstStride[1], srcStride[0]);
285 
286  return srcSliceH;
287 }
288 
289 static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels,
290  const uint8_t *palette)
291 {
292  int i;
293  for (i = 0; i < num_pixels; i++)
294  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | (src[(i << 1) + 1] << 24);
295 }
296 
297 static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels,
298  const uint8_t *palette)
299 {
300  int i;
301 
302  for (i = 0; i < num_pixels; i++)
303  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | src[(i << 1) + 1];
304 }
305 
306 static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels,
307  const uint8_t *palette)
308 {
309  int i;
310 
311  for (i = 0; i < num_pixels; i++) {
312  //FIXME slow?
313  dst[0] = palette[src[i << 1] * 4 + 0];
314  dst[1] = palette[src[i << 1] * 4 + 1];
315  dst[2] = palette[src[i << 1] * 4 + 2];
316  dst += 3;
317  }
318 }
319 
320 static int packed_16bpc_bswap(SwsContext *c, const uint8_t *src[],
321  int srcStride[], int srcSliceY, int srcSliceH,
322  uint8_t *dst[], int dstStride[])
323 {
324  int i, j;
325  int srcstr = srcStride[0] >> 1;
326  int dststr = dstStride[0] >> 1;
327  uint16_t *dstPtr = (uint16_t *) dst[0];
328  const uint16_t *srcPtr = (const uint16_t *) src[0];
329  int min_stride = FFMIN(srcstr, dststr);
330 
331  for (i = 0; i < srcSliceH; i++) {
332  for (j = 0; j < min_stride; j++) {
333  dstPtr[j] = av_bswap16(srcPtr[j]);
334  }
335  srcPtr += srcstr;
336  dstPtr += dststr;
337  }
338 
339  return srcSliceH;
340 }
341 
342 static int palToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
343  int srcSliceY, int srcSliceH, uint8_t *dst[],
344  int dstStride[])
345 {
346  const enum AVPixelFormat srcFormat = c->srcFormat;
347  const enum AVPixelFormat dstFormat = c->dstFormat;
348  void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels,
349  const uint8_t *palette) = NULL;
350  int i;
351  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
352  const uint8_t *srcPtr = src[0];
353 
354  if (srcFormat == AV_PIX_FMT_YA8) {
355  switch (dstFormat) {
356  case AV_PIX_FMT_RGB32 : conv = gray8aToPacked32; break;
357  case AV_PIX_FMT_BGR32 : conv = gray8aToPacked32; break;
358  case AV_PIX_FMT_BGR32_1: conv = gray8aToPacked32_1; break;
359  case AV_PIX_FMT_RGB32_1: conv = gray8aToPacked32_1; break;
360  case AV_PIX_FMT_RGB24 : conv = gray8aToPacked24; break;
361  case AV_PIX_FMT_BGR24 : conv = gray8aToPacked24; break;
362  }
363  } else if (usePal(srcFormat)) {
364  switch (dstFormat) {
365  case AV_PIX_FMT_RGB32 : conv = sws_convertPalette8ToPacked32; break;
366  case AV_PIX_FMT_BGR32 : conv = sws_convertPalette8ToPacked32; break;
369  case AV_PIX_FMT_RGB24 : conv = sws_convertPalette8ToPacked24; break;
370  case AV_PIX_FMT_BGR24 : conv = sws_convertPalette8ToPacked24; break;
371  }
372  }
373 
374  if (!conv)
375  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
376  sws_format_name(srcFormat), sws_format_name(dstFormat));
377  else {
378  for (i = 0; i < srcSliceH; i++) {
379  conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb);
380  srcPtr += srcStride[0];
381  dstPtr += dstStride[0];
382  }
383  }
384 
385  return srcSliceH;
386 }
387 
388 static void gbr24ptopacked24(const uint8_t *src[], int srcStride[],
389  uint8_t *dst, int dstStride, int srcSliceH,
390  int width)
391 {
392  int x, h, i;
393  for (h = 0; h < srcSliceH; h++) {
394  uint8_t *dest = dst + dstStride * h;
395  for (x = 0; x < width; x++) {
396  *dest++ = src[0][x];
397  *dest++ = src[1][x];
398  *dest++ = src[2][x];
399  }
400 
401  for (i = 0; i < 3; i++)
402  src[i] += srcStride[i];
403  }
404 }
405 
406 static void gbr24ptopacked32(const uint8_t *src[], int srcStride[],
407  uint8_t *dst, int dstStride, int srcSliceH,
408  int alpha_first, int width)
409 {
410  int x, h, i;
411  for (h = 0; h < srcSliceH; h++) {
412  uint8_t *dest = dst + dstStride * h;
413 
414  if (alpha_first) {
415  for (x = 0; x < width; x++) {
416  *dest++ = 0xff;
417  *dest++ = src[0][x];
418  *dest++ = src[1][x];
419  *dest++ = src[2][x];
420  }
421  } else {
422  for (x = 0; x < width; x++) {
423  *dest++ = src[0][x];
424  *dest++ = src[1][x];
425  *dest++ = src[2][x];
426  *dest++ = 0xff;
427  }
428  }
429 
430  for (i = 0; i < 3; i++)
431  src[i] += srcStride[i];
432  }
433 }
434 
435 static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *src[],
436  int srcStride[], int srcSliceY, int srcSliceH,
437  uint8_t *dst[], int dstStride[])
438 {
439  int alpha_first = 0;
440  const uint8_t *src102[] = { src[1], src[0], src[2] };
441  const uint8_t *src201[] = { src[2], src[0], src[1] };
442  int stride102[] = { srcStride[1], srcStride[0], srcStride[2] };
443  int stride201[] = { srcStride[2], srcStride[0], srcStride[1] };
444 
445  if (c->srcFormat != AV_PIX_FMT_GBRP) {
446  av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n",
449  return srcSliceH;
450  }
451 
452  switch (c->dstFormat) {
453  case AV_PIX_FMT_BGR24:
454  gbr24ptopacked24(src102, stride102,
455  dst[0] + srcSliceY * dstStride[0], dstStride[0],
456  srcSliceH, c->srcW);
457  break;
458 
459  case AV_PIX_FMT_RGB24:
460  gbr24ptopacked24(src201, stride201,
461  dst[0] + srcSliceY * dstStride[0], dstStride[0],
462  srcSliceH, c->srcW);
463  break;
464 
465  case AV_PIX_FMT_ARGB:
466  alpha_first = 1;
467  case AV_PIX_FMT_RGBA:
468  gbr24ptopacked32(src201, stride201,
469  dst[0] + srcSliceY * dstStride[0], dstStride[0],
470  srcSliceH, alpha_first, c->srcW);
471  break;
472 
473  case AV_PIX_FMT_ABGR:
474  alpha_first = 1;
475  case AV_PIX_FMT_BGRA:
476  gbr24ptopacked32(src102, stride102,
477  dst[0] + srcSliceY * dstStride[0], dstStride[0],
478  srcSliceH, alpha_first, c->srcW);
479  break;
480 
481  default:
482  av_log(c, AV_LOG_ERROR,
483  "unsupported planar RGB conversion %s -> %s\n",
486  }
487 
488  return srcSliceH;
489 }
490 
492  const uint8_t *src[], int srcStride[],
493  int srcSliceY, int srcSliceH,
494  uint8_t *dst[], int dstStride[])
495 {
496  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
497  dst[0], dstStride[0]);
498  copyPlane(src[1], srcStride[1], srcSliceY, srcSliceH, c->srcW,
499  dst[1], dstStride[1]);
500  copyPlane(src[2], srcStride[2], srcSliceY, srcSliceH, c->srcW,
501  dst[2], dstStride[2]);
502  if (dst[3])
503  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
504 
505  return srcSliceH;
506 }
507 
508 static void packedtogbr24p(const uint8_t *src, int srcStride,
509  uint8_t *dst[], int dstStride[], int srcSliceH,
510  int alpha_first, int inc_size, int width)
511 {
512  uint8_t *dest[3];
513  int x, h;
514 
515  dest[0] = dst[0];
516  dest[1] = dst[1];
517  dest[2] = dst[2];
518 
519  if (alpha_first)
520  src++;
521 
522  for (h = 0; h < srcSliceH; h++) {
523  for (x = 0; x < width; x++) {
524  dest[0][x] = src[0];
525  dest[1][x] = src[1];
526  dest[2][x] = src[2];
527 
528  src += inc_size;
529  }
530  src += srcStride - width * inc_size;
531  dest[0] += dstStride[0];
532  dest[1] += dstStride[1];
533  dest[2] += dstStride[2];
534  }
535 }
536 
537 static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *src[],
538  int srcStride[], int srcSliceY, int srcSliceH,
539  uint8_t *dst[], int dstStride[])
540 {
541  int alpha_first = 0;
542  int stride102[] = { dstStride[1], dstStride[0], dstStride[2] };
543  int stride201[] = { dstStride[2], dstStride[0], dstStride[1] };
544  uint8_t *dst102[] = { dst[1] + srcSliceY * dstStride[1],
545  dst[0] + srcSliceY * dstStride[0],
546  dst[2] + srcSliceY * dstStride[2] };
547  uint8_t *dst201[] = { dst[2] + srcSliceY * dstStride[2],
548  dst[0] + srcSliceY * dstStride[0],
549  dst[1] + srcSliceY * dstStride[1] };
550 
551  switch (c->srcFormat) {
552  case AV_PIX_FMT_RGB24:
553  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
554  stride201, srcSliceH, alpha_first, 3, c->srcW);
555  break;
556  case AV_PIX_FMT_BGR24:
557  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
558  stride102, srcSliceH, alpha_first, 3, c->srcW);
559  break;
560  case AV_PIX_FMT_ARGB:
561  alpha_first = 1;
562  case AV_PIX_FMT_RGBA:
563  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst201,
564  stride201, srcSliceH, alpha_first, 4, c->srcW);
565  break;
566  case AV_PIX_FMT_ABGR:
567  alpha_first = 1;
568  case AV_PIX_FMT_BGRA:
569  packedtogbr24p((const uint8_t *) src[0], srcStride[0], dst102,
570  stride102, srcSliceH, alpha_first, 4, c->srcW);
571  break;
572  default:
573  av_log(c, AV_LOG_ERROR,
574  "unsupported planar RGB conversion %s -> %s\n",
577  }
578 
579  return srcSliceH;
580 }
581 
582 #define isRGBA32(x) ( \
583  (x) == AV_PIX_FMT_ARGB \
584  || (x) == AV_PIX_FMT_RGBA \
585  || (x) == AV_PIX_FMT_BGRA \
586  || (x) == AV_PIX_FMT_ABGR \
587  )
588 
589 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
590 typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int);
592 {
593  const enum AVPixelFormat srcFormat = c->srcFormat;
594  const enum AVPixelFormat dstFormat = c->dstFormat;
595  const int srcId = c->srcFormatBpp;
596  const int dstId = c->dstFormatBpp;
597  rgbConvFn conv = NULL;
598  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(srcFormat);
599  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(dstFormat);
600 
601 #define IS_NOT_NE(bpp, desc) \
602  (((bpp + 7) >> 3) == 2 && \
603  (!(desc->flags & AV_PIX_FMT_FLAG_BE) != !HAVE_BIGENDIAN))
604 
605  /* if this is non-native rgb444/555/565, don't handle it here. */
606  if (IS_NOT_NE(srcId, desc_src) || IS_NOT_NE(dstId, desc_dst))
607  return NULL;
608 
609 #define CONV_IS(src, dst) (srcFormat == AV_PIX_FMT_##src && dstFormat == AV_PIX_FMT_##dst)
610 
611  if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) {
612  if ( CONV_IS(ABGR, RGBA)
613  || CONV_IS(ARGB, BGRA)
614  || CONV_IS(BGRA, ARGB)
615  || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210;
616  else if (CONV_IS(ABGR, ARGB)
617  || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321;
618  else if (CONV_IS(ABGR, BGRA)
619  || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230;
620  else if (CONV_IS(BGRA, RGBA)
621  || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103;
622  else if (CONV_IS(BGRA, ABGR)
623  || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012;
624  } else
625  /* BGR -> BGR */
626  if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) ||
627  (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) {
628  switch (srcId | (dstId << 16)) {
629  case 0x000F000C: conv = rgb12to15; break;
630  case 0x000F0010: conv = rgb16to15; break;
631  case 0x000F0018: conv = rgb24to15; break;
632  case 0x000F0020: conv = rgb32to15; break;
633  case 0x0010000F: conv = rgb15to16; break;
634  case 0x00100018: conv = rgb24to16; break;
635  case 0x00100020: conv = rgb32to16; break;
636  case 0x0018000F: conv = rgb15to24; break;
637  case 0x00180010: conv = rgb16to24; break;
638  case 0x00180020: conv = rgb32to24; break;
639  case 0x0020000F: conv = rgb15to32; break;
640  case 0x00200010: conv = rgb16to32; break;
641  case 0x00200018: conv = rgb24to32; break;
642  }
643  } else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) ||
644  (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) {
645  switch (srcId | (dstId << 16)) {
646  case 0x000C000C: conv = rgb12tobgr12; break;
647  case 0x000F000F: conv = rgb15tobgr15; break;
648  case 0x000F0010: conv = rgb16tobgr15; break;
649  case 0x000F0018: conv = rgb24tobgr15; break;
650  case 0x000F0020: conv = rgb32tobgr15; break;
651  case 0x0010000F: conv = rgb15tobgr16; break;
652  case 0x00100010: conv = rgb16tobgr16; break;
653  case 0x00100018: conv = rgb24tobgr16; break;
654  case 0x00100020: conv = rgb32tobgr16; break;
655  case 0x0018000F: conv = rgb15tobgr24; break;
656  case 0x00180010: conv = rgb16tobgr24; break;
657  case 0x00180018: conv = rgb24tobgr24; break;
658  case 0x00180020: conv = rgb32tobgr24; break;
659  case 0x0020000F: conv = rgb15tobgr32; break;
660  case 0x00200010: conv = rgb16tobgr32; break;
661  case 0x00200018: conv = rgb24tobgr32; break;
662  }
663  }
664 
665  return conv;
666 }
667 
668 /* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */
669 static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[],
670  int srcSliceY, int srcSliceH, uint8_t *dst[],
671  int dstStride[])
672 
673 {
674  const enum AVPixelFormat srcFormat = c->srcFormat;
675  const enum AVPixelFormat dstFormat = c->dstFormat;
676  const int srcBpp = (c->srcFormatBpp + 7) >> 3;
677  const int dstBpp = (c->dstFormatBpp + 7) >> 3;
678  rgbConvFn conv = findRgbConvFn(c);
679 
680  if (!conv) {
681  av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n",
682  sws_format_name(srcFormat), sws_format_name(dstFormat));
683  } else {
684  const uint8_t *srcPtr = src[0];
685  uint8_t *dstPtr = dst[0];
686  if ((srcFormat == AV_PIX_FMT_RGB32_1 || srcFormat == AV_PIX_FMT_BGR32_1) &&
687  !isRGBA32(dstFormat))
688  srcPtr += ALT32_CORR;
689 
690  if ((dstFormat == AV_PIX_FMT_RGB32_1 || dstFormat == AV_PIX_FMT_BGR32_1) &&
691  !isRGBA32(srcFormat))
692  dstPtr += ALT32_CORR;
693 
694  if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 &&
695  !(srcStride[0] % srcBpp))
696  conv(srcPtr, dstPtr + dstStride[0] * srcSliceY,
697  (srcSliceH - 1) * srcStride[0] + c->srcW * srcBpp);
698  else {
699  int i;
700  dstPtr += dstStride[0] * srcSliceY;
701 
702  for (i = 0; i < srcSliceH; i++) {
703  conv(srcPtr, dstPtr, c->srcW * srcBpp);
704  srcPtr += srcStride[0];
705  dstPtr += dstStride[0];
706  }
707  }
708  }
709  return srcSliceH;
710 }
711 
712 static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
713  int srcStride[], int srcSliceY, int srcSliceH,
714  uint8_t *dst[], int dstStride[])
715 {
716  rgb24toyv12(
717  src[0],
718  dst[0] + srcSliceY * dstStride[0],
719  dst[1] + (srcSliceY >> 1) * dstStride[1],
720  dst[2] + (srcSliceY >> 1) * dstStride[2],
721  c->srcW, srcSliceH,
722  dstStride[0], dstStride[1], srcStride[0]);
723  if (dst[3])
724  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
725  return srcSliceH;
726 }
727 
728 static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[],
729  int srcStride[], int srcSliceY, int srcSliceH,
730  uint8_t *dst[], int dstStride[])
731 {
732  copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW,
733  dst[0], dstStride[0]);
734 
735  planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW,
736  srcSliceH >> 2, srcStride[1], dstStride[1]);
737  planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW,
738  srcSliceH >> 2, srcStride[2], dstStride[2]);
739  if (dst[3])
740  fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255);
741  return srcSliceH;
742 }
743 
744 /* unscaled copy like stuff (assumes nearly identical formats) */
745 static int packedCopyWrapper(SwsContext *c, const uint8_t *src[],
746  int srcStride[], int srcSliceY, int srcSliceH,
747  uint8_t *dst[], int dstStride[])
748 {
749  if (dstStride[0] == srcStride[0] && srcStride[0] > 0)
750  memcpy(dst[0] + dstStride[0] * srcSliceY, src[0], srcSliceH * dstStride[0]);
751  else {
752  int i;
753  const uint8_t *srcPtr = src[0];
754  uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
755  int length = 0;
756 
757  /* universal length finder */
758  while (length + c->srcW <= FFABS(dstStride[0]) &&
759  length + c->srcW <= FFABS(srcStride[0]))
760  length += c->srcW;
761  assert(length != 0);
762 
763  for (i = 0; i < srcSliceH; i++) {
764  memcpy(dstPtr, srcPtr, length);
765  srcPtr += srcStride[0];
766  dstPtr += dstStride[0];
767  }
768  }
769  return srcSliceH;
770 }
771 
772 #define clip9(x) av_clip_uintp2(x, 9)
773 #define clip10(x) av_clip_uintp2(x, 10)
774 #define DITHER_COPY(dst, dstStride, wfunc, src, srcStride, rfunc, dithers, shift, clip) \
775  for (i = 0; i < height; i++) { \
776  const uint8_t *dither = dithers[i & 7]; \
777  for (j = 0; j < length - 7; j += 8) { \
778  wfunc(&dst[j + 0], clip((rfunc(&src[j + 0]) + dither[0]) >> shift)); \
779  wfunc(&dst[j + 1], clip((rfunc(&src[j + 1]) + dither[1]) >> shift)); \
780  wfunc(&dst[j + 2], clip((rfunc(&src[j + 2]) + dither[2]) >> shift)); \
781  wfunc(&dst[j + 3], clip((rfunc(&src[j + 3]) + dither[3]) >> shift)); \
782  wfunc(&dst[j + 4], clip((rfunc(&src[j + 4]) + dither[4]) >> shift)); \
783  wfunc(&dst[j + 5], clip((rfunc(&src[j + 5]) + dither[5]) >> shift)); \
784  wfunc(&dst[j + 6], clip((rfunc(&src[j + 6]) + dither[6]) >> shift)); \
785  wfunc(&dst[j + 7], clip((rfunc(&src[j + 7]) + dither[7]) >> shift)); \
786  } \
787  for (; j < length; j++) \
788  wfunc(&dst[j], (rfunc(&src[j]) + dither[j & 7]) >> shift); \
789  dst += dstStride; \
790  src += srcStride; \
791  }
792 
793 static int planarCopyWrapper(SwsContext *c, const uint8_t *src[],
794  int srcStride[], int srcSliceY, int srcSliceH,
795  uint8_t *dst[], int dstStride[])
796 {
797  const AVPixFmtDescriptor *desc_src = av_pix_fmt_desc_get(c->srcFormat);
798  const AVPixFmtDescriptor *desc_dst = av_pix_fmt_desc_get(c->dstFormat);
799  int plane, i, j;
800  for (plane = 0; plane < 4; plane++) {
801  int length = (plane == 0 || plane == 3) ? c->srcW : AV_CEIL_RSHIFT(c->srcW, c->chrDstHSubSample);
802  int y = (plane == 0 || plane == 3) ? srcSliceY: AV_CEIL_RSHIFT(srcSliceY, c->chrDstVSubSample);
803  int height = (plane == 0 || plane == 3) ? srcSliceH: AV_CEIL_RSHIFT(srcSliceH, c->chrDstVSubSample);
804  const uint8_t *srcPtr = src[plane];
805  uint8_t *dstPtr = dst[plane] + dstStride[plane] * y;
806  int shiftonly = plane == 1 || plane == 2 || (!c->srcRange && plane == 0);
807 
808  if (!dst[plane])
809  continue;
810  // ignore palette for GRAY8
811  if (plane == 1 && !dst[2]) continue;
812  if (!src[plane] || (plane == 1 && !src[2])) {
813  int val = (plane == 3) ? 255 : 128;
814  if (is16BPS(c->dstFormat))
815  length *= 2;
816  if (is9_OR_10BPS(c->dstFormat)) {
817  fill_plane9or10(dst[plane], dstStride[plane],
818  length, height, y, val,
819  desc_dst->comp[plane].depth,
820  isBE(c->dstFormat));
821  } else
822  fillPlane(dst[plane], dstStride[plane], length, height, y,
823  val);
824  } else {
825  if (is9_OR_10BPS(c->srcFormat)) {
826  const int src_depth = desc_src->comp[plane].depth;
827  const int dst_depth = desc_dst->comp[plane].depth;
828  const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
829 
830  if (is16BPS(c->dstFormat)) {
831  uint16_t *dstPtr2 = (uint16_t *) dstPtr;
832 #define COPY9_OR_10TO16(rfunc, wfunc) \
833  if (shiftonly) { \
834  for (i = 0; i < height; i++) { \
835  for (j = 0; j < length; j++) { \
836  int srcpx = rfunc(&srcPtr2[j]); \
837  wfunc(&dstPtr2[j], srcpx << (16 - src_depth)); \
838  } \
839  dstPtr2 += dstStride[plane] / 2; \
840  srcPtr2 += srcStride[plane] / 2; \
841  } \
842  } else { \
843  for (i = 0; i < height; i++) { \
844  for (j = 0; j < length; j++) { \
845  int srcpx = rfunc(&srcPtr2[j]); \
846  wfunc(&dstPtr2[j], (srcpx << (16 - src_depth)) | (srcpx >> (2 * src_depth - 16))); \
847  } \
848  dstPtr2 += dstStride[plane] / 2; \
849  srcPtr2 += srcStride[plane] / 2; \
850  } \
851  }
852  if (isBE(c->dstFormat)) {
853  if (isBE(c->srcFormat)) {
855  } else {
857  }
858  } else {
859  if (isBE(c->srcFormat)) {
861  } else {
863  }
864  }
865  } else if (is9_OR_10BPS(c->dstFormat)) {
866  uint16_t *dstPtr2 = (uint16_t *) dstPtr;
867 #define COPY9_OR_10TO9_OR_10(loop) \
868  for (i = 0; i < height; i++) { \
869  for (j = 0; j < length; j++) { \
870  loop; \
871  } \
872  dstPtr2 += dstStride[plane] / 2; \
873  srcPtr2 += srcStride[plane] / 2; \
874  }
875 #define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc) \
876  if (dst_depth > src_depth) { \
877  COPY9_OR_10TO9_OR_10(int srcpx = rfunc(&srcPtr2[j]); \
878  wfunc(&dstPtr2[j], (srcpx << 1) | (srcpx >> 9))); \
879  } else if (dst_depth < src_depth) { \
880  DITHER_COPY(dstPtr2, dstStride[plane] / 2, wfunc, \
881  srcPtr2, srcStride[plane] / 2, rfunc, \
882  dither_8x8_1, 1, clip9); \
883  } else { \
884  COPY9_OR_10TO9_OR_10(wfunc(&dstPtr2[j], rfunc(&srcPtr2[j]))); \
885  }
886  if (isBE(c->dstFormat)) {
887  if (isBE(c->srcFormat)) {
889  } else {
891  }
892  } else {
893  if (isBE(c->srcFormat)) {
895  } else {
897  }
898  }
899  } else {
900 #define W8(a, b) { *(a) = (b); }
901 #define COPY9_OR_10TO8(rfunc) \
902  if (src_depth == 9) { \
903  DITHER_COPY(dstPtr, dstStride[plane], W8, \
904  srcPtr2, srcStride[plane] / 2, rfunc, \
905  dither_8x8_1, 1, av_clip_uint8); \
906  } else { \
907  DITHER_COPY(dstPtr, dstStride[plane], W8, \
908  srcPtr2, srcStride[plane] / 2, rfunc, \
909  dither_8x8_3, 2, av_clip_uint8); \
910  }
911  if (isBE(c->srcFormat)) {
913  } else {
915  }
916  }
917  } else if (is9_OR_10BPS(c->dstFormat)) {
918  const int dst_depth = desc_dst->comp[plane].depth;
919  uint16_t *dstPtr2 = (uint16_t *) dstPtr;
920 
921  if (is16BPS(c->srcFormat)) {
922  const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
923 #define COPY16TO9_OR_10(rfunc, wfunc) \
924  if (dst_depth == 9) { \
925  DITHER_COPY(dstPtr2, dstStride[plane] / 2, wfunc, \
926  srcPtr2, srcStride[plane] / 2, rfunc, \
927  ff_dither_8x8_128, 7, clip9); \
928  } else { \
929  DITHER_COPY(dstPtr2, dstStride[plane] / 2, wfunc, \
930  srcPtr2, srcStride[plane] / 2, rfunc, \
931  dither_8x8_64, 6, clip10); \
932  }
933  if (isBE(c->dstFormat)) {
934  if (isBE(c->srcFormat)) {
936  } else {
938  }
939  } else {
940  if (isBE(c->srcFormat)) {
942  } else {
944  }
945  }
946  } else /* 8 bits */ {
947 #define COPY8TO9_OR_10(wfunc) \
948  if (shiftonly) { \
949  for (i = 0; i < height; i++) { \
950  for (j = 0; j < length; j++) { \
951  const int srcpx = srcPtr[j]; \
952  wfunc(&dstPtr2[j], srcpx << (dst_depth - 8)); \
953  } \
954  dstPtr2 += dstStride[plane] / 2; \
955  srcPtr += srcStride[plane]; \
956  } \
957  } else { \
958  for (i = 0; i < height; i++) { \
959  for (j = 0; j < length; j++) { \
960  const int srcpx = srcPtr[j]; \
961  wfunc(&dstPtr2[j], (srcpx << (dst_depth - 8)) | (srcpx >> (16 - dst_depth))); \
962  } \
963  dstPtr2 += dstStride[plane] / 2; \
964  srcPtr += srcStride[plane]; \
965  } \
966  }
967  if (isBE(c->dstFormat)) {
969  } else {
971  }
972  }
973  } else if (is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) {
974  const uint16_t *srcPtr2 = (const uint16_t *) srcPtr;
975 #define COPY16TO8(rfunc) \
976  DITHER_COPY(dstPtr, dstStride[plane], W8, \
977  srcPtr2, srcStride[plane] / 2, rfunc, \
978  dither_8x8_256, 8, av_clip_uint8);
979  if (isBE(c->srcFormat)) {
981  } else {
983  }
984  } else if (!is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) {
985  for (i = 0; i < height; i++) {
986  for (j = 0; j < length; j++) {
987  dstPtr[ j << 1 ] = srcPtr[j];
988  dstPtr[(j << 1) + 1] = srcPtr[j];
989  }
990  srcPtr += srcStride[plane];
991  dstPtr += dstStride[plane];
992  }
993  } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) &&
994  isBE(c->srcFormat) != isBE(c->dstFormat)) {
995 
996  for (i = 0; i < height; i++) {
997  for (j = 0; j < length; j++)
998  ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]);
999  srcPtr += srcStride[plane];
1000  dstPtr += dstStride[plane];
1001  }
1002  } else if (dstStride[plane] == srcStride[plane] &&
1003  srcStride[plane] > 0 && srcStride[plane] == length) {
1004  memcpy(dst[plane] + dstStride[plane] * y, src[plane],
1005  height * dstStride[plane]);
1006  } else {
1007  if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat))
1008  length *= 2;
1009  else if (desc_src->comp[0].depth == 1)
1010  length >>= 3; // monowhite/black
1011  for (i = 0; i < height; i++) {
1012  memcpy(dstPtr, srcPtr, length);
1013  srcPtr += srcStride[plane];
1014  dstPtr += dstStride[plane];
1015  }
1016  }
1017  }
1018  }
1019  return srcSliceH;
1020 }
1021 
1022 
1023 #define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \
1024  ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \
1025  (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE))
1026 
1027 
1029 {
1030  const enum AVPixelFormat srcFormat = c->srcFormat;
1031  const enum AVPixelFormat dstFormat = c->dstFormat;
1032  const int flags = c->flags;
1033  const int dstH = c->dstH;
1034  int needsDither;
1035 
1036  needsDither = isAnyRGB(dstFormat) &&
1037  c->dstFormatBpp < 24 &&
1038  (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat)));
1039 
1040  /* yv12_to_nv12 */
1041  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) &&
1042  (dstFormat == AV_PIX_FMT_NV12 || dstFormat == AV_PIX_FMT_NV21)) {
1044  }
1045  /* nv12_to_yv12 */
1046  if (dstFormat == AV_PIX_FMT_YUV420P &&
1047  (srcFormat == AV_PIX_FMT_NV12 || srcFormat == AV_PIX_FMT_NV21)) {
1049  }
1050  /* yuv2bgr */
1051  if ((srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUV422P ||
1052  srcFormat == AV_PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) &&
1053  !(flags & SWS_ACCURATE_RND) && !(dstH & 1)) {
1055  }
1056 
1057  if (srcFormat == AV_PIX_FMT_YUV410P &&
1058  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
1059  !(flags & SWS_BITEXACT)) {
1061  }
1062 
1063  /* bgr24toYV12 */
1064  if (srcFormat == AV_PIX_FMT_BGR24 &&
1065  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P) &&
1066  !(flags & SWS_ACCURATE_RND))
1068 
1069  /* RGB/BGR -> RGB/BGR (no dither needed forms) */
1070  if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c)
1071  && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT))))
1072  c->swscale = rgbToRgbWrapper;
1073 
1074  /* RGB to planar RGB */
1075  if ((srcFormat == AV_PIX_FMT_GBRP && dstFormat == AV_PIX_FMT_GBRAP) ||
1076  (srcFormat == AV_PIX_FMT_GBRAP && dstFormat == AV_PIX_FMT_GBRP))
1078 
1079 #define isByteRGB(f) ( \
1080  f == AV_PIX_FMT_RGB32 || \
1081  f == AV_PIX_FMT_RGB32_1 || \
1082  f == AV_PIX_FMT_RGB24 || \
1083  f == AV_PIX_FMT_BGR32 || \
1084  f == AV_PIX_FMT_BGR32_1 || \
1085  f == AV_PIX_FMT_BGR24)
1086 
1087  if (srcFormat == AV_PIX_FMT_GBRP && isPlanar(srcFormat) && isByteRGB(dstFormat))
1089 
1090  if (av_pix_fmt_desc_get(srcFormat)->comp[0].depth == 8 &&
1091  isPackedRGB(srcFormat) && dstFormat == AV_PIX_FMT_GBRP)
1093 
1094  /* bswap 16 bits per pixel/component packed formats */
1095  if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR444) ||
1096  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR48) ||
1097  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR555) ||
1098  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGR565) ||
1099  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_BGRA64) ||
1100  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GRAY16) ||
1101  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_YA16) ||
1102  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_GBRAP16)||
1103  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB444) ||
1104  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB48) ||
1105  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB555) ||
1106  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGB565) ||
1107  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_RGBA64) ||
1108  IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, AV_PIX_FMT_XYZ12))
1110 
1111  if ((usePal(srcFormat) && (
1112  dstFormat == AV_PIX_FMT_RGB32 ||
1113  dstFormat == AV_PIX_FMT_RGB32_1 ||
1114  dstFormat == AV_PIX_FMT_RGB24 ||
1115  dstFormat == AV_PIX_FMT_BGR32 ||
1116  dstFormat == AV_PIX_FMT_BGR32_1 ||
1117  dstFormat == AV_PIX_FMT_BGR24)))
1118  c->swscale = palToRgbWrapper;
1119 
1120  if (srcFormat == AV_PIX_FMT_YUV422P) {
1121  if (dstFormat == AV_PIX_FMT_YUYV422)
1123  else if (dstFormat == AV_PIX_FMT_UYVY422)
1125  }
1126 
1127  /* LQ converters if -sws 0 or -sws 4*/
1128  if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) {
1129  /* yv12_to_yuy2 */
1130  if (srcFormat == AV_PIX_FMT_YUV420P || srcFormat == AV_PIX_FMT_YUVA420P) {
1131  if (dstFormat == AV_PIX_FMT_YUYV422)
1133  else if (dstFormat == AV_PIX_FMT_UYVY422)
1135  }
1136  }
1137  if (srcFormat == AV_PIX_FMT_YUYV422 &&
1138  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
1140  if (srcFormat == AV_PIX_FMT_UYVY422 &&
1141  (dstFormat == AV_PIX_FMT_YUV420P || dstFormat == AV_PIX_FMT_YUVA420P))
1143  if (srcFormat == AV_PIX_FMT_YUYV422 && dstFormat == AV_PIX_FMT_YUV422P)
1145  if (srcFormat == AV_PIX_FMT_UYVY422 && dstFormat == AV_PIX_FMT_YUV422P)
1147 
1148  /* simple copy */
1149  if ( srcFormat == dstFormat ||
1150  (srcFormat == AV_PIX_FMT_YUVA420P && dstFormat == AV_PIX_FMT_YUV420P) ||
1151  (srcFormat == AV_PIX_FMT_YUV420P && dstFormat == AV_PIX_FMT_YUVA420P) ||
1152  (isPlanarYUV(srcFormat) && isGray(dstFormat)) ||
1153  (isPlanarYUV(dstFormat) && isGray(srcFormat)) ||
1154  (isGray(dstFormat) && isGray(srcFormat)) ||
1155  (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) &&
1158  dstFormat != AV_PIX_FMT_NV12 && dstFormat != AV_PIX_FMT_NV21 &&
1159  dstFormat != AV_PIX_FMT_P010LE && dstFormat != AV_PIX_FMT_P010BE &&
1160  srcFormat != AV_PIX_FMT_NV12 && srcFormat != AV_PIX_FMT_NV21 &&
1161  srcFormat != AV_PIX_FMT_P010LE && srcFormat != AV_PIX_FMT_P010BE))
1162  {
1163  if (isPacked(c->srcFormat))
1165  else /* Planar YUV or gray */
1167  }
1168 
1169  if (ARCH_PPC)
1171 }
1172 
1173 static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
1174 {
1175  if (!isALPHA(format))
1176  src[3] = NULL;
1177  if (!isPlanar(format)) {
1178  src[3] = src[2] = NULL;
1179 
1180  if (!usePal(format))
1181  src[1] = NULL;
1182  }
1183 }
1184 
1186  const int linesizes[4])
1187 {
1188  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
1189  int i;
1190 
1191  for (i = 0; i < 4; i++) {
1192  int plane = desc->comp[i].plane;
1193  if (!data[plane] || !linesizes[plane])
1194  return 0;
1195  }
1196 
1197  return 1;
1198 }
1199 
1205  const uint8_t * const srcSlice[],
1206  const int srcStride[], int srcSliceY,
1207  int srcSliceH, uint8_t *const dst[],
1208  const int dstStride[])
1209 {
1210  int i;
1211  const uint8_t *src2[4] = { srcSlice[0], srcSlice[1], srcSlice[2], srcSlice[3] };
1212  uint8_t *dst2[4] = { dst[0], dst[1], dst[2], dst[3] };
1213 
1214  // do not mess up sliceDir if we have a "trailing" 0-size slice
1215  if (srcSliceH == 0)
1216  return 0;
1217 
1218  if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) {
1219  av_log(c, AV_LOG_ERROR, "bad src image pointers\n");
1220  return 0;
1221  }
1222  if (!check_image_pointers(dst, c->dstFormat, dstStride)) {
1223  av_log(c, AV_LOG_ERROR, "bad dst image pointers\n");
1224  return 0;
1225  }
1226 
1227  if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
1228  av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n");
1229  return 0;
1230  }
1231  if (c->sliceDir == 0) {
1232  if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1;
1233  }
1234 
1235  if (usePal(c->srcFormat)) {
1236  for (i = 0; i < 256; i++) {
1237  int r, g, b, y, u, v;
1238  if (c->srcFormat == AV_PIX_FMT_PAL8) {
1239  uint32_t p = ((const uint32_t *)(srcSlice[1]))[i];
1240  r = (p >> 16) & 0xFF;
1241  g = (p >> 8) & 0xFF;
1242  b = p & 0xFF;
1243  } else if (c->srcFormat == AV_PIX_FMT_RGB8) {
1244  r = ( i >> 5 ) * 36;
1245  g = ((i >> 2) & 7) * 36;
1246  b = ( i & 3) * 85;
1247  } else if (c->srcFormat == AV_PIX_FMT_BGR8) {
1248  b = ( i >> 6 ) * 85;
1249  g = ((i >> 3) & 7) * 36;
1250  r = ( i & 7) * 36;
1251  } else if (c->srcFormat == AV_PIX_FMT_RGB4_BYTE) {
1252  r = ( i >> 3 ) * 255;
1253  g = ((i >> 1) & 3) * 85;
1254  b = ( i & 1) * 255;
1255  } else if (c->srcFormat == AV_PIX_FMT_GRAY8 ||
1256  c->srcFormat == AV_PIX_FMT_YA8) {
1257  r = g = b = i;
1258  } else {
1259  assert(c->srcFormat == AV_PIX_FMT_BGR4_BYTE);
1260  b = ( i >> 3 ) * 255;
1261  g = ((i >> 1) & 3) * 85;
1262  r = ( i & 1) * 255;
1263  }
1264  y = av_clip_uint8((RY * r + GY * g + BY * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
1265  u = av_clip_uint8((RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
1266  v = av_clip_uint8((RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
1267  c->pal_yuv[i] = y + (u << 8) + (v << 16) + (0xFFU << 24);
1268 
1269  switch (c->dstFormat) {
1270  case AV_PIX_FMT_BGR32:
1271 #if !HAVE_BIGENDIAN
1272  case AV_PIX_FMT_RGB24:
1273 #endif
1274  c->pal_rgb[i] = r + (g << 8) + (b << 16) + (0xFFU << 24);
1275  break;
1276  case AV_PIX_FMT_BGR32_1:
1277 #if HAVE_BIGENDIAN
1278  case AV_PIX_FMT_BGR24:
1279 #endif
1280  c->pal_rgb[i] = 0xFF + (r << 8) + (g << 16) + ((unsigned)b << 24);
1281  break;
1282  case AV_PIX_FMT_RGB32_1:
1283 #if HAVE_BIGENDIAN
1284  case AV_PIX_FMT_RGB24:
1285 #endif
1286  c->pal_rgb[i] = 0xFF + (b << 8) + (g << 16) + ((unsigned)r << 24);
1287  break;
1288  case AV_PIX_FMT_RGB32:
1289 #if !HAVE_BIGENDIAN
1290  case AV_PIX_FMT_BGR24:
1291 #endif
1292  default:
1293  c->pal_rgb[i] = b + (g << 8) + (r << 16) + (0xFFU << 24);
1294  }
1295  }
1296  }
1297 
1298  // copy strides, so they can safely be modified
1299  if (c->sliceDir == 1) {
1300  // slices go from top to bottom
1301  int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2],
1302  srcStride[3] };
1303  int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2],
1304  dstStride[3] };
1305 
1306  reset_ptr(src2, c->srcFormat);
1307  reset_ptr((const uint8_t **) dst2, c->dstFormat);
1308 
1309  /* reset slice direction at end of frame */
1310  if (srcSliceY + srcSliceH == c->srcH)
1311  c->sliceDir = 0;
1312 
1313  return c->swscale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2,
1314  dstStride2);
1315  } else {
1316  // slices go from bottom to top => we flip the image internally
1317  int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2],
1318  -srcStride[3] };
1319  int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2],
1320  -dstStride[3] };
1321 
1322  src2[0] += (srcSliceH - 1) * srcStride[0];
1323  if (!usePal(c->srcFormat))
1324  src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1];
1325  src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2];
1326  src2[3] += (srcSliceH - 1) * srcStride[3];
1327  dst2[0] += ( c->dstH - 1) * dstStride[0];
1328  dst2[1] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[1];
1329  dst2[2] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[2];
1330  dst2[3] += ( c->dstH - 1) * dstStride[3];
1331 
1332  reset_ptr(src2, c->srcFormat);
1333  reset_ptr((const uint8_t **) dst2, c->dstFormat);
1334 
1335  /* reset slice direction at end of frame */
1336  if (!srcSliceY)
1337  c->sliceDir = 0;
1338 
1339  return c->swscale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH,
1340  srcSliceH, dst2, dstStride2);
1341  }
1342 }
1343 
1344 /* Convert the palette to the same packed 32-bit format as the palette */
1346  int num_pixels, const uint8_t *palette)
1347 {
1348  int i;
1349 
1350  for (i = 0; i < num_pixels; i++)
1351  ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]];
1352 }
1353 
1354 /* Palette format: ABCD -> dst format: ABC */
1356  int num_pixels, const uint8_t *palette)
1357 {
1358  int i;
1359 
1360  for (i = 0; i < num_pixels; i++) {
1361  //FIXME slow?
1362  dst[0] = palette[src[i] * 4 + 0];
1363  dst[1] = palette[src[i] * 4 + 1];
1364  dst[2] = palette[src[i] * 4 + 2];
1365  dst += 3;
1366  }
1367 }
#define IS_NOT_NE(bpp, desc)
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:56
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:78
void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, int src_size)
const char * sws_format_name(enum AVPixelFormat format)
Definition: utils.c:210
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:34
void(* rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:52
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1768
static const uint8_t dither_8x8_3[8][8]
static int packed_16bpc_bswap(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
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.
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.
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
#define ARCH_PPC
Definition: config.h:24
Definition: vf_drawbox.c:37
void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:177
uint32_t pal_rgb[256]
void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:309
void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, int src_size)
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:61
#define BU
const char * desc
Definition: nvenc.c:101
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:253
void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, int src_size)
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:162
void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:232
void(* rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:36
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
static void gbr24ptopacked32(const uint8_t *src[], int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int alpha_first, int width)
#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:58
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:258
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
external API header
#define AV_RL16
Definition: intreadwrite.h:42
#define isRGBA32(x)
static void gbr24ptopacked24(const uint8_t *src[], int srcStride[], uint8_t *dst, int dstStride, int srcSliceH, int width)
#define RGBA(r, g, b, a)
Definition: dvbsubdec.c:94
int srcRange
0 = MPG YUV range, 1 = JPG YUV range (source image).
#define COPY16TO9_OR_10(rfunc, wfunc)
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:252
int stride
Definition: mace.c:144
void(* rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:42
static const uint8_t dither_8x8_1[8][8]
int srcH
Height of source luma/alpha planes.
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:82
void(* rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:40
static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
void(* shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:54
void(* rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:45
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:98
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:119
uint8_t
#define isByteRGB(f)
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:60
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:70
static int rgbToPlanarRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
#define GU
static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
#define isRGBinInt(x)
static const uint8_t dither_8x8_64[8][8]
#define BY
#define COPY9_OR_10TO8(rfunc)
#define b
Definition: input.c:52
#define GV
void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:218
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:91
#define SWS_FAST_BILINEAR
Definition: swscale.h:57
const char data[16]
Definition: mxf.c:70
static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
static int flags
Definition: log.c:50
#define COPY9_OR_10TO16(rfunc, wfunc)
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:254
#define RGB2YUV_SHIFT
#define isAnyRGB(x)
external api for the swscale stuff
enum AVPixelFormat dstFormat
Destination pixel format.
void(* rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, int width, int height, int lumStride, int chromStride, int srcStride)
Height should be a multiple of 2 and width should be a multiple of 2.
Definition: rgb2rgb.c:76
#define isALPHA(x)
Definition: swscale.c:50
int chrSrcHSubSample
Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source imag...
#define AV_WL16(p, val)
Definition: intreadwrite.h:231
#define r
Definition: input.c:51
int dstH
Height of destination luma/alpha planes.
#define src
Definition: vp8dsp.c:254
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[])
#define CONV_IS(src, dst)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:124
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:245
#define isBGRinInt(x)
static int planarToNv12Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
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
void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, int src_size)
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:92
g
Definition: yuv2rgb.c:546
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:248
void(* rgbConvFn)(const uint8_t *, uint8_t *, int)
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:86
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:249
static void fillPlane(uint8_t *plane, int stride, int width, int height, int y, uint8_t val)
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, big-endian
Definition: pixfmt.h:231
static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
void(* rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:43
void(* rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:37
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:89
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:274
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:90
void(* rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:47
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:63
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[])
void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:288
as above, but U and V bytes are swapped
Definition: pixfmt.h:87
#define COPY9_OR_10TO9_OR_10_2(rfunc, wfunc)
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:82
#define GY
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:247
#define FFMIN(a, b)
Definition: common.h:66
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:85
static void fill_plane9or10(uint8_t *plane, int stride, int width, int height, int y, uint8_t val, const int dst_depth, const int big_endian)
static av_always_inline int is9_OR_10BPS(enum AVPixelFormat pix_fmt)
#define RV
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:64
#define FFABS(a)
Definition: common.h:61
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:62
void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:199
enum AVPixelFormat pix_fmt
Definition: movenc.c:853
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian
Definition: pixfmt.h:230
static int check_image_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, const int linesizes[4])
int sliceDir
Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top).
void(* rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:38
static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
#define AV_PIX_FMT_BGR555
Definition: pixfmt.h:256
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:244
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
#define attribute_align_arg
Definition: internal.h:55
NULL
Definition: eval.c:55
void(* rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:50
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:80
static int width
Definition: utils.c:156
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:85
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:104
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:80
#define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt)
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:242
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:60
int attribute_align_arg sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don&#39;t need to export the SwsContext.
void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:139
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:65
#define AV_PIX_FMT_XYZ12
Definition: pixfmt.h:286
const char * format
Definition: movenc.c:47
static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
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:68
SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c)
Definition: yuv2rgb.c:570
#define SWS_ACCURATE_RND
Definition: swscale.h:82
byte swapping routines
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:101
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette)
void(* rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:48
#define RU
#define u(width,...)
static const uint8_t dither_8x8_256[8][8]
void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:157
#define SWS_POINT
Definition: swscale.h:61
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:98
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:255
#define BV
static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
void(* rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:49
#define SWS_BITEXACT
Definition: swscale.h:83
void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:298
int height
Definition: gxfenc.c:72
void(* rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:39
void(* rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:41
#define FILL8TO9_OR_10(wfunc)
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:59
Y , 8bpp.
Definition: pixfmt.h:67
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:208
#define COPY16TO8(rfunc)
#define AV_PIX_FMT_BGR444
Definition: pixfmt.h:257
enum AVPixelFormat srcFormat
Source pixel format.
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:83
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:251
static void copyPlane(const uint8_t *src, int srcStride, int srcSliceY, int srcSliceH, int width, uint8_t *dst, int dstStride)
SwsFunc swscale
Note that src, dst, srcStride, dstStride will be copied in the sws_scale() wrapper so they can be fre...
static int planarToUyvyWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dstParam[], int dstStride[])
void(* rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:46
#define RY
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:243
void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:252
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(* planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, int srcStride, int dstStride)
Definition: rgb2rgb.c:80
void(* rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:35
av_cold void ff_get_unscaled_swscale_ppc(SwsContext *c)
#define COPY8TO9_OR_10(wfunc)
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:250
static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:83
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:1704
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.
#define isGray(x)
int depth
Number of bits in the component.
Definition: pixdesc.h:57
#define AV_WB16(p, val)
Definition: intreadwrite.h:218
int srcW
Width of source luma/alpha planes.
void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:242
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...
AVPixelFormat
Pixel format.
Definition: pixfmt.h:57
uint32_t pal_yuv[256]
void(* rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:51
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:107
#define AV_CEIL_RSHIFT(a, b)
Fast a / (1 << b) rounded toward +inf, assuming a >= 0 and b >= 0.
Definition: common.h:57
void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size)
Definition: rgb2rgb.c:274