diff --git a/README.md b/README.md index cd86f97..dc33e8c 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,13 @@ `TinyGLTF` is a header only C++11 glTF 2.0 https://github.com/KhronosGroup/glTF library. `TinyGLTF` uses Niels Lohmann's json library(https://github.com/nlohmann/json), so now it requires C++11 compiler. -If you are looking for old, C++03 version, please use `devel-picojson` branch. +If you are looking for old, C++03 version, please use `devel-picojson` branch. ## Status -v2.0.0 release(22 Aug, 2018)! +v2.2.0 release(Support loading 16bit PNG) +v2.1.0 release(Draco support) +v2.0.0 release(22 Aug, 2018)! ## Builds @@ -38,14 +40,15 @@ v2.0.0 release(22 Aug, 2018)! * Image(Using stb_image) * [x] Parse BASE64 encoded embedded image data(DataURI). * [x] Load external image file. - * [x] PNG(8bit only) - * [x] JPEG(8bit only) - * [x] BMP - * [x] GIF + * [x] Load PNG(8bit and 16bit) + * [x] Load JPEG(8bit only) + * [x] Load BMP + * [x] Load GIF * [x] Custom Image decoder callback(e.g. for decoding OpenEXR image) * Load from memory * Custom callback handler * [x] Image load + * [x] Image save * Extensions * [x] Draco mesh decoding @@ -69,10 +72,12 @@ v2.0.0 release(22 Aug, 2018)! * [ ] Mesh Compression/decompression(Open3DGC, etc) * [x] Load Draco compressed mesh * [x] Save Draco compressed mesh + * [ ] Open3DGC? * [ ] Support `extensions` and `extras` property * [ ] HDR image? * [ ] OpenEXR extension through TinyEXR. -* [ ] Write example and tests for `animation` and `skin` +* [ ] 16bit PNG support in Serialization +* [ ] Write example and tests for `animation` and `skin` * [ ] Skinning * [ ] Morph targets @@ -104,13 +109,13 @@ Copy `stb_image.h`, `stb_image_write.h`, `json.hpp` and `tiny_gltf.h` to your pr using namespace tinygltf; -Model model; +Model model; TinyGLTF loader; std::string err; std::string warn; - + bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, argv[1]); -//bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, argv[1]); // for binary glTF(.glb) +//bool ret = loader.LoadBinaryFromFile(&model, &err, &warn, argv[1]); // for binary glTF(.glb) if (!warn.empty()) { printf("Warn: %s\n", warn.c_str()); diff --git a/tiny_gltf.h b/tiny_gltf.h index 0338ab5..d675777 100644 --- a/tiny_gltf.h +++ b/tiny_gltf.h @@ -26,6 +26,7 @@ // THE SOFTWARE. // Version: +// - v2.2.0 Add loading 16bit PNG support. // - v2.1.0 Add draco compression. // - v2.0.1 Add comparsion feature(Thanks to @Selmar). // - v2.0.0 glTF 2.0!. @@ -493,7 +494,7 @@ struct Image { int height; int component; int bits; // bit depth per channel. 8(byte), 16 or 32. - int pixel_type; // pixel type(TINYGLTF_COMPONENT_TYPE_***). usually UBYTE(bits = 8) or USHORT(bits = 16) + int pixel_type; // pixel type(TINYGLTF_COMPONENT_TYPE_***). usually UBYTE(bits = 8) or USHORT(bits = 16) std::vector image; int bufferView; // (required if no uri) std::string mimeType; // (required if no uri) ["image/jpeg", "image/png", @@ -1772,6 +1773,11 @@ bool WriteImageData(const std::string *basepath, const std::string *filename, std::vector data; if (ext == "png") { + if ((image->bits != 8) || (image->pixel_type != TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE)) { + // Unsupported pixel format + return false; + } + if (!stbi_write_png_to_func(WriteToMemory_stbi, &data, image->width, image->height, image->component, &image->image[0], 0)) { @@ -4905,7 +4911,7 @@ static void WriteBinaryGltfFile(const std::string &output, // 12 bytes for header, JSON content length, 8 bytes for JSON chunk info, padding const int length = 12 + 8 + int(content.size()) + padding_size; - + gltfFile.write(header.c_str(), header.size()); gltfFile.write(reinterpret_cast(&version), sizeof(version)); gltfFile.write(reinterpret_cast(&length), sizeof(length));