diff --git a/Color.go b/Color.go deleted file mode 100644 index 3922de3..0000000 --- a/Color.go +++ /dev/null @@ -1,5 +0,0 @@ -package imagequant - -type Color struct { - r, g, b, a uint8 -} diff --git a/Palette.go b/Palette.go deleted file mode 100644 index 7b57320..0000000 --- a/Palette.go +++ /dev/null @@ -1,29 +0,0 @@ -package imagequant - -/* -#include "libimagequant.h" -*/ -import "C" - -// This struct has standard Go lifetime and does not need manual release. -type Palette struct { - p C.struct_liq_palette -} - -func (this *Palette) Count() uint { - return uint(this.p.count) -} - -func (this *Palette) At(idx int) (Color, error) { - if idx < 0 || idx >= int(this.Count()) { - return Color{}, ErrValueOutOfRange - } - - return Color{ - r: uint8(this.p.entries[idx].r), - g: uint8(this.p.entries[idx].g), - b: uint8(this.p.entries[idx].b), - a: uint8(this.p.entries[idx].a), - }, nil - -} diff --git a/Result.go b/Result.go index eb156d0..cd4836a 100644 --- a/Result.go +++ b/Result.go @@ -1,5 +1,9 @@ package imagequant +import ( + "image/color" +) + /* #include "libimagequant.h" */ @@ -68,9 +72,21 @@ func (this *Result) WriteRemappedImage() ([]byte, error) { return buff, nil } -func (this *Result) GetPalette() *Palette { - ptr := *C.liq_get_palette(this.p) // copy struct content - return &Palette{p: ptr} +func (this *Result) GetPalette() color.Palette { + ptr := C.liq_get_palette(this.p) // copy struct content + max := int(ptr.count) + + ret := make([]color.Color, max) + for i := 0; i < max; i += 1 { + ret[i] = color.RGBA{ + R: uint8(ptr.entries[i].r), + G: uint8(ptr.entries[i].g), + B: uint8(ptr.entries[i].b), + A: uint8(ptr.entries[i].a), + } + } + + return ret } // Free memory. Callers must not use this object after Release has been called.