|
| 1 | +#include <stddef.h> |
| 2 | +#include <cstring> |
| 3 | +#include <stdint.h> |
| 4 | +#include "crn_decomp.h" |
| 5 | + |
| 6 | +extern "C" { |
| 7 | + unsigned int crn_get_decompressed_size(const void *src, unsigned int src_size, unsigned int level_index); |
| 8 | + void crn_decompress(const void *src, unsigned int src_size, void *dst, unsigned int dst_size, unsigned int level_index); |
| 9 | +} |
| 10 | + |
| 11 | +unsigned int crn_get_decompressed_size(const void *src, unsigned int src_size, unsigned int level_index) { |
| 12 | + crnd::crn_texture_info tex_info; |
| 13 | + crnd::crnd_get_texture_info(static_cast<const crn_uint8*>(src), src_size, &tex_info); |
| 14 | + const crn_uint32 width = tex_info.m_width >> level_index; |
| 15 | + const crn_uint32 height = tex_info.m_height >> level_index; |
| 16 | + const crn_uint32 blocks_x = (width + 3) >> 2; |
| 17 | + const crn_uint32 blocks_y = (height + 3) >> 2; |
| 18 | + const crn_uint32 row_pitch = blocks_x * crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format); |
| 19 | + const crn_uint32 total_face_size = row_pitch * blocks_y; |
| 20 | + return total_face_size; |
| 21 | +} |
| 22 | + |
| 23 | +void crn_decompress(const void *src, unsigned int src_size, void *dst, unsigned int dst_size, unsigned int level_index) { |
| 24 | + crnd::crn_texture_info tex_info; |
| 25 | + crnd::crnd_get_texture_info(static_cast<const crn_uint8*>(src), src_size, &tex_info); |
| 26 | + const crn_uint32 width = tex_info.m_width >> level_index; |
| 27 | + const crn_uint32 height = tex_info.m_height >> level_index; |
| 28 | + const crn_uint32 blocks_x = (width + 3) >> 2; |
| 29 | + const crn_uint32 blocks_y = (height + 3) >> 2; |
| 30 | + const crn_uint32 row_pitch = blocks_x * crnd::crnd_get_bytes_per_dxt_block(tex_info.m_format); |
| 31 | + crnd::crnd_unpack_context pContext = crnd::crnd_unpack_begin(static_cast<const crn_uint8*>(src), src_size); |
| 32 | + void *pDecomp_images[1]; |
| 33 | + pDecomp_images[0] = dst; |
| 34 | + crnd::crnd_unpack_level(pContext, pDecomp_images, dst_size, row_pitch, level_index); |
| 35 | + crnd::crnd_unpack_end(pContext); |
| 36 | +} |
0 commit comments