Skip to content

Commit 54da7b2

Browse files
authored
Update decode_jpeg.cpp
1 parent e171488 commit 54da7b2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ inline unsigned char clamped_cmyk_rgb_convert(
7272
unsigned char cmy) {
7373
// Inspired from Pillow:
7474
// https://github.com/python-pillow/Pillow/blob/07623d1a7cc65206a5355fba2ae256550bfcaba6/src/libImaging/Convert.c#L568-L569
75-
auto v = k * cmy + 128;
75+
int v = k * cmy + 128;
7676
v = ((v >> 8) + v) >> 8;
7777
return std::clamp(k - v, 0, 255);
7878
}
@@ -200,9 +200,9 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
200200
auto tensor =
201201
torch::empty({int64_t(height), int64_t(width), channels}, torch::kU8);
202202
auto ptr = tensor.data_ptr<uint8_t>();
203-
torch::Tensor temp_tensor;
203+
torch::Tensor cmyk_line_tensor;
204204
if (cmyk_to_rgb_or_gray) {
205-
temp_tensor = torch::empty({int64_t(width), 4}, torch::kU8);
205+
cmyk_line_tensor = torch::empty({int64_t(width), 4}, torch::kU8);
206206
}
207207

208208
while (cinfo.output_scanline < cinfo.output_height) {
@@ -211,13 +211,13 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
211211
* more than one scanline at a time if that's more convenient.
212212
*/
213213
if (cmyk_to_rgb_or_gray) {
214-
auto temp_buffer = temp_tensor.data_ptr<uint8_t>();
215-
jpeg_read_scanlines(&cinfo, &temp_buffer, 1);
214+
auto cmyk_line_ptr = cmyk_line_tensor.data_ptr<uint8_t>();
215+
jpeg_read_scanlines(&cinfo, &cmyk_line_ptr, 1);
216216

217217
if (channels == 3) {
218-
convert_line_cmyk_to_rgb(&cinfo, temp_buffer, ptr);
218+
convert_line_cmyk_to_rgb(&cinfo, cmyk_line_ptr, ptr);
219219
} else if (channels == 1) {
220-
convert_line_cmyk_to_gray(&cinfo, temp_buffer, ptr);
220+
convert_line_cmyk_to_gray(&cinfo, cmyk_line_ptr, ptr);
221221
}
222222
} else {
223223
jpeg_read_scanlines(&cinfo, &ptr, 1);

0 commit comments

Comments
 (0)