Skip to content

Commit 9a38011

Browse files
authored
Update decode_jpeg.cpp
1 parent 668d5d1 commit 9a38011

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
157157
jpeg_read_header(&cinfo, TRUE);
158158

159159
int channels = cinfo.num_components;
160-
bool cmyk_to_rgb = false;
160+
bool cmyk_to_rgb_or_gray = false;
161161

162162
if (mode != IMAGE_READ_MODE_UNCHANGED) {
163163
switch (mode) {
164164
case IMAGE_READ_MODE_GRAY:
165165
if (cinfo.jpeg_color_space == JCS_CMYK ||
166166
cinfo.jpeg_color_space == JCS_YCCK) {
167167
cinfo.out_color_space = JCS_CMYK;
168-
cmyk_to_rgb = true;
168+
cmyk_to_rgb_or_gray = true;
169169
} else {
170170
cinfo.out_color_space = JCS_GRAYSCALE;
171171
}
@@ -175,7 +175,7 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
175175
if (cinfo.jpeg_color_space == JCS_CMYK ||
176176
cinfo.jpeg_color_space == JCS_YCCK) {
177177
cinfo.out_color_space = JCS_CMYK;
178-
cmyk_to_rgb = true;
178+
cmyk_to_rgb_or_gray = true;
179179
} else {
180180
cinfo.out_color_space = JCS_RGB;
181181
}
@@ -204,7 +204,7 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
204204
torch::empty({int64_t(height), int64_t(width), channels}, torch::kU8);
205205
auto ptr = tensor.data_ptr<uint8_t>();
206206
torch::Tensor temp_tensor;
207-
if (cmyk_to_rgb) {
207+
if (cmyk_to_rgb_or_gray) {
208208
temp_tensor = torch::empty({int64_t(width), 4}, torch::kU8);
209209
}
210210

@@ -213,7 +213,7 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
213213
* Here the array is only one element long, but you could ask for
214214
* more than one scanline at a time if that's more convenient.
215215
*/
216-
if (cmyk_to_rgb) {
216+
if (cmyk_to_rgb_or_gray) {
217217
auto temp_buffer = temp_tensor.data_ptr<uint8_t>();
218218
jpeg_read_scanlines(&cinfo, &temp_buffer, 1);
219219

0 commit comments

Comments
 (0)