mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-16 19:05:54 -07:00
refactor(vips): use shortcut to VipsImage C type
This commit is contained in:
parent
b78fe09f17
commit
1c2f37648c
2 changed files with 38 additions and 38 deletions
18
resize.go
18
resize.go
|
|
@ -138,7 +138,7 @@ func shouldTransformImage(o Options, inWidth, inHeight int) bool {
|
||||||
(o.Height > 0 && o.Height != inHeight) || o.AreaWidth > 0 || o.AreaHeight > 0
|
(o.Height > 0 && o.Height != inHeight) || o.AreaWidth > 0 || o.AreaHeight > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func transformImage(image *C.struct__VipsImage, o Options, shrink int, residual float64) (*C.struct__VipsImage, error) {
|
func transformImage(image *C.VipsImage, o Options, shrink int, residual float64) (*C.VipsImage, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Use vips_shrink with the integral reduction
|
// Use vips_shrink with the integral reduction
|
||||||
|
|
@ -178,7 +178,7 @@ func transformImage(image *C.struct__VipsImage, o Options, shrink int, residual
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractOrEmbedImage(image *C.struct__VipsImage, o Options) (*C.struct__VipsImage, error) {
|
func extractOrEmbedImage(image *C.VipsImage, o Options) (*C.VipsImage, error) {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
inWidth := int(image.Xsize)
|
inWidth := int(image.Xsize)
|
||||||
inHeight := int(image.Ysize)
|
inHeight := int(image.Ysize)
|
||||||
|
|
@ -212,7 +212,7 @@ func extractOrEmbedImage(image *C.struct__VipsImage, o Options) (*C.struct__Vips
|
||||||
return image, err
|
return image, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func rotateAndFlipImage(image *C.struct__VipsImage, o Options) (*C.struct__VipsImage, error) {
|
func rotateAndFlipImage(image *C.VipsImage, o Options) (*C.VipsImage, error) {
|
||||||
var err error
|
var err error
|
||||||
var direction Direction = -1
|
var direction Direction = -1
|
||||||
|
|
||||||
|
|
@ -243,7 +243,7 @@ func rotateAndFlipImage(image *C.struct__VipsImage, o Options) (*C.struct__VipsI
|
||||||
return image, err
|
return image, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func watermakImage(image *C.struct__VipsImage, w Watermark) (*C.struct__VipsImage, error) {
|
func watermakImage(image *C.VipsImage, w Watermark) (*C.VipsImage, error) {
|
||||||
if w.Text == "" {
|
if w.Text == "" {
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
|
|
@ -275,14 +275,14 @@ func watermakImage(image *C.struct__VipsImage, w Watermark) (*C.struct__VipsImag
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func zoomImage(image *C.struct__VipsImage, zoom int) (*C.struct__VipsImage, error) {
|
func zoomImage(image *C.VipsImage, zoom int) (*C.VipsImage, error) {
|
||||||
if zoom == 0 {
|
if zoom == 0 {
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
return vipsZoom(image, zoom+1)
|
return vipsZoom(image, zoom+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func shrinkImage(image *C.struct__VipsImage, o Options, residual float64, shrink int) (*C.struct__VipsImage, float64, error) {
|
func shrinkImage(image *C.VipsImage, o Options, residual float64, shrink int) (*C.VipsImage, float64, error) {
|
||||||
// Use vips_shrink with the integral reduction
|
// Use vips_shrink with the integral reduction
|
||||||
image, err := vipsShrink(image, shrink)
|
image, err := vipsShrink(image, shrink)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -302,8 +302,8 @@ func shrinkImage(image *C.struct__VipsImage, o Options, residual float64, shrink
|
||||||
return image, residual, nil
|
return image, residual, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shrinkJpegImage(buf []byte, input *C.struct__VipsImage, factor float64, shrink int) (*C.struct__VipsImage, float64, error) {
|
func shrinkJpegImage(buf []byte, input *C.VipsImage, factor float64, shrink int) (*C.VipsImage, float64, error) {
|
||||||
var image *C.struct__VipsImage
|
var image *C.VipsImage
|
||||||
var err error
|
var err error
|
||||||
shrinkOnLoad := 1
|
shrinkOnLoad := 1
|
||||||
|
|
||||||
|
|
@ -381,7 +381,7 @@ func calculateCrop(inWidth, inHeight, outWidth, outHeight int, gravity Gravity)
|
||||||
return left, top
|
return left, top
|
||||||
}
|
}
|
||||||
|
|
||||||
func calculateRotationAndFlip(image *C.struct__VipsImage, angle Angle) (Angle, bool) {
|
func calculateRotationAndFlip(image *C.VipsImage, angle Angle) (Angle, bool) {
|
||||||
rotate := D0
|
rotate := D0
|
||||||
flip := false
|
flip := false
|
||||||
|
|
||||||
|
|
|
||||||
58
vips.go
58
vips.go
|
|
@ -122,15 +122,15 @@ func VipsMemory() VipsMemoryInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsExifOrientation(image *C.struct__VipsImage) int {
|
func vipsExifOrientation(image *C.VipsImage) int {
|
||||||
return int(C.vips_exif_orientation(image))
|
return int(C.vips_exif_orientation(image))
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsHasAlpha(image *C.struct__VipsImage) bool {
|
func vipsHasAlpha(image *C.VipsImage) bool {
|
||||||
return int(C.has_alpha_channel(image)) > 0
|
return int(C.has_alpha_channel(image)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsHasProfile(image *C.struct__VipsImage) bool {
|
func vipsHasProfile(image *C.VipsImage) bool {
|
||||||
return int(C.has_profile_embed(image)) > 0
|
return int(C.has_profile_embed(image)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,12 +140,12 @@ func vipsWindowSize(name string) float64 {
|
||||||
return float64(C.interpolator_window_size(cname))
|
return float64(C.interpolator_window_size(cname))
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsSpace(image *C.struct__VipsImage) string {
|
func vipsSpace(image *C.VipsImage) string {
|
||||||
return C.GoString(C.vips_enum_nick_bridge(image))
|
return C.GoString(C.vips_enum_nick_bridge(image))
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsRotate(image *C.struct__VipsImage, angle Angle) (*C.struct__VipsImage, error) {
|
func vipsRotate(image *C.VipsImage, angle Angle) (*C.VipsImage, error) {
|
||||||
var out *C.struct__VipsImage
|
var out *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(image))
|
defer C.g_object_unref(C.gpointer(image))
|
||||||
|
|
||||||
err := C.vips_rotate(image, &out, C.int(angle))
|
err := C.vips_rotate(image, &out, C.int(angle))
|
||||||
|
|
@ -156,8 +156,8 @@ func vipsRotate(image *C.struct__VipsImage, angle Angle) (*C.struct__VipsImage,
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsFlip(image *C.struct__VipsImage, direction Direction) (*C.struct__VipsImage, error) {
|
func vipsFlip(image *C.VipsImage, direction Direction) (*C.VipsImage, error) {
|
||||||
var out *C.struct__VipsImage
|
var out *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(image))
|
defer C.g_object_unref(C.gpointer(image))
|
||||||
|
|
||||||
err := C.vips_flip_bridge(image, &out, C.int(direction))
|
err := C.vips_flip_bridge(image, &out, C.int(direction))
|
||||||
|
|
@ -168,8 +168,8 @@ func vipsFlip(image *C.struct__VipsImage, direction Direction) (*C.struct__VipsI
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsZoom(image *C.struct__VipsImage, zoom int) (*C.struct__VipsImage, error) {
|
func vipsZoom(image *C.VipsImage, zoom int) (*C.VipsImage, error) {
|
||||||
var out *C.struct__VipsImage
|
var out *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(image))
|
defer C.g_object_unref(C.gpointer(image))
|
||||||
|
|
||||||
err := C.vips_zoom_bridge(image, &out, C.int(zoom), C.int(zoom))
|
err := C.vips_zoom_bridge(image, &out, C.int(zoom), C.int(zoom))
|
||||||
|
|
@ -180,8 +180,8 @@ func vipsZoom(image *C.struct__VipsImage, zoom int) (*C.struct__VipsImage, error
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsWatermark(image *C.struct__VipsImage, w Watermark) (*C.struct__VipsImage, error) {
|
func vipsWatermark(image *C.VipsImage, w Watermark) (*C.VipsImage, error) {
|
||||||
var out *C.struct__VipsImage
|
var out *C.VipsImage
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
noReplicate := 0
|
noReplicate := 0
|
||||||
|
|
@ -207,8 +207,8 @@ func vipsWatermark(image *C.struct__VipsImage, w Watermark) (*C.struct__VipsImag
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsRead(buf []byte) (*C.struct__VipsImage, ImageType, error) {
|
func vipsRead(buf []byte) (*C.VipsImage, ImageType, error) {
|
||||||
var image *C.struct__VipsImage
|
var image *C.VipsImage
|
||||||
imageType := vipsImageType(buf)
|
imageType := vipsImageType(buf)
|
||||||
|
|
||||||
if imageType == UNKNOWN {
|
if imageType == UNKNOWN {
|
||||||
|
|
@ -235,7 +235,7 @@ func vipsColourspaceIsSupportedBuffer(buf []byte) (bool, error) {
|
||||||
return vipsColourspaceIsSupported(image), nil
|
return vipsColourspaceIsSupported(image), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsColourspaceIsSupported(image *C.struct__VipsImage) bool {
|
func vipsColourspaceIsSupported(image *C.VipsImage) bool {
|
||||||
return int(C.vips_colourspace_issupported_bridge(image)) == 1
|
return int(C.vips_colourspace_issupported_bridge(image)) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,11 +248,11 @@ func vipsInterpretationBuffer(buf []byte) (Interpretation, error) {
|
||||||
return vipsInterpretation(image), nil
|
return vipsInterpretation(image), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsInterpretation(image *C.struct__VipsImage) Interpretation {
|
func vipsInterpretation(image *C.VipsImage) Interpretation {
|
||||||
return Interpretation(C.vips_image_guess_interpretation_bridge(image))
|
return Interpretation(C.vips_image_guess_interpretation_bridge(image))
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsPreSave(image *C.struct__VipsImage, o *vipsSaveOptions) (*C.struct__VipsImage, error) {
|
func vipsPreSave(image *C.VipsImage, o *vipsSaveOptions) (*C.VipsImage, error) {
|
||||||
// Remove ICC profile metadata
|
// Remove ICC profile metadata
|
||||||
if o.NoProfile {
|
if o.NoProfile {
|
||||||
C.remove_profile(image)
|
C.remove_profile(image)
|
||||||
|
|
@ -265,7 +265,7 @@ func vipsPreSave(image *C.struct__VipsImage, o *vipsSaveOptions) (*C.struct__Vip
|
||||||
interpretation := C.VipsInterpretation(o.Interpretation)
|
interpretation := C.VipsInterpretation(o.Interpretation)
|
||||||
|
|
||||||
// Apply the proper colour space
|
// Apply the proper colour space
|
||||||
var outImage *C.struct__VipsImage
|
var outImage *C.VipsImage
|
||||||
if vipsColourspaceIsSupported(image) {
|
if vipsColourspaceIsSupported(image) {
|
||||||
err := int(C.vips_colourspace_bridge(image, &outImage, interpretation))
|
err := int(C.vips_colourspace_bridge(image, &outImage, interpretation))
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
|
|
@ -278,7 +278,7 @@ func vipsPreSave(image *C.struct__VipsImage, o *vipsSaveOptions) (*C.struct__Vip
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsSave(image *C.struct__VipsImage, o vipsSaveOptions) ([]byte, error) {
|
func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
defer C.g_object_unref(C.gpointer(image))
|
defer C.g_object_unref(C.gpointer(image))
|
||||||
|
|
||||||
image, err := vipsPreSave(image, &o)
|
image, err := vipsPreSave(image, &o)
|
||||||
|
|
@ -317,8 +317,8 @@ func vipsSave(image *C.struct__VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsExtract(image *C.struct__VipsImage, left, top, width, height int) (*C.struct__VipsImage, error) {
|
func vipsExtract(image *C.VipsImage, left, top, width, height int) (*C.VipsImage, error) {
|
||||||
var buf *C.struct__VipsImage
|
var buf *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(image))
|
defer C.g_object_unref(C.gpointer(image))
|
||||||
|
|
||||||
if width > MAX_SIZE || height > MAX_SIZE {
|
if width > MAX_SIZE || height > MAX_SIZE {
|
||||||
|
|
@ -333,8 +333,8 @@ func vipsExtract(image *C.struct__VipsImage, left, top, width, height int) (*C.s
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsShrinkJpeg(buf []byte, input *C.struct__VipsImage, shrink int) (*C.struct__VipsImage, error) {
|
func vipsShrinkJpeg(buf []byte, input *C.VipsImage, shrink int) (*C.VipsImage, error) {
|
||||||
var image *C.struct__VipsImage
|
var image *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(input))
|
defer C.g_object_unref(C.gpointer(input))
|
||||||
|
|
||||||
err := C.vips_jpegload_buffer_shrink(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), &image, C.int(shrink))
|
err := C.vips_jpegload_buffer_shrink(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), &image, C.int(shrink))
|
||||||
|
|
@ -345,8 +345,8 @@ func vipsShrinkJpeg(buf []byte, input *C.struct__VipsImage, shrink int) (*C.stru
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsShrink(input *C.struct__VipsImage, shrink int) (*C.struct__VipsImage, error) {
|
func vipsShrink(input *C.VipsImage, shrink int) (*C.VipsImage, error) {
|
||||||
var image *C.struct__VipsImage
|
var image *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(input))
|
defer C.g_object_unref(C.gpointer(input))
|
||||||
|
|
||||||
err := C.vips_shrink_bridge(input, &image, C.double(float64(shrink)), C.double(float64(shrink)))
|
err := C.vips_shrink_bridge(input, &image, C.double(float64(shrink)), C.double(float64(shrink)))
|
||||||
|
|
@ -357,8 +357,8 @@ func vipsShrink(input *C.struct__VipsImage, shrink int) (*C.struct__VipsImage, e
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsEmbed(input *C.struct__VipsImage, left, top, width, height, extend int) (*C.struct__VipsImage, error) {
|
func vipsEmbed(input *C.VipsImage, left, top, width, height, extend int) (*C.VipsImage, error) {
|
||||||
var image *C.struct__VipsImage
|
var image *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(input))
|
defer C.g_object_unref(C.gpointer(input))
|
||||||
|
|
||||||
err := C.vips_embed_bridge(input, &image, C.int(left), C.int(top), C.int(width), C.int(height), C.int(extend))
|
err := C.vips_embed_bridge(input, &image, C.int(left), C.int(top), C.int(width), C.int(height), C.int(extend))
|
||||||
|
|
@ -369,8 +369,8 @@ func vipsEmbed(input *C.struct__VipsImage, left, top, width, height, extend int)
|
||||||
return image, nil
|
return image, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func vipsAffine(input *C.struct__VipsImage, residualx, residualy float64, i Interpolator) (*C.struct__VipsImage, error) {
|
func vipsAffine(input *C.VipsImage, residualx, residualy float64, i Interpolator) (*C.VipsImage, error) {
|
||||||
var image *C.struct__VipsImage
|
var image *C.VipsImage
|
||||||
cstring := C.CString(i.String())
|
cstring := C.CString(i.String())
|
||||||
interpolator := C.vips_interpolate_new(cstring)
|
interpolator := C.vips_interpolate_new(cstring)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue