From 466ffc07f67faf0cd8c207d8efe1726b3a3716e4 Mon Sep 17 00:00:00 2001 From: Ram Mohan Date: Wed, 1 Nov 2023 02:46:57 +0530 Subject: [PATCH] add support for building on windows platform cmake -G "MinGW Makefiles" -DUHDR_BUILD_TESTS=1 ../ cmake --build ./ --- CMakeLists.txt | 84 +++++++----- examples/ultrahdr_app.cpp | 30 ++++- lib/jpegr.cpp | 126 ++++++++++-------- tests/jpegdecoderhelper_test.cpp | 37 ++--- tests/jpegencoderhelper_test.cpp | 37 ++--- tests/jpegr_test.cpp | 26 +++- .../includes/image_io/base/data_range.h | 4 +- third_party/image_io/src/utils/file_utils.cc | 6 +- 8 files changed, 204 insertions(+), 146 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 09ba3e5b..50862dca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ project(UltraHdr C CXX) # Detect system ########################################################### if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") +elseif(WIN32) elseif(APPLE) else() message(FATAL_ERROR "Platform not supported") @@ -84,39 +85,50 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -add_compile_options(-ffunction-sections) -add_compile_options(-fdata-sections) -add_compile_options(-fomit-frame-pointer) -if(ARCH STREQUAL "x86") - add_compile_options(-m32) - add_compile_options(-march=pentium4) - add_compile_options(-mtune=generic) -endif() -if(ARCH STREQUAL "x86_64") - add_compile_options(-m64) - add_compile_options(-march=x86-64) - add_compile_options(-mtune=generic) -endif() - -include(CheckCXXCompilerFlag) -function(CheckCompilerOption opt res) - set(CMAKE_REQUIRED_FLAGS ${opt}) - check_cxx_compiler_flag(${opt} ${res}) - unset(CMAKE_REQUIRED_FLAGS) - if(NOT ${res}) - message(FATAL_ERROR "Unsupported compiler option(s) ${opt}") +if(MSVC) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + # Disable specific warnings + # TODO: None of these should be disabled, but for now,for a warning-free msvc build these are + # added. fix the warnings and remove these filters + add_compile_options(/wd4244) # conversion from 'type1' to 'type2', possible loss of data + add_compile_options(/wd4267) # conversion from 'size_t' to 'type' possible loss of data + add_compile_options(/wd4305) # truncation from 'double' to 'float' + add_compile_options(/wd4838) # conversion from 'type1' to 'type2' requires a narrowing conversion +else() + add_compile_options(-ffunction-sections) + add_compile_options(-fdata-sections) + add_compile_options(-fomit-frame-pointer) + if(ARCH STREQUAL "x86") + add_compile_options(-m32) + add_compile_options(-march=pentium4) + add_compile_options(-mtune=generic) + endif() + if(ARCH STREQUAL "x86_64") + add_compile_options(-m64) + add_compile_options(-march=x86-64) + add_compile_options(-mtune=generic) endif() -endfunction(CheckCompilerOption) -if(DEFINED UHDR_SANITIZE_OPTIONS) - CheckCompilerOption("-fsanitize=${UHDR_SANITIZE_OPTIONS}" SUPPORTS_SAN_OPTIONS) - add_compile_options(-fsanitize=${UHDR_SANITIZE_OPTIONS}) - add_link_options(-fsanitize=${UHDR_SANITIZE_OPTIONS}) -endif() + include(CheckCXXCompilerFlag) + function(CheckCompilerOption opt res) + set(CMAKE_REQUIRED_FLAGS ${opt}) + check_cxx_compiler_flag(${opt} ${res}) + unset(CMAKE_REQUIRED_FLAGS) + if(NOT ${res}) + message(FATAL_ERROR "Unsupported compiler option(s) ${opt}") + endif() + endfunction(CheckCompilerOption) -if(UHDR_BUILD_FUZZERS) - CheckCompilerOption("-fsanitize=fuzzer-no-link" fuzz) - add_compile_options(-fsanitize=fuzzer-no-link) + if(DEFINED UHDR_SANITIZE_OPTIONS) + CheckCompilerOption("-fsanitize=${UHDR_SANITIZE_OPTIONS}" SUPPORTS_SAN_OPTIONS) + add_compile_options(-fsanitize=${UHDR_SANITIZE_OPTIONS}) + add_link_options(-fsanitize=${UHDR_SANITIZE_OPTIONS}) + endif() + + if(UHDR_BUILD_FUZZERS) + CheckCompilerOption("-fsanitize=fuzzer-no-link" fuzz) + add_compile_options(-fsanitize=fuzzer-no-link) + endif() endif() if(UHDR_ENABLE_LOGS) @@ -228,10 +240,14 @@ if(UHDR_BUILD_TESTS) target_link_options(ultrahdr_unit_test PRIVATE -fsanitize=fuzzer-no-link) endif() target_link_libraries(ultrahdr_unit_test ultrahdr ${GTEST_BOTH_LIBRARIES}) - execute_process(COMMAND cmake -E create_symlink - "${TESTS_DIR}/data/" - "${CMAKE_CURRENT_BINARY_DIR}/data" - ) + if(WIN32) + file(COPY "${TESTS_DIR}/data/" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/data") + else() + execute_process(COMMAND cmake -E create_symlink + "${TESTS_DIR}/data/" + "${CMAKE_CURRENT_BINARY_DIR}/data" + ) + endif() add_test(NAME UHDRUnitTests, COMMAND ultrahdr_unit_test) endif() diff --git a/examples/ultrahdr_app.cpp b/examples/ultrahdr_app.cpp index 25170c94..e24d64b7 100644 --- a/examples/ultrahdr_app.cpp +++ b/examples/ultrahdr_app.cpp @@ -14,8 +14,12 @@ * limitations under the License. */ +#ifdef _MSC_VER +#include +#else #include #include +#endif #include #include @@ -57,7 +61,26 @@ const float BT2020RGBtoYUVMatrix[9] = {0.2627, (-0.6780 / 1.4746), (-0.0593 / 1.4746)}; -//#define PROFILE_ENABLE 1 +#ifdef _MSC_VER +class Profiler { + public: + void timerStart() { QueryPerformanceCounter(&mStartingTime); } + + void timerStop() { QueryPerformanceCounter(&mEndingTime); } + + int64_t elapsedTime() { + LARGE_INTEGER frequency; + LARGE_INTEGER elapsedMicroseconds; + QueryPerformanceFrequency(&frequency); + elapsedMicroseconds.QuadPart = mEndingTime.QuadPart - mStartingTime.QuadPart; + return (double)elapsedMicroseconds.QuadPart / (double)frequency.QuadPart * 1000000; + } + + private: + LARGE_INTEGER mStartingTime; + LARGE_INTEGER mEndingTime; +}; +#else class Profiler { public: void timerStart() { gettimeofday(&mStartingTime, nullptr); } @@ -75,6 +98,7 @@ class Profiler { struct timeval mStartingTime; struct timeval mEndingTime; }; +#endif static bool loadFile(const char* filename, void*& result, int length) { std::ifstream ifd(filename, std::ios::binary | std::ios::ate); @@ -247,8 +271,8 @@ bool UltraHdrAppInput::encode() { if (mYuv420File != nullptr && !fillYuv420ImageHandle()) return false; if (mYuv420JpegFile != nullptr && !fillYuv420JpegImageHandle()) return false; - mJpegImgR.maxLength = std::max(static_cast(8 * 1024) /* min size 8kb */, - mRawP010Image.width * mRawP010Image.height * 3 * 2); + mJpegImgR.maxLength = (std::max)(static_cast(8 * 1024) /* min size 8kb */, + mRawP010Image.width * mRawP010Image.height * 3 * 2); mJpegImgR.data = malloc(mJpegImgR.maxLength); if (mJpegImgR.data == nullptr) { std::cerr << "unable to allocate memory to store compressed image" << std::endl; diff --git a/lib/jpegr.cpp b/lib/jpegr.cpp index 6fb8922c..06111d85 100644 --- a/lib/jpegr.cpp +++ b/lib/jpegr.cpp @@ -14,7 +14,12 @@ * limitations under the License. */ +#ifdef _WIN32 +#include +#include +#else #include +#endif #include #include @@ -56,17 +61,22 @@ namespace ultrahdr { // JPEG compress quality (0 ~ 100) for gain map static const int kMapCompressQuality = 85; -#define CONFIG_MULTITHREAD 1 int GetCPUCoreCount() { int cpuCoreCount = 1; -#if CONFIG_MULTITHREAD -#if defined(_SC_NPROCESSORS_ONLN) + +#if defined(_WIN32) + SYSTEM_INFO system_info; + ZeroMemory(&system_info, sizeof(system_info)); + GetSystemInfo(&system_info); + cpuCoreCount = (size_t)system_info.dwNumberOfProcessors; +#elif defined(_SC_NPROCESSORS_ONLN) cpuCoreCount = sysconf(_SC_NPROCESSORS_ONLN); +#elif defined(_SC_NPROCESSORS_CONF) + cpuCoreCount = sysconf(_SC_NPROCESSORS_CONF); #else - // _SC_NPROC_ONLN must be defined... - cpuCoreCount = sysconf(_SC_NPROC_ONLN); -#endif +#error platform-specific implementation for GetCPUCoreCount() missing. #endif + if (cpuCoreCount < 0) cpuCoreCount = 1; return cpuCoreCount; } @@ -218,13 +228,14 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, ultrahdr_transfe const size_t yu420_luma_stride = ALIGNM(p010_image.width, JpegEncoderHelper::kCompressBatchSize); unique_ptr yuv420_image_data = make_unique(yu420_luma_stride * p010_image.height * 3 / 2); - jpegr_uncompressed_struct yuv420_image = {.data = yuv420_image_data.get(), - .width = p010_image.width, - .height = p010_image.height, - .colorGamut = p010_image.colorGamut, - .chroma_data = nullptr, - .luma_stride = yu420_luma_stride, - .chroma_stride = yu420_luma_stride >> 1}; + jpegr_uncompressed_struct yuv420_image; + yuv420_image.data = yuv420_image_data.get(); + yuv420_image.width = p010_image.width; + yuv420_image.height = p010_image.height; + yuv420_image.colorGamut = p010_image.colorGamut; + yuv420_image.chroma_data = nullptr; + yuv420_image.luma_stride = yu420_luma_stride; + yuv420_image.chroma_stride = yu420_luma_stride >> 1; uint8_t* data = reinterpret_cast(yuv420_image.data); yuv420_image.chroma_data = data + yuv420_image.luma_stride * yuv420_image.height; @@ -232,7 +243,8 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, ultrahdr_transfe JPEGR_CHECK(toneMap(&p010_image, &yuv420_image)); // gain map - ultrahdr_metadata_struct metadata = {.version = kJpegrVersion}; + ultrahdr_metadata_struct metadata; + metadata.version = kJpegrVersion; jpegr_uncompressed_struct gainmap_image; JPEGR_CHECK(generateGainMap(&yuv420_image, &p010_image, hdr_tf, &metadata, &gainmap_image)); std::unique_ptr map_data; @@ -241,11 +253,11 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, ultrahdr_transfe // compress gain map JpegEncoderHelper jpeg_enc_obj_gm; JPEGR_CHECK(compressGainMap(&gainmap_image, &jpeg_enc_obj_gm)); - jpegr_compressed_struct compressed_map = { - .data = jpeg_enc_obj_gm.getCompressedImagePtr(), - .length = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()), - .maxLength = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()), - .colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED}; + jpegr_compressed_struct compressed_map; + compressed_map.data = jpeg_enc_obj_gm.getCompressedImagePtr(); + compressed_map.length = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()); + compressed_map.maxLength = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()); + compressed_map.colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED; std::shared_ptr icc = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, yuv420_image.colorGamut); @@ -264,11 +276,11 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, ultrahdr_transfe quality, icc->getData(), icc->getLength())) { return ERROR_JPEGR_ENCODE_ERROR; } - jpegr_compressed_struct jpeg = { - .data = jpeg_enc_obj_yuv420.getCompressedImagePtr(), - .length = static_cast(jpeg_enc_obj_yuv420.getCompressedImageSize()), - .maxLength = static_cast(jpeg_enc_obj_yuv420.getCompressedImageSize()), - .colorGamut = yuv420_image.colorGamut}; + jpegr_compressed_struct jpeg; + jpeg.data = jpeg_enc_obj_yuv420.getCompressedImagePtr(); + jpeg.length = static_cast(jpeg_enc_obj_yuv420.getCompressedImageSize()); + jpeg.maxLength = static_cast(jpeg_enc_obj_yuv420.getCompressedImageSize()); + jpeg.colorGamut = yuv420_image.colorGamut; // append gain map, no ICC since JPEG encode already did it JPEGR_CHECK(appendGainMap(&jpeg, &compressed_map, exif, /* icc */ nullptr, /* icc size */ 0, @@ -312,7 +324,8 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, } // gain map - ultrahdr_metadata_struct metadata = {.version = kJpegrVersion}; + ultrahdr_metadata_struct metadata; + metadata.version = kJpegrVersion; jpegr_uncompressed_struct gainmap_image; JPEGR_CHECK(generateGainMap(&yuv420_image, &p010_image, hdr_tf, &metadata, &gainmap_image)); std::unique_ptr map_data; @@ -321,11 +334,11 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, // compress gain map JpegEncoderHelper jpeg_enc_obj_gm; JPEGR_CHECK(compressGainMap(&gainmap_image, &jpeg_enc_obj_gm)); - jpegr_compressed_struct compressed_map = { - .data = jpeg_enc_obj_gm.getCompressedImagePtr(), - .length = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()), - .maxLength = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()), - .colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED}; + jpegr_compressed_struct compressed_map; + compressed_map.data = jpeg_enc_obj_gm.getCompressedImagePtr(); + compressed_map.length = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()); + compressed_map.maxLength = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()); + compressed_map.colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED; std::shared_ptr icc = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB, yuv420_image.colorGamut); @@ -403,11 +416,11 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, return ERROR_JPEGR_ENCODE_ERROR; } - jpegr_compressed_struct jpeg = { - .data = jpeg_enc_obj_yuv420.getCompressedImagePtr(), - .length = static_cast(jpeg_enc_obj_yuv420.getCompressedImageSize()), - .maxLength = static_cast(jpeg_enc_obj_yuv420.getCompressedImageSize()), - .colorGamut = yuv420_image.colorGamut}; + jpegr_compressed_struct jpeg; + jpeg.data = jpeg_enc_obj_yuv420.getCompressedImagePtr(); + jpeg.length = static_cast(jpeg_enc_obj_yuv420.getCompressedImageSize()); + jpeg.maxLength = static_cast(jpeg_enc_obj_yuv420.getCompressedImageSize()); + jpeg.colorGamut = yuv420_image.colorGamut; // append gain map, no ICC since JPEG encode already did it JPEGR_CHECK(appendGainMap(&jpeg, &compressed_map, exif, /* icc */ nullptr, /* icc size */ 0, @@ -451,7 +464,8 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, } // gain map - ultrahdr_metadata_struct metadata = {.version = kJpegrVersion}; + ultrahdr_metadata_struct metadata; + metadata.version = kJpegrVersion; jpegr_uncompressed_struct gainmap_image; JPEGR_CHECK(generateGainMap(&yuv420_image, &p010_image, hdr_tf, &metadata, &gainmap_image)); std::unique_ptr map_data; @@ -460,11 +474,11 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, // compress gain map JpegEncoderHelper jpeg_enc_obj_gm; JPEGR_CHECK(compressGainMap(&gainmap_image, &jpeg_enc_obj_gm)); - jpegr_compressed_struct gainmapjpg_image = { - .data = jpeg_enc_obj_gm.getCompressedImagePtr(), - .length = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()), - .maxLength = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()), - .colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED}; + jpegr_compressed_struct gainmapjpg_image; + gainmapjpg_image.data = jpeg_enc_obj_gm.getCompressedImagePtr(); + gainmapjpg_image.length = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()); + gainmapjpg_image.maxLength = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()); + gainmapjpg_image.colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED; return encodeJPEGR(yuv420jpg_image_ptr, &gainmapjpg_image, &metadata, dest); } @@ -516,7 +530,8 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, } // gain map - ultrahdr_metadata_struct metadata = {.version = kJpegrVersion}; + ultrahdr_metadata_struct metadata; + metadata.version = kJpegrVersion; jpegr_uncompressed_struct gainmap_image; JPEGR_CHECK(generateGainMap(&yuv420_image, &p010_image, hdr_tf, &metadata, &gainmap_image, true /* sdr_is_601 */)); @@ -526,11 +541,11 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr p010_image_ptr, // compress gain map JpegEncoderHelper jpeg_enc_obj_gm; JPEGR_CHECK(compressGainMap(&gainmap_image, &jpeg_enc_obj_gm)); - jpegr_compressed_struct gainmapjpg_image = { - .data = jpeg_enc_obj_gm.getCompressedImagePtr(), - .length = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()), - .maxLength = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()), - .colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED}; + jpegr_compressed_struct gainmapjpg_image; + gainmapjpg_image.data = jpeg_enc_obj_gm.getCompressedImagePtr(); + gainmapjpg_image.length = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()); + gainmapjpg_image.maxLength = static_cast(jpeg_enc_obj_gm.getCompressedImageSize()); + gainmapjpg_image.colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED; return encodeJPEGR(yuv420jpg_image_ptr, &gainmapjpg_image, &metadata, dest); } @@ -967,7 +982,7 @@ status_t JpegR::generateGainMap(jr_uncompressed_ptr yuv420_image_ptr, rowStep = (threads == 1 ? image_height : kJobSzInRows) / kMapDimensionScaleFactor; for (size_t rowStart = 0; rowStart < map_height;) { - size_t rowEnd = std::min(rowStart + rowStep, map_height); + size_t rowEnd = (std::min)(rowStart + rowStep, map_height); jobQueue.enqueueJob(rowStart, rowEnd); rowStart = rowEnd; } @@ -1023,7 +1038,7 @@ status_t JpegR::applyGainMap(jr_uncompressed_ptr yuv420_image_ptr, dest->width = yuv420_image_ptr->width; dest->height = yuv420_image_ptr->height; ShepardsIDW idwTable(kMapDimensionScaleFactor); - float display_boost = std::min(max_display_boost, metadata->maxContentBoost); + float display_boost = (std::min)(max_display_boost, metadata->maxContentBoost); GainLUT gainLUT(metadata, display_boost); JobQueue jobQueue; @@ -1109,7 +1124,7 @@ status_t JpegR::applyGainMap(jr_uncompressed_ptr yuv420_image_ptr, } const int rowStep = threads == 1 ? yuv420_image_ptr->height : kJobSzInRows; for (size_t rowStart = 0; rowStart < yuv420_image_ptr->height;) { - int rowEnd = std::min(rowStart + rowStep, yuv420_image_ptr->height); + int rowEnd = (std::min)(rowStart + rowStep, yuv420_image_ptr->height); jobQueue.enqueueJob(rowStart, rowEnd); rowStart = rowEnd; } @@ -1262,9 +1277,14 @@ status_t JpegR::appendGainMap(jr_compressed_ptr primary_jpg_image_ptr, if (!decoder.extractEXIF(primary_jpg_image_ptr->data, primary_jpg_image_ptr->length)) { return ERROR_JPEGR_DECODE_ERROR; } - jpegr_exif_struct exif_from_jpg = {.data = nullptr, .length = 0}; - jpegr_compressed_struct new_jpg_image = { - .data = nullptr, .length = 0, .maxLength = 0, .colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED}; + jpegr_exif_struct exif_from_jpg; + exif_from_jpg.data = nullptr; + exif_from_jpg.length = 0; + jpegr_compressed_struct new_jpg_image; + new_jpg_image.data = nullptr; + new_jpg_image.length = 0; + new_jpg_image.maxLength = 0; + new_jpg_image.colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED; std::unique_ptr dest_data; if (decoder.getEXIFPos() >= 0) { if (pExif != nullptr) { diff --git a/tests/jpegdecoderhelper_test.cpp b/tests/jpegdecoderhelper_test.cpp index e811e371..3b8e88ed 100644 --- a/tests/jpegdecoderhelper_test.cpp +++ b/tests/jpegdecoderhelper_test.cpp @@ -14,9 +14,11 @@ * limitations under the License. */ -#include #include +#include +#include + #include "ultrahdrcommon.h" #include "jpegdecoderhelper.h" #include "icc.h" @@ -60,32 +62,17 @@ JpegDecoderHelperTest::JpegDecoderHelperTest() {} JpegDecoderHelperTest::~JpegDecoderHelperTest() {} -static size_t getFileSize(int fd) { - struct stat st; - if (fstat(fd, &st) < 0) { - ALOGW("%s : fstat failed", __func__); - return 0; - } - return st.st_size; // bytes -} - static bool loadFile(const char filename[], JpegDecoderHelperTest::Image* result) { - int fd = open(filename, O_CLOEXEC); - if (fd < 0) { - return false; - } - int length = getFileSize(fd); - if (length == 0) { - close(fd); - return false; - } - result->buffer.reset(new uint8_t[length]); - if (read(fd, result->buffer.get(), length) != static_cast(length)) { - close(fd); - return false; + std::ifstream ifd(filename, std::ios::binary | std::ios::ate); + if (ifd.good()) { + int size = ifd.tellg(); + ifd.seekg(0, std::ios::beg); + result->buffer.reset(new uint8_t[size]); + ifd.read(reinterpret_cast(result->buffer.get()), size); + ifd.close(); + return true; } - close(fd); - return true; + return false; } void JpegDecoderHelperTest::SetUp() { diff --git a/tests/jpegencoderhelper_test.cpp b/tests/jpegencoderhelper_test.cpp index b1f0fea7..3463c262 100644 --- a/tests/jpegencoderhelper_test.cpp +++ b/tests/jpegencoderhelper_test.cpp @@ -14,9 +14,11 @@ * limitations under the License. */ -#include #include +#include +#include + #include "ultrahdrcommon.h" #include "ultrahdr.h" #include "jpegencoderhelper.h" @@ -61,32 +63,17 @@ JpegEncoderHelperTest::JpegEncoderHelperTest() {} JpegEncoderHelperTest::~JpegEncoderHelperTest() {} -static size_t getFileSize(int fd) { - struct stat st; - if (fstat(fd, &st) < 0) { - ALOGW("%s : fstat failed", __func__); - return 0; - } - return st.st_size; // bytes -} - static bool loadFile(const char filename[], JpegEncoderHelperTest::Image* result) { - int fd = open(filename, O_CLOEXEC); - if (fd < 0) { - return false; - } - int length = getFileSize(fd); - if (length == 0) { - close(fd); - return false; - } - result->buffer.reset(new uint8_t[length]); - if (read(fd, result->buffer.get(), length) != static_cast(length)) { - close(fd); - return false; + std::ifstream ifd(filename, std::ios::binary | std::ios::ate); + if (ifd.good()) { + int size = ifd.tellg(); + ifd.seekg(0, std::ios::beg); + result->buffer.reset(new uint8_t[size]); + ifd.read(reinterpret_cast(result->buffer.get()), size); + ifd.close(); + return true; } - close(fd); - return true; + return false; } void JpegEncoderHelperTest::SetUp() { diff --git a/tests/jpegr_test.cpp b/tests/jpegr_test.cpp index 07977c28..d236f2fa 100644 --- a/tests/jpegr_test.cpp +++ b/tests/jpegr_test.cpp @@ -14,7 +14,11 @@ * limitations under the License. */ +#ifdef _WIN32 +#include +#else #include +#endif #include #include @@ -259,7 +263,7 @@ bool UhdrCompressedStructWrapper::allocateMemory() { std::cerr << "Object in bad state, mem alloc failed" << std::endl; return false; } - int maxLength = std::max(8 * 1024 /* min size 8kb */, (int)(mWidth * mHeight * 3 * 2)); + int maxLength = (std::max)(8 * 1024 /* min size 8kb */, (int)(mWidth * mHeight * 3 * 2)); mData = std::make_unique(maxLength); mImg.data = mData.get(); mImg.length = 0; @@ -1916,7 +1920,26 @@ INSTANTIATE_TEST_SUITE_P( // ============================================================================ // Profiling // ============================================================================ +#ifdef _WIN32 +class Profiler { + public: + void timerStart() { QueryPerformanceCounter(&mStartingTime); } + + void timerStop() { QueryPerformanceCounter(&mEndingTime); } + + int64_t elapsedTime() { + LARGE_INTEGER frequency; + LARGE_INTEGER elapsedMicroseconds; + QueryPerformanceFrequency(&frequency); + elapsedMicroseconds.QuadPart = mEndingTime.QuadPart - mStartingTime.QuadPart; + return (double)elapsedMicroseconds.QuadPart / (double)frequency.QuadPart * 1000000; + } + private: + LARGE_INTEGER mStartingTime; + LARGE_INTEGER mEndingTime; +}; +#else class Profiler { public: void timerStart() { gettimeofday(&mStartingTime, nullptr); } @@ -1934,6 +1957,7 @@ class Profiler { struct timeval mStartingTime; struct timeval mEndingTime; }; +#endif class JpegRBenchmark : public JpegR { public: diff --git a/third_party/image_io/includes/image_io/base/data_range.h b/third_party/image_io/includes/image_io/base/data_range.h index e2e339a9..c7404ff6 100644 --- a/third_party/image_io/includes/image_io/base/data_range.h +++ b/third_party/image_io/includes/image_io/base/data_range.h @@ -59,8 +59,8 @@ class DataRange { /// @return The DataRange that represents the intersection, or one that is /// is invalid if the ranges do not overlap at all. DataRange GetIntersection(const DataRange& data_range) const { - return DataRange(std::max(data_range.begin_, begin_), - std::min(data_range.end_, end_)); + return DataRange((std::max)(data_range.begin_, begin_), + (std::min)(data_range.end_, end_)); } /// @param rhs A DataRange to compare with this one. diff --git a/third_party/image_io/src/utils/file_utils.cc b/third_party/image_io/src/utils/file_utils.cc index 626d537a..8156d50e 100644 --- a/third_party/image_io/src/utils/file_utils.cc +++ b/third_party/image_io/src/utils/file_utils.cc @@ -1,9 +1,9 @@ #include "image_io/utils/file_utils.h" #include -#import -#import -#import +#include +#include +#include #include "image_io/base/data_range.h"