Skip to content

Commit

Permalink
[Bug] default initialize layeredfile to be 1x1 rather than 0x0 (#104)
Browse files Browse the repository at this point in the history
* Default initialize layered file to 1 px

* Remove msvc runtime from main cmakelists

* Change runtime to set it up before we pull dependencies
  • Loading branch information
EmilDohne committed Sep 15, 2024
1 parent 700fb72 commit da83065
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@ option(PSAPI_BUILD_BENCHMARKS "Build the benchmarks associated with the Photosho
option(PSAPI_BUILD_DOCS "Builds the documentation, requires some external installs which are documented in the README.md" OFF)
option(PSAPI_BUILD_PYTHON "Build the python bindings associated with the PhotoshopAPI" OFF)


if (PSAPI_BUILD_PYTHON)
# Link in the msvc runtime so that users dont need vcredist when using the python bindings
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()


# Build setup
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set (CMAKE_CXX_STANDARD 20)

# Add the cmake/ folder so the FindSphinx module is found
# --------------------------------------------------------------------------
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
# Link in the msvc runtime so that users dont have to have it dynamically loaded
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")


# Add thirdparty libraries
# --------------------------------------------------------------------------
Expand Down
35 changes: 31 additions & 4 deletions PhotoshopAPI/src/LayeredFile/LayeredFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ struct LayeredFile
{
/// The root layers in the file, they may contain multiple levels of sub-layers
std::vector<std::shared_ptr<Layer<T>>> m_Layers;

/// The ICC Profile associated with the file, this may be empty in which case there will be no colour
/// profile associated with the file
ICCProfile m_ICCProfile;
Expand All @@ -508,13 +508,13 @@ struct LayeredFile
Enum::BitDepth m_BitDepth = Enum::BitDepth::BD_8;

/// The color mode of the file. Currently supports RGB only.
Enum::ColorMode m_ColorMode = Enum::ColorMode::RGB;
Enum::ColorMode m_ColorMode = Enum::ColorMode::RGB;

/// The width of the file in pixels. Can be up to 30,000 for PSD and up to 300,000 for PSB
uint64_t m_Width = 0u;
uint64_t m_Width = 1u;

/// The height of the file in pixels. Can be up to 30,000 for PSD and up to 300,000 for PSB
uint64_t m_Height = 0u;
uint64_t m_Height = 1u;

LayeredFile() = default;

Expand Down Expand Up @@ -557,20 +557,47 @@ struct LayeredFile
/// \param height The height of the file in pixels.
LayeredFile(Enum::ColorMode colorMode, uint64_t width, uint64_t height) requires std::same_as<T, uint8_t>
{
if (width < 1 || width > 300000)
{
PSAPI_LOG_ERROR("LayeredFile", "Invalid width for Photoshop file provided, must be in the range of 1-300,000 pixels. Got: %" PRIu64 " pixels", width);
}
if (height < 1 || height > 300000)
{
PSAPI_LOG_ERROR("LayeredFile", "Invalid height for Photoshop file provided, must be in the range of 1-300,000 pixels. Got: %" PRIu64 " pixels", width);
}

m_BitDepth = Enum::BitDepth::BD_8;
m_ColorMode = colorMode;
m_Width = width;
m_Height = height;
}
LayeredFile(Enum::ColorMode colorMode, uint64_t width, uint64_t height) requires std::same_as<T, uint16_t>
{
if (width < 1 || width > 300000)
{
PSAPI_LOG_ERROR("LayeredFile", "Invalid width for Photoshop file provided, must be in the range of 1-300,000 pixels. Got: %" PRIu64 " pixels", width);
}
if (height < 1 || height > 300000)
{
PSAPI_LOG_ERROR("LayeredFile", "Invalid height for Photoshop file provided, must be in the range of 1-300,000 pixels. Got: %" PRIu64 " pixels", width);
}

m_BitDepth = Enum::BitDepth::BD_16;
m_ColorMode = colorMode;
m_Width = width;
m_Height = height;
}
LayeredFile(Enum::ColorMode colorMode, uint64_t width, uint64_t height) requires std::same_as<T, float32_t>
{
if (width < 1 || width > 300000)
{
PSAPI_LOG_ERROR("LayeredFile", "Invalid width for Photoshop file provided, must be in the range of 1-300,000 pixels. Got: %" PRIu64 " pixels", width);
}
if (height < 1 || height > 300000)
{
PSAPI_LOG_ERROR("LayeredFile", "Invalid height for Photoshop file provided, must be in the range of 1-300,000 pixels. Got: %" PRIu64 " pixels", width);
}

m_BitDepth = Enum::BitDepth::BD_32;
m_ColorMode = colorMode;
m_Width = width;
Expand Down

0 comments on commit da83065

Please sign in to comment.