Repository: python-pillow/Pillow

Issue:
DdsImagePlugin fails when dxgi_format == DXGI_FORMAT_BC7_UNORM_SRGB
https://github.com/python-pillow/Pillow/blob/84fed4d213a50b359188aa59f99ed06ba1249c14/src/PIL/DdsImagePlugin.py#L156-L159

At `self.im_info["gamma"] = 1 / 2.2`, `self.im_info` has never been initialized and so trying to set `self.im_info["gamma"]` fails with:
```
AttributeError: 'DdsImageFile' object has no attribute 'im_info'
```
As far as I can tell, this is the only place `im_info` is ever referenced in this or the ancestor classes.

A possible solution would be to change this section to:
```python
                elif dxgi_format == DXGI_FORMAT_BC7_UNORM_SRGB:
                    self.pixel_format = "BC7"
                    if not hasattr(self, 'im_info'):
                        self.im_info = {}
                    self.im_info["gamma"] = 1 / 2.2
                    n = 7
```

An alternate solution would be to initialize `im_info` earlier in the loader method.


Discussion:
Can you provide an image that demonstrates the problem? Ideally, one that can be included as part of the test suite and distributed under the Pillow license?
@radarhere None of the images I'm working with are available for that and I don't have a way to generate a new file. I'll see what I can do, but you shouldn't get your hopes up.
@radarhere In a rare alignment of fortune, I was able to produce a file that triggers this issue. See contents of [DXGI_FORMAT_BC7_UNORM_SRGB.zip](https://github.com/python-pillow/Pillow/files/3769280/DXGI_FORMAT_BC7_UNORM_SRGB.zip)
.



Resolving patch:
diff --git a/src/PIL/DdsImagePlugin.py b/src/PIL/DdsImagePlugin.py
--- a/src/PIL/DdsImagePlugin.py
+++ b/src/PIL/DdsImagePlugin.py
@@ -155,7 +155,7 @@ def _open(self):
                     n = 7
                 elif dxgi_format == DXGI_FORMAT_BC7_UNORM_SRGB:
                     self.pixel_format = "BC7"
-                    self.im_info["gamma"] = 1 / 2.2
+                    self.info["gamma"] = 1 / 2.2
                     n = 7
                 else:
                     raise NotImplementedError(


Test patch:
diff --git a/Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.dds b/Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.dds
new file mode 100644
Binary files /dev/null and b/Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.dds differ
diff --git a/Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.png b/Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.png
new file mode 100644
Binary files /dev/null and b/Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.png differ
diff --git a/Tests/test_file_dds.py b/Tests/test_file_dds.py
--- a/Tests/test_file_dds.py
+++ b/Tests/test_file_dds.py
@@ -8,6 +8,7 @@
 TEST_FILE_DXT3 = "Tests/images/dxt3-argb-8bbp-explicitalpha_MipMaps-1.dds"
 TEST_FILE_DXT5 = "Tests/images/dxt5-argb-8bbp-interpolatedalpha_MipMaps-1.dds"
 TEST_FILE_DX10_BC7 = "Tests/images/bc7-argb-8bpp_MipMaps-1.dds"
+TEST_FILE_DX10_BC7_UNORM_SRGB = "Tests/images/DXGI_FORMAT_BC7_UNORM_SRGB.dds"
 TEST_FILE_UNCOMPRESSED_RGB = "Tests/images/uncompressed_rgb.dds"
 
 
@@ -69,6 +70,21 @@ def test_dx10_bc7(self):
 
         self.assert_image_equal(target, im)
 
+    def test_dx10_bc7_unorm_srgb(self):
+        """Check DX10 unsigned normalized integer images can be opened"""
+
+        target = Image.open(TEST_FILE_DX10_BC7_UNORM_SRGB.replace(".dds", ".png"))
+
+        im = Image.open(TEST_FILE_DX10_BC7_UNORM_SRGB)
+        im.load()
+
+        self.assertEqual(im.format, "DDS")
+        self.assertEqual(im.mode, "RGBA")
+        self.assertEqual(im.size, (16, 16))
+        self.assertEqual(im.info["gamma"], 1 / 2.2)
+
+        self.assert_image_equal(target, im)
+
     def test_unimplemented_dxgi_format(self):
         self.assertRaises(
             NotImplementedError,