From 5480a08e77e3a7500e20b9a2f08e52495bf904fc Mon Sep 17 00:00:00 2001 From: John Whitington Date: Fri, 29 Dec 2023 17:46:54 +0000 Subject: [PATCH] Speed up dumping of PNM files --- cpdfimage.ml | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/cpdfimage.ml b/cpdfimage.ml index 65392a0..7451682 100644 --- a/cpdfimage.ml +++ b/cpdfimage.ml @@ -20,26 +20,14 @@ let pnm_to_channel_24 ch w h s = pnm_header ch w h; pnm_output_string ch "255"; pnm_newline ch; - let pos = ref 0 in - for y = 1 to h do - for x = 1 to w * 3 do - output_byte ch (bget s !pos); - incr pos - done - done + bytes_to_output_channel ch s let pnm_to_channel_8 ch w h s = pnm_output_string ch "P5"; pnm_header ch w h; pnm_output_string ch "255"; pnm_newline ch; - let pos = ref 0 in - for y = 1 to h do - for x = 1 to w do - output_byte ch (bget s !pos); - incr pos - done - done + bytes_to_output_channel ch s let pnm_to_channel_1_inverted ch w h s = pnm_output_string ch "P4"; @@ -47,16 +35,12 @@ let pnm_to_channel_1_inverted ch w h s = pnm_newline ch; let inverted = Pdfio.copybytes s in Pdfio.bytes_selfmap lnot inverted; - pnm_output_string ch (Pdfio.string_of_bytes inverted) + bytes_to_output_channel ch inverted let cmyk_to_channel_32 ch w h s = - let pos = ref 0 in - for y = 1 to h do - for x = 1 to w * 4 do - output_byte ch (255 - bget s !pos); - incr pos - done - done + let inverted = Pdfio.copybytes s in + Pdfio.bytes_selfmap (fun x -> 255 - x) inverted; + bytes_to_output_channel ch inverted let jbig2_serial = ref 0