From a6ec80abb5a7691bae561f62eaff7aeeca640932 Mon Sep 17 00:00:00 2001 From: Ali Naqvi Date: Wed, 6 Mar 2024 20:21:21 +0800 Subject: [PATCH 1/2] fix: patch required to work with latest crystal version --- shard.yml | 2 +- spec/connection_spec.cr | 29 ++++++++++------------------- spec/image_spec.cr | 1 - src/vips/lib.cr | 30 +++++++++++++++--------------- src/vips/source.cr | 2 +- src/vips/target.cr | 2 +- 6 files changed, 28 insertions(+), 38 deletions(-) diff --git a/shard.yml b/shard.yml index e40ea92..d325a4b 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: vips -version: 0.1.5 +version: 0.1.6 authors: - Ali Naqvi diff --git a/spec/connection_spec.cr b/spec/connection_spec.cr index 3be87ca..ce4569d 100644 --- a/spec/connection_spec.cr +++ b/spec/connection_spec.cr @@ -114,28 +114,19 @@ describe Vips::Connection do Vips::TargetCustom.new end - pending "can write an image to a user output stream" do + it "can write an image to a user output stream" do filename = timg("x5.png") file = File.open(filename, "wb") + io = IO::Memory.new target = Vips::TargetCustom.new - target.on_write { |slice| file.write(slice); slice.size.to_i64 } - target.on_finish { file.close } - - image = Vips::Image.new_from_file(simg("wagon.jpg")) - image.write_to_target(target, "%.png") - - image = Vips::Image.new_from_file(filename) - - image.width.should eq(685) - image.height.should eq(478) - image.bands.should eq(3) - (image.avg - 109.789).should be <= 0.001 - end - - it "can write an image via target stream" do - filename = timg("x5.png") - file = File.open(filename, "wb") - target = Vips::TargetStream.new_from_stream(file) + target.on_write { |slice| io.write(slice); slice.size.to_i64 } + target.on_finish do + io.rewind + File.open(filename, "wb") do |file| + IO.copy(io, file) + end + io.clear + end image = Vips::Image.new_from_file(simg("wagon.jpg")) image.write_to_target(target, "%.png") diff --git a/spec/image_spec.cr b/spec/image_spec.cr index 9978e8b..704d1fd 100644 --- a/spec/image_spec.cr +++ b/spec/image_spec.cr @@ -599,7 +599,6 @@ describe Vips::Image do Vips::Enums::Interpretation::Lch, Vips::Enums::Interpretation::Cmc, Vips::Enums::Interpretation::Labs, - Vips::Enums::Interpretation::Scrgb, Vips::Enums::Interpretation::Hsv, Vips::Enums::Interpretation::Srgb, Vips::Enums::Interpretation::Yxy] diff --git a/src/vips/lib.cr b/src/vips/lib.cr index 0036700..183a0c0 100644 --- a/src/vips/lib.cr +++ b/src/vips/lib.cr @@ -465,13 +465,13 @@ lib LibVips enum GLogLevelFlags Recursion = 1 Fatal = 2 - Error = 4 - Critical = 8 - Warning = 16 - Message = 32 - Info = 64 - Debug = 128 - Mask = -4 + Error = 4 + Critical = 8 + Warning = 16 + Message = 32 + Info = 64 + Debug = 128 + Mask = -4 end alias GLogFunc = (Gchar*, GLogLevelFlags, Gchar*, Gpointer -> Void) @@ -1373,13 +1373,13 @@ lib LibVips @[Flags] enum VipsOperationFlags - Sequential = 1 - SequentialUnbuffered = 2 - Nocache = 4 - Deprecated = 8 - Untrusted = 16 - Blocked = 32 - Revalidate = 64 + Sequential = 1 + SequentialUnbuffered = 2 + Nocache = 4 + Deprecated = 8 + Untrusted = 16 + Blocked = 32 + Revalidate = 64 end fun vips_operation_class_print_usage(operation_class : VipsOperationClass*) @@ -2089,6 +2089,6 @@ lib LibVips alias ReadCB = (Void*, Void*, Gint64, Void* -> Gint) alias SeekCB = (Void*, Gint64, Gint, Void* -> Gint64) - alias WriteCB = (Void*, UInt8*, Gint, Void* -> Gint64) + alias WriteCB = (Void*, Void*, Gint, Void* -> Gint64) alias FinishCB = (Void*, Void* ->) end diff --git a/src/vips/source.cr b/src/vips/source.cr index c77a9de..15da31b 100644 --- a/src/vips/source.cr +++ b/src/vips/source.cr @@ -97,7 +97,7 @@ module Vips signal_connect("read", LibVips::ReadCB.new { |_source, buff, size, data| next 0 if size <= 0 callback = Box(typeof(block)).unbox(data) - slice = Bytes.new(buff.as(UInt8*), size) + slice = Bytes.new(buff.as(UInt8*), size - 1) callback.call(slice) }, boxed_data) end diff --git a/src/vips/target.cr b/src/vips/target.cr index 7940aa2..9129299 100644 --- a/src/vips/target.cr +++ b/src/vips/target.cr @@ -83,7 +83,7 @@ module Vips signal_connect("write", LibVips::WriteCB.new { |source, buff, size, data| next -1_i64 if size <= 0 callback = Box(typeof(block)).unbox(data) - slice = Bytes.new(buff, size) + slice = Bytes.new(buff.as(UInt8*), size) @@box.delete(data) callback.call(slice) }, boxed_data) From fd6faa3889527765ddcb576831018a144b46b1f6 Mon Sep 17 00:00:00 2001 From: Ali Naqvi Date: Wed, 6 Mar 2024 20:24:13 +0800 Subject: [PATCH 2/2] updated ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2ea5e7..c57342f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: DEBIAN_FRONTEND: noninteractive run: # we only need the library - sudo apt-get install --fix-missing -qq -o Acquire::Retries=3 libvips-dev + sudo apt-get update && sudo apt-get install libvips-dev - name: Run tests run: crystal spec --error-trace -v spec - name: Check formatting