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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 **************************************************************************/
27 #include "u_format_rgtc.h"
28 #include "u_format_latc.h"
30 static void u_format_unsigned_encode_rgtc_chan(uint8_t *blkaddr, uint8_t srccolors[4][4],
31 int numxpixels, int numypixels);
33 static void u_format_unsigned_fetch_texel_rgtc(unsigned srcRowStride, const uint8_t *pixdata,
34 unsigned i, unsigned j, uint8_t *value, unsigned comps);
36 static void u_format_signed_encode_rgtc_chan(int8_t *blkaddr, int8_t srccolors[4][4],
37 int numxpixels, int numypixels);
39 static void u_format_signed_fetch_texel_rgtc(unsigned srcRowStride, const int8_t *pixdata,
40 unsigned i, unsigned j, int8_t *value, unsigned comps);
43 util_format_latc1_unorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
45 /* Fix warnings here: */
46 (void) u_format_unsigned_encode_rgtc_chan;
47 (void) u_format_signed_encode_rgtc_chan;
49 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 1);
53 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)
55 util_format_rgtc1_unorm_unpack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
59 util_format_latc1_unorm_pack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row,
60 unsigned src_stride, unsigned width, unsigned height)
62 util_format_rgtc1_unorm_pack_rgba_8unorm(dst_row, dst_stride, src_row, src_stride, width, height);
66 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)
71 for(y = 0; y < height; y += 4) {
72 const uint8_t *src = src_row;
73 for(x = 0; x < width; x += 4) {
74 for(j = 0; j < 4; ++j) {
75 for(i = 0; i < 4; ++i) {
76 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
78 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);
81 dst[2] = ubyte_to_float(tmp_r);
87 src_row += src_stride;
92 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)
94 util_format_rgtc1_unorm_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
98 util_format_latc1_unorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
102 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);
105 dst[2] = ubyte_to_float(tmp_r);
110 util_format_latc1_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
112 fprintf(stderr,"%s\n", __func__);
116 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)
118 fprintf(stderr,"%s\n", __func__);
122 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)
124 fprintf(stderr,"%s\n", __func__);
128 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)
130 util_format_rgtc1_snorm_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height);
134 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)
139 for(y = 0; y < height; y += 4) {
140 const int8_t *src = (int8_t *)src_row;
141 for(x = 0; x < width; x += 4) {
142 for(j = 0; j < 4; ++j) {
143 for(i = 0; i < 4; ++i) {
144 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
146 u_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 1);
149 dst[2] = byte_to_float_tex(tmp_r);
155 src_row += src_stride;
160 util_format_latc1_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
164 u_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)
177 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, dst, 2);
178 u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, dst + 1, 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(float *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 = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
211 uint8_t tmp_r, tmp_g;
212 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);
213 u_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_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
229 uint8_t tmp_r, tmp_g;
231 u_format_unsigned_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);
232 u_format_unsigned_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);
235 dst[2] = ubyte_to_float(tmp_r);
236 dst[3] = ubyte_to_float(tmp_g);
241 util_format_latc2_snorm_fetch_rgba_8unorm(uint8_t *dst, const uint8_t *src, unsigned i, unsigned j)
243 fprintf(stderr,"%s\n", __func__);
247 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)
249 fprintf(stderr,"%s\n", __func__);
253 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)
255 fprintf(stderr,"%s\n", __func__);
259 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)
264 for(y = 0; y < height; y += 4) {
265 const int8_t *src = (int8_t *)src_row;
266 for(x = 0; x < width; x += 4) {
267 for(j = 0; j < 4; ++j) {
268 for(i = 0; i < 4; ++i) {
269 float *dst = dst_row + (y + j)*dst_stride/sizeof(*dst_row) + (x + i)*4;
271 u_format_signed_fetch_texel_rgtc(0, src, i, j, &tmp_r, 2);
272 u_format_signed_fetch_texel_rgtc(0, src + 8, i, j, &tmp_g, 2);
275 dst[2] = byte_to_float_tex(tmp_r);
276 dst[3] = byte_to_float_tex(tmp_g);
281 src_row += src_stride;
286 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)
288 util_format_rxtc2_snorm_pack_rgba_float(dst_row, dst_stride, src_row, src_stride, width, height, 3);
292 util_format_latc2_snorm_fetch_rgba_float(float *dst, const uint8_t *src, unsigned i, unsigned j)
296 u_format_signed_fetch_texel_rgtc(0, (int8_t *)src, i, j, &tmp_r, 2);
297 u_format_signed_fetch_texel_rgtc(0, (int8_t *)src + 8, i, j, &tmp_g, 2);
300 dst[2] = byte_to_float_tex(tmp_r);
301 dst[3] = byte_to_float_tex(tmp_g);
305 #define TAG(x) u_format_unsigned_##x
310 #include "../../../mesa/main/texcompress_rgtc_tmp.h"
318 #define TAG(x) u_format_signed_##x
320 #define T_MIN (int8_t)-128
321 #define T_MAX (int8_t)127
323 #include "../../../mesa/main/texcompress_rgtc_tmp.h"