1 /* babl - dynamically extendable universal pixel conversion library.
2 * Copyright (C) 2013 Daniel Sabo
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General
15 * Public License along with this library; if not, see
16 * <https://www.gnu.org/licenses/>.
21 #if defined(USE_SSE4_1)
24 #include <smmintrin.h>
30 #include "babl-cpuaccel.h"
31 #include "extensions/util.h"
34 conv_y8_yF (const Babl
*conversion
,
39 const float factor
= 1.0f
/ 255.0f
;
40 const __v4sf factor_vec
= {1.0f
/ 255.0f
, 1.0f
/ 255.0f
, 1.0f
/ 255.0f
, 1.0f
/ 255.0f
};
41 const uint32_t *s_vec
;
46 s_vec
= (const uint32_t *)src
;
47 d_vec
= (__v4sf
*)dst
;
53 in_val
= _mm_insert_epi32 ((__m128i
)_mm_setzero_ps(), *s_vec
++, 0);
54 in_val
= _mm_cvtepu8_epi32 (in_val
);
55 out_val
= _mm_cvtepi32_ps (in_val
) * factor_vec
;
56 _mm_storeu_ps ((float *)d_vec
++, out_val
);
60 src
= (const uint8_t *)s_vec
;
65 *dst
++ = (float)(*src
++) * factor
;
71 conv_ya8_yaF (const Babl
*conversion
,
76 conv_y8_yF (conversion
, src
, dst
, samples
* 2);
80 conv_rgb8_rgbF (const Babl
*conversion
,
85 conv_y8_yF (conversion
, src
, dst
, samples
* 3);
89 conv_rgba8_rgbaF (const Babl
*conversion
,
94 conv_y8_yF (conversion
, src
, dst
, samples
* 4);
104 #if defined(USE_SSE4_1)
105 const Babl
*rgbaF_linear
= babl_format_new (
108 babl_component ("R"),
109 babl_component ("G"),
110 babl_component ("B"),
111 babl_component ("A"),
113 const Babl
*rgba8_linear
= babl_format_new (
116 babl_component ("R"),
117 babl_component ("G"),
118 babl_component ("B"),
119 babl_component ("A"),
121 const Babl
*rgbaF_gamma
= babl_format_new (
122 babl_model ("R'G'B'A"),
124 babl_component ("R'"),
125 babl_component ("G'"),
126 babl_component ("B'"),
127 babl_component ("A"),
129 const Babl
*rgba8_gamma
= babl_format_new (
130 babl_model ("R'G'B'A"),
132 babl_component ("R'"),
133 babl_component ("G'"),
134 babl_component ("B'"),
135 babl_component ("A"),
137 const Babl
*rgbF_linear
= babl_format_new (
140 babl_component ("R"),
141 babl_component ("G"),
142 babl_component ("B"),
144 const Babl
*rgb8_linear
= babl_format_new (
147 babl_component ("R"),
148 babl_component ("G"),
149 babl_component ("B"),
151 const Babl
*rgbF_gamma
= babl_format_new (
152 babl_model ("R'G'B'"),
154 babl_component ("R'"),
155 babl_component ("G'"),
156 babl_component ("B'"),
158 const Babl
*rgb8_gamma
= babl_format_new (
159 babl_model ("R'G'B'"),
161 babl_component ("R'"),
162 babl_component ("G'"),
163 babl_component ("B'"),
165 const Babl
*yaF_linear
= babl_format_new (
168 babl_component ("Y"),
169 babl_component ("A"),
171 const Babl
*ya8_linear
= babl_format_new (
174 babl_component ("Y"),
175 babl_component ("A"),
177 const Babl
*yaF_gamma
= babl_format_new (
180 babl_component ("Y'"),
181 babl_component ("A"),
183 const Babl
*ya8_gamma
= babl_format_new (
186 babl_component ("Y'"),
187 babl_component ("A"),
189 const Babl
*yF_linear
= babl_format_new (
192 babl_component ("Y"),
194 const Babl
*y8_linear
= babl_format_new (
197 babl_component ("Y"),
199 const Babl
*yF_gamma
= babl_format_new (
202 babl_component ("Y'"),
204 const Babl
*y8_gamma
= babl_format_new (
207 babl_component ("Y'"),
210 #define CONV(src, dst) \
212 babl_conversion_new (src ## _linear, dst ## _linear, "linear", conv_ ## src ## _ ## dst, NULL); \
213 babl_conversion_new (src ## _gamma, dst ## _gamma, "linear", conv_ ## src ## _ ## dst, NULL); \
216 if ((babl_cpu_accel_get_support () & BABL_CPU_ACCEL_X86_SSE4_1
))