Separations for lossless to JPEG

This commit is contained in:
John Whitington 2023-12-20 17:12:18 +00:00
parent e76d5bf98f
commit d4b571d089
1 changed files with 4 additions and 3 deletions

View File

@ -531,13 +531,14 @@ let suitable_num pdf dict =
| Some (Pdf.Integer 4) -> 4 | Some (Pdf.Integer 4) -> 4
| _ -> 0 | _ -> 0
end end
| Some (Pdf.Array (Pdf.Name "/Separation"::_)) -> ~-1
| _ -> 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 =
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
| (1 | 3 | 4), Some (Pdf.Integer 8) -> | (1 | 3 | 4 | -1), Some (Pdf.Integer 8) ->
let size = match Pdf.lookup_direct pdf "/Length" dict with Some (Pdf.Integer i) -> i | _ -> 0 in let size = match Pdf.lookup_direct pdf "/Length" dict with Some (Pdf.Integer i) -> i | _ -> 0 in
Pdfcodec.decode_pdfstream_until_unknown pdf s; Pdfcodec.decode_pdfstream_until_unknown pdf s;
begin match Pdf.lookup_direct pdf "/Filter" (fst !reference) with Some _ -> () | None -> begin match Pdf.lookup_direct pdf "/Filter" (fst !reference) with Some _ -> () | None ->
@ -580,13 +581,13 @@ let lossless_to_jpeg pdf ~qlossless ~path_to_convert s dict reference =
Sys.remove out2 Sys.remove out2
end end
| colspace, bpc -> | colspace, bpc ->
let colspace = Pdf.lookup_direct pdf "/ColorSpace" dict in (*let colspace = Pdf.lookup_direct pdf "/ColorSpace" dict in
let colspace, bpc, filter = let colspace, bpc, filter =
(match colspace with None -> "none" | Some x -> Pdfwrite.string_of_pdf x), (match colspace with None -> "none" | Some x -> Pdfwrite.string_of_pdf x),
(match bpc with None -> "none" | Some x -> Pdfwrite.string_of_pdf x), (match bpc with None -> "none" | Some x -> Pdfwrite.string_of_pdf x),
(match Pdf.lookup_direct pdf "/Filter" dict with None -> "none" | Some x -> Pdfwrite.string_of_pdf x) (match Pdf.lookup_direct pdf "/Filter" dict with None -> "none" | Some x -> Pdfwrite.string_of_pdf x)
in in
print_string (Printf.sprintf "%s (%s) [%s]\n" colspace bpc filter); print_string (Printf.sprintf "%s (%s) [%s]\n" colspace bpc filter);*)
() (* an image we cannot or do not handle *) () (* an image we cannot or do not handle *)
let process pdf ~q ~qlossless ~path_to_convert = let process pdf ~q ~qlossless ~path_to_convert =