This task is the opposite of the PPM conversion through a pipe. In this task, using a delegate tool (like cjpeg, one of the netpbm package, or convert of the ImageMagick package) we read an image file and load it into the data storage type defined here. We can also use the code from Read ppm file, so that we can use PPM format like a (natural) bridge between the foreign image format and our simple data storage.

-- demo\rosetta\Bitmap_Read_an_image_through_a_pipe.exw
without js -- file i/o, system_exec(), pipes[!!]
include builtins\pipeio.e
include ppm.e -- read_ppm(), write_ppm()

sequence pipes = repeat(0,3)
pipes[PIPOUT] = create_pipe(INHERIT_READ)

-- Create the child process, with replacement stdout. 
string cmd = sprintf("%s viewppm -load test.jpg",{get_interpreter(true)})
atom hProc = system_exec(cmd, 12, pipes),
     hPipe = pipes[PIPOUT][READ_PIPE]

string ppm = read_from_pipe(hPipe, hProc)
while true do
    object chunk = read_from_pipe(hPipe, hProc)
    if chunk=-1 then exit end if
    ppm &= chunk
end while

pipes = close_handles(pipes)

if 0 then
    sequence img = read_ppm(ppm,bText:=true)
    write_ppm("Lenapipe.ppm", img)
else -- or
    integer fn = open("Lenapipe.ppm","wb")
    puts(fn,ppm)
    close(fn)
end if

?"done"
{} = wait_key()
