[gimp] plug-ins: raw_load_rgb565() ported to GEGL iterators.



commit ba582253df28f9e8be1e882c8e241bac6fe4b315
Author: Jehan <jehan girinstud io>
Date:   Mon Jun 20 14:34:58 2022 +0200

    plug-ins: raw_load_rgb565() ported to GEGL iterators.
    
    Rather than allocating 2 huge data buffers of the whole image size (one
    in RGB565 and one in RGB-u8), just iterate through the file only
    creating one single small temporary data buffer for single input line in
    tiles returned by the iterator. This will be much better,
    memory-efficiency wise.

 plug-ins/common/file-raw-data.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/plug-ins/common/file-raw-data.c b/plug-ins/common/file-raw-data.c
index aaf7cd057a..c829b04595 100644
--- a/plug-ins/common/file-raw-data.c
+++ b/plug-ins/common/file-raw-data.c
@@ -868,18 +868,29 @@ raw_load_rgb565 (RawGimpData *data,
                  gint         offset,
                  RawType      type)
 {
-  gint32   num_pixels = width * height;
-  guint16 *in         = g_malloc (num_pixels * 2);
-  guchar  *row        = g_malloc (num_pixels * 3);
+  GeglBufferIterator *iter;
+  guint16            *in = NULL;
 
-  raw_read_row (data->fp, (guchar *)in, offset, num_pixels * 2);
-  rgb_565_to_888 (in, row, num_pixels, type);
+  iter = gegl_buffer_iterator_new (data->buffer, GEGL_RECTANGLE (0, 0, width, height),
+                                   0, NULL, GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE, 1);
 
-  gegl_buffer_set (data->buffer, GEGL_RECTANGLE (0, 0, width, height),
-                   0, NULL, row, GEGL_AUTO_ROWSTRIDE);
+  while (gegl_buffer_iterator_next (iter))
+    {
+      const GeglRectangle *roi = &iter->items[0].roi;
+      guchar              *out = iter->items[0].data;
+      gint                 line;
+
+      in = g_realloc (in, iter->length * 2);
+      for (line = 0; line < roi->height; line++)
+        {
+          raw_read_row (data->fp, (guchar *) in,
+                        offset + ((roi->y + line) * width * 2) + roi->x * 2,
+                        iter->length * 2);
+          rgb_565_to_888 (in, out + line * roi->width * 3, roi->width, type);
+        }
+    }
 
   g_free (in);
-  g_free (row);
 
   return TRUE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]