46 const char *bc5normal =
"dds:bc5normal";
47 const char *oiio_env =
BLI_getenv(
"OPENIMAGEIO_OPTIONS");
49 OIIO::attribute(bc5normal, 1);
63 ImageSpec config, spec;
68 std::string compression = spec.get_string_attribute(
"compression",
"");
69 if (compression ==
"DXT1") {
72 if (compression ==
"DXT3") {
75 if (compression ==
"DXT5") {
177 uint line_0_1 = block[2] + 256 * (block[3] + 256 * block[4]);
178 uint line_2_3 = block[5] + 256 * (block[6] + 256 * block[7]);
180 uint line_1_0 = ((line_0_1 & 0x000fff) << 12) | ((line_0_1 & 0xfff000) >> 12);
182 uint line_3_2 = ((line_2_3 & 0x000fff) << 12) | ((line_2_3 & 0xfff000) >> 12);
184 block[2] = line_3_2 & 0xff;
185 block[3] = (line_3_2 & 0xff00) >> 8;
186 block[4] = (line_3_2 & 0xff0000) >> 16;
187 block[5] = line_1_0 & 0xff;
188 block[6] = (line_1_0 & 0xff00) >> 8;
189 block[7] = (line_1_0 & 0xff0000) >> 16;
199 uint line_0_1 = block[2] + 256 * (block[3] + 256 * block[4]);
200 uint line_1_0 = ((line_0_1 & 0x000fff) << 12) | ((line_0_1 & 0xfff000) >> 12);
201 block[2] = line_1_0 & 0xff;
202 block[3] = (line_1_0 & 0xff00) >> 8;
203 block[4] = (line_1_0 & 0xff0000) >> 16;
220 if (width == 0 || height == 0) {
234 size_t block_bytes = 0;
256 int mip_width = width;
257 int mip_height = height;
261 for (
int level = 0; level < levels; level++) {
262 int blocks_per_row = (mip_width + 3) / 4;
263 int blocks_per_col = (mip_height + 3) / 4;
264 int blocks = blocks_per_row * blocks_per_col;
266 if (
data + block_bytes * blocks > data_end) {
272 if (mip_height == 1) {
276 if (mip_height == 2) {
278 for (
int i = 0; i < blocks_per_row; i++) {
279 half_block_function(
data + i * block_bytes);
284 for (
int i = 0; i < blocks; i++) {
285 full_block_function(
data + i * block_bytes);
291 size_t row_bytes = block_bytes * blocks_per_row;
294 for (
int y = 0;
y < blocks_per_col / 2;
y++) {
296 uint8_t *line2 =
data + (blocks_per_col -
y - 1) * row_bytes;
298 memcpy(temp_line, line1, row_bytes);
299 memcpy(line1, line2, row_bytes);
300 memcpy(line2, temp_line, row_bytes);
307 data += block_bytes * blocks;
308 mip_width = std::max(1, mip_width >> 1);
309 mip_height = std::max(1, mip_height >> 1);
331 if (mmap_file ==
nullptr) {
340 constexpr size_t dds_header_size = 128;
341 if (file_size < dds_header_size) {
347 uint32_t flags = 0, mipcount = 0, fourcc = 0;
348 memcpy(&flags, file_data + 8, 4);
349 memcpy(&mipcount, file_data + 28, 4);
350 memcpy(&fourcc, file_data + 84, 4);
356 constexpr uint32_t DDSD_MIPMAPCOUNT = 0x00020000U;
357 if ((flags & DDSD_MIPMAPCOUNT) == 0) {
361 size_t pixel_data_size = file_size - dds_header_size;
364 memcpy(
result, file_data + dds_header_size, pixel_data_size);
File and directory operations.
#define DDS_COMPRESSED_DXT3
#define DDS_COMPRESSED_DXT1
#define DDS_COMPRESSED_DXT5
Read Blender memory allocation and freeing.
ImBuf * imb_oiio_read(const ReadContext &ctx, const ImageSpec &config, ImFileColorSpace &r_colorspace, ImageSpec &r_newspec)
bool imb_oiio_check(const uchar *mem, size_t mem_size, const char *file_format)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static constexpr uint32_t fourcc_dxt3
size_t BLI_mmap_get_length(const BLI_mmap_file *file) ATTR_WARN_UNUSED_RESULT
BLI_mmap_file * BLI_mmap_open(int fd) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
static constexpr uint32_t fourcc_dxt5
static void FlipDXT5BlockFull(uint8_t *block)
int BLI_open(const char *filepath, int oflag, int pmode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static int flip_dxtc_image(uint8_t *data, size_t data_size, int width, int height, int levels, uint32_t fourcc)
void BLI_mmap_free(BLI_mmap_file *file) ATTR_NONNULL(1)
int char * BLI_strcasestr(const char *s, const char *find) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
ImBuf * imb_load_dds(const uchar *mem, size_t size, ImBufFlags flags, ImFileColorSpace &r_colorspace)
static void FlipDXT1BlockHalf(uint8_t *block)
uint8_t * imb_load_dds_compressed_data(const char *filepath, int width, int height, int &r_mipcount)
BMesh const char void * data
static void FlipDXT3BlockHalf(uint8_t *block)
static void FlipDXT1BlockFull(uint8_t *block)
const char * imb_file_extensions_dds[]
static void FlipDXT3BlockFull(uint8_t *block)
static void FlipDXT5BlockHalf(uint8_t *block)
bool imb_is_a_dds(const uchar *mem, size_t size)
void * BLI_mmap_get_pointer(BLI_mmap_file *file) ATTR_WARN_UNUSED_RESULT
static constexpr uint32_t fourcc_dxt1
void(*)(uint8_t *block) FlipBlockFunction
MINLINE int is_power_of_2_i(int n)
const char * BLI_getenv(const char *env) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
ImbFormatOptions foptions