diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2011-08-01 20:16:25 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2011-08-01 20:16:25 -0400 |
commit | 9f052b706178d591a4fff0ca6a6c304dde154143 (patch) | |
tree | 7bb170f5f27a5286aae48020dd5d75d5ced0f225 | |
parent | b35c4c031ae610bd21cf2dfd5876f54b2539079d (diff) |
Move complex_image_from_pixbuf() to image.[ch]
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | image.c | 36 | ||||
-rw-r--r-- | image.h | 5 | ||||
-rw-r--r-- | noise2.c | 37 | ||||
-rw-r--r-- | pngtrans.c | 62 |
5 files changed, 44 insertions, 100 deletions
@@ -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) @@ -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; +} @@ -1,3 +1,5 @@ +#include <gdk/gdkpixbuf.h> +#include <stdint.h> #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); @@ -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 * @@ -4,67 +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_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); |