diff --git a/include/bimg/bimg.h b/include/bimg/bimg.h index d4b1302..bf840f7 100644 --- a/include/bimg/bimg.h +++ b/include/bimg/bimg.h @@ -533,6 +533,14 @@ namespace bimg , bx::Error* _err ); + /// + ImageContainer* imageParseGnf( + bx::AllocatorI* _allocator + , const void* _src + , uint32_t _size + , bx::Error* _err + ); + /// void imageDecodeToR8( bx::AllocatorI* _allocator diff --git a/scripts/bimg.lua b/scripts/bimg.lua index b1f56d1..835722d 100644 --- a/scripts/bimg.lua +++ b/scripts/bimg.lua @@ -3,6 +3,38 @@ -- License: https://github.com/bkaradzic/bx#license-bsd-2-clause -- +function filesexist(_srcPath, _dstPath, _files) + for _, file in ipairs(_files) do + file = path.getrelative(_srcPath, file) + local filePath = path.join(_dstPath, file) + if not os.isfile(filePath) then return false end + end + + return true +end + +function overridefiles(_srcPath, _dstPath, _files) + + local remove = {} + local add = {} + for _, file in ipairs(_files) do + file = path.getrelative(_srcPath, file) + local filePath = path.join(_dstPath, file) + if not os.isfile(filePath) then return end + + table.insert(remove, path.join(_srcPath, file)) + table.insert(add, filePath) + end + + removefiles { + remove, + } + + files { + add, + } +end + project "bimg" kind "StaticLib" @@ -16,9 +48,17 @@ project "bimg" path.join(BIMG_DIR, "src/image.*"), } + overridefiles(BIMG_DIR, path.join(BIMG_DIR, "../bimg-ext"), { + path.join(BIMG_DIR, "src/image_gnf.cpp"), + }) + configuration { "linux-*" } buildoptions { "-fPIC", } configuration {} + + if filesexist(BIMG_DIR, path.join(BIMG_DIR, "../bimg-ext"), { path.join(BIMG_DIR, "scripts/bimg.lua"), }) then + dofile(path.join(BIMG_DIR, "../bimg-ext/scripts/bimg.lua") ) + end diff --git a/src/bimg_p.h b/src/bimg_p.h index 45baeaa..ef73940 100644 --- a/src/bimg_p.h +++ b/src/bimg_p.h @@ -12,6 +12,7 @@ #include #define BIMG_CHUNK_MAGIC_TEX BX_MAKEFOURCC('T', 'E', 'X', 0x0) +#define BIMG_CHUNK_MAGIC_GNF BX_MAKEFOURCC('G', 'N', 'F', ' ') BX_ERROR_RESULT(BIMG_ERROR, BX_MAKEFOURCC('b', 'i', 'm', 'g') ); @@ -71,4 +72,11 @@ namespace bimg , uint32_t _srcPitch ); + /// + bool imageParseGnf( + ImageContainer& _imageContainer + , bx::ReaderSeekerI* _reader + , bx::Error* _err + ); + } // namespace bimg diff --git a/src/image.cpp b/src/image.cpp index 9b34985..eb1b78c 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -2728,6 +2728,10 @@ namespace bimg { return imageParsePvr3(_imageContainer, _reader, _err); } + else if (BIMG_CHUNK_MAGIC_GNF == magic) + { + return imageParseGnf(_imageContainer, _reader, _err); + } else if (BIMG_CHUNK_MAGIC_TEX == magic) { TextureCreate tc; diff --git a/src/image_decode.cpp b/src/image_decode.cpp index 37038f3..99d13c2 100644 --- a/src/image_decode.cpp +++ b/src/image_decode.cpp @@ -661,6 +661,7 @@ namespace bimg 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; diff --git a/src/image_gnf.cpp b/src/image_gnf.cpp new file mode 100644 index 0000000..1e69899 --- /dev/null +++ b/src/image_gnf.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2011-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#include "bimg_p.h" + +namespace bimg +{ + bool imageParseGnf(ImageContainer& _imageContainer, bx::ReaderSeekerI* _reader, bx::Error* _err) + { + BX_UNUSED(_imageContainer, _reader, _err); + BX_ERROR_SET(_err, BIMG_ERROR, "GNF: not supported."); + return false; + } + + ImageContainer* imageParseGnf(bx::AllocatorI* _allocator, const void* _src, uint32_t _size, bx::Error* _err) + { + bx::MemoryReader reader(_src, _size); + + uint32_t magic; + bx::read(&reader, magic); + + ImageContainer imageContainer; + if (BIMG_CHUNK_MAGIC_GNF != magic + || !imageParseGnf(imageContainer, &reader, _err) ) + { + return NULL; + } + + BX_ERROR_SET(_err, BIMG_ERROR, "GNF: not supported."); + return false; + } + +} // namespace bimg