annotate imgconvert.c @ 1203:80c73b9b0ba2 libavcodec

accurate YUV to RGB and RGB to YUV conversions - added comments
author bellard
date Mon, 21 Apr 2003 12:12:58 +0000
parents 8b49a7ee4e4e
children e55580ae9969
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * Misc image convertion routines
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
3 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
5 * This library is free software; you can redistribute it and/or
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
7 * License as published by the Free Software Foundation; either
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
8 * version 2 of the License, or (at your option) any later version.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 *
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
10 * This library is distributed in the hope that it will be useful,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
13 * Lesser General Public License for more details.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 *
429
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
16 * License along with this library; if not, write to the Free Software
718a22dc121f license/copyright change
glantau
parents: 396
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
18 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
19
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
20 /**
1108
bfc18110d4b6 typos & cosmetics
michaelni
parents: 1106
diff changeset
21 * @file imgconvert.c
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
22 * Misc image convertion routines.
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
23 */
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
24
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
25 /* TODO:
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
26 * - write 'ffimg' program to test all the image related stuff
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
27 * - move all api to slice based system
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
28 * - integrate deinterlacing, postprocessing and scaling in the conversion process
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
29 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1073
diff changeset
30
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 #include "avcodec.h"
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
32 #include "dsputil.h"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
33
17
b69fe46fd708 Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents: 0
diff changeset
34 #ifdef USE_FASTMEMCPY
b69fe46fd708 Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents: 0
diff changeset
35 #include "fastmemcpy.h"
b69fe46fd708 Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents: 0
diff changeset
36 #endif
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
37
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
38 #ifdef HAVE_MMX
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
39 #include "i386/mmx.h"
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
40 #endif
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
41
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
42 #define FF_COLOR_RGB 0 /* RGB color space */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
43 #define FF_COLOR_GRAY 1 /* gray color space */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
44 #define FF_COLOR_YUV 2 /* YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
45 #define FF_COLOR_YUV_JPEG 3 /* YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
46
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
47 typedef struct PixFmtInfo {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
48 const char *name;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
49 uint8_t nb_components; /* number of components in AVPicture array */
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
50 uint8_t color_type; /* color type (see FF_COLOR_xxx constants) */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
51 uint8_t is_packed : 1; /* true if multiple components in same word */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
52 uint8_t is_paletted : 1; /* true if paletted */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
53 uint8_t is_alpha : 1; /* true if alpha can be specified */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
54 uint8_t x_chroma_shift; /* X chroma subsampling factor is 2 ^ shift */
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
55 uint8_t y_chroma_shift; /* Y chroma subsampling factor is 2 ^ shift */
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
56 uint8_t depth; /* bit depth of the color components */
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
57 } PixFmtInfo;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
58
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
59 /* this table gives more information about formats */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
60 static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
61 /* YUV formats */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
62 [PIX_FMT_YUV420P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
63 .name = "yuv420p",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
64 .nb_components = 3,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
65 .color_type = FF_COLOR_YUV,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
66 .depth = 8,
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
67 .x_chroma_shift = 1, .y_chroma_shift = 1,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
68 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
69 [PIX_FMT_YUV422P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
70 .name = "yuv422p",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
71 .nb_components = 3,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
72 .color_type = FF_COLOR_YUV,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
73 .depth = 8,
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
74 .x_chroma_shift = 1, .y_chroma_shift = 0,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
75 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
76 [PIX_FMT_YUV444P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
77 .name = "yuv444p",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
78 .nb_components = 3,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
79 .color_type = FF_COLOR_YUV,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
80 .depth = 8,
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
81 .x_chroma_shift = 0, .y_chroma_shift = 0,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
82 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
83 [PIX_FMT_YUV422] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
84 .name = "yuv422",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
85 .nb_components = 1, .is_packed = 1,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
86 .color_type = FF_COLOR_YUV,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
87 .depth = 8,
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
88 .x_chroma_shift = 1, .y_chroma_shift = 0,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
89 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
90 [PIX_FMT_YUV410P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
91 .name = "yuv410p",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
92 .nb_components = 3,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
93 .color_type = FF_COLOR_YUV,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
94 .depth = 8,
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
95 .x_chroma_shift = 2, .y_chroma_shift = 2,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
96 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
97 [PIX_FMT_YUV411P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
98 .name = "yuv411p",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
99 .nb_components = 3,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
100 .color_type = FF_COLOR_YUV,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
101 .depth = 8,
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
102 .x_chroma_shift = 2, .y_chroma_shift = 0,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
103 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
104
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
105 /* JPEG YUV */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
106 [PIX_FMT_YUVJ420P] = {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
107 .name = "yuvj420p",
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
108 .nb_components = 3,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
109 .color_type = FF_COLOR_YUV_JPEG,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
110 .depth = 8,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
111 .x_chroma_shift = 1, .y_chroma_shift = 1,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
112 },
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
113 [PIX_FMT_YUVJ422P] = {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
114 .name = "yuvj422p",
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
115 .nb_components = 3,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
116 .color_type = FF_COLOR_YUV_JPEG,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
117 .depth = 8,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
118 .x_chroma_shift = 1, .y_chroma_shift = 0,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
119 },
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
120 [PIX_FMT_YUVJ444P] = {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
121 .name = "yuvj444p",
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
122 .nb_components = 3,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
123 .color_type = FF_COLOR_YUV_JPEG,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
124 .depth = 8,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
125 .x_chroma_shift = 0, .y_chroma_shift = 0,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
126 },
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
127
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
128 /* RGB formats */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
129 [PIX_FMT_RGB24] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
130 .name = "rgb24",
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
131 .nb_components = 1, .is_packed = 1,
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
132 .color_type = FF_COLOR_RGB,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
133 .depth = 8,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
134 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
135 [PIX_FMT_BGR24] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
136 .name = "bgr24",
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
137 .nb_components = 1, .is_packed = 1,
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
138 .color_type = FF_COLOR_RGB,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
139 .depth = 8,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
140 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
141 [PIX_FMT_RGBA32] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
142 .name = "rgba32",
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
143 .nb_components = 1, .is_packed = 1, .is_alpha = 1,
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
144 .color_type = FF_COLOR_RGB,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
145 .depth = 8,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
146 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
147 [PIX_FMT_RGB565] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
148 .name = "rgb565",
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
149 .nb_components = 1, .is_packed = 1,
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
150 .color_type = FF_COLOR_RGB,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
151 .depth = 5,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
152 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
153 [PIX_FMT_RGB555] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
154 .name = "rgb555",
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
155 .nb_components = 1, .is_packed = 1, .is_alpha = 1,
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
156 .color_type = FF_COLOR_RGB,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
157 .depth = 5,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
158 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
159
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
160 /* gray / mono formats */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
161 [PIX_FMT_GRAY8] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
162 .name = "gray",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
163 .nb_components = 1,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
164 .color_type = FF_COLOR_GRAY,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
165 .depth = 8,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
166 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
167 [PIX_FMT_MONOWHITE] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
168 .name = "monow",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
169 .nb_components = 1,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
170 .color_type = FF_COLOR_GRAY,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
171 .depth = 1,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
172 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
173 [PIX_FMT_MONOBLACK] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
174 .name = "monob",
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
175 .nb_components = 1,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
176 .color_type = FF_COLOR_GRAY,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
177 .depth = 1,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
178 },
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
179
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
180 /* paletted formats */
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
181 [PIX_FMT_PAL8] = {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
182 .name = "pal8",
1199
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
183 .nb_components = 1, .is_packed = 1, .is_alpha = 1, .is_paletted = 1,
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
184 .color_type = FF_COLOR_RGB,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
185 .depth = 8,
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
186 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
187 };
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
188
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
189 void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
190 {
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
191 *h_shift = pix_fmt_info[pix_fmt].x_chroma_shift;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
192 *v_shift = pix_fmt_info[pix_fmt].y_chroma_shift;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
193 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
194
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
195 const char *avcodec_get_pix_fmt_name(int pix_fmt)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
196 {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
197 if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
198 return "???";
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
199 else
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
200 return pix_fmt_info[pix_fmt].name;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
201 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
202
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
203 /* Picture field are filled with 'ptr' addresses. Also return size */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
204 int avpicture_fill(AVPicture *picture, uint8_t *ptr,
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
205 int pix_fmt, int width, int height)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
206 {
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
207 int size, w2, h2, size2;
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
208 PixFmtInfo *pinfo;
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
209
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
210 pinfo = &pix_fmt_info[pix_fmt];
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
211 size = width * height;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
212 switch(pix_fmt) {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
213 case PIX_FMT_YUV420P:
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
214 case PIX_FMT_YUV422P:
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
215 case PIX_FMT_YUV444P:
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
216 case PIX_FMT_YUV410P:
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
217 case PIX_FMT_YUV411P:
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
218 case PIX_FMT_YUVJ420P:
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
219 case PIX_FMT_YUVJ422P:
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
220 case PIX_FMT_YUVJ444P:
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
221 w2 = (width + (1 << pinfo->x_chroma_shift) - 1) >> pinfo->x_chroma_shift;
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
222 h2 = (height + (1 << pinfo->y_chroma_shift) - 1) >> pinfo->y_chroma_shift;
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
223 size2 = w2 * h2;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
224 picture->data[0] = ptr;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
225 picture->data[1] = picture->data[0] + size;
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
226 picture->data[2] = picture->data[1] + size2;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
227 picture->linesize[0] = width;
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
228 picture->linesize[1] = w2;
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
229 picture->linesize[2] = w2;
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
230 return size + 2 * size2;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
231 case PIX_FMT_RGB24:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
232 case PIX_FMT_BGR24:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
233 picture->data[0] = ptr;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
234 picture->data[1] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
235 picture->data[2] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
236 picture->linesize[0] = width * 3;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
237 return size * 3;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
238 case PIX_FMT_RGBA32:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
239 picture->data[0] = ptr;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
240 picture->data[1] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
241 picture->data[2] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
242 picture->linesize[0] = width * 4;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
243 return size * 4;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
244 case PIX_FMT_RGB555:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
245 case PIX_FMT_RGB565:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
246 case PIX_FMT_YUV422:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
247 picture->data[0] = ptr;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
248 picture->data[1] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
249 picture->data[2] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
250 picture->linesize[0] = width * 2;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
251 return size * 2;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
252 case PIX_FMT_GRAY8:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
253 picture->data[0] = ptr;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
254 picture->data[1] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
255 picture->data[2] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
256 picture->linesize[0] = width;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
257 return size;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
258 case PIX_FMT_MONOWHITE:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
259 case PIX_FMT_MONOBLACK:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
260 picture->data[0] = ptr;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
261 picture->data[1] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
262 picture->data[2] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
263 picture->linesize[0] = (width + 7) >> 3;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
264 return picture->linesize[0] * height;
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
265 case PIX_FMT_PAL8:
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
266 size2 = (size + 3) & ~3;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
267 picture->data[0] = ptr;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
268 picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
269 picture->data[2] = NULL;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
270 picture->linesize[0] = width;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
271 picture->linesize[1] = 4;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
272 return size2 + 256 * 4;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
273 default:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
274 picture->data[0] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
275 picture->data[1] = NULL;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
276 picture->data[2] = NULL;
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
277 picture->data[3] = NULL;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
278 return -1;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
279 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
280 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
281
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
282 int avpicture_get_size(int pix_fmt, int width, int height)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
283 {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
284 AVPicture dummy_pict;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
285 return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
286 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
287
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
288 /**
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
289 * compute the loss when converting from a pixel format to another
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
290 */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
291 int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
292 int has_alpha)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
293 {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
294 const PixFmtInfo *pf, *ps;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
295 int loss;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
296
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
297 ps = &pix_fmt_info[src_pix_fmt];
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
298 pf = &pix_fmt_info[dst_pix_fmt];
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
299
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
300 /* compute loss */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
301 loss = 0;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
302 pf = &pix_fmt_info[dst_pix_fmt];
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
303 if (pf->depth < ps->depth)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
304 loss |= FF_LOSS_DEPTH;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
305 if (pf->x_chroma_shift >= ps->x_chroma_shift ||
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
306 pf->y_chroma_shift >= ps->y_chroma_shift)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
307 loss |= FF_LOSS_RESOLUTION;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
308 switch(pf->color_type) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
309 case FF_COLOR_RGB:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
310 if (ps->color_type != FF_COLOR_RGB &&
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
311 ps->color_type != FF_COLOR_GRAY)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
312 loss |= FF_LOSS_COLORSPACE;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
313 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
314 case FF_COLOR_GRAY:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
315 if (ps->color_type != FF_COLOR_GRAY)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
316 loss |= FF_LOSS_COLORSPACE;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
317 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
318 case FF_COLOR_YUV:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
319 if (ps->color_type != FF_COLOR_YUV)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
320 loss |= FF_LOSS_COLORSPACE;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
321 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
322 case FF_COLOR_YUV_JPEG:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
323 if (ps->color_type != FF_COLOR_YUV_JPEG &&
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
324 ps->color_type != FF_COLOR_YUV)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
325 loss |= FF_LOSS_COLORSPACE;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
326 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
327 default:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
328 /* fail safe test */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
329 if (ps->color_type != pf->color_type)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
330 loss |= FF_LOSS_COLORSPACE;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
331 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
332 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
333 if (pf->color_type == FF_COLOR_GRAY &&
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
334 ps->color_type != FF_COLOR_GRAY)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
335 loss |= FF_LOSS_CHROMA;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
336 if (!pf->is_alpha && (ps->is_alpha && has_alpha))
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
337 loss |= FF_LOSS_ALPHA;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
338 if (pf->is_paletted && (!ps->is_paletted && ps->color_type != FF_COLOR_GRAY))
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
339 loss |= FF_LOSS_COLORQUANT;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
340 return loss;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
341 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
342
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
343 static int avg_bits_per_pixel(int pix_fmt)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
344 {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
345 int bits;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
346 const PixFmtInfo *pf;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
347
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
348 pf = &pix_fmt_info[pix_fmt];
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
349 if (pf->is_packed) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
350 switch(pix_fmt) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
351 case PIX_FMT_RGB24:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
352 case PIX_FMT_BGR24:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
353 bits = 24;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
354 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
355 case PIX_FMT_RGBA32:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
356 bits = 32;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
357 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
358 case PIX_FMT_RGB565:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
359 case PIX_FMT_RGB555:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
360 bits = 16;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
361 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
362 case PIX_FMT_PAL8:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
363 bits = 8;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
364 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
365 default:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
366 bits = 32;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
367 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
368 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
369 } else {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
370 bits = pf->depth;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
371 bits += (2 * pf->depth >>
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
372 (pf->x_chroma_shift + pf->x_chroma_shift));
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
373 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
374 return bits;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
375 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
376
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
377 static int avcodec_find_best_pix_fmt1(int pix_fmt_mask,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
378 int src_pix_fmt,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
379 int has_alpha,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
380 int loss_mask)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
381 {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
382 int dist, i, loss, min_dist, dst_pix_fmt;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
383
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
384 /* find exact color match with smallest size */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
385 dst_pix_fmt = -1;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
386 min_dist = 0x7fffffff;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
387 for(i = 0;i < PIX_FMT_NB; i++) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
388 if (pix_fmt_mask & (1 << i)) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
389 loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
390 if (loss == 0) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
391 dist = avg_bits_per_pixel(i);
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
392 if (dist < min_dist) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
393 min_dist = dist;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
394 dst_pix_fmt = i;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
395 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
396 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
397 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
398 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
399 return dst_pix_fmt;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
400 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
401
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
402 /**
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
403 * find best pixel format to convert to. Return -1 if none found
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
404 */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
405 int avcodec_find_best_pix_fmt(int pix_fmt_mask, int src_pix_fmt,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
406 int has_alpha, int *loss_ptr)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
407 {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
408 int dst_pix_fmt, loss_mask, i;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
409 static const int loss_mask_order[] = {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
410 ~0, /* no loss first */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
411 ~FF_LOSS_ALPHA,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
412 ~FF_LOSS_RESOLUTION,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
413 ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION),
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
414 ~FF_LOSS_COLORQUANT,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
415 ~FF_LOSS_DEPTH,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
416 0,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
417 };
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
418
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
419 /* try with successive loss */
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
420 i = 0;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
421 for(;;) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
422 loss_mask = loss_mask_order[i++];
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
423 dst_pix_fmt = avcodec_find_best_pix_fmt1(pix_fmt_mask, src_pix_fmt,
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
424 has_alpha, loss_mask);
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
425 if (dst_pix_fmt >= 0)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
426 goto found;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
427 if (loss_mask == 0)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
428 break;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
429 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
430 return -1;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
431 found:
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
432 if (loss_ptr)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
433 *loss_ptr = avcodec_get_pix_fmt_loss(dst_pix_fmt, src_pix_fmt, has_alpha);
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
434 return dst_pix_fmt;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
435 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
436
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
437
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
438 /* XXX: totally non optimized */
986e461dc072 Initial revision
glantau
parents:
diff changeset
439
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
440 static void yuv422_to_yuv420p(AVPicture *dst, AVPicture *src,
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
441 int width, int height)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
442 {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
443 const uint8_t *p, *p1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
444 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
445 int x;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
446
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
447 p1 = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
448 lum1 = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
449 cb1 = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
450 cr1 = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
451
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
452 for(;height >= 2; height -= 2) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
453 p = p1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
454 lum = lum1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
455 cb = cb1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
456 cr = cr1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
457 for(x=0;x<width;x+=2) {
1028
e76fb91de4cc reversing my own stupidity ... (raw packed yuv422 files dont use YUY2 but UYVY)
michaelni
parents: 1023
diff changeset
458 lum[0] = p[0];
e76fb91de4cc reversing my own stupidity ... (raw packed yuv422 files dont use YUY2 but UYVY)
michaelni
parents: 1023
diff changeset
459 cb[0] = p[1];
e76fb91de4cc reversing my own stupidity ... (raw packed yuv422 files dont use YUY2 but UYVY)
michaelni
parents: 1023
diff changeset
460 lum[1] = p[2];
e76fb91de4cc reversing my own stupidity ... (raw packed yuv422 files dont use YUY2 but UYVY)
michaelni
parents: 1023
diff changeset
461 cr[0] = p[3];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
462 p += 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
463 lum += 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
464 cb++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
465 cr++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
466 }
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
467 p1 += src->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
468 lum1 += dst->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
469 p = p1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
470 lum = lum1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
471 for(x=0;x<width;x+=2) {
1028
e76fb91de4cc reversing my own stupidity ... (raw packed yuv422 files dont use YUY2 but UYVY)
michaelni
parents: 1023
diff changeset
472 lum[0] = p[0];
e76fb91de4cc reversing my own stupidity ... (raw packed yuv422 files dont use YUY2 but UYVY)
michaelni
parents: 1023
diff changeset
473 lum[1] = p[2];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
474 p += 4;
986e461dc072 Initial revision
glantau
parents:
diff changeset
475 lum += 2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
476 }
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
477 p1 += src->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
478 lum1 += dst->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
479 cb1 += dst->linesize[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
480 cr1 += dst->linesize[2];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
481 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
482 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
483
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
484 static void yuv422_to_yuv422p(AVPicture *dst, AVPicture *src,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
485 int width, int height)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
486 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
487 const uint8_t *p, *p1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
488 uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
489 int w;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
490
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
491 p1 = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
492 lum1 = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
493 cb1 = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
494 cr1 = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
495 for(;height >= 2; height -= 2) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
496 p = p1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
497 lum = lum1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
498 cb = cb1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
499 cr = cr1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
500 for(w = width; w >= 2; w -= 2) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
501 lum[0] = p[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
502 cb[0] = p[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
503 lum[1] = p[2];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
504 cr[0] = p[3];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
505 p += 4;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
506 lum += 2;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
507 cb++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
508 cr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
509 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
510 p1 += src->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
511 lum1 += dst->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
512 cb1 += dst->linesize[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
513 cr1 += dst->linesize[2];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
514 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
515 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
516
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
517 static void yuv422p_to_yuv422(AVPicture *dst, AVPicture *src,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
518 int width, int height)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
519 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
520 uint8_t *p, *p1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
521 const uint8_t *lum, *cr, *cb, *lum1, *cr1, *cb1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
522 int w;
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
523
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
524 p1 = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
525 lum1 = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
526 cb1 = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
527 cr1 = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
528 for(;height >= 2; height -= 2) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
529 p = p1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
530 lum = lum1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
531 cb = cb1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
532 cr = cr1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
533 for(w = width; w >= 2; w -= 2) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
534 p[0] = lum[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
535 p[1] = cb[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
536 p[2] = lum[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
537 p[3] = cr[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
538 p += 4;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
539 lum += 2;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
540 cb++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
541 cr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
542 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
543 p1 += src->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
544 lum1 += dst->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
545 cb1 += dst->linesize[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
546 cr1 += dst->linesize[2];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
547 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
548 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
549
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
550 #define SCALEBITS 10
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
551 #define ONE_HALF (1 << (SCALEBITS - 1))
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
552 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
553
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
554 #define YUV_TO_RGB1_CCIR(cb1, cr1)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
555 {\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
556 cb = (cb1) - 128;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
557 cr = (cr1) - 128;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
558 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
559 g_add = - FIX(0.34414*255.0/224.0) * cb - FIX(0.71414*255.0/224.0) * cr + \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
560 ONE_HALF;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
561 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
562 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
563
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
564 #define YUV_TO_RGB2_CCIR(r, g, b, y1)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
565 {\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
566 y = ((y1) - 16) * FIX(255.0/219.0);\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
567 r = cm[(y + r_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
568 g = cm[(y + g_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
569 b = cm[(y + b_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
570 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
571
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
572 #define YUV_TO_RGB1(cb1, cr1)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
573 {\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
574 cb = (cb1) - 128;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
575 cr = (cr1) - 128;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
576 r_add = FIX(1.40200) * cr + ONE_HALF;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
577 g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
578 b_add = FIX(1.77200) * cb + ONE_HALF;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
579 }
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
580
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
581 #define YUV_TO_RGB2(r, g, b, y1)\
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
582 {\
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
583 y = (y1) << SCALEBITS;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
584 r = cm[(y + r_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
585 g = cm[(y + g_add) >> SCALEBITS];\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
586 b = cm[(y + b_add) >> SCALEBITS];\
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
587 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
588
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
589 #define Y_CCIR_TO_JPEG(y)\
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
590 cm[((y) * FIX(255.0/219.0) + (ONE_HALF - 16 * FIX(255.0/219.0))) >> SCALEBITS]
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
591
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
592 #define Y_JPEG_TO_CCIR(y)\
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
593 (((y) * FIX(219.0/255.0) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
594
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
595 #define C_CCIR_TO_JPEG(y)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
596 cm[(((y) - 128) * FIX(127.0/112.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS]
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
597
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
598 /* NOTE: the clamp is really necessary! */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
599 #define C_JPEG_TO_CCIR(y)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
600 ({\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
601 int __y;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
602 __y = ((((y) - 128) * FIX(112.0/127.0) + (ONE_HALF + (128 << SCALEBITS))) >> SCALEBITS);\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
603 if (__y < 16)\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
604 __y = 16;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
605 __y;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
606 })
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
607
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
608 #define RGB_TO_Y(r, g, b) \
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
609 ((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
610 FIX(0.11400) * (b) + ONE_HALF) >> SCALEBITS)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
611
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
612 #define RGB_TO_U(r1, g1, b1, shift)\
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
613 (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
614 FIX(0.50000) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
615
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
616 #define RGB_TO_V(r1, g1, b1, shift)\
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
617 (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
618 FIX(0.08131) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
619
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
620 #define RGB_TO_Y_CCIR(r, g, b) \
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
621 ((FIX(0.29900*219.0/255.0) * (r) + FIX(0.58700*219.0/255.0) * (g) + \
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
622 FIX(0.11400*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS)
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
623
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
624 #define RGB_TO_U_CCIR(r1, g1, b1, shift)\
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
625 (((- FIX(0.16874*224.0/255.0) * r1 - FIX(0.33126*224.0/255.0) * g1 + \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
626 FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
627
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
628 #define RGB_TO_V_CCIR(r1, g1, b1, shift)\
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
629 (((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
630 FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
631
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
632 static uint8_t y_ccir_to_jpeg[256];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
633 static uint8_t y_jpeg_to_ccir[256];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
634 static uint8_t c_ccir_to_jpeg[256];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
635 static uint8_t c_jpeg_to_ccir[256];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
636
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
637 /* init various conversion tables */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
638 static void img_convert_init(void)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
639 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
640 int i;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
641 uint8_t *cm = cropTbl + MAX_NEG_CROP;
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
642
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
643 for(i = 0;i < 256; i++) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
644 y_ccir_to_jpeg[i] = Y_CCIR_TO_JPEG(i);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
645 y_jpeg_to_ccir[i] = Y_JPEG_TO_CCIR(i);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
646 c_ccir_to_jpeg[i] = C_CCIR_TO_JPEG(i);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
647 c_jpeg_to_ccir[i] = C_JPEG_TO_CCIR(i);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
648 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
649 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
650
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
651 /* apply to each pixel the given table */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
652 static void img_apply_table(uint8_t *dst, int dst_wrap,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
653 const uint8_t *src, int src_wrap,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
654 int width, int height, const uint8_t *table1)
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
655 {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
656 int n;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
657 const uint8_t *s;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
658 uint8_t *d;
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
659 const uint8_t *table;
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
660
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
661 table = table1;
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
662 for(;height > 0; height--) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
663 s = src;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
664 d = dst;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
665 n = width;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
666 while (n >= 4) {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
667 d[0] = table[s[0]];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
668 d[1] = table[s[1]];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
669 d[2] = table[s[2]];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
670 d[3] = table[s[3]];
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
671 d += 4;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
672 s += 4;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
673 n -= 4;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
674 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
675 while (n > 0) {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
676 d[0] = table[s[0]];
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
677 d++;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
678 s++;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
679 n--;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
680 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
681 dst += dst_wrap;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
682 src += src_wrap;
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
683 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
684 }
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
685
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
686 /* XXX: use generic filter ? */
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
687 /* 1x2 -> 1x1 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
688 static void shrink2(uint8_t *dst, int dst_wrap,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
689 uint8_t *src, int src_wrap,
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
690 int width, int height)
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
691 {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
692 int w;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
693 uint8_t *s1, *s2, *d;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
694
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
695 for(;height > 0; height--) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
696 s1 = src;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
697 s2 = s1 + src_wrap;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
698 d = dst;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
699 for(w = width;w >= 4; w-=4) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
700 d[0] = (s1[0] + s2[0]) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
701 d[1] = (s1[1] + s2[1]) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
702 d[2] = (s1[2] + s2[2]) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
703 d[3] = (s1[3] + s2[3]) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
704 s1 += 4;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
705 s2 += 4;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
706 d += 4;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
707 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
708 for(;w > 0; w--) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
709 d[0] = (s1[0] + s2[0]) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
710 s1++;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
711 s2++;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
712 d++;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
713 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
714 src += 2 * src_wrap;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
715 dst += dst_wrap;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
716 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
717 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
718
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
719 /* 2x2 -> 1x1 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
720 static void shrink22(uint8_t *dst, int dst_wrap,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
721 uint8_t *src, int src_wrap,
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
722 int width, int height)
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
723 {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
724 int w;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
725 uint8_t *s1, *s2, *d;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
726
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
727 for(;height > 0; height--) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
728 s1 = src;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
729 s2 = s1 + src_wrap;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
730 d = dst;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
731 for(w = width;w >= 4; w-=4) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
732 d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
733 d[1] = (s1[2] + s1[3] + s2[2] + s2[3] + 2) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
734 d[2] = (s1[4] + s1[5] + s2[4] + s2[5] + 2) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
735 d[3] = (s1[6] + s1[7] + s2[6] + s2[7] + 2) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
736 s1 += 8;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
737 s2 += 8;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
738 d += 4;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
739 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
740 for(;w > 0; w--) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
741 d[0] = (s1[0] + s1[1] + s2[0] + s2[1] + 2) >> 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
742 s1 += 2;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
743 s2 += 2;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
744 d++;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
745 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
746 src += 2 * src_wrap;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
747 dst += dst_wrap;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
748 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
749 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
750
576
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
751 /* 1x1 -> 2x2 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
752 static void grow22(uint8_t *dst, int dst_wrap,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
753 uint8_t *src, int src_wrap,
576
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
754 int width, int height)
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
755 {
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
756 int w;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
757 uint8_t *s1, *d;
576
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
758
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
759 for(;height > 0; height--) {
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
760 s1 = src;
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
761 d = dst;
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
762 for(w = width;w >= 4; w-=4) {
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
763 d[1] = d[0] = s1[0];
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
764 d[3] = d[2] = s1[1];
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
765 s1 += 2;
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
766 d += 4;
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
767 }
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
768 for(;w > 0; w--) {
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
769 d[0] = s1[0];
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
770 s1 ++;
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
771 d++;
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
772 }
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
773 if (height%2)
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
774 src += src_wrap;
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
775 dst += dst_wrap;
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
776 }
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
777 }
9aa5f0d0124e YUV410P to YUV420P patch by Franois Revol <revol at free dot fr>
michaelni
parents: 440
diff changeset
778
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
779 /* 1x2 -> 2x1 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
780 static void conv411(uint8_t *dst, int dst_wrap,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
781 uint8_t *src, int src_wrap,
736
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
782 int width, int height)
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
783 {
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
784 int w, c;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
785 uint8_t *s1, *s2, *d;
736
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
786
1166
54384dc71fe7 fixing mem corruption
michaelni
parents: 1108
diff changeset
787 width>>=1;
54384dc71fe7 fixing mem corruption
michaelni
parents: 1108
diff changeset
788
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
789 for(;height > 0; height--) {
736
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
790 s1 = src;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
791 s2 = src + src_wrap;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
792 d = dst;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
793 for(w = width;w > 0; w--) {
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
794 c = (s1[0] + s2[0]) >> 1;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
795 d[0] = c;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
796 d[1] = c;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
797 s1++;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
798 s2++;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
799 d += 2;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
800 }
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
801 src += src_wrap * 2;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
802 dst += dst_wrap;
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
803 }
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
804 }
918756bffda2 minimum support for YUV411P (new combined scaler/converter will handle that better...)
bellard
parents: 583
diff changeset
805
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
806 static void img_copy(uint8_t *dst, int dst_wrap,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
807 uint8_t *src, int src_wrap,
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
808 int width, int height)
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
809 {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
810 for(;height > 0; height--) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
811 memcpy(dst, src, width);
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
812 dst += dst_wrap;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
813 src += src_wrap;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
814 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
815 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
816
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
817 /* XXX: no chroma interpolating is done */
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
818 #define RGB_FUNCTIONS(rgb_name) \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
819 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
820 static void yuv420p_to_ ## rgb_name (AVPicture *dst, AVPicture *src, \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
821 int width, int height) \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
822 { \
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
823 uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2; \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
824 int w, y, cb, cr, r_add, g_add, b_add, width2; \
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
825 uint8_t *cm = cropTbl + MAX_NEG_CROP; \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
826 unsigned int r, g, b; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
827 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
828 d = dst->data[0]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
829 y1_ptr = src->data[0]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
830 cb_ptr = src->data[1]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
831 cr_ptr = src->data[2]; \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
832 width2 = (width + 1) >> 1; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
833 for(;height >= 2; height -= 2) { \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
834 d1 = d; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
835 d2 = d + dst->linesize[0]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
836 y2_ptr = y1_ptr + src->linesize[0]; \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
837 for(w = width; w >= 2; w -= 2) { \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
838 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
839 /* output 4 pixels */ \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
840 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
841 RGB_OUT(d1, r, g, b); \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
842 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
843 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
844 RGB_OUT(d1 + BPP, r, g, b); \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
845 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
846 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
847 RGB_OUT(d2, r, g, b); \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
848 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
849 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[1]); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
850 RGB_OUT(d2 + BPP, r, g, b); \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
851 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
852 d1 += 2 * BPP; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
853 d2 += 2 * BPP; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
854 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
855 y1_ptr += 2; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
856 y2_ptr += 2; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
857 cb_ptr++; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
858 cr_ptr++; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
859 } \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
860 /* handle odd width */ \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
861 if (w) { \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
862 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
863 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
864 RGB_OUT(d1, r, g, b); \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
865 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
866 YUV_TO_RGB2_CCIR(r, g, b, y2_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
867 RGB_OUT(d2, r, g, b); \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
868 d1 += BPP; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
869 d2 += BPP; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
870 y1_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
871 y2_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
872 cb_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
873 cr_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
874 } \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
875 d += 2 * dst->linesize[0]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
876 y1_ptr += 2 * src->linesize[0] - width; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
877 cb_ptr += src->linesize[1] - width2; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
878 cr_ptr += src->linesize[2] - width2; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
879 } \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
880 /* handle odd height */ \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
881 if (height) { \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
882 d1 = d; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
883 for(w = width; w >= 2; w -= 2) { \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
884 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
885 /* output 2 pixels */ \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
886 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
887 RGB_OUT(d1, r, g, b); \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
888 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
889 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[1]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
890 RGB_OUT(d1 + BPP, r, g, b); \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
891 \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
892 d1 += 2 * BPP; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
893 \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
894 y1_ptr += 2; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
895 cb_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
896 cr_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
897 } \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
898 /* handle width */ \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
899 if (w) { \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
900 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
901 /* output 2 pixels */ \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
902 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
903 RGB_OUT(d1, r, g, b); \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
904 d1 += BPP; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
905 \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
906 y1_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
907 cb_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
908 cr_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
909 } \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
910 } \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
911 } \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
912 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
913 static void yuvj420p_to_ ## rgb_name (AVPicture *dst, AVPicture *src, \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
914 int width, int height) \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
915 { \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
916 uint8_t *y1_ptr, *y2_ptr, *cb_ptr, *cr_ptr, *d, *d1, *d2; \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
917 int w, y, cb, cr, r_add, g_add, b_add, width2; \
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
918 uint8_t *cm = cropTbl + MAX_NEG_CROP; \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
919 unsigned int r, g, b; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
920 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
921 d = dst->data[0]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
922 y1_ptr = src->data[0]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
923 cb_ptr = src->data[1]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
924 cr_ptr = src->data[2]; \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
925 width2 = (width + 1) >> 1; \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
926 for(;height >= 2; height -= 2) { \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
927 d1 = d; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
928 d2 = d + dst->linesize[0]; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
929 y2_ptr = y1_ptr + src->linesize[0]; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
930 for(w = width; w >= 2; w -= 2) { \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
931 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
932 /* output 4 pixels */ \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
933 YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
934 RGB_OUT(d1, r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
935 \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
936 YUV_TO_RGB2(r, g, b, y1_ptr[1]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
937 RGB_OUT(d1 + BPP, r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
938 \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
939 YUV_TO_RGB2(r, g, b, y2_ptr[0]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
940 RGB_OUT(d2, r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
941 \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
942 YUV_TO_RGB2(r, g, b, y2_ptr[1]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
943 RGB_OUT(d2 + BPP, r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
944 \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
945 d1 += 2 * BPP; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
946 d2 += 2 * BPP; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
947 \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
948 y1_ptr += 2; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
949 y2_ptr += 2; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
950 cb_ptr++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
951 cr_ptr++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
952 } \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
953 /* handle odd width */ \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
954 if (w) { \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
955 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
956 YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
957 RGB_OUT(d1, r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
958 \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
959 YUV_TO_RGB2(r, g, b, y2_ptr[0]); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
960 RGB_OUT(d2, r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
961 d1 += BPP; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
962 d2 += BPP; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
963 y1_ptr++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
964 y2_ptr++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
965 cb_ptr++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
966 cr_ptr++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
967 } \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
968 d += 2 * dst->linesize[0]; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
969 y1_ptr += 2 * src->linesize[0] - width; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
970 cb_ptr += src->linesize[1] - width2; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
971 cr_ptr += src->linesize[2] - width2; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
972 } \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
973 /* handle odd height */ \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
974 if (height) { \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
975 d1 = d; \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
976 for(w = width; w >= 2; w -= 2) { \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
977 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
978 /* output 2 pixels */ \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
979 YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
980 RGB_OUT(d1, r, g, b); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
981 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
982 YUV_TO_RGB2(r, g, b, y1_ptr[1]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
983 RGB_OUT(d1 + BPP, r, g, b); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
984 \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
985 d1 += 2 * BPP; \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
986 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
987 y1_ptr += 2; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
988 cb_ptr++; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
989 cr_ptr++; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
990 } \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
991 /* handle width */ \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
992 if (w) { \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
993 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
994 /* output 2 pixels */ \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
995 YUV_TO_RGB2(r, g, b, y1_ptr[0]); \
1047
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
996 RGB_OUT(d1, r, g, b); \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
997 d1 += BPP; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
998 \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
999 y1_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
1000 cb_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
1001 cr_ptr++; \
3f316a471019 handle odd image sizes when using subsampled chroma (useful for JPEG images)
bellard
parents: 1044
diff changeset
1002 } \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1003 } \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1004 } \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1005 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1006 static void rgb_name ## _to_yuv420p(AVPicture *dst, AVPicture *src, \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1007 int width, int height) \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1008 { \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1009 int wrap, wrap3, width2; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1010 int r, g, b, r1, g1, b1, w; \
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1011 uint8_t *lum, *cb, *cr; \
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1012 const uint8_t *p; \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1013 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1014 lum = dst->data[0]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1015 cb = dst->data[1]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1016 cr = dst->data[2]; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1017 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1018 width2 = (width + 1) >> 1; \
1052
f529b09e64b7 Fix a bug in the conversion of rgba32->yuv420p. This resulted in garbage images
philipjsg
parents: 1047
diff changeset
1019 wrap = dst->linesize[0]; \
f529b09e64b7 Fix a bug in the conversion of rgba32->yuv420p. This resulted in garbage images
philipjsg
parents: 1047
diff changeset
1020 wrap3 = src->linesize[0]; \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1021 p = src->data[0]; \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1022 for(;height>=2;height -= 2) { \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1023 for(w = width; w >= 2; w -= 2) { \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1024 RGB_IN(r, g, b, p); \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1025 r1 = r; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1026 g1 = g; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1027 b1 = b; \
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
1028 lum[0] = RGB_TO_Y_CCIR(r, g, b); \
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
1029 \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1030 RGB_IN(r, g, b, p + BPP); \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1031 r1 += r; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1032 g1 += g; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1033 b1 += b; \
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
1034 lum[1] = RGB_TO_Y_CCIR(r, g, b); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1035 p += wrap3; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1036 lum += wrap; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1037 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1038 RGB_IN(r, g, b, p); \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1039 r1 += r; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1040 g1 += g; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1041 b1 += b; \
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
1042 lum[0] = RGB_TO_Y_CCIR(r, g, b); \
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
1043 \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1044 RGB_IN(r, g, b, p + BPP); \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1045 r1 += r; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1046 g1 += g; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1047 b1 += b; \
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
1048 lum[1] = RGB_TO_Y_CCIR(r, g, b); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1049 \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1050 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 2); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1051 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 2); \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1052 \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1053 cb++; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1054 cr++; \
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1055 p += -wrap3 + 2 * BPP; \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1056 lum += -wrap + 2; \
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1057 } \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1058 if (w) { \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1059 RGB_IN(r, g, b, p); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1060 r1 = r; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1061 g1 = g; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1062 b1 = b; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1063 lum[0] = RGB_TO_Y_CCIR(r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1064 p += wrap3; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1065 lum += wrap; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1066 RGB_IN(r, g, b, p); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1067 r1 += r; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1068 g1 += g; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1069 b1 += b; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1070 lum[0] = RGB_TO_Y_CCIR(r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1071 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1072 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1073 cb++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1074 cr++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1075 p += -wrap3 + BPP; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1076 lum += -wrap + 1; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1077 } \
1052
f529b09e64b7 Fix a bug in the conversion of rgba32->yuv420p. This resulted in garbage images
philipjsg
parents: 1047
diff changeset
1078 p += wrap3 + (wrap3 - width * BPP); \
f529b09e64b7 Fix a bug in the conversion of rgba32->yuv420p. This resulted in garbage images
philipjsg
parents: 1047
diff changeset
1079 lum += wrap + (wrap - width); \
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1080 cb += dst->linesize[1] - width2; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1081 cr += dst->linesize[2] - width2; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1082 } \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1083 /* handle odd height */ \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1084 if (height) { \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1085 for(w = width; w >= 2; w -= 2) { \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1086 RGB_IN(r, g, b, p); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1087 r1 = r; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1088 g1 = g; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1089 b1 = b; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1090 lum[0] = RGB_TO_Y_CCIR(r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1091 \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1092 RGB_IN(r, g, b, p + BPP); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1093 r1 += r; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1094 g1 += g; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1095 b1 += b; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1096 lum[1] = RGB_TO_Y_CCIR(r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1097 cb[0] = RGB_TO_U_CCIR(r1, g1, b1, 1); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1098 cr[0] = RGB_TO_V_CCIR(r1, g1, b1, 1); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1099 cb++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1100 cr++; \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1101 p += 2 * BPP;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1102 lum += 2;\
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1103 } \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1104 if (w) { \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1105 RGB_IN(r, g, b, p); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1106 lum[0] = RGB_TO_Y_CCIR(r, g, b); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1107 cb[0] = RGB_TO_U_CCIR(r, g, b, 0); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1108 cr[0] = RGB_TO_V_CCIR(r, g, b, 0); \
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1109 } \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1110 } \
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1111 } \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1112 \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1113 static void rgb_name ## _to_gray(AVPicture *dst, AVPicture *src, \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1114 int width, int height) \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1115 { \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1116 const unsigned char *p; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1117 unsigned char *q; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1118 int r, g, b, dst_wrap, src_wrap; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1119 int x, y; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1120 \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1121 p = src->data[0]; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1122 src_wrap = src->linesize[0] - BPP * width; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1123 \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1124 q = dst->data[0]; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1125 dst_wrap = dst->linesize[0] - width; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1126 \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1127 for(y=0;y<height;y++) { \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1128 for(x=0;x<width;x++) { \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1129 RGB_IN(r, g, b, p); \
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
1130 q[0] = RGB_TO_Y(r, g, b); \
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1131 q++; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1132 p += BPP; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1133 } \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1134 p += src_wrap; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1135 q += dst_wrap; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1136 } \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1137 } \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1138 \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1139 static void gray_to_ ## rgb_name(AVPicture *dst, AVPicture *src, \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1140 int width, int height) \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1141 { \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1142 const unsigned char *p; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1143 unsigned char *q; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1144 int r, dst_wrap, src_wrap; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1145 int x, y; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1146 \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1147 p = src->data[0]; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1148 src_wrap = src->linesize[0] - width; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1149 \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1150 q = dst->data[0]; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1151 dst_wrap = dst->linesize[0] - BPP * width; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1152 \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1153 for(y=0;y<height;y++) { \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1154 for(x=0;x<width;x++) { \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1155 r = p[0]; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1156 RGB_OUT(q, r, r, r); \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1157 q += BPP; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1158 p ++; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1159 } \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1160 p += src_wrap; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1161 q += dst_wrap; \
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1162 } \
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1163 } \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1164 \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1165 static void pal8_to_ ## rgb_name(AVPicture *dst, AVPicture *src, \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1166 int width, int height) \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1167 { \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1168 const unsigned char *p; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1169 unsigned char *q; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1170 int r, g, b, dst_wrap, src_wrap; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1171 int x, y; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1172 uint32_t v;\
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1173 const uint32_t *palette;\
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1174 \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1175 p = src->data[0]; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1176 src_wrap = src->linesize[0] - width; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1177 palette = (uint32_t *)src->data[1];\
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1178 \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1179 q = dst->data[0]; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1180 dst_wrap = dst->linesize[0] - BPP * width; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1181 \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1182 for(y=0;y<height;y++) { \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1183 for(x=0;x<width;x++) { \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1184 v = palette[p[0]];\
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1185 r = (v >> 16) & 0xff;\
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1186 g = (v >> 8) & 0xff;\
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1187 b = (v) & 0xff;\
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1188 RGB_OUT(q, r, g, b); \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1189 q += BPP; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1190 p ++; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1191 } \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1192 p += src_wrap; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1193 q += dst_wrap; \
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1194 } \
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1195 }
583
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1196
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1197 /* copy bit n to bits 0 ... n - 1 */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1198 static inline unsigned int bitcopy_n(unsigned int a, int n)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1199 {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1200 int mask;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1201 mask = (1 << n) - 1;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1202 return (a & (0xff & ~mask)) | ((-((a >> n) & 1)) & mask);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1203 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1204
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1205 /* rgb555 handling */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1206
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1207 #define RGB_IN(r, g, b, s)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1208 {\
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1209 unsigned int v = ((const uint16_t *)(s))[0];\
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1210 r = bitcopy_n(v >> (10 - 3), 3);\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1211 g = bitcopy_n(v >> (5 - 3), 3);\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1212 b = bitcopy_n(v << 3, 3);\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1213 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1214
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1215 #define RGB_OUT(d, r, g, b)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1216 {\
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1217 ((uint16_t *)(d))[0] = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) | 0x8000;\
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1218 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1219
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1220 #define BPP 2
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1221
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1222 RGB_FUNCTIONS(rgb555)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1223
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1224 #undef RGB_IN
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1225 #undef RGB_OUT
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1226 #undef BPP
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1227
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1228 /* rgb565 handling */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1229
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1230 #define RGB_IN(r, g, b, s)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1231 {\
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1232 unsigned int v = ((const uint16_t *)(s))[0];\
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1233 r = bitcopy_n(v >> (11 - 3), 3);\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1234 g = bitcopy_n(v >> (5 - 2), 2);\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1235 b = bitcopy_n(v << 3, 3);\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1236 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1237
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1238 #define RGB_OUT(d, r, g, b)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1239 {\
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1240 ((uint16_t *)(d))[0] = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);\
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1241 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1242
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1243 #define BPP 2
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1244
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1245 RGB_FUNCTIONS(rgb565)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1246
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1247 #undef RGB_IN
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1248 #undef RGB_OUT
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1249 #undef BPP
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1250
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1251 /* bgr24 handling */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1252
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1253 #define RGB_IN(r, g, b, s)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1254 {\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1255 b = (s)[0];\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1256 g = (s)[1];\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1257 r = (s)[2];\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1258 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1259
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1260 #define RGB_OUT(d, r, g, b)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1261 {\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1262 (d)[0] = b;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1263 (d)[1] = g;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1264 (d)[2] = r;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1265 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1266
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1267 #define BPP 3
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1268
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1269 RGB_FUNCTIONS(bgr24)
583
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1270
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1271 #undef RGB_IN
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1272 #undef RGB_OUT
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1273 #undef BPP
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1274
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1275 /* rgb24 handling */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1276
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1277 #define RGB_IN(r, g, b, s)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1278 {\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1279 r = (s)[0];\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1280 g = (s)[1];\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1281 b = (s)[2];\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1282 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1283
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1284 #define RGB_OUT(d, r, g, b)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1285 {\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1286 (d)[0] = r;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1287 (d)[1] = g;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1288 (d)[2] = b;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1289 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1290
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1291 #define BPP 3
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1292
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1293 RGB_FUNCTIONS(rgb24)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1294
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1295 static void yuv444p_to_rgb24(AVPicture *dst, AVPicture *src,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1296 int width, int height)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1297 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1298 uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1299 int w, y, cb, cr, r_add, g_add, b_add;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1300 uint8_t *cm = cropTbl + MAX_NEG_CROP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1301 unsigned int r, g, b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1302
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1303 d = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1304 y1_ptr = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1305 cb_ptr = src->data[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1306 cr_ptr = src->data[2];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1307 for(;height > 0; height --) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1308 d1 = d;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1309 for(w = width; w > 0; w--) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1310 YUV_TO_RGB1_CCIR(cb_ptr[0], cr_ptr[0]);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1311
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1312 YUV_TO_RGB2_CCIR(r, g, b, y1_ptr[0]);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1313 RGB_OUT(d1, r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1314 d1 += BPP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1315
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1316 y1_ptr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1317 cb_ptr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1318 cr_ptr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1319 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1320 d += dst->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1321 y1_ptr += src->linesize[0] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1322 cb_ptr += src->linesize[1] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1323 cr_ptr += src->linesize[2] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1324 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1325 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1326
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1327 static void yuvj444p_to_rgb24(AVPicture *dst, AVPicture *src,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1328 int width, int height)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1329 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1330 uint8_t *y1_ptr, *cb_ptr, *cr_ptr, *d, *d1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1331 int w, y, cb, cr, r_add, g_add, b_add;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1332 uint8_t *cm = cropTbl + MAX_NEG_CROP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1333 unsigned int r, g, b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1334
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1335 d = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1336 y1_ptr = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1337 cb_ptr = src->data[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1338 cr_ptr = src->data[2];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1339 for(;height > 0; height --) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1340 d1 = d;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1341 for(w = width; w > 0; w--) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1342 YUV_TO_RGB1(cb_ptr[0], cr_ptr[0]);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1343
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1344 YUV_TO_RGB2(r, g, b, y1_ptr[0]);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1345 RGB_OUT(d1, r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1346 d1 += BPP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1347
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1348 y1_ptr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1349 cb_ptr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1350 cr_ptr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1351 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1352 d += dst->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1353 y1_ptr += src->linesize[0] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1354 cb_ptr += src->linesize[1] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1355 cr_ptr += src->linesize[2] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1356 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1357 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1358
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1359 static void rgb24_to_yuv444p(AVPicture *dst, AVPicture *src,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1360 int width, int height)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1361 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1362 int src_wrap, x, y;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1363 int r, g, b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1364 uint8_t *lum, *cb, *cr;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1365 const uint8_t *p;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1366
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1367 lum = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1368 cb = dst->data[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1369 cr = dst->data[2];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1370
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1371 src_wrap = src->linesize[0] - width * BPP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1372 p = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1373 for(y=0;y<height;y++) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1374 for(x=0;x<width;x++) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1375 RGB_IN(r, g, b, p);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1376 lum[0] = RGB_TO_Y_CCIR(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1377 cb[0] = RGB_TO_U_CCIR(r, g, b, 0);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1378 cr[0] = RGB_TO_V_CCIR(r, g, b, 0);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1379 cb++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1380 cr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1381 lum++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1382 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1383 p += src_wrap;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1384 lum += dst->linesize[0] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1385 cb += dst->linesize[1] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1386 cr += dst->linesize[2] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1387 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1388 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1389
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1390 static void rgb24_to_yuvj420p(AVPicture *dst, AVPicture *src,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1391 int width, int height)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1392 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1393 int wrap, wrap3, width2;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1394 int r, g, b, r1, g1, b1, w;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1395 uint8_t *lum, *cb, *cr;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1396 const uint8_t *p;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1397
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1398 lum = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1399 cb = dst->data[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1400 cr = dst->data[2];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1401
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1402 width2 = (width + 1) >> 1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1403 wrap = dst->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1404 wrap3 = src->linesize[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1405 p = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1406 for(;height>=2;height -= 2) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1407 for(w = width; w >= 2; w -= 2) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1408 RGB_IN(r, g, b, p);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1409 r1 = r;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1410 g1 = g;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1411 b1 = b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1412 lum[0] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1413
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1414 RGB_IN(r, g, b, p + BPP);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1415 r1 += r;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1416 g1 += g;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1417 b1 += b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1418 lum[1] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1419 p += wrap3;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1420 lum += wrap;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1421
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1422 RGB_IN(r, g, b, p);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1423 r1 += r;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1424 g1 += g;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1425 b1 += b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1426 lum[0] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1427
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1428 RGB_IN(r, g, b, p + BPP);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1429 r1 += r;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1430 g1 += g;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1431 b1 += b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1432 lum[1] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1433
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1434 cb[0] = RGB_TO_U(r1, g1, b1, 2);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1435 cr[0] = RGB_TO_V(r1, g1, b1, 2);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1436
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1437 cb++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1438 cr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1439 p += -wrap3 + 2 * BPP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1440 lum += -wrap + 2;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1441 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1442 if (w) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1443 RGB_IN(r, g, b, p);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1444 r1 = r;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1445 g1 = g;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1446 b1 = b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1447 lum[0] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1448 p += wrap3;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1449 lum += wrap;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1450 RGB_IN(r, g, b, p);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1451 r1 += r;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1452 g1 += g;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1453 b1 += b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1454 lum[0] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1455 cb[0] = RGB_TO_U(r1, g1, b1, 1);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1456 cr[0] = RGB_TO_V(r1, g1, b1, 1);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1457 cb++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1458 cr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1459 p += -wrap3 + BPP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1460 lum += -wrap + 1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1461 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1462 p += wrap3 + (wrap3 - width * BPP);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1463 lum += wrap + (wrap - width);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1464 cb += dst->linesize[1] - width2;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1465 cr += dst->linesize[2] - width2;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1466 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1467 /* handle odd height */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1468 if (height) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1469 for(w = width; w >= 2; w -= 2) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1470 RGB_IN(r, g, b, p);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1471 r1 = r;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1472 g1 = g;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1473 b1 = b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1474 lum[0] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1475
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1476 RGB_IN(r, g, b, p + BPP);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1477 r1 += r;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1478 g1 += g;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1479 b1 += b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1480 lum[1] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1481 cb[0] = RGB_TO_U(r1, g1, b1, 1);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1482 cr[0] = RGB_TO_V(r1, g1, b1, 1);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1483 cb++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1484 cr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1485 p += 2 * BPP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1486 lum += 2;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1487 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1488 if (w) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1489 RGB_IN(r, g, b, p);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1490 lum[0] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1491 cb[0] = RGB_TO_U(r, g, b, 0);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1492 cr[0] = RGB_TO_V(r, g, b, 0);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1493 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1494 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1495 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1496
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1497 static void rgb24_to_yuvj444p(AVPicture *dst, AVPicture *src,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1498 int width, int height)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1499 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1500 int src_wrap, x, y;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1501 int r, g, b;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1502 uint8_t *lum, *cb, *cr;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1503 const uint8_t *p;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1504
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1505 lum = dst->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1506 cb = dst->data[1];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1507 cr = dst->data[2];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1508
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1509 src_wrap = src->linesize[0] - width * BPP;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1510 p = src->data[0];
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1511 for(y=0;y<height;y++) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1512 for(x=0;x<width;x++) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1513 RGB_IN(r, g, b, p);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1514 lum[0] = RGB_TO_Y(r, g, b);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1515 cb[0] = RGB_TO_U(r, g, b, 0);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1516 cr[0] = RGB_TO_V(r, g, b, 0);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1517 cb++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1518 cr++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1519 lum++;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1520 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1521 p += src_wrap;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1522 lum += dst->linesize[0] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1523 cb += dst->linesize[1] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1524 cr += dst->linesize[2] - width;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1525 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1526 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1527
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1528 #undef RGB_IN
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1529 #undef RGB_OUT
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1530 #undef BPP
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1531
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1532 /* rgba32 handling */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1533
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1534 #define RGB_IN(r, g, b, s)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1535 {\
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1536 unsigned int v = ((const uint32_t *)(s))[0];\
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1537 r = (v >> 16) & 0xff;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1538 g = (v >> 8) & 0xff;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1539 b = v & 0xff;\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1540 }
583
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1541
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1542 #define RGB_OUT(d, r, g, b)\
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1543 {\
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1544 ((uint32_t *)(d))[0] = (0xff << 24) | (r << 16) | (g << 8) | b;\
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1545 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1546
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1547 #define BPP 4
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1548
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1549 RGB_FUNCTIONS(rgba32)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1550
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1551 #undef RGB_IN
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1552 #undef RGB_OUT
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1553 #undef BPP
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1554
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1555
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1556 static void rgb24_to_rgb565(AVPicture *dst, AVPicture *src,
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1557 int width, int height)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1558 {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1559 const unsigned char *p;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1560 unsigned char *q;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1561 int r, g, b, dst_wrap, src_wrap;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1562 int x, y;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1563
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1564 p = src->data[0];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1565 src_wrap = src->linesize[0] - 3 * width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1566
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1567 q = dst->data[0];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1568 dst_wrap = dst->linesize[0] - 2 * width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1569
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1570 for(y=0;y<height;y++) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1571 for(x=0;x<width;x++) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1572 r = p[0];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1573 g = p[1];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1574 b = p[2];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1575
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1576 ((unsigned short *)q)[0] =
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1577 ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1578 q += 2;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1579 p += 3;
583
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1580 }
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1581 p += src_wrap;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1582 q += dst_wrap;
583
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1583 }
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1584 }
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1585
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1586 /* NOTE: we also add a dummy alpha bit */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1587 static void rgb24_to_rgb555(AVPicture *dst, AVPicture *src,
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1588 int width, int height)
583
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1589 {
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1590 const unsigned char *p;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1591 unsigned char *q;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1592 int r, g, b, dst_wrap, src_wrap;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1593 int x, y;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1594
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1595 p = src->data[0];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1596 src_wrap = src->linesize[0] - 3 * width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1597
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1598 q = dst->data[0];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1599 dst_wrap = dst->linesize[0] - 2 * width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1600
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1601 for(y=0;y<height;y++) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1602 for(x=0;x<width;x++) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1603 r = p[0];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1604 g = p[1];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1605 b = p[2];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1606
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1607 ((unsigned short *)q)[0] =
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1608 ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3) | 0x8000;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1609 q += 2;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1610 p += 3;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1611 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1612 p += src_wrap;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1613 q += dst_wrap;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1614 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1615 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1616
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1617 static void mono_to_gray(AVPicture *dst, AVPicture *src,
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1618 int width, int height, int xor_mask)
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1619 {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1620 const unsigned char *p;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1621 unsigned char *q;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1622 int v, dst_wrap, src_wrap;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1623 int y, w;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1624
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1625 p = src->data[0];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1626 src_wrap = src->linesize[0] - ((width + 7) >> 3);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1627
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1628 q = dst->data[0];
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1629 dst_wrap = dst->linesize[0] - width;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1630 for(y=0;y<height;y++) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1631 w = width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1632 while (w >= 8) {
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1633 v = *p++ ^ xor_mask;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1634 q[0] = -(v >> 7);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1635 q[1] = -((v >> 6) & 1);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1636 q[2] = -((v >> 5) & 1);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1637 q[3] = -((v >> 4) & 1);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1638 q[4] = -((v >> 3) & 1);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1639 q[5] = -((v >> 2) & 1);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1640 q[6] = -((v >> 1) & 1);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1641 q[7] = -((v >> 0) & 1);
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1642 w -= 8;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1643 q += 8;
583
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1644 }
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1645 if (w > 0) {
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1646 v = *p++ ^ xor_mask;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1647 do {
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1648 q[0] = -((v >> 7) & 1);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1649 q++;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1650 v <<= 1;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1651 } while (--w);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1652 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1653 p += src_wrap;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1654 q += dst_wrap;
583
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1655 }
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1656 }
d6955d0d7d27 Add conversions to and from RGBA32 and BGRA32.
philipjsg
parents: 576
diff changeset
1657
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1658 static void monowhite_to_gray(AVPicture *dst, AVPicture *src,
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1659 int width, int height)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1660 {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1661 mono_to_gray(dst, src, width, height, 0xff);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1662 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1663
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1664 static void monoblack_to_gray(AVPicture *dst, AVPicture *src,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1665 int width, int height)
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
1666 {
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1667 mono_to_gray(dst, src, width, height, 0x00);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1668 }
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1669
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1670 static void gray_to_mono(AVPicture *dst, AVPicture *src,
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1671 int width, int height, int xor_mask)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1672 {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1673 int n;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1674 const uint8_t *s;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1675 uint8_t *d;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1676 int j, b, v, n1, src_wrap, dst_wrap, y;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1677
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1678 s = src->data[0];
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1679 src_wrap = src->linesize[0] - width;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1680
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1681 d = dst->data[0];
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1682 dst_wrap = dst->linesize[0] - ((width + 7) >> 3);
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
1683
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1684 for(y=0;y<height;y++) {
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1685 n = width;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1686 while (n >= 8) {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1687 v = 0;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1688 for(j=0;j<8;j++) {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1689 b = s[0];
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1690 s++;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1691 v = (v << 1) | (b >> 7);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1692 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1693 d[0] = v ^ xor_mask;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1694 d++;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1695 n -= 8;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
1696 }
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1697 if (n > 0) {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1698 n1 = n;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1699 v = 0;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1700 while (n > 0) {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1701 b = s[0];
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1702 s++;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1703 v = (v << 1) | (b >> 7);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1704 n--;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1705 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1706 d[0] = (v << (8 - (n1 & 7))) ^ xor_mask;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1707 d++;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1708 }
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1709 s += src_wrap;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1710 d += dst_wrap;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
1711 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
1712 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
1713
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1714 static void gray_to_monowhite(AVPicture *dst, AVPicture *src,
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1715 int width, int height)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1716 {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1717 gray_to_mono(dst, src, width, height, 0xff);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1718 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1719
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1720 static void gray_to_monoblack(AVPicture *dst, AVPicture *src,
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1721 int width, int height)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1722 {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1723 gray_to_mono(dst, src, width, height, 0x00);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1724 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1725
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1726 /* this is maybe slow, but allows for extensions */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
1727 static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1728 {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1729 return ((((r)/47)%6)*6*6+(((g)/47)%6)*6+(((b)/47)%6));
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1730 }
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1731
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1732 /* XXX: put jpeg quantize code instead */
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1733 static void rgb24_to_pal8(AVPicture *dst, AVPicture *src,
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1734 int width, int height)
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1735 {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1736 const unsigned char *p;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1737 unsigned char *q;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1738 int r, g, b, dst_wrap, src_wrap;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1739 int x, y, i;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1740 static const uint8_t pal_value[6] = { 0x00, 0x33, 0x66, 0x99, 0xcc, 0xff };
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1741 uint32_t *pal;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1742
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1743 p = src->data[0];
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1744 src_wrap = src->linesize[0] - 3 * width;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1745
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1746 q = dst->data[0];
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1747 dst_wrap = dst->linesize[0] - width;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1748
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1749 for(y=0;y<height;y++) {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1750 for(x=0;x<width;x++) {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1751 r = p[0];
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1752 g = p[1];
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1753 b = p[2];
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1754
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1755 q[0] = gif_clut_index(r, g, b);
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1756 q++;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1757 p += 3;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1758 }
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1759 p += src_wrap;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1760 q += dst_wrap;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1761 }
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1762
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1763 /* build palette */
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1764 pal = (uint32_t *)dst->data[1];
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1765 i = 0;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1766 for(r = 0; r < 6; r++) {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1767 for(g = 0; g < 6; g++) {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1768 for(b = 0; b < 6; b++) {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1769 pal[i++] = (0xff << 24) | (pal_value[r] << 16) |
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1770 (pal_value[g] << 8) | pal_value[b];
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1771 }
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1772 }
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1773 }
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1774 while (i < 256)
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1775 pal[i++] = 0;
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1776 }
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1777
1199
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1778 static void rgba32_to_rgb24(AVPicture *dst, AVPicture *src,
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1779 int width, int height)
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1780 {
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1781 const uint8_t *s;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1782 uint8_t *d;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1783 int src_wrap, dst_wrap, j, y;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1784 unsigned int v;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1785
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1786 s = src->data[0];
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1787 src_wrap = src->linesize[0] - width * 4;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1788
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1789 d = dst->data[0];
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1790 dst_wrap = dst->linesize[0] - width * 3;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1791
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1792 for(y=0;y<height;y++) {
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1793 for(j = 0;j < width; j++) {
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1794 v = *(uint32_t *)s;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1795 s += 4;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1796 d[0] = v >> 16;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1797 d[1] = v >> 8;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1798 d[2] = v;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1799 d += 3;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1800 }
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1801 s += src_wrap;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1802 d += dst_wrap;
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1803 }
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1804 }
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1805
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1806 typedef struct ConvertEntry {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1807 void (*convert)(AVPicture *dst, AVPicture *src, int width, int height);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1808 } ConvertEntry;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1809
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1810 /* Add each new convertion function in this table. In order to be able
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1811 to convert from any format to any format, the following constraints
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1812 must be satisfied:
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1813
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1814 - all FF_COLOR_RGB formats must convert to and from PIX_FMT_RGB24
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1815
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1816 - all FF_COLOR_GRAY formats must convert to and from PIX_FMT_GRAY8
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1817
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1818 - all FF_COLOR_RGB formats with alpha must convert to and from PIX_FMT_RGBA32
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1819
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1820 - all PIX_FMT_YUV444P and PIX_FMT_YUVJ444P must convert to and from
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1821 PIX_FMT_RGB24.
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1822
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1823 - PIX_FMT_422 must convert to and from PIX_FMT_422P.
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1824 */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1825 static ConvertEntry convert_table[PIX_FMT_NB][PIX_FMT_NB] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1826 [PIX_FMT_YUV420P] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1827 [PIX_FMT_RGB555] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1828 .convert = yuv420p_to_rgb555
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1829 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1830 [PIX_FMT_RGB565] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1831 .convert = yuv420p_to_rgb565
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1832 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1833 [PIX_FMT_BGR24] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1834 .convert = yuv420p_to_bgr24
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1835 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1836 [PIX_FMT_RGB24] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1837 .convert = yuv420p_to_rgb24
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1838 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1839 [PIX_FMT_RGBA32] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1840 .convert = yuv420p_to_rgba32
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1841 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1842 },
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1843 [PIX_FMT_YUV422P] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1844 [PIX_FMT_YUV422] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1845 .convert = yuv422p_to_yuv422,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1846 },
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1847 },
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1848 [PIX_FMT_YUV444P] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1849 [PIX_FMT_RGB24] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1850 .convert = yuv444p_to_rgb24
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1851 },
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1852 },
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1853 [PIX_FMT_YUVJ420P] = {
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1854 [PIX_FMT_RGB555] = {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1855 .convert = yuvj420p_to_rgb555
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1856 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1857 [PIX_FMT_RGB565] = {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1858 .convert = yuvj420p_to_rgb565
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1859 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1860 [PIX_FMT_BGR24] = {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1861 .convert = yuvj420p_to_bgr24
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1862 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1863 [PIX_FMT_RGB24] = {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1864 .convert = yuvj420p_to_rgb24
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1865 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1866 [PIX_FMT_RGBA32] = {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1867 .convert = yuvj420p_to_rgba32
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1868 },
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1869 },
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1870 [PIX_FMT_YUVJ444P] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1871 [PIX_FMT_RGB24] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1872 .convert = yuvj444p_to_rgb24
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1873 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1874 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1875 [PIX_FMT_YUV422] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1876 [PIX_FMT_YUV420P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1877 .convert = yuv422_to_yuv420p,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1878 },
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1879 [PIX_FMT_YUV422P] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1880 .convert = yuv422_to_yuv422p,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1881 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1882 },
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
1883
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1884 [PIX_FMT_RGB24] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1885 [PIX_FMT_YUV420P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1886 .convert = rgb24_to_yuv420p
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1887 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1888 [PIX_FMT_RGB565] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1889 .convert = rgb24_to_rgb565
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1890 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1891 [PIX_FMT_RGB555] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1892 .convert = rgb24_to_rgb555
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1893 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1894 [PIX_FMT_GRAY8] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1895 .convert = rgb24_to_gray
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1896 },
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1897 [PIX_FMT_PAL8] = {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1898 .convert = rgb24_to_pal8
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1899 },
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1900 [PIX_FMT_YUV444P] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1901 .convert = rgb24_to_yuv444p
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1902 },
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1903 [PIX_FMT_YUVJ420P] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1904 .convert = rgb24_to_yuvj420p
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1905 },
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1906 [PIX_FMT_YUVJ444P] = {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1907 .convert = rgb24_to_yuvj444p
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
1908 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1909 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1910 [PIX_FMT_RGBA32] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1911 [PIX_FMT_YUV420P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1912 .convert = rgba32_to_yuv420p
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1913 },
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1914 [PIX_FMT_GRAY8] = {
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1915 .convert = rgba32_to_gray
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1916 },
1199
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1917 [PIX_FMT_RGB24] = {
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1918 .convert = rgba32_to_rgb24
6b566c5d02e4 rgba32 convert
bellard
parents: 1166
diff changeset
1919 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1920 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1921 [PIX_FMT_BGR24] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1922 [PIX_FMT_YUV420P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1923 .convert = bgr24_to_yuv420p
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1924 },
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1925 [PIX_FMT_GRAY8] = {
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1926 .convert = bgr24_to_gray
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1927 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1928 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1929 [PIX_FMT_RGB555] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1930 [PIX_FMT_YUV420P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1931 .convert = rgb555_to_yuv420p
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1932 },
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1933 [PIX_FMT_GRAY8] = {
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1934 .convert = rgb555_to_gray
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1935 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1936 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1937 [PIX_FMT_RGB565] = {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1938 [PIX_FMT_YUV420P] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1939 .convert = rgb565_to_yuv420p
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1940 },
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1941 [PIX_FMT_GRAY8] = {
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1942 .convert = rgb565_to_gray
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1943 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1944 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1945 [PIX_FMT_GRAY8] = {
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1946 [PIX_FMT_RGB555] = {
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1947 .convert = gray_to_rgb555
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1948 },
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1949 [PIX_FMT_RGB565] = {
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1950 .convert = gray_to_rgb565
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1951 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1952 [PIX_FMT_RGB24] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1953 .convert = gray_to_rgb24
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1954 },
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1955 [PIX_FMT_BGR24] = {
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1956 .convert = gray_to_bgr24
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1957 },
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1958 [PIX_FMT_RGBA32] = {
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1959 .convert = gray_to_rgba32
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
1960 },
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1961 [PIX_FMT_MONOWHITE] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1962 .convert = gray_to_monowhite
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1963 },
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1964 [PIX_FMT_MONOBLACK] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1965 .convert = gray_to_monoblack
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1966 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1967 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1968 [PIX_FMT_MONOWHITE] = {
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1969 [PIX_FMT_GRAY8] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1970 .convert = monowhite_to_gray
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1971 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1972 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1973 [PIX_FMT_MONOBLACK] = {
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
1974 [PIX_FMT_GRAY8] = {
1014
48349e11c9b2 C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (Mns Rullgrd))
michaelni
parents: 993
diff changeset
1975 .convert = monoblack_to_gray
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1976 },
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1977 },
1055
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1978 [PIX_FMT_PAL8] = {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1979 [PIX_FMT_RGB555] = {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1980 .convert = pal8_to_rgb555
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1981 },
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1982 [PIX_FMT_RGB565] = {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1983 .convert = pal8_to_rgb565
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1984 },
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1985 [PIX_FMT_BGR24] = {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1986 .convert = pal8_to_bgr24
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1987 },
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1988 [PIX_FMT_RGB24] = {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1989 .convert = pal8_to_rgb24
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1990 },
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1991 [PIX_FMT_RGBA32] = {
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1992 .convert = pal8_to_rgba32
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1993 },
6261fdd1f69d added paletted 8 bit format support
bellard
parents: 1052
diff changeset
1994 },
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1995 };
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
1996
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1997 static int avpicture_alloc(AVPicture *picture,
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1998 int pix_fmt, int width, int height)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
1999 {
1057
bb5de8a59da8 * static,const,compiler warning cleanup
kabi
parents: 1055
diff changeset
2000 unsigned int size;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2001 void *ptr;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2002
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2003 size = avpicture_get_size(pix_fmt, width, height);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2004 if (size < 0)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2005 goto fail;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2006 ptr = av_malloc(size);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2007 if (!ptr)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2008 goto fail;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2009 avpicture_fill(picture, ptr, pix_fmt, width, height);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2010 return 0;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2011 fail:
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2012 memset(picture, 0, sizeof(AVPicture));
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2013 return -1;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2014 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2015
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2016 static void avpicture_free(AVPicture *picture)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2017 {
1031
19de1445beb2 use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents: 1028
diff changeset
2018 av_free(picture->data[0]);
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2019 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2020
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2021 /* return true if yuv planar */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2022 static inline int is_yuv_planar(PixFmtInfo *ps)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2023 {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2024 return (ps->color_type == FF_COLOR_YUV ||
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2025 ps->color_type == FF_COLOR_YUV_JPEG) && !ps->is_packed;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2026 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2027
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2028 /* XXX: always use linesize. Return -1 if not supported */
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2029 int img_convert(AVPicture *dst, int dst_pix_fmt,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2030 AVPicture *src, int src_pix_fmt,
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2031 int src_width, int src_height)
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2032 {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2033 static int inited;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2034 int i, ret, dst_width, dst_height, int_pix_fmt;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2035 PixFmtInfo *src_pix, *dst_pix;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2036 ConvertEntry *ce;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2037 AVPicture tmp1, *tmp = &tmp1;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2038
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2039 if (src_pix_fmt < 0 || src_pix_fmt >= PIX_FMT_NB ||
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2040 dst_pix_fmt < 0 || dst_pix_fmt >= PIX_FMT_NB)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2041 return -1;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2042 if (src_width <= 0 || src_height <= 0)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2043 return 0;
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
2044
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2045 if (!inited) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2046 inited = 1;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2047 img_convert_init();
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2048 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2049
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2050 dst_width = src_width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2051 dst_height = src_height;
1022
d651df667898 added gray<->RGB functions - fixed rgb<->yuv functions for non RGB24 case
bellard
parents: 1020
diff changeset
2052
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2053 dst_pix = &pix_fmt_info[dst_pix_fmt];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2054 src_pix = &pix_fmt_info[src_pix_fmt];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2055 if (src_pix_fmt == dst_pix_fmt) {
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2056 /* XXX: incorrect */
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2057 /* same format: just copy */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2058 for(i = 0; i < dst_pix->nb_components; i++) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2059 int w, h;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2060 w = dst_width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2061 h = dst_height;
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2062 if (is_yuv_planar(dst_pix) && (i == 1 || i == 2)) {
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2063 w >>= dst_pix->x_chroma_shift;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2064 h >>= dst_pix->y_chroma_shift;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2065 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2066 img_copy(dst->data[i], dst->linesize[i],
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2067 src->data[i], src->linesize[i],
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2068 w, h);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2069 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2070 return 0;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2071 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2072
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2073 ce = &convert_table[src_pix_fmt][dst_pix_fmt];
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2074 if (ce->convert) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2075 /* specific convertion routine */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2076 ce->convert(dst, src, dst_width, dst_height);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2077 return 0;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2078 }
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2079
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2080 /* gray to YUV */
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2081 if (is_yuv_planar(dst_pix) &&
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2082 src_pix_fmt == PIX_FMT_GRAY8) {
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2083 int w, h, y;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2084 uint8_t *d;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2085
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2086 if (dst_pix->color_type == FF_COLOR_YUV_JPEG) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2087 img_copy(dst->data[0], dst->linesize[0],
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2088 src->data[0], src->linesize[0],
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2089 dst_width, dst_height);
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2090 } else {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2091 img_apply_table(dst->data[0], dst->linesize[0],
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2092 src->data[0], src->linesize[0],
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2093 dst_width, dst_height,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2094 y_jpeg_to_ccir);
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2095 }
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2096 /* fill U and V with 128 */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2097 w = dst_width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2098 h = dst_height;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2099 w >>= dst_pix->x_chroma_shift;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2100 h >>= dst_pix->y_chroma_shift;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2101 for(i = 1; i <= 2; i++) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2102 d = dst->data[i];
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2103 for(y = 0; y< h; y++) {
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2104 memset(d, 128, w);
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2105 d += dst->linesize[i];
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2106 }
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2107 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2108 return 0;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2109 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2110
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2111 /* YUV to gray */
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2112 if (is_yuv_planar(src_pix) &&
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2113 dst_pix_fmt == PIX_FMT_GRAY8) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2114 if (src_pix->color_type == FF_COLOR_YUV_JPEG) {
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2115 img_copy(dst->data[0], dst->linesize[0],
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2116 src->data[0], src->linesize[0],
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2117 dst_width, dst_height);
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2118 } else {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2119 img_apply_table(dst->data[0], dst->linesize[0],
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2120 src->data[0], src->linesize[0],
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2121 dst_width, dst_height,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2122 y_ccir_to_jpeg);
1202
8b49a7ee4e4e YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
bellard
parents: 1199
diff changeset
2123 }
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2124 return 0;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2125 }
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2126
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2127 /* YUV to YUV planar */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2128 if (is_yuv_planar(dst_pix) && is_yuv_planar(src_pix)) {
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2129 int x_shift, y_shift, w, h;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2130 void (*resize_func)(uint8_t *dst, int dst_wrap,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2131 uint8_t *src, int src_wrap,
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2132 int width, int height);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2133
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2134 /* compute chroma size of the smallest dimensions */
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2135 w = dst_width;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2136 h = dst_height;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2137 if (dst_pix->x_chroma_shift >= src_pix->x_chroma_shift)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2138 w >>= dst_pix->x_chroma_shift;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2139 else
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2140 w >>= src_pix->x_chroma_shift;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2141 if (dst_pix->y_chroma_shift >= src_pix->y_chroma_shift)
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2142 h >>= dst_pix->y_chroma_shift;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2143 else
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2144 h >>= src_pix->y_chroma_shift;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2145
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2146 x_shift = (dst_pix->x_chroma_shift - src_pix->x_chroma_shift);
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2147 y_shift = (dst_pix->y_chroma_shift - src_pix->y_chroma_shift);
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2148
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2149 if (x_shift == 0 && y_shift == 0) {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2150 resize_func = img_copy;
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2151 } else if (x_shift == 0 && y_shift == 1) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2152 resize_func = shrink2;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2153 } else if (x_shift == 1 && y_shift == 1) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2154 resize_func = shrink22;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2155 } else if (x_shift == -1 && y_shift == -1) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2156 resize_func = grow22;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2157 } else if (x_shift == -1 && y_shift == 1) {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2158 resize_func = conv411;
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2159 } else {
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2160 /* currently not handled */
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2161 return -1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2162 }
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2163
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2164 img_copy(dst->data[0], dst->linesize[0],
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2165 src->data[0], src->linesize[0],
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2166 dst_width, dst_height);
1023
e61be5796027 img_convert() (YUV to YUV) patch by (Max Krasnyansky <maxk at qualcomm dot com>)
michaelni
parents: 1022
diff changeset
2167
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2168 for(i = 1;i <= 2; i++)
1023
e61be5796027 img_convert() (YUV to YUV) patch by (Max Krasnyansky <maxk at qualcomm dot com>)
michaelni
parents: 1022
diff changeset
2169 resize_func(dst->data[i], dst->linesize[i],
e61be5796027 img_convert() (YUV to YUV) patch by (Max Krasnyansky <maxk at qualcomm dot com>)
michaelni
parents: 1022
diff changeset
2170 src->data[i], src->linesize[i],
1073
4bc02fcf4d8c fixing 410 -> 420
michaelni
parents: 1064
diff changeset
2171 dst_width>>dst_pix->x_chroma_shift, dst_height>>dst_pix->y_chroma_shift);
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2172 /* if yuv color space conversion is needed, we do it here on
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2173 the destination image */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2174 if (dst_pix->color_type != src_pix->color_type) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2175 const uint8_t *y_table, *c_table;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2176 if (dst_pix->color_type == FF_COLOR_YUV) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2177 y_table = y_jpeg_to_ccir;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2178 c_table = c_jpeg_to_ccir;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2179 } else {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2180 y_table = y_ccir_to_jpeg;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2181 c_table = c_ccir_to_jpeg;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2182 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2183 img_apply_table(dst->data[0], dst->linesize[0],
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2184 dst->data[0], dst->linesize[0],
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2185 dst_width, dst_height,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2186 y_table);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2187
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2188 for(i = 1;i <= 2; i++)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2189 img_apply_table(dst->data[i], dst->linesize[i],
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2190 dst->data[i], dst->linesize[i],
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2191 dst_width>>dst_pix->x_chroma_shift,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2192 dst_height>>dst_pix->y_chroma_shift,
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2193 c_table);
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2194 }
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2195 return 0;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2196 }
989
fe9083c56733 simplified code (need automatic testing) - added primitive new format support.
bellard
parents: 940
diff changeset
2197
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2198 /* try to use an intermediate format */
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2199 if (src_pix_fmt == PIX_FMT_YUV422 ||
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2200 dst_pix_fmt == PIX_FMT_YUV422) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2201 /* specific case: convert to YUV422P first */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2202 int_pix_fmt = PIX_FMT_YUV422P;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2203 } else if ((src_pix->color_type == FF_COLOR_GRAY &&
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2204 src_pix_fmt != PIX_FMT_GRAY8) ||
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2205 (dst_pix->color_type == FF_COLOR_GRAY &&
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2206 dst_pix_fmt != PIX_FMT_GRAY8)) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2207 /* gray8 is the normalized format */
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2208 int_pix_fmt = PIX_FMT_GRAY8;
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2209 } else if ((is_yuv_planar(src_pix) &&
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2210 src_pix_fmt != PIX_FMT_YUV444P &&
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2211 src_pix_fmt != PIX_FMT_YUVJ444P)) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2212 /* yuv444 is the normalized format */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2213 if (src_pix->color_type == FF_COLOR_YUV_JPEG)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2214 int_pix_fmt = PIX_FMT_YUVJ444P;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2215 else
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2216 int_pix_fmt = PIX_FMT_YUV444P;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2217 } else if ((is_yuv_planar(dst_pix) &&
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2218 dst_pix_fmt != PIX_FMT_YUV444P &&
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2219 dst_pix_fmt != PIX_FMT_YUVJ444P)) {
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2220 /* yuv444 is the normalized format */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2221 if (dst_pix->color_type == FF_COLOR_YUV_JPEG)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2222 int_pix_fmt = PIX_FMT_YUVJ444P;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2223 else
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2224 int_pix_fmt = PIX_FMT_YUV444P;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2225 } else {
1203
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2226 /* the two formats are rgb or gray8 or yuv[j]444p */
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2227 if (src_pix->is_alpha && dst_pix->is_alpha)
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2228 int_pix_fmt = PIX_FMT_RGBA32;
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2229 else
80c73b9b0ba2 accurate YUV to RGB and RGB to YUV conversions - added comments
bellard
parents: 1202
diff changeset
2230 int_pix_fmt = PIX_FMT_RGB24;
993
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2231 }
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2232 if (avpicture_alloc(tmp, int_pix_fmt, dst_width, dst_height) < 0)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2233 return -1;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2234 ret = -1;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2235 if (img_convert(tmp, int_pix_fmt,
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2236 src, src_pix_fmt, src_width, src_height) < 0)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2237 goto fail1;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2238 if (img_convert(dst, dst_pix_fmt,
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2239 tmp, int_pix_fmt, dst_width, dst_height) < 0)
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2240 goto fail1;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2241 ret = 0;
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2242 fail1:
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2243 avpicture_free(tmp);
895d3b01c6f4 added missing formats in all functions - added monoblack, monowhite and gray8 support for most conversions
bellard
parents: 989
diff changeset
2244 return ret;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2245 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2246
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2247
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2248 #ifdef HAVE_MMX
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2249 #define DEINT_INPLACE_LINE_LUM \
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2250 movd_m2r(lum_m4[0],mm0);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2251 movd_m2r(lum_m3[0],mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2252 movd_m2r(lum_m2[0],mm2);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2253 movd_m2r(lum_m1[0],mm3);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2254 movd_m2r(lum[0],mm4);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2255 punpcklbw_r2r(mm7,mm0);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2256 movd_r2m(mm2,lum_m4[0]);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2257 punpcklbw_r2r(mm7,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2258 punpcklbw_r2r(mm7,mm2);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2259 punpcklbw_r2r(mm7,mm3);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2260 punpcklbw_r2r(mm7,mm4);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2261 paddw_r2r(mm3,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2262 psllw_i2r(1,mm2);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2263 paddw_r2r(mm4,mm0);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2264 psllw_i2r(2,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2265 paddw_r2r(mm6,mm2);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2266 paddw_r2r(mm2,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2267 psubusw_r2r(mm0,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2268 psrlw_i2r(3,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2269 packuswb_r2r(mm7,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2270 movd_r2m(mm1,lum_m2[0]);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2271
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2272 #define DEINT_LINE_LUM \
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2273 movd_m2r(lum_m4[0],mm0);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2274 movd_m2r(lum_m3[0],mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2275 movd_m2r(lum_m2[0],mm2);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2276 movd_m2r(lum_m1[0],mm3);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2277 movd_m2r(lum[0],mm4);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2278 punpcklbw_r2r(mm7,mm0);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2279 punpcklbw_r2r(mm7,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2280 punpcklbw_r2r(mm7,mm2);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2281 punpcklbw_r2r(mm7,mm3);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2282 punpcklbw_r2r(mm7,mm4);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2283 paddw_r2r(mm3,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2284 psllw_i2r(1,mm2);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2285 paddw_r2r(mm4,mm0);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2286 psllw_i2r(2,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2287 paddw_r2r(mm6,mm2);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2288 paddw_r2r(mm2,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2289 psubusw_r2r(mm0,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2290 psrlw_i2r(3,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2291 packuswb_r2r(mm7,mm1);\
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2292 movd_r2m(mm1,dst[0]);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2293 #endif
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2294
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2295 /* filter parameters: [-1 4 2 4 -1] // 8 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2296 static void deinterlace_line(uint8_t *dst, uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2297 int size)
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2298 {
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2299 #ifndef HAVE_MMX
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2300 uint8_t *cm = cropTbl + MAX_NEG_CROP;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2301 int sum;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2302
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2303 for(;size > 0;size--) {
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2304 sum = -lum_m4[0];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2305 sum += lum_m3[0] << 2;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2306 sum += lum_m2[0] << 1;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2307 sum += lum_m1[0] << 2;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2308 sum += -lum[0];
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2309 dst[0] = cm[(sum + 4) >> 3];
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2310 lum_m4++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2311 lum_m3++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2312 lum_m2++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2313 lum_m1++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2314 lum++;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2315 dst++;
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2316 }
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2317 #else
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2318
1044
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2319 {
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2320 mmx_t rounder;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2321 rounder.uw[0]=4;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2322 rounder.uw[1]=4;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2323 rounder.uw[2]=4;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2324 rounder.uw[3]=4;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2325 pxor_r2r(mm7,mm7);
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2326 movq_m2r(rounder,mm6);
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2327 }
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2328 for (;size > 3; size-=4) {
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2329 DEINT_LINE_LUM
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2330 lum_m4+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2331 lum_m3+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2332 lum_m2+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2333 lum_m1+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2334 lum+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2335 dst+=4;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2336 }
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2337 #endif
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2338 }
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2339 static void deinterlace_line_inplace(uint8_t *lum_m4, uint8_t *lum_m3, uint8_t *lum_m2, uint8_t *lum_m1, uint8_t *lum,
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2340 int size)
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2341 {
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2342 #ifndef HAVE_MMX
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2343 uint8_t *cm = cropTbl + MAX_NEG_CROP;
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2344 int sum;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2345
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2346 for(;size > 0;size--) {
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2347 sum = -lum_m4[0];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2348 sum += lum_m3[0] << 2;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2349 sum += lum_m2[0] << 1;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2350 lum_m4[0]=lum_m2[0];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2351 sum += lum_m1[0] << 2;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2352 sum += -lum[0];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2353 lum_m2[0] = cm[(sum + 4) >> 3];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2354 lum_m4++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2355 lum_m3++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2356 lum_m2++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2357 lum_m1++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2358 lum++;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2359 }
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2360 #else
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2361
1044
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2362 {
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2363 mmx_t rounder;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2364 rounder.uw[0]=4;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2365 rounder.uw[1]=4;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2366 rounder.uw[2]=4;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2367 rounder.uw[3]=4;
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2368 pxor_r2r(mm7,mm7);
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2369 movq_m2r(rounder,mm6);
c6b3af81d79e 100000l
michaelni
parents: 1031
diff changeset
2370 }
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2371 for (;size > 3; size-=4) {
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2372 DEINT_INPLACE_LINE_LUM
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2373 lum_m4+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2374 lum_m3+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2375 lum_m2+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2376 lum_m1+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2377 lum+=4;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2378 }
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2379 #endif
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2380 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2381
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2382 /* deinterlacing : 2 temporal taps, 3 spatial taps linear filter. The
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2383 top field is copied as is, but the bottom field is deinterlaced
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2384 against the top field. */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2385 static void deinterlace_bottom_field(uint8_t *dst, int dst_wrap,
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2386 uint8_t *src1, int src_wrap,
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2387 int width, int height)
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2388 {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2389 uint8_t *src_m2, *src_m1, *src_0, *src_p1, *src_p2;
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2390 int y;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2391
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2392 src_m2 = src1;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2393 src_m1 = src1;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2394 src_0=&src_m1[src_wrap];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2395 src_p1=&src_0[src_wrap];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2396 src_p2=&src_p1[src_wrap];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2397 for(y=0;y<(height-2);y+=2) {
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2398 memcpy(dst,src_m1,width);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2399 dst += dst_wrap;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2400 deinterlace_line(dst,src_m2,src_m1,src_0,src_p1,src_p2,width);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2401 src_m2 = src_0;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2402 src_m1 = src_p1;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2403 src_0 = src_p2;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2404 src_p1 += 2*src_wrap;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2405 src_p2 += 2*src_wrap;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2406 dst += dst_wrap;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2407 }
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2408 memcpy(dst,src_m1,width);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2409 dst += dst_wrap;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2410 /* do last line */
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2411 deinterlace_line(dst,src_m2,src_m1,src_0,src_0,src_0,width);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2412 }
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2413
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2414 static void deinterlace_bottom_field_inplace(uint8_t *src1, int src_wrap,
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2415 int width, int height)
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2416 {
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2417 uint8_t *src_m1, *src_0, *src_p1, *src_p2;
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2418 int y;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2419 uint8_t *buf;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 1057
diff changeset
2420 buf = (uint8_t*)av_malloc(width);
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2421
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2422 src_m1 = src1;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2423 memcpy(buf,src_m1,width);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2424 src_0=&src_m1[src_wrap];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2425 src_p1=&src_0[src_wrap];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2426 src_p2=&src_p1[src_wrap];
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2427 for(y=0;y<(height-2);y+=2) {
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2428 deinterlace_line_inplace(buf,src_m1,src_0,src_p1,src_p2,width);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2429 src_m1 = src_p1;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2430 src_0 = src_p2;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2431 src_p1 += 2*src_wrap;
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2432 src_p2 += 2*src_wrap;
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2433 }
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2434 /* do last line */
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2435 deinterlace_line_inplace(buf,src_m1,src_0,src_0,src_0,width);
396
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 315
diff changeset
2436 av_free(buf);
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2437 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2438
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2439
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2440 /* deinterlace - if not supported return -1 */
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2441 int avpicture_deinterlace(AVPicture *dst, AVPicture *src,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2442 int pix_fmt, int width, int height)
986e461dc072 Initial revision
glantau
parents:
diff changeset
2443 {
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2444 int i;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2445
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2446 if (pix_fmt != PIX_FMT_YUV420P &&
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2447 pix_fmt != PIX_FMT_YUV422P &&
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2448 pix_fmt != PIX_FMT_YUV444P)
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2449 return -1;
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2450 if ((width & 3) != 0 || (height & 3) != 0)
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2451 return -1;
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2452
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2453 for(i=0;i<3;i++) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2454 if (i == 1) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2455 switch(pix_fmt) {
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2456 case PIX_FMT_YUV420P:
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2457 width >>= 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2458 height >>= 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2459 break;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2460 case PIX_FMT_YUV422P:
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2461 width >>= 1;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2462 break;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2463 default:
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2464 break;
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2465 }
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2466 }
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2467 if (src == dst) {
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2468 deinterlace_bottom_field_inplace(src->data[i], src->linesize[i],
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2469 width, height);
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2470 } else {
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2471 deinterlace_bottom_field(dst->data[i],dst->linesize[i],
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2472 src->data[i], src->linesize[i],
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2473 width, height);
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2474 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2475 }
801
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2476 #ifdef HAVE_MMX
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2477 emms();
f720b01c0fd5 1) Add MMX deinterlace code.
michaelni
parents: 736
diff changeset
2478 #endif
52
1d796bdb2c2a added 422P, 444P support - added deinterlace support - added xxx to RGB24 convertion
glantau
parents: 18
diff changeset
2479 return 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
2480 }
440
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
2481
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
2482 #undef FIX