Make 4-channel versions of certain image operations. (#676)

Background: with the Vulkan backend, RGB8 textures do
not work (at least not on my hadrware). This makes me unable to run some
examples, because they use normal maps in RGB8 format.

It appears that the following commit addresses the problem by adding a
special command line option to mipgen:
8dda07bf2c

However, processing normal maps with this option does not work: certain
assertions in the image library fail.

This PR changes these functions in the image library to handle 4-channel
images instead of failing.
This commit is contained in:
nicebyte
2019-01-07 15:16:00 -08:00
committed by Romain Guy
parent 28f2806beb
commit 83c40e6664
2 changed files with 41 additions and 18 deletions

View File

@@ -18,6 +18,7 @@
#include <image/ImageOps.h>
#include <math/vec3.h>
#include <math/vec4.h>
#include <utils/Panic.h>
#include <utils/CString.h>
@@ -204,15 +205,25 @@ FilterFunction createFilterFunction(Filter ftype) {
return fn;
}
void normalize(LinearImage& image) {
ASSERT_PRECONDITION(image.getChannels() == 3, "Must be a 3-channel image.");
template <class VecT>
void normalizeImpl(LinearImage& image) {
const uint32_t width = image.getWidth(), height = image.getHeight();
auto vecs = (math::float3*) image.getPixelRef();
auto vecs = (VecT*) image.getPixelRef();
for (uint32_t n = 0; n < width * height; ++n) {
vecs[n] = normalize(vecs[n]);
}
}
void normalize(LinearImage& image) {
ASSERT_PRECONDITION(image.getChannels() == 3 || image.getChannels() == 4,
"Must be a 3 or 4 channel image");
if (image.getChannels() == 3) {
normalizeImpl<math::float3>(image);
} else {
normalizeImpl<math::float4>(image);
}
}
LinearImage resampleImage1D(const LinearImage& source, MadProgram* program,
uint32_t twidth, Filter filter, float left, float right, float filterRadiusMultiplier) {
const uint32_t swidth = source.getWidth();