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(void *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
= (float *)((uint8_t *)dst_row
+ (y
+ j
)*dst_stride
+ (x
+ i
)*16);
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(void *in_dst
, const uint8_t *src
, unsigned i
, unsigned j
)
96 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 1);
99 dst
[2] = ubyte_to_float(tmp_r
);
104 util_format_latc1_snorm_fetch_rgba_8unorm(UNUSED
uint8_t *dst
, UNUSED
const uint8_t *src
,
105 UNUSED
unsigned i
, UNUSED
unsigned j
)
107 fprintf(stderr
,"%s\n", __func__
);
111 util_format_latc1_snorm_unpack_rgba_8unorm(UNUSED
uint8_t *dst_row
, UNUSED
unsigned dst_stride
,
112 UNUSED
const uint8_t *src_row
, UNUSED
unsigned src_stride
,
113 UNUSED
unsigned width
, UNUSED
unsigned height
)
115 fprintf(stderr
,"%s\n", __func__
);
119 util_format_latc1_snorm_pack_rgba_8unorm(UNUSED
uint8_t *dst_row
, UNUSED
unsigned dst_stride
,
120 UNUSED
const uint8_t *src_row
, UNUSED
unsigned src_stride
,
121 UNUSED
unsigned width
, UNUSED
unsigned height
)
123 fprintf(stderr
,"%s\n", __func__
);
127 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
)
129 util_format_rgtc1_snorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
133 util_format_latc1_snorm_unpack_rgba_float(void *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
138 for(y
= 0; y
< height
; y
+= 4) {
139 const int8_t *src
= (int8_t *)src_row
;
140 for(x
= 0; x
< width
; x
+= 4) {
141 for(j
= 0; j
< 4; ++j
) {
142 for(i
= 0; i
< 4; ++i
) {
143 float *dst
= (float *)((uint8_t *)dst_row
+ (y
+ j
)*dst_stride
+ (x
+ i
)*16);
145 util_format_signed_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 1);
148 dst
[2] = byte_to_float_tex(tmp_r
);
154 src_row
+= src_stride
;
159 util_format_latc1_snorm_fetch_rgba(void *in_dst
, const uint8_t *src
, unsigned i
, unsigned j
)
164 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
, i
, j
, &tmp_r
, 1);
167 dst
[2] = byte_to_float_tex(tmp_r
);
173 util_format_latc2_unorm_fetch_rgba_8unorm(uint8_t *dst
, const uint8_t *src
, unsigned i
, unsigned j
)
175 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, dst
, 2);
178 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, dst
+ 3, 2);
182 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
)
184 util_format_rgtc2_unorm_unpack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
188 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
)
190 util_format_rgtc2_unorm_pack_rgba_8unorm(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
);
194 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
)
196 util_format_rxtc2_unorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
, 3);
200 util_format_latc2_unorm_unpack_rgba_float(void *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
205 for(y
= 0; y
< height
; y
+= 4) {
206 const uint8_t *src
= src_row
;
207 for(x
= 0; x
< width
; x
+= 4) {
208 for(j
= 0; j
< 4; ++j
) {
209 for(i
= 0; i
< 4; ++i
) {
210 float *dst
= (float *)((uint8_t *)dst_row
+ (y
+ j
)*dst_stride
+ (x
+ i
)*16);
211 uint8_t tmp_r
, tmp_g
;
212 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
213 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
216 dst
[2] = ubyte_to_float(tmp_r
);
217 dst
[3] = ubyte_to_float(tmp_g
);
222 src_row
+= src_stride
;
227 util_format_latc2_unorm_fetch_rgba(void *in_dst
, const uint8_t *src
, unsigned i
, unsigned j
)
230 uint8_t tmp_r
, tmp_g
;
232 util_format_unsigned_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
233 util_format_unsigned_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
236 dst
[2] = ubyte_to_float(tmp_r
);
237 dst
[3] = ubyte_to_float(tmp_g
);
242 util_format_latc2_snorm_fetch_rgba_8unorm(UNUSED
uint8_t *dst
, UNUSED
const uint8_t *src
,
243 UNUSED
unsigned i
, UNUSED
unsigned j
)
245 fprintf(stderr
,"%s\n", __func__
);
249 util_format_latc2_snorm_unpack_rgba_8unorm(UNUSED
uint8_t *dst_row
, UNUSED
unsigned dst_stride
,
250 UNUSED
const uint8_t *src_row
, UNUSED
unsigned src_stride
,
251 UNUSED
unsigned width
, UNUSED
unsigned height
)
253 fprintf(stderr
,"%s\n", __func__
);
257 util_format_latc2_snorm_pack_rgba_8unorm(UNUSED
uint8_t *dst_row
, UNUSED
unsigned dst_stride
,
258 UNUSED
const uint8_t *src_row
, UNUSED
unsigned src_stride
,
259 UNUSED
unsigned width
, UNUSED
unsigned height
)
261 fprintf(stderr
,"%s\n", __func__
);
265 util_format_latc2_snorm_unpack_rgba_float(void *dst_row
, unsigned dst_stride
, const uint8_t *src_row
, unsigned src_stride
, unsigned width
, unsigned height
)
270 for(y
= 0; y
< height
; y
+= 4) {
271 const int8_t *src
= (int8_t *)src_row
;
272 for(x
= 0; x
< width
; x
+= 4) {
273 for(j
= 0; j
< 4; ++j
) {
274 for(i
= 0; i
< 4; ++i
) {
275 float *dst
= (float *)(uint8_t *)dst_row
+ (y
+ j
)*dst_stride
+ (x
+ i
)*16;
277 util_format_signed_fetch_texel_rgtc(0, src
, i
, j
, &tmp_r
, 2);
278 util_format_signed_fetch_texel_rgtc(0, src
+ 8, i
, j
, &tmp_g
, 2);
281 dst
[2] = byte_to_float_tex(tmp_r
);
282 dst
[3] = byte_to_float_tex(tmp_g
);
287 src_row
+= src_stride
;
292 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
)
294 util_format_rxtc2_snorm_pack_rgba_float(dst_row
, dst_stride
, src_row
, src_stride
, width
, height
, 3);
298 util_format_latc2_snorm_fetch_rgba(void *in_dst
, const uint8_t *src
, unsigned i
, unsigned j
)
303 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
, i
, j
, &tmp_r
, 2);
304 util_format_signed_fetch_texel_rgtc(0, (int8_t *)src
+ 8, i
, j
, &tmp_g
, 2);
307 dst
[2] = byte_to_float_tex(tmp_r
);
308 dst
[3] = byte_to_float_tex(tmp_g
);