package main

/*
	#cgo LDFLAGS: -lm
	#include "img.h"
*/
import "C"
import (
//	"encoding/json"
//	"fmt"
)

var pimg *C.img

type img struct {
	ImgReadCode int     `json:"imgReadCode"`
	Title       string  `json:"title"`
	MvX         float64 `json:"mv_x"`
	MvY         float64 `json:"mv_y"`
	MvZ         float64 `json:"mv_z"`
}

func ImgOpen(filename string) interface{} {
	pimg = C.img_open_survey(C.CString(filename), nil)
	//	fmt.Println(C.GoFloat64(pimg.mv.x))

	if pimg.title == nil {
		return img{
			ImgReadCode: 0,
			Title:       "NULL",
			MvX:         float64(pimg.mv.x),
			MvY:         float64(pimg.mv.y),
			MvZ:         float64(pimg.mv.z),
		}
	} else {
		return img{
			ImgReadCode: 0,
			Title:       C.GoString(pimg.title),
			MvX:         float64(pimg.mv.x),
			MvY:         float64(pimg.mv.y),
			MvZ:         float64(pimg.mv.z),
		}
	}
}

func ImgReadItem() img {
	img_read_code := C.img_read_item(pimg, &pimg.mv)

	if pimg.title == nil {
		return img{
			ImgReadCode: int(img_read_code),
			Title:       "NULL",
			MvX:         float64(pimg.mv.x),
			MvY:         float64(pimg.mv.y),
			MvZ:         float64(pimg.mv.z),
		}
	} else {
		return img{
			ImgReadCode: int(img_read_code),
			Title:       C.GoString(pimg.title),
			MvX:         float64(pimg.mv.x),
			MvY:         float64(pimg.mv.y),
			MvZ:         float64(pimg.mv.z),
		}
	}
}
