More CCITT G4 work

This commit is contained in:
John Whitington 2025-06-03 18:40:21 +01:00
parent 97ceabeb0d
commit b51ce326d8

View File

@ -851,7 +851,7 @@ let recompress_1bpp_ccitt_lossless ~pixel_threshold ~length_threshold pdf s dict
let old = !reference in let old = !reference in
let restore () = reference := old in let restore () = reference := old in
let w = match Pdf.lookup_direct pdf "/Width" dict with Some (Pdf.Integer i) -> i | _ -> error "bad width" in let w = match Pdf.lookup_direct pdf "/Width" dict with Some (Pdf.Integer i) -> i | _ -> error "bad width" in
(*let h = match Pdf.lookup_direct pdf "/Height" dict with Some (Pdf.Integer i) -> i | _ -> error "bad height" in*) let h = match Pdf.lookup_direct pdf "/Height" dict with Some (Pdf.Integer i) -> i | _ -> error "bad height" in
(*if w * h < pixel_threshold then (if !debug_image_processing then Printf.printf "pixel threshold not met\n%!") else*) (*if w * h < pixel_threshold then (if !debug_image_processing then Printf.printf "pixel threshold not met\n%!") else*)
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
(*if size < length_threshold then (if !debug_image_processing then Printf.printf "length threshold not met\n%!") else*) (*if size < length_threshold then (if !debug_image_processing then Printf.printf "length threshold not met\n%!") else*)
@ -863,7 +863,7 @@ let recompress_1bpp_ccitt_lossless ~pixel_threshold ~length_threshold pdf s dict
restore () restore ()
| None -> | None ->
let data = match s with Pdf.Stream {contents = _, Pdf.Got d} -> d | _ -> assert false in let data = match s with Pdf.Stream {contents = _, Pdf.Got d} -> d | _ -> assert false in
let compressed = Pdfcodec.encode_ccitt w data in let compressed = Pdfcodec.encode_ccitt w h data in
let newsize = bytes_size compressed in let newsize = bytes_size compressed in
if true (*newsize < size*) then if true (*newsize < size*) then
begin begin
@ -897,7 +897,7 @@ let recompress_1bpp_ccittg4_lossless ~pixel_threshold ~length_threshold pdf s di
restore () restore ()
| None -> | None ->
let data = match s with Pdf.Stream {contents = _, Pdf.Got d} -> d | _ -> assert false in let data = match s with Pdf.Stream {contents = _, Pdf.Got d} -> d | _ -> assert false in
let compressed = Pdfcodec.encode_ccittg4 w data in let compressed = Pdfcodec.encode_ccittg4 w h data in
let newsize = bytes_size compressed in let newsize = bytes_size compressed in
if true (* newsize < size *) then if true (* newsize < size *) then
begin begin