summaryrefslogtreecommitdiff
path: root/pngtrans.c
blob: 32df81f5f8aec6dffe3a668ef7ac18f0cc757e61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <stdlib.h>
#include <stdint.h>
#include <cairo.h>
#include <gtk/gtk.h>
#include <gdk/gdkpixbuf.h>
#include "fft.h"
#include "image.h"

static complex_t
filter (complex_t c, double dist)
{
    double m = complex_mag (c);
    double arg = complex_arg (c);
    
    return complex_from_mag_arg (m * (1/(pow (sqrt (dist) / 128.0, 4) + 1)) , arg);
}

static void
low_pass (complex_image_t *image, double d)
{
    int w = image->width;
    int h = image->height;
    int i, j;
    double d2 = d * d;
    int c = h / 2;
    
    for (i = 0; i < h; ++i)
    {
	for (j = 0; j < w; ++j)
	{
	    int idx = i * w + j;
	    double dist = (c - i) * (c - i) + (c - j) * (c -j);
	    double t;
	    
	    image->red[idx] = filter (image->red[idx], dist);
	    image->green[idx] = filter (image->green[idx], dist);
	    image->blue[idx] = filter (image->blue[idx], dist);
	}
    }
}

int
main (int argc, char **argv)
{
    char *input;
    GdkPixbuf *pb;
    complex_image_t *image;
    
    g_type_init ();
    
    if (argc < 2)
    {
	printf ("Usage: %s <input name>\n\n", argv[0]);
	return 1;
    }
    
    input = argv[1];
    
    if (!(pb = gdk_pixbuf_new_from_file (input, NULL)))
    {
	printf ("Could not open %s\n", input);
	return -1;
    }
    
    image = complex_image_from_pixbuf (pb);
    
    g_print ("width, height %d %d\n", image->width, image->height);
    
    complex_image_fft (image);
    
    complex_image_show ("test", image, CONVERT_MAG);
    
    low_pass (image, 2 * image->width);
    
    complex_image_show ("test", image, CONVERT_MAG);
    
    complex_image_ifft (image);
    
    complex_image_show ("test", image, CONVERT_RE);
    
    return 0;
}