Interpolation

This commit is contained in:
John Whitington 2024-01-01 19:09:40 +00:00
parent 597d2a5e16
commit 9703f812d5
2 changed files with 16 additions and 8 deletions

View File

@ -1965,8 +1965,8 @@ let setpercentagethreshold i =
let setlosslessresample i = let setlosslessresample i =
args.resample_factor <- i args.resample_factor <- i
let setresampleinterpolate b = let setresampleinterpolate () =
args.resample_interpolate <- b args.resample_interpolate <- true
let setprocessimagesinfo () = let setprocessimagesinfo () =
set Cpdfimage.debug_image_processing set Cpdfimage.debug_image_processing
@ -2776,7 +2776,7 @@ and specs =
Arg.Int setlosslessresample, Arg.Int setlosslessresample,
" Resample lossless images to given part of original"); " Resample lossless images to given part of original");
("-resample-interpolate", ("-resample-interpolate",
Arg.Bool setresampleinterpolate, Arg.Unit setresampleinterpolate,
" Interpolate when resampling"); " Interpolate when resampling");
("-squeeze", ("-squeeze",
Arg.Unit setsqueeze, Arg.Unit setsqueeze,

View File

@ -617,6 +617,13 @@ let lossless_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshol
remove out; remove out;
remove out2 remove out2
let combine_dicts o n =
let x =
fold_right (fun (k, v) d -> add k v d) o n
in
Printf.printf "%s\n" (Pdfwrite.string_of_pdf (Pdf.Dictionary x));
x
(* FIXME Need to specify exactly where this works, how to process with convert for each etc. *) (* FIXME Need to specify exactly where this works, how to process with convert for each etc. *)
let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~factor ~interpolate ~path_to_convert s dict reference = let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~factor ~interpolate ~path_to_convert s dict reference =
match lossless_out pdf ~pixel_threshold ~length_threshold ".png" s dict reference with None -> () | Some (out, out2, size, components, w, h) -> match lossless_out pdf ~pixel_threshold ~length_threshold ".png" s dict reference with None -> () | Some (out, out2, size, components, w, h) ->
@ -626,7 +633,7 @@ let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_thresho
(Filename.quote_command path_to_convert (Filename.quote_command path_to_convert
((if components = 4 then ["-depth"; "8"; "-size"; string_of_int w ^ "x" ^ string_of_int h] else []) @ ((if components = 4 then ["-depth"; "8"; "-size"; string_of_int w ^ "x" ^ string_of_int h] else []) @
(if components = 1 then ["-colorspace"; "Gray"] else if components = 3 then ["-colorspace"; "RGB"] else if components = 4 then ["-colorspace"; "CMYK"] else []) @ (if components = 1 then ["-colorspace"; "Gray"] else if components = 3 then ["-colorspace"; "RGB"] else if components = 4 then ["-colorspace"; "CMYK"] else []) @
["-sample"; string_of_int factor ^ "%"] @ [if interpolate then "-resize" else "-sample"; string_of_int factor ^ "%"] @
[out] @ [out] @
["PNG24:" ^ out2])) (*FIXME do we need this anymore? *) ["PNG24:" ^ out2])) (*FIXME do we need this anymore? *)
in in
@ -639,12 +646,13 @@ let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_thresho
if newsize < size then if newsize < size then
begin begin
if !debug_image_processing then Printf.printf "lossless resample %i -> %i (%i%%)\n%!" size newsize (int_of_float (float newsize /. float size *. 100.)); if !debug_image_processing then Printf.printf "lossless resample %i -> %i (%i%%)\n%!" size newsize (int_of_float (float newsize /. float size *. 100.));
(* FIXME Merge any extra dictionary entries from original on top of the one read back. *)
(* FIXME Check that we got back in what we expected? *) (* FIXME Check that we got back in what we expected? *)
reference := reference :=
match fst (obj_of_png_data (Pdfio.bytes_of_input_channel result)) with (match fst (obj_of_png_data (Pdfio.bytes_of_input_channel result)) with
| Pdf.Stream s -> !s | Pdf.Stream {contents = Pdf.Dictionary d, data} ->
| _ -> assert false let d' = fold_right (fun (k, v) d -> add k v d) d (match dict with Pdf.Dictionary x -> x | _ -> []) in
(Pdf.Dictionary d', data)
| _ -> assert false)
end end
else else
begin begin