7 #include "../src/mark.h"
11 /* fill makred area with different color */
12 void fill(int x, int y, int clear)
14 GdkDrawable *draw = gtk_widget_get_window(img_drawing_area);
15 int window_width, window_height;
16 unsigned char *img_fill_buffer;
17 unsigned char old, new = 0;
19 gdk_drawable_get_size (draw, &window_width, &window_height);
24 img_fill_buffer = calloc(img_width*img_height, sizeof(*img_fill_buffer));
28 /* we need to calculate an offset, since the drawing area is now larger */
29 x -= (window_width - img_width*img_scale_x/16) / 2;
30 y -= (window_height - img_height*img_scale_y/16) / 2;
35 if (x < 0 || x >= img_width || y < 0 || y >= img_height)
38 old = img_mark_buffer[img_width*y+x];
40 new = mark_selected + 1;
45 img_mark_buffer[img_width*y+x] = new;
46 img_fill_buffer[img_width*y+x] = 1;
51 for (y = 0; y < img_height; y++) {
53 for (x = 0; x < img_width; x++) {
54 /* check for filled pixle */
55 if (!img_fill_buffer[img_width*y+x])
57 /* if right neighbor pixle is old, set to new */
58 if (x < img_width-1 && img_mark_buffer[img_width*y+(x+1)] == old) {
59 img_mark_buffer[img_width*y+(x+1)] = new;
60 img_fill_buffer[img_width*y+(x+1)] = 1;
63 /* if lower neighbor pixle is old, set to new */
64 if (y < img_height-1 && img_mark_buffer[img_width*(y+1)+x] == old) {
65 img_mark_buffer[img_width*(y+1)+x] = new;
66 img_fill_buffer[img_width*(y+1)+x] = 1;
69 /* fill8: if lower right neighbor pixle is old, set to new */
70 if (old && x < img_width-1 && y < img_height-1 && img_mark_buffer[img_width*(y+1)+(x+1)] == old) {
71 img_mark_buffer[img_width*(y+1)+(x+1)] = new;
72 img_fill_buffer[img_width*(y+1)+(x+1)] = 1;
77 for (x = img_width - 1; x >= 0; x--) {
78 /* check for filled pixle */
79 if (!img_fill_buffer[img_width*y+x])
81 /* if left neighbor pixle is old, set to new */
82 if (x > 0 && img_mark_buffer[img_width*y+(x-1)] == old) {
83 img_mark_buffer[img_width*y+(x-1)] = new;
84 img_fill_buffer[img_width*y+(x-1)] = 1;
87 /* if lower neighbor pixle is old, set to new */
88 if (y < img_height-1 && img_mark_buffer[img_width*(y+1)+x] == old) {
89 img_mark_buffer[img_width*(y+1)+x] = new;
90 img_fill_buffer[img_width*(y+1)+x] = 1;
93 /* if fill8. lower left neighbor pixle is old, set to new */
94 if (old && x > 0 && y < img_height-1 && img_mark_buffer[img_width*(y+1)+(x-1)] == old) {
95 img_mark_buffer[img_width*(y+1)+(x-1)] = new;
96 img_fill_buffer[img_width*(y+1)+(x-1)] = 1;
102 for (y = img_height-1; y >= 0; y--) {
104 for (x = 0; x < img_width; x++) {
105 /* check for filled pixle */
106 if (!img_fill_buffer[img_width*y+x])
108 /* if right neighbor pixle is old, set to new */
109 if (x < img_width-1 && img_mark_buffer[img_width*y+(x+1)] == old) {
110 img_mark_buffer[img_width*y+(x+1)] = new;
111 img_fill_buffer[img_width*y+(x+1)] = 1;
114 /* if upper neighbor pixle is old, set to new */
115 if (y > 0 && img_mark_buffer[img_width*(y-1)+x] == old) {
116 img_mark_buffer[img_width*(y-1)+x] = new;
117 img_fill_buffer[img_width*(y-1)+x] = 1;
120 /* fill8: if upper right neighbor pixle is old, set to new */
121 if (old && x < img_width-1 && y > 0 && img_mark_buffer[img_width*(y-1)+(x+1)] == old) {
122 img_mark_buffer[img_width*(y-1)+(x+1)] = new;
123 img_fill_buffer[img_width*(y-1)+(x+1)] = 1;
128 for (x = img_width - 1; x >= 0; x--) {
129 /* check for filled pixle */
130 if (!img_fill_buffer[img_width*y+x])
132 /* if left neighbor pixle is old, set to new */
133 if (x > 0 && img_mark_buffer[img_width*y+(x-1)] == old) {
134 img_mark_buffer[img_width*y+(x-1)] = new;
135 img_fill_buffer[img_width*y+(x-1)] = 1;
138 /* if upper neighbor pixle is old, set to new */
139 if (y > 0 && img_mark_buffer[img_width*(y-1)+x] == old) {
140 img_mark_buffer[img_width*(y-1)+x] = new;
141 img_fill_buffer[img_width*(y-1)+x] = 1;
144 /* if upper leftneighbor pixle is old, set to new */
145 if (old && x > 0 && y > 0 && img_mark_buffer[img_width*(y-1)+(x-1)] == old) {
146 img_mark_buffer[img_width*(y-1)+(x-1)] = new;
147 img_fill_buffer[img_width*(y-1)+(x-1)] = 1;
152 // printf("filled %d pixles in this iteration\n", filled);
156 free(img_fill_buffer);