mirror of
https://github.com/BinomialLLC/basis_universal.git
synced 2026-06-08 00:23:52 +00:00
tinyexr: upgrading to latest library version. We no longer modify tinyexr, i.e. the tinyexr.h header we're using is now completely standard. We direct tinyexr's zlib calls to our fork of miniz internally.
This commit is contained in:
@@ -247,7 +247,7 @@ set(ENCODER_LIB_SRC_LIST
|
||||
encoder/basisu_astc_hdr_common.cpp
|
||||
encoder/basisu_astc_ldr_common.cpp
|
||||
encoder/basisu_astc_ldr_encode.cpp
|
||||
encoder/3rdparty/tinyexr.cpp
|
||||
encoder/basisu_tinyexr.cpp
|
||||
transcoder/basisu_transcoder.cpp
|
||||
encoder/basisu_astc_hdr_6x6_enc.h
|
||||
encoder/basisu_astc_hdr_common.h
|
||||
|
||||
2261
encoder/3rdparty/tinyexr.h
vendored
2261
encoder/3rdparty/tinyexr.h
vendored
File diff suppressed because it is too large
Load Diff
@@ -28,9 +28,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#ifndef TINYEXR_USE_ZFP
|
||||
#define TINYEXR_USE_ZFP (1)
|
||||
#endif
|
||||
#define TINYEXR_USE_MINIZ (0)
|
||||
#include "3rdparty/tinyexr.h"
|
||||
|
||||
#ifndef MINIZ_HEADER_FILE_ONLY
|
||||
@@ -3448,7 +3446,7 @@ namespace basisu
|
||||
float* out_rgba = nullptr;
|
||||
const char* err = nullptr;
|
||||
|
||||
int status = LoadEXRWithLayer(&out_rgba, &width, &height, pFilename, nullptr, &err, &n_chans);
|
||||
int status = LoadEXRWithLayer(&out_rgba, &width, &height, pFilename, nullptr, &err);
|
||||
if (status != 0)
|
||||
{
|
||||
error_printf("Failed loading .EXR image \"%s\"! (TinyEXR error: %s)\n", pFilename, err ? err : "?");
|
||||
@@ -3457,7 +3455,7 @@ namespace basisu
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint32_t MAX_SUPPORTED_DIM = 65536;
|
||||
const uint32_t MAX_SUPPORTED_DIM = 32768;
|
||||
if ((width < 1) || (height < 1) || (width > (int)MAX_SUPPORTED_DIM) || (height > (int)MAX_SUPPORTED_DIM))
|
||||
{
|
||||
error_printf("Invalid dimensions of .EXR image \"%s\"!\n", pFilename);
|
||||
@@ -3467,31 +3465,59 @@ namespace basisu
|
||||
|
||||
img.resize(width, height);
|
||||
|
||||
if (n_chans == 1)
|
||||
{
|
||||
const float* pSrc = out_rgba;
|
||||
vec4F* pDst = img.get_ptr();
|
||||
memcpy((void*)img.get_ptr(), out_rgba, static_cast<size_t>(sizeof(float) * 4 * img.get_total_pixels()));
|
||||
|
||||
free(out_rgba);
|
||||
out_rgba = nullptr;
|
||||
|
||||
uint32_t total_all_same_rgba = 0, total_all_same_rgb = 0, total_has_alpha = 0;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
(*pDst)[0] = pSrc[0];
|
||||
(*pDst)[1] = pSrc[1];
|
||||
(*pDst)[2] = pSrc[2];
|
||||
(*pDst)[3] = 1.0f;
|
||||
const vec4F& p = img(x, y);
|
||||
|
||||
pSrc += 4;
|
||||
++pDst;
|
||||
if ((p[0] == p[1]) && (p[0] == p[2]))
|
||||
total_all_same_rgb++;
|
||||
|
||||
const float a = p[3];
|
||||
|
||||
if ((a == p[0]) && (a == p[1]) && (a == p[2]))
|
||||
total_all_same_rgba++;
|
||||
|
||||
if (a != 1.0f)
|
||||
total_has_alpha++;
|
||||
|
||||
} // x
|
||||
} // y
|
||||
|
||||
const uint32_t total_pixels = width * height;
|
||||
if (total_all_same_rgba == total_pixels)
|
||||
{
|
||||
// TinyEXR loads single channel EXR images into all output channels (including alpha) - assume they are luminance and fix our alpha.
|
||||
// Odds are this is an opaque luminance-only image, not a true alpha channel image. (As of early 2026 we don't support any HDR format with alpha, anyway.)
|
||||
for (int y = 0; y < height; y++)
|
||||
for (int x = 0; x < width; x++)
|
||||
img(x, y)[3] = 1.0f;
|
||||
|
||||
n_chans = 1;
|
||||
}
|
||||
else if (total_has_alpha)
|
||||
{
|
||||
n_chans = 4;
|
||||
}
|
||||
else if (total_all_same_rgb == total_pixels)
|
||||
{
|
||||
n_chans = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy((void *)img.get_ptr(), out_rgba, static_cast<size_t>(sizeof(float) * 4 * img.get_total_pixels()));
|
||||
n_chans = 3;
|
||||
}
|
||||
|
||||
free(out_rgba);
|
||||
//fmt_printf("Number of detected EXR channels: {}\n", n_chans);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3513,6 +3539,8 @@ namespace basisu
|
||||
memcpy((void *)img.get_ptr(), out_rgba, width * height * sizeof(float) * 4);
|
||||
free(out_rgba);
|
||||
|
||||
// TODO: detect luminance-only etc.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,34 +5,27 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Pull in our local fork of the miniz library. (Binomial wrote the original miniz library. Basisu was tested with this specific version.)
|
||||
#define MINIZ_HEADER_FILE_ONLY
|
||||
#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
|
||||
#include "basisu_miniz.h"
|
||||
|
||||
// Force tinyexr to use zlib-style compression API's, then we'll direct them to our own customized copy of miniz. (Binomial wrote the original miniz library.)
|
||||
// This allows us to use tinyexr.h without modify it at all, or relying on zlib.
|
||||
// A bit of a hack to force tinyexr to use plain zlib-style compression API's, then we'll direct them to our own customized copy of miniz with #define's.
|
||||
// This allows us to use tinyexr.h without modifying it at all, or relying on zlib, or pulling in a system-wide miniz dependency.
|
||||
// This assumes tinyexr.h doesn't include zlib.h (it doesn't: "Please include your own zlib-compatible API header before...")
|
||||
// (Time will tell how fragile this is in reality.)
|
||||
#define TINYEXR_USE_MINIZ (0)
|
||||
|
||||
enum { Z_OK = 0, Z_STREAM_END = 1, Z_NEED_DICT = 2, Z_ERRNO = -1, Z_STREAM_ERROR = -2, Z_DATA_ERROR = -3, Z_MEM_ERROR = -4, Z_BUF_ERROR = -5, Z_VERSION_ERROR = -6, Z_PARAM_ERROR = -10000 };
|
||||
typedef unsigned long uLongf;
|
||||
typedef unsigned long uLong;
|
||||
#define Z_OK buminiz::MZ_OK
|
||||
#define uLong buminiz::mz_ulong
|
||||
#define uLongf buminiz::mz_ulong
|
||||
|
||||
typedef unsigned char Byte;
|
||||
typedef Byte Bytef;
|
||||
|
||||
uLong compressBound(uLong src_size)
|
||||
{
|
||||
return buminiz::mz_compressBound(src_size);
|
||||
}
|
||||
|
||||
int compress(Bytef* dest, uLongf* destLen, const Bytef* source, uLong sourceLen)
|
||||
{
|
||||
return buminiz::mz_compress(dest, destLen, source, sourceLen);
|
||||
}
|
||||
|
||||
int uncompress(Bytef* dest, uLongf* destLen, const Bytef* source, uLong sourceLen)
|
||||
{
|
||||
return buminiz::mz_uncompress(dest, destLen, source, sourceLen);
|
||||
}
|
||||
#define compressBound buminiz::mz_compressBound
|
||||
#define compress buminiz::mz_compress
|
||||
#define uncompress buminiz::mz_uncompress
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable: 4060)
|
||||
@@ -40,6 +33,7 @@ int uncompress(Bytef* dest, uLongf* destLen, const Bytef* source, uLong sourceLe
|
||||
#pragma warning (disable: 4245)
|
||||
#pragma warning (disable: 4505)
|
||||
#pragma warning (disable: 4702)
|
||||
#pragma warning (disable: 4530) // warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
|
||||
#endif
|
||||
|
||||
#define TINYEXR_IMPLEMENTATION
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\encoder\3rdparty\android_astc_decomp.cpp" />
|
||||
<ClCompile Include="..\encoder\3rdparty\tinyexr.cpp" />
|
||||
<ClCompile Include="..\encoder\basisu_astc_hdr_6x6_enc.cpp" />
|
||||
<ClCompile Include="..\encoder\basisu_astc_hdr_common.cpp" />
|
||||
<ClCompile Include="..\encoder\basisu_astc_ldr_common.cpp" />
|
||||
<ClCompile Include="..\encoder\basisu_astc_ldr_encode.cpp" />
|
||||
<ClCompile Include="..\encoder\basisu_tinyexr.cpp" />
|
||||
<ClCompile Include="..\encoder\basisu_uastc_hdr_4x4_enc.cpp" />
|
||||
<ClCompile Include="..\encoder\basisu_backend.cpp" />
|
||||
<ClCompile Include="..\encoder\basisu_basis_file.cpp" />
|
||||
|
||||
@@ -84,9 +84,6 @@
|
||||
<ClCompile Include="..\encoder\pvpngreader.cpp">
|
||||
<Filter>Source Files\encoder</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\encoder\3rdparty\tinyexr.cpp">
|
||||
<Filter>Source Files\encoder\3rdparty</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\zstd\zstd.c">
|
||||
<Filter>Source Files\encoder\3rdparty</Filter>
|
||||
</ClCompile>
|
||||
@@ -105,6 +102,9 @@
|
||||
<ClCompile Include="..\encoder\basisu_astc_ldr_encode.cpp">
|
||||
<Filter>Source Files\encoder</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\encoder\basisu_tinyexr.cpp">
|
||||
<Filter>Source Files\encoder</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\transcoder\basisu_astc_helpers.h">
|
||||
|
||||
@@ -67,7 +67,7 @@ if(EMSCRIPTEN)
|
||||
../../encoder/basisu_astc_hdr_common.cpp
|
||||
../../encoder/basisu_astc_ldr_common.cpp
|
||||
../../encoder/basisu_astc_ldr_encode.cpp
|
||||
../../encoder/3rdparty/tinyexr.cpp
|
||||
../../encoder/basisu_tinyexr.cpp
|
||||
)
|
||||
if(KTX2_ZSTANDARD)
|
||||
list(APPEND SRC_LIST ../../zstd/zstd.c)
|
||||
|
||||
Reference in New Issue
Block a user