2016-11-20 00:51:48 +00:00
|
|
|
package imagequant
|
|
|
|
|
2016-11-20 01:25:24 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2016-11-20 00:51:48 +00:00
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -O3 -fno-math-errno -fopenmp -funroll-loops -fomit-frame-pointer -Wall -Wno-attributes -std=c99 -DNDEBUG -DUSE_SSE=1 -msse -fexcess-precision=fast
|
|
|
|
#cgo LDFLAGS: -fopenmp -static
|
|
|
|
#include "libimagequant.h"
|
2016-11-24 06:33:48 +00:00
|
|
|
|
|
|
|
const char* liqVersionString() {
|
|
|
|
return LIQ_VERSION_STRING;
|
|
|
|
}
|
|
|
|
|
2016-11-20 00:51:48 +00:00
|
|
|
*/
|
2016-11-20 01:25:24 +00:00
|
|
|
import "C"
|
|
|
|
|
|
|
|
var (
|
2016-11-21 05:42:51 +00:00
|
|
|
ErrQualityTooLow = errors.New("Quality too low")
|
|
|
|
ErrValueOutOfRange = errors.New("Value out of range")
|
|
|
|
ErrOutOfMemory = errors.New("Out of memory")
|
|
|
|
ErrAborted = errors.New("Aborted")
|
|
|
|
ErrBitmapNotAvailable = errors.New("Bitmap not available")
|
|
|
|
ErrBufferTooSmall = errors.New("Buffer too small")
|
|
|
|
ErrInvalidPointer = errors.New("Invalid pointer")
|
2016-11-24 06:33:48 +00:00
|
|
|
|
|
|
|
ErrUseAfterFree = errors.New("Use after free")
|
2016-11-20 00:51:48 +00:00
|
|
|
)
|
|
|
|
|
2016-11-21 05:42:51 +00:00
|
|
|
func translateError(iqe C.liq_error) error {
|
|
|
|
switch iqe {
|
|
|
|
case C.LIQ_OK:
|
|
|
|
return nil
|
|
|
|
case (C.LIQ_QUALITY_TOO_LOW):
|
|
|
|
return ErrQualityTooLow
|
|
|
|
case (C.LIQ_VALUE_OUT_OF_RANGE):
|
|
|
|
return ErrValueOutOfRange
|
|
|
|
case (C.LIQ_OUT_OF_MEMORY):
|
|
|
|
return ErrOutOfMemory
|
|
|
|
case (C.LIQ_ABORTED):
|
|
|
|
return ErrAborted
|
|
|
|
case (C.LIQ_BITMAP_NOT_AVAILABLE):
|
|
|
|
return ErrBitmapNotAvailable
|
|
|
|
case (C.LIQ_BUFFER_TOO_SMALL):
|
|
|
|
return ErrBufferTooSmall
|
|
|
|
case (C.LIQ_INVALID_POINTER):
|
|
|
|
return ErrInvalidPointer
|
|
|
|
default:
|
|
|
|
return errors.New("Unknown error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-20 00:51:48 +00:00
|
|
|
func GetLibraryVersion() int {
|
|
|
|
return int(C.liq_version())
|
|
|
|
}
|
2016-11-20 01:25:24 +00:00
|
|
|
|
2016-11-24 06:33:48 +00:00
|
|
|
func GetLibraryVersionString() string {
|
|
|
|
return C.GoString(C.liqVersionString())
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
SPEED_SLOWEST = 1
|
|
|
|
SPEED_DEFAULT = 3
|
|
|
|
SPEED_FASTEST = 10
|
|
|
|
)
|