Author: abrander
Date: 2009-06-01 23:50:40 +0200 (Mon, 01 Jun 2009)
New Revision: 2498
Modified:
trunk/plugins/cache/cache.c
Log:
Made RSCache ROI-aware.
Modified: trunk/plugins/cache/cache.c
===================================================================
--- trunk/plugins/cache/cache.c 2009-06-01 21:50:02 UTC (rev 2497)
+++ trunk/plugins/cache/cache.c 2009-06-01 21:50:40 UTC (rev 2498)
@@ -36,6 +36,7 @@
GdkPixbuf *image8;
gboolean ignore_changed;
RSFilterChangedMask mask;
+ GdkRectangle *last_roi;
gint latency;
};
@@ -54,6 +55,7 @@
static void set_property (GObject *object, guint property_id, const GValue
*value, GParamSpec *pspec);
static RS_IMAGE16 *get_image(RSFilter *filter, RS_FILTER_PARAM *param);
static GdkPixbuf *get_image8(RSFilter *filter, RS_FILTER_PARAM *param);
+static void flush(RSCache *cache);
static void previous_changed(RSFilter *filter, RSFilter *parent,
RSFilterChangedMask mask);
G_MODULE_EXPORT void
@@ -90,6 +92,7 @@
cache->image = NULL;
cache->image8 = NULL;
cache->ignore_changed = FALSE;
+ cache->last_roi = NULL;
cache->latency = 1;
}
@@ -123,11 +126,46 @@
}
}
+static gboolean
+rectangle_is_inside(GdkRectangle *outer_rect, GdkRectangle *inner_rect)
+{
+ const gint inner_x2 = inner_rect->x + inner_rect->width;
+ const gint inner_y2 = inner_rect->y + inner_rect->height;
+ const gint outer_x2 = outer_rect->x + outer_rect->width;
+ const gint outer_y2 = outer_rect->y + outer_rect->height;
+
+ /* outside left/top */
+ if (inner_rect->x < outer_rect->x || inner_rect->y < outer_rect->y)
+ return FALSE;
+
+ /* outside right/bottom */
+ if ((inner_x2 > outer_x2) || (inner_y2 > outer_y2))
+ return FALSE;
+
+ return TRUE;
+}
+
static RS_IMAGE16 *
get_image(RSFilter *filter, RS_FILTER_PARAM *param)
{
RSCache *cache = RS_CACHE(filter);
+ if (param && param->roi)
+ {
+ if (cache->last_roi)
+ {
+ if (!rectangle_is_inside(cache->last_roi, param->roi))
+ flush(cache);
+ }
+
+ /* cache->last_roi can change in flush() */
+ if (!cache->last_roi)
+ {
+ cache->last_roi = g_new(GdkRectangle, 1);
+ *cache->last_roi = *param->roi;
+ }
+ }
+
if (!cache->image)
cache->image = rs_filter_get_image(filter->previous, param);
@@ -139,6 +177,22 @@
{
RSCache *cache = RS_CACHE(filter);
+ if (param)
+ {
+ if (cache->last_roi)
+ {
+ if (!rectangle_is_inside(cache->last_roi, param->roi))
+ flush(cache);
+ }
+
+ /* cache->last_roi can change in flush() */
+ if (!cache->last_roi)
+ {
+ cache->last_roi = g_new(GdkRectangle, 1);
+ *cache->last_roi = *param->roi;
+ }
+ }
+
if (!cache->image8)
cache->image8 = rs_filter_get_image8(filter->previous, param);
@@ -156,23 +210,32 @@
}
static void
+flush(RSCache *cache)
+{
+ if (cache->last_roi)
+ g_free(cache->last_roi);
+
+ cache->last_roi = NULL;
+
+ if (cache->image)
+ g_object_unref(cache->image);
+
+ cache->image = NULL;
+
+ if (cache->image8)
+ g_object_unref(cache->image8);
+
+ cache->image8 = NULL;
+}
+
+static void
previous_changed(RSFilter *filter, RSFilter *parent, RSFilterChangedMask mask)
{
RSCache *cache = RS_CACHE(filter);
if (mask & RS_FILTER_CHANGED_PIXELDATA)
- {
- if (cache->image)
- g_object_unref(cache->image);
+ flush(cache);
- cache->image = NULL;
-
- if (cache->image8)
- g_object_unref(cache->image8);
-
- cache->image8 = NULL;
- }
-
if (cache->latency > 0)
{
cache->mask = mask;
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit