/*
Copyright (c) 2016, The go-imagequant author(s)

Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
*/

package imagequant

/*
#include "libimagequant.h"
*/
import "C"

type Histogram struct {
	p *C.struct_liq_histogram
}

func (this *Histogram) AddImage(attr *Attributes, img *Image) error {
	return translateError(C.liq_histogram_add_image(this.p, attr.p, img.p))
}

func (this *Histogram) Quantize(attr *Attributes) (*Result, error) {
	res := Result{}
	liqerr := C.liq_histogram_quantize(this.p, attr.p, &res.p)
	if liqerr != C.LIQ_OK {
		return nil, translateError(liqerr)
	}

	return &res, nil
}

// Free memory. Callers must not use this object after Release has been called.
func (this *Histogram) Release() {
	C.liq_histogram_destroy(this.p)
}
