File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed
torchvision/csrc/io/image/cpu Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -40,20 +40,22 @@ torch::Tensor decode_webp(
40
40
TORCH_CHECK (
41
41
!features.has_animation , " Animated webp files are not supported." );
42
42
43
- auto decoding_func = WebPDecodeRGB;
44
- int num_channels = 0 ;
45
- if (mode == IMAGE_READ_MODE_RGB) {
46
- decoding_func = WebPDecodeRGB;
47
- num_channels = 3 ;
48
- } else if (mode == IMAGE_READ_MODE_RGB_ALPHA) {
49
- decoding_func = WebPDecodeRGBA;
50
- num_channels = 4 ;
51
- } else {
52
- // Assume mode is "unchanged"
53
- decoding_func = features.has_alpha ? WebPDecodeRGBA : WebPDecodeRGB;
54
- num_channels = features.has_alpha ? 4 : 3 ;
43
+ if (mode != IMAGE_READ_MODE_UNCHANGED && mode != IMAGE_READ_MODE_RGB &&
44
+ mode != IMAGE_READ_MODE_RGB_ALPHA) {
45
+ // Other modes aren't supported, but we don't error or even warn because we
46
+ // have generic entry points like decode_image which may support all modes,
47
+ // it just depends on the underlying decoder.
48
+ mode = IMAGE_READ_MODE_UNCHANGED;
55
49
}
56
50
51
+ // If return_rgb is false it means we return rgba - nothing else.
52
+ auto return_rgb =
53
+ (mode == IMAGE_READ_MODE_RGB ||
54
+ (mode == IMAGE_READ_MODE_UNCHANGED && !features.has_alpha ));
55
+
56
+ auto decoding_func = return_rgb ? WebPDecodeRGB : WebPDecodeRGBA;
57
+ auto num_channels = return_rgb ? 3 : 4 ;
58
+
57
59
int width = 0 ;
58
60
int height = 0 ;
59
61
You can’t perform that action at this time.
0 commit comments