~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_libswscale/yuv2rgb.c

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * yuv2rgb.c, Software YUV to RGB coverter
3
 
 *
4
 
 *  Copyright (C) 1999, Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
5
 
 *  All Rights Reserved.
6
 
 *
7
 
 *  Functions broken out from display_x11.c and several new modes
8
 
 *  added by H�kan Hjort <d95hjort@dtek.chalmers.se>
9
 
 *
10
 
 *  15 & 16 bpp support by Franck Sicard <Franck.Sicard@solsoft.fr>
11
 
 *
12
 
 *  This file is part of mpeg2dec, a free MPEG-2 video decoder
13
 
 *
14
 
 *  mpeg2dec is free software; you can redistribute it and/or modify
15
 
 *  it under the terms of the GNU General Public License as published by
16
 
 *  the Free Software Foundation; either version 2, or (at your option)
17
 
 *  any later version.
18
 
 *
19
 
 *  mpeg2dec is distributed in the hope that it will be useful,
20
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 
 *  GNU General Public License for more details.
23
 
 *
24
 
 *  You should have received a copy of the GNU General Public License
25
 
 *  along with GNU Make; see the file COPYING.  If not, write to
26
 
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27
 
 *
28
 
 * MMX/MMX2 Template stuff from Michael Niedermayer (michaelni@gmx.at) (needed for fast movntq support)
29
 
 * 1,4,8bpp support by Michael Niedermayer (michaelni@gmx.at)
30
 
 * context / deglobalize stuff by Michael Niedermayer
31
 
 */
32
 
 
33
 
// MEANX
34
 
#include "config.h"
35
 
// /MEANX
36
 
#include <stdio.h>
37
 
#include <stdlib.h>
38
 
#include <inttypes.h>
39
 
#include <assert.h>
40
 
 
41
 
#include "config.h"
42
 
#include "rgb2rgb.h"
43
 
#include "swscale.h"
44
 
#include "swscale_internal.h"
45
 
 
46
 
#ifdef HAVE_MLIB
47
 
#include "yuv2rgb_mlib.c"
48
 
#endif
49
 
// MEANX
50
 
#include "wrapper.h"
51
 
#include "../admmangle.h"
52
 
// /MEANX
53
 
 
54
 
#define DITHER1XBPP // only for mmx
55
 
 
56
 
const uint8_t  __attribute__((aligned(8))) dither_2x2_4[2][8]={
57
 
{  1,   3,   1,   3,   1,   3,   1,   3, },
58
 
{  2,   0,   2,   0,   2,   0,   2,   0, },
59
 
};
60
 
 
61
 
const uint8_t  __attribute__((aligned(8))) dither_2x2_8[2][8]={
62
 
{  6,   2,   6,   2,   6,   2,   6,   2, },
63
 
{  0,   4,   0,   4,   0,   4,   0,   4, },
64
 
};
65
 
 
66
 
const uint8_t  __attribute__((aligned(8))) dither_8x8_32[8][8]={
67
 
{ 17,   9,  23,  15,  16,   8,  22,  14, },
68
 
{  5,  29,   3,  27,   4,  28,   2,  26, },
69
 
{ 21,  13,  19,  11,  20,  12,  18,  10, },
70
 
{  0,  24,   6,  30,   1,  25,   7,  31, },
71
 
{ 16,   8,  22,  14,  17,   9,  23,  15, },
72
 
{  4,  28,   2,  26,   5,  29,   3,  27, },
73
 
{ 20,  12,  18,  10,  21,  13,  19,  11, },
74
 
{  1,  25,   7,  31,   0,  24,   6,  30, },
75
 
};
76
 
 
77
 
#if 0
78
 
const uint8_t  __attribute__((aligned(8))) dither_8x8_64[8][8]={
79
 
{  0,  48,  12,  60,   3,  51,  15,  63, },
80
 
{ 32,  16,  44,  28,  35,  19,  47,  31, },
81
 
{  8,  56,   4,  52,  11,  59,   7,  55, },
82
 
{ 40,  24,  36,  20,  43,  27,  39,  23, },
83
 
{  2,  50,  14,  62,   1,  49,  13,  61, },
84
 
{ 34,  18,  46,  30,  33,  17,  45,  29, },
85
 
{ 10,  58,   6,  54,   9,  57,   5,  53, },
86
 
{ 42,  26,  38,  22,  41,  25,  37,  21, },
87
 
};
88
 
#endif
89
 
 
90
 
const uint8_t  __attribute__((aligned(8))) dither_8x8_73[8][8]={
91
 
{  0,  55,  14,  68,   3,  58,  17,  72, },
92
 
{ 37,  18,  50,  32,  40,  22,  54,  35, },
93
 
{  9,  64,   5,  59,  13,  67,   8,  63, },
94
 
{ 46,  27,  41,  23,  49,  31,  44,  26, },
95
 
{  2,  57,  16,  71,   1,  56,  15,  70, },
96
 
{ 39,  21,  52,  34,  38,  19,  51,  33, },
97
 
{ 11,  66,   7,  62,  10,  65,   6,  60, },
98
 
{ 48,  30,  43,  25,  47,  29,  42,  24, },
99
 
};
100
 
 
101
 
#if 0
102
 
const uint8_t  __attribute__((aligned(8))) dither_8x8_128[8][8]={
103
 
{ 68,  36,  92,  60,  66,  34,  90,  58, },
104
 
{ 20, 116,  12, 108,  18, 114,  10, 106, },
105
 
{ 84,  52,  76,  44,  82,  50,  74,  42, },
106
 
{  0,  96,  24, 120,   6, 102,  30, 126, },
107
 
{ 64,  32,  88,  56,  70,  38,  94,  62, },
108
 
{ 16, 112,   8, 104,  22, 118,  14, 110, },
109
 
{ 80,  48,  72,  40,  86,  54,  78,  46, },
110
 
{  4, 100,  28, 124,   2,  98,  26, 122, },
111
 
};
112
 
#endif
113
 
 
114
 
#if 1
115
 
const uint8_t  __attribute__((aligned(8))) dither_8x8_220[8][8]={
116
 
{117,  62, 158, 103, 113,  58, 155, 100, },
117
 
{ 34, 199,  21, 186,  31, 196,  17, 182, },
118
 
{144,  89, 131,  76, 141,  86, 127,  72, },
119
 
{  0, 165,  41, 206,  10, 175,  52, 217, },
120
 
{110,  55, 151,  96, 120,  65, 162, 107, },
121
 
{ 28, 193,  14, 179,  38, 203,  24, 189, },
122
 
{138,  83, 124,  69, 148,  93, 134,  79, },
123
 
{  7, 172,  48, 213,   3, 168,  45, 210, },
124
 
};
125
 
#elif 1
126
 
// tries to correct a gamma of 1.5
127
 
const uint8_t  __attribute__((aligned(8))) dither_8x8_220[8][8]={
128
 
{  0, 143,  18, 200,   2, 156,  25, 215, },
129
 
{ 78,  28, 125,  64,  89,  36, 138,  74, },
130
 
{ 10, 180,   3, 161,  16, 195,   8, 175, },
131
 
{109,  51,  93,  38, 121,  60, 105,  47, },
132
 
{  1, 152,  23, 210,   0, 147,  20, 205, },
133
 
{ 85,  33, 134,  71,  81,  30, 130,  67, },
134
 
{ 14, 190,   6, 171,  12, 185,   5, 166, },
135
 
{117,  57, 101,  44, 113,  54,  97,  41, },
136
 
};
137
 
#elif 1
138
 
// tries to correct a gamma of 2.0
139
 
const uint8_t  __attribute__((aligned(8))) dither_8x8_220[8][8]={
140
 
{  0, 124,   8, 193,   0, 140,  12, 213, },
141
 
{ 55,  14, 104,  42,  66,  19, 119,  52, },
142
 
{  3, 168,   1, 145,   6, 187,   3, 162, },
143
 
{ 86,  31,  70,  21,  99,  39,  82,  28, },
144
 
{  0, 134,  11, 206,   0, 129,   9, 200, },
145
 
{ 62,  17, 114,  48,  58,  16, 109,  45, },
146
 
{  5, 181,   2, 157,   4, 175,   1, 151, },
147
 
{ 95,  36,  78,  26,  90,  34,  74,  24, },
148
 
};
149
 
#else
150
 
// tries to correct a gamma of 2.5
151
 
const uint8_t  __attribute__((aligned(8))) dither_8x8_220[8][8]={
152
 
{  0, 107,   3, 187,   0, 125,   6, 212, },
153
 
{ 39,   7,  86,  28,  49,  11, 102,  36, },
154
 
{  1, 158,   0, 131,   3, 180,   1, 151, },
155
 
{ 68,  19,  52,  12,  81,  25,  64,  17, },
156
 
{  0, 119,   5, 203,   0, 113,   4, 195, },
157
 
{ 45,   9,  96,  33,  42,   8,  91,  30, },
158
 
{  2, 172,   1, 144,   2, 165,   0, 137, },
159
 
{ 77,  23,  60,  15,  72,  21,  56,  14, },
160
 
};
161
 
#endif
162
 
 
163
 
#ifdef HAVE_MMX
164
 
 
165
 
/* hope these constant values are cache line aligned */
166
 
uint64_t attribute_used __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ffULL;
167
 
uint64_t attribute_used __attribute__((aligned(8))) mmx_redmask = 0xf8f8f8f8f8f8f8f8ULL;
168
 
uint64_t attribute_used __attribute__((aligned(8))) mmx_grnmask = 0xfcfcfcfcfcfcfcfcULL;
169
 
 
170
 
uint64_t attribute_used __attribute__((aligned(8))) M24A=   0x00FF0000FF0000FFULL;
171
 
uint64_t attribute_used __attribute__((aligned(8))) M24B=   0xFF0000FF0000FF00ULL;
172
 
uint64_t attribute_used __attribute__((aligned(8))) M24C=   0x0000FF0000FF0000ULL;
173
 
 
174
 
// the volatile is required because gcc otherwise optimizes some writes away not knowing that these
175
 
// are read in the asm block
176
 
volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither;
177
 
volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither;
178
 
volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither;
179
 
volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither;
180
 
 
181
 
uint64_t __attribute__((aligned(8))) dither4[2]={
182
 
        0x0103010301030103LL,
183
 
        0x0200020002000200LL,};
184
 
 
185
 
uint64_t __attribute__((aligned(8))) dither8[2]={
186
 
        0x0602060206020602LL,
187
 
        0x0004000400040004LL,};
188
 
 
189
 
#undef HAVE_MMX
190
 
 
191
 
//MMX versions
192
 
#undef RENAME
193
 
#define HAVE_MMX
194
 
#undef HAVE_MMX2
195
 
#undef HAVE_3DNOW
196
 
#define RENAME(a) a ## _MMX
197
 
#include "yuv2rgb_template.c"
198
 
 
199
 
//MMX2 versions
200
 
#undef RENAME
201
 
#define HAVE_MMX
202
 
#define HAVE_MMX2
203
 
#undef HAVE_3DNOW
204
 
#define RENAME(a) a ## _MMX2
205
 
#include "yuv2rgb_template.c"
206
 
 
207
 
#endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */
208
 
 
209
 
const int32_t Inverse_Table_6_9[8][4] = {
210
 
    {117504, 138453, 13954, 34903}, /* no sequence_display_extension */
211
 
    {117504, 138453, 13954, 34903}, /* ITU-R Rec. 709 (1990) */
212
 
    {104597, 132201, 25675, 53279}, /* unspecified */
213
 
    {104597, 132201, 25675, 53279}, /* reserved */
214
 
    {104448, 132798, 24759, 53109}, /* FCC */
215
 
    {104597, 132201, 25675, 53279}, /* ITU-R Rec. 624-4 System B, G */
216
 
    {104597, 132201, 25675, 53279}, /* SMPTE 170M */
217
 
    {117579, 136230, 16907, 35559}  /* SMPTE 240M (1987) */
218
 
};
219
 
 
220
 
#define RGB(i)                                  \
221
 
        U = pu[i];                              \
222
 
        V = pv[i];                              \
223
 
        r = c->table_rV[V];                     \
224
 
        g = c->table_gU[U] + c->table_gV[V];            \
225
 
        b = c->table_bU[U];
226
 
 
227
 
#define DST1(i)                                 \
228
 
        Y = py_1[2*i];                          \
229
 
        dst_1[2*i] = r[Y] + g[Y] + b[Y];        \
230
 
        Y = py_1[2*i+1];                        \
231
 
        dst_1[2*i+1] = r[Y] + g[Y] + b[Y];
232
 
 
233
 
#define DST2(i)                                 \
234
 
        Y = py_2[2*i];                          \
235
 
        dst_2[2*i] = r[Y] + g[Y] + b[Y];        \
236
 
        Y = py_2[2*i+1];                        \
237
 
        dst_2[2*i+1] = r[Y] + g[Y] + b[Y];
238
 
 
239
 
#define DST1RGB(i)                                                      \
240
 
        Y = py_1[2*i];                                                  \
241
 
        dst_1[6*i] = r[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = b[Y];    \
242
 
        Y = py_1[2*i+1];                                                \
243
 
        dst_1[6*i+3] = r[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = b[Y];
244
 
 
245
 
#define DST2RGB(i)                                                      \
246
 
        Y = py_2[2*i];                                                  \
247
 
        dst_2[6*i] = r[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = b[Y];    \
248
 
        Y = py_2[2*i+1];                                                \
249
 
        dst_2[6*i+3] = r[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = b[Y];
250
 
 
251
 
#define DST1BGR(i)                                                      \
252
 
        Y = py_1[2*i];                                                  \
253
 
        dst_1[6*i] = b[Y]; dst_1[6*i+1] = g[Y]; dst_1[6*i+2] = r[Y];    \
254
 
        Y = py_1[2*i+1];                                                \
255
 
        dst_1[6*i+3] = b[Y]; dst_1[6*i+4] = g[Y]; dst_1[6*i+5] = r[Y];
256
 
 
257
 
#define DST2BGR(i)                                                      \
258
 
        Y = py_2[2*i];                                                  \
259
 
        dst_2[6*i] = b[Y]; dst_2[6*i+1] = g[Y]; dst_2[6*i+2] = r[Y];    \
260
 
        Y = py_2[2*i+1];                                                \
261
 
        dst_2[6*i+3] = b[Y]; dst_2[6*i+4] = g[Y]; dst_2[6*i+5] = r[Y];
262
 
 
263
 
#define PROLOG(func_name, dst_type) \
264
 
static int func_name(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY, \
265
 
             int srcSliceH, uint8_t* dst[], int dstStride[]){\
266
 
    int y;\
267
 
\
268
 
    if(c->srcFormat == PIX_FMT_YUV422P){\
269
 
        srcStride[1] *= 2;\
270
 
        srcStride[2] *= 2;\
271
 
    }\
272
 
    for(y=0; y<srcSliceH; y+=2){\
273
 
        dst_type *dst_1= (dst_type*)(dst[0] + (y+srcSliceY  )*dstStride[0]);\
274
 
        dst_type *dst_2= (dst_type*)(dst[0] + (y+srcSliceY+1)*dstStride[0]);\
275
 
        dst_type *r, *g, *b;\
276
 
        uint8_t *py_1= src[0] + y*srcStride[0];\
277
 
        uint8_t *py_2= py_1 + srcStride[0];\
278
 
        uint8_t *pu= src[1] + (y>>1)*srcStride[1];\
279
 
        uint8_t *pv= src[2] + (y>>1)*srcStride[2];\
280
 
        unsigned int h_size= c->dstW>>3;\
281
 
        while (h_size--) {\
282
 
            int U, V, Y;\
283
 
 
284
 
#define EPILOG(dst_delta)\
285
 
            pu += 4;\
286
 
            pv += 4;\
287
 
            py_1 += 8;\
288
 
            py_2 += 8;\
289
 
            dst_1 += dst_delta;\
290
 
            dst_2 += dst_delta;\
291
 
        }\
292
 
    }\
293
 
    return srcSliceH;\
294
 
}
295
 
 
296
 
PROLOG(yuv2rgb_c_32, uint32_t)
297
 
        RGB(0);
298
 
        DST1(0);
299
 
        DST2(0);
300
 
 
301
 
        RGB(1);
302
 
        DST2(1);
303
 
        DST1(1);
304
 
 
305
 
        RGB(2);
306
 
        DST1(2);
307
 
        DST2(2);
308
 
 
309
 
        RGB(3);
310
 
        DST2(3);
311
 
        DST1(3);
312
 
EPILOG(8)
313
 
 
314
 
PROLOG(yuv2rgb_c_24_rgb, uint8_t)
315
 
        RGB(0);
316
 
        DST1RGB(0);
317
 
        DST2RGB(0);
318
 
 
319
 
        RGB(1);
320
 
        DST2RGB(1);
321
 
        DST1RGB(1);
322
 
 
323
 
        RGB(2);
324
 
        DST1RGB(2);
325
 
        DST2RGB(2);
326
 
 
327
 
        RGB(3);
328
 
        DST2RGB(3);
329
 
        DST1RGB(3);
330
 
EPILOG(24)
331
 
 
332
 
// only trivial mods from yuv2rgb_c_24_rgb
333
 
PROLOG(yuv2rgb_c_24_bgr, uint8_t)
334
 
        RGB(0);
335
 
        DST1BGR(0);
336
 
        DST2BGR(0);
337
 
 
338
 
        RGB(1);
339
 
        DST2BGR(1);
340
 
        DST1BGR(1);
341
 
 
342
 
        RGB(2);
343
 
        DST1BGR(2);
344
 
        DST2BGR(2);
345
 
 
346
 
        RGB(3);
347
 
        DST2BGR(3);
348
 
        DST1BGR(3);
349
 
EPILOG(24)
350
 
 
351
 
// This is exactly the same code as yuv2rgb_c_32 except for the types of
352
 
// r, g, b, dst_1, dst_2
353
 
PROLOG(yuv2rgb_c_16, uint16_t)
354
 
        RGB(0);
355
 
        DST1(0);
356
 
        DST2(0);
357
 
 
358
 
        RGB(1);
359
 
        DST2(1);
360
 
        DST1(1);
361
 
 
362
 
        RGB(2);
363
 
        DST1(2);
364
 
        DST2(2);
365
 
 
366
 
        RGB(3);
367
 
        DST2(3);
368
 
        DST1(3);
369
 
EPILOG(8)
370
 
 
371
 
// This is exactly the same code as yuv2rgb_c_32 except for the types of
372
 
// r, g, b, dst_1, dst_2
373
 
PROLOG(yuv2rgb_c_8, uint8_t)
374
 
        RGB(0);
375
 
        DST1(0);
376
 
        DST2(0);
377
 
 
378
 
        RGB(1);
379
 
        DST2(1);
380
 
        DST1(1);
381
 
 
382
 
        RGB(2);
383
 
        DST1(2);
384
 
        DST2(2);
385
 
 
386
 
        RGB(3);
387
 
        DST2(3);
388
 
        DST1(3);
389
 
EPILOG(8)
390
 
 
391
 
// r, g, b, dst_1, dst_2
392
 
PROLOG(yuv2rgb_c_8_ordered_dither, uint8_t)
393
 
        const uint8_t *d32= dither_8x8_32[y&7];
394
 
        const uint8_t *d64= dither_8x8_73[y&7];
395
 
#define DST1bpp8(i,o)                                   \
396
 
        Y = py_1[2*i];                          \
397
 
        dst_1[2*i] = r[Y+d32[0+o]] + g[Y+d32[0+o]] + b[Y+d64[0+o]];     \
398
 
        Y = py_1[2*i+1];                        \
399
 
        dst_1[2*i+1] = r[Y+d32[1+o]] + g[Y+d32[1+o]] + b[Y+d64[1+o]];
400
 
 
401
 
#define DST2bpp8(i,o)                                   \
402
 
        Y = py_2[2*i];                          \
403
 
        dst_2[2*i] =  r[Y+d32[8+o]] + g[Y+d32[8+o]] + b[Y+d64[8+o]];    \
404
 
        Y = py_2[2*i+1];                        \
405
 
        dst_2[2*i+1] =  r[Y+d32[9+o]] + g[Y+d32[9+o]] + b[Y+d64[9+o]];
406
 
 
407
 
 
408
 
        RGB(0);
409
 
        DST1bpp8(0,0);
410
 
        DST2bpp8(0,0);
411
 
 
412
 
        RGB(1);
413
 
        DST2bpp8(1,2);
414
 
        DST1bpp8(1,2);
415
 
 
416
 
        RGB(2);
417
 
        DST1bpp8(2,4);
418
 
        DST2bpp8(2,4);
419
 
 
420
 
        RGB(3);
421
 
        DST2bpp8(3,6);
422
 
        DST1bpp8(3,6);
423
 
EPILOG(8)
424
 
 
425
 
 
426
 
// This is exactly the same code as yuv2rgb_c_32 except for the types of
427
 
// r, g, b, dst_1, dst_2
428
 
PROLOG(yuv2rgb_c_4, uint8_t)
429
 
        int acc;
430
 
#define DST1_4(i)                                       \
431
 
        Y = py_1[2*i];                          \
432
 
        acc = r[Y] + g[Y] + b[Y];       \
433
 
        Y = py_1[2*i+1];                        \
434
 
        acc |= (r[Y] + g[Y] + b[Y])<<4;\
435
 
        dst_1[i] = acc; 
436
 
 
437
 
#define DST2_4(i)                                       \
438
 
        Y = py_2[2*i];                          \
439
 
        acc = r[Y] + g[Y] + b[Y];       \
440
 
        Y = py_2[2*i+1];                        \
441
 
        acc |= (r[Y] + g[Y] + b[Y])<<4;\
442
 
        dst_2[i] = acc; 
443
 
        
444
 
        RGB(0);
445
 
        DST1_4(0);
446
 
        DST2_4(0);
447
 
 
448
 
        RGB(1);
449
 
        DST2_4(1);
450
 
        DST1_4(1);
451
 
 
452
 
        RGB(2);
453
 
        DST1_4(2);
454
 
        DST2_4(2);
455
 
 
456
 
        RGB(3);
457
 
        DST2_4(3);
458
 
        DST1_4(3);
459
 
EPILOG(4)
460
 
 
461
 
PROLOG(yuv2rgb_c_4_ordered_dither, uint8_t)
462
 
        const uint8_t *d64= dither_8x8_73[y&7];
463
 
        const uint8_t *d128=dither_8x8_220[y&7];
464
 
        int acc;
465
 
 
466
 
#define DST1bpp4(i,o)                                   \
467
 
        Y = py_1[2*i];                          \
468
 
        acc = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]];  \
469
 
        Y = py_1[2*i+1];                        \
470
 
        acc |= (r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]])<<4;\
471
 
        dst_1[i]= acc;
472
 
 
473
 
#define DST2bpp4(i,o)                                   \
474
 
        Y = py_2[2*i];                          \
475
 
        acc =  r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]]; \
476
 
        Y = py_2[2*i+1];                        \
477
 
        acc |=  (r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]])<<4;\
478
 
        dst_2[i]= acc;
479
 
 
480
 
 
481
 
        RGB(0);
482
 
        DST1bpp4(0,0);
483
 
        DST2bpp4(0,0);
484
 
 
485
 
        RGB(1);
486
 
        DST2bpp4(1,2);
487
 
        DST1bpp4(1,2);
488
 
 
489
 
        RGB(2);
490
 
        DST1bpp4(2,4);
491
 
        DST2bpp4(2,4);
492
 
 
493
 
        RGB(3);
494
 
        DST2bpp4(3,6);
495
 
        DST1bpp4(3,6);
496
 
EPILOG(4)
497
 
 
498
 
// This is exactly the same code as yuv2rgb_c_32 except for the types of
499
 
// r, g, b, dst_1, dst_2
500
 
PROLOG(yuv2rgb_c_4b, uint8_t)
501
 
        RGB(0);
502
 
        DST1(0);
503
 
        DST2(0);
504
 
 
505
 
        RGB(1);
506
 
        DST2(1);
507
 
        DST1(1);
508
 
 
509
 
        RGB(2);
510
 
        DST1(2);
511
 
        DST2(2);
512
 
 
513
 
        RGB(3);
514
 
        DST2(3);
515
 
        DST1(3);
516
 
EPILOG(8)
517
 
 
518
 
PROLOG(yuv2rgb_c_4b_ordered_dither, uint8_t)
519
 
        const uint8_t *d64= dither_8x8_73[y&7];
520
 
        const uint8_t *d128=dither_8x8_220[y&7];
521
 
 
522
 
#define DST1bpp4b(i,o)                                  \
523
 
        Y = py_1[2*i];                          \
524
 
        dst_1[2*i] = r[Y+d128[0+o]] + g[Y+d64[0+o]] + b[Y+d128[0+o]];   \
525
 
        Y = py_1[2*i+1];                        \
526
 
        dst_1[2*i+1] = r[Y+d128[1+o]] + g[Y+d64[1+o]] + b[Y+d128[1+o]];
527
 
 
528
 
#define DST2bpp4b(i,o)                                  \
529
 
        Y = py_2[2*i];                          \
530
 
        dst_2[2*i] =  r[Y+d128[8+o]] + g[Y+d64[8+o]] + b[Y+d128[8+o]];  \
531
 
        Y = py_2[2*i+1];                        \
532
 
        dst_2[2*i+1] =  r[Y+d128[9+o]] + g[Y+d64[9+o]] + b[Y+d128[9+o]];
533
 
 
534
 
 
535
 
        RGB(0);
536
 
        DST1bpp4b(0,0);
537
 
        DST2bpp4b(0,0);
538
 
 
539
 
        RGB(1);
540
 
        DST2bpp4b(1,2);
541
 
        DST1bpp4b(1,2);
542
 
 
543
 
        RGB(2);
544
 
        DST1bpp4b(2,4);
545
 
        DST2bpp4b(2,4);
546
 
 
547
 
        RGB(3);
548
 
        DST2bpp4b(3,6);
549
 
        DST1bpp4b(3,6);
550
 
EPILOG(8)
551
 
 
552
 
PROLOG(yuv2rgb_c_1_ordered_dither, uint8_t)
553
 
        const uint8_t *d128=dither_8x8_220[y&7];
554
 
        char out_1=0, out_2=0;
555
 
        g= c->table_gU[128] + c->table_gV[128];
556
 
 
557
 
#define DST1bpp1(i,o)                                   \
558
 
        Y = py_1[2*i];                          \
559
 
        out_1+= out_1 + g[Y+d128[0+o]]; \
560
 
        Y = py_1[2*i+1];                        \
561
 
        out_1+= out_1 + g[Y+d128[1+o]];
562
 
 
563
 
#define DST2bpp1(i,o)                                   \
564
 
        Y = py_2[2*i];                          \
565
 
        out_2+= out_2 + g[Y+d128[8+o]]; \
566
 
        Y = py_2[2*i+1];                        \
567
 
        out_2+= out_2 + g[Y+d128[9+o]];
568
 
 
569
 
        DST1bpp1(0,0);
570
 
        DST2bpp1(0,0);
571
 
 
572
 
        DST2bpp1(1,2);
573
 
        DST1bpp1(1,2);
574
 
 
575
 
        DST1bpp1(2,4);
576
 
        DST2bpp1(2,4);
577
 
 
578
 
        DST2bpp1(3,6);
579
 
        DST1bpp1(3,6);
580
 
        
581
 
        dst_1[0]= out_1;
582
 
        dst_2[0]= out_2;
583
 
EPILOG(1)
584
 
 
585
 
SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
586
 
{
587
 
#if defined(HAVE_MMX2) || defined(HAVE_MMX)
588
 
    if(c->flags & SWS_CPU_CAPS_MMX2){
589
 
        switch(c->dstFormat){
590
 
        case PIX_FMT_RGB32: return yuv420_rgb32_MMX2;
591
 
        case PIX_FMT_BGR24: return yuv420_rgb24_MMX2;
592
 
        case PIX_FMT_BGR565: return yuv420_rgb16_MMX2;
593
 
        case PIX_FMT_BGR555: return yuv420_rgb15_MMX2;
594
 
        }
595
 
    }
596
 
    if(c->flags & SWS_CPU_CAPS_MMX){
597
 
        switch(c->dstFormat){
598
 
        case PIX_FMT_RGB32: return yuv420_rgb32_MMX;
599
 
        case PIX_FMT_BGR24: return yuv420_rgb24_MMX;
600
 
        case PIX_FMT_BGR565: return yuv420_rgb16_MMX;
601
 
        case PIX_FMT_BGR555: return yuv420_rgb15_MMX;
602
 
        }
603
 
    }
604
 
#endif
605
 
#ifdef HAVE_MLIB
606
 
    {
607
 
        SwsFunc t= yuv2rgb_init_mlib(c);
608
 
        if(t) return t;
609
 
    }
610
 
#endif
611
 
#ifdef HAVE_ALTIVEC
612
 
    if (c->flags & SWS_CPU_CAPS_ALTIVEC)
613
 
    {
614
 
        SwsFunc t = yuv2rgb_init_altivec(c);
615
 
        if(t) return t;
616
 
    }
617
 
#endif
618
 
 
619
 
    MSG_WARN("No accelerated colorspace conversion found\n");
620
 
 
621
 
    switch(c->dstFormat){
622
 
    case PIX_FMT_BGR32:
623
 
    case PIX_FMT_RGB32: return yuv2rgb_c_32;
624
 
    case PIX_FMT_RGB24: return yuv2rgb_c_24_rgb;
625
 
    case PIX_FMT_BGR24: return yuv2rgb_c_24_bgr;
626
 
    case PIX_FMT_RGB565:
627
 
    case PIX_FMT_BGR565:
628
 
    case PIX_FMT_RGB555:
629
 
    case PIX_FMT_BGR555: return yuv2rgb_c_16;
630
 
    case PIX_FMT_RGB8:
631
 
    case PIX_FMT_BGR8:  return yuv2rgb_c_8_ordered_dither;
632
 
    case PIX_FMT_RGB4:
633
 
    case PIX_FMT_BGR4:  return yuv2rgb_c_4_ordered_dither;
634
 
    case PIX_FMT_RGB4_BYTE:
635
 
    case PIX_FMT_BGR4_BYTE:  return yuv2rgb_c_4b_ordered_dither;
636
 
    case PIX_FMT_MONOBLACK:  return yuv2rgb_c_1_ordered_dither;
637
 
    default:
638
 
        assert(0);
639
 
    }
640
 
    return NULL;
641
 
}
642
 
 
643
 
static int div_round (int dividend, int divisor)
644
 
{
645
 
    if (dividend > 0)
646
 
        return (dividend + (divisor>>1)) / divisor;
647
 
    else
648
 
        return -((-dividend + (divisor>>1)) / divisor);
649
 
}
650
 
 
651
 
int yuv2rgb_c_init_tables (SwsContext *c, const int inv_table[4], int fullRange, int brightness, int contrast, int saturation)
652
 
{  
653
 
    const int isRgb = isBGR(c->dstFormat);
654
 
    const int bpp = fmt_depth(c->dstFormat);
655
 
    int i;
656
 
    uint8_t table_Y[1024];
657
 
    uint32_t *table_32 = 0;
658
 
    uint16_t *table_16 = 0;
659
 
    uint8_t *table_8 = 0;
660
 
    uint8_t *table_332 = 0;
661
 
    uint8_t *table_121 = 0;
662
 
    uint8_t *table_1 = 0;
663
 
    int entry_size = 0;
664
 
    void *table_r = 0, *table_g = 0, *table_b = 0;
665
 
    void *table_start;
666
 
 
667
 
    int64_t crv =  inv_table[0];
668
 
    int64_t cbu =  inv_table[1];
669
 
    int64_t cgu = -inv_table[2];
670
 
    int64_t cgv = -inv_table[3];
671
 
    int64_t cy  = 1<<16;
672
 
    int64_t oy  = 0;
673
 
 
674
 
//printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv);
675
 
    if(!fullRange){
676
 
        cy= (cy*255) / 219;
677
 
        oy= 16<<16;
678
 
    }
679
 
        
680
 
    cy = (cy *contrast             )>>16;
681
 
    crv= (crv*contrast * saturation)>>32;
682
 
    cbu= (cbu*contrast * saturation)>>32;
683
 
    cgu= (cgu*contrast * saturation)>>32;
684
 
    cgv= (cgv*contrast * saturation)>>32;
685
 
//printf("%lld %lld %lld %lld %lld\n", cy, crv, cbu, cgu, cgv);
686
 
    oy -= 256*brightness;
687
 
 
688
 
    for (i = 0; i < 1024; i++) {
689
 
        int j;
690
 
 
691
 
        j= (cy*(((i - 384)<<16) - oy) + (1<<31))>>32;
692
 
        j = (j < 0) ? 0 : ((j > 255) ? 255 : j);
693
 
        table_Y[i] = j;
694
 
    }
695
 
 
696
 
    switch (bpp) {
697
 
    case 32:
698
 
        table_start= table_32 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint32_t));
699
 
 
700
 
        entry_size = sizeof (uint32_t);
701
 
        table_r = table_32 + 197;
702
 
        table_b = table_32 + 197 + 685;
703
 
        table_g = table_32 + 197 + 2*682;
704
 
 
705
 
        for (i = -197; i < 256+197; i++)
706
 
            ((uint32_t *)table_r)[i] = table_Y[i+384] << (isRgb ? 16 : 0);
707
 
        for (i = -132; i < 256+132; i++)
708
 
            ((uint32_t *)table_g)[i] = table_Y[i+384] << 8;
709
 
        for (i = -232; i < 256+232; i++)
710
 
            ((uint32_t *)table_b)[i] = table_Y[i+384] << (isRgb ? 0 : 16);
711
 
        break;
712
 
 
713
 
    case 24:
714
 
        table_start= table_8 = av_malloc ((256 + 2*232) * sizeof (uint8_t));
715
 
 
716
 
        entry_size = sizeof (uint8_t);
717
 
        table_r = table_g = table_b = table_8 + 232;
718
 
 
719
 
        for (i = -232; i < 256+232; i++)
720
 
            ((uint8_t * )table_b)[i] = table_Y[i+384];
721
 
        break;
722
 
 
723
 
    case 15:
724
 
    case 16:
725
 
        table_start= table_16 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint16_t));
726
 
 
727
 
        entry_size = sizeof (uint16_t);
728
 
        table_r = table_16 + 197;
729
 
        table_b = table_16 + 197 + 685;
730
 
        table_g = table_16 + 197 + 2*682;
731
 
 
732
 
        for (i = -197; i < 256+197; i++) {
733
 
            int j = table_Y[i+384] >> 3;
734
 
 
735
 
            if (isRgb)
736
 
                j <<= ((bpp==16) ? 11 : 10);
737
 
 
738
 
            ((uint16_t *)table_r)[i] = j;
739
 
        }
740
 
        for (i = -132; i < 256+132; i++) {
741
 
            int j = table_Y[i+384] >> ((bpp==16) ? 2 : 3);
742
 
 
743
 
            ((uint16_t *)table_g)[i] = j << 5;
744
 
        }
745
 
        for (i = -232; i < 256+232; i++) {
746
 
            int j = table_Y[i+384] >> 3;
747
 
 
748
 
            if (!isRgb)
749
 
                j <<= ((bpp==16) ? 11 : 10);
750
 
 
751
 
            ((uint16_t *)table_b)[i] = j;
752
 
        }
753
 
        break;
754
 
 
755
 
    case 8:
756
 
        table_start= table_332 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
757
 
 
758
 
        entry_size = sizeof (uint8_t);
759
 
        table_r = table_332 + 197;
760
 
        table_b = table_332 + 197 + 685;
761
 
        table_g = table_332 + 197 + 2*682;
762
 
 
763
 
        for (i = -197; i < 256+197; i++) {
764
 
            int j = (table_Y[i+384 - 16] + 18)/36;
765
 
 
766
 
            if (isRgb)
767
 
                j <<= 5;
768
 
 
769
 
            ((uint8_t *)table_r)[i] = j;
770
 
        }
771
 
        for (i = -132; i < 256+132; i++) {
772
 
            int j = (table_Y[i+384 - 16] + 18)/36;
773
 
 
774
 
            if (!isRgb)
775
 
                j <<= 1;
776
 
 
777
 
            ((uint8_t *)table_g)[i] = j << 2;
778
 
        }
779
 
        for (i = -232; i < 256+232; i++) {
780
 
            int j = (table_Y[i+384 - 37] + 43)/85;
781
 
 
782
 
            if (!isRgb)
783
 
                j <<= 6;
784
 
 
785
 
            ((uint8_t *)table_b)[i] = j;
786
 
        }
787
 
        break;
788
 
    case 4:
789
 
    case 4|128:
790
 
        table_start= table_121 = av_malloc ((197 + 2*682 + 256 + 132) * sizeof (uint8_t));
791
 
 
792
 
        entry_size = sizeof (uint8_t);
793
 
        table_r = table_121 + 197;
794
 
        table_b = table_121 + 197 + 685;
795
 
        table_g = table_121 + 197 + 2*682;
796
 
 
797
 
        for (i = -197; i < 256+197; i++) {
798
 
            int j = table_Y[i+384 - 110] >> 7;
799
 
 
800
 
            if (isRgb)
801
 
                j <<= 3;
802
 
 
803
 
            ((uint8_t *)table_r)[i] = j;
804
 
        }
805
 
        for (i = -132; i < 256+132; i++) {
806
 
            int j = (table_Y[i+384 - 37]+ 43)/85;
807
 
 
808
 
            ((uint8_t *)table_g)[i] = j << 1;
809
 
        }
810
 
        for (i = -232; i < 256+232; i++) {
811
 
            int j =table_Y[i+384 - 110] >> 7;
812
 
 
813
 
            if (!isRgb)
814
 
                j <<= 3;
815
 
 
816
 
            ((uint8_t *)table_b)[i] = j;
817
 
        }
818
 
        break;
819
 
 
820
 
    case 1:
821
 
        table_start= table_1 = av_malloc (256*2 * sizeof (uint8_t));
822
 
 
823
 
        entry_size = sizeof (uint8_t);
824
 
        table_g = table_1;
825
 
        table_r = table_b = NULL;
826
 
 
827
 
        for (i = 0; i < 256+256; i++) {
828
 
            int j = table_Y[i + 384 - 110]>>7;
829
 
 
830
 
            ((uint8_t *)table_g)[i] = j;
831
 
        }
832
 
        break;
833
 
 
834
 
    default:
835
 
        table_start= NULL;
836
 
        MSG_ERR("%ibpp not supported by yuv2rgb\n", bpp);
837
 
        //free mem?
838
 
        return -1;
839
 
    }
840
 
 
841
 
    for (i = 0; i < 256; i++) {
842
 
        c->table_rV[i] = table_r + entry_size * div_round (crv * (i-128), 76309);
843
 
        c->table_gU[i] = table_g + entry_size * div_round (cgu * (i-128), 76309);
844
 
        c->table_gV[i] = entry_size * div_round (cgv * (i-128), 76309);
845
 
        c->table_bU[i] = table_b + entry_size * div_round (cbu * (i-128), 76309);
846
 
    }
847
 
 
848
 
    av_free(c->yuvTable);
849
 
    c->yuvTable= table_start;
850
 
    return 0;
851
 
}