First stab at dpi_threshold

This commit is contained in:
John Whitington 2024-01-04 19:31:21 +00:00
parent b26d36cddf
commit 847f498add
1 changed files with 16 additions and 1 deletions

View File

@ -723,13 +723,28 @@ let process
| `List l -> hashset_of_list (map (function `Assoc (("Object", `Int i)::_) -> i | _ -> assert false) l) | `List l -> hashset_of_list (map (function `Assoc (("Object", `Int i)::_) -> i | _ -> assert false) l)
| _ -> assert false | _ -> assert false
in in
let highdpi =
let objnums =
if dpi_threshold = 0 then [] else
let results = image_resolution pdf range max_float in
let cmp (_, _, _, _, _, _, a) (_, _, _, _, _, _, b) = compare a b in
(* Get each obj number associated with its *lowest* resolution *)
let sets = collate cmp (sort cmp results) in
let heads = map hd (map (sort (fun (_, _, _, _, a, b, _) (_, _, _, _, c, d, _) -> compare (fmin a b) (fmin c d))) sets) in
(* Choose only those where this figure is more than the dpi_threshold *)
(*iter (fun (_, _, _, _, wdpi, hdpi, objnum) -> Printf.printf "%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
map (fun (_, _, _, _, _, _, objnum) -> objnum) needed
in
hashset_of_list objnums
in
let nobjects = Pdf.objcard pdf in let nobjects = Pdf.objcard pdf in
let ndone = ref 0 in let ndone = ref 0 in
let process_obj objnum s = let process_obj objnum s =
match s with match s with
| Pdf.Stream ({contents = dict, _} as reference) -> | Pdf.Stream ({contents = dict, _} as reference) ->
ndone += 1; ndone += 1;
if Hashtbl.mem inrange objnum then begin match if Hashtbl.mem inrange objnum && (dpi_threshold = 0 || Hashtbl.mem highdpi objnum) then begin match
Pdf.lookup_direct pdf "/Subtype" dict, Pdf.lookup_direct pdf "/Subtype" dict,
Pdf.lookup_direct pdf "/Filter" dict, Pdf.lookup_direct pdf "/Filter" dict,
Pdf.lookup_direct pdf "/BitsPerComponent" dict, Pdf.lookup_direct pdf "/BitsPerComponent" dict,