simplify a lot libibl's Image class
This commit is contained in:
committed by
Mathias Agopian
parent
13d3ade5bb
commit
7807cffc49
@@ -26,16 +26,10 @@
|
||||
namespace filament {
|
||||
namespace ibl {
|
||||
|
||||
/**
|
||||
* \deprecated
|
||||
* We are phasing out this class in favor of LinearImage. The latter has a stable and well-defined
|
||||
* pixel format, making it easier to implement image-based algorithms.
|
||||
*/
|
||||
class Image {
|
||||
public:
|
||||
Image();
|
||||
Image(std::unique_ptr<uint8_t[]> data, size_t w, size_t h,
|
||||
size_t bpr, size_t bpp, size_t channels = 3);
|
||||
Image(size_t w, size_t h, size_t stride = 0);
|
||||
|
||||
void reset();
|
||||
|
||||
@@ -51,24 +45,22 @@ public:
|
||||
|
||||
size_t getBytesPerRow() const { return mBpr; }
|
||||
|
||||
size_t getBytesPerPixel() const { return mBpp; }
|
||||
size_t getBytesPerPixel() const { return sizeof(math::float3); }
|
||||
|
||||
void* getData() const { return mData; }
|
||||
|
||||
void* getPixelRef(size_t x, size_t y) const;
|
||||
|
||||
private:
|
||||
std::unique_ptr<uint8_t[]> mOwnedData;
|
||||
void* mData = nullptr;
|
||||
size_t mBpr = 0;
|
||||
size_t mWidth = 0;
|
||||
size_t mHeight = 0;
|
||||
size_t mBpr = 0;
|
||||
size_t mBpp = 0;
|
||||
size_t mChannels = 0;
|
||||
std::unique_ptr<uint8_t[]> mOwnedData;
|
||||
void* mData = nullptr;
|
||||
};
|
||||
|
||||
inline void* Image::getPixelRef(size_t x, size_t y) const {
|
||||
return static_cast<uint8_t*>(mData) + y * mBpr + x * mBpp;
|
||||
return static_cast<uint8_t*>(mData) + y * getBytesPerRow() + x * getBytesPerPixel();
|
||||
}
|
||||
|
||||
} // namespace ibl
|
||||
|
||||
@@ -65,7 +65,7 @@ static double3 UTILS_UNUSED hemisphereUniformSample(double2 u) { // pdf = 1.0 /
|
||||
/*
|
||||
*
|
||||
* Importance sampling Charlie
|
||||
* ------------------------------------------
|
||||
* ---------------------------
|
||||
*
|
||||
* In order to pick the most significative samples and increase the convergence rate, we chose to
|
||||
* rely on Charlie's distribution function for the pdf as we do in hemisphereImportanceSampleDggx.
|
||||
@@ -167,7 +167,7 @@ static double Visibility(double NoV, double NoL, double a) {
|
||||
return 0.5 / (GGXV + GGXL);
|
||||
}
|
||||
|
||||
static double UTILS_UNUSED VisibilityAshikhmin(double NoV, double NoL, double a) {
|
||||
static double UTILS_UNUSED VisibilityAshikhmin(double NoV, double NoL, double /*a*/) {
|
||||
// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
|
||||
return 1 / (4 * (NoL + NoV - NoL * NoV));
|
||||
}
|
||||
@@ -814,7 +814,7 @@ static double DFV_Charlie_Uniform(double NoV, double linearRoughness, size_t num
|
||||
/*
|
||||
*
|
||||
* Importance sampling Charlie
|
||||
* ------------------------------------------
|
||||
* ---------------------------
|
||||
*
|
||||
* Important samples are chosen to integrate DCharlie() * cos(theta) over the hemisphere.
|
||||
*
|
||||
@@ -884,14 +884,14 @@ static double DFV_Charlie_Uniform(double NoV, double linearRoughness, size_t num
|
||||
*
|
||||
* It results that:
|
||||
*
|
||||
* 1 4 <v•h>
|
||||
* 1 4 <v•h>
|
||||
* Er() = --- ∑ DCharlie(h) V(v, l) ------------ <n•l>
|
||||
* N h DCharlie(h) <n•h>
|
||||
*
|
||||
*
|
||||
* +---------------------------------------+
|
||||
* | 4 <v•h> |
|
||||
* | Er() = --- ∑ V(v, l) --- <n•l> |
|
||||
* | Er() = --- ∑ V(v, l) ------- <n•l> |
|
||||
* | N h <n•h> |
|
||||
* +---------------------------------------+
|
||||
*
|
||||
@@ -947,7 +947,7 @@ void CubemapIBL::DFG(Image& dst, bool multiscatter, bool cloth) {
|
||||
auto dfvFunction = multiscatter ? DFV_Multiscatter : DFV;
|
||||
JobSystem& js = CubemapUtils::getJobSystem();
|
||||
auto job = jobs::parallel_for<char>(js, nullptr, nullptr, uint32_t(dst.getHeight()),
|
||||
[&dst, dfvFunction, cloth](char* d, size_t c) {
|
||||
[&dst, dfvFunction, cloth](char const* d, size_t c) {
|
||||
const size_t width = dst.getWidth();
|
||||
const size_t height = dst.getHeight();
|
||||
size_t y0 = size_t(d);
|
||||
|
||||
@@ -292,12 +292,8 @@ Image CubemapUtils::createCubemapImage(size_t dim, bool horizontal) {
|
||||
std::swap(width, height);
|
||||
}
|
||||
|
||||
size_t bpr = width * sizeof(Cubemap::Texel);
|
||||
bpr = (bpr + 31) & ~31;
|
||||
size_t bufSize = bpr * height;
|
||||
std::unique_ptr<uint8_t[]> data(new uint8_t[bufSize]);
|
||||
memset(data.get(), 0, bufSize);
|
||||
Image image(std::move(data), width, height, bpr, sizeof(Cubemap::Texel));
|
||||
Image image(width, height);
|
||||
memset(image.getData(), 0, image.getBytesPerRow() * height);
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
+6
-16
@@ -23,16 +23,12 @@ namespace ibl {
|
||||
|
||||
Image::Image() = default;
|
||||
|
||||
Image::Image(std::unique_ptr<uint8_t[]> data,
|
||||
size_t w, size_t h, size_t bpr, size_t bpp, size_t channels)
|
||||
: mOwnedData(std::move(data)),
|
||||
mData(mOwnedData.get()),
|
||||
mWidth(w),
|
||||
mHeight(h),
|
||||
mBpr(bpr),
|
||||
mBpp(bpp),
|
||||
mChannels(channels)
|
||||
{
|
||||
Image::Image(size_t w, size_t h, size_t stride)
|
||||
: mBpr((stride ? stride : w) * sizeof(math::float3)),
|
||||
mWidth(w),
|
||||
mHeight(h),
|
||||
mOwnedData(new uint8_t[mBpr * h]),
|
||||
mData(mOwnedData.get()) {
|
||||
}
|
||||
|
||||
void Image::reset() {
|
||||
@@ -40,8 +36,6 @@ void Image::reset() {
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mBpr = 0;
|
||||
mBpp = 0;
|
||||
mChannels = 0;
|
||||
mData = nullptr;
|
||||
}
|
||||
|
||||
@@ -50,8 +44,6 @@ void Image::set(Image const& image) {
|
||||
mWidth = image.mWidth;
|
||||
mHeight = image.mHeight;
|
||||
mBpr = image.mBpr;
|
||||
mBpp = image.mBpp;
|
||||
mChannels = image.mChannels;
|
||||
mData = image.mData;
|
||||
}
|
||||
|
||||
@@ -60,8 +52,6 @@ void Image::subset(Image const& image, size_t x, size_t y, size_t w, size_t h) {
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
mBpr = image.mBpr;
|
||||
mBpp = image.mBpp;
|
||||
mChannels = image.mChannels;
|
||||
mData = static_cast<uint8_t*>(image.getPixelRef(x, y));
|
||||
}
|
||||
|
||||
|
||||
@@ -489,12 +489,9 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Convert from LinearImage to the deprecated Image object which is used throughout cmgen.
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[
|
||||
linputImage.getWidth() * linputImage.getHeight() * sizeof(float3)]);
|
||||
const size_t width = linputImage.getWidth(), height = linputImage.getHeight();
|
||||
const size_t bpp = sizeof(float) * 3, bpr = bpp * width;
|
||||
memcpy(buf.get(), linputImage.getPixelRef(), height * bpr);
|
||||
Image inputImage(std::move(buf), width, height, bpr, bpp);
|
||||
Image inputImage(width, height);
|
||||
memcpy(inputImage.getData(), linputImage.getPixelRef(), height * inputImage.getBytesPerRow());
|
||||
|
||||
CubemapUtils::clamp(inputImage);
|
||||
|
||||
@@ -782,8 +779,7 @@ void iblMipmapPrefilter(const utils::Path& iname,
|
||||
|
||||
if (g_type == OutputType::EQUIRECT) {
|
||||
size_t dim = dst.getDimensions();
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[dim * 2 * dim * sizeof(float3)]);
|
||||
Image image(std::move(buf), dim * 2, dim, dim * 2 * sizeof(float3), sizeof(float3));
|
||||
Image image(dim * 2, dim);
|
||||
CubemapUtils::cubemapToEquirectangular(image, dst);
|
||||
std::string filename = outputDir + ("is_m" + std::to_string(level) + ext);
|
||||
saveImage(filename, g_format, image, g_compression);
|
||||
@@ -792,8 +788,7 @@ void iblMipmapPrefilter(const utils::Path& iname,
|
||||
|
||||
if (g_type == OutputType::OCTAHEDRON) {
|
||||
size_t dim = dst.getDimensions();
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[dim * dim * sizeof(float3)]);
|
||||
Image image(std::move(buf), dim, dim, dim * sizeof(float3), sizeof(float3));
|
||||
Image image(dim, dim);
|
||||
CubemapUtils::cubemapToOctahedron(image, dst);
|
||||
std::string filename = outputDir + ("is_m" + std::to_string(level) + ext);
|
||||
saveImage(filename, g_format, image, g_compression);
|
||||
@@ -898,8 +893,7 @@ void iblRoughnessPrefilter(const utils::Path& iname,
|
||||
}
|
||||
|
||||
if (g_type == OutputType::EQUIRECT) {
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[dim * 2 * dim * sizeof(float3)]);
|
||||
Image outImage(std::move(buf), dim * 2, dim, dim * 2 * sizeof(float3), sizeof(float3));
|
||||
Image outImage(dim * 2, dim);
|
||||
CubemapUtils::cubemapToEquirectangular(outImage, dst);
|
||||
std::string filename = outputDir + ("m" + std::to_string(level) + ext);
|
||||
saveImage(filename, g_format, outImage, g_compression);
|
||||
@@ -907,8 +901,7 @@ void iblRoughnessPrefilter(const utils::Path& iname,
|
||||
}
|
||||
|
||||
if (g_type == OutputType::OCTAHEDRON) {
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[dim * dim * sizeof(float3)]);
|
||||
Image outImage(std::move(buf), dim, dim, dim * sizeof(float3), sizeof(float3));
|
||||
Image outImage(dim, dim);
|
||||
CubemapUtils::cubemapToOctahedron(outImage, dst);
|
||||
std::string filename = outputDir + ("m" + std::to_string(level) + ext);
|
||||
saveImage(filename, g_format, outImage, g_compression);
|
||||
@@ -1009,8 +1002,7 @@ static bool isIncludeFile(const utils::Path& filename) {
|
||||
}
|
||||
|
||||
void iblLutDfg(const utils::Path& filename, size_t size, bool multiscatter, bool cloth) {
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[size * size * sizeof(float3)]);
|
||||
Image image(std::move(buf), size, size, size * sizeof(float3), sizeof(float3));
|
||||
Image image(size, size);
|
||||
CubemapIBL::DFG(image, multiscatter, cloth);
|
||||
|
||||
utils::Path outputDir(filename.getAbsolutePath().getParent());
|
||||
@@ -1089,8 +1081,7 @@ void extractCubemapFaces(const utils::Path& iname, const Cubemap& cm, const util
|
||||
|
||||
if (g_type == OutputType::EQUIRECT) {
|
||||
size_t dim = cm.getDimensions();
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[dim * 2 * dim * sizeof(float3)]);
|
||||
Image image(std::move(buf), dim * 2, dim, dim * 2 * sizeof(float3), sizeof(float3));
|
||||
Image image(dim * 2, dim);
|
||||
CubemapUtils::cubemapToEquirectangular(image, cm);
|
||||
std::string filename = outputDir + ("skybox" + ext);
|
||||
saveImage(filename, g_format, image, g_compression);
|
||||
@@ -1099,8 +1090,7 @@ void extractCubemapFaces(const utils::Path& iname, const Cubemap& cm, const util
|
||||
|
||||
if (g_type == OutputType::OCTAHEDRON) {
|
||||
size_t dim = cm.getDimensions();
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[dim * dim * sizeof(float3)]);
|
||||
Image image(std::move(buf), dim, dim, dim * sizeof(float3), sizeof(float3));
|
||||
Image image(dim, dim);
|
||||
CubemapUtils::cubemapToOctahedron(image, cm);
|
||||
std::string filename = outputDir + ("skybox" + ext);
|
||||
saveImage(filename, g_format, image, g_compression);
|
||||
|
||||
Reference in New Issue
Block a user