swscale_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2001-2003 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef SWSCALE_SWSCALE_INTERNAL_H
22 #define SWSCALE_SWSCALE_INTERNAL_H
23 
24 #include "config.h"
25 
26 #if HAVE_ALTIVEC_H
27 #include <altivec.h>
28 #endif
29 
30 #include "libavutil/avutil.h"
31 #include "libavutil/log.h"
32 #include "libavutil/pixfmt.h"
33 #include "libavutil/pixdesc.h"
34 
35 #define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long
36 
37 #define FAST_BGR2YV12 // use 7-bit instead of 15-bit coefficients
38 
39 #define MAX_FILTER_SIZE 256
40 
41 #if HAVE_BIGENDIAN
42 #define ALT32_CORR (-1)
43 #else
44 #define ALT32_CORR 1
45 #endif
46 
47 #if ARCH_X86_64
48 # define APCK_PTR2 8
49 # define APCK_COEF 16
50 # define APCK_SIZE 24
51 #else
52 # define APCK_PTR2 4
53 # define APCK_COEF 8
54 # define APCK_SIZE 16
55 #endif
56 
57 struct SwsContext;
58 
59 typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[],
60  int srcStride[], int srcSliceY, int srcSliceH,
61  uint8_t *dst[], int dstStride[]);
62 
75 typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW,
76  const uint8_t *dither, int offset);
77 
91 typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize,
92  const int16_t **src, uint8_t *dest, int dstW,
93  const uint8_t *dither, int offset);
94 
110 typedef void (*yuv2interleavedX_fn)(struct SwsContext *c,
111  const int16_t *chrFilter,
112  int chrFilterSize,
113  const int16_t **chrUSrc,
114  const int16_t **chrVSrc,
115  uint8_t *dest, int dstW);
116 
146 typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc,
147  const int16_t *chrUSrc[2],
148  const int16_t *chrVSrc[2],
149  const int16_t *alpSrc, uint8_t *dest,
150  int dstW, int uvalpha, int y);
179 typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2],
180  const int16_t *chrUSrc[2],
181  const int16_t *chrVSrc[2],
182  const int16_t *alpSrc[2],
183  uint8_t *dest,
184  int dstW, int yalpha, int uvalpha, int y);
211 typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter,
212  const int16_t **lumSrc, int lumFilterSize,
213  const int16_t *chrFilter,
214  const int16_t **chrUSrc,
215  const int16_t **chrVSrc, int chrFilterSize,
216  const int16_t **alpSrc, uint8_t *dest,
217  int dstW, int y);
218 
219 /* This struct should be aligned on at least a 32-byte boundary. */
220 typedef struct SwsContext {
225 
231  int srcW;
232  int srcH;
233  int dstH;
234  int chrSrcW;
235  int chrSrcH;
236  int chrDstW;
237  int chrDstH;
249  int vChrDrop;
250  int sliceDir;
251  double param[2];
252 
253  uint32_t pal_yuv[256];
254  uint32_t pal_rgb[256];
255 
266  int16_t **lumPixBuf;
267  int16_t **chrUPixBuf;
268  int16_t **chrVPixBuf;
269  int16_t **alpPixBuf;
276 
277 
279 
294  int16_t *hLumFilter;
295  int16_t *hChrFilter;
296  int16_t *vLumFilter;
297  int16_t *vChrFilter;
298  int32_t *hLumFilterPos;
299  int32_t *hChrFilterPos;
300  int32_t *vLumFilterPos;
301  int32_t *vChrFilterPos;
306 
307 
310  uint8_t *lumMmx2FilterCode;
311  uint8_t *chrMmx2FilterCode;
312 
314 
315  int dstY;
316  int flags;
317  void *yuvTable; // pointer to the yuv->rgb table start so it can be freed()
318  uint8_t *table_rV[256];
319  uint8_t *table_gU[256];
320  int table_gV[256];
321  uint8_t *table_bU[256];
322 
323  //Colorspace stuff
324  int contrast, brightness, saturation; // for sws_getColorspaceDetails
327  int srcRange;
328  int dstRange;
335 
336 #define RED_DITHER "0*8"
337 #define GREEN_DITHER "1*8"
338 #define BLUE_DITHER "2*8"
339 #define Y_COEFF "3*8"
340 #define VR_COEFF "4*8"
341 #define UB_COEFF "5*8"
342 #define VG_COEFF "6*8"
343 #define UG_COEFF "7*8"
344 #define Y_OFFSET "8*8"
345 #define U_OFFSET "9*8"
346 #define V_OFFSET "10*8"
347 #define LUM_MMX_FILTER_OFFSET "11*8"
348 #define CHR_MMX_FILTER_OFFSET "11*8+4*4*256"
349 #define DSTW_OFFSET "11*8+4*4*256*2" //do not change, it is hardcoded in the ASM
350 #define ESP_OFFSET "11*8+4*4*256*2+8"
351 #define VROUNDER_OFFSET "11*8+4*4*256*2+16"
352 #define U_TEMP "11*8+4*4*256*2+24"
353 #define V_TEMP "11*8+4*4*256*2+32"
354 #define Y_TEMP "11*8+4*4*256*2+40"
355 #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48"
356 #define UV_OFF_PX "11*8+4*4*256*3+48"
357 #define UV_OFF_BYTE "11*8+4*4*256*3+56"
358 #define DITHER16 "11*8+4*4*256*3+64"
359 #define DITHER32 "11*8+4*4*256*3+80"
360 
361  DECLARE_ALIGNED(8, uint64_t, redDither);
364 
365  DECLARE_ALIGNED(8, uint64_t, yCoeff);
366  DECLARE_ALIGNED(8, uint64_t, vrCoeff);
367  DECLARE_ALIGNED(8, uint64_t, ubCoeff);
368  DECLARE_ALIGNED(8, uint64_t, vgCoeff);
369  DECLARE_ALIGNED(8, uint64_t, ugCoeff);
370  DECLARE_ALIGNED(8, uint64_t, yOffset);
371  DECLARE_ALIGNED(8, uint64_t, uOffset);
372  DECLARE_ALIGNED(8, uint64_t, vOffset);
375  int dstW;
376  DECLARE_ALIGNED(8, uint64_t, esp);
377  DECLARE_ALIGNED(8, uint64_t, vRounder);
378  DECLARE_ALIGNED(8, uint64_t, u_temp);
379  DECLARE_ALIGNED(8, uint64_t, v_temp);
380  DECLARE_ALIGNED(8, uint64_t, y_temp);
382  // alignment of these values is not necessary, but merely here
383  // to maintain the same offset across x8632 and x86-64. Once we
384  // use proper offset macros in the asm, they can be removed.
385  DECLARE_ALIGNED(8, ptrdiff_t, uv_off_px);
386  DECLARE_ALIGNED(8, ptrdiff_t, uv_off_byte);
387  DECLARE_ALIGNED(8, uint16_t, dither16)[8];
388  DECLARE_ALIGNED(8, uint32_t, dither32)[8];
389 
390  const uint8_t *chrDither8, *lumDither8;
391 
392 #if HAVE_ALTIVEC
393  vector signed short CY;
394  vector signed short CRV;
395  vector signed short CBU;
396  vector signed short CGU;
397  vector signed short CGV;
398  vector signed short OY;
399  vector unsigned short CSHIFT;
400  vector signed short *vYCoeffsBank, *vCCoeffsBank;
401 #endif
402 
403 #if ARCH_BFIN
404  DECLARE_ALIGNED(4, uint32_t, oy);
405  DECLARE_ALIGNED(4, uint32_t, oc);
406  DECLARE_ALIGNED(4, uint32_t, zero);
407  DECLARE_ALIGNED(4, uint32_t, cy);
408  DECLARE_ALIGNED(4, uint32_t, crv);
409  DECLARE_ALIGNED(4, uint32_t, rmask);
410  DECLARE_ALIGNED(4, uint32_t, cbu);
411  DECLARE_ALIGNED(4, uint32_t, bmask);
412  DECLARE_ALIGNED(4, uint32_t, cgu);
413  DECLARE_ALIGNED(4, uint32_t, cgv);
414  DECLARE_ALIGNED(4, uint32_t, gmask);
415 #endif
416 
417 #if HAVE_VIS
418  DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10];
419 #endif
420 
421  /* function pointers for swScale() */
428 
430  void (*lumToYV12)(uint8_t *dst, const uint8_t *src,
431  int width, uint32_t *pal);
433  void (*alpToYV12)(uint8_t *dst, const uint8_t *src,
434  int width, uint32_t *pal);
436  void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV,
437  const uint8_t *src1, const uint8_t *src2,
438  int width, uint32_t *pal);
439 
445  void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width);
446  void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4],
447  int width);
470  int16_t *dst, int dstWidth,
471  const uint8_t *src, int srcW, int xInc);
473  int16_t *dst1, int16_t *dst2, int dstWidth,
474  const uint8_t *src1, const uint8_t *src2,
475  int srcW, int xInc);
509  void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW,
510  const uint8_t *src, const int16_t *filter,
511  const int32_t *filterPos, int filterSize);
512  void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW,
513  const uint8_t *src, const int16_t *filter,
514  const int32_t *filterPos, int filterSize);
517 
518  void (*lumConvertRange)(int16_t *dst, int width);
520  void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width);
521 
523 } SwsContext;
524 //FIXME check init (where 0)
525 
527 int ff_yuv2rgb_c_init_tables(SwsContext *c, const int inv_table[4],
528  int fullRange, int brightness,
529  int contrast, int saturation);
530 
531 void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4],
532  int brightness, int contrast, int saturation);
534  int lastInLumBuf, int lastInChrBuf);
535 
542 
543 const char *sws_format_name(enum PixelFormat format);
544 
545 #define is16BPS(x) \
546  (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 15)
547 
548 #define is9_OR_10BPS(x) \
549  (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 8 || \
550  av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 9)
551 
552 #define isBE(x) \
553  (av_pix_fmt_descriptors[x].flags & PIX_FMT_BE)
554 
555 #define isYUV(x) \
556  (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB) && \
557  av_pix_fmt_descriptors[x].nb_components >= 2)
558 
559 #define isPlanarYUV(x) \
560  ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR) && \
561  isYUV(x))
562 
563 #define isRGB(x) \
564  (av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB)
565 
566 #if 0 // FIXME
567 #define isGray(x) \
568  (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) && \
569  av_pix_fmt_descriptors[x].nb_components <= 2)
570 #else
571 #define isGray(x) \
572  ((x) == PIX_FMT_GRAY8 || \
573  (x) == PIX_FMT_Y400A || \
574  (x) == PIX_FMT_GRAY16BE || \
575  (x) == PIX_FMT_GRAY16LE)
576 #endif
577 
578 #define isRGBinInt(x) \
579  ((x) == PIX_FMT_RGB48BE || \
580  (x) == PIX_FMT_RGB48LE || \
581  (x) == PIX_FMT_RGB32 || \
582  (x) == PIX_FMT_RGB32_1 || \
583  (x) == PIX_FMT_RGB24 || \
584  (x) == PIX_FMT_RGB565BE || \
585  (x) == PIX_FMT_RGB565LE || \
586  (x) == PIX_FMT_RGB555BE || \
587  (x) == PIX_FMT_RGB555LE || \
588  (x) == PIX_FMT_RGB444BE || \
589  (x) == PIX_FMT_RGB444LE || \
590  (x) == PIX_FMT_RGB8 || \
591  (x) == PIX_FMT_RGB4 || \
592  (x) == PIX_FMT_RGB4_BYTE || \
593  (x) == PIX_FMT_MONOBLACK || \
594  (x) == PIX_FMT_MONOWHITE)
595 
596 #define isBGRinInt(x) \
597  ((x) == PIX_FMT_BGR48BE || \
598  (x) == PIX_FMT_BGR48LE || \
599  (x) == PIX_FMT_BGR32 || \
600  (x) == PIX_FMT_BGR32_1 || \
601  (x) == PIX_FMT_BGR24 || \
602  (x) == PIX_FMT_BGR565BE || \
603  (x) == PIX_FMT_BGR565LE || \
604  (x) == PIX_FMT_BGR555BE || \
605  (x) == PIX_FMT_BGR555LE || \
606  (x) == PIX_FMT_BGR444BE || \
607  (x) == PIX_FMT_BGR444LE || \
608  (x) == PIX_FMT_BGR8 || \
609  (x) == PIX_FMT_BGR4 || \
610  (x) == PIX_FMT_BGR4_BYTE || \
611  (x) == PIX_FMT_MONOBLACK || \
612  (x) == PIX_FMT_MONOWHITE)
613 
614 #define isAnyRGB(x) \
615  (isRGBinInt(x) || \
616  isBGRinInt(x))
617 
618 #define isALPHA(x) \
619  (av_pix_fmt_descriptors[x].nb_components == 2 || \
620  av_pix_fmt_descriptors[x].nb_components == 4)
621 
622 #define isPacked(x) \
623  ((av_pix_fmt_descriptors[x].nb_components >= 2 && \
624  !(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) || \
625  (x) == PIX_FMT_PAL8)
626 
627 #define isPlanar(x) \
628  (av_pix_fmt_descriptors[x].nb_components >= 2 && \
629  (av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR))
630 
631 #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_Y400A)
632 
633 extern const uint64_t ff_dither4[2];
634 extern const uint64_t ff_dither8[2];
635 
636 extern const AVClass sws_context_class;
637 
643 
645 
651 
654 
655 #endif /* SWSCALE_SWSCALE_INTERNAL_H */