mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-03 10:50:39 +08:00
Update README.
Check bit depth when saving image as PNG.
This commit is contained in:
parent
8fd91aea04
commit
e8a46c4e1d
25
README.md
25
README.md
@ -3,11 +3,13 @@
|
|||||||
`TinyGLTF` is a header only C++11 glTF 2.0 https://github.com/KhronosGroup/glTF library.
|
`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.
|
`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
|
## 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
|
## Builds
|
||||||
|
|
||||||
@ -38,14 +40,15 @@ v2.0.0 release(22 Aug, 2018)!
|
|||||||
* Image(Using stb_image)
|
* Image(Using stb_image)
|
||||||
* [x] Parse BASE64 encoded embedded image data(DataURI).
|
* [x] Parse BASE64 encoded embedded image data(DataURI).
|
||||||
* [x] Load external image file.
|
* [x] Load external image file.
|
||||||
* [x] PNG(8bit only)
|
* [x] Load PNG(8bit and 16bit)
|
||||||
* [x] JPEG(8bit only)
|
* [x] Load JPEG(8bit only)
|
||||||
* [x] BMP
|
* [x] Load BMP
|
||||||
* [x] GIF
|
* [x] Load GIF
|
||||||
* [x] Custom Image decoder callback(e.g. for decoding OpenEXR image)
|
* [x] Custom Image decoder callback(e.g. for decoding OpenEXR image)
|
||||||
* Load from memory
|
* Load from memory
|
||||||
* Custom callback handler
|
* Custom callback handler
|
||||||
* [x] Image load
|
* [x] Image load
|
||||||
|
* [x] Image save
|
||||||
* Extensions
|
* Extensions
|
||||||
* [x] Draco mesh decoding
|
* [x] Draco mesh decoding
|
||||||
|
|
||||||
@ -69,10 +72,12 @@ v2.0.0 release(22 Aug, 2018)!
|
|||||||
* [ ] Mesh Compression/decompression(Open3DGC, etc)
|
* [ ] Mesh Compression/decompression(Open3DGC, etc)
|
||||||
* [x] Load Draco compressed mesh
|
* [x] Load Draco compressed mesh
|
||||||
* [x] Save Draco compressed mesh
|
* [x] Save Draco compressed mesh
|
||||||
|
* [ ] Open3DGC?
|
||||||
* [ ] Support `extensions` and `extras` property
|
* [ ] Support `extensions` and `extras` property
|
||||||
* [ ] HDR image?
|
* [ ] HDR image?
|
||||||
* [ ] OpenEXR extension through TinyEXR.
|
* [ ] 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
|
* [ ] Skinning
|
||||||
* [ ] Morph targets
|
* [ ] 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;
|
using namespace tinygltf;
|
||||||
|
|
||||||
Model model;
|
Model model;
|
||||||
TinyGLTF loader;
|
TinyGLTF loader;
|
||||||
std::string err;
|
std::string err;
|
||||||
std::string warn;
|
std::string warn;
|
||||||
|
|
||||||
bool ret = loader.LoadASCIIFromFile(&model, &err, &warn, argv[1]);
|
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()) {
|
if (!warn.empty()) {
|
||||||
printf("Warn: %s\n", warn.c_str());
|
printf("Warn: %s\n", warn.c_str());
|
||||||
|
10
tiny_gltf.h
10
tiny_gltf.h
@ -26,6 +26,7 @@
|
|||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
// Version:
|
// Version:
|
||||||
|
// - v2.2.0 Add loading 16bit PNG support.
|
||||||
// - v2.1.0 Add draco compression.
|
// - v2.1.0 Add draco compression.
|
||||||
// - v2.0.1 Add comparsion feature(Thanks to @Selmar).
|
// - v2.0.1 Add comparsion feature(Thanks to @Selmar).
|
||||||
// - v2.0.0 glTF 2.0!.
|
// - v2.0.0 glTF 2.0!.
|
||||||
@ -493,7 +494,7 @@ struct Image {
|
|||||||
int height;
|
int height;
|
||||||
int component;
|
int component;
|
||||||
int bits; // bit depth per channel. 8(byte), 16 or 32.
|
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<unsigned char> image;
|
std::vector<unsigned char> image;
|
||||||
int bufferView; // (required if no uri)
|
int bufferView; // (required if no uri)
|
||||||
std::string mimeType; // (required if no uri) ["image/jpeg", "image/png",
|
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<unsigned char> data;
|
std::vector<unsigned char> data;
|
||||||
|
|
||||||
if (ext == "png") {
|
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,
|
if (!stbi_write_png_to_func(WriteToMemory_stbi, &data, image->width,
|
||||||
image->height, image->component,
|
image->height, image->component,
|
||||||
&image->image[0], 0)) {
|
&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
|
// 12 bytes for header, JSON content length, 8 bytes for JSON chunk info, padding
|
||||||
const int length = 12 + 8 + int(content.size()) + padding_size;
|
const int length = 12 + 8 + int(content.size()) + padding_size;
|
||||||
|
|
||||||
gltfFile.write(header.c_str(), header.size());
|
gltfFile.write(header.c_str(), header.size());
|
||||||
gltfFile.write(reinterpret_cast<const char *>(&version), sizeof(version));
|
gltfFile.write(reinterpret_cast<const char *>(&version), sizeof(version));
|
||||||
gltfFile.write(reinterpret_cast<const char *>(&length), sizeof(length));
|
gltfFile.write(reinterpret_cast<const char *>(&length), sizeof(length));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user