From e348555c2ce9d5d37997afb638820a12b103cbe4 Mon Sep 17 00:00:00 2001 From: Nova Kwok Date: Mon, 18 Mar 2024 09:00:40 +0800 Subject: [PATCH 1/4] Refine NewJxlExportParams (#416) --- vips/foreign.c | 8 +++++++- vips/image.go | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vips/foreign.c b/vips/foreign.c index 65cc522c..306ea914 100644 --- a/vips/foreign.c +++ b/vips/foreign.c @@ -562,7 +562,13 @@ static SaveParams defaultSaveParams = { .jp2kLossless = FALSE, .jp2kTileHeight = 512, - .jp2kTileWidth = 512}; + .jp2kTileWidth = 512, + + .jxlTier = 0, + .jxlDistance = 1.0, + .jxlEffort = 7, + .jxlLossless = FALSE, + }; SaveParams create_save_params(ImageType outputFormat) { SaveParams params = defaultSaveParams; diff --git a/vips/image.go b/vips/image.go index cae1a669..8f7b449e 100644 --- a/vips/image.go +++ b/vips/image.go @@ -405,6 +405,7 @@ func NewJxlExportParams() *JxlExportParams { Quality: 75, Lossless: false, Effort: 7, + Distance: 1.0, } } From 0d1504b6f81549ba1070b2a7efb325693e34bb9e Mon Sep 17 00:00:00 2001 From: Johan Lindh Date: Thu, 28 Mar 2024 03:44:54 +0100 Subject: [PATCH 2/4] Add ImageRef.Sobel() and a test. (#419) * add ImageRef.Sobel() * minimize changes * restore whitespace --- vips/convolution.c | 4 ++++ vips/convolution.go | 12 ++++++++++++ vips/convolution.h | 1 + vips/image.go | 10 ++++++++++ vips/image_golden_test.go | 6 ++++++ 5 files changed, 33 insertions(+) diff --git a/vips/convolution.c b/vips/convolution.c index 5dafc052..48a9472b 100644 --- a/vips/convolution.c +++ b/vips/convolution.c @@ -8,3 +8,7 @@ int sharpen_image(VipsImage *in, VipsImage **out, double sigma, double x1, double m2) { return vips_sharpen(in, out, "sigma", sigma, "x1", x1, "m2", m2, NULL); } + +int sobel_image(VipsImage *in, VipsImage **out) { + return vips_sobel(in, out, NULL); +} diff --git a/vips/convolution.go b/vips/convolution.go index 15d3098a..23622767 100644 --- a/vips/convolution.go +++ b/vips/convolution.go @@ -26,3 +26,15 @@ func vipsSharpen(in *C.VipsImage, sigma float64, x1 float64, m2 float64) (*C.Vip return out, nil } + +// https://libvips.github.io/libvips/API/current/libvips-convolution.html#vips-sobel +func vipsSobel(in *C.VipsImage) (*C.VipsImage, error) { + incOpCounter("sobel") + var out *C.VipsImage + + if err := C.sobel_image(in, &out); err != 0 { + return nil, handleImageError(out) + } + + return out, nil +} diff --git a/vips/convolution.h b/vips/convolution.h index a5e39298..30a525ee 100644 --- a/vips/convolution.h +++ b/vips/convolution.h @@ -6,3 +6,4 @@ int gaussian_blur_image(VipsImage *in, VipsImage **out, double sigma, double min_ampl); int sharpen_image(VipsImage *in, VipsImage **out, double sigma, double x1, double m2); +int sobel_image(VipsImage *in, VipsImage **out); diff --git a/vips/image.go b/vips/image.go index 8f7b449e..3e749445 100644 --- a/vips/image.go +++ b/vips/image.go @@ -1553,6 +1553,16 @@ func (r *ImageRef) Sharpen(sigma float64, x1 float64, m2 float64) error { return nil } +// Apply Sobel edge detector to the image. +func (r *ImageRef) Sobel() error { + out, err := vipsSobel(r.image) + if err != nil { + return err + } + r.setImage(out) + return nil +} + // Modulate the colors func (r *ImageRef) Modulate(brightness, saturation, hue float64) error { var err error diff --git a/vips/image_golden_test.go b/vips/image_golden_test.go index d078ddf5..c162c311 100644 --- a/vips/image_golden_test.go +++ b/vips/image_golden_test.go @@ -437,6 +437,12 @@ func TestImage_Sharpen_8bit_Alpha(t *testing.T) { }, nil, nil) } +func TestImage_Sobel(t *testing.T) { + goldenTest(t, resources+"png-8bit+alpha.png", func(img *ImageRef) error { + return img.Sobel() + }, nil, nil) +} + func TestImage_Modulate(t *testing.T) { goldenTest(t, resources+"jpg-24bit-icc-iec.jpg", func(img *ImageRef) error { return img.Modulate(0.7, 0.5, 180) From d2d2a1f593bb3b46bdea2913e299731dbce0f502 Mon Sep 17 00:00:00 2001 From: Nova Kwok Date: Thu, 28 Mar 2024 11:39:14 +0800 Subject: [PATCH 3/4] Refine `GifExportParams` (#417) * Refine GifExportParams * Change gifDither range back to 0~10 * Add StripMetadata back * Add StripMetadata back --- vips/foreign.c | 5 +++-- vips/image.go | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/vips/foreign.c b/vips/foreign.c index 306ea914..23f9d27d 100644 --- a/vips/foreign.c +++ b/vips/foreign.c @@ -319,7 +319,8 @@ int set_tiffsave_options(VipsOperation *operation, SaveParams *params) { // https://libvips.github.io/libvips/API/current/VipsForeignSave.html#vips-magicksave-buffer int set_magicksave_options(VipsOperation *operation, SaveParams *params) { - int ret = vips_object_set(VIPS_OBJECT(operation), "format", "GIF", NULL); + int ret = vips_object_set(VIPS_OBJECT(operation), "format", "GIF", "bitdepth", params->gifBitdepth, NULL); + if (!ret && params->quality) { ret = vips_object_set(VIPS_OBJECT(operation), "quality", params->quality, NULL); @@ -331,7 +332,7 @@ int set_magicksave_options(VipsOperation *operation, SaveParams *params) { int set_gifsave_options(VipsOperation *operation, SaveParams *params) { int ret = 0; // See for argument values: https://www.libvips.org/API/current/VipsForeignSave.html#vips-gifsave - if (params->gifDither > 0.0 && params->gifDither <= 1.0) { + if (params->gifDither > 0.0 && params->gifDither <= 10) { ret = vips_object_set(VIPS_OBJECT(operation), "dither", params->gifDither, NULL); } if (params->gifEffort >= 1 && params->gifEffort <= 10) { diff --git a/vips/image.go b/vips/image.go index 3e749445..20afe99e 100644 --- a/vips/image.go +++ b/vips/image.go @@ -314,6 +314,10 @@ func NewTiffExportParams() *TiffExportParams { } } +// GifExportParams are options when exporting a GIF to file or buffer +// Please note that if vips version is above 8.12, then `vips_gifsave_buffer` is used, and only `Dither`, `Effort`, `Bitdepth` is used. +// If vips version is below 8.12, then `vips_magicksave_buffer` is used, and only `Bitdepth`, `Quality` is used. +// StripMetadata does nothing to Gif images. type GifExportParams struct { StripMetadata bool Quality int From bb678baf9560a95c9ab0e5a99c1e2204ca85c4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E5=BF=97=E9=94=8B?= <781545872@qq.com> Date: Tue, 16 Apr 2024 14:31:42 +0800 Subject: [PATCH 4/4] fix: bug in SetPages (#421) Co-authored-by: qinghuan --- vips/image.go | 2 +- vips/image_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/vips/image.go b/vips/image.go index 20afe99e..01aba400 100644 --- a/vips/image.go +++ b/vips/image.go @@ -766,7 +766,7 @@ func (r *ImageRef) SetPages(pages int) error { return err } - vipsSetImageNPages(r.image, pages) + vipsSetImageNPages(out, pages) r.setImage(out) return nil diff --git a/vips/image_test.go b/vips/image_test.go index 4783a2f4..987942cc 100644 --- a/vips/image_test.go +++ b/vips/image_test.go @@ -1169,6 +1169,18 @@ func TestImageRef_HistogramEntropy(t *testing.T) { require.True(t, e > 0) } +func TestImageRef_SetPages(t *testing.T) { + Startup(nil) + + image, err := NewImageFromFile(resources + "gif-animated.gif") + require.NoError(t, err) + require.Equal(t, 8, image.Pages()) + + err = image.SetPages(3) + require.NoError(t, err) + require.Equal(t, 3, image.Pages()) +} + // TODO unit tests to cover: // NewImageFromReader failing test // NewImageFromFile failing test