Bitmap/Read an image through a pipe: Difference between revisions

→‎{{header|Go}}: Integrate with flood fill task. (The previous rev was still working fine)
(Added Mathematica)
(→‎{{header|Go}}: Integrate with flood fill task. (The previous rev was still working fine))
Line 105:
 
=={{header|Go}}==
This example uses convert to convert the test image for the flood fill task. It reads through the pipe as required for this task, then writes as a .ppm file convenient for the flood fill task.
{{works with|Go weekly.2011-12-14}}
Using djpeg:
<lang go>package main
 
Line 115 ⟶ 114:
 
import (
"fmtlog"
"os/exec"
"raster"
Line 121 ⟶ 120:
 
func main() {
c := exec.Command("convert", "Unfilledcirc.png", "-depth", "8", "ppm:-")
// (A file with this name is output by the Go solution to the task
// "Bitmap/PPM conversion through a pipe," but of course any handy
// jpeg should work.)
c := exec.Command("djpeg", "pipeout.jpg")
pipe, err := c.StdoutPipe()
if err != nil {
fmtlog.PrintlnFatal(err)
return
}
if err = c.Start(); err != nil {
if err != nil {log.Fatal(err)
fmt.Println(err)
return
}
b, err := raster.ReadPpmFrom(pipe)
if err != nil {
fmtlog.PrintlnFatal(err)
return
}
if err = b.WritePpmFile("pipeinUnfilledcirc.ppm"); err != nil {
if err != nil {log.Fatal(err)
fmt.Println(err)
}
}</lang>
1,707

edits