summaryrefslogtreecommitdiff
path: root/roi.c
diff options
context:
space:
mode:
Diffstat (limited to 'roi.c')
-rw-r--r--roi.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/roi.c b/roi.c
index 266cb15..59eb57a 100644
--- a/roi.c
+++ b/roi.c
@@ -33,16 +33,24 @@ calc_rubberband_rect(struct roi *roi,
*height = ABS(roi->rubberband.y1 - roi->rubberband.y2);
}
+static inline void
+pixbuf_get(GdkPixbuf *pixbuf, guchar **pixels,
+ gint *width, gint *height, gint *nch, gint *stride)
+{
+ if (pixels) *pixels = gdk_pixbuf_get_pixels(pixbuf);
+ if (width) *width = gdk_pixbuf_get_width(pixbuf);
+ if (height) *height = gdk_pixbuf_get_height(pixbuf);
+ if (nch) *nch = gdk_pixbuf_get_n_channels(pixbuf);
+ if (stride) *stride = gdk_pixbuf_get_rowstride(pixbuf);
+}
+
static gboolean
do_roi(struct roi *roi)
{
GdkPixbuf *match;
cairo_rectangle_t area;
- gint x, y, i;
- gint width, height;
- gint stride, nch;
+ gint i, s, x, y, width, height, nch, stride;
guchar *pix, *row;
- gint s;
gint middle[3] = { 0, 0, 0 };
gint sigma[3] = { 0, 0, 0 };
struct match_interval { gint min, max; } interval[3];
@@ -54,12 +62,10 @@ do_roi(struct roi *roi)
match = gdk_pixbuf_new_subpixbuf(roi->input, area.x, area.y,
area.width, area.height);
- nch = gdk_pixbuf_get_n_channels(match);
- stride = gdk_pixbuf_get_rowstride(match);
s = area.width * area.height;
- for (y = 0, row = gdk_pixbuf_get_pixels(match);
- y < area.height; ++y, row += stride) {
+ pixbuf_get(match, &row, NULL, NULL, &nch, &stride);
+ for (y = 0; y < area.height; ++y, row += stride) {
for (x = 0, pix = row; x < area.width; ++x, pix += nch) {
for (i = 0; i < 3; ++i)
middle[i] += pix[i];
@@ -68,8 +74,8 @@ do_roi(struct roi *roi)
for (i = 0; i < 3; ++i)
middle[i] /= s;
- for (y = 0, row = gdk_pixbuf_get_pixels(match);
- y < area.height; ++y, row += stride) {
+ pixbuf_get(match, &row, NULL, NULL, NULL, NULL);
+ for (y = 0; y < area.height; ++y, row += stride) {
for (x = 0, pix = row; x < area.width; ++x, pix += nch) {
for (i = 0; i < 3; ++i)
sigma[i] +=
@@ -77,7 +83,6 @@ do_roi(struct roi *roi)
(pix[i] - middle[i]);
}
}
-
for (i = 0; i < 3; ++i)
sigma[i] = sqrt(sigma[i] / (s - 1));
@@ -91,17 +96,12 @@ do_roi(struct roi *roi)
i, interval[i].min, interval[i].max);
}
- nch = gdk_pixbuf_get_n_channels(roi->input);
- stride = gdk_pixbuf_get_rowstride(roi->input);
- width = gdk_pixbuf_get_width(roi->input);
- height = gdk_pixbuf_get_height(roi->input);
-
if (roi->modified_input)
g_object_unref(roi->modified_input);
roi->modified_input = gdk_pixbuf_copy(roi->input);
- for (y = 0, row = gdk_pixbuf_get_pixels(roi->modified_input);
- y < height; ++y, row += stride) {
+ pixbuf_get(roi->modified_input, &row, &width, &height, &nch, &stride);
+ for (y = 0; y < height; ++y, row += stride) {
for (x = 0, pix = row; x < width; ++x, pix += nch) {
int H = 1;
for (i = 0; i < 3; ++i) {