From 3d0a4676a54871c0c6f25bf7f648bcfa284f5a22 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Tue, 20 Feb 2024 18:55:20 +0000 Subject: [PATCH] tidying up -process-images --- cpdfimage.ml | 13 ++++++++++--- cpdfmanual.pdf | Bin 412264 -> 412281 bytes cpdfmanual.tex | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cpdfimage.ml b/cpdfimage.ml index 99420ee..24a1c47 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -5,7 +5,7 @@ open Cpdferror let debug_image_processing = ref false let remove x = - try (*Printf.printf "%s\n" x;*) Sys.remove x with _ -> () + try Printf.printf "%s\n" x; Sys.remove x with _ -> () let pnm_white ch = output_char ch ' ' let pnm_newline ch = output_char ch '\n' @@ -709,7 +709,11 @@ let lossless_resample_target_dpi objnum pdf ~pixel_threshold ~length_threshold ~ if real_factor < 100. then lossless_resample pdf ~pixel_threshold ~length_threshold ~factor:real_factor ~interpolate ~path_to_convert s dict reference +let complain_jbig2enc path = + if path = "" then error "Specify jbig2enc location with -jbig2enc" + let recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_jbig2enc pdf s dict reference = + complain_jbig2enc path_to_jbig2enc; let old = !reference in let restore () = reference := old in let w = match Pdf.lookup_direct pdf "/Width" dict with Some (Pdf.Integer i) -> i | _ -> error "bad width" in @@ -734,7 +738,9 @@ let recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_j let command = Filename.quote_command ~stdout:out2 path_to_jbig2enc ["-d"; "-p"; out] in (*Printf.printf "%S\n" command;*) Sys.command command in - if retcode = 0 then + if retcode <> 0 then + restore () + else begin let result = open_in_bin out2 in let newsize = in_channel_length result in @@ -761,6 +767,7 @@ let recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_j (* Recompress 1bpp images (except existing JBIG2 compressed ones) to lossy jbig2 *) let preprocess_jbig2_lossy ~path_to_jbig2enc ~jbig2_lossy_threshold ~length_threshold ~pixel_threshold ~dpi_threshold inrange highdpi pdf = + complain_jbig2enc path_to_jbig2enc; let objnum_name_pairs = ref [] in let process_obj objnum s = match s with @@ -791,7 +798,7 @@ let preprocess_jbig2_lossy ~path_to_jbig2enc ~jbig2_lossy_threshold ~length_thre let data = match s with Pdf.Stream {contents = _, Pdf.Got d} -> d | _ -> assert false in pnm_to_channel_1_inverted fh w h data; close_out fh; - if !debug_image_processing then Printf.printf "obj %i is suitable\n%!" objnum; + if !debug_image_processing then Printf.printf "JBIG2Lossy: obj %i is suitable\n%!" objnum; objnum_name_pairs := (objnum, out)::!objnum_name_pairs end | _ -> () (* not a 1bpp image *) diff --git a/cpdfmanual.pdf b/cpdfmanual.pdf index 39cd9f9e36101fc66a1b89e1d91f1d48917326c8..d4cc67e8208675248b4744b202fb1667ccec3268 100644 GIT binary patch delta 4628 zcmaiwXHXMrw6zneArxtm61qq;lu$w^Kp=FG-ldZuRq4ghqz6!X(@;eaMU0?;M?ktD z2}S7&B1nfrktSTuIrGgo_t*Wg_pEuJwby=U|H|b&&gG0v1QID!c!2PnSGwZ3GAqM- z$w=K>Iqo*O=QATSlWw9)$bwfn$ zIjbag$h^s%cS?`3MgYz$D9w~sC`O^11-67Y744o!XJ#l~$ zI4<-J?}4)GgA_jv&Kdk$&M(hX4q7VXba<1wEgEFv4FYsrI@NMAJkq58;HFBzFWT0A z_bYm$JbbXzr=&wS(HV61b*o)ZKkr6-g8}W=&C$28muByo`rKbi?4_E&z%kYC7^!7A znQ4wY`9JzVDdk~81v8vbh7vejJQQBAK4J=m4SGX^fznhKm(f0)#b z4-!n2y;BiZk1)K(nb7wmerYHC!>(qfB{O3fsprdq@=m^Xuff}l^7B1MU31Z{CVK97 zYfL-*X`_m(v<|C5M)b|%;x7${0uX&clN-h@c6F@H+ox3%7Jf{%yExCkM+@-o4<$IH zbaJKnogf^?amjx#7oo7qcN0b`hMN`vb8&GHOZW}LKQ^oe#EjiloU%?9&}_+A-KYFbU-alw#l4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`0m){vaBufPCaN0TFnK}HF{FD}nxaDb2 zn1gRG!lIDj9g6>y?B}Z*Jv0A;MQ(@Ru`dljUTgcv2b0fxc=AaRY(+a6{t{)}h*eTQ z$vh42r+pyYx&+88ApF#WIu#I3GIt~{kPZ;Tmjv@4o&2)~{=~ykP9sp!rEW{w+Y+tM zYiAC7LVkY=Ulf=xng?%7j6}f-2MEmsN3&|l>w{nQoF{ya>kp!co~e~If+fHEW#40U zatZK;jeNIx&-Dd8MZ6%!>h_8I()Tyx&@h%_*z_^Q&^72?{K1`aJ9I=o@WzqHoIjl_ zR;g*r={MqM|4dJ)WU#?SJIb*$Z3{+%z5WoN>}jpHS>GG=H?L6b?A=9y=lnAS?$Pld zwWN&)pwZvl3HB;J9rL~0Pdo%`1bUTj9>M}cDu^!6`_4P^-GIp{-JDkx=^>iz<)tPg znqte5x~|>+J-)EZ?z!)rFq^t4-;V8db6<{%dn>8eV9*mdx=r@o5S+tRn4zVO4Zmw|$hD;={mJ+QHzk0fcCjz*3d0j#cZlOgEf~9nJ zysLrZ>v``u$XSgB-fw{6y3!e;d07|8S;eEZ@8dNkM&j<^CmcE4m40o%8lE7q@4o7S z1@|T0>^rti-Rx|3Jih^^Y--Q2p4__k@fU?4elUO1B@gy!f*@(@=5$eYN(a5BvnXQT2_`SoUip@Pp-%@-z8I zw)WAep5YGY$6(B;(^JYp<3+}#YUngvtN+ew)S^&cP2HZ^X;rdygg=nm)0>G1lMA zr!yXS+^zddXtVNk-JIwe)2g(ou7+8x%rj>%nYiStdyPB{eyLdSK#LFW#@B*+FcY%` z7Yvt`jt-HIekuLtn>Oc78NSU!(It5POptfMz5TR@ZTI$t7_0eu8AH!}J4=uxyP7H(4mYti1^)+O%Y;Dy diff --git a/cpdfmanual.tex b/cpdfmanual.tex index f4b8011..87ec19b 100644 --- a/cpdfmanual.tex +++ b/cpdfmanual.tex @@ -3895,7 +3895,7 @@ Method & Effect\\\hline \noindent It is not currently possible to reprocess lossless JBIG2 into lossy JBIG2, nor is it possible to recompress into CCITT. -NB: CYMK images will be converted to RGB by some of these processes. A future version of cpdf will remove this limitation. +NB: CYMK images will be converted to RGB or untouched by some of these processes. A future version of cpdf will remove this limitation. \begin{cpdflib} \clearpage