From 0d97d39c02e5740364af49c7e9c8a2cac8f61b7a Mon Sep 17 00:00:00 2001 From: John Whitington Date: Mon, 4 Dec 2023 13:39:56 +0000 Subject: [PATCH] First working -jbig2 --- cpdfcommand.ml | 4 ++++ cpdfimage.ml | 17 ++++++++++++++++- cpdfimage.mli | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 896aa25..5e23542 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -1789,6 +1789,7 @@ let set_input_image f s = let set_input_png = set_input_image Cpdfimage.obj_of_png_data let set_input_jpeg = set_input_image Cpdfimage.obj_of_jpeg_data +let set_input_jbig2 = set_input_image (Cpdfimage.obj_of_jbig2_data ~global:1) let embed_font_inner font = match font with @@ -1915,6 +1916,9 @@ and specs = ("-jpeg", Arg.String set_input_jpeg, " Load from a JPEG file, converting to PDF"); + ("-jbig2", + Arg.String set_input_jbig2, + " Load from a JBIG2 fragment, converting to PDF"); ("-idir", Arg.String set_input_dir, " Add a directory of files"); diff --git a/cpdfimage.ml b/cpdfimage.ml index d405cae..bf8366d 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -405,7 +405,22 @@ let obj_of_png_data data = "/Width", Pdf.Integer png.width; "/Height", Pdf.Integer png.height] in - Pdf.Stream {contents = (Pdf.Dictionary d , Pdf.Got png.idat)} + Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got png.idat)} + +let obj_of_jbig2_data ?global:int data = + let d = + let w = 800 in + let h = 1200 in + [("/Length", Pdf.Integer (Pdfio.bytes_size data)); + ("/Filter", Pdf.Name "/JBIG2Decode"); + ("/Subtype", Pdf.Name "/Image"); + ("/BitsPerComponent", Pdf.Integer 1); + ("/ColorSpace", Pdf.Name "/DeviceGray"); + (* FIXME decodeparms for global *) + ("/Width", Pdf.Integer w); + ("/Height", Pdf.Integer h)] + in + Pdf.Stream {contents = (Pdf.Dictionary d, Pdf.Got data)} let image_of_input fobj i = let pdf = Pdf.empty () in diff --git a/cpdfimage.mli b/cpdfimage.mli index 69bbf33..ef2c838 100644 --- a/cpdfimage.mli +++ b/cpdfimage.mli @@ -15,3 +15,4 @@ val images : Pdf.t -> int list -> Cpdfyojson.Safe.t val image_of_input : (Pdfio.bytes -> Pdf.pdfobject) -> Pdfio.input -> Pdf.t val obj_of_jpeg_data : Pdfio.bytes -> Pdf.pdfobject val obj_of_png_data : Pdfio.bytes -> Pdf.pdfobject +val obj_of_jbig2_data : ?global:int -> Pdfio.bytes -> Pdf.pdfobject