From 22114c1fc4b27a6474b9a7b63d6f279e50fe80f5 Mon Sep 17 00:00:00 2001 From: John Whitington Date: Thu, 1 Feb 2024 15:22:19 +0000 Subject: [PATCH] More work towards -lossless-resample-dpi --- cpdfcommand.ml | 2 +- cpdfimage.ml | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index c0e4a2b..e0262cf 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -2677,7 +2677,7 @@ and specs = ("-lossless-resample", Arg.Int setlosslessresample, " Resample lossless images to given part of original"); - ("-lossless-resample", + ("-lossless-resample-dpi", Arg.Int setlosslessresampledpi, " Resample lossless images to given DPI"); ("-resample-interpolate", diff --git a/cpdfimage.ml b/cpdfimage.ml index 8a8a03f..7e01091 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -813,9 +813,9 @@ let process | `List l -> hashset_of_list (map (function `Assoc (("Object", `Int i)::_) -> i | _ -> assert false) l) | _ -> assert false in - let highdpi = - let objnums = - if dpi_threshold = 0 then [] else + let highdpi, target_dpi_info = + let objnums, dpi = + if dpi_threshold = 0 && factor > 0 then ([], []) else let results = image_resolution pdf range max_float in (*iter (fun (_, _, _, _, wdpi, hdpi, objnum) -> Printf.printf "From image_resolution %f %f %i\n" wdpi hdpi objnum) results;*) let cmp (_, _, _, _, _, _, a) (_, _, _, _, _, _, b) = compare a b in @@ -824,14 +824,17 @@ let process (*iter (fun (_, _, _, _, wdpi, hdpi, objnum) -> Printf.printf "Lowest resolution exemplar %f %f %i\n" wdpi hdpi objnum) heads;*) let needed = keep (fun (_, _, _, _, wdpi, hdpi, objnum) -> fmin wdpi hdpi > float_of_int dpi_threshold) heads in (*iter (fun (_, _, _, _, wdpi, hdpi, objnum) -> Printf.printf "keep %f %f %i\n" wdpi hdpi objnum) needed;*) - map (fun (_, _, _, _, _, _, objnum) -> objnum) needed + map (fun (_, _, _, _, _, _, objnum) -> objnum) needed, +let r = + map (fun (_, _, _, _, wdpi, hdpi, objnum) -> (objnum, fmin wdpi hdpi)) heads + in + iter (fun (x, d) -> Printf.printf "obj %i at %f dpi\n" x d) r; r in - hashset_of_list objnums + hashset_of_list objnums, hashset_of_list dpi in begin match onebppmethod with Some "JBIG2Lossy" -> preprocess_jbig2_lossy ~path_to_jbig2enc ~jbig2_lossy_threshold ~dpi_threshold ~length_threshold ~pixel_threshold inrange highdpi pdf | _ -> () end; let nobjects = Pdf.objcard pdf in let ndone = ref 0 in - let target_dpi_info = if factor < 0 then [] else [] in let process_obj objnum s = match s with | Pdf.Stream ({contents = dict, _} as reference) ->