Add --linear to mipgen.

This commit is contained in:
Philip Rideout
2018-09-19 09:57:17 -07:00
parent 29e891a7b1
commit 14e1bbdf3d
2 changed files with 43 additions and 11 deletions

View File

@@ -164,6 +164,24 @@ std::unique_ptr<uint8_t[]> fromLinearTosRGB(const LinearImage& image) {
return dst;
}
// Creates a 1-channel sRGB image from a floating-point image.
template <typename T>
std::unique_ptr<uint8_t[]> fromLinearToGrayscale_sRGB(const LinearImage& image) {
const size_t w = image.getWidth();
const size_t h = image.getHeight();
assert(image.getChannels() == 1);
std::unique_ptr<uint8_t[]> dst(new uint8_t[w * h * sizeof(T)]);
T* d = reinterpret_cast<T*>(dst.get());
for (size_t y = 0; y < h; ++y) {
float const* p = image.getPixelRef(0, y);
for (size_t x = 0; x < w; ++x, ++p, ++d) {
const float gray = math::saturate(linearTosRGB(*p)) * std::numeric_limits<T>::max();
d[0] = T(gray);
}
}
return dst;
}
// Creates a 3-channel RGB u8 image from a f32 image.
// The source image can have three or more channels, but only the first three are honored.
template <typename T>