mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 07:57:27 +03:00 
			
		
		
		
	Test j2k
This commit is contained in:
		
							parent
							
								
									6cd0e1757b
								
							
						
					
					
						commit
						329fd00d3f
					
				
							
								
								
									
										
											BIN
										
									
								
								Tests/images/rgb_trns_ycbc.j2k
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/rgb_trns_ycbc.j2k
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Tests/images/rgb_trns_ycbc.jp2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tests/images/rgb_trns_ycbc.jp2
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							|  | @ -1,7 +1,6 @@ | ||||||
| from tester import * | from tester import * | ||||||
| 
 | 
 | ||||||
| from PIL import Image | from PIL import Image | ||||||
| from PIL import ImageFile |  | ||||||
| 
 | 
 | ||||||
| codecs = dir(Image.core) | codecs = dir(Image.core) | ||||||
| 
 | 
 | ||||||
|  | @ -15,18 +14,20 @@ ignore('Not enough memory to handle tile data') | ||||||
| test_card = Image.open('Tests/images/test-card.png') | test_card = Image.open('Tests/images/test-card.png') | ||||||
| test_card.load() | test_card.load() | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def roundtrip(im, **options): | def roundtrip(im, **options): | ||||||
|     out = BytesIO() |     out = BytesIO() | ||||||
|     im.save(out, "JPEG2000", **options) |     im.save(out, "JPEG2000", **options) | ||||||
|     bytes = out.tell() |     bytes = out.tell() | ||||||
|     out.seek(0) |     out.seek(0) | ||||||
|     im = Image.open(out) |     im = Image.open(out) | ||||||
|     im.bytes = bytes # for testing only |     im.bytes = bytes  # for testing only | ||||||
|     im.load() |     im.load() | ||||||
|     return im |     return im | ||||||
| 
 | 
 | ||||||
| # ---------------------------------------------------------------------- | # ---------------------------------------------------------------------- | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_sanity(): | def test_sanity(): | ||||||
|     # Internal version number |     # Internal version number | ||||||
|     assert_match(Image.core.jp2klib_version, '\d+\.\d+\.\d+$') |     assert_match(Image.core.jp2klib_version, '\d+\.\d+\.\d+$') | ||||||
|  | @ -36,9 +37,10 @@ def test_sanity(): | ||||||
|     assert_equal(im.mode, 'RGB') |     assert_equal(im.mode, 'RGB') | ||||||
|     assert_equal(im.size, (640, 480)) |     assert_equal(im.size, (640, 480)) | ||||||
|     assert_equal(im.format, 'JPEG2000') |     assert_equal(im.format, 'JPEG2000') | ||||||
|      | 
 | ||||||
| # ---------------------------------------------------------------------- | # ---------------------------------------------------------------------- | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| # These two test pre-written JPEG 2000 files that were not written with | # These two test pre-written JPEG 2000 files that were not written with | ||||||
| # PIL (they were made using Adobe Photoshop) | # PIL (they were made using Adobe Photoshop) | ||||||
| 
 | 
 | ||||||
|  | @ -48,6 +50,7 @@ def test_lossless(): | ||||||
|     im.save('/tmp/test-card.png') |     im.save('/tmp/test-card.png') | ||||||
|     assert_image_similar(im, test_card, 1.0e-3) |     assert_image_similar(im, test_card, 1.0e-3) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_lossy_tiled(): | def test_lossy_tiled(): | ||||||
|     im = Image.open('Tests/images/test-card-lossy-tiled.jp2') |     im = Image.open('Tests/images/test-card-lossy-tiled.jp2') | ||||||
|     im.load() |     im.load() | ||||||
|  | @ -55,49 +58,58 @@ def test_lossy_tiled(): | ||||||
| 
 | 
 | ||||||
| # ---------------------------------------------------------------------- | # ---------------------------------------------------------------------- | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_lossless_rt(): | def test_lossless_rt(): | ||||||
|     im = roundtrip(test_card) |     im = roundtrip(test_card) | ||||||
|     assert_image_equal(im, test_card) |     assert_image_equal(im, test_card) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_lossy_rt(): | def test_lossy_rt(): | ||||||
|     im = roundtrip(test_card, quality_layers=[20]) |     im = roundtrip(test_card, quality_layers=[20]) | ||||||
|     assert_image_similar(im, test_card, 2.0) |     assert_image_similar(im, test_card, 2.0) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_tiled_rt(): | def test_tiled_rt(): | ||||||
|     im = roundtrip(test_card, tile_size=(128, 128)) |     im = roundtrip(test_card, tile_size=(128, 128)) | ||||||
|     assert_image_equal(im, test_card) |     assert_image_equal(im, test_card) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_tiled_offset_rt(): | def test_tiled_offset_rt(): | ||||||
|     im = roundtrip(test_card, tile_size=(128, 128), tile_offset=(0, 0), |     im = roundtrip(test_card, tile_size=(128, 128), tile_offset=(0, 0), | ||||||
|                    offset=(32, 32)) |                    offset=(32, 32)) | ||||||
|     assert_image_equal(im, test_card) |     assert_image_equal(im, test_card) | ||||||
|      | 
 | ||||||
|  | 
 | ||||||
| def test_irreversible_rt(): | def test_irreversible_rt(): | ||||||
|     im = roundtrip(test_card, irreversible=True, quality_layers=[20]) |     im = roundtrip(test_card, irreversible=True, quality_layers=[20]) | ||||||
|     assert_image_similar(im, test_card, 2.0) |     assert_image_similar(im, test_card, 2.0) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_prog_qual_rt(): | def test_prog_qual_rt(): | ||||||
|     im = roundtrip(test_card, quality_layers=[60, 40, 20], progression='LRCP') |     im = roundtrip(test_card, quality_layers=[60, 40, 20], progression='LRCP') | ||||||
|     assert_image_similar(im, test_card, 2.0) |     assert_image_similar(im, test_card, 2.0) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_prog_res_rt(): | def test_prog_res_rt(): | ||||||
|     im = roundtrip(test_card, num_resolutions=8, progression='RLCP') |     im = roundtrip(test_card, num_resolutions=8, progression='RLCP') | ||||||
|     assert_image_equal(im, test_card) |     assert_image_equal(im, test_card) | ||||||
| 
 | 
 | ||||||
| # ---------------------------------------------------------------------- | # ---------------------------------------------------------------------- | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_reduce(): | def test_reduce(): | ||||||
|     im = Image.open('Tests/images/test-card-lossless.jp2') |     im = Image.open('Tests/images/test-card-lossless.jp2') | ||||||
|     im.reduce = 2 |     im.reduce = 2 | ||||||
|     im.load() |     im.load() | ||||||
|     assert_equal(im.size, (160, 120)) |     assert_equal(im.size, (160, 120)) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_layers(): | def test_layers(): | ||||||
|     out = BytesIO() |     out = BytesIO() | ||||||
|     test_card.save(out, 'JPEG2000', quality_layers=[100, 50, 10], |     test_card.save(out, 'JPEG2000', quality_layers=[100, 50, 10], | ||||||
|                    progression='LRCP') |                    progression='LRCP') | ||||||
|     out.seek(0) |     out.seek(0) | ||||||
|      | 
 | ||||||
|     im = Image.open(out) |     im = Image.open(out) | ||||||
|     im.layers = 1 |     im.layers = 1 | ||||||
|     im.load() |     im.load() | ||||||
|  | @ -108,3 +120,17 @@ def test_layers(): | ||||||
|     im.layers = 3 |     im.layers = 3 | ||||||
|     im.load() |     im.load() | ||||||
|     assert_image_similar(im, test_card, 0.4) |     assert_image_similar(im, test_card, 0.4) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def test_rgba(): | ||||||
|  |     # Arrange | ||||||
|  |     j2k = Image.open('Tests/images/rgb_trns_ycbc.j2k') | ||||||
|  |     jp2 = Image.open('Tests/images/rgb_trns_ycbc.jp2') | ||||||
|  | 
 | ||||||
|  |     # Act | ||||||
|  |     j2k.load() | ||||||
|  |     jp2.load() | ||||||
|  | 
 | ||||||
|  |     # Assert | ||||||
|  |     assert_equal(j2k.mode, 'RGBA') | ||||||
|  |     assert_equal(jp2.mode, 'RGBA') | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user