mirror of
https://github.com/bkaradzic/bimg.git
synced 2026-02-17 20:52:38 +01:00
texturec: Added quality option.
This commit is contained in:
@@ -10,6 +10,18 @@
|
||||
|
||||
namespace bimg
|
||||
{
|
||||
struct Quality
|
||||
{
|
||||
enum Enum
|
||||
{
|
||||
Default,
|
||||
Highest,
|
||||
Fastest,
|
||||
|
||||
Count
|
||||
};
|
||||
};
|
||||
|
||||
///
|
||||
bool imageEncodeFromRgba8(
|
||||
void* _dst
|
||||
@@ -17,6 +29,7 @@ namespace bimg
|
||||
, uint32_t _width
|
||||
, uint32_t _height
|
||||
, TextureFormat::Enum _format
|
||||
, Quality::Enum _quality
|
||||
);
|
||||
|
||||
///
|
||||
@@ -27,7 +40,8 @@ namespace bimg
|
||||
, uint32_t _width
|
||||
, uint32_t _height
|
||||
, TextureFormat::Enum _format
|
||||
);
|
||||
, Quality::Enum _quality
|
||||
);
|
||||
|
||||
///
|
||||
void imageRgba32f11to01(
|
||||
@@ -36,7 +50,7 @@ namespace bimg
|
||||
, uint32_t _height
|
||||
, uint32_t _pitch
|
||||
, const void* _src
|
||||
);
|
||||
);
|
||||
|
||||
///
|
||||
void imageMakeDist(
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
#include <bimg/encode.h>
|
||||
#include "bimg_p.h"
|
||||
|
||||
#include <libsquish/squish.h>
|
||||
@@ -26,7 +27,15 @@ extern "C" {
|
||||
|
||||
namespace bimg
|
||||
{
|
||||
bool imageEncodeFromRgba8(void* _dst, const void* _src, uint32_t _width, uint32_t _height, TextureFormat::Enum _format)
|
||||
static uint32_t s_squishQuality[] =
|
||||
{
|
||||
squish::kColourClusterFit, // Default
|
||||
squish::kColourIterativeClusterFit, // Highest
|
||||
squish::kColourRangeFit, // Fastest
|
||||
};
|
||||
BX_STATIC_ASSERT(Quality::Count == BX_COUNTOF(s_squishQuality) );
|
||||
|
||||
bool imageEncodeFromRgba8(void* _dst, const void* _src, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, Quality::Enum _quality)
|
||||
{
|
||||
switch (_format)
|
||||
{
|
||||
@@ -36,11 +45,12 @@ namespace bimg
|
||||
case TextureFormat::BC4:
|
||||
case TextureFormat::BC5:
|
||||
squish::CompressImage( (const uint8_t*)_src, _width, _height, _dst
|
||||
, _format == TextureFormat::BC2 ? squish::kDxt3
|
||||
: _format == TextureFormat::BC3 ? squish::kDxt5
|
||||
: _format == TextureFormat::BC4 ? squish::kBc4
|
||||
: _format == TextureFormat::BC5 ? squish::kBc5
|
||||
: squish::kDxt1
|
||||
, s_squishQuality[_quality]
|
||||
| (_format == TextureFormat::BC2 ? squish::kDxt3
|
||||
: _format == TextureFormat::BC3 ? squish::kDxt5
|
||||
: _format == TextureFormat::BC4 ? squish::kBc4
|
||||
: _format == TextureFormat::BC5 ? squish::kBc5
|
||||
: squish::kDxt1)
|
||||
);
|
||||
return true;
|
||||
|
||||
@@ -121,7 +131,7 @@ namespace bimg
|
||||
return imageConvert(_dst, _format, _src, TextureFormat::RGBA8, _width, _height);
|
||||
}
|
||||
|
||||
bool imageEncodeFromRgba32f(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, TextureFormat::Enum _format)
|
||||
bool imageEncodeFromRgba32f(bx::AllocatorI* _allocator, void* _dst, const void* _src, uint32_t _width, uint32_t _height, TextureFormat::Enum _format, Quality::Enum _quality)
|
||||
{
|
||||
const uint8_t* src = (const uint8_t*)_src;
|
||||
|
||||
@@ -163,7 +173,7 @@ namespace bimg
|
||||
}
|
||||
}
|
||||
|
||||
imageEncodeFromRgba8(_dst, temp, _width, _height, _format);
|
||||
imageEncodeFromRgba8(_dst, temp, _width, _height, _format, _quality);
|
||||
BX_FREE(_allocator, temp);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <bx/uint32_t.h>
|
||||
|
||||
#define BIMG_TEXTUREC_VERSION_MAJOR 1
|
||||
#define BIMG_TEXTUREC_VERSION_MINOR 2
|
||||
#define BIMG_TEXTUREC_VERSION_MINOR 3
|
||||
|
||||
struct Options
|
||||
{
|
||||
@@ -31,6 +31,7 @@ struct Options
|
||||
: maxSize(UINT32_MAX)
|
||||
, edge(0.0f)
|
||||
, format(bimg::TextureFormat::Count)
|
||||
, quality(bimg::Quality::Default)
|
||||
, mips(false)
|
||||
, normalMap(false)
|
||||
, iqa(false)
|
||||
@@ -61,6 +62,7 @@ struct Options
|
||||
uint32_t maxSize;
|
||||
float edge;
|
||||
bimg::TextureFormat::Enum format;
|
||||
bimg::Quality::Enum quality;
|
||||
bool mips;
|
||||
bool normalMap;
|
||||
bool iqa;
|
||||
@@ -230,6 +232,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
, dstMip.m_width
|
||||
, dstMip.m_height
|
||||
, outputFormat
|
||||
, _options.quality
|
||||
);
|
||||
|
||||
for (uint8_t lod = 1; lod < numMips; ++lod)
|
||||
@@ -257,6 +260,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
, dstMip.m_width
|
||||
, dstMip.m_height
|
||||
, outputFormat
|
||||
, _options.quality
|
||||
);
|
||||
}
|
||||
|
||||
@@ -294,6 +298,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
, dstMip.m_width
|
||||
, dstMip.m_height
|
||||
, outputFormat
|
||||
, _options.quality
|
||||
);
|
||||
|
||||
if (1 < numMips)
|
||||
@@ -330,6 +335,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
, dstMip.m_width
|
||||
, dstMip.m_height
|
||||
, outputFormat
|
||||
, _options.quality
|
||||
);
|
||||
|
||||
if (!succeeded)
|
||||
@@ -374,7 +380,13 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
|
||||
bimg::imageGetRawData(*output, side, 0, output->m_data, output->m_size, dstMip);
|
||||
dstData = const_cast<uint8_t*>(dstMip.m_data);
|
||||
bimg::imageEncodeFromRgba8(dstData, rgba, dstMip.m_width, dstMip.m_height, outputFormat);
|
||||
bimg::imageEncodeFromRgba8(dstData
|
||||
, rgba
|
||||
, dstMip.m_width
|
||||
, dstMip.m_height
|
||||
, outputFormat
|
||||
, _options.quality
|
||||
);
|
||||
|
||||
for (uint8_t lod = 1; lod < numMips; ++lod)
|
||||
{
|
||||
@@ -393,6 +405,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
||||
, dstMip.m_width
|
||||
, dstMip.m_height
|
||||
, outputFormat
|
||||
, _options.quality
|
||||
);
|
||||
}
|
||||
|
||||
@@ -470,6 +483,7 @@ void help(const char* _error = NULL)
|
||||
" -f <file path> Input file path.\n"
|
||||
" -o <file path> Output file path (file will be written in KTX format).\n"
|
||||
" -t <format> Output format type (BC1/2/3/4/5, ETC1, PVR14, etc.).\n"
|
||||
" -q <quality> Encoding quality (default, fastest, highest).\n"
|
||||
" -m, --mips Generate mip-maps.\n"
|
||||
" -n, --normalmap Input texture is normal map.\n"
|
||||
" --sdf <edge> Compute SDF texture.\n"
|
||||
@@ -558,6 +572,20 @@ int main(int _argc, const char* _argv[])
|
||||
}
|
||||
}
|
||||
|
||||
const char* quality = cmdLine.findOption('q');
|
||||
if (NULL != quality)
|
||||
{
|
||||
switch (bx::toLower(quality[0]) )
|
||||
{
|
||||
case 'h': options.quality = bimg::Quality::Highest; break;
|
||||
case 'f': options.quality = bimg::Quality::Fastest; break;
|
||||
case 'd': options.quality = bimg::Quality::Default; break;
|
||||
default:
|
||||
help("Invalid quality specified.");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
bx::CrtFileReader reader;
|
||||
if (!bx::open(&reader, inputFileName) )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user