Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add invalidate() method #317

Merged
merged 2 commits into from
Mar 28, 2022
Merged

add invalidate() method #317

merged 2 commits into from
Mar 28, 2022

Conversation

jcupitt
Copy link
Member

@jcupitt jcupitt commented Mar 28, 2022

useful if you're modifying image memory arrays outside libvips, eg. with
numpy

see #316

useful if you're modifying image memory arrays outside libvips, eg. with
numpy

see #316
@jcupitt
Copy link
Member Author

jcupitt commented Mar 28, 2022

I've not added a test, so any testing would be great!

@erdmann
Copy link
Contributor

erdmann commented Mar 28, 2022

Great!

When I first tried this, I got an error about

--> 736     vips_lib.vips_image_invalidate_all(self.pointer)

AttributeError: cffi library '_libvips' has no function, constant or global variable named 'vips_image_invalidate_all'

But on updating libvips and recompiling and then reinstalling pyvips it works.

Here's a little test:

diff --git a/tests/test_image.py b/tests/test_image.py
index ba69275..da07c60 100644
--- a/tests/test_image.py
+++ b/tests/test_image.py
@@ -168,3 +168,21 @@ class TestImage:
             wrongargtype = dict(a=1, b=2)
             x = im[wrongargtype]
 
+
+    def test_invalidate(self):
+        try:
+            import numpy as np
+        except ImportError:
+            pytest.skip('numpy not available')
+
+        a = np.zeros((1,1))
+        p = pyvips.Image.new_from_memory(a.data, 1, 1, 1, 'double')
+        v = p(0, 0)
+        assert v == [0]
+        a[0,0] = 1
+        v = p(0, 0)
+        assert v == [0]
+        p.invalidate()
+        v = p(0, 0)
+        assert v == [1]

@jcupitt
Copy link
Member Author

jcupitt commented Mar 28, 2022

Oh hmm that's bad. Do you remember which libvips it failed on? I thought invalidate_all() had been around for years.

@jcupitt
Copy link
Member Author

jcupitt commented Mar 28, 2022

Yes, looks like it has been around since 8.0. Perhaps you just needed to force the rebuild of your FFI binding.

I'll paste the test in, thanks!

@erdmann
Copy link
Contributor

erdmann commented Mar 28, 2022

Do you remember which libvips it failed on? I thought invalidate_all() had been around for years.

I was using a build from git back in February, so it was almost certainly just a stale binding. I'm not sure what I did to force the refresh, since I installed your branch just like any other, but anyway all is right now.

@jcupitt jcupitt merged commit c048aaa into master Mar 28, 2022
@jcupitt jcupitt deleted the add-invalidate branch March 28, 2022 14:34
@jcupitt
Copy link
Member Author

jcupitt commented Mar 28, 2022

OK, let's merge then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants