mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 15:05:58 +08:00
Merge pull request #92 from walf443/respect_stb_image_write_error
handling stbi_write_xxx_to_func return code
This commit is contained in:
commit
098dfee982
19
tiny_gltf.h
19
tiny_gltf.h
@ -1385,18 +1385,24 @@ 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") {
|
||||||
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->image[0],
|
image->height, image->component, &image->image[0],
|
||||||
0);
|
0)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
header = "data:image/png;base64,";
|
header = "data:image/png;base64,";
|
||||||
} else if (ext == "jpg") {
|
} else if (ext == "jpg") {
|
||||||
stbi_write_jpg_to_func(WriteToMemory_stbi, &data, image->width,
|
if (!stbi_write_jpg_to_func(WriteToMemory_stbi, &data, image->width,
|
||||||
image->height, image->component, &image->image[0],
|
image->height, image->component, &image->image[0],
|
||||||
100);
|
100)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
header = "data:image/jpeg;base64,";
|
header = "data:image/jpeg;base64,";
|
||||||
} else if (ext == "bmp") {
|
} else if (ext == "bmp") {
|
||||||
stbi_write_bmp_to_func(WriteToMemory_stbi, &data, image->width,
|
if (!stbi_write_bmp_to_func(WriteToMemory_stbi, &data, image->width,
|
||||||
image->height, image->component, &image->image[0]);
|
image->height, image->component, &image->image[0])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
header = "data:image/bmp;base64,";
|
header = "data:image/bmp;base64,";
|
||||||
} else if (!embedImages) {
|
} else if (!embedImages) {
|
||||||
// Error: can't output requested format to file
|
// Error: can't output requested format to file
|
||||||
@ -1421,6 +1427,7 @@ bool WriteImageData(const std::string *basepath, const std::string *filename,
|
|||||||
if (!fs->WriteWholeFile(&writeError, imagefilepath, data,
|
if (!fs->WriteWholeFile(&writeError, imagefilepath, data,
|
||||||
fs->user_data)) {
|
fs->user_data)) {
|
||||||
// Could not write image file to disc; Throw error ?
|
// Could not write image file to disc; Throw error ?
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Throw error?
|
// Throw error?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user