mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	Add support for few more formats
This commit is contained in:
		
							parent
							
								
									ed70519396
								
							
						
					
					
						commit
						3e7843745b
					
				|  | @ -125,13 +125,11 @@ VTFHeader = NamedTuple( | ||||||
|         ("resource_count", int), |         ("resource_count", int), | ||||||
|     ], |     ], | ||||||
| ) | ) | ||||||
| RGB_FORMATS = ( | RGB_FORMATS = (VtfPF.DXT1, | ||||||
|                VtfPF.RGB888, |                VtfPF.RGB888, | ||||||
|                VtfPF.BGR888, |                VtfPF.BGR888, | ||||||
|     VtfPF.UV88, |                VtfPF.UV88,) | ||||||
| ) |  | ||||||
| RGBA_FORMATS = ( | RGBA_FORMATS = ( | ||||||
|     VtfPF.DXT1, |  | ||||||
|     VtfPF.DXT1_ONEBITALPHA, |     VtfPF.DXT1_ONEBITALPHA, | ||||||
|     VtfPF.DXT3, |     VtfPF.DXT3, | ||||||
|     VtfPF.DXT5, |     VtfPF.DXT5, | ||||||
|  | @ -230,8 +228,13 @@ def _write_image(fp: BufferedIOBase, im: Image.Image, pixel_format: VtfPF): | ||||||
|         im = im.convert("LA") |         im = im.convert("LA") | ||||||
|     elif pixel_format == VtfPF.UV88: |     elif pixel_format == VtfPF.UV88: | ||||||
|         encoder = "raw" |         encoder = "raw" | ||||||
|  |         if im.mode == "RGB" or im.mode == "RGBA": | ||||||
|             r, g, *_ = im.split() |             r, g, *_ = im.split() | ||||||
|         im = Image.merge("LA", (r, g)) |             im = Image.merge('LA', (r, g)) | ||||||
|  |         elif im.mode == "LA": | ||||||
|  |             pass | ||||||
|  |         else: | ||||||
|  |             raise VTFException(f'Cannot encode {im.mode} as {pixel_format}') | ||||||
|         encoder_args = ("LA", 0, 0) |         encoder_args = ("LA", 0, 0) | ||||||
|     else: |     else: | ||||||
|         raise VTFException(f"Unsupported pixel format: {pixel_format!r}") |         raise VTFException(f"Unsupported pixel format: {pixel_format!r}") | ||||||
|  | @ -283,8 +286,9 @@ class VtfImageFile(ImageFile.ImageFile): | ||||||
|         # flags = CompiledVtfFlags(header.flags) |         # flags = CompiledVtfFlags(header.flags) | ||||||
|         pixel_format = VtfPF(header.pixel_format) |         pixel_format = VtfPF(header.pixel_format) | ||||||
|         low_format = VtfPF(header.low_pixel_format) |         low_format = VtfPF(header.low_pixel_format) | ||||||
| 
 |         if pixel_format == VtfPF.DXT1:  # Special case for DXT1 | ||||||
|         if pixel_format in RGB_FORMATS: |             self.mode = "RGBA" | ||||||
|  |         elif pixel_format in RGB_FORMATS: | ||||||
|             self.mode = "RGB" |             self.mode = "RGB" | ||||||
|         elif pixel_format in RGBA_FORMATS: |         elif pixel_format in RGBA_FORMATS: | ||||||
|             self.mode = "RGBA" |             self.mode = "RGBA" | ||||||
|  | @ -316,6 +320,12 @@ class VtfImageFile(ImageFile.ImageFile): | ||||||
|             tile = ("raw", (0, 0) + self.size, data_start, ("RGBA", 0, 1)) |             tile = ("raw", (0, 0) + self.size, data_start, ("RGBA", 0, 1)) | ||||||
|         elif pixel_format in (VtfPF.RGB888,): |         elif pixel_format in (VtfPF.RGB888,): | ||||||
|             tile = ("raw", (0, 0) + self.size, data_start, ("RGB", 0, 1)) |             tile = ("raw", (0, 0) + self.size, data_start, ("RGB", 0, 1)) | ||||||
|  |         elif pixel_format in (VtfPF.BGR888,): | ||||||
|  |             tile = ("raw", (0, 0) + self.size, data_start, ("BGR", 0, 1)) | ||||||
|  |         elif pixel_format in (VtfPF.BGRA8888,): | ||||||
|  |             tile = ("raw", (0, 0) + self.size, data_start, ("BGRA", 0, 1)) | ||||||
|  |         elif pixel_format in (VtfPF.UV88,): | ||||||
|  |             tile = ("raw", (0, 0) + self.size, data_start, ("LA", 0, 1)) | ||||||
|         elif pixel_format in L_FORMATS: |         elif pixel_format in L_FORMATS: | ||||||
|             tile = ("raw", (0, 0) + self.size, data_start, ("L", 0, 1)) |             tile = ("raw", (0, 0) + self.size, data_start, ("L", 0, 1)) | ||||||
|         elif pixel_format in LA_FORMATS: |         elif pixel_format in LA_FORMATS: | ||||||
|  |  | ||||||
|  | @ -384,7 +384,6 @@ PyImaging_BcnEncoderNew(PyObject *self, PyObject *args) { | ||||||
|     ImagingEncoderObject *encoder; |     ImagingEncoderObject *encoder; | ||||||
| 
 | 
 | ||||||
|     char *mode; |     char *mode; | ||||||
|     char *actual; |  | ||||||
|     int n = 0; |     int n = 0; | ||||||
|     char *pixel_format = ""; |     char *pixel_format = ""; | ||||||
|     if (!PyArg_ParseTuple(args, "si|s", &mode, &n, &pixel_format)) { |     if (!PyArg_ParseTuple(args, "si|s", &mode, &n, &pixel_format)) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user