// Copyright (c) Team CharLS. // SPDX-License-Identifier: BSD-3-Clause #pragma once #include #include #include #include #include struct rect_size final { rect_size(const size_t width, const size_t height) noexcept : cx(width), cy(height) { } size_t cx; size_t cy; }; std::ofstream open_output_stream(const char* filename); void fix_endian(std::vector* buffer, bool little_endian_data) noexcept; std::vector read_file(const char* filename, long offset = 0, size_t bytes = 0); void write_file(const char* filename, const void* data, size_t size); void test_file(const char* filename, int offset, rect_size size2, int bits_per_sample, int component_count, bool little_endian_file = false, int loop_count = 1); void test_round_trip(const char* name, const std::vector& decoded_buffer, rect_size size, int bits_per_sample, int component_count, int loop_count = 1); void test_round_trip(const char* name, const std::vector& original_buffer, const JlsParameters& params, int loop_count = 1); void test_portable_anymap_file(const char* filename, int loop_count = 1); /// /// Computes how many bytes are needed to hold the number of bits. /// constexpr uint32_t bit_to_byte_count(const int32_t bit_count) noexcept { return static_cast((bit_count + 7) / 8); } template void read(std::istream& input, Container& destination) { input.read(reinterpret_cast(destination.data()), static_cast(destination.size())); } template void write(std::ostream& output, const Container& source, const size_t size) { output.write(reinterpret_cast(source.data()), static_cast(size)); } class unit_test_exception final : public std::exception { }; namespace assert { inline void is_true(const bool condition) { if (!condition) throw unit_test_exception(); } } #ifdef _MSC_VER #define MSVC_WARNING_SUPPRESS(x) \ __pragma(warning(push)) __pragma(warning(disable : x)) // NOLINT(misc-macro-parentheses, bugprone-macro-parentheses) #define MSVC_WARNING_UNSUPPRESS() __pragma(warning(pop)) #define MSVC_WARNING_SUPPRESS_NEXT_LINE(x) \ __pragma(warning(suppress \ : x)) // NOLINT(misc-macro-parentheses, bugprone-macro-parentheses, cppcoreguidelines-macro-usage) #else #define MSVC_WARNING_SUPPRESS(x) #define MSVC_WARNING_UNSUPPRESS() #define MSVC_WARNING_SUPPRESS_NEXT_LINE(x) #endif // clang-format off #ifdef __clang__ #define DISABLE_DEPRECATED_WARNING \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") #elif defined(__GNUC__) || defined(__GNUG__) #define DISABLE_DEPRECATED_WARNING \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #elif defined(_MSC_VER) #define DISABLE_DEPRECATED_WARNING \ __pragma(warning(push)) \ __pragma(warning(disable : 4996)) // was declared deprecated #else #define DISABLE_DEPRECATED_WARNING #endif // clang-format on #ifdef __clang__ #define RESTORE_DEPRECATED_WARNING _Pragma("clang diagnostic pop") #elif defined(__GNUC__) || defined(__GNUG__) #define RESTORE_DEPRECATED_WARNING _Pragma("GCC diagnostic pop") #elif defined(_MSC_VER) #define RESTORE_DEPRECATED_WARNING __pragma(warning(pop)) #else #define RESTORE_DEPRECATED_WARNING #endif