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