2016-11-24 08:28:55 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
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())
|
|
|
|
}
|