Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 47 additions & 61 deletions Code/png_cicp_editor/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@
#include "FileWriter.hpp"
#include "PNGParser.hpp"

namespace {

void print_bsd_3_clause_license(const std::string_view year, const std::string_view copyright_holder) noexcept {
std::cout << "Copyright " << year << ", " << copyright_holder << R"(
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
)";
}

} // anonymous namespace

namespace PNG_CICP_Editor {

void VersionAction::operator()() const noexcept {
Expand Down Expand Up @@ -86,67 +122,17 @@ PNG puts further restrictions on which values are valid.
}

void LicenseAction::operator()() const noexcept {
std::cout << R"(Copyright 2025, The png_cicp_editor Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of png_cicp_editor nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

static const auto png_cicp_editor_year = std::string_view{"2025"};
static const auto png_cicp_editor_copyright_holder = std::string_view{"The png_cicp_editor Contributors"};
print_bsd_3_clause_license(png_cicp_editor_year, png_cicp_editor_copyright_holder);

std::cout << R"(
png_cicp_editor depends on max:
)";

Copyright 2015, The max Contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of max nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
)" << std::endl;
static const auto max_year = std::string_view{"2025"};
static const auto max_copyright_holder = std::string_view{"The max Contributors"};
print_bsd_3_clause_license(max_year, max_copyright_holder);
}

AddAction::AddAction(CICP cicp, std::string file_path) noexcept
Expand Down Expand Up @@ -184,7 +170,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


// Prepare cICP buffer to write
auto cicp_buffer = create_cicp_buffer(cicp_.color_primaries_, cicp_.transfer_function_, cicp_.matrix_coefficients_, cicp_.video_full_range_flag_);
auto cicp_buffer = create_cicp_buffer(cicp_);


// Prepare file before & after buffers for write
Expand Down Expand Up @@ -238,7 +224,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


// Prepare cICP buffer to write
auto cicp_buffer = create_cicp_buffer(cicp_.color_primaries_, cicp_.transfer_function_, cicp_.matrix_coefficients_, cicp_.video_full_range_flag_);
auto cicp_buffer = create_cicp_buffer(cicp_);


// Prepare file before & after buffers for write
Expand Down Expand Up @@ -360,7 +346,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{}

Action::Action(const Action& rhs) noexcept
: action_type_(std::move(rhs.action_type_))
: action_type_(rhs.action_type_)
, action_{.version_{}}
{
switch (action_type_) {
Expand Down
8 changes: 4 additions & 4 deletions Code/png_cicp_editor/CICP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
namespace PNG_CICP_Editor {

CICP::CICP(uint8_t color_primaries, uint8_t transfer_function, uint8_t matrix_coefficients, uint8_t video_full_range_flag) noexcept
: color_primaries_(std::move(color_primaries))
, transfer_function_(std::move(transfer_function))
, matrix_coefficients_(std::move(matrix_coefficients))
, video_full_range_flag_(std::move(video_full_range_flag))
: color_primaries_{ std::move(color_primaries) }
, transfer_function_{ std::move(transfer_function) }
, matrix_coefficients_{ std::move(matrix_coefficients) }
, video_full_range_flag_{ std::move(video_full_range_flag) }
{}

bool CICP::operator ==(const CICP& rhs) noexcept {
Expand Down
9 changes: 4 additions & 5 deletions Code/png_cicp_editor/CICP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define PNG_CICP_EDITOR_CICP_HPP

#include <cstdint>
//#include <cstdlib>

namespace PNG_CICP_Editor {

Expand All @@ -16,10 +15,10 @@ namespace PNG_CICP_Editor {
bool operator ==(const CICP& rhs) noexcept;
bool operator !=(const CICP& rhs) noexcept;

uint8_t color_primaries_ = 0;
uint8_t transfer_function_ = 0;
uint8_t matrix_coefficients_ = 0;
uint8_t video_full_range_flag_ = 1;
uint8_t color_primaries_;
uint8_t transfer_function_;
uint8_t matrix_coefficients_;
uint8_t video_full_range_flag_;
};

} // namespace PNG_CICP_Editor
Expand Down
10 changes: 5 additions & 5 deletions Code/png_cicp_editor/CICPCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace {

namespace PNG_CICP_Editor {

std::array<char, 16> create_cicp_buffer(uint8_t color_primaries, uint8_t transfer_function, uint8_t matrix_coefficients, uint8_t video_full_range_flag) noexcept {
std::array<char, 16> create_cicp_buffer(const CICP& cicp) noexcept {
std::array<char, 16> buffer;

// length
Expand All @@ -70,10 +70,10 @@ namespace PNG_CICP_Editor {
buffer[7] = 'P';

// chunk data
buffer[8] = color_primaries;
buffer[9] = transfer_function;
buffer[10] = matrix_coefficients;
buffer[11] = video_full_range_flag;
buffer[8] = cicp.color_primaries_;
buffer[9] = cicp.transfer_function_;
buffer[10] = cicp.matrix_coefficients_;
buffer[11] = cicp.video_full_range_flag_;

// crc
unsigned long calculated_crc = crc(&buffer[4], 8);
Expand Down
4 changes: 3 additions & 1 deletion Code/png_cicp_editor/CICPCreator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include <array>
#include <cstdint>

#include "CICP.hpp"

namespace PNG_CICP_Editor {

std::array<char, 16> create_cicp_buffer(uint8_t color_primaries, uint8_t transfer_function, uint8_t matrix_coefficients, uint8_t video_full_range_flag) noexcept;
std::array<char, 16> create_cicp_buffer(const CICP& cicp) noexcept;

} // namespace PNG_CICP_Editor

Expand Down
2 changes: 1 addition & 1 deletion Code/png_cicp_editor/CICPInserter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace {
static constinit std::string_view newline = "\n";


std::array<char, 4> get_chunk_type(const std::span<char>& file_contents, size_t index) noexcept {
constexpr std::array<char, 4> get_chunk_type(const std::span<char>& file_contents, size_t index) noexcept {
return {
file_contents[index + 4],
file_contents[index + 5],
Expand Down
1 change: 0 additions & 1 deletion Code/png_cicp_editor/CICPInserter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <expected>
#include <span>
#include <string_view>
#include <vector>

#include "Error.hpp"
Expand Down
Loading
Loading