package main

import (
	"C"

	"bytes"
	"image"
	"image/png"
	"os"

	_ "github.com/oov/psd"
)

//export PSD2PNG
func PSD2PNG(filename *C.char, buf **C.char, ln *int, errno *int) {
	file, err := os.Open(C.GoString(filename))
	if err != nil {
		*errno = 1
		return
	}
	defer file.Close()

	img, _, err := image.Decode(file)
	if err != nil {
		*errno = 2
		return
	}

	var b bytes.Buffer
	err = png.Encode(&b, img)
	if err != nil {
		*errno = 3
		return
	}

	*buf = C.CString(b.String())
	*ln = b.Len()
	*errno = 0
}

func main() {}
