mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-30 23:47:27 +03:00 
			
		
		
		
	Merge pull request #5430 from radarhere/pdf_1
Switched to saving 1-bit PDFs with DCTDecode
This commit is contained in:
		
						commit
						dc817ead76
					
				|  | @ -42,7 +42,8 @@ def test_monochrome(tmp_path): | ||||||
|     mode = "1" |     mode = "1" | ||||||
| 
 | 
 | ||||||
|     # Act / Assert |     # Act / Assert | ||||||
|     helper_save_as_pdf(tmp_path, mode) |     outfile = helper_save_as_pdf(tmp_path, mode) | ||||||
|  |     assert os.path.getsize(outfile) < 15000 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_greyscale(tmp_path): | def test_greyscale(tmp_path): | ||||||
|  |  | ||||||
|  | @ -124,7 +124,7 @@ def _save(im, fp, filename, save_all=False): | ||||||
|             decode = None |             decode = None | ||||||
| 
 | 
 | ||||||
|             if im.mode == "1": |             if im.mode == "1": | ||||||
|                 filter = "ASCIIHexDecode" |                 filter = "DCTDecode" | ||||||
|                 colorspace = PdfParser.PdfName("DeviceGray") |                 colorspace = PdfParser.PdfName("DeviceGray") | ||||||
|                 procset = "ImageB"  # grayscale |                 procset = "ImageB"  # grayscale | ||||||
|                 bits = 1 |                 bits = 1 | ||||||
|  | @ -161,12 +161,6 @@ def _save(im, fp, filename, save_all=False): | ||||||
|             op = io.BytesIO() |             op = io.BytesIO() | ||||||
| 
 | 
 | ||||||
|             if filter == "ASCIIHexDecode": |             if filter == "ASCIIHexDecode": | ||||||
|                 if bits == 1: |  | ||||||
|                     # FIXME: the hex encoder doesn't support packed 1-bit |  | ||||||
|                     # images; do things the hard way... |  | ||||||
|                     data = im.tobytes("raw", "1") |  | ||||||
|                     im = Image.new("L", im.size) |  | ||||||
|                     im.putdata(data) |  | ||||||
|                 ImageFile._save(im, op, [("hex", (0, 0) + im.size, 0, im.mode)]) |                 ImageFile._save(im, op, [("hex", (0, 0) + im.size, 0, im.mode)]) | ||||||
|             elif filter == "DCTDecode": |             elif filter == "DCTDecode": | ||||||
|                 Image.SAVE["JPEG"](im, op, filename) |                 Image.SAVE["JPEG"](im, op, filename) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user