First functioning resample

This commit is contained in:
John Whitington 2024-01-01 16:58:58 +00:00
parent bb620c8f06
commit 597d2a5e16
1 changed files with 10 additions and 8 deletions

View File

@ -617,17 +617,20 @@ let lossless_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshol
remove out;
remove out2
(* 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 =
match lossless_out pdf ~pixel_threshold ~length_threshold ".png" s dict reference with None -> () | Some (out, out2, size, components, w, h) ->
let retcode =
(* FIXME upscale required at all? *)
let command =
(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 = 1 then ["-colorspace"; "Gray"] else if components = 3 then ["-colorspace"; "RGB"] else if components = 4 then ["-colorspace"; "CMYK"] else []) @
["-sample"; string_of_int factor ^ "%"] @
[out] @
["PNG24:" ^ out2]))
["PNG24:" ^ out2])) (*FIXME do we need this anymore? *)
in
Printf.printf "%S\n" command; Sys.command command
(*Printf.printf "%S\n" command;*) Sys.command command
in
if retcode = 0 then
begin
@ -636,13 +639,12 @@ let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_thresho
if newsize < size then
begin
if !debug_image_processing then Printf.printf "lossless resample %i -> %i (%i%%)\n%!" size newsize (int_of_float (float newsize /. float size *. 100.));
(* FIXME Load PNG data in, per existing code: add filter, predictor, length *)
(* 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? *)
reference :=
(Pdf.add_dict_entry
(Pdf.add_dict_entry dict "/Length" (Pdf.Integer newsize))
"/Filter"
(Pdf.Name "/DCTDecode")),
Pdf.Got (Pdfio.bytes_of_input_channel result)
match fst (obj_of_png_data (Pdfio.bytes_of_input_channel result)) with
| Pdf.Stream s -> !s
| _ -> assert false
end
else
begin