diff --git a/cpdfcommand.ml b/cpdfcommand.ml index 7cd0cef..f2ab6ea 100644 --- a/cpdfcommand.ml +++ b/cpdfcommand.ml @@ -4496,7 +4496,6 @@ let go () = | Some Draw -> let pdf = get_single_pdf args.op false in let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in - let ops = match !Cpdfdrawcontrol.drawops with [("_MAIN", ops)] -> rev ops | _ -> error "not enough -end-xobj or -et" in write_pdf false @@ -4515,11 +4514,12 @@ let go () = write_pdf false (Cpdfchop.chop ~x ~y ~columns:args.impose_columns ~btt:args.impose_btt ~rtl:args.impose_rtl pdf range) | Some ProcessImages -> let pdf = get_single_pdf args.op false in + let range = parse_pagespec_allow_empty pdf (get_pagespec ()) in Cpdfimage.process ~q:args.jpegquality ~qlossless:args.jpegqualitylossless ~onebppmethod:args.onebppmethod ~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 range pdf; write_pdf false pdf (* Advise the user if a combination of command line flags makes little sense, diff --git a/cpdfimage.ml b/cpdfimage.ml index 28b5e47..1f75e2a 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -713,20 +713,26 @@ let recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_j remove out2 end -(* JPEG to JPEG: RGB and CMYK JPEGS *) -(* Lossless to JPEG: 8bpp Grey, 8bpp RGB, 8bpp CMYK including separation and ICCBased colourspaces *) -(* 1 bit: anything to JBIG2 lossless (no globals) *) +(* TODO: + - 2bpp, 4bpp, 16bpp images. + - Downsample colours as well as pixels + - JBIG2 with refinement coding for multipage lossless? *) let process ?q ?qlossless ?onebppmethod ~length_threshold ~percentage_threshold ~pixel_threshold ~factor ~interpolate - ~path_to_jbig2enc ~path_to_convert pdf + ~path_to_jbig2enc ~path_to_convert range pdf = + let inrange = + match images pdf range with + | `List l -> hashset_of_list (map (function `Assoc (("Object", `Int i)::_) -> i | _ -> assert false) l) + | _ -> assert false + in let nobjects = Pdf.objcard pdf in let ndone = ref 0 in let process_obj objnum s = match s with | Pdf.Stream ({contents = dict, _} as reference) -> ndone += 1; - begin match + if Hashtbl.mem inrange objnum then begin match Pdf.lookup_direct pdf "/Subtype" dict, Pdf.lookup_direct pdf "/Filter" dict, Pdf.lookup_direct pdf "/BitsPerComponent" dict, diff --git a/cpdfimage.mli b/cpdfimage.mli index 913b990..b79f324 100644 --- a/cpdfimage.mli +++ b/cpdfimage.mli @@ -18,7 +18,7 @@ val process : ?q:int -> ?qlossless:int -> ?onebppmethod:string -> 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 -> int list -> Pdf.t -> unit (**/**) val image_of_input : (unit -> Pdfio.bytes -> Pdf.pdfobject * (int * Pdf.pdfobject) list) -> Pdfio.input -> Pdf.t