Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void dxt5_decompress_block(const BYTE *src, BYTE *dst, UINT width, UINT height, UINT depth,
- unsigned int x_pos, unsigned int y_pos, unsigned int z_pos, UINT dst_slice_pitch, UINT64 cur_block)
- {
- DWORD alpha_lookup;
- DWORD bgra;
- DWORD temp;
- UINT64 alpha_block, alpha_index, color_block, color_index;
- DWORD *Dest;
- const UINT64 *Source;
- unsigned short color[2];
- unsigned int i, x, y;
- unsigned char alpha_val, color_val;
- unsigned char alpha[8];
- unsigned char r[4];
- unsigned char g[4];
- unsigned char b[4];
- Source = (const UINT64 *)(src + cur_block * 16);
- alpha_block = Source[0];
- color_block = Source[1];
- alpha[0] = alpha_block & 0xFF;
- alpha[1] = (alpha_block >> 8) & 0xFF;
- /* Generate alpha lookup values */
- if (alpha[0] > alpha[1])
- {
- for (i = 0; i < 6; i++)
- alpha[2 + i] = (((6 - i) * alpha[0]) + ((1 + i) * alpha[1])) / 7;
- }
- else if (alpha[0] <= alpha[1])
- {
- for (i = 0; i < 4; i++)
- alpha[2 + i] = (((4 - i) * alpha[0]) + ((1 + i) * alpha[1])) / 5;
- alpha[6] = 0;
- alpha[7] = 255;
- }
- /* Generate color lookup values */
- color[0] = color_block & 0xFFFF;
- color[1] = (color_block >> 16) & 0xFFFF;
- for (i = 0; i < 2; i++)
- {
- temp = (color[i] >> 11) * 255 + 16;
- r[i] = (temp / 32 + temp) / 32;
- temp = ((color[i] >> 5) & 0x3F) * 255 + 32;
- g[i] = (temp / 64 + temp) / 64;
- temp = (color[i] & 0x1F) * 255 + 16;
- b[i] = (temp / 32 + temp) / 32;
- }
- for (i = 0; i < 2; i++)
- {
- r[2 + i] = (2 * r[0 + i] + r[1 - i]) / 3;
- g[2 + i] = (2 * g[0 + i] + g[1 - i]) / 3;
- b[2 + i] = (2 * b[0 + i] + b[1 - i]) / 3;
- }
- color_index = (color_block >> 32) & 0xFFFFFFFF;
- alpha_index = (alpha_block >> 16);
- Dest = (DWORD *)(dst + z_pos * dst_slice_pitch);
- for (y = 0; y < 4; y++) {
- if (y_pos + y >= height)
- break;
- for (x = 0; x < 4; x++) {
- if (x_pos + x >= width)
- break;
- color_val = 0;
- alpha_val = 0;
- bgra = 0;
- color_val = (color_index >> (y * 8));
- color_val = (color_val >> (x * 2)) & 0x3;
- alpha_lookup = (alpha_index >> (y * 12)) & 0xFFF;
- alpha_val = (alpha_lookup >> (x * 3)) & 0x7;
- bgra = ((alpha[alpha_val] << 24) | (r[color_val] << 16) | (g[color_val] << 8) | b[color_val]);
- Dest[(y_pos + y) * height + (x_pos + x)] = bgra;
- }
- }
- }
- static void convert_dxt5_b8g8r8a8_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
- UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
- {
- UINT64 current_block;
- unsigned int x, y, z;
- current_block = 0;
- for (z = 0; z < depth; z++)
- {
- for (y = 0; y < height; y += 4)
- {
- for (x = 0; x < width; x += 4)
- {
- dxt5_decompress_block(src, dst, width, height, depth, x, y, z, dst_slice_pitch, current_block);
- current_block++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement