Skip to content

Commit 5b524cd

Browse files
datumboxZhongkai Zhu
authored andcommitted
[fbsync] Unpinned the libjpeg version and fixed jpeg_mem_dest's size type Wind… (#4288)
Summary: * Unpinned the libjpeg version and fixed jpeg_mem_dest's size type Windows BC issue * Temporarily get back pinned jpeg lib in order to run tests on CircleCI * Revert "Temporarily get back pinned jpeg lib in order to run tests on CircleCI" This reverts commit ab18a35. * Used using instead of typedef and Fixed comment typo Reviewed By: fmassa Differential Revision: D30525893 fbshipit-source-id: bae9830e2d2212b9575a9ba6b4cc8313ba91e395 Co-authored-by: Zhongkai Zhu <[email protected]> Co-authored-by: Vasilis Vryniotis <[email protected]>
1 parent aaff90f commit 5b524cd

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

.circleci/unittest/linux/scripts/environment.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ dependencies:
77
- pytest-mock
88
- pip
99
- libpng
10-
# NOTE: Pinned to fix issues with size_t on Windows
11-
- jpeg <=9b
10+
- jpeg
1211
- ca-certificates
1312
- pip:
1413
- future

.circleci/unittest/windows/scripts/environment.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ dependencies:
77
- pytest-mock
88
- pip
99
- libpng
10-
# NOTE: Pinned to fix issues with size_t on Windows
11-
- jpeg <=9b
10+
- jpeg
1211
- ca-certificates
1312
- pip:
1413
- future

packaging/torchvision/meta.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ requirements:
99
build:
1010
- {{ compiler('c') }} # [win]
1111
- libpng
12-
# NOTE: Pinned to fix issues with size_t on Windows
13-
- jpeg <=9b
12+
- jpeg
1413
# NOTE: The only ffmpeg version that we build is actually 4.2
1514
- ffmpeg >=4.2 # [not win]
1615

@@ -25,8 +24,7 @@ requirements:
2524
- python
2625
- libpng
2726
- ffmpeg >=4.2 # [not win]
28-
# NOTE: Pinned to fix issues with size_t on Windows
29-
- jpeg <=9b
27+
- jpeg
3028
- pillow >=5.3.0
3129
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
3230
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}
@@ -52,8 +50,7 @@ test:
5250
requires:
5351
- pytest
5452
- scipy
55-
# NOTE: Pinned to fix issues with size_t on Windows
56-
- jpeg <=9b
53+
- jpeg
5754
- ca-certificates
5855

5956

torchvision/csrc/io/image/cpu/encode_jpeg.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) {
1313
}
1414

1515
#else
16+
// For libjpeg version <= 9b, the out_size parameter in jpeg_mem_dest() is
17+
// defined as unsigned long, where as in later version, it is defined as size_t.
18+
// For windows backward compatibility, we define JpegSizeType as different types
19+
// according to the libjpeg version used, in order to prevent compilcation
20+
// errors.
21+
#if defined(_WIN32) || !defined(JPEG_LIB_VERSION_MAJOR) || \
22+
(JPEG_LIB_VERSION_MAJOR < 9) || \
23+
(JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR <= 2)
24+
using JpegSizeType = unsigned long;
25+
#else
26+
using JpegSizeType = size_t;
27+
#endif
1628

1729
using namespace detail;
1830

@@ -22,7 +34,7 @@ torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) {
2234
struct torch_jpeg_error_mgr jerr {};
2335

2436
// Define buffer to write JPEG information to and its size
25-
unsigned long jpegSize = 0;
37+
JpegSizeType jpegSize = 0;
2638
uint8_t* jpegBuf = nullptr;
2739

2840
cinfo.err = jpeg_std_error(&jerr.pub);

0 commit comments

Comments
 (0)