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 **************************************************************************/
28 #include "u_format_rgtc.h"
29 #include "u_format_latc.h"
30 #include "util/rgtc.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(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
105 fprintf(stderr
,"%s\n", __func__
);
109 util_format_latc1_snorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
111 fprintf(stderr
,"%s\n", __func__
);
115 util_format_latc1_snorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
117 fprintf(stderr
,"%s\n", __func__
);
121 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
)
123 util_format_rgtc1_snorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
127 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
)
132 for(y
= 0; y
< height
; y
+= 4) {
133 const int8_t *src
= (int8_t *)src_row
;
134 for(x
= 0; x
< width
; x
+= 4) {
135 for(j
= 0; j
< 4; ++j
) {
136 for(i
= 0; i
< 4; ++i
) {
137 float *dst
= dst_row
+ (y
+ j
)*dst_stride
/sizeof(*dst_row
) + (x
+ i
)*4;
139 util_format_signed_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 1);
142 dst
[2] = byte_to_float_tex(tmp_r
);
148 src_row
+= src_stride
;
153 util_format_latc1_snorm_fetch_rgba_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
157 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
, i
, j
, &tmp_r
, 1);
160 dst
[2] = byte_to_float_tex(tmp_r
);
166 util_format_latc2_unorm_fetch_rgba_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
168 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, dst
, 2);
171 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, dst
+ 3, 2);
175 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
)
177 util_format_rgtc2_unorm_unpack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
181 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
)
183 util_format_rgtc2_unorm_pack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
187 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
)
189 util_format_rxtc2_unorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
, 3);
193 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
)
198 for(y
= 0; y
< height
; y
+= 4) {
199 const uint8_t *src
= src_row
;
200 for(x
= 0; x
< width
; x
+= 4) {
201 for(j
= 0; j
< 4; ++j
) {
202 for(i
= 0; i
< 4; ++i
) {
203 float *dst
= dst_row
+ (y
+ j
)*dst_stride
/sizeof(*dst_row
) + (x
+ i
)*4;
204 uint8_t tmp_r
, tmp_g
;
205 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
206 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
209 dst
[2] = ubyte_to_float(tmp_r
);
210 dst
[3] = ubyte_to_float(tmp_g
);
215 src_row
+= src_stride
;
220 util_format_latc2_unorm_fetch_rgba_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
222 uint8_t tmp_r
, tmp_g
;
224 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
225 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
228 dst
[2] = ubyte_to_float(tmp_r
);
229 dst
[3] = ubyte_to_float(tmp_g
);
234 util_format_latc2_snorm_fetch_rgba_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
236 fprintf(stderr
,"%s\n", __func__
);
240 util_format_latc2_snorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
242 fprintf(stderr
,"%s\n", __func__
);
246 util_format_latc2_snorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
248 fprintf(stderr
,"%s\n", __func__
);
252 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
)
257 for(y
= 0; y
< height
; y
+= 4) {
258 const int8_t *src
= (int8_t *)src_row
;
259 for(x
= 0; x
< width
; x
+= 4) {
260 for(j
= 0; j
< 4; ++j
) {
261 for(i
= 0; i
< 4; ++i
) {
262 float *dst
= dst_row
+ (y
+ j
)*dst_stride
/sizeof(*dst_row
) + (x
+ i
)*4;
264 util_format_signed_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
265 util_format_signed_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
268 dst
[2] = byte_to_float_tex(tmp_r
);
269 dst
[3] = byte_to_float_tex(tmp_g
);
274 src_row
+= src_stride
;
279 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
)
281 util_format_rxtc2_snorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
, 3);
285 util_format_latc2_snorm_fetch_rgba_float(float *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
289 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
, i
, j
, &tmp_r
, 2);
290 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
+ 8, i
, j
, &tmp_g
, 2);
293 dst
[2] = byte_to_float_tex(tmp_r
);
294 dst
[3] = byte_to_float_tex(tmp_g
);