@@ -72,7 +72,7 @@ inline unsigned char clamped_cmyk_rgb_convert(
72
72
unsigned char cmy) {
73
73
// Inspired from Pillow:
74
74
// 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 ;
76
76
v = ((v >> 8 ) + v) >> 8 ;
77
77
return std::clamp (k - v, 0 , 255 );
78
78
}
@@ -200,9 +200,9 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
200
200
auto tensor =
201
201
torch::empty ({int64_t (height), int64_t (width), channels}, torch::kU8 );
202
202
auto ptr = tensor.data_ptr <uint8_t >();
203
- torch::Tensor temp_tensor ;
203
+ torch::Tensor cmyk_line_tensor ;
204
204
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 );
206
206
}
207
207
208
208
while (cinfo.output_scanline < cinfo.output_height ) {
@@ -211,13 +211,13 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
211
211
* more than one scanline at a time if that's more convenient.
212
212
*/
213
213
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 );
216
216
217
217
if (channels == 3 ) {
218
- convert_line_cmyk_to_rgb (&cinfo, temp_buffer , ptr);
218
+ convert_line_cmyk_to_rgb (&cinfo, cmyk_line_ptr , ptr);
219
219
} 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);
221
221
}
222
222
} else {
223
223
jpeg_read_scanlines (&cinfo, &ptr, 1 );
0 commit comments