Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- early test of all functions put together.
- static void dxtn_decompress_block(const BYTE *src, BYTE *dst, UINT width, UINT height, UINT depth,
- UINT x_pos, UINT y_pos, UINT z_pos, UINT dst_slice_pitch, UINT64 cur_block, UINT fmt)
- {
- UINT64 alpha_block, alpha_index, color_block, color_index;
- const UINT64 *source;
- DWORD *dest;
- DWORD alpha_lookup;
- DWORD bgra;
- DWORD temp;
- DWORD i, x, y;
- WORD color[2];
- BYTE alpha_val, color_val;
- BYTE alpha[8];
- BYTE r[4];
- BYTE g[4];
- BYTE b[4];
- BYTE block_offset;
- /* Block selection section. */
- if (fmt == WINED3DFMT_DXT1)
- block_offset = 8;
- else
- block_offset = 16;
- source = (const UINT64 *)(src + cur_block * block_offset);
- if (fmt == WINED3DFMT_DXT1)
- color_block = source[0];
- else
- {
- alpha_block = source[0];
- color_block = source[1];
- }
- /* Color handling section. */
- 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;
- }
- if (fmt == WINED3DFMT_DXT3 || fmt == WINED3DFMT_DXT5 || color[0] > color[1])
- {
- 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;
- }
- if (fmt == WINED3DFMT_DXT1)
- {
- for (i = 0; i < 8; ++i)
- alpha[i] = 255;
- }
- }
- else if (fmt == WINED3DFMT_DXT1 && color[0] <= color[1])
- {
- r[2] = (r[0] + r[1]) / 2;
- g[2] = (g[0] + g[1]) / 2;
- b[2] = (b[0] + b[1]) / 2;
- r[3] = 0;
- g[3] = 0;
- b[3] = 0;
- for (i = 0; i < 8; ++i)
- alpha[i] = 255;
- alpha[3] = 0;
- }
- /* Alpha handling section. */
- switch (fmt)
- {
- case WINED3DFMT_DXT1:
- alpha_index = 0;
- for (i = 0; i < 8; ++i)
- alpha[i] = 255;
- if (color[0] <= color[1])
- alpha[3] = 0;
- break;
- case WINED3DFMT_DXT3:
- alpha_index = alpha_block;
- for (i = 0; i < 8; ++i)
- alpha[i] = 0;
- break;
- case WINED3DFMT_DXT5:
- alpha_index = (alpha_block >> 16);
- alpha[0] = alpha_block & 0xff;
- alpha[1] = (alpha_block >> 8) & 0xff;
- 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;
- }
- break;
- default:
- alpha_index = 0;
- break;
- }
- /* This is the data writing section. */
- color_index = (color_block >> 32) & 0xffffffff;
- 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;
- switch (fmt)
- {
- case WINED3DFMT_DXT1:
- alpha_val = color_val;
- break;
- case WINED3DFMT_DXT3:
- alpha_lookup = (alpha_index >> (y * 16)) & 0xffff;
- alpha_val = (alpha_lookup >> (x * 4)) & 0xf;
- temp = alpha_val * 255 + 8;
- alpha[0] = (temp / 16 + temp) / 16;
- break;
- case WINED3DFMT_DXT5:
- alpha_lookup = (alpha_index >> (y * 12)) & 0xfff;
- alpha_val = (alpha_lookup >> (x * 3)) & 0x7;
- break;
- }
- bgra = ((alpha[alpha_val] << 24) | (r[color_val] << 16) | (g[color_val] << 8) | b[color_val]);
- dest[(y_pos + y) * width + (x_pos + x)] = bgra;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement