diff --git a/tools/cmd/icat/native.go b/tools/cmd/icat/native.go index e72b3e0af..fecec2348 100644 --- a/tools/cmd/icat/native.go +++ b/tools/cmd/icat/native.go @@ -4,9 +4,29 @@ package icat import ( "fmt" + "image" + + "golang.org/x/image/draw" ) var _ = fmt.Print -func render_image_with_go(imgd *image_data, src *opened_input) { +func render_image_with_go(imgd *image_data, src *opened_input) (err error) { + switch imgd.format_uppercase { + case "GIF": + return fmt.Errorf("TODO: implement GIF decoding") + default: + img, _, err := image.Decode(src.file) + if err != nil { + return err + } + b := img.Bounds() + rgba := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) + draw.Draw(rgba, rgba.Bounds(), img, b.Min, draw.Src) + imgd.format_uppercase = "RGBA" + f := image_frame{width: b.Dx(), height: b.Dy()} + f.in_memory_bytes = rgba.Pix + imgd.frames = append(imgd.frames, &f) + } + return nil } diff --git a/tools/cmd/icat/process_images.go b/tools/cmd/icat/process_images.go index 14a4b20fd..40e752df2 100644 --- a/tools/cmd/icat/process_images.go +++ b/tools/cmd/icat/process_images.go @@ -251,7 +251,7 @@ func process_arg(arg input_arg) { send_output(&imgd) return } - err = render_image_with_go(imgd, &f) + err = render_image_with_go(&imgd, &f) if err != nil { report_error(arg.value, "Could not render image to RGB", err) return