Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/fill/eggfill.c
diff options
context:
space:
mode:
Diffstat (limited to 'fill/eggfill.c')
-rw-r--r--fill/eggfill.c63
1 files changed, 27 insertions, 36 deletions
diff --git a/fill/eggfill.c b/fill/eggfill.c
index 5de388d..318879c 100644
--- a/fill/eggfill.c
+++ b/fill/eggfill.c
@@ -51,7 +51,6 @@ Roseli de Deus Lopes (roseli@lsi.usp.br)
*/
-#include <gtk/gtk.h>
#include "eggfill.h"
#define front(q) ( (q)->front )
@@ -60,9 +59,9 @@ Roseli de Deus Lopes (roseli@lsi.usp.br)
/* this queue has a Header that points to the Front and Rear elements */
/* empty queue: q->front = NULL and q->rear = NULL */
-/* check if queue q is empty */
+/* check if queue q is empty */
int queue_is_empty(queue *q){
- return ((front(q)==NULL) && (rear(q)==NULL));
+ return ((front(q)==NULL) && (rear(q)==NULL));
}
queue *queue_init(void){
@@ -90,7 +89,6 @@ void queue_make_empty(queue *q){
queue_dequeue(q);
}
-
void queue_enqueue(int element, queue *q){
no *tmp;
tmp = (no*)malloc(sizeof(no));
@@ -123,50 +121,50 @@ void queue_dequeue(queue *q){
}
}/* end of queue*/
-void fill(GdkDrawable *drawable, GdkGC *gc, int x, int y, int width, int height, int color){
+void
+floodfill(unsigned int* pixels, int x, int y, int width, int height, unsigned int color) {
- printf("Entrando no fill\n");
- int color_start;
+ printf("\nEntrando to floodfill\n");
queue *lista_xy;
lista_xy = queue_init();
- GdkImage *image;
- image = gdk_drawable_get_image(drawable,0,0,width,height);
- printf("0x%x\n", image);
-
- color_start = gdk_image_get_pixel(image, x, y);
+ int color_start = pixels[x + y * width];
- if (color!=color_start) {
+ if (color != color_start) {
queue_enqueue(x, lista_xy);
- queue_enqueue(y, lista_xy);
- gdk_image_put_pixel(image, x, y, color);
+ queue_enqueue(y, lista_xy);
+
+ pixels[x + y * width] = color;
+
while (!queue_is_empty(lista_xy)) {
- if (x+1 < width){
- if (gdk_image_get_pixel(image, x+1, y) == color_start){
- gdk_image_put_pixel(image, x+1, y, color);
+ if (x + 1 < width) {
+ if (pixels[(x + 1) + y * width] == color_start) {
+ pixels[(x + 1) + y * width] = color;
queue_enqueue(x+1, lista_xy);
queue_enqueue(y, lista_xy);
}
- }
-
- if (x-1 >= 0){
- if (gdk_image_get_pixel(image, x-1, y) == color_start){
- gdk_image_put_pixel(image, x-1, y, color);
+ }
+
+ if (x - 1 >= 0){
+ if (pixels[(x - 1) + y * width] == color_start) {
+ pixels[(x - 1) + y * width] = color;
queue_enqueue(x-1, lista_xy);
queue_enqueue(y, lista_xy);
}
}
- if (y+1 < height){
- if (gdk_image_get_pixel(image, x, y+1) == color_start){
- gdk_image_put_pixel(image, x, y+1, color);
+
+ if (y + 1 < height){
+ if (pixels[x + (y + 1) * width] == color_start) {
+ pixels[x + (y + 1) * width] = color;
queue_enqueue(x, lista_xy);
queue_enqueue(y+1, lista_xy);
}
}
- if (y-1 >= 0){
- if (gdk_image_get_pixel(image, x, y-1) == color_start){
- gdk_image_put_pixel(image, x, y-1, color);
+
+ if (y - 1 >= 0){
+ if (pixels[x + (y - 1) * width] == color_start){
+ pixels[x + (y - 1) * width] = color;
queue_enqueue(x, lista_xy);
queue_enqueue(y-1, lista_xy);
}
@@ -177,13 +175,6 @@ void fill(GdkDrawable *drawable, GdkGC *gc, int x, int y, int width, int height,
queue_dequeue(lista_xy);
}
}
- gdk_draw_image(drawable, gc, image, 0,0,0,0,width,height);
- if (image != NULL) {
- g_object_unref(image);
- printf("Imagem %x\n", image);
- } else {
- printf("Image = null\n");
- }
queue_destroy(lista_xy);
}