This commit is contained in:
John Whitington 2023-12-20 12:30:44 +00:00
parent f1b39a0c84
commit e76d5bf98f
1 changed files with 5 additions and 9 deletions

View File

@ -504,18 +504,16 @@ let jpeg_to_jpeg pdf ~q ~path_to_convert s dict reference =
close_out fh; close_out fh;
let retcode = let retcode =
let command = let command =
(Filename.quote_command path_to_convert (Filename.quote_command path_to_convert [out; "-quality"; string_of_int q ^ "%"; out2])
[out; "-quality"; string_of_int q ^ "%"; out2])
in in
(*Printf.printf "%S\n" command;*) (*Printf.printf "%S\n" command;*) Sys.command command
Sys.command command
in in
if retcode = 0 then if retcode = 0 then
begin begin
let result = open_in_bin out2 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
Printf.printf "JPEG to JPEG %i -> %i\n" size newsize; (*Printf.printf "JPEG to JPEG %i -> %i\n" size newsize;*)
reference := Pdf.add_dict_entry dict "/Length" (Pdf.Integer newsize), Pdf.Got (Pdfio.bytes_of_input_channel result) reference := Pdf.add_dict_entry dict "/Length" (Pdf.Integer newsize), Pdf.Got (Pdfio.bytes_of_input_channel result)
end; end;
Sys.remove out; Sys.remove out;
@ -536,7 +534,6 @@ let suitable_num pdf dict =
| _ -> 0 | _ -> 0
let lossless_to_jpeg pdf ~qlossless ~path_to_convert s dict reference = let lossless_to_jpeg pdf ~qlossless ~path_to_convert s dict reference =
(* 0. Test if this is one we can do - for now just Colourspace=RGB, BPC=8 *)
let bpc = Pdf.lookup_direct pdf "/BitsPerComponent" dict in let bpc = Pdf.lookup_direct pdf "/BitsPerComponent" dict in
let components = suitable_num pdf dict in let components = suitable_num pdf dict in
match components, bpc with match components, bpc with
@ -561,8 +558,7 @@ let lossless_to_jpeg pdf ~qlossless ~path_to_convert s dict reference =
(if components = 1 then ["-colorspace"; "Gray"] else if components = 4 then ["-colorspace"; "CMYK"] else []) @ (if components = 1 then ["-colorspace"; "Gray"] else if components = 4 then ["-colorspace"; "CMYK"] else []) @
[out2])) [out2]))
in in
(*Printf.printf "%S\n" command;*) (*Printf.printf "%S\n" command;*) Sys.command command
Sys.command command
in in
if retcode = 0 then if retcode = 0 then
begin begin
@ -570,7 +566,7 @@ let lossless_to_jpeg pdf ~qlossless ~path_to_convert s dict reference =
let newsize = in_channel_length result in let newsize = in_channel_length result in
if newsize < size then if newsize < size then
begin begin
Printf.printf "Lossless to JPEG %i -> %i (components %i) \n" size newsize components; (*Printf.printf "Lossless to JPEG %i -> %i (components %i) \n" size newsize components;*)
reference := reference :=
(Pdf.add_dict_entry (Pdf.add_dict_entry
(Pdf.add_dict_entry dict "/Length" (Pdf.Integer newsize)) (Pdf.add_dict_entry dict "/Length" (Pdf.Integer newsize))