From a8b16be07dfc9fe5899c7a5108a12afc3670adf3 Mon Sep 17 00:00:00 2001 From: Phuntsok Drak-pa Date: Mon, 17 Dec 2018 14:50:01 +0100 Subject: [PATCH] some comments --- src/compress.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compress.c b/src/compress.c index 32877db..319725c 100644 --- a/src/compress.c +++ b/src/compress.c @@ -59,15 +59,18 @@ void addPixelToSelectedZone(Image *t_img, int64_t t_idx, Zone *t_zone) { const uint32_t y = (uint32_t)(t_idx / t_img->sizeX); int64_t left_limit, right_limit; const int64_t xd_limit = (int64_t)t_img->sizeX * (y + 1); - if (t_idx >= (int64_t)img_size || t_idx < 0) { + if (t_idx >= (int64_t)img_size || t_idx < 0) { /* Pixel in range? */ return; } current_pixel = darrayGet(t_img->pixels, (size_t)t_idx); + + /* Pixel already visited or of the right color? */ if (current_pixel->visited || !sameColor(current_pixel, t_zone)) { return; } (*current_pixel).visited = 1; + /* right limit */ for (right_limit = t_idx; right_limit < xd_limit; ++right_limit) { current_pixel = darrayGet(t_img->pixels, (size_t)right_limit); if (!sameColor(current_pixel, t_zone)) { @@ -75,6 +78,7 @@ void addPixelToSelectedZone(Image *t_img, int64_t t_idx, Zone *t_zone) { } current_pixel->visited = 1; } + /* left limit */ for (left_limit = t_idx; left_limit - (y - 1) * (int64_t)t_img->sizeX >= 0; --left_limit) { current_pixel = darrayGet(t_img->pixels, (size_t)left_limit); @@ -86,9 +90,11 @@ void addPixelToSelectedZone(Image *t_img, int64_t t_idx, Zone *t_zone) { darrayPushBack(t_zone->segments, newSegment((uint32_t)right_limit, (uint32_t)left_limit)); + /* for each pixel of the segment, test the pixel above */ for (; left_limit <= right_limit; ++left_limit) { addPixelToSelectedZone(t_img, t_idx + t_img->sizeX, t_zone); } + /* for each pixel of the segment, test the pixel below */ for (; left_limit <= right_limit; ++left_limit) { addPixelToSelectedZone(t_img, t_idx - t_img->sizeX, t_zone); }