Libav
yuv2rgb.c
Go to the documentation of this file.
1 /*
2  * software YUV to RGB converter
3  *
4  * Copyright (C) 2009 Konstantin Shishkov
5  *
6  * MMX/MMXEXT template stuff (needed for fast movntq support),
7  * 1,4,8bpp support and context / deglobalize stuff
8  * by Michael Niedermayer (michaelni@gmx.at)
9  *
10  * This file is part of Libav.
11  *
12  * Libav is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  *
17  * Libav is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public
23  * License along with Libav; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25  */
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <inttypes.h>
30 #include <assert.h>
31 
32 #include "config.h"
33 #include "libswscale/rgb2rgb.h"
34 #include "libswscale/swscale.h"
36 #include "libavutil/attributes.h"
37 #include "libavutil/x86/asm.h"
38 #include "libavutil/x86/cpu.h"
39 #include "libavutil/cpu.h"
40 
41 #if HAVE_INLINE_ASM
42 
43 #define DITHER1XBPP // only for MMX
44 
45 /* hope these constant values are cache line aligned */
46 DECLARE_ASM_CONST(8, uint64_t, mmx_00ffw) = 0x00ff00ff00ff00ffULL;
47 DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
48 DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
49 DECLARE_ASM_CONST(8, uint64_t, pb_e0) = 0xe0e0e0e0e0e0e0e0ULL;
50 DECLARE_ASM_CONST(8, uint64_t, pb_03) = 0x0303030303030303ULL;
51 DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL;
52 
53 //MMX versions
54 #if HAVE_MMX_INLINE
55 #undef RENAME
56 #undef COMPILE_TEMPLATE_MMXEXT
57 #define COMPILE_TEMPLATE_MMXEXT 0
58 #define RENAME(a) a ## _mmx
59 #include "yuv2rgb_template.c"
60 #endif /* HAVE_MMX_INLINE */
61 
62 // MMXEXT versions
63 #if HAVE_MMXEXT_INLINE
64 #undef RENAME
65 #undef COMPILE_TEMPLATE_MMXEXT
66 #define COMPILE_TEMPLATE_MMXEXT 1
67 #define RENAME(a) a ## _mmxext
68 #include "yuv2rgb_template.c"
69 #endif /* HAVE_MMXEXT_INLINE */
70 
71 #endif /* HAVE_INLINE_ASM */
72 
74 {
75 #if HAVE_MMX_INLINE
76  int cpu_flags = av_get_cpu_flags();
77 
78  if (c->srcFormat != AV_PIX_FMT_YUV420P &&
80  return NULL;
81 
82 #if HAVE_MMXEXT_INLINE
83  if (INLINE_MMXEXT(cpu_flags)) {
84  switch (c->dstFormat) {
85  case AV_PIX_FMT_RGB24:
86  return yuv420_rgb24_mmxext;
87  case AV_PIX_FMT_BGR24:
88  return yuv420_bgr24_mmxext;
89  }
90  }
91 #endif
92 
93  if (INLINE_MMX(cpu_flags)) {
94  switch (c->dstFormat) {
95  case AV_PIX_FMT_RGB32:
96  if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
97 #if HAVE_7REGS && CONFIG_SWSCALE_ALPHA
98  return yuva420_rgb32_mmx;
99 #endif
100  break;
101  } else
102  return yuv420_rgb32_mmx;
103  case AV_PIX_FMT_BGR32:
104  if (c->srcFormat == AV_PIX_FMT_YUVA420P) {
105 #if HAVE_7REGS && CONFIG_SWSCALE_ALPHA
106  return yuva420_bgr32_mmx;
107 #endif
108  break;
109  } else
110  return yuv420_bgr32_mmx;
111  case AV_PIX_FMT_RGB24:
112  return yuv420_rgb24_mmx;
113  case AV_PIX_FMT_BGR24:
114  return yuv420_bgr24_mmx;
115  case AV_PIX_FMT_RGB565:
116  return yuv420_rgb16_mmx;
117  case AV_PIX_FMT_RGB555:
118  return yuv420_rgb15_mmx;
119  }
120  }
121 #endif /* HAVE_MMX_INLINE */
122 
123  return NULL;
124 }
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
av_cold SwsFunc ff_yuv2rgb_init_x86(SwsContext *c)
Definition: yuv2rgb.c:73
Macro definitions for various function/variable attributes.
#define DECLARE_ASM_CONST(n, t, v)
Definition: mem.h:59
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:104
#define av_cold
Definition: attributes.h:66
external api for the swscale stuff
enum AVPixelFormat dstFormat
Destination pixel format.
#define INLINE_MMX(flags)
Definition: cpu.h:63
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:224
NULL
Definition: eval.c:55
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:222
int(* SwsFunc)(struct SwsContext *context, const uint8_t *src[], int srcStride[], int srcSliceY, int srcSliceH, uint8_t *dst[], int dstStride[])
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:47
#define INLINE_MMXEXT(flags)
Definition: cpu.h:64
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
enum AVPixelFormat srcFormat
Source pixel format.
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:231
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:230