Scaffolding for -lossless-resample
This commit is contained in:
parent
8859f17584
commit
67d1cb604e
|
@ -528,7 +528,9 @@ type args =
|
||||||
mutable onebppmethod : string;
|
mutable onebppmethod : string;
|
||||||
mutable pixel_threshold : int;
|
mutable pixel_threshold : int;
|
||||||
mutable length_threshold : int;
|
mutable length_threshold : int;
|
||||||
mutable percentage_threshold : int}
|
mutable percentage_threshold : int;
|
||||||
|
mutable resample_factor : int;
|
||||||
|
mutable resample_interpolate : bool}
|
||||||
|
|
||||||
let args =
|
let args =
|
||||||
{op = None;
|
{op = None;
|
||||||
|
@ -657,8 +659,15 @@ let args =
|
||||||
onebppmethod = "";
|
onebppmethod = "";
|
||||||
pixel_threshold = 25;
|
pixel_threshold = 25;
|
||||||
length_threshold = 100;
|
length_threshold = 100;
|
||||||
percentage_threshold = 99}
|
percentage_threshold = 99;
|
||||||
|
resample_factor = 100;
|
||||||
|
resample_interpolate = false}
|
||||||
|
|
||||||
|
(* Do not reset original_filename or cpdflin or was_encrypted or
|
||||||
|
was_decrypted_with_owner or recrypt or producer or creator or path_to_* or
|
||||||
|
gs_malformed or gs_quiet or no-warn-rotate, since we want these to work
|
||||||
|
across ANDs. Or squeeze options: a little odd, but we want it to happen on
|
||||||
|
eventual output. Or -debug-force (from v2.6). *)
|
||||||
let reset_arguments () =
|
let reset_arguments () =
|
||||||
args.op <- None;
|
args.op <- None;
|
||||||
args.preserve_objstm <- true;
|
args.preserve_objstm <- true;
|
||||||
|
@ -768,11 +777,8 @@ 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;
|
||||||
(* Do not reset original_filename or cpdflin or was_encrypted or
|
args.resample_factor <- 100;
|
||||||
was_decrypted_with_owner or recrypt or producer or creator or path_to_* or
|
args.resample_interpolate <- false;
|
||||||
gs_malformed or gs_quiet or no-warn-rotate, since we want these to work
|
|
||||||
across ANDs. Or squeeze options: a little odd, but we want it to happen on
|
|
||||||
eventual output. Or -debug-force (from v2.6). *)
|
|
||||||
clear Cpdfdrawcontrol.fontpack_initialised
|
clear Cpdfdrawcontrol.fontpack_initialised
|
||||||
|
|
||||||
(* Prefer a) the one given with -cpdflin b) a local cpdflin, c) otherwise assume
|
(* Prefer a) the one given with -cpdflin b) a local cpdflin, c) otherwise assume
|
||||||
|
@ -1956,6 +1962,12 @@ let setlengththreshold i =
|
||||||
let setpercentagethreshold i =
|
let setpercentagethreshold i =
|
||||||
args.percentage_threshold <- i
|
args.percentage_threshold <- i
|
||||||
|
|
||||||
|
let setlosslessresample i =
|
||||||
|
args.resample_factor <- i
|
||||||
|
|
||||||
|
let setresampleinterpolate b =
|
||||||
|
args.resample_interpolate <- b
|
||||||
|
|
||||||
let setprocessimagesinfo () =
|
let setprocessimagesinfo () =
|
||||||
set Cpdfimage.debug_image_processing
|
set Cpdfimage.debug_image_processing
|
||||||
|
|
||||||
|
@ -2760,6 +2772,12 @@ and specs =
|
||||||
("-percentage-threshold",
|
("-percentage-threshold",
|
||||||
Arg.Int setpercentagethreshold,
|
Arg.Int setpercentagethreshold,
|
||||||
" Only substitute lossy image when smaller than this");
|
" Only substitute lossy image when smaller than this");
|
||||||
|
("-lossless-resample",
|
||||||
|
Arg.Int setlosslessresample,
|
||||||
|
" Resample lossless images to given part of original");
|
||||||
|
("-resample-interpolate",
|
||||||
|
Arg.Bool setresampleinterpolate,
|
||||||
|
" Interpolate when resampling");
|
||||||
("-squeeze",
|
("-squeeze",
|
||||||
Arg.Unit setsqueeze,
|
Arg.Unit setsqueeze,
|
||||||
" Squeeze");
|
" Squeeze");
|
||||||
|
@ -4499,7 +4517,8 @@ let go () =
|
||||||
let pdf = get_single_pdf args.op false in
|
let pdf = get_single_pdf args.op false in
|
||||||
Cpdfimage.process
|
Cpdfimage.process
|
||||||
~q:args.jpegquality ~qlossless:args.jpegqualitylossless ~onebppmethod:args.onebppmethod
|
~q:args.jpegquality ~qlossless:args.jpegqualitylossless ~onebppmethod:args.onebppmethod
|
||||||
~length_threshold:args.length_threshold ~pixel_threshold:args.pixel_threshold ~percentage_threshold:args.percentage_threshold
|
~length_threshold:args.length_threshold ~percentage_threshold:args.percentage_threshold ~pixel_threshold:args.pixel_threshold
|
||||||
|
~factor:args.resample_factor ~interpolate:args.resample_interpolate
|
||||||
~path_to_jbig2enc:args.path_to_jbig2enc ~path_to_convert:args.path_to_convert pdf;
|
~path_to_jbig2enc:args.path_to_jbig2enc ~path_to_convert:args.path_to_convert pdf;
|
||||||
write_pdf false pdf
|
write_pdf false pdf
|
||||||
|
|
||||||
|
|
12
cpdfimage.ml
12
cpdfimage.ml
|
@ -617,7 +617,7 @@ let lossless_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshol
|
||||||
remove out;
|
remove out;
|
||||||
remove out2
|
remove out2
|
||||||
|
|
||||||
let lossless_resample pdf ~pixel_threshold ~length_threshold ~percentage_threshold~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 =
|
||||||
let command =
|
let command =
|
||||||
|
@ -702,7 +702,7 @@ let recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_j
|
||||||
(* Lossless to JPEG: 8bpp Grey, 8bpp RGB, 8bpp CMYK including separation and ICCBased colourspaces *)
|
(* Lossless to JPEG: 8bpp Grey, 8bpp RGB, 8bpp CMYK including separation and ICCBased colourspaces *)
|
||||||
(* 1 bit: anything to JBIG2 lossless (no globals) *)
|
(* 1 bit: anything to JBIG2 lossless (no globals) *)
|
||||||
let process
|
let process
|
||||||
?q ?qlossless ?onebppmethod ~length_threshold ~percentage_threshold ~pixel_threshold
|
?q ?qlossless ?onebppmethod ~length_threshold ~percentage_threshold ~pixel_threshold ~factor ~interpolate
|
||||||
~path_to_jbig2enc ~path_to_convert pdf
|
~path_to_jbig2enc ~path_to_convert pdf
|
||||||
=
|
=
|
||||||
let nobjects = Pdf.objcard pdf in
|
let nobjects = Pdf.objcard pdf in
|
||||||
|
@ -745,6 +745,14 @@ let process
|
||||||
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_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~qlossless ~path_to_convert s dict reference
|
lossless_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~qlossless ~path_to_convert s dict reference
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
if factor < 100 then
|
||||||
|
begin
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
| None -> ()
|
| None -> ()
|
||||||
end
|
end
|
||||||
| _ -> () (* not an image *)
|
| _ -> () (* not an image *)
|
||||||
|
|
|
@ -17,6 +17,7 @@ val images : Pdf.t -> int list -> Cpdfyojson.Safe.t
|
||||||
val process :
|
val process :
|
||||||
?q:int -> ?qlossless:int -> ?onebppmethod:string ->
|
?q:int -> ?qlossless:int -> ?onebppmethod:string ->
|
||||||
length_threshold:int -> percentage_threshold:int -> pixel_threshold:int ->
|
length_threshold:int -> percentage_threshold:int -> pixel_threshold:int ->
|
||||||
|
factor:int -> interpolate:bool ->
|
||||||
path_to_jbig2enc:string -> path_to_convert:string -> Pdf.t -> unit
|
path_to_jbig2enc:string -> path_to_convert:string -> Pdf.t -> unit
|
||||||
|
|
||||||
(**/**)
|
(**/**)
|
||||||
|
|
Loading…
Reference in New Issue