First functioning resample
This commit is contained in:
parent
bb620c8f06
commit
597d2a5e16
18
cpdfimage.ml
18
cpdfimage.ml
|
@ -617,17 +617,20 @@ let lossless_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshol
|
||||||
remove out;
|
remove out;
|
||||||
remove out2
|
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 =
|
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) ->
|
||||||
let retcode =
|
let retcode =
|
||||||
|
(* FIXME upscale required at all? *)
|
||||||
let command =
|
let command =
|
||||||
(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 ^ "%"] @
|
||||||
[out] @
|
[out] @
|
||||||
["PNG24:" ^ out2]))
|
["PNG24:" ^ out2])) (*FIXME do we need this anymore? *)
|
||||||
in
|
in
|
||||||
Printf.printf "%S\n" command; Sys.command command
|
(*Printf.printf "%S\n" command;*) Sys.command command
|
||||||
in
|
in
|
||||||
if retcode = 0 then
|
if retcode = 0 then
|
||||||
begin
|
begin
|
||||||
|
@ -636,13 +639,12 @@ 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 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 :=
|
reference :=
|
||||||
(Pdf.add_dict_entry
|
match fst (obj_of_png_data (Pdfio.bytes_of_input_channel result)) with
|
||||||
(Pdf.add_dict_entry dict "/Length" (Pdf.Integer newsize))
|
| Pdf.Stream s -> !s
|
||||||
"/Filter"
|
| _ -> assert false
|
||||||
(Pdf.Name "/DCTDecode")),
|
|
||||||
Pdf.Got (Pdfio.bytes_of_input_channel result)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
|
Loading…
Reference in New Issue