From 3e8a0fc522ee5bf7185a4b404c7f8a581129ed35 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 19 Apr 2024 11:27:51 +0100 Subject: [PATCH] Ensure only one StaySequential operation per pipeline This should reduce memory consumption for more complex pipelines that combine multiple operations without sequential access support e.g. flip and Gaussian blur. --- src/common.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common.cc b/src/common.cc index 588b2a07e..ae48ff58a 100644 --- a/src/common.cc +++ b/src/common.cc @@ -1082,8 +1082,10 @@ namespace sharp { Ensure decoding remains sequential. */ VImage StaySequential(VImage image, VipsAccess access, bool condition) { - if (access == VIPS_ACCESS_SEQUENTIAL && condition) { - return image.copy_memory(); + static const char* meta = "sharp-copy-memory"; + if (access == VIPS_ACCESS_SEQUENTIAL && condition && image.get_typeof(meta) != G_TYPE_INT) { + image = image.copy_memory(); + image.set(meta, 1); } return image; }