Allow -lossless-resample 100
This commit is contained in:
parent
310b5e1a19
commit
35826e45cc
|
@ -660,7 +660,7 @@ let args =
|
||||||
pixel_threshold = 25;
|
pixel_threshold = 25;
|
||||||
length_threshold = 100;
|
length_threshold = 100;
|
||||||
percentage_threshold = 99;
|
percentage_threshold = 99;
|
||||||
resample_factor = 100;
|
resample_factor = 101;
|
||||||
resample_interpolate = false}
|
resample_interpolate = false}
|
||||||
|
|
||||||
(* Do not reset original_filename or cpdflin or was_encrypted or
|
(* Do not reset original_filename or cpdflin or was_encrypted or
|
||||||
|
@ -777,7 +777,7 @@ let reset_arguments () =
|
||||||
args.pixel_threshold <- 25;
|
args.pixel_threshold <- 25;
|
||||||
args.length_threshold <- 100;
|
args.length_threshold <- 100;
|
||||||
args.percentage_threshold <- 99;
|
args.percentage_threshold <- 99;
|
||||||
args.resample_factor <- 100;
|
args.resample_factor <- 101;
|
||||||
args.resample_interpolate <- false;
|
args.resample_interpolate <- false;
|
||||||
clear Cpdfdrawcontrol.fontpack_initialised
|
clear Cpdfdrawcontrol.fontpack_initialised
|
||||||
|
|
||||||
|
|
41
cpdfimage.ml
41
cpdfimage.ml
|
@ -624,19 +624,8 @@ let combine_dicts o n =
|
||||||
Printf.printf "%s\n" (Pdfwrite.string_of_pdf (Pdf.Dictionary x));
|
Printf.printf "%s\n" (Pdfwrite.string_of_pdf (Pdf.Dictionary x));
|
||||||
x
|
x
|
||||||
|
|
||||||
let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~factor ~interpolate ~path_to_convert s dict reference =
|
(*let out3 = Filename.temp_file "cpdf" "convertout" ^ ".png" in*)
|
||||||
match lossless_out pdf ~pixel_threshold ~length_threshold ".png" s dict reference with None -> () | Some (out, out2, size, components, w, h) ->
|
(*let factor' = int_of_float (100. /. float_of_int factor *. 100.) in
|
||||||
let out3 = Filename.temp_file "cpdf" "convertout" ^ ".png" in
|
|
||||||
let retcode =
|
|
||||||
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 []) @
|
|
||||||
[if interpolate then "-resize" else "-sample"; string_of_int factor ^ "%"] @
|
|
||||||
[out] @
|
|
||||||
[(*"PNG24:" ^*) out2])) (* without this, might produce a palettised PNG. FIXME:How can we allow 1/2/4/8/24 but without palette? Might anyway? *)
|
|
||||||
in
|
|
||||||
let factor' = int_of_float (100. /. float_of_int factor *. 100.) in
|
|
||||||
let command2 =
|
let command2 =
|
||||||
(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 []) @
|
||||||
|
@ -644,16 +633,27 @@ let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_thresho
|
||||||
[if interpolate then "-resize" else "-sample"; string_of_int factor' ^ "%"] @
|
[if interpolate then "-resize" else "-sample"; string_of_int factor' ^ "%"] @
|
||||||
[out2] @
|
[out2] @
|
||||||
[(*"PNG24:" ^*) out3]))
|
[(*"PNG24:" ^*) out3]))
|
||||||
|
in*)
|
||||||
|
|
||||||
|
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 (_, _, _, 4, _, _) -> Printf.printf "lossless resampling for CMYK not supported yet\n%!"
|
||||||
|
| Some (out, out2, size, components, w, h) ->
|
||||||
|
let retcode =
|
||||||
|
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 ["-define"; "png:color-type=0"; "-colorspace"; "Gray"] else if components = 3 then ["-define"; "-png:color-type=2"; "-colorspace"; "RGB"] else if components = 4 then ["-colorspace"; "CMYK"] else []) @
|
||||||
|
[if interpolate then "-resize" else "-sample"; string_of_int factor ^ "%"; out; out2])
|
||||||
in
|
in
|
||||||
Printf.printf "1: %S\n" command;
|
(*Printf.printf "%S\n" command; *)
|
||||||
Printf.printf "2: %S\n" command2;
|
Sys.command command
|
||||||
let r = Sys.command command in
|
|
||||||
let r' = Sys.command command2 in
|
|
||||||
r + r'
|
|
||||||
in
|
in
|
||||||
|
try
|
||||||
if retcode = 0 then
|
if retcode = 0 then
|
||||||
begin
|
begin
|
||||||
let result = open_in_bin out3 in
|
let result = open_in_bin out2 in
|
||||||
let newsize = in_channel_length result in
|
let newsize = in_channel_length result in
|
||||||
if newsize < size then
|
if newsize < size then
|
||||||
begin
|
begin
|
||||||
|
@ -674,6 +674,7 @@ let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_thresho
|
||||||
remove out;
|
remove out;
|
||||||
remove out2
|
remove out2
|
||||||
remove out3*)
|
remove out3*)
|
||||||
|
with _ -> () (* FIXME Remove *)
|
||||||
|
|
||||||
let recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_jbig2enc pdf s dict reference =
|
let recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_jbig2enc pdf s dict reference =
|
||||||
let w = match Pdf.lookup_direct pdf "/Width" dict with Some (Pdf.Integer i) -> i | _ -> error "bad width" in
|
let w = match Pdf.lookup_direct pdf "/Width" dict with Some (Pdf.Integer i) -> i | _ -> error "bad width" in
|
||||||
|
@ -770,7 +771,7 @@ let process
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
if factor < 100 then
|
if factor < 101 then
|
||||||
begin
|
begin
|
||||||
if !debug_image_processing then Printf.printf "(%i/%i) object %i (lossless)... %!" !ndone nobjects objnum;
|
if !debug_image_processing then Printf.printf "(%i/%i) object %i (lossless)... %!" !ndone nobjects objnum;
|
||||||
lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~factor ~interpolate ~path_to_convert s dict reference
|
lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~factor ~interpolate ~path_to_convert s dict reference
|
||||||
|
|
Loading…
Reference in New Issue