From 3049380b489f2d9cfbec7f311d742054871ac3f8 Mon Sep 17 00:00:00 2001 From: zzk1st Date: Thu, 19 Aug 2021 15:35:50 +0100 Subject: [PATCH 1/2] Jpeg unpin - Cherrypicking #4288 --- .circleci/unittest/linux/scripts/environment.yml | 3 +-- .circleci/unittest/windows/scripts/environment.yml | 3 +-- packaging/torchvision/meta.yaml | 9 +++------ torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 14 +++++++++++++- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.circleci/unittest/linux/scripts/environment.yml b/.circleci/unittest/linux/scripts/environment.yml index b2efb93de75..8bec8b2b054 100644 --- a/.circleci/unittest/linux/scripts/environment.yml +++ b/.circleci/unittest/linux/scripts/environment.yml @@ -6,8 +6,7 @@ dependencies: - pytest-cov - pip - libpng - # NOTE: Pinned to fix issues with size_t on Windows - - jpeg <=9b + - jpeg - ca-certificates - pip: - future diff --git a/.circleci/unittest/windows/scripts/environment.yml b/.circleci/unittest/windows/scripts/environment.yml index da2f502f3fe..02ac1285dea 100644 --- a/.circleci/unittest/windows/scripts/environment.yml +++ b/.circleci/unittest/windows/scripts/environment.yml @@ -6,8 +6,7 @@ dependencies: - pytest-cov - pip - libpng - # NOTE: Pinned to fix issues with size_t on Windows - - jpeg <=9b + - jpeg - ca-certificates - pip: - future diff --git a/packaging/torchvision/meta.yaml b/packaging/torchvision/meta.yaml index 222071ede93..da061c5cc2a 100644 --- a/packaging/torchvision/meta.yaml +++ b/packaging/torchvision/meta.yaml @@ -9,8 +9,7 @@ requirements: build: - {{ compiler('c') }} # [win] - libpng - # NOTE: Pinned to fix issues with size_t on Windows - - jpeg <=9b + - jpeg # NOTE: The only ffmpeg version that we build is actually 4.2 - ffmpeg >=4.2 # [not win] @@ -25,8 +24,7 @@ requirements: - python - libpng - ffmpeg >=4.2 # [not win] - # NOTE: Pinned to fix issues with size_t on Windows - - jpeg <=9b + - jpeg - pillow >=5.3.0 {{ environ.get('CONDA_PYTORCH_CONSTRAINT') }} {{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }} @@ -52,8 +50,7 @@ test: requires: - pytest - scipy - # NOTE: Pinned to fix issues with size_t on Windows - - jpeg <=9b + - jpeg - ca-certificates diff --git a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp index c84ad37005d..2f445d21e47 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -13,6 +13,18 @@ torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) { } #else +// For libjpeg version <= 9b, the out_size parameter in jpeg_mem_dest() is +// defined as unsigned long, where as in later version, it is defined as size_t. +// For windows backward compatibility, we define JpegSizeType as different types +// according to the libjpeg version used, in order to prevent compilcation +// errors. +#if defined(_WIN32) || !defined(JPEG_LIB_VERSION_MAJOR) || \ + (JPEG_LIB_VERSION_MAJOR < 9) || \ + (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR <= 2) +using JpegSizeType = unsigned long; +#else +using JpegSizeType = size_t; +#endif using namespace detail; @@ -22,7 +34,7 @@ torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) { struct torch_jpeg_error_mgr jerr; // Define buffer to write JPEG information to and its size - unsigned long jpegSize = 0; + JpegSizeType jpegSize = 0; uint8_t* jpegBuf = NULL; cinfo.err = jpeg_std_error(&jerr.pub); From 4619ae4545d871791e4b6ffb78e7312be4bfe5aa Mon Sep 17 00:00:00 2001 From: Vasilis Vryniotis Date: Fri, 17 Sep 2021 15:29:52 +0100 Subject: [PATCH 2/2] Jerry picking fix from #4439 --- torchvision/csrc/io/image/cpu/encode_jpeg.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp index 2f445d21e47..00facd33ae7 100644 --- a/torchvision/csrc/io/image/cpu/encode_jpeg.cpp +++ b/torchvision/csrc/io/image/cpu/encode_jpeg.cpp @@ -15,11 +15,7 @@ torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) { #else // For libjpeg version <= 9b, the out_size parameter in jpeg_mem_dest() is // defined as unsigned long, where as in later version, it is defined as size_t. -// For windows backward compatibility, we define JpegSizeType as different types -// according to the libjpeg version used, in order to prevent compilcation -// errors. -#if defined(_WIN32) || !defined(JPEG_LIB_VERSION_MAJOR) || \ - (JPEG_LIB_VERSION_MAJOR < 9) || \ +#if !defined(JPEG_LIB_VERSION_MAJOR) || JPEG_LIB_VERSION_MAJOR < 9 || \ (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR <= 2) using JpegSizeType = unsigned long; #else