summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-08-29 11:55:05 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-08-29 11:55:05 -0400
commitaa9a48fdb041b90df9a88c5175dd7e0681f10894 (patch)
tree9a10eed12a71ee679bc5d1f2892c1b59069bfe15
parentb237bfb6c2159d555c1778ef6f049a16c2cbd03d (diff)
optimize away unnecessary calls to gamma->flush()
-rw-r--r--ggamma.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/ggamma.c b/ggamma.c
index 3373be2..ac4eb35 100644
--- a/ggamma.c
+++ b/ggamma.c
@@ -19,12 +19,18 @@ struct gamma_channel {
void curve_edited(GtkWidget *raw_curve, UNUSED GdkEvent *event, struct gamma_channel *gamma) {
gfloat vec[gamma->size];
+ gboolean dirty = FALSE;
gtk_curve_get_vector(GTK_CURVE(raw_curve), gamma->size, vec);
- for (int i = 0; i < gamma->size; i++)
- gamma->data[i] = (uint16_t)(vec[i] * 65535.0 / gamma->size);
+ for (int i = 0; i < gamma->size; i++) {
+ uint16_t y = vec[i] * 65535.0 / gamma->size;
+ if (y != gamma->data[i]) {
+ gamma->data[i] = y;
+ dirty = TRUE;
+ }
+ }
- if (gamma->flush)
+ if (dirty && gamma->flush)
gamma->flush();
}