mirror of
				https://github.com/johnwhitington/cpdf-source.git
				synced 2025-06-05 22:09:39 +02:00 
			
		
		
		
	Add debug output for image processing
This commit is contained in:
		| @@ -1956,6 +1956,9 @@ let setlengththreshold i = | |||||||
| let setpercentagethreshold i = | let setpercentagethreshold i = | ||||||
|   args.percentage_threshold <- i |   args.percentage_threshold <- i | ||||||
|  |  | ||||||
|  | let setprocessimagesinfo () = | ||||||
|  |   set Cpdfimage.debug_image_processing | ||||||
|  |  | ||||||
| (* Parse a control file, make an argv, and then make Arg parse it. *) | (* Parse a control file, make an argv, and then make Arg parse it. *) | ||||||
| let rec make_control_argv_and_parse filename = | let rec make_control_argv_and_parse filename = | ||||||
|   control_args := !control_args @ parse_control_file filename |   control_args := !control_args @ parse_control_file filename | ||||||
| @@ -2730,6 +2733,9 @@ and specs = | |||||||
|    ("-process-images", |    ("-process-images", | ||||||
|      Arg.Unit (setop ProcessImages), |      Arg.Unit (setop ProcessImages), | ||||||
|      " Process images within PDF"); |      " Process images within PDF"); | ||||||
|  |    ("-process-images-info", | ||||||
|  |      Arg.Unit setprocessimagesinfo, | ||||||
|  |      " Show info when processing images"); | ||||||
|    ("-convert", |    ("-convert", | ||||||
|      Arg.String setconvertpath, |      Arg.String setconvertpath, | ||||||
|      " Path to convert executable"); |      " Path to convert executable"); | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								cpdfimage.ml
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								cpdfimage.ml
									
									
									
									
									
								
							| @@ -2,6 +2,8 @@ open Pdfutil | |||||||
| open Pdfio | open Pdfio | ||||||
| open Cpdferror | open Cpdferror | ||||||
|  |  | ||||||
|  | let debug_image_processing = ref false | ||||||
|  |  | ||||||
| let pnm_white ch = output_char ch ' ' | let pnm_white ch = output_char ch ' ' | ||||||
| let pnm_newline ch = output_char ch '\n' | let pnm_newline ch = output_char ch '\n' | ||||||
| let pnm_output_string = Stdlib.output_string | let pnm_output_string = Stdlib.output_string | ||||||
| @@ -528,7 +530,7 @@ let jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~q | |||||||
|         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;*) |           if !debug_image_processing then 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; | ||||||
| @@ -584,7 +586,7 @@ let lossless_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshol | |||||||
|             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;*) |                 if !debug_image_processing then Printf.printf "Lossless to JPEG %i -> %i\n%!" size newsize; | ||||||
|                 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)) | ||||||
| @@ -632,7 +634,7 @@ let recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_j | |||||||
|             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 "1bpp to JBIG2 %i -> %i \n" size newsize;*) |                 if !debug_image_processing then Printf.printf "1bpp to JBIG2 %i -> %i\n%!" size newsize; | ||||||
|                 reference := |                 reference := | ||||||
|                   (Pdf.remove_dict_entry |                   (Pdf.remove_dict_entry | ||||||
|                   (Pdf.add_dict_entry |                   (Pdf.add_dict_entry | ||||||
| @@ -653,7 +655,7 @@ let process | |||||||
|   ?q ?qlossless ?onebppmethod ~length_threshold ~percentage_threshold ~pixel_threshold |   ?q ?qlossless ?onebppmethod ~length_threshold ~percentage_threshold ~pixel_threshold | ||||||
|   ~path_to_jbig2enc ~path_to_convert pdf |   ~path_to_jbig2enc ~path_to_convert pdf | ||||||
| = | = | ||||||
|   let process_obj _ s = |   let process_obj objnum s = | ||||||
|     match s with |     match s with | ||||||
|     | Pdf.Stream ({contents = dict, _} as reference) -> |     | Pdf.Stream ({contents = dict, _} as reference) -> | ||||||
|         begin match |         begin match | ||||||
| @@ -663,6 +665,7 @@ let process | |||||||
|           Pdf.lookup_direct pdf "/ImageMask" dict |           Pdf.lookup_direct pdf "/ImageMask" dict | ||||||
|         with |         with | ||||||
|         | Some (Pdf.Name "/Image"), Some (Pdf.Name "/DCTDecode" | Pdf.Array [Pdf.Name "/DCTDecode"]), _, _ -> |         | Some (Pdf.Name "/Image"), Some (Pdf.Name "/DCTDecode" | Pdf.Array [Pdf.Name "/DCTDecode"]), _, _ -> | ||||||
|  |             if !debug_image_processing then Printf.printf "Object %i (JPEG)...\n%!" objnum; | ||||||
|             begin match q with |             begin match q with | ||||||
|             | Some q -> |             | Some q -> | ||||||
|                 if q < 100 then jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~q ~path_to_convert s dict reference |                 if q < 100 then jpeg_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~q ~path_to_convert s dict reference | ||||||
| @@ -670,12 +673,14 @@ let process | |||||||
|             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) -> | ||||||
|  |             if !debug_image_processing then Printf.printf "Object %i (1bpp)...\n%!" objnum; | ||||||
|             begin match onebppmethod with |             begin match onebppmethod with | ||||||
|             | Some "JBIG2" -> |             | Some "JBIG2" -> | ||||||
|                 recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_jbig2enc pdf s dict reference |                 recompress_1bpp_jbig2_lossless ~pixel_threshold ~length_threshold ~path_to_jbig2enc pdf s dict reference | ||||||
|             | _ -> () |             | _ -> () | ||||||
|             end |             end | ||||||
|         | Some (Pdf.Name "/Image"), _, _, _ -> |         | Some (Pdf.Name "/Image"), _, _, _ -> | ||||||
|  |             if !debug_image_processing then Printf.printf "Object %i (lossless)...\n%!" objnum; | ||||||
|             begin match qlossless with |             begin match qlossless with | ||||||
|             | Some qlossless -> |             | Some qlossless -> | ||||||
|                 if qlossless < 101 then lossless_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~qlossless ~path_to_convert s dict reference |                 if qlossless < 101 then lossless_to_jpeg pdf ~pixel_threshold ~length_threshold ~percentage_threshold ~qlossless ~path_to_convert s dict reference | ||||||
|   | |||||||
| @@ -1,5 +1,8 @@ | |||||||
| (** Images *) | (** Images *) | ||||||
|  |  | ||||||
|  | (** Print info when processing image *) | ||||||
|  | val debug_image_processing : bool ref | ||||||
|  |  | ||||||
| (** Extract images. *) | (** Extract images. *) | ||||||
| val extract_images : | val extract_images : | ||||||
|   ?raw:bool -> ?path_to_p2p:string -> ?path_to_im:string -> |   ?raw:bool -> ?path_to_p2p:string -> ?path_to_im:string -> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user