FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
swscale.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 <math.h>
23 #include <stdio.h>
24 #include <string.h>
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/avutil.h"
28 #include "libavutil/bswap.h"
29 #include "libavutil/cpu.h"
30 #include "libavutil/imgutils.h"
31 #include "libavutil/intreadwrite.h"
32 #include "libavutil/mathematics.h"
33 #include "libavutil/pixdesc.h"
34 #include "config.h"
35 #include "rgb2rgb.h"
36 #include "swscale_internal.h"
37 #include "swscale.h"
38 
40  { 36, 68, 60, 92, 34, 66, 58, 90, },
41  { 100, 4, 124, 28, 98, 2, 122, 26, },
42  { 52, 84, 44, 76, 50, 82, 42, 74, },
43  { 116, 20, 108, 12, 114, 18, 106, 10, },
44  { 32, 64, 56, 88, 38, 70, 62, 94, },
45  { 96, 0, 120, 24, 102, 6, 126, 30, },
46  { 48, 80, 40, 72, 54, 86, 46, 78, },
47  { 112, 16, 104, 8, 118, 22, 110, 14, },
48  { 36, 68, 60, 92, 34, 66, 58, 90, },
49 };
50 
51 DECLARE_ALIGNED(8, static const uint8_t, sws_pb_64)[8] = {
52  64, 64, 64, 64, 64, 64, 64, 64
53 };
54 
55 #ifndef NEW_FILTER
56 static void gamma_convert(uint8_t * src[], int width, uint16_t *gamma)
57 {
58  int i;
59  uint16_t *src1 = (uint16_t*)src[0];
60 
61  for (i = 0; i < width; ++i) {
62  uint16_t r = AV_RL16(src1 + i*4 + 0);
63  uint16_t g = AV_RL16(src1 + i*4 + 1);
64  uint16_t b = AV_RL16(src1 + i*4 + 2);
65 
66  AV_WL16(src1 + i*4 + 0, gamma[r]);
67  AV_WL16(src1 + i*4 + 1, gamma[g]);
68  AV_WL16(src1 + i*4 + 2, gamma[b]);
69  }
70 }
71 #endif
72 
73 static av_always_inline void fillPlane(uint8_t *plane, int stride, int width,
74  int height, int y, uint8_t val)
75 {
76  int i;
77  uint8_t *ptr = plane + stride * y;
78  for (i = 0; i < height; i++) {
79  memset(ptr, val, width);
80  ptr += stride;
81  }
82 }
83 
84 static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW,
85  const uint8_t *_src, const int16_t *filter,
86  const int32_t *filterPos, int filterSize)
87 {
89  int i;
90  int32_t *dst = (int32_t *) _dst;
91  const uint16_t *src = (const uint16_t *) _src;
92  int bits = desc->comp[0].depth - 1;
93  int sh = bits - 4;
94 
95  if((isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8) && desc->comp[0].depth<16)
96  sh= 9;
97 
98  for (i = 0; i < dstW; i++) {
99  int j;
100  int srcPos = filterPos[i];
101  int val = 0;
102 
103  for (j = 0; j < filterSize; j++) {
104  val += src[srcPos + j] * filter[filterSize * i + j];
105  }
106  // filter=14 bit, input=16 bit, output=30 bit, >> 11 makes 19 bit
107  dst[i] = FFMIN(val >> sh, (1 << 19) - 1);
108  }
109 }
110 
111 static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW,
112  const uint8_t *_src, const int16_t *filter,
113  const int32_t *filterPos, int filterSize)
114 {
116  int i;
117  const uint16_t *src = (const uint16_t *) _src;
118  int sh = desc->comp[0].depth - 1;
119 
120  if(sh<15)
121  sh= isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1);
122 
123  for (i = 0; i < dstW; i++) {
124  int j;
125  int srcPos = filterPos[i];
126  int val = 0;
127 
128  for (j = 0; j < filterSize; j++) {
129  val += src[srcPos + j] * filter[filterSize * i + j];
130  }
131  // filter=14 bit, input=16 bit, output=30 bit, >> 15 makes 15 bit
132  dst[i] = FFMIN(val >> sh, (1 << 15) - 1);
133  }
134 }
135 
136 // bilinear / bicubic scaling
137 static void hScale8To15_c(SwsContext *c, int16_t *dst, int dstW,
138  const uint8_t *src, const int16_t *filter,
139  const int32_t *filterPos, int filterSize)
140 {
141  int i;
142  for (i = 0; i < dstW; i++) {
143  int j;
144  int srcPos = filterPos[i];
145  int val = 0;
146  for (j = 0; j < filterSize; j++) {
147  val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
148  }
149  dst[i] = FFMIN(val >> 7, (1 << 15) - 1); // the cubic equation does overflow ...
150  }
151 }
152 
153 static void hScale8To19_c(SwsContext *c, int16_t *_dst, int dstW,
154  const uint8_t *src, const int16_t *filter,
155  const int32_t *filterPos, int filterSize)
156 {
157  int i;
158  int32_t *dst = (int32_t *) _dst;
159  for (i = 0; i < dstW; i++) {
160  int j;
161  int srcPos = filterPos[i];
162  int val = 0;
163  for (j = 0; j < filterSize; j++) {
164  val += ((int)src[srcPos + j]) * filter[filterSize * i + j];
165  }
166  dst[i] = FFMIN(val >> 3, (1 << 19) - 1); // the cubic equation does overflow ...
167  }
168 }
169 
170 // FIXME all pal and rgb srcFormats could do this conversion as well
171 // FIXME all scalers more complex than bilinear could do half of this transform
172 static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width)
173 {
174  int i;
175  for (i = 0; i < width; i++) {
176  dstU[i] = (FFMIN(dstU[i], 30775) * 4663 - 9289992) >> 12; // -264
177  dstV[i] = (FFMIN(dstV[i], 30775) * 4663 - 9289992) >> 12; // -264
178  }
179 }
180 
181 static void chrRangeFromJpeg_c(int16_t *dstU, int16_t *dstV, int width)
182 {
183  int i;
184  for (i = 0; i < width; i++) {
185  dstU[i] = (dstU[i] * 1799 + 4081085) >> 11; // 1469
186  dstV[i] = (dstV[i] * 1799 + 4081085) >> 11; // 1469
187  }
188 }
189 
190 static void lumRangeToJpeg_c(int16_t *dst, int width)
191 {
192  int i;
193  for (i = 0; i < width; i++)
194  dst[i] = (FFMIN(dst[i], 30189) * 19077 - 39057361) >> 14;
195 }
196 
197 static void lumRangeFromJpeg_c(int16_t *dst, int width)
198 {
199  int i;
200  for (i = 0; i < width; i++)
201  dst[i] = (dst[i] * 14071 + 33561947) >> 14;
202 }
203 
204 static void chrRangeToJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width)
205 {
206  int i;
207  int32_t *dstU = (int32_t *) _dstU;
208  int32_t *dstV = (int32_t *) _dstV;
209  for (i = 0; i < width; i++) {
210  dstU[i] = (FFMIN(dstU[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12; // -264
211  dstV[i] = (FFMIN(dstV[i], 30775 << 4) * 4663 - (9289992 << 4)) >> 12; // -264
212  }
213 }
214 
215 static void chrRangeFromJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width)
216 {
217  int i;
218  int32_t *dstU = (int32_t *) _dstU;
219  int32_t *dstV = (int32_t *) _dstV;
220  for (i = 0; i < width; i++) {
221  dstU[i] = (dstU[i] * 1799 + (4081085 << 4)) >> 11; // 1469
222  dstV[i] = (dstV[i] * 1799 + (4081085 << 4)) >> 11; // 1469
223  }
224 }
225 
226 static void lumRangeToJpeg16_c(int16_t *_dst, int width)
227 {
228  int i;
229  int32_t *dst = (int32_t *) _dst;
230  for (i = 0; i < width; i++) {
231  dst[i] = ((int)(FFMIN(dst[i], 30189 << 4) * 4769U - (39057361 << 2))) >> 12;
232  }
233 }
234 
235 static void lumRangeFromJpeg16_c(int16_t *_dst, int width)
236 {
237  int i;
238  int32_t *dst = (int32_t *) _dst;
239  for (i = 0; i < width; i++)
240  dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12;
241 }
242 
243 #ifndef NEW_FILTER
244 // *** horizontal scale Y line to temp buffer
245 static av_always_inline void hyscale(SwsContext *c, int16_t *dst, int dstWidth,
246  const uint8_t *src_in[4],
247  int srcW, int xInc,
248  const int16_t *hLumFilter,
249  const int32_t *hLumFilterPos,
250  int hLumFilterSize,
252  uint32_t *pal, int isAlpha)
253 {
254  void (*toYV12)(uint8_t *, const uint8_t *, const uint8_t *, const uint8_t *, int, uint32_t *) =
255  isAlpha ? c->alpToYV12 : c->lumToYV12;
256  void (*convertRange)(int16_t *, int) = isAlpha ? NULL : c->lumConvertRange;
257  const uint8_t *src = src_in[isAlpha ? 3 : 0];
258 
259  if (toYV12) {
260  toYV12(formatConvBuffer, src, src_in[1], src_in[2], srcW, pal);
261  src = formatConvBuffer;
262  } else if (c->readLumPlanar && !isAlpha) {
263  c->readLumPlanar(formatConvBuffer, src_in, srcW, c->input_rgb2yuv_table);
264  src = formatConvBuffer;
265  } else if (c->readAlpPlanar && isAlpha) {
266  c->readAlpPlanar(formatConvBuffer, src_in, srcW, NULL);
267  src = formatConvBuffer;
268  }
269 
270  if (!c->hyscale_fast) {
271  c->hyScale(c, dst, dstWidth, src, hLumFilter,
272  hLumFilterPos, hLumFilterSize);
273  } else { // fast bilinear upscale / crap downscale
274  c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc);
275  }
276 
277  if (convertRange)
278  convertRange(dst, dstWidth);
279 }
280 
281 static av_always_inline void hcscale(SwsContext *c, int16_t *dst1,
282  int16_t *dst2, int dstWidth,
283  const uint8_t *src_in[4],
284  int srcW, int xInc,
285  const int16_t *hChrFilter,
286  const int32_t *hChrFilterPos,
287  int hChrFilterSize,
288  uint8_t *formatConvBuffer, uint32_t *pal)
289 {
290  const uint8_t *src1 = src_in[1], *src2 = src_in[2];
291  if (c->chrToYV12) {
292  uint8_t *buf2 = formatConvBuffer +
293  FFALIGN(srcW*2+78, 16);
294  c->chrToYV12(formatConvBuffer, buf2, src_in[0], src1, src2, srcW, pal);
295  src1= formatConvBuffer;
296  src2= buf2;
297  } else if (c->readChrPlanar) {
298  uint8_t *buf2 = formatConvBuffer +
299  FFALIGN(srcW*2+78, 16);
300  c->readChrPlanar(formatConvBuffer, buf2, src_in, srcW, c->input_rgb2yuv_table);
301  src1 = formatConvBuffer;
302  src2 = buf2;
303  }
304 
305  if (!c->hcscale_fast) {
306  c->hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize);
307  c->hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize);
308  } else { // fast bilinear upscale / crap downscale
309  c->hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc);
310  }
311 
312  if (c->chrConvertRange)
313  c->chrConvertRange(dst1, dst2, dstWidth);
314 }
315 #endif /* NEW_FILTER */
316 
317 #define DEBUG_SWSCALE_BUFFERS 0
318 #define DEBUG_BUFFERS(...) \
319  if (DEBUG_SWSCALE_BUFFERS) \
320  av_log(c, AV_LOG_DEBUG, __VA_ARGS__)
321 
322 static int swscale(SwsContext *c, const uint8_t *src[],
323  int srcStride[], int srcSliceY,
324  int srcSliceH, uint8_t *dst[], int dstStride[])
325 {
326  /* load a few things into local vars to make the code more readable?
327  * and faster */
328 #ifndef NEW_FILTER
329  const int srcW = c->srcW;
330 #endif
331  const int dstW = c->dstW;
332  const int dstH = c->dstH;
333 #ifndef NEW_FILTER
334  const int chrDstW = c->chrDstW;
335  const int chrSrcW = c->chrSrcW;
336  const int lumXInc = c->lumXInc;
337  const int chrXInc = c->chrXInc;
338 #endif
339  const enum AVPixelFormat dstFormat = c->dstFormat;
340  const int flags = c->flags;
343 #ifndef NEW_FILTER
344  int32_t *hLumFilterPos = c->hLumFilterPos;
345  int32_t *hChrFilterPos = c->hChrFilterPos;
346  int16_t *hLumFilter = c->hLumFilter;
347  int16_t *hChrFilter = c->hChrFilter;
350 #endif
351  const int vLumFilterSize = c->vLumFilterSize;
352  const int vChrFilterSize = c->vChrFilterSize;
353 #ifndef NEW_FILTER
354  const int hLumFilterSize = c->hLumFilterSize;
355  const int hChrFilterSize = c->hChrFilterSize;
356  int16_t **lumPixBuf = c->lumPixBuf;
357  int16_t **chrUPixBuf = c->chrUPixBuf;
358  int16_t **chrVPixBuf = c->chrVPixBuf;
359 #endif
360  int16_t **alpPixBuf = c->alpPixBuf;
361  const int vLumBufSize = c->vLumBufSize;
362  const int vChrBufSize = c->vChrBufSize;
363 #ifndef NEW_FILTER
364  uint8_t *formatConvBuffer = c->formatConvBuffer;
365  uint32_t *pal = c->pal_yuv;
366  int perform_gamma = c->is_internal_gamma;
367 #endif
375  const int chrSrcSliceY = srcSliceY >> c->chrSrcVSubSample;
376  const int chrSrcSliceH = AV_CEIL_RSHIFT(srcSliceH, c->chrSrcVSubSample);
377  int should_dither = is9_OR_10BPS(c->srcFormat) ||
378  is16BPS(c->srcFormat);
379  int lastDstY;
380 
381  /* vars which will change and which we need to store back in the context */
382  int dstY = c->dstY;
383  int lumBufIndex = c->lumBufIndex;
384  int chrBufIndex = c->chrBufIndex;
385  int lastInLumBuf = c->lastInLumBuf;
386  int lastInChrBuf = c->lastInChrBuf;
387 
388 #ifdef NEW_FILTER
389  int lumStart = 0;
390  int lumEnd = c->descIndex[0];
391  int chrStart = lumEnd;
392  int chrEnd = c->descIndex[1];
393  int vStart = chrEnd;
394  int vEnd = c->numDesc;
395  SwsSlice *src_slice = &c->slice[lumStart];
396  SwsSlice *hout_slice = &c->slice[c->numSlice-2];
397  SwsSlice *vout_slice = &c->slice[c->numSlice-1];
399 
400  int hasLumHoles = 1;
401  int hasChrHoles = 1;
402 #endif
403 
404 #ifndef NEW_FILTER
405  if (!usePal(c->srcFormat)) {
406  pal = c->input_rgb2yuv_table;
407  }
408 #endif
409 
410  if (isPacked(c->srcFormat)) {
411  src[0] =
412  src[1] =
413  src[2] =
414  src[3] = src[0];
415  srcStride[0] =
416  srcStride[1] =
417  srcStride[2] =
418  srcStride[3] = srcStride[0];
419  }
420  srcStride[1] <<= c->vChrDrop;
421  srcStride[2] <<= c->vChrDrop;
422 
423  DEBUG_BUFFERS("swscale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n",
424  src[0], srcStride[0], src[1], srcStride[1],
425  src[2], srcStride[2], src[3], srcStride[3],
426  dst[0], dstStride[0], dst[1], dstStride[1],
427  dst[2], dstStride[2], dst[3], dstStride[3]);
428  DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n",
429  srcSliceY, srcSliceH, dstY, dstH);
430  DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n",
431  vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize);
432 
433  if (dstStride[0]&15 || dstStride[1]&15 ||
434  dstStride[2]&15 || dstStride[3]&15) {
435  static int warnedAlready = 0; // FIXME maybe move this into the context
436  if (flags & SWS_PRINT_INFO && !warnedAlready) {
438  "Warning: dstStride is not aligned!\n"
439  " ->cannot do aligned memory accesses anymore\n");
440  warnedAlready = 1;
441  }
442  }
443 
444  if ( (uintptr_t)dst[0]&15 || (uintptr_t)dst[1]&15 || (uintptr_t)dst[2]&15
445  || (uintptr_t)src[0]&15 || (uintptr_t)src[1]&15 || (uintptr_t)src[2]&15
446  || dstStride[0]&15 || dstStride[1]&15 || dstStride[2]&15 || dstStride[3]&15
447  || srcStride[0]&15 || srcStride[1]&15 || srcStride[2]&15 || srcStride[3]&15
448  ) {
449  static int warnedAlready=0;
450  int cpu_flags = av_get_cpu_flags();
451  if (HAVE_MMXEXT && (cpu_flags & AV_CPU_FLAG_SSE2) && !warnedAlready){
452  av_log(c, AV_LOG_WARNING, "Warning: data is not aligned! This can lead to a speedloss\n");
453  warnedAlready=1;
454  }
455  }
456 
457  /* Note the user might start scaling the picture in the middle so this
458  * will not get executed. This is not really intended but works
459  * currently, so people might do it. */
460  if (srcSliceY == 0) {
461  lumBufIndex = -1;
462  chrBufIndex = -1;
463  dstY = 0;
464  lastInLumBuf = -1;
465  lastInChrBuf = -1;
466  }
467 
468  if (!should_dither) {
469  c->chrDither8 = c->lumDither8 = sws_pb_64;
470  }
471  lastDstY = dstY;
472 
473 #ifdef NEW_FILTER
474  ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
475  yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, c->use_mmx_vfilter);
476 
477  ff_init_slice_from_src(src_slice, (uint8_t**)src, srcStride, c->srcW,
478  srcSliceY, srcSliceH, chrSrcSliceY, chrSrcSliceH, 1);
479 
480  ff_init_slice_from_src(vout_slice, (uint8_t**)dst, dstStride, c->dstW,
481  dstY, dstH, dstY >> c->chrDstVSubSample,
482  AV_CEIL_RSHIFT(dstH, c->chrDstVSubSample), 0);
483  if (srcSliceY == 0) {
484  hout_slice->plane[0].sliceY = lastInLumBuf + 1;
485  hout_slice->plane[1].sliceY = lastInChrBuf + 1;
486  hout_slice->plane[2].sliceY = lastInChrBuf + 1;
487  hout_slice->plane[3].sliceY = lastInLumBuf + 1;
488 
489  hout_slice->plane[0].sliceH =
490  hout_slice->plane[1].sliceH =
491  hout_slice->plane[2].sliceH =
492  hout_slice->plane[3].sliceH = 0;
493  hout_slice->width = dstW;
494  }
495 #endif
496 
497  for (; dstY < dstH; dstY++) {
498  const int chrDstY = dstY >> c->chrDstVSubSample;
499 #ifndef NEW_FILTER
500  uint8_t *dest[4] = {
501  dst[0] + dstStride[0] * dstY,
502  dst[1] + dstStride[1] * chrDstY,
503  dst[2] + dstStride[2] * chrDstY,
504  (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL,
505  };
506 #endif
508 
509  // First line needed as input
510  const int firstLumSrcY = FFMAX(1 - vLumFilterSize, vLumFilterPos[dstY]);
511  const int firstLumSrcY2 = FFMAX(1 - vLumFilterSize, vLumFilterPos[FFMIN(dstY | ((1 << c->chrDstVSubSample) - 1), dstH - 1)]);
512  // First line needed as input
513  const int firstChrSrcY = FFMAX(1 - vChrFilterSize, vChrFilterPos[chrDstY]);
514 
515  // Last line needed as input
516  int lastLumSrcY = FFMIN(c->srcH, firstLumSrcY + vLumFilterSize) - 1;
517  int lastLumSrcY2 = FFMIN(c->srcH, firstLumSrcY2 + vLumFilterSize) - 1;
518  int lastChrSrcY = FFMIN(c->chrSrcH, firstChrSrcY + vChrFilterSize) - 1;
519  int enough_lines;
520 #ifdef NEW_FILTER
521  int i;
522  int posY, cPosY, firstPosY, lastPosY, firstCPosY, lastCPosY;
523 #endif
524 
525  // handle holes (FAST_BILINEAR & weird filters)
526  if (firstLumSrcY > lastInLumBuf) {
527 #ifdef NEW_FILTER
528  hasLumHoles = lastInLumBuf != firstLumSrcY - 1;
529  if (hasLumHoles) {
530  hout_slice->plane[0].sliceY = firstLumSrcY;
531  hout_slice->plane[3].sliceY = firstLumSrcY;
532  hout_slice->plane[0].sliceH =
533  hout_slice->plane[3].sliceH = 0;
534  }
535 #endif
536  lastInLumBuf = firstLumSrcY - 1;
537  }
538  if (firstChrSrcY > lastInChrBuf) {
539 #ifdef NEW_FILTER
540  hasChrHoles = lastInChrBuf != firstChrSrcY - 1;
541  if (hasChrHoles) {
542  hout_slice->plane[1].sliceY = firstChrSrcY;
543  hout_slice->plane[2].sliceY = firstChrSrcY;
544  hout_slice->plane[1].sliceH =
545  hout_slice->plane[2].sliceH = 0;
546  }
547 #endif
548  lastInChrBuf = firstChrSrcY - 1;
549  }
550  av_assert0(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1);
551  av_assert0(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1);
552 
553  DEBUG_BUFFERS("dstY: %d\n", dstY);
554  DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n",
555  firstLumSrcY, lastLumSrcY, lastInLumBuf);
556  DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n",
557  firstChrSrcY, lastChrSrcY, lastInChrBuf);
558 
559  // Do we have enough lines in this slice to output the dstY line
560  enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH &&
561  lastChrSrcY < AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample);
562 
563  if (!enough_lines) {
564  lastLumSrcY = srcSliceY + srcSliceH - 1;
565  lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1;
566  DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n",
567  lastLumSrcY, lastChrSrcY);
568  }
569 
570 #ifdef NEW_FILTER
571  posY = hout_slice->plane[0].sliceY + hout_slice->plane[0].sliceH;
572  if (posY <= lastLumSrcY && !hasLumHoles) {
573  firstPosY = FFMAX(firstLumSrcY, posY);
574  lastPosY = FFMIN(lastLumSrcY + MAX_LINES_AHEAD, srcSliceY + srcSliceH - 1);
575  } else {
576  firstPosY = lastInLumBuf + 1;
577  lastPosY = lastLumSrcY;
578  }
579 
580  cPosY = hout_slice->plane[1].sliceY + hout_slice->plane[1].sliceH;
581  if (cPosY <= lastChrSrcY && !hasChrHoles) {
582  firstCPosY = FFMAX(firstChrSrcY, cPosY);
583  lastCPosY = FFMIN(lastChrSrcY + MAX_LINES_AHEAD, AV_CEIL_RSHIFT(srcSliceY + srcSliceH, c->chrSrcVSubSample) - 1);
584  } else {
585  firstCPosY = lastInChrBuf + 1;
586  lastCPosY = lastChrSrcY;
587  }
588 
589  ff_rotate_slice(hout_slice, lastPosY, lastCPosY);
590 
591  if (posY < lastLumSrcY + 1) {
592  for (i = lumStart; i < lumEnd; ++i)
593  desc[i].process(c, &desc[i], firstPosY, lastPosY - firstPosY + 1);
594  }
595 
596  lumBufIndex += lastLumSrcY - lastInLumBuf;
597  lastInLumBuf = lastLumSrcY;
598 
599  if (cPosY < lastChrSrcY + 1) {
600  for (i = chrStart; i < chrEnd; ++i)
601  desc[i].process(c, &desc[i], firstCPosY, lastCPosY - firstCPosY + 1);
602  }
603 
604  chrBufIndex += lastChrSrcY - lastInChrBuf;
605  lastInChrBuf = lastChrSrcY;
606 
607 #else
608  // Do horizontal scaling
609  while (lastInLumBuf < lastLumSrcY) {
610  const uint8_t *src1[4] = {
611  src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0],
612  src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1],
613  src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2],
614  src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3],
615  };
616  lumBufIndex++;
617  av_assert0(lumBufIndex < 2 * vLumBufSize);
618  av_assert0(lastInLumBuf + 1 - srcSliceY < srcSliceH);
619  av_assert0(lastInLumBuf + 1 - srcSliceY >= 0);
620 
621  if (perform_gamma)
622  gamma_convert((uint8_t **)src1, srcW, c->inv_gamma);
623 
624  hyscale(c, lumPixBuf[lumBufIndex], dstW, src1, srcW, lumXInc,
625  hLumFilter, hLumFilterPos, hLumFilterSize,
626  formatConvBuffer, pal, 0);
627  if (CONFIG_SWSCALE_ALPHA && alpPixBuf)
628  hyscale(c, alpPixBuf[lumBufIndex], dstW, src1, srcW,
629  lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize,
630  formatConvBuffer, pal, 1);
631  lastInLumBuf++;
632  DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n",
633  lumBufIndex, lastInLumBuf);
634  }
635  while (lastInChrBuf < lastChrSrcY) {
636  const uint8_t *src1[4] = {
637  src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0],
638  src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1],
639  src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2],
640  src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3],
641  };
642  chrBufIndex++;
643  av_assert0(chrBufIndex < 2 * vChrBufSize);
644  av_assert0(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH));
645  av_assert0(lastInChrBuf + 1 - chrSrcSliceY >= 0);
646  // FIXME replace parameters through context struct (some at least)
647 
648  if (c->needs_hcscale)
649  hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex],
650  chrDstW, src1, chrSrcW, chrXInc,
651  hChrFilter, hChrFilterPos, hChrFilterSize,
652  formatConvBuffer, pal);
653  lastInChrBuf++;
654  DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n",
655  chrBufIndex, lastInChrBuf);
656  }
657 #endif
658  // wrap buf index around to stay inside the ring buffer
659  if (lumBufIndex >= vLumBufSize)
660  lumBufIndex -= vLumBufSize;
661  if (chrBufIndex >= vChrBufSize)
662  chrBufIndex -= vChrBufSize;
663  if (!enough_lines)
664  break; // we can't output a dstY line so let's try with the next slice
665 
666 #if HAVE_MMX_INLINE
667  ff_updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex,
668  lastInLumBuf, lastInChrBuf);
669 #endif
670  if (should_dither) {
671  c->chrDither8 = ff_dither_8x8_128[chrDstY & 7];
672  c->lumDither8 = ff_dither_8x8_128[dstY & 7];
673  }
674  if (dstY >= dstH - 2) {
675  /* hmm looks like we can't use MMX here without overwriting
676  * this array's tail */
677  ff_sws_init_output_funcs(c, &yuv2plane1, &yuv2planeX, &yuv2nv12cX,
678  &yuv2packed1, &yuv2packed2, &yuv2packedX, &yuv2anyX);
679  use_mmx_vfilter= 0;
680  ff_init_vscale_pfn(c, yuv2plane1, yuv2planeX, yuv2nv12cX,
681  yuv2packed1, yuv2packed2, yuv2packedX, yuv2anyX, use_mmx_vfilter);
682  }
683 
684  {
685 #ifdef NEW_FILTER
686  for (i = vStart; i < vEnd; ++i)
687  desc[i].process(c, &desc[i], dstY, 1);
688 #else
689  const int16_t **lumSrcPtr = (const int16_t **)(void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize;
690  const int16_t **chrUSrcPtr = (const int16_t **)(void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
691  const int16_t **chrVSrcPtr = (const int16_t **)(void*) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize;
692  const int16_t **alpSrcPtr = (CONFIG_SWSCALE_ALPHA && alpPixBuf) ?
693  (const int16_t **)(void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL;
694  int16_t *vLumFilter = c->vLumFilter;
695  int16_t *vChrFilter = c->vChrFilter;
696 
697  if (isPlanarYUV(dstFormat) ||
698  (isGray(dstFormat) && !isALPHA(dstFormat))) { // YV12 like
699  const int chrSkipMask = (1 << c->chrDstVSubSample) - 1;
700 
701  vLumFilter += dstY * vLumFilterSize;
702  vChrFilter += chrDstY * vChrFilterSize;
703 
704 // av_assert0(use_mmx_vfilter != (
705 // yuv2planeX == yuv2planeX_10BE_c
706 // || yuv2planeX == yuv2planeX_10LE_c
707 // || yuv2planeX == yuv2planeX_9BE_c
708 // || yuv2planeX == yuv2planeX_9LE_c
709 // || yuv2planeX == yuv2planeX_16BE_c
710 // || yuv2planeX == yuv2planeX_16LE_c
711 // || yuv2planeX == yuv2planeX_8_c) || !ARCH_X86);
712 
713  if(use_mmx_vfilter){
714  vLumFilter= (int16_t *)c->lumMmxFilter;
715  vChrFilter= (int16_t *)c->chrMmxFilter;
716  }
717 
718  if (vLumFilterSize == 1) {
719  yuv2plane1(lumSrcPtr[0], dest[0], dstW, c->lumDither8, 0);
720  } else {
721  yuv2planeX(vLumFilter, vLumFilterSize,
722  lumSrcPtr, dest[0],
723  dstW, c->lumDither8, 0);
724  }
725 
726  if (!((dstY & chrSkipMask) || isGray(dstFormat))) {
727  if (yuv2nv12cX) {
728  yuv2nv12cX(c, vChrFilter,
729  vChrFilterSize, chrUSrcPtr, chrVSrcPtr,
730  dest[1], chrDstW);
731  } else if (vChrFilterSize == 1) {
732  yuv2plane1(chrUSrcPtr[0], dest[1], chrDstW, c->chrDither8, 0);
733  yuv2plane1(chrVSrcPtr[0], dest[2], chrDstW, c->chrDither8, 3);
734  } else {
735  yuv2planeX(vChrFilter,
736  vChrFilterSize, chrUSrcPtr, dest[1],
737  chrDstW, c->chrDither8, 0);
738  yuv2planeX(vChrFilter,
739  vChrFilterSize, chrVSrcPtr, dest[2],
740  chrDstW, c->chrDither8, use_mmx_vfilter ? (c->uv_offx2 >> 1) : 3);
741  }
742  }
743 
744  if (CONFIG_SWSCALE_ALPHA && alpPixBuf) {
745  if(use_mmx_vfilter){
746  vLumFilter= (int16_t *)c->alpMmxFilter;
747  }
748  if (vLumFilterSize == 1) {
749  yuv2plane1(alpSrcPtr[0], dest[3], dstW,
750  c->lumDither8, 0);
751  } else {
752  yuv2planeX(vLumFilter,
753  vLumFilterSize, alpSrcPtr, dest[3],
754  dstW, c->lumDither8, 0);
755  }
756  }
757  } else if (yuv2packedX) {
758  av_assert1(lumSrcPtr + vLumFilterSize - 1 < (const int16_t **)lumPixBuf + vLumBufSize * 2);
759  av_assert1(chrUSrcPtr + vChrFilterSize - 1 < (const int16_t **)chrUPixBuf + vChrBufSize * 2);
760  if (c->yuv2packed1 && vLumFilterSize == 1 &&
761  vChrFilterSize <= 2) { // unscaled RGB
762  int chrAlpha = vChrFilterSize == 1 ? 0 : vChrFilter[2 * dstY + 1];
763  yuv2packed1(c, *lumSrcPtr, chrUSrcPtr, chrVSrcPtr,
764  alpPixBuf ? *alpSrcPtr : NULL,
765  dest[0], dstW, chrAlpha, dstY);
766  } else if (c->yuv2packed2 && vLumFilterSize == 2 &&
767  vChrFilterSize == 2) { // bilinear upscale RGB
768  int lumAlpha = vLumFilter[2 * dstY + 1];
769  int chrAlpha = vChrFilter[2 * dstY + 1];
770  lumMmxFilter[2] =
771  lumMmxFilter[3] = vLumFilter[2 * dstY] * 0x10001;
772  chrMmxFilter[2] =
773  chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001;
774  yuv2packed2(c, lumSrcPtr, chrUSrcPtr, chrVSrcPtr,
775  alpPixBuf ? alpSrcPtr : NULL,
776  dest[0], dstW, lumAlpha, chrAlpha, dstY);
777  } else { // general RGB
778  yuv2packedX(c, vLumFilter + dstY * vLumFilterSize,
779  lumSrcPtr, vLumFilterSize,
780  vChrFilter + dstY * vChrFilterSize,
781  chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
782  alpSrcPtr, dest[0], dstW, dstY);
783  }
784  } else {
785  av_assert1(!yuv2packed1 && !yuv2packed2);
786  yuv2anyX(c, vLumFilter + dstY * vLumFilterSize,
787  lumSrcPtr, vLumFilterSize,
788  vChrFilter + dstY * vChrFilterSize,
789  chrUSrcPtr, chrVSrcPtr, vChrFilterSize,
790  alpSrcPtr, dest, dstW, dstY);
791  }
792  if (perform_gamma)
793  gamma_convert(dest, dstW, c->gamma);
794 #endif
795  }
796  }
797  if (isPlanar(dstFormat) && isALPHA(dstFormat) && !alpPixBuf) {
798  int length = dstW;
799  int height = dstY - lastDstY;
800 
801  if (is16BPS(dstFormat) || isNBPS(dstFormat)) {
802  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(dstFormat);
803  fillPlane16(dst[3], dstStride[3], length, height, lastDstY,
804  1, desc->comp[3].depth,
805  isBE(dstFormat));
806  } else
807  fillPlane(dst[3], dstStride[3], length, height, lastDstY, 255);
808  }
809 
810 #if HAVE_MMXEXT_INLINE
812  __asm__ volatile ("sfence" ::: "memory");
813 #endif
814  emms_c();
815 
816  /* store changed local vars back in the context */
817  c->dstY = dstY;
822 
823  return dstY - lastDstY;
824 }
825 
827 {
828  c->lumConvertRange = NULL;
829  c->chrConvertRange = NULL;
830  if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) {
831  if (c->dstBpc <= 14) {
832  if (c->srcRange) {
835  } else {
838  }
839  } else {
840  if (c->srcRange) {
843  } else {
846  }
847  }
848  }
849 }
850 
852 {
854 
856  &c->yuv2nv12cX, &c->yuv2packed1,
857  &c->yuv2packed2, &c->yuv2packedX, &c->yuv2anyX);
858 
860 
861 
862  if (c->srcBpc == 8) {
863  if (c->dstBpc <= 14) {
864  c->hyScale = c->hcScale = hScale8To15_c;
865  if (c->flags & SWS_FAST_BILINEAR) {
868  }
869  } else {
870  c->hyScale = c->hcScale = hScale8To19_c;
871  }
872  } else {
873  c->hyScale = c->hcScale = c->dstBpc > 14 ? hScale16To19_c
874  : hScale16To15_c;
875  }
876 
878 
879  if (!(isGray(srcFormat) || isGray(c->dstFormat) ||
880  srcFormat == AV_PIX_FMT_MONOBLACK || srcFormat == AV_PIX_FMT_MONOWHITE))
881  c->needs_hcscale = 1;
882 }
883 
885 {
886  sws_init_swscale(c);
887 
888  if (ARCH_PPC)
890  if (ARCH_X86)
892 
893  return swscale;
894 }
895 
896 static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
897 {
898  if (!isALPHA(format))
899  src[3] = NULL;
900  if (!isPlanar(format)) {
901  src[3] = src[2] = NULL;
902 
903  if (!usePal(format))
904  src[1] = NULL;
905  }
906 }
907 
908 static int check_image_pointers(const uint8_t * const data[4], enum AVPixelFormat pix_fmt,
909  const int linesizes[4])
910 {
911  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
912  int i;
913 
914  av_assert2(desc);
915 
916  for (i = 0; i < 4; i++) {
917  int plane = desc->comp[i].plane;
918  if (!data[plane] || !linesizes[plane])
919  return 0;
920  }
921 
922  return 1;
923 }
924 
925 static void xyz12Torgb48(struct SwsContext *c, uint16_t *dst,
926  const uint16_t *src, int stride, int h)
927 {
928  int xp,yp;
930 
931  for (yp=0; yp<h; yp++) {
932  for (xp=0; xp+2<stride; xp+=3) {
933  int x, y, z, r, g, b;
934 
935  if (desc->flags & AV_PIX_FMT_FLAG_BE) {
936  x = AV_RB16(src + xp + 0);
937  y = AV_RB16(src + xp + 1);
938  z = AV_RB16(src + xp + 2);
939  } else {
940  x = AV_RL16(src + xp + 0);
941  y = AV_RL16(src + xp + 1);
942  z = AV_RL16(src + xp + 2);
943  }
944 
945  x = c->xyzgamma[x>>4];
946  y = c->xyzgamma[y>>4];
947  z = c->xyzgamma[z>>4];
948 
949  // convert from XYZlinear to sRGBlinear
950  r = c->xyz2rgb_matrix[0][0] * x +
951  c->xyz2rgb_matrix[0][1] * y +
952  c->xyz2rgb_matrix[0][2] * z >> 12;
953  g = c->xyz2rgb_matrix[1][0] * x +
954  c->xyz2rgb_matrix[1][1] * y +
955  c->xyz2rgb_matrix[1][2] * z >> 12;
956  b = c->xyz2rgb_matrix[2][0] * x +
957  c->xyz2rgb_matrix[2][1] * y +
958  c->xyz2rgb_matrix[2][2] * z >> 12;
959 
960  // limit values to 12-bit depth
961  r = av_clip_uintp2(r, 12);
962  g = av_clip_uintp2(g, 12);
963  b = av_clip_uintp2(b, 12);
964 
965  // convert from sRGBlinear to RGB and scale from 12bit to 16bit
966  if (desc->flags & AV_PIX_FMT_FLAG_BE) {
967  AV_WB16(dst + xp + 0, c->rgbgamma[r] << 4);
968  AV_WB16(dst + xp + 1, c->rgbgamma[g] << 4);
969  AV_WB16(dst + xp + 2, c->rgbgamma[b] << 4);
970  } else {
971  AV_WL16(dst + xp + 0, c->rgbgamma[r] << 4);
972  AV_WL16(dst + xp + 1, c->rgbgamma[g] << 4);
973  AV_WL16(dst + xp + 2, c->rgbgamma[b] << 4);
974  }
975  }
976  src += stride;
977  dst += stride;
978  }
979 }
980 
981 static void rgb48Toxyz12(struct SwsContext *c, uint16_t *dst,
982  const uint16_t *src, int stride, int h)
983 {
984  int xp,yp;
986 
987  for (yp=0; yp<h; yp++) {
988  for (xp=0; xp+2<stride; xp+=3) {
989  int x, y, z, r, g, b;
990 
991  if (desc->flags & AV_PIX_FMT_FLAG_BE) {
992  r = AV_RB16(src + xp + 0);
993  g = AV_RB16(src + xp + 1);
994  b = AV_RB16(src + xp + 2);
995  } else {
996  r = AV_RL16(src + xp + 0);
997  g = AV_RL16(src + xp + 1);
998  b = AV_RL16(src + xp + 2);
999  }
1000 
1001  r = c->rgbgammainv[r>>4];
1002  g = c->rgbgammainv[g>>4];
1003  b = c->rgbgammainv[b>>4];
1004 
1005  // convert from sRGBlinear to XYZlinear
1006  x = c->rgb2xyz_matrix[0][0] * r +
1007  c->rgb2xyz_matrix[0][1] * g +
1008  c->rgb2xyz_matrix[0][2] * b >> 12;
1009  y = c->rgb2xyz_matrix[1][0] * r +
1010  c->rgb2xyz_matrix[1][1] * g +
1011  c->rgb2xyz_matrix[1][2] * b >> 12;
1012  z = c->rgb2xyz_matrix[2][0] * r +
1013  c->rgb2xyz_matrix[2][1] * g +
1014  c->rgb2xyz_matrix[2][2] * b >> 12;
1015 
1016  // limit values to 12-bit depth
1017  x = av_clip_uintp2(x, 12);
1018  y = av_clip_uintp2(y, 12);
1019  z = av_clip_uintp2(z, 12);
1020 
1021  // convert from XYZlinear to X'Y'Z' and scale from 12bit to 16bit
1022  if (desc->flags & AV_PIX_FMT_FLAG_BE) {
1023  AV_WB16(dst + xp + 0, c->xyzgammainv[x] << 4);
1024  AV_WB16(dst + xp + 1, c->xyzgammainv[y] << 4);
1025  AV_WB16(dst + xp + 2, c->xyzgammainv[z] << 4);
1026  } else {
1027  AV_WL16(dst + xp + 0, c->xyzgammainv[x] << 4);
1028  AV_WL16(dst + xp + 1, c->xyzgammainv[y] << 4);
1029  AV_WL16(dst + xp + 2, c->xyzgammainv[z] << 4);
1030  }
1031  }
1032  src += stride;
1033  dst += stride;
1034  }
1035 }
1036 
1037 /**
1038  * swscale wrapper, so we don't need to export the SwsContext.
1039  * Assumes planar YUV to be in YUV order instead of YVU.
1040  */
1041 int attribute_align_arg sws_scale(struct SwsContext *c,
1042  const uint8_t * const srcSlice[],
1043  const int srcStride[], int srcSliceY,
1044  int srcSliceH, uint8_t *const dst[],
1045  const int dstStride[])
1046 {
1047  int i, ret;
1048  const uint8_t *src2[4];
1049  uint8_t *dst2[4];
1050  uint8_t *rgb0_tmp = NULL;
1051  int macro_height = isBayer(c->srcFormat) ? 2 : (1 << c->chrSrcVSubSample);
1052 
1053  if (!srcStride || !dstStride || !dst || !srcSlice) {
1054  av_log(c, AV_LOG_ERROR, "One of the input parameters to sws_scale() is NULL, please check the calling code\n");
1055  return 0;
1056  }
1057 
1058  if ((srcSliceY & (macro_height-1)) ||
1059  ((srcSliceH& (macro_height-1)) && srcSliceY + srcSliceH != c->srcH) ||
1060  srcSliceY + srcSliceH > c->srcH) {
1061  av_log(c, AV_LOG_ERROR, "Slice parameters %d, %d are invalid\n", srcSliceY, srcSliceH);
1062  return AVERROR(EINVAL);
1063  }
1064 
1065  if (c->gamma_flag && c->cascaded_context[0]) {
1066 
1067 
1068  ret = sws_scale(c->cascaded_context[0],
1069  srcSlice, srcStride, srcSliceY, srcSliceH,
1071 
1072  if (ret < 0)
1073  return ret;
1074 
1075  if (c->cascaded_context[2])
1076  ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, c->cascaded1_tmp, c->cascaded1_tmpStride);
1077  else
1078  ret = sws_scale(c->cascaded_context[1], (const uint8_t * const *)c->cascaded_tmp, c->cascaded_tmpStride, srcSliceY, srcSliceH, dst, dstStride);
1079 
1080  if (ret < 0)
1081  return ret;
1082 
1083  if (c->cascaded_context[2]) {
1084  ret = sws_scale(c->cascaded_context[2],
1085  (const uint8_t * const *)c->cascaded1_tmp, c->cascaded1_tmpStride, c->cascaded_context[1]->dstY - ret, c->cascaded_context[1]->dstY,
1086  dst, dstStride);
1087  }
1088  return ret;
1089  }
1090 
1091  if (c->cascaded_context[0] && srcSliceY == 0 && srcSliceH == c->cascaded_context[0]->srcH) {
1092  ret = sws_scale(c->cascaded_context[0],
1093  srcSlice, srcStride, srcSliceY, srcSliceH,
1095  if (ret < 0)
1096  return ret;
1097  ret = sws_scale(c->cascaded_context[1],
1098  (const uint8_t * const * )c->cascaded_tmp, c->cascaded_tmpStride, 0, c->cascaded_context[0]->dstH,
1099  dst, dstStride);
1100  return ret;
1101  }
1102 
1103  memcpy(src2, srcSlice, sizeof(src2));
1104  memcpy(dst2, dst, sizeof(dst2));
1105 
1106  // do not mess up sliceDir if we have a "trailing" 0-size slice
1107  if (srcSliceH == 0)
1108  return 0;
1109 
1110  if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) {
1111  av_log(c, AV_LOG_ERROR, "bad src image pointers\n");
1112  return 0;
1113  }
1114  if (!check_image_pointers((const uint8_t* const*)dst, c->dstFormat, dstStride)) {
1115  av_log(c, AV_LOG_ERROR, "bad dst image pointers\n");
1116  return 0;
1117  }
1118 
1119  if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) {
1120  av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n");
1121  return 0;
1122  }
1123  if (c->sliceDir == 0) {
1124  if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1;
1125  }
1126 
1127  if (usePal(c->srcFormat)) {
1128  for (i = 0; i < 256; i++) {
1129  int r, g, b, y, u, v, a = 0xff;
1130  if (c->srcFormat == AV_PIX_FMT_PAL8) {
1131  uint32_t p = ((const uint32_t *)(srcSlice[1]))[i];
1132  a = (p >> 24) & 0xFF;
1133  r = (p >> 16) & 0xFF;
1134  g = (p >> 8) & 0xFF;
1135  b = p & 0xFF;
1136  } else if (c->srcFormat == AV_PIX_FMT_RGB8) {
1137  r = ( i >> 5 ) * 36;
1138  g = ((i >> 2) & 7) * 36;
1139  b = ( i & 3) * 85;
1140  } else if (c->srcFormat == AV_PIX_FMT_BGR8) {
1141  b = ( i >> 6 ) * 85;
1142  g = ((i >> 3) & 7) * 36;
1143  r = ( i & 7) * 36;
1144  } else if (c->srcFormat == AV_PIX_FMT_RGB4_BYTE) {
1145  r = ( i >> 3 ) * 255;
1146  g = ((i >> 1) & 3) * 85;
1147  b = ( i & 1) * 255;
1148  } else if (c->srcFormat == AV_PIX_FMT_GRAY8 || c->srcFormat == AV_PIX_FMT_GRAY8A) {
1149  r = g = b = i;
1150  } else {
1152  b = ( i >> 3 ) * 255;
1153  g = ((i >> 1) & 3) * 85;
1154  r = ( i & 1) * 255;
1155  }
1156 #define RGB2YUV_SHIFT 15
1157 #define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1158 #define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1159 #define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1160 #define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1161 #define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1162 #define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1163 #define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1164 #define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1165 #define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5))
1166 
1167  y = av_clip_uint8((RY * r + GY * g + BY * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
1168  u = av_clip_uint8((RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
1169  v = av_clip_uint8((RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT);
1170  c->pal_yuv[i]= y + (u<<8) + (v<<16) + ((unsigned)a<<24);
1171 
1172  switch (c->dstFormat) {
1173  case AV_PIX_FMT_BGR32:
1174 #if !HAVE_BIGENDIAN
1175  case AV_PIX_FMT_RGB24:
1176 #endif
1177  c->pal_rgb[i]= r + (g<<8) + (b<<16) + ((unsigned)a<<24);
1178  break;
1179  case AV_PIX_FMT_BGR32_1:
1180 #if HAVE_BIGENDIAN
1181  case AV_PIX_FMT_BGR24:
1182 #endif
1183  c->pal_rgb[i]= a + (r<<8) + (g<<16) + ((unsigned)b<<24);
1184  break;
1185  case AV_PIX_FMT_RGB32_1:
1186 #if HAVE_BIGENDIAN
1187  case AV_PIX_FMT_RGB24:
1188 #endif
1189  c->pal_rgb[i]= a + (b<<8) + (g<<16) + ((unsigned)r<<24);
1190  break;
1191  case AV_PIX_FMT_RGB32:
1192 #if !HAVE_BIGENDIAN
1193  case AV_PIX_FMT_BGR24:
1194 #endif
1195  default:
1196  c->pal_rgb[i]= b + (g<<8) + (r<<16) + ((unsigned)a<<24);
1197  }
1198  }
1199  }
1200 
1201  if (c->src0Alpha && !c->dst0Alpha && isALPHA(c->dstFormat)) {
1202  uint8_t *base;
1203  int x,y;
1204  rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32);
1205  if (!rgb0_tmp)
1206  return AVERROR(ENOMEM);
1207 
1208  base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
1209  for (y=0; y<srcSliceH; y++){
1210  memcpy(base + srcStride[0]*y, src2[0] + srcStride[0]*y, 4*c->srcW);
1211  for (x=c->src0Alpha-1; x<4*c->srcW; x+=4) {
1212  base[ srcStride[0]*y + x] = 0xFF;
1213  }
1214  }
1215  src2[0] = base;
1216  }
1217 
1218  if (c->srcXYZ && !(c->dstXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) {
1219  uint8_t *base;
1220  rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32);
1221  if (!rgb0_tmp)
1222  return AVERROR(ENOMEM);
1223 
1224  base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp;
1225 
1226  xyz12Torgb48(c, (uint16_t*)base, (const uint16_t*)src2[0], srcStride[0]/2, srcSliceH);
1227  src2[0] = base;
1228  }
1229 
1230  if (!srcSliceY && (c->flags & SWS_BITEXACT) && c->dither == SWS_DITHER_ED && c->dither_error[0])
1231  for (i = 0; i < 4; i++)
1232  memset(c->dither_error[i], 0, sizeof(c->dither_error[0][0]) * (c->dstW+2));
1233 
1234 
1235  // copy strides, so they can safely be modified
1236  if (c->sliceDir == 1) {
1237  // slices go from top to bottom
1238  int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2],
1239  srcStride[3] };
1240  int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2],
1241  dstStride[3] };
1242 
1243  reset_ptr(src2, c->srcFormat);
1244  reset_ptr((void*)dst2, c->dstFormat);
1245 
1246  /* reset slice direction at end of frame */
1247  if (srcSliceY + srcSliceH == c->srcH)
1248  c->sliceDir = 0;
1249 
1250  ret = c->swscale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2,
1251  dstStride2);
1252  } else {
1253  // slices go from bottom to top => we flip the image internally
1254  int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2],
1255  -srcStride[3] };
1256  int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2],
1257  -dstStride[3] };
1258 
1259  src2[0] += (srcSliceH - 1) * srcStride[0];
1260  if (!usePal(c->srcFormat))
1261  src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1];
1262  src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2];
1263  src2[3] += (srcSliceH - 1) * srcStride[3];
1264  dst2[0] += ( c->dstH - 1) * dstStride[0];
1265  dst2[1] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[1];
1266  dst2[2] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[2];
1267  dst2[3] += ( c->dstH - 1) * dstStride[3];
1268 
1269  reset_ptr(src2, c->srcFormat);
1270  reset_ptr((void*)dst2, c->dstFormat);
1271 
1272  /* reset slice direction at end of frame */
1273  if (!srcSliceY)
1274  c->sliceDir = 0;
1275 
1276  ret = c->swscale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH,
1277  srcSliceH, dst2, dstStride2);
1278  }
1279 
1280 
1281  if (c->dstXYZ && !(c->srcXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) {
1282  /* replace on the same data */
1283  rgb48Toxyz12(c, (uint16_t*)dst2[0], (const uint16_t*)dst2[0], dstStride[0]/2, ret);
1284  }
1285 
1286  av_free(rgb0_tmp);
1287  return ret;
1288 }
int plane
Definition: avisynth_c.h:291
#define BU
int plane
Which of the 4 planes contains the component.
Definition: pixdesc.h:35
int16_t ** alpPixBuf
Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler.
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:634
int chrBufIndex
Index in ring buffer of the last scaled horizontal chroma line from source.
static void lumRangeToJpeg_c(int16_t *dst, int width)
Definition: swscale.c:190
void(* hcscale_fast)(struct SwsContext *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc)
av_cold void ff_sws_init_output_funcs(SwsContext *c, yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, yuv2interleavedX_fn *yuv2nv12cX, yuv2packed1_fn *yuv2packed1, yuv2packed2_fn *yuv2packed2, yuv2packedX_fn *yuv2packedX, yuv2anyX_fn *yuv2anyX)
Definition: output.c:2076
static enum AVPixelFormat pix_fmt
static void chrRangeFromJpeg_c(int16_t *dstU, int16_t *dstV, int width)
Definition: swscale.c:181
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2157
int chrSrcH
Height of source chroma planes.
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void reset_ptr(const uint8_t *src[], enum AVPixelFormat format)
Definition: swscale.c:896
uint32_t pal_rgb[256]
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int16_t * rgbgamma
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:65
#define GU
const char * g
Definition: vf_curves.c:108
int ff_init_slice_from_src(SwsSlice *s, uint8_t *src[4], int stride[4], int srcW, int lumY, int lumH, int chrY, int chrH, int relative)
Definition: slice.c:147
int vChrDrop
Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user...
static void lumRangeToJpeg16_c(int16_t *_dst, int width)
Definition: swscale.c:226
Struct which holds all necessary data for processing a slice.
int16_t * rgbgammainv
const char * b
Definition: vf_curves.c:109
#define DECLARE_ALIGNED(n, t, v)
Definition: mem.h:53
#define RU
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
external API header
int16_t * xyzgammainv
int srcRange
0 = MPG YUV range, 1 = JPG YUV range (source image).
const uint8_t * lumDither8
#define BY
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:87
#define SWS_PRINT_INFO
Definition: swscale.h:73
int dstY
Last destination vertical line output from last slice.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:87
void ff_sws_init_input_funcs(SwsContext *c)
int srcH
Height of source luma/alpha planes.
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
Definition: pixfmt.h:87
static void rgb48Toxyz12(struct SwsContext *c, uint16_t *dst, const uint16_t *src, int stride, int h)
Definition: swscale.c:981
static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale.c:84
int ff_rotate_slice(SwsSlice *s, int lum, int chr)
Definition: slice.c:119
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int chrDstVSubSample
Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination i...
void(* yuv2interleavedX_fn)(struct SwsContext *c, const int16_t *chrFilter, int chrFilterSize, const int16_t **chrUSrc, const int16_t **chrVSrc, uint8_t *dest, int dstW)
Write one line of horizontally scaled chroma to interleaved output with multi-point vertical scaling ...
uint8_t bits
Definition: crc.c:295
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
static void lumRangeFromJpeg_c(int16_t *dst, int width)
Definition: swscale.c:197
void(* readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int width, int32_t *rgb2yuv)
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
8 bit with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:74
int vChrFilterSize
Vertical filter size for chroma pixels.
void(* yuv2anyX_fn)(struct SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t **dest, int dstW, int y)
Write one line of horizontally scaled Y/U/V/A to YUV/RGB output by doing multi-point vertical scaling...
int16_t ** lumPixBuf
Ring buffer for scaled horizontal luma plane lines to be fed to the vertical scaler.
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:30
void(* lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3, int width, uint32_t *pal)
Unscaled conversion of luma plane to YV12 for horizontal scaler.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, uint8_t clip)
Definition: cfhd.c:82
int cascaded_tmpStride[4]
av_cold void ff_sws_init_swscale_x86(SwsContext *c)
Definition: swscale.c:407
#define SWS_FAST_BILINEAR
Definition: swscale.h:56
int lastInLumBuf
Last scaled horizontal luma/alpha line from source in the ring buffer.
int16_t rgb2xyz_matrix[3][4]
#define isAnyRGB(x)
external API header
enum AVPixelFormat dstFormat
Destination pixel format.
#define BV
#define isALPHA(x)
Definition: swscale-test.c:49
uint16_t * inv_gamma
#define AV_WB16(p, v)
Definition: intreadwrite.h:405
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
yuv2packedX_fn yuv2packedX
void ff_init_vscale_pfn(SwsContext *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX, yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2, yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx)
setup vertical scaler functions
Definition: vscale.c:250
void(* lumConvertRange)(int16_t *dst, int width)
Color range conversion function for luma plane if needed.
int32_t * vChrFilterPos
Array of vertical filter starting positions for each dst[i] for chroma planes.
#define DEBUG_BUFFERS(...)
Definition: swscale.c:318
int dstH
Height of destination luma/alpha planes.
int * dither_error[4]
void(* yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc, const int16_t *chrUSrc[2], const int16_t *chrVSrc[2], const int16_t *alpSrc, uint8_t *dest, int dstW, int uvalpha, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output without any additional v...
#define U(x)
Definition: vp56_arith.h:37
yuv2anyX_fn yuv2anyX
#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:310
int16_t ** chrVPixBuf
Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
int32_t * hChrFilterPos
Array of horizontal filter starting positions for each dst[i] for chroma planes.
#define AVERROR(e)
Definition: error.h:43
int hLumFilterSize
Horizontal filter size for luma/alpha pixels.
SwsFunc ff_getSwsFunc(SwsContext *c)
Return function pointer to fastest main scaler path function depending on architecture and available ...
Definition: swscale.c:884
#define RV
static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width)
Definition: swscale.c:172
const char * r
Definition: vf_curves.c:107
yuv2packed1_fn yuv2packed1
simple assert() macros that are a bit more flexible than ISO C assert().
static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *_src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale.c:111
GLsizei GLsizei * length
Definition: opengl_enc.c:115
void ff_hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2, int dstWidth, const uint8_t *src1, const uint8_t *src2, int srcW, int xInc)
int vChrBufSize
Number of vertical chroma lines allocated in the ring buffer.
#define FFMAX(a, b)
Definition: common.h:94
static int check_image_pointers(const uint8_t *const data[4], enum AVPixelFormat pix_fmt, const int linesizes[4])
Definition: swscale.c:908
int chrDstW
Width of destination chroma planes.
#define isNBPS(x)
uint8_t * cascaded1_tmp[4]
static av_cold void sws_init_swscale(SwsContext *c)
Definition: swscale.c:851
SwsPlane plane[MAX_SLICE_PLANES]
color planes
int32_t alpMmxFilter[4 *MAX_FILTER_SIZE]
void(* chrConvertRange)(int16_t *dst1, int16_t *dst2, int width)
Color range conversion function for chroma planes if needed.
int32_t * hLumFilterPos
Array of horizontal filter starting positions for each dst[i] for luma/alpha planes.
int hChrFilterSize
Horizontal filter size for chroma pixels.
int sliceH
number of lines
int16_t * xyzgamma
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
static void xyz12Torgb48(struct SwsContext *c, uint16_t *dst, const uint16_t *src, int stride, int h)
Definition: swscale.c:925
av_cold void ff_sws_init_swscale_ppc(SwsContext *c)
int dstRange
0 = MPG YUV range, 1 = JPG YUV range (destination image).
#define RGB2YUV_SHIFT
void(* yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output without any additional vertical scaling (...
ptrdiff_t uv_offx2
offset (in bytes) between u and v planes
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:158
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define FFMIN(a, b)
Definition: common.h:96
#define isBayer(x)
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
Definition: pixfmt.h:90
#define RY
uint8_t * formatConvBuffer
static av_always_inline int is9_OR_10BPS(enum AVPixelFormat pix_fmt)
yuv2planar1_fn yuv2plane1
int vLumBufSize
Number of vertical luma/alpha lines allocated in the ring buffer.
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
int16_t ** chrUPixBuf
Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler.
yuv2interleavedX_fn yuv2nv12cX
int(* process)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int32_t
void(* hcScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
void(* readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv)
Functions to read planar input, such as planar RGB, and convert internally to Y/UV/A.
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:66
av_cold void ff_sws_init_range_convert(SwsContext *c)
Definition: swscale.c:826
struct SwsFilterDescriptor * desc
#define src
Definition: vp9dsp.c:530
int dstW
Width of destination luma/alpha planes.
uint8_t * cascaded_tmp[4]
int sliceDir
Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top).
int cascaded1_tmpStride[4]
int needs_hcscale
Set if there are chroma planes to be converted.
int32_t * vLumFilterPos
Array of vertical filter starting positions for each dst[i] for luma/alpha planes.
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:309
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
int32_t lumMmxFilter[4 *MAX_FILTER_SIZE]
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Definition: pixfmt.h:85
#define src1
Definition: h264pred.c:139
int width
Slice line width.
int16_t xyz2rgb_matrix[3][4]
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
yuv2planarX_fn yuv2planeX
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:307
static const char * format
Definition: movenc-test.c:47
const uint8_t ff_dither_8x8_128[9][8]
Definition: swscale.c:39
Struct which defines a slice of an image to be scaled or a output for a scaled slice.
struct SwsSlice * slice
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't need to export the SwsContext.
Definition: swscale.c:1041
static av_always_inline void fillPlane(uint8_t *plane, int stride, int width, int height, int y, uint8_t val)
Definition: swscale.c:73
static void lumRangeFromJpeg16_c(int16_t *_dst, int width)
Definition: swscale.c:235
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
int(* SwsFunc)(struct SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
void ff_hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc)
int vLumFilterSize
Vertical filter size for luma/alpha pixels.
byte swapping routines
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
int16_t * vChrFilter
Array of vertical filter coefficients for chroma planes.
#define isGray(x)
Definition: swscale-test.c:38
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:76
int16_t * hLumFilter
Array of horizontal filter coefficients for luma/alpha planes.
static void fillPlane16(uint8_t *plane, int stride, int width, int height, int y, int alpha, int bits, const int big_endian)
const uint8_t * chrDither8
static void chrRangeToJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width)
Definition: swscale.c:204
static int flags
Definition: cpu.c:47
#define SWS_BITEXACT
Definition: swscale.h:82
int lumBufIndex
Index in ring buffer of the last scaled horizontal luma/alpha line from source.
static int swscale(SwsContext *c, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
Definition: swscale.c:322
SwsDither dither
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:73
int lastInChrBuf
Last scaled horizontal chroma line from source in the ring buffer.
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
yuv2packed2_fn yuv2packed2
void(* readAlpPlanar)(uint8_t *dst, const uint8_t *src[4], int width, int32_t *rgb2yuv)
Y , 8bpp.
Definition: pixfmt.h:71
#define GY
void(* yuv2planarX_fn)(const int16_t *filter, int filterSize, const int16_t **src, uint8_t *dest, int dstW, const uint8_t *dither, int offset)
Write one line of horizontally scaled data to planar output with multi-point vertical scaling between...
if(ret< 0)
Definition: vf_mcdeint.c:282
void(* yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2], const int16_t *chrUSrc[2], const int16_t *chrVSrc[2], const int16_t *alpSrc[2], uint8_t *dest, int dstW, int yalpha, int uvalpha, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output by doing bilinear scalin...
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:72
static double c[64]
void(* yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, const int16_t *chrFilter, const int16_t **chrUSrc, const int16_t **chrVSrc, int chrFilterSize, const int16_t **alpSrc, uint8_t *dest, int dstW, int y)
Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB output by doing multi-point ver...
#define AV_WL16(p, v)
Definition: intreadwrite.h:412
enum AVPixelFormat srcFormat
Source pixel format.
int32_t chrMmxFilter[4 *MAX_FILTER_SIZE]
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
Definition: pixfmt.h:88
void(* hyscale_fast)(struct SwsContext *c, int16_t *dst, int dstWidth, const uint8_t *src, int srcW, int xInc)
Scale one horizontal line of input data using a bilinear filter to produce one line of output data...
struct SwsContext * cascaded_context[3]
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:128
uint16_t * gamma
SwsFunc swscale
Note that src, dst, srcStride, dstStride will be copied in the sws_scale() wrapper so they can be fre...
#define GV
void(* alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3, int width, uint32_t *pal)
Unscaled conversion of alpha plane to YV12 for horizontal scaler.
#define av_free(p)
void ff_updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex, int lastInLumBuf, int lastInChrBuf)
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:308
#define MAX_LINES_AHEAD
static int gamma_convert(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
Definition: gamma.c:30
void(* chrToYV12)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, int width, uint32_t *pal)
Unscaled conversion of chroma planes to YV12 for horizontal scaler.
static void chrRangeFromJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width)
Definition: swscale.c:215
int32_t input_rgb2yuv_table[16+40 *4]
int16_t * vLumFilter
Array of vertical filter coefficients for luma/alpha planes.
#define AV_CPU_FLAG_SSE2
PIV SSE2 functions.
Definition: cpu.h:34
static const uint8_t sws_pb_64[8]
Definition: swscale.c:51
#define av_always_inline
Definition: attributes.h:39
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
int16_t * hChrFilter
Array of horizontal filter coefficients for chroma planes.
#define stride
static void hScale8To15_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale.c:137
int sliceY
index of first line
int chrSrcW
Width of source chroma planes.
#define isPacked(x)
int depth
Number of bits in the component.
Definition: pixdesc.h:58
int srcW
Width of source luma/alpha planes.
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:61
uint32_t pal_yuv[256]
void(* hyScale)(struct SwsContext *c, int16_t *dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Scale one horizontal line of input data using a filter over the input lines, to produce one (differen...
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
static int width
static void hScale8To19_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *src, const int16_t *filter, const int32_t *filterPos, int filterSize)
Definition: swscale.c:153