Skip to content
Snippets Groups Projects
Commit e48bd290 authored by mbellgardt's avatar mbellgardt
Browse files

Merge branch 'feature/#323_default_image' into 'master'

Add implementation for default fuchsia image

See merge request VR-Group/Project_Phoenix!150
parents a205059d 8dc6c9b4
Branches
No related tags found
1 merge request!150Add implementation for default fuchsia image
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "phx/core/logger.hpp"
namespace phx { namespace phx {
std::once_flag Image::once_flag_; std::once_flag Image::once_flag_;
...@@ -46,7 +48,20 @@ Image::Image(const std::string& filepath, const std::int32_t native_flags) { ...@@ -46,7 +48,20 @@ Image::Image(const std::string& filepath, const std::int32_t native_flags) {
format = FreeImage_GetFIFFromFilename(filepath.c_str()); format = FreeImage_GetFIFFromFilename(filepath.c_str());
native_ = FreeImage_Load(format, filepath.c_str(), native_flags); native_ = FreeImage_Load(format, filepath.c_str(), native_flags);
if (!native_) throw std::runtime_error("FreeImage_Load failed."); if (!native_) {
error(
"FreeImage_Load failed for path {}. A default 1x1 fuchsia image is "
"used instead.",
filepath);
native_ = FreeImage_AllocateT(FIT_BITMAP, static_cast<std::int32_t>(1),
static_cast<std::int32_t>(1),
static_cast<std::int32_t>(32), 0, 0, 0);
std::array<std::uint8_t, 4> fuchsia_pixel = {{255u, 0u, 255u, 255u}};
FreeImage_SetPixelColor(native_, 0, 0,
reinterpret_cast<RGBQUAD*>(fuchsia_pixel.data()));
}
SwapRedBlue(native_); SwapRedBlue(native_);
} }
Image::Image(const Image& that) Image::Image(const Image& that)
......
...@@ -173,3 +173,22 @@ SCENARIO("Images can be loaded from and saved to disk.", "[phx][phx::Image]") { ...@@ -173,3 +173,22 @@ SCENARIO("Images can be loaded from and saved to disk.", "[phx][phx::Image]") {
} }
} }
} }
SCENARIO(
"When the filepath of an image does not exist, a default image is "
"generated.",
"[phx][phx::Image]") {
WHEN("We load an Image from an invalid filepath.") {
auto invalid_image = std::make_unique<phx::Image>("This is nonsense");
THEN("The image is a 1x1 fuchsia image.") {
auto dimensions = invalid_image->GetDimensions();
auto pixel = invalid_image->GetPixelColor({{0, 0}});
std::array<std::uint8_t, 4> fuchsia_pixel = {{255u, 0u, 255u, 255u}};
REQUIRE(dimensions[0] == 1);
REQUIRE(dimensions[1] == 1);
REQUIRE(pixel == fuchsia_pixel);
}
}
}
...@@ -35,11 +35,15 @@ ...@@ -35,11 +35,15 @@
#include <tuple> #include <tuple>
#include <utility> #include <utility>
#include "boost/filesystem/operations.hpp"
#include "boost/filesystem/path.hpp"
#include "catch/catch.hpp" #include "catch/catch.hpp"
#include "phx/core/logger.hpp"
#include "phx/rendering/backend/opengl_image_buffer_data.hpp" #include "phx/rendering/backend/opengl_image_buffer_data.hpp"
#include "phx/resources/types/image.hpp"
#include "phx/resources/resource_manager.hpp" #include "phx/resources/resource_manager.hpp"
#include "phx/resources/types/image.hpp"
#include "test_utilities/reference_image_path.hpp" #include "test_utilities/reference_image_path.hpp"
...@@ -217,9 +221,14 @@ void OpenGLBufferComparison::REQUIRE_REFERENCE_IMAGE_SIMILARITY( ...@@ -217,9 +221,14 @@ void OpenGLBufferComparison::REQUIRE_REFERENCE_IMAGE_SIMILARITY(
phx::ResourceUtils::DeclarationFromFile( phx::ResourceUtils::DeclarationFromFile(
filename_with_path, {{"bit_format", bit_format}}, true)); filename_with_path, {{"bit_format", bit_format}}, true));
if (boost::filesystem::exists(boost::filesystem::path(filename_with_path))) {
try { try {
image.Load(); image.Load();
} catch (const std::exception&) { } catch (const std::exception&) {
phx::error(
"Unexpected exception while loading the reference image. File exists "
"but may be corrupted.");
}
} }
similarity = ComputeSimilarity(buffer_test, image.Get()); similarity = ComputeSimilarity(buffer_test, image.Get());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment