Basic go based rendering

This commit is contained in:
Kovid Goyal 2023-01-01 14:51:46 +05:30
parent 7f866b2b1f
commit 373ab95f14
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 2 deletions

View File

@ -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
}

View File

@ -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