1 /**************************************************************************
3 * Copyright (C) 2011 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 **************************************************************************/
26 #include "util/format/u_format.h"
27 #include "util/format/u_format_rgtc.h"
28 #include "util/format/u_format_latc.h"
29 #include "util/rgtc.h"
30 #include "util/u_math.h"
33 util_format_latc1_unorm_fetch_rgba_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
35 /* Fix warnings here: */
36 (void) util_format_unsigned_encode_rgtc_ubyte
;
37 (void) util_format_signed_encode_rgtc_ubyte
;
39 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, dst
, 1);
46 util_format_latc1_unorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
48 util_format_rgtc1_unorm_unpack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
52 util_format_latc1_unorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
,
53 unsigned src_stride
, unsigned width
, unsigned height
)
55 util_format_rgtc1_unorm_pack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
59 util_format_latc1_unorm_unpack_rgba_float(float *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
64 for(y
= 0; y
< height
; y
+= 4) {
65 const uint8_t *src
= src_row
;
66 for(x
= 0; x
< width
; x
+= 4) {
67 for(j
= 0; j
< 4; ++j
) {
68 for(i
= 0; i
< 4; ++i
) {
69 float *dst
= dst_row
+ (y
+ j
)*dst_stride
/sizeof(*dst_row
) + (x
+ i
)*4;
71 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 1);
74 dst
[2] = ubyte_to_float(tmp_r
);
80 src_row
+= src_stride
;
85 util_format_latc1_unorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
, const float *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
87 util_format_rgtc1_unorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
91 util_format_latc1_unorm_fetch_rgba_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
95 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 1);
98 dst
[2] = ubyte_to_float(tmp_r
);
103 util_format_latc1_snorm_fetch_rgba_8unorm(UNUSED
uint8_t *dst
, UNUSED
const uint8_t *src
,
104 UNUSED
unsigned i
, UNUSED
unsigned j
)
106 fprintf(stderr
,"%s\n", __func__
);
110 util_format_latc1_snorm_unpack_rgba_8unorm(UNUSED
uint8_t *dst_row
, UNUSED
unsigned dst_stride
,
111 UNUSED
const uint8_t *src_row
, UNUSED
unsigned src_stride
,
112 UNUSED
unsigned width
, UNUSED
unsigned height
)
114 fprintf(stderr
,"%s\n", __func__
);
118 util_format_latc1_snorm_pack_rgba_8unorm(UNUSED
uint8_t *dst_row
, UNUSED
unsigned dst_stride
,
119 UNUSED
const uint8_t *src_row
, UNUSED
unsigned src_stride
,
120 UNUSED
unsigned width
, UNUSED
unsigned height
)
122 fprintf(stderr
,"%s\n", __func__
);
126 util_format_latc1_snorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
, const float *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
128 util_format_rgtc1_snorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
132 util_format_latc1_snorm_unpack_rgba_float(float *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
137 for(y
= 0; y
< height
; y
+= 4) {
138 const int8_t *src
= (int8_t *)src_row
;
139 for(x
= 0; x
< width
; x
+= 4) {
140 for(j
= 0; j
< 4; ++j
) {
141 for(i
= 0; i
< 4; ++i
) {
142 float *dst
= dst_row
+ (y
+ j
)*dst_stride
/sizeof(*dst_row
) + (x
+ i
)*4;
144 util_format_signed_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 1);
147 dst
[2] = byte_to_float_tex(tmp_r
);
153 src_row
+= src_stride
;
158 util_format_latc1_snorm_fetch_rgba_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
162 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
, i
, j
, &tmp_r
, 1);
165 dst
[2] = byte_to_float_tex(tmp_r
);
171 util_format_latc2_unorm_fetch_rgba_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
173 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, dst
, 2);
176 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, dst
+ 3, 2);
180 util_format_latc2_unorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
182 util_format_rgtc2_unorm_unpack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
186 util_format_latc2_unorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
188 util_format_rgtc2_unorm_pack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
192 util_format_latc2_unorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
, const float *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
194 util_format_rxtc2_unorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
, 3);
198 util_format_latc2_unorm_unpack_rgba_float(float *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
203 for(y
= 0; y
< height
; y
+= 4) {
204 const uint8_t *src
= src_row
;
205 for(x
= 0; x
< width
; x
+= 4) {
206 for(j
= 0; j
< 4; ++j
) {
207 for(i
= 0; i
< 4; ++i
) {
208 float *dst
= dst_row
+ (y
+ j
)*dst_stride
/sizeof(*dst_row
) + (x
+ i
)*4;
209 uint8_t tmp_r
, tmp_g
;
210 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
211 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
214 dst
[2] = ubyte_to_float(tmp_r
);
215 dst
[3] = ubyte_to_float(tmp_g
);
220 src_row
+= src_stride
;
225 util_format_latc2_unorm_fetch_rgba_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
227 uint8_t tmp_r
, tmp_g
;
229 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
230 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
233 dst
[2] = ubyte_to_float(tmp_r
);
234 dst
[3] = ubyte_to_float(tmp_g
);
239 util_format_latc2_snorm_fetch_rgba_8unorm(UNUSED
uint8_t *dst
, UNUSED
const uint8_t *src
,
240 UNUSED
unsigned i
, UNUSED
unsigned j
)
242 fprintf(stderr
,"%s\n", __func__
);
246 util_format_latc2_snorm_unpack_rgba_8unorm(UNUSED
uint8_t *dst_row
, UNUSED
unsigned dst_stride
,
247 UNUSED
const uint8_t *src_row
, UNUSED
unsigned src_stride
,
248 UNUSED
unsigned width
, UNUSED
unsigned height
)
250 fprintf(stderr
,"%s\n", __func__
);
254 util_format_latc2_snorm_pack_rgba_8unorm(UNUSED
uint8_t *dst_row
, UNUSED
unsigned dst_stride
,
255 UNUSED
const uint8_t *src_row
, UNUSED
unsigned src_stride
,
256 UNUSED
unsigned width
, UNUSED
unsigned height
)
258 fprintf(stderr
,"%s\n", __func__
);
262 util_format_latc2_snorm_unpack_rgba_float(float *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
267 for(y
= 0; y
< height
; y
+= 4) {
268 const int8_t *src
= (int8_t *)src_row
;
269 for(x
= 0; x
< width
; x
+= 4) {
270 for(j
= 0; j
< 4; ++j
) {
271 for(i
= 0; i
< 4; ++i
) {
272 float *dst
= dst_row
+ (y
+ j
)*dst_stride
/sizeof(*dst_row
) + (x
+ i
)*4;
274 util_format_signed_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
275 util_format_signed_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
278 dst
[2] = byte_to_float_tex(tmp_r
);
279 dst
[3] = byte_to_float_tex(tmp_g
);
284 src_row
+= src_stride
;
289 util_format_latc2_snorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
, const float *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
291 util_format_rxtc2_snorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
, 3);
295 util_format_latc2_snorm_fetch_rgba_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
299 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
, i
, j
, &tmp_r
, 2);
300 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
+ 8, i
, j
, &tmp_g
, 2);
303 dst
[2] = byte_to_float_tex(tmp_r
);
304 dst
[3] = byte_to_float_tex(tmp_g
);