From 9f052b706178d591a4fff0ca6a6c304dde154143 Mon Sep 17 00:00:00 2001 From: Søren Sandmann Pedersen Date: Mon, 1 Aug 2011 20:16:25 -0400 Subject: Move complex_image_from_pixbuf() to image.[ch] --- Makefile | 4 ++-- image.c | 36 ++++++++++++++++++++++++++++++++++++ image.h | 5 +++++ noise2.c | 37 ------------------------------------- pngtrans.c | 62 +------------------------------------------------------------- 5 files changed, 44 insertions(+), 100 deletions(-) diff --git a/Makefile b/Makefile index 3cf248e..ce169c7 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,8 @@ filters: fft.c fft.h filters.c fft-test: fft.c fft.h fft-test.c $(CC) -o fft-test fft.c fft-test.c $(LDFLAGS) -trans: pngtrans.c fft.c fft.h - $(CC) $(GTKFLAGS) -o trans fft.c pngtrans.c $(LDFLAGS) +trans: pngtrans.c fft.c fft.h image.c image.h + $(CC) $(GTKFLAGS) -o trans fft.c pngtrans.c image.c $(LDFLAGS) bluenoise: fft.c fft.h bluenoise.c gtk-utils.c $(CC) $(GTKFLAGS) -o bluenoise fft.c bluenoise.c gtk-utils.c $(LDFLAGS) diff --git a/image.c b/image.c index 4b554ff..d0f868e 100644 --- a/image.c +++ b/image.c @@ -49,3 +49,39 @@ complex_image_subtract (complex_image_t *image, complex_image_t *other) } } +complex_image_t * +complex_image_from_pixbuf (GdkPixbuf *pixbuf) +{ + complex_image_t *result; + uint8_t *pdata; + int w, h, s; + int i, j; + gboolean has_alpha; + int n_channels; + + w = gdk_pixbuf_get_width (pixbuf); + h = gdk_pixbuf_get_height (pixbuf); + s = gdk_pixbuf_get_rowstride (pixbuf); + pdata = gdk_pixbuf_get_pixels (pixbuf); + has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); + n_channels = 3 + has_alpha; + + printf ("has alpha: %d\n", has_alpha); + + result = complex_image_new (w, h); + + for (i = 0; i < h; ++i) + { + for (j = 0; j < w; ++j) + { + uint8_t *p = &pdata[i * s + j * n_channels]; + int idx = i * w + j; + + result->red[idx].re = p[0] / 255.0; + result->green[idx].re = p[1] / 255.0; + result->blue[idx].re = p[2] / 255.0; + } + } + + return result; +} diff --git a/image.h b/image.h index 8d767f9..c5baebc 100644 --- a/image.h +++ b/image.h @@ -1,3 +1,5 @@ +#include +#include #include "complex.h" typedef struct complex_image_t complex_image_t; @@ -19,3 +21,6 @@ complex_image_copy (complex_image_t *image); void complex_image_subtract (complex_image_t *image, complex_image_t *other); + +complex_image_t * +complex_image_from_pixbuf (GdkPixbuf *pixbuf); diff --git a/noise2.c b/noise2.c index 1bfe3e2..4cea4a2 100644 --- a/noise2.c +++ b/noise2.c @@ -6,43 +6,6 @@ #include "fft.h" #include "image.h" -static complex_image_t * -complex_image_from_pixbuf (GdkPixbuf *pixbuf) -{ - complex_image_t *result; - uint8_t *pdata; - int w, h, s; - int i, j; - gboolean has_alpha; - int n_channels; - - w = gdk_pixbuf_get_width (pixbuf); - h = gdk_pixbuf_get_height (pixbuf); - s = gdk_pixbuf_get_rowstride (pixbuf); - pdata = gdk_pixbuf_get_pixels (pixbuf); - has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); - n_channels = 3 + has_alpha; - - printf ("has alpha: %d\n", has_alpha); - - result = complex_image_new (w, h); - - for (i = 0; i < h; ++i) - { - for (j = 0; j < w; ++j) - { - uint8_t *p = &pdata[i * s + j * n_channels]; - int idx = i * w + j; - - result->red[idx].re = p[0] / 255.0; - result->green[idx].re = p[1] / 255.0; - result->blue[idx].re = p[2] / 255.0; - } - } - - return result; -} - typedef uint8_t (* convert_t) (complex_t c); static GdkPixbuf * diff --git a/pngtrans.c b/pngtrans.c index aeb910e..7aaf0b8 100644 --- a/pngtrans.c +++ b/pngtrans.c @@ -4,67 +4,7 @@ #include #include #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_from_pixbuf (GdkPixbuf *pixbuf) -{ - complex_image_t *result; - uint8_t *pdata; - int w, h, s; - int i, j; - gboolean has_alpha; - int n_channels; - - w = gdk_pixbuf_get_width (pixbuf); - h = gdk_pixbuf_get_height (pixbuf); - s = gdk_pixbuf_get_rowstride (pixbuf); - pdata = gdk_pixbuf_get_pixels (pixbuf); - has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); - n_channels = 3 + has_alpha; - - printf ("has alpha: %d\n", has_alpha); - - result = complex_image_new (w, h); - - for (i = 0; i < h; ++i) - { - for (j = 0; j < w; ++j) - { - uint8_t *p = &pdata[i * s + j * n_channels]; - int idx = i * w + j; - - result->red[idx].re = p[0] / 255.0; - result->green[idx].re = p[1] / 255.0; - result->blue[idx].re = p[2] / 255.0; - } - } - - return result; -} +#include "image.h" typedef uint8_t (* convert_t) (complex_t c); -- cgit v1.2.3