Browse Source

Added GNF stub.

Branimir Karadžić 8 years ago
parent
commit
1948869a48
6 changed files with 96 additions and 0 deletions
  1. 8 0
      include/bimg/bimg.h
  2. 40 0
      scripts/bimg.lua
  3. 8 0
      src/bimg_p.h
  4. 4 0
      src/image.cpp
  5. 1 0
      src/image_decode.cpp
  6. 35 0
      src/image_gnf.cpp

+ 8 - 0
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

+ 40 - 0
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

+ 8 - 0
src/bimg_p.h

@@ -12,6 +12,7 @@
 #include <bx/simd_t.h>
 
 #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

+ 4 - 0
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;

+ 1 - 0
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;

+ 35 - 0
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