Squeeze now recompresses old compression methods

This commit is contained in:
John Whitington 2024-01-16 16:25:07 +00:00
parent 6408bd8879
commit 81409cfcaf
2 changed files with 8 additions and 3 deletions

View File

@ -28,6 +28,7 @@ o More PNGs - greyscale 1, 2, 4, 8, 16bpp and RGB 16bpp
o -pages -fast to print number of pages from /Count
o Report number of annotations in -page-info
o Specify image based only on file extension
o -squeeze updates old compression methods
Fixes:
@ -36,7 +37,6 @@ o Fixed -set-annotations with page links
o Allow Exif JPEGs as well as JFIF ones in -jpeg and -draw-jpeg
o Only compress a stream if it actually makes it smaller
2.6.1 (September 2023)
o Fixed regression in UTF8 text with -add-text

View File

@ -13,14 +13,19 @@ let report_pdf_size pdf =
(* Recompress anything which isn't compressed, unless it's metadata. *)
let recompress_stream pdf = function
(* If there is no compression, compress with /FlateDecode *)
(* If there is no compression, or bad compression with /FlateDecode *)
| Pdf.Stream {contents = (dict, _)} as stream ->
begin match
Pdf.lookup_direct pdf "/Filter" dict,
Pdf.lookup_direct pdf "/Type" dict
with
| _, Some (Pdf.Name "/Metadata") -> ()
| (None | Some (Pdf.Array [])), _ ->
| ( None
| Some (Pdf.Name ("/ASCIIHexDecode" | "/ASCII85Decode" | "/LZWDecode" | "/RunLengthDecode"))
| Some (Pdf.Array []
| Pdf.Array (Pdf.Name ("/ASCIIHexDecode" | "/ASCII85Decode" | "/LZWDecode" | "/RunLengthDecode")::_)
)), _ ->
Pdfcodec.decode_pdfstream_until_unknown pdf stream;
Pdfcodec.encode_pdfstream ~only_if_smaller:true pdf Pdfcodec.Flate stream
| _ -> ()
end