-
Notifications
You must be signed in to change notification settings - Fork 14
/
Histogram.go
49 lines (40 loc) · 1.71 KB
/
Histogram.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
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
}
// "Learns" colors from the image, which will be later used to generate the palette.
// After the image is added to the histogram it may be freed to save memory (but it's more efficient to keep the image object if it's going to be used for remapping).
// Fixed colors added to the image are also added to the histogram.
func (this *Histogram) AddImage(attr *Attributes, img *Image) error {
return translateError(C.liq_histogram_add_image(this.p, attr.p, img.p))
}
// Quantize generate palette from the histogram.
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)
}