Bitmap/PPM conversion through a pipe
< Bitmap
Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm
function defined on this other page.
Bitmap/PPM conversion through a pipe
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux), convert (from ImageMagick, multi-platform).
OCaml
<ocaml>let print_jpeg ~img ?(quality=96) () =
let cmd = Printf.sprintf "cjpeg -quality %d" quality in (* let cmd = Printf.sprintf "ppmtojpeg -quality %d" quality in let cmd = Printf.sprintf "convert ppm:- -quality %d jpg:-" quality in *) let ic, oc = Unix.open_process cmd in output_ppm ~img ~oc; try while true do let c = input_char ic in print_char c done with End_of_file -> ()
- </ocaml>