mirror of
https://github.com/bkaradzic/bimg.git
synced 2026-06-08 02:43:48 +00:00
Added .ktx2 support. (#127)
This commit is contained in:
committed by
GitHub
parent
4e00d20f52
commit
43fef5f44e
@@ -209,7 +209,7 @@ namespace bimg
|
||||
bool m_hasAlpha;
|
||||
bool m_cubeMap;
|
||||
bool m_ktx;
|
||||
bool m_ktxLE;
|
||||
bool m_ktx2;
|
||||
bool m_pvr3;
|
||||
bool m_srgb;
|
||||
};
|
||||
@@ -571,6 +571,30 @@ namespace bimg
|
||||
, bx::Error* _err = NULL
|
||||
);
|
||||
|
||||
///
|
||||
int32_t imageWriteKtx2(
|
||||
bx::WriterI* _writer
|
||||
, TextureFormat::Enum _format
|
||||
, bool _cubeMap
|
||||
, uint32_t _width
|
||||
, uint32_t _height
|
||||
, uint32_t _depth
|
||||
, uint8_t _numMips
|
||||
, uint32_t _numLayers
|
||||
, bool _srgb
|
||||
, const void* _src
|
||||
, bx::Error* _err = NULL
|
||||
);
|
||||
|
||||
///
|
||||
int32_t imageWriteKtx2(
|
||||
bx::WriterI* _writer
|
||||
, ImageContainer& _imageContainer
|
||||
, const void* _data
|
||||
, uint32_t _size
|
||||
, bx::Error* _err = NULL
|
||||
);
|
||||
|
||||
///
|
||||
bool imageParse(
|
||||
ImageContainer& _imageContainer
|
||||
@@ -602,6 +626,14 @@ namespace bimg
|
||||
, bx::Error* _err
|
||||
);
|
||||
|
||||
///
|
||||
ImageContainer* imageParseKtx2(
|
||||
bx::AllocatorI* _allocator
|
||||
, const void* _src
|
||||
, uint32_t _size
|
||||
, bx::Error* _err
|
||||
);
|
||||
|
||||
///
|
||||
ImageContainer* imageParsePvr3(
|
||||
bx::AllocatorI* _allocator
|
||||
|
||||
1168
src/image.cpp
1168
src/image.cpp
File diff suppressed because it is too large
Load Diff
@@ -1135,16 +1135,38 @@ namespace bimg
|
||||
{
|
||||
BX_ERROR_SCOPE(_err);
|
||||
|
||||
ImageContainer* input = imageParseDds (_allocator, _data, _size, _err) ;
|
||||
input = NULL == input ? imageParseKtx (_allocator, _data, _size, _err) : input;
|
||||
input = NULL == input ? imageParsePvr3 (_allocator, _data, _size, _err) : input;
|
||||
input = NULL == input ? imageParseGnf (_allocator, _data, _size, _err) : input;
|
||||
input = NULL == input ? imageParseLodePng (_allocator, _data, _size, _err) : input;
|
||||
input = NULL == input ? imageParseTinyExr (_allocator, _data, _size, _err) : input;
|
||||
input = NULL == input ? imageParseJpeg (_allocator, _data, _size, _err) : input;
|
||||
input = NULL == input ? imageParseSimpleWebp(_allocator, _data, _size, _err) : input;
|
||||
input = NULL == input ? imageParseStbImage (_allocator, _data, _size, _err) : input;
|
||||
input = NULL == input ? imageParseLibHeif (_allocator, _data, _size, _err) : input;
|
||||
typedef ImageContainer* (*ImageParseFn)(bx::AllocatorI*, const void*, uint32_t, bx::Error*);
|
||||
static const ImageParseFn parsers[] =
|
||||
{
|
||||
imageParseDds,
|
||||
imageParseKtx2,
|
||||
imageParseKtx,
|
||||
imageParsePvr3,
|
||||
imageParseGnf,
|
||||
imageParseLodePng,
|
||||
imageParseTinyExr,
|
||||
imageParseJpeg,
|
||||
imageParseSimpleWebp,
|
||||
imageParseStbImage,
|
||||
imageParseLibHeif,
|
||||
};
|
||||
|
||||
ImageContainer* input = NULL;
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(parsers); ++ii)
|
||||
{
|
||||
input = parsers[ii](_allocator, _data, _size, _err);
|
||||
if (NULL != input)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// If a parser recognized the format but failed, surface its specific
|
||||
// error instead of letting the next parser overwrite it.
|
||||
if (!_err->isOk() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL == input)
|
||||
{
|
||||
|
||||
@@ -930,6 +930,7 @@ void help(const char* _error = NULL, bool _showHelp = true)
|
||||
" *.jpg (input) JPEG Interchange Format.\n"
|
||||
" *.hdr (input, output) Radiance RGBE.\n"
|
||||
" *.ktx (input, output) Khronos Texture.\n"
|
||||
" *.ktx2 (input, output) Khronos Texture 2.\n"
|
||||
" *.png (input, output) Portable Network Graphics.\n"
|
||||
" *.psd (input) Photoshop Document.\n"
|
||||
" *.pvr (input) PowerVR.\n"
|
||||
@@ -1066,6 +1067,7 @@ int main(int _argc, const char* _argv[])
|
||||
}
|
||||
|
||||
bx::StringView saveAs = cmdLine.findOption("as");
|
||||
saveAs = saveAs.isEmpty() ? bx::strFindI(outputFileName, ".ktx2") : saveAs;
|
||||
saveAs = saveAs.isEmpty() ? bx::strFindI(outputFileName, ".ktx") : saveAs;
|
||||
saveAs = saveAs.isEmpty() ? bx::strFindI(outputFileName, ".dds") : saveAs;
|
||||
saveAs = saveAs.isEmpty() ? bx::strFindI(outputFileName, ".png") : saveAs;
|
||||
@@ -1240,7 +1242,11 @@ int main(int _argc, const char* _argv[])
|
||||
bx::FileWriter writer;
|
||||
if (bx::open(&writer, outputFileName, false, &err) )
|
||||
{
|
||||
if (!bx::strFindI(saveAs, "ktx").isEmpty() )
|
||||
if (!bx::strFindI(saveAs, "ktx2").isEmpty() )
|
||||
{
|
||||
bimg::imageWriteKtx2(&writer, *output, output->m_data, output->m_size, &err);
|
||||
}
|
||||
else if (!bx::strFindI(saveAs, "ktx").isEmpty() )
|
||||
{
|
||||
bimg::imageWriteKtx(&writer, *output, output->m_data, output->m_size, &err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user