Rewrite W/H when -jpeg-to-jpeg
This commit is contained in:
parent
b10245ffd0
commit
f35954e16a
|
@ -683,7 +683,7 @@ let args =
|
||||||
no_warn_rotate = false;
|
no_warn_rotate = false;
|
||||||
jpegquality = 100.;
|
jpegquality = 100.;
|
||||||
jpegqualitylossless = 101.;
|
jpegqualitylossless = 101.;
|
||||||
jpegtojpegscale = 1.;
|
jpegtojpegscale = 100.;
|
||||||
jpegtojpegdpi = 0.;
|
jpegtojpegdpi = 0.;
|
||||||
onebppmethod = "";
|
onebppmethod = "";
|
||||||
pixel_threshold = 25;
|
pixel_threshold = 25;
|
||||||
|
|
12
cpdfimage.ml
12
cpdfimage.ml
|
@ -562,7 +562,7 @@ let image_of_input ?subformat ?title ~process_struct_tree fobj i =
|
||||||
let pdf, pageroot = Pdfpage.add_pagetree [page] pdf in
|
let pdf, pageroot = Pdfpage.add_pagetree [page] pdf in
|
||||||
Pdfpage.add_root pageroot [] pdf
|
Pdfpage.add_root pageroot [] pdf
|
||||||
|
|
||||||
let jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~jpeg_to_jpeg_scale ~jpeg_to_jpeg_dpi ~q ~path_to_convert s dict reference =
|
let jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~jpeg_to_jpeg_scale ~jpeg_to_jpeg_dpi ~interpolate ~q ~path_to_convert s dict reference =
|
||||||
if q < 0. || q > 100. then error "Out of range quality";
|
if q < 0. || q > 100. then error "Out of range quality";
|
||||||
complain_convert path_to_convert;
|
complain_convert path_to_convert;
|
||||||
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
|
||||||
|
@ -580,7 +580,7 @@ let jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~j
|
||||||
let command =
|
let command =
|
||||||
(Filename.quote_command path_to_convert [out; "-quality"; string_of_float q ^ "%"; out2])
|
(Filename.quote_command path_to_convert [out; "-quality"; string_of_float q ^ "%"; out2])
|
||||||
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
|
||||||
|
@ -590,8 +590,12 @@ let jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~j
|
||||||
let perc_ok = float newsize /. float size < percentage_threshold /. 100. in
|
let perc_ok = float newsize /. float size < percentage_threshold /. 100. in
|
||||||
if newsize < size && perc_ok then
|
if newsize < size && perc_ok then
|
||||||
begin
|
begin
|
||||||
|
let data = Pdfio.bytes_of_input_channel result in
|
||||||
|
let w, h = Cpdfjpeg.jpeg_dimensions data in
|
||||||
if !debug_image_processing then Printf.printf "JPEG to JPEG %i -> %i (%i%%)\n%!" size newsize (int_of_float (float newsize /. float size *. 100.));
|
if !debug_image_processing then Printf.printf "JPEG to JPEG %i -> %i (%i%%)\n%!" size newsize (int_of_float (float newsize /. float size *. 100.));
|
||||||
reference := Pdf.add_dict_entry dict "/Length" (Pdf.Integer newsize), Pdf.Got (Pdfio.bytes_of_input_channel result)
|
reference :=
|
||||||
|
Pdf.add_dict_entry (Pdf.add_dict_entry (Pdf.add_dict_entry dict "/Length" (Pdf.Integer newsize)) "/Width" (Pdf.Integer w)) "/Height" (Pdf.Integer h),
|
||||||
|
Pdf.Got (Pdfio.bytes_of_input_channel result)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
@ -975,7 +979,7 @@ let process
|
||||||
if q < 100. then
|
if q < 100. then
|
||||||
begin
|
begin
|
||||||
if !debug_image_processing then Printf.printf "(%i/%i) Object %i (JPEG)... %!" !ndone nobjects objnum;
|
if !debug_image_processing then Printf.printf "(%i/%i) Object %i (JPEG)... %!" !ndone nobjects objnum;
|
||||||
jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~jpeg_to_jpeg_scale ~jpeg_to_jpeg_dpi ~q ~path_to_convert s dict reference
|
jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~jpeg_to_jpeg_scale ~jpeg_to_jpeg_dpi ~interpolate ~q ~path_to_convert s dict reference
|
||||||
end
|
end
|
||||||
| Some (Pdf.Name "/Image"), _, Some (Pdf.Integer 1), _
|
| Some (Pdf.Name "/Image"), _, Some (Pdf.Integer 1), _
|
||||||
| Some (Pdf.Name "/Image"), _, _, Some (Pdf.Boolean true) ->
|
| Some (Pdf.Name "/Image"), _, _, Some (Pdf.Boolean true) ->
|
||||||
|
|
Loading…
Reference in New Issue