summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2011-08-01 20:13:06 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2011-08-01 20:13:06 -0400
commitb35c4c031ae610bd21cf2dfd5876f54b2539079d (patch)
tree23e6acd830a65e03b0678f4cbc790bea088da636
parent6073c155a3caf6feac4b19851777b53c70185e3f (diff)
Move image support to separate file
-rw-r--r--Makefile4
-rw-r--r--complex.h1
-rw-r--r--image.c51
-rw-r--r--image.h21
-rw-r--r--noise2.c59
5 files changed, 76 insertions, 60 deletions
diff --git a/Makefile b/Makefile
index 223a5b8..3cf248e 100644
--- a/Makefile
+++ b/Makefile
@@ -16,5 +16,5 @@ trans: pngtrans.c fft.c fft.h
bluenoise: fft.c fft.h bluenoise.c gtk-utils.c
$(CC) $(GTKFLAGS) -o bluenoise fft.c bluenoise.c gtk-utils.c $(LDFLAGS)
-noise2: noise2.c fft.c fft.h
- $(CC) $(GTKFLAGS) -o noise2 noise2.c fft.c $(LDFLAGS)
+noise2: noise2.c fft.c fft.h image.c image.h
+ $(CC) $(GTKFLAGS) -o noise2 noise2.c image.c fft.c $(LDFLAGS)
diff --git a/complex.h b/complex.h
index 0dcde9c..58260a5 100644
--- a/complex.h
+++ b/complex.h
@@ -1,4 +1,5 @@
#ifndef COMPLEX_H
+#define COMPLEX_H
#include <math.h>
diff --git a/image.c b/image.c
new file mode 100644
index 0000000..4b554ff
--- /dev/null
+++ b/image.c
@@ -0,0 +1,51 @@
+#include <glib.h>
+#include "image.h"
+
+complex_image_t *
+complex_image_new (int width, int height)
+{
+ complex_image_t *image = g_new0 (complex_image_t, 1);
+
+ image->width = width;
+ image->height = height;
+ image->red = g_new0 (complex_t, width * height);
+ image->green = g_new0 (complex_t, width * height);
+ image->blue = g_new0 (complex_t, width * height);
+
+ return image;
+}
+
+complex_image_t *
+complex_image_copy (complex_image_t *image)
+{
+ complex_image_t *copy = complex_image_new (image->width, image->height);
+ int width = image->width;
+ int height = image->height;
+
+ copy->red = g_memdup (image->red, width * height * sizeof (complex_t));
+ copy->green = g_memdup (image->green, width * height * sizeof (complex_t));
+ copy->blue = g_memdup (image->blue, width * height * sizeof (complex_t));
+
+ return copy;
+}
+
+void
+complex_image_subtract (complex_image_t *image, complex_image_t *other)
+{
+ int i, j;
+ int h = image->height;
+ int w = image->width;
+
+ for (i = 0; i < h; ++i)
+ {
+ for (j = 0; j < w; ++j)
+ {
+ int idx = i * w + j;
+
+ image->red[idx] = complex_sub (image->red[idx], other->red[idx]);
+ image->green[idx] = complex_sub (image->green[idx], other->green[idx]);
+ image->blue[idx] = complex_sub (image->blue[idx], other->blue[idx]);
+ }
+ }
+}
+
diff --git a/image.h b/image.h
new file mode 100644
index 0000000..8d767f9
--- /dev/null
+++ b/image.h
@@ -0,0 +1,21 @@
+#include "complex.h"
+
+typedef struct complex_image_t complex_image_t;
+struct complex_image_t
+{
+ int width;
+ int height;
+ complex_t *red;
+ complex_t *green;
+ complex_t *blue;
+};
+
+complex_image_t *
+complex_image_new (int width, int height);
+
+complex_image_t *
+complex_image_copy (complex_image_t *image);
+
+void
+complex_image_subtract (complex_image_t *image,
+ complex_image_t *other);
diff --git a/noise2.c b/noise2.c
index 5974e40..1bfe3e2 100644
--- a/noise2.c
+++ b/noise2.c
@@ -4,64 +4,7 @@
#include <gtk/gtk.h>
#include <gdk/gdkpixbuf.h>
#include "fft.h"
-
-typedef struct complex_image_t complex_image_t;
-struct complex_image_t
-{
- int width;
- int height;
- complex_t *red;
- complex_t *green;
- complex_t *blue;
-};
-
-static complex_image_t *
-complex_image_new (int width, int height)
-{
- complex_image_t *image = g_new0 (complex_image_t, 1);
-
- image->width = width;
- image->height = height;
- image->red = g_new0 (complex_t, width * height);
- image->green = g_new0 (complex_t, width * height);
- image->blue = g_new0 (complex_t, width * height);
-
- return image;
-}
-
-static complex_image_t *
-complex_image_copy (complex_image_t *image)
-{
- complex_image_t *copy = complex_image_new (image->width, image->height);
- int width = image->width;
- int height = image->height;
-
- copy->red = g_memdup (image->red, width * height * sizeof (complex_t));
- copy->green = g_memdup (image->green, width * height * sizeof (complex_t));
- copy->blue = g_memdup (image->blue, width * height * sizeof (complex_t));
-
- return copy;
-}
-
-static void
-complex_image_subtract (complex_image_t *image, complex_image_t *other)
-{
- int i, j;
- int h = image->height;
- int w = image->width;
-
- for (i = 0; i < h; ++i)
- {
- for (j = 0; j < w; ++j)
- {
- int idx = i * w + j;
-
- image->red[idx] = complex_sub (image->red[idx], other->red[idx]);
- image->green[idx] = complex_sub (image->green[idx], other->green[idx]);
- image->blue[idx] = complex_sub (image->blue[idx], other->blue[idx]);
- }
- }
-}
+#include "image.h"
static complex_image_t *
complex_image_from_pixbuf (GdkPixbuf *pixbuf)