/* * Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. * * NVIDIA CORPORATION and its licensors retain all intellectual property * and proprietary rights in and to this software, related documentation * and any modifications thereto. Any use, reproduction, disclosure or * distribution of this software and related documentation without an express * license agreement from NVIDIA CORPORATION is strictly prohibited. */ /** @file common_device.cu * @author Thomas Müller, NVIDIA */ #include #include #include #include using namespace Eigen; using namespace tcnn; NGP_NAMESPACE_BEGIN Matrix log_space_lerp(const Matrix& begin, const Matrix& end, float t) { Matrix4f A = Matrix4f::Identity(); A.block<3,4>(0,0) = begin; Matrix4f B = Matrix4f::Identity(); B.block<3,4>(0,0) = end; Matrix4f log_space_a_to_b = (B * A.inverse()).log(); return ((log_space_a_to_b * t).exp() * A).block<3,4>(0,0); } GPUMemory load_exr(const std::string& filename, int& width, int& height) { float* out; // width * height * RGBA load_exr(&out, &width, &height, filename.c_str()); ScopeGuard mem_guard{[&]() { free(out); }}; GPUMemory result(width * height * 4); result.copy_from_host(out); return result; } GPUMemory load_stbi(const std::string& filename, int& width, int& height) { bool is_hdr = stbi_is_hdr(filename.c_str()); void* data; // width * height * RGBA int comp; if (is_hdr) { data = stbi_loadf(filename.c_str(), &width, &height, &comp, 4); } else { data = stbi_load(filename.c_str(), &width, &height, &comp, 4); } if (!data) { throw std::runtime_error{std::string{stbi_failure_reason()}}; } ScopeGuard mem_guard{[&]() { stbi_image_free(data); }}; if (width == 0 || height == 0) { throw std::runtime_error{"Image has zero pixels."}; } GPUMemory result(width * height * 4); if (is_hdr) { result.copy_from_host((float*)data); } else { GPUMemory bytes(width * height * 4); bytes.copy_from_host((uint8_t*)data); linear_kernel(from_rgba32, 0, nullptr, width * height, bytes.data(), result.data(), false, false, 0); } return result; } NGP_NAMESPACE_END