Skip to content

Commit

Permalink
Merge pull request #14 from V-Sekai/write-png
Browse files Browse the repository at this point in the history
Always write png instead of jpg.
  • Loading branch information
fire authored May 23, 2022
2 parents 815c19e + 3d8bd0e commit 869ac2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:

- name: Conan install
run: |
conan install . --build=missing -i build -s build_type=Release -s compiler="Visual Studio"
conan install . -i build -s build_type=Release -s compiler="Visual Studio" --build missing
shell: cmd

- name: Conan build
Expand Down Expand Up @@ -171,7 +171,7 @@ jobs:

- name: Conan install
run: |
conan install . -i build -s build_type=Release --build fmt -s compiler.libcxx=libstdc++11
conan install . -i build -s build_type=Release --build fmt -s compiler.libcxx=libstdc++11 --build missing
shell: bash

- name: Conan build
Expand Down Expand Up @@ -276,7 +276,7 @@ jobs:

- name: Conan install
run: |
env CMAKE_OSX_ARCHITECTURES=x86_64 conan install . -i build -s build_type=Release --build missing --settings arch=x86_64
env CMAKE_OSX_ARCHITECTURES=x86_64 conan install . -i build -s build_type=Release --settings arch=x86_64 --build missing
shell: bash

- name: Conan build
Expand Down
29 changes: 10 additions & 19 deletions src/gltf/TextureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,15 @@ std::shared_ptr<TextureData> TextureBuilder::combine(
}
}

// write a .png iff we need transparency in the destination texture
bool png = includeAlphaChannel;

std::vector<char> imgBuffer;
int res;
if (png) {
res = stbi_write_png_to_func(
WriteToVectorContext,
&imgBuffer,
width,
height,
channels,
mergedPixels.data(),
width * channels);
} else {
res = stbi_write_jpg_to_func(
WriteToVectorContext, &imgBuffer, width, height, channels, mergedPixels.data(), 80);
}
int res = stbi_write_png_to_func(
WriteToVectorContext,
&imgBuffer,
width,
height,
channels,
mergedPixels.data(),
width * channels);
if (!res) {
fmt::printf("Warning: failed to generate merge texture '%s'.\n", mergedFilename);
return nullptr;
Expand All @@ -145,9 +136,9 @@ std::shared_ptr<TextureData> TextureBuilder::combine(
if (options.outputBinary && !options.separateTextures) {
const auto bufferView =
gltf.AddRawBufferView(*gltf.defaultBuffer, imgBuffer.data(), to_uint32(imgBuffer.size()));
image = new ImageData(mergedName, *bufferView, png ? "image/png" : "image/jpeg");
image = new ImageData(mergedName, *bufferView, "image/png");
} else {
const std::string imageFilename = mergedFilename + (png ? ".png" : ".jpg");
const std::string imageFilename = mergedFilename + (".png");
const std::string imagePath = outputFolder + imageFilename;
FILE* fp = fopen(imagePath.c_str(), "wb");
if (fp == nullptr) {
Expand Down

0 comments on commit 869ac2e

Please sign in to comment.