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 **************************************************************************/
27 #include "u_format_bptc.h"
28 #include "util/format_srgb.h"
29 #include "util/u_math.h"
31 #define BPTC_BLOCK_DECODE
32 #include "../../../mesa/main/texcompress_bptc_tmp.h"
35 util_format_bptc_rgba_unorm_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
36 const uint8_t *src_row
, unsigned src_stride
,
37 unsigned width
, unsigned height
)
39 decompress_rgba_unorm(width
, height
,
45 util_format_bptc_rgba_unorm_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
46 const uint8_t *src_row
, unsigned src_stride
,
47 unsigned width
, unsigned height
)
49 compress_rgba_unorm(width
, height
,
55 util_format_bptc_rgba_unorm_unpack_rgba_float(float *dst_row
, unsigned dst_stride
,
56 const uint8_t *src_row
, unsigned src_stride
,
57 unsigned width
, unsigned height
)
60 temp_block
= malloc(width
* height
* 4 * sizeof(uint8_t));
61 decompress_rgba_unorm(width
, height
,
63 temp_block
, width
* 4 * sizeof(uint8_t));
64 util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM
,
66 temp_block
, width
* 4 * sizeof(uint8_t),
68 free((void *) temp_block
);
72 util_format_bptc_rgba_unorm_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
73 const float *src_row
, unsigned src_stride
,
74 unsigned width
, unsigned height
)
77 temp_block
= malloc(width
* height
* 4 * sizeof(uint8_t));
78 util_format_read_4ub(PIPE_FORMAT_R32G32B32A32_FLOAT
,
79 temp_block
, width
* 4 * sizeof(uint8_t),
82 compress_rgba_unorm(width
, height
,
83 temp_block
, width
* 4 * sizeof(uint8_t),
85 free((void *) temp_block
);
89 util_format_bptc_rgba_unorm_fetch_rgba_float(float *dst
, const uint8_t *src
,
90 unsigned width
, unsigned height
)
92 uint8_t temp_block
[4];
94 fetch_rgba_unorm_from_block(src
+ ((width
* sizeof(uint8_t)) * (height
/ 4) + (width
/ 4)) * 16,
95 temp_block
, (width
% 4) + (height
% 4) * 4);
97 util_format_read_4f(PIPE_FORMAT_R8G8B8A8_UNORM
,
98 dst
, 4 * sizeof(float),
99 temp_block
, 4 * sizeof(uint8_t),
104 util_format_bptc_srgba_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
105 const uint8_t *src_row
, unsigned src_stride
,
106 unsigned width
, unsigned height
)
108 decompress_rgba_unorm(width
, height
,
110 dst_row
, dst_stride
);
114 util_format_bptc_srgba_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
115 const uint8_t *src_row
, unsigned src_stride
,
116 unsigned width
, unsigned height
)
118 compress_rgba_unorm(width
, height
,
120 dst_row
, dst_stride
);
124 util_format_bptc_srgba_unpack_rgba_float(float *dst_row
, unsigned dst_stride
,
125 const uint8_t *src_row
, unsigned src_stride
,
126 unsigned width
, unsigned height
)
129 temp_block
= malloc(width
* height
* 4 * sizeof(uint8_t));
130 decompress_rgba_unorm(width
, height
,
132 temp_block
, width
* 4 * sizeof(uint8_t));
133 util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB
,
135 temp_block
, width
* 4 * sizeof(uint8_t),
136 0, 0, width
, height
);
137 free((void *) temp_block
);
141 util_format_bptc_srgba_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
142 const float *src_row
, unsigned src_stride
,
143 unsigned width
, unsigned height
)
145 compress_rgb_float(width
, height
,
152 util_format_bptc_srgba_fetch_rgba_float(float *dst
, const uint8_t *src
,
153 unsigned width
, unsigned height
)
155 uint8_t temp_block
[4];
157 fetch_rgba_unorm_from_block(src
+ ((width
* sizeof(uint8_t)) * (height
/ 4) + (width
/ 4)) * 16,
158 temp_block
, (width
% 4) + (height
% 4) * 4);
159 util_format_read_4f(PIPE_FORMAT_R8G8B8A8_SRGB
,
160 dst
, 4 * sizeof(float),
161 temp_block
, width
* 4 * sizeof(uint8_t),
166 util_format_bptc_rgb_float_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
167 const uint8_t *src_row
, unsigned src_stride
,
168 unsigned width
, unsigned height
)
171 temp_block
= malloc(width
* height
* 4 * sizeof(float));
172 decompress_rgb_float(width
, height
,
174 temp_block
, width
* 4 * sizeof(float),
176 util_format_read_4ub(PIPE_FORMAT_R32G32B32A32_FLOAT
,
178 temp_block
, width
* 4 * sizeof(float),
179 0, 0, width
, height
);
180 free((void *) temp_block
);
184 util_format_bptc_rgb_float_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
185 const uint8_t *src_row
, unsigned src_stride
,
186 unsigned width
, unsigned height
)
188 compress_rgba_unorm(width
, height
,
190 dst_row
, dst_stride
);
194 util_format_bptc_rgb_float_unpack_rgba_float(float *dst_row
, unsigned dst_stride
,
195 const uint8_t *src_row
, unsigned src_stride
,
196 unsigned width
, unsigned height
)
198 decompress_rgb_float(width
, height
,
205 util_format_bptc_rgb_float_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
206 const float *src_row
, unsigned src_stride
,
207 unsigned width
, unsigned height
)
209 compress_rgb_float(width
, height
,
216 util_format_bptc_rgb_float_fetch_rgba_float(float *dst
, const uint8_t *src
,
217 unsigned width
, unsigned height
)
219 fetch_rgb_float_from_block(src
+ ((width
* sizeof(uint8_t)) * (height
/ 4) + (width
/ 4)) * 16,
220 dst
, (width
% 4) + (height
% 4) * 4, true);
224 util_format_bptc_rgb_ufloat_unpack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
225 const uint8_t *src_row
, unsigned src_stride
,
226 unsigned width
, unsigned height
)
229 temp_block
= malloc(width
* height
* 4 * sizeof(float));
230 decompress_rgb_float(width
, height
,
232 temp_block
, width
* 4 * sizeof(float),
234 util_format_read_4ub(PIPE_FORMAT_R32G32B32A32_FLOAT
,
236 temp_block
, width
* 4 * sizeof(float),
237 0, 0, width
, height
);
238 free((void *) temp_block
);
242 util_format_bptc_rgb_ufloat_pack_rgba_8unorm(uint8_t *dst_row
, unsigned dst_stride
,
243 const uint8_t *src_row
, unsigned src_stride
,
244 unsigned width
, unsigned height
)
246 compress_rgba_unorm(width
, height
,
248 dst_row
, dst_stride
);
252 util_format_bptc_rgb_ufloat_unpack_rgba_float(float *dst_row
, unsigned dst_stride
,
253 const uint8_t *src_row
, unsigned src_stride
,
254 unsigned width
, unsigned height
)
256 decompress_rgb_float(width
, height
,
263 util_format_bptc_rgb_ufloat_pack_rgba_float(uint8_t *dst_row
, unsigned dst_stride
,
264 const float *src_row
, unsigned src_stride
,
265 unsigned width
, unsigned height
)
267 compress_rgb_float(width
, height
,
274 util_format_bptc_rgb_ufloat_fetch_rgba_float(float *dst
, const uint8_t *src
,
275 unsigned width
, unsigned height
)
277 fetch_rgb_float_from_block(src
+ ((width
* sizeof(uint8_t)) * (height
/ 4) + (width
/ 4)) * 16,
278 dst
, (width
% 4) + (height
% 4) * 4, false);