1 /**************************************************************************
3 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
4 * Copyright (c) 2008 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 **************************************************************************/
26 #include "util/format/u_format.h"
27 #include "util/format/u_format_bptc.h"
28 #include "u_format_pack.h"
29 #include "util/format_srgb.h"
30 #include "util/u_math.h"
32 #define BPTC_BLOCK_DECODE
33 #include "../../mesa/main/texcompress_bptc_tmp.h"
36 util_format_bptc_rgba_unorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
37 const uint8_t *src_row
, unsigned src_stride
,
38 unsigned width
, unsigned height
)
40 decompress_rgba_unorm(width
, height
,
46 util_format_bptc_rgba_unorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
47 const uint8_t *src_row
, unsigned src_stride
,
48 unsigned width
, unsigned height
)
50 compress_rgba_unorm(width
, height
,
56 util_format_bptc_rgba_unorm_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
57 const uint8_t *src_row
, unsigned src_stride
,
58 unsigned width
, unsigned height
)
61 temp_block
= malloc(width
* height
* 4 * sizeof(uint8_t));
62 decompress_rgba_unorm(width
, height
,
64 temp_block
, width
* 4 * sizeof(uint8_t));
65 util_format_r8g8b8a8_unorm_unpack_rgba_float(
67 temp_block
, width
* 4 * sizeof(uint8_t),
69 free((void *) temp_block
);
73 util_format_bptc_rgba_unorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
74 const float *src_row
, unsigned src_stride
,
75 unsigned width
, unsigned height
)
78 temp_block
= malloc(width
* height
* 4 * sizeof(uint8_t));
79 util_format_r32g32b32a32_float_unpack_rgba_8unorm(
80 temp_block
, width
* 4 * sizeof(uint8_t),
81 (uint8_t *)src_row
, src_stride
,
83 compress_rgba_unorm(width
, height
,
84 temp_block
, width
* 4 * sizeof(uint8_t),
86 free((void *) temp_block
);
90 util_format_bptc_rgba_unorm_fetch_rgba(void *dst
, const uint8_t *src
,
91 unsigned width
, unsigned height
)
93 uint8_t temp_block
[4];
95 fetch_rgba_unorm_from_block(src
+ ((width
* sizeof(uint8_t)) * (height
/ 4) + (width
/ 4)) * 16,
96 temp_block
, (width
% 4) + (height
% 4) * 4);
98 util_format_read_4(PIPE_FORMAT_R8G8B8A8_UNORM
,
99 dst
, 4 * sizeof(float),
100 temp_block
, 4 * sizeof(uint8_t),
105 util_format_bptc_srgba_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
106 const uint8_t *src_row
, unsigned src_stride
,
107 unsigned width
, unsigned height
)
109 decompress_rgba_unorm(width
, height
,
111 dst_row
, dst_stride
);
115 util_format_bptc_srgba_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
116 const uint8_t *src_row
, unsigned src_stride
,
117 unsigned width
, unsigned height
)
119 compress_rgba_unorm(width
, height
,
121 dst_row
, dst_stride
);
125 util_format_bptc_srgba_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
126 const uint8_t *src_row
, unsigned src_stride
,
127 unsigned width
, unsigned height
)
130 temp_block
= malloc(width
* height
* 4 * sizeof(uint8_t));
131 decompress_rgba_unorm(width
, height
,
133 temp_block
, width
* 4 * sizeof(uint8_t));
134 util_format_r8g8b8a8_srgb_unpack_rgba_float(dst_row
, dst_stride
,
135 temp_block
, width
* 4 * sizeof(uint8_t),
138 free((void *) temp_block
);
142 util_format_bptc_srgba_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
143 const float *src_row
, unsigned src_stride
,
144 unsigned width
, unsigned height
)
146 compress_rgb_float(width
, height
,
153 util_format_bptc_srgba_fetch_rgba(void *dst
, const uint8_t *src
,
154 unsigned width
, unsigned height
)
156 uint8_t temp_block
[4];
158 fetch_rgba_unorm_from_block(src
+ ((width
* sizeof(uint8_t)) * (height
/ 4) + (width
/ 4)) * 16,
159 temp_block
, (width
% 4) + (height
% 4) * 4);
160 util_format_r8g8b8a8_srgb_fetch_rgba(dst
, temp_block
, 0, 0);
164 util_format_bptc_rgb_float_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
165 const uint8_t *src_row
, unsigned src_stride
,
166 unsigned width
, unsigned height
)
169 temp_block
= malloc(width
* height
* 4 * sizeof(float));
170 decompress_rgb_float(width
, height
,
172 temp_block
, width
* 4 * sizeof(float),
174 util_format_r32g32b32a32_float_unpack_rgba_8unorm(
176 (const uint8_t *)temp_block
, width
* 4 * sizeof(float),
178 free((void *) temp_block
);
182 util_format_bptc_rgb_float_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
183 const uint8_t *src_row
, unsigned src_stride
,
184 unsigned width
, unsigned height
)
186 compress_rgba_unorm(width
, height
,
188 dst_row
, dst_stride
);
192 util_format_bptc_rgb_float_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
193 const uint8_t *src_row
, unsigned src_stride
,
194 unsigned width
, unsigned height
)
196 decompress_rgb_float(width
, height
,
203 util_format_bptc_rgb_float_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
204 const float *src_row
, unsigned src_stride
,
205 unsigned width
, unsigned height
)
207 compress_rgb_float(width
, height
,
214 util_format_bptc_rgb_float_fetch_rgba(void *dst
, const uint8_t *src
,
215 unsigned width
, unsigned height
)
217 fetch_rgb_float_from_block(src
+ ((width
* sizeof(uint8_t)) * (height
/ 4) + (width
/ 4)) * 16,
218 dst
, (width
% 4) + (height
% 4) * 4, true);
222 util_format_bptc_rgb_ufloat_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
223 const uint8_t *src_row
, unsigned src_stride
,
224 unsigned width
, unsigned height
)
227 temp_block
= malloc(width
* height
* 4 * sizeof(float));
228 decompress_rgb_float(width
, height
,
230 temp_block
, width
* 4 * sizeof(float),
232 util_format_r32g32b32a32_float_unpack_rgba_8unorm(
234 (const uint8_t *)temp_block
, width
* 4 * sizeof(float),
236 free((void *) temp_block
);
240 util_format_bptc_rgb_ufloat_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
241 const uint8_t *src_row
, unsigned src_stride
,
242 unsigned width
, unsigned height
)
244 compress_rgba_unorm(width
, height
,
246 dst_row
, dst_stride
);
250 util_format_bptc_rgb_ufloat_unpack_rgba_float(void *dst_row
, unsigned dst_stride
,
251 const uint8_t *src_row
, unsigned src_stride
,
252 unsigned width
, unsigned height
)
254 decompress_rgb_float(width
, height
,
261 util_format_bptc_rgb_ufloat_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
262 const float *src_row
, unsigned src_stride
,
263 unsigned width
, unsigned height
)
265 compress_rgb_float(width
, height
,
272 util_format_bptc_rgb_ufloat_fetch_rgba(void *dst
, const uint8_t *src
,
273 unsigned width
, unsigned height
)
275 fetch_rgb_float_from_block(src
+ ((width
* sizeof(uint8_t)) * (height
/ 4) + (width
/ 4)) * 16,
276 dst
, (width
% 4) + (height
% 4) * 4, false);