mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 16:07:30 +03:00 
			
		
		
		
	fixed support for hopper.ras, and other RGB sun raster files
This commit is contained in:
		
							parent
							
								
									e43c91cf1c
								
							
						
					
					
						commit
						318ff7d332
					
				|  | @ -48,17 +48,20 @@ class SunImageFile(ImageFile.ImageFile): | |||
|         self.size = i32(s[4:8]), i32(s[8:12]) | ||||
| 
 | ||||
|         depth = i32(s[12:16]) | ||||
|         file_type = i32(s[20:24]) | ||||
|          | ||||
|         if depth == 1: | ||||
|             self.mode, rawmode = "1", "1;I" | ||||
|         elif depth == 8: | ||||
|             self.mode = rawmode = "L" | ||||
|         elif depth == 24: | ||||
|             self.mode, rawmode = "RGB", "BGR" | ||||
|             if file_type == 3: | ||||
|                 self.mode, rawmode = "RGB", "RGB" | ||||
|             else: | ||||
|                 self.mode, rawmode = "RGB", "BGR" | ||||
|         else: | ||||
|             raise SyntaxError("unsupported mode") | ||||
| 
 | ||||
|         compression = i32(s[20:24]) | ||||
| 
 | ||||
|         if i32(s[24:28]) != 0: | ||||
|             length = i32(s[28:32]) | ||||
|             offset = offset + length | ||||
|  | @ -68,11 +71,31 @@ class SunImageFile(ImageFile.ImageFile): | |||
| 
 | ||||
|         stride = (((self.size[0] * depth + 7) // 8) + 3) & (~3) | ||||
| 
 | ||||
|         if compression == 1: | ||||
|             self.tile = [("raw", (0, 0)+self.size, offset, (rawmode, stride))] | ||||
|         elif compression == 2: | ||||
|             self.tile = [("sun_rle", (0, 0)+self.size, offset, rawmode)] | ||||
|         # file type: Type is the version (or flavor) of the bitmap | ||||
|         # file. The following values are typically found in the Type | ||||
|         # field: | ||||
|         # 0000h	Old | ||||
|         # 0001h	Standard | ||||
|         # 0002h	Byte-encoded | ||||
|         # 0003h	RGB format | ||||
|         # 0004h	TIFF format | ||||
|         # 0005h	IFF format | ||||
|         # FFFFh	Experimental | ||||
| 
 | ||||
|         # Old and standard are the same, except for the length tag. | ||||
|         # byte-encoded is run-length-encoded | ||||
|         # RGB looks similar to standard, but RGB byte order | ||||
|         # TIFF and IFF mean that they were converted from T/IFF | ||||
|         # Experimental means that it's something else. | ||||
|         # (http://www.fileformat.info/format/sunraster/egff.htm) | ||||
| 
 | ||||
|         if file_type in (0, 1, 3, 4, 5): | ||||
|             self.tile = [("raw", (0, 0)+self.size, offset, (rawmode, stride))] | ||||
|         elif file_type == 2: | ||||
|             self.tile = [("sun_rle", (0, 0)+self.size, offset, rawmode)] | ||||
|         else: | ||||
|             raise SyntaxError('Unsupported Sun Raster file type') | ||||
|          | ||||
| # | ||||
| # registry | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| from helper import unittest, PillowTestCase | ||||
| from helper import unittest, PillowTestCase, hopper | ||||
| 
 | ||||
| from PIL import Image, SunImagePlugin | ||||
| 
 | ||||
|  | @ -16,12 +16,12 @@ class TestFileSun(PillowTestCase): | |||
|         # Assert | ||||
|         self.assertEqual(im.size, (128, 128)) | ||||
| 
 | ||||
|         self.assert_image_similar(im, hopper(), 5) # visually verified | ||||
|          | ||||
|         invalid_file = "Tests/images/flower.jpg" | ||||
|         self.assertRaises(SyntaxError, | ||||
|                           lambda: SunImagePlugin.SunImageFile(invalid_file)) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|     def test_im1(self): | ||||
|         im = Image.open('Tests/images/sunraster.im1') | ||||
|         target = Image.open('Tests/images/sunraster.im1.png') | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user