sl@0
|
1 |
/*
|
sl@0
|
2 |
* LIBOIL - Library of Optimized Inner Loops
|
sl@0
|
3 |
* Copyright (c) 2003,2004 David A. Schleef <ds@schleef.org>
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
7 |
* modification, are permitted provided that the following conditions
|
sl@0
|
8 |
* are met:
|
sl@0
|
9 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
10 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
11 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
13 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
sl@0
|
16 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
sl@0
|
17 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
sl@0
|
19 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
sl@0
|
20 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
sl@0
|
21 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
23 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
sl@0
|
24 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
sl@0
|
25 |
* POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
26 |
*/
|
sl@0
|
27 |
//Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
sl@0
|
28 |
|
sl@0
|
29 |
#ifdef HAVE_CONFIG_H
|
sl@0
|
30 |
#include "config.h"
|
sl@0
|
31 |
#endif
|
sl@0
|
32 |
|
sl@0
|
33 |
#include "liboil/liboil.h"
|
sl@0
|
34 |
#include "liboilfunction.h"
|
sl@0
|
35 |
#include "liboil/liboilcolorspace.h"
|
sl@0
|
36 |
#include "liboil/liboiltest.h"
|
sl@0
|
37 |
#include <string.h>
|
sl@0
|
38 |
|
sl@0
|
39 |
/**
|
sl@0
|
40 |
* oil_ayuv2argb_u8:
|
sl@0
|
41 |
* @d_4xn:
|
sl@0
|
42 |
* @s_4xn:
|
sl@0
|
43 |
* @n:
|
sl@0
|
44 |
*
|
sl@0
|
45 |
* Converts AYUV pixels to ARGB pixels. AYUV pixels are in the
|
sl@0
|
46 |
* JPEG colorspace. Note that this function doesn't follow normal
|
sl@0
|
47 |
* liboil pixel conventions.
|
sl@0
|
48 |
*
|
sl@0
|
49 |
* (This function should be replaced by one that handles other
|
sl@0
|
50 |
* conversion factors.)
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
OIL_DEFINE_CLASS (ayuv2argb_u8, "uint8_t *d_4xn, uint8_t *s_4xn, int n");
|
sl@0
|
53 |
|
sl@0
|
54 |
|
sl@0
|
55 |
#define clamp(x,a,b) clamp_lower(clamp_upper(x,b),a)
|
sl@0
|
56 |
#define clamp_lower(x,a) ((x<a)?(a):(x))
|
sl@0
|
57 |
#define clamp_upper(x,b) ((x>b)?(b):(x))
|
sl@0
|
58 |
|
sl@0
|
59 |
/* from the JFIF spec */
|
sl@0
|
60 |
#define YUV_TO_R(y,u,v) clamp((y) + 1.402*((v)-128.0),0,255)
|
sl@0
|
61 |
#define YUV_TO_G(y,u,v) clamp((y) - 0.34414*((u)-128.0) - 0.71414*((v)-128.0),0,255)
|
sl@0
|
62 |
#define YUV_TO_B(y,u,v) clamp((y) + 1.772*((u)-128.0),0,255)
|
sl@0
|
63 |
|
sl@0
|
64 |
#define muldiv256(x,y) (((x)*(y) + 128)>>8)
|
sl@0
|
65 |
#define YUV_TO_R_INT8(y,u,v) clamp((y) + muldiv256(359,(v)-128),0,255)
|
sl@0
|
66 |
#define YUV_TO_G_INT8(y,u,v) clamp((y) + muldiv256(-88,(u)-128) + muldiv256(-183,(v)-128),0,255)
|
sl@0
|
67 |
#define YUV_TO_B_INT8(y,u,v) clamp((y) + muldiv256(454,(u)-128),0,255)
|
sl@0
|
68 |
|
sl@0
|
69 |
#define muldiv65536(x,y) (((x)*(y) + 32768)>>16)
|
sl@0
|
70 |
#define YUV_TO_R_INT16(y,u,v) clamp((y) + muldiv65536(91881,(v)-128),0,255)
|
sl@0
|
71 |
#define YUV_TO_G_INT16(y,u,v) clamp((y) - muldiv65536(22554,(u)-128) - muldiv65536(46802,(v)-128),0,255)
|
sl@0
|
72 |
#define YUV_TO_B_INT16(y,u,v) clamp((y) + muldiv65536(116130,(u)-128),0,255)
|
sl@0
|
73 |
|
sl@0
|
74 |
|
sl@0
|
75 |
#define SHIFT 6
|
sl@0
|
76 |
#define MULT (1<<6)
|
sl@0
|
77 |
#define X(x) ((int)((x)*(1<<(SHIFT+8)) + 0.5))
|
sl@0
|
78 |
static int16_t jfif_matrix[][4] = {
|
sl@0
|
79 |
{ 0, 0, -8192, -8192 },
|
sl@0
|
80 |
{ 16384, 0, 0, 0 },
|
sl@0
|
81 |
{ 0, 16384, 16384, 16384 },
|
sl@0
|
82 |
{ 0, 0, -5638, 29032 },
|
sl@0
|
83 |
{ 0, 22970, -11700, 0 },
|
sl@0
|
84 |
{ 0, 0, 0, 0 }
|
sl@0
|
85 |
};
|
sl@0
|
86 |
|
sl@0
|
87 |
static void
|
sl@0
|
88 |
colorspace_argb_test (OilTest *test)
|
sl@0
|
89 |
{
|
sl@0
|
90 |
int16_t *data = oil_test_get_source_data (test, OIL_ARG_SRC2);
|
sl@0
|
91 |
|
sl@0
|
92 |
memcpy (data, jfif_matrix, 4*2*6);
|
sl@0
|
93 |
}
|
sl@0
|
94 |
|
sl@0
|
95 |
OIL_DEFINE_CLASS_FULL (colorspace_argb, "uint32_t *d, uint32_t *s, int16_t *s2_24, int n", colorspace_argb_test);
|
sl@0
|
96 |
|
sl@0
|
97 |
static void
|
sl@0
|
98 |
colorspace_argb_ref (uint32_t *dest, const uint32_t *src, const int16_t *matrix, int n)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
int i;
|
sl@0
|
101 |
|
sl@0
|
102 |
for(i=0;i<n;i++){
|
sl@0
|
103 |
int sa = (oil_argb_A(src[i])<<SHIFT) + matrix[0*4+0];
|
sl@0
|
104 |
int sr = (oil_argb_R(src[i])<<SHIFT) + matrix[0*4+1];
|
sl@0
|
105 |
int sg = (oil_argb_G(src[i])<<SHIFT) + matrix[0*4+2];
|
sl@0
|
106 |
int sb = (oil_argb_B(src[i])<<SHIFT) + matrix[0*4+3];
|
sl@0
|
107 |
int da, dr, dg, db;
|
sl@0
|
108 |
|
sl@0
|
109 |
#define MUL(a,b) (((a)*(b))>>16)
|
sl@0
|
110 |
da = (MUL(sa,matrix[1*4+0]) + MUL(sr,matrix[2*4+0]) + MUL(sg,matrix[3*4+0]) +
|
sl@0
|
111 |
MUL(sb,matrix[4*4+0]) + matrix[5*4+0] + 8)>>(2*SHIFT - 8);
|
sl@0
|
112 |
dr = (MUL(sa,matrix[1*4+1]) + MUL(sr,matrix[2*4+1]) + MUL(sg,matrix[3*4+1]) +
|
sl@0
|
113 |
MUL(sb,matrix[4*4+1]) + matrix[5*4+1] + 8)>>(2*SHIFT - 8);
|
sl@0
|
114 |
dg = (MUL(sa,matrix[1*4+2]) + MUL(sr,matrix[2*4+2]) + MUL(sg,matrix[3*4+2]) +
|
sl@0
|
115 |
MUL(sb,matrix[4*4+2]) + matrix[5*4+2] + 8)>>(2*SHIFT - 8);
|
sl@0
|
116 |
db = (MUL(sa,matrix[1*4+3]) + MUL(sr,matrix[2*4+3]) + MUL(sg,matrix[3*4+3]) +
|
sl@0
|
117 |
MUL(sb,matrix[4*4+3]) + matrix[5*4+3] + 8)>>(2*SHIFT - 8);
|
sl@0
|
118 |
dest[i] = oil_argb(da, dr, dg, db);
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
}
|
sl@0
|
122 |
OIL_DEFINE_IMPL_REF (colorspace_argb_ref, colorspace_argb);
|
sl@0
|
123 |
|
sl@0
|
124 |
|
sl@0
|
125 |
static void
|
sl@0
|
126 |
ayuv2argb_u8_ref (uint8_t *argb, const uint8_t *ayuv, int n)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
int i;
|
sl@0
|
129 |
|
sl@0
|
130 |
for(i=0;i<n;i++){
|
sl@0
|
131 |
argb[0] = ayuv[0];
|
sl@0
|
132 |
argb[1] = YUV_TO_R_INT8(ayuv[1], ayuv[2], ayuv[3]);
|
sl@0
|
133 |
argb[2] = YUV_TO_G_INT8(ayuv[1], ayuv[2], ayuv[3]);
|
sl@0
|
134 |
argb[3] = YUV_TO_B_INT8(ayuv[1], ayuv[2], ayuv[3]);
|
sl@0
|
135 |
argb+=4;
|
sl@0
|
136 |
ayuv+=4;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
}
|
sl@0
|
140 |
OIL_DEFINE_IMPL_REF (ayuv2argb_u8_ref, ayuv2argb_u8);
|
sl@0
|
141 |
|
sl@0
|
142 |
|
sl@0
|
143 |
|
sl@0
|
144 |
|
sl@0
|
145 |
#ifdef __SYMBIAN32__
|
sl@0
|
146 |
|
sl@0
|
147 |
OilFunctionClass* __oil_function_class_ayuv2argb_u8() {
|
sl@0
|
148 |
return &_oil_function_class_ayuv2argb_u8;
|
sl@0
|
149 |
}
|
sl@0
|
150 |
#endif
|
sl@0
|
151 |
|
sl@0
|
152 |
#ifdef __SYMBIAN32__
|
sl@0
|
153 |
|
sl@0
|
154 |
OilFunctionClass* __oil_function_class_colorspace_argb() {
|
sl@0
|
155 |
return &_oil_function_class_colorspace_argb;
|
sl@0
|
156 |
}
|
sl@0
|
157 |
#endif
|
sl@0
|
158 |
|
sl@0
|
159 |
|
sl@0
|
160 |
|
sl@0
|
161 |
#ifdef __SYMBIAN32__
|
sl@0
|
162 |
|
sl@0
|
163 |
OilFunctionImpl* __oil_function_impl_colorspace_argb_ref() {
|
sl@0
|
164 |
return &_oil_function_impl_colorspace_argb_ref;
|
sl@0
|
165 |
}
|
sl@0
|
166 |
#endif
|
sl@0
|
167 |
|
sl@0
|
168 |
#ifdef __SYMBIAN32__
|
sl@0
|
169 |
|
sl@0
|
170 |
OilFunctionImpl* __oil_function_impl_ayuv2argb_u8_ref() {
|
sl@0
|
171 |
return &_oil_function_impl_ayuv2argb_u8_ref;
|
sl@0
|
172 |
}
|
sl@0
|
173 |
#endif
|
sl@0
|
174 |
|
sl@0
|
175 |
|
sl@0
|
176 |
|
sl@0
|
177 |
#ifdef __SYMBIAN32__
|
sl@0
|
178 |
|
sl@0
|
179 |
EXPORT_C void** _oil_function_class_ptr_ayuv2argb_u8 () {
|
sl@0
|
180 |
oil_function_class_ptr_ayuv2argb_u8 = __oil_function_class_ayuv2argb_u8();
|
sl@0
|
181 |
return &oil_function_class_ptr_ayuv2argb_u8->func;
|
sl@0
|
182 |
}
|
sl@0
|
183 |
#endif
|
sl@0
|
184 |
|
sl@0
|
185 |
#ifdef __SYMBIAN32__
|
sl@0
|
186 |
|
sl@0
|
187 |
EXPORT_C void** _oil_function_class_ptr_colorspace_argb () {
|
sl@0
|
188 |
oil_function_class_ptr_colorspace_argb = __oil_function_class_colorspace_argb();
|
sl@0
|
189 |
return &oil_function_class_ptr_colorspace_argb->func;
|
sl@0
|
190 |
}
|
sl@0
|
191 |
#endif
|
sl@0
|
192 |
|