removed y from segments and fixed their pixel indexing
This commit is contained in:
parent
87dfa5b2a6
commit
d34e106a4f
@ -32,9 +32,8 @@ bool sameColor(Pixel* t_pixel, Zone* t_zone) {
|
|||||||
* \param[out] t_zone Zone à laquelle sera potentiellement ajouté le pixel
|
* \param[out] t_zone Zone à laquelle sera potentiellement ajouté le pixel
|
||||||
*/
|
*/
|
||||||
void addPixelToSelectedZone(Image* t_img, int t_idx, Zone* t_zone) {
|
void addPixelToSelectedZone(Image* t_img, int t_idx, Zone* t_zone) {
|
||||||
Pixel* current_pixel;
|
Pixel *current_pixel = darrayGet(t_img->pixels, t_idx);
|
||||||
int xd, xg, y = t_idx / (int)t_img->x;
|
int xd, xg, y = t_idx / (int)t_img->x;
|
||||||
current_pixel = darrayGet(t_img->pixels, t_idx);
|
|
||||||
if (current_pixel->visited || t_idx >= (int)darraySize(t_img->pixels) ||
|
if (current_pixel->visited || t_idx >= (int)darraySize(t_img->pixels) ||
|
||||||
t_idx < 0 || !sameColor(current_pixel, t_zone)) {
|
t_idx < 0 || !sameColor(current_pixel, t_zone)) {
|
||||||
return;
|
return;
|
||||||
@ -42,20 +41,20 @@ void addPixelToSelectedZone(Image* t_img, int t_idx, Zone* t_zone) {
|
|||||||
(*current_pixel).visited = true;
|
(*current_pixel).visited = true;
|
||||||
for(xd = t_idx; xd % (int)t_img->x != 0; ++xd) { /* fetch right limit of segment */
|
for(xd = t_idx; xd % (int)t_img->x != 0; ++xd) { /* fetch right limit of segment */
|
||||||
current_pixel = darrayGet(t_img->pixels, xd);
|
current_pixel = darrayGet(t_img->pixels, xd);
|
||||||
if(!sameColor(current_pixel, t_zone)) {
|
if(current_pixel->visited || !sameColor(current_pixel, t_zone)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(*current_pixel).visited = true;
|
(*current_pixel).visited = true;
|
||||||
}
|
}
|
||||||
for(xg = t_idx; xg - y >= 0; --xg) { /* fetch right limit of segment */
|
for(xg = t_idx; xg - y >= 0; --xg) { /* fetch right limit of segment */
|
||||||
current_pixel = darrayGet(t_img->pixels, xd);
|
current_pixel = darrayGet(t_img->pixels, xd);
|
||||||
if(!sameColor(current_pixel, t_zone)) {
|
if(current_pixel->visited || !sameColor(current_pixel, t_zone)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(*current_pixel).visited = true;
|
(*current_pixel).visited = true;
|
||||||
}
|
}
|
||||||
/* Add segment to its zone */
|
/* Add segment to its zone */
|
||||||
darrayPushBack(t_zone->segments, newSegment(y, xd, xg));
|
darrayPushBack(t_zone->segments, newSegment(xd, xg));
|
||||||
for(; xg <= xd; ++xg) { /* process every pixel up and down the segment */
|
for(; xg <= xd; ++xg) { /* process every pixel up and down the segment */
|
||||||
addPixelToSelectedZone(t_img, t_idx + t_img->x, t_zone);
|
addPixelToSelectedZone(t_img, t_idx + t_img->x, t_zone);
|
||||||
}
|
}
|
||||||
|
@ -80,10 +80,9 @@ void deleteImage(Image *t_self) {
|
|||||||
* \param[in] xg Abscisse extrême gauche du segment
|
* \param[in] xg Abscisse extrême gauche du segment
|
||||||
* \return Pointeur sur un conteneur de segment
|
* \return Pointeur sur un conteneur de segment
|
||||||
*/
|
*/
|
||||||
Segment *newSegment(uint16_t t_y, uint16_t t_xd, uint16_t t_xg) {
|
Segment *newSegment(uint16_t t_xd, uint16_t t_xg) {
|
||||||
Segment *res;
|
Segment *res;
|
||||||
res = (Segment *)malloc(sizeof(Segment));
|
res = (Segment *)malloc(sizeof(Segment));
|
||||||
res->y = t_y;
|
|
||||||
res->xd = t_xd;
|
res->xd = t_xd;
|
||||||
res->xg = t_xg;
|
res->xg = t_xg;
|
||||||
return res;
|
return res;
|
||||||
|
@ -98,7 +98,6 @@ struct Zone {
|
|||||||
* à son extrême droite et à son extrême gauche.
|
* à son extrême droite et à son extrême gauche.
|
||||||
*/
|
*/
|
||||||
struct Segment {
|
struct Segment {
|
||||||
uint16_t y; /*!< ligne du segment */
|
|
||||||
uint16_t xd; /*!< extrême droit du segment */
|
uint16_t xd; /*!< extrême droit du segment */
|
||||||
uint16_t xg; /*!< extrême gauche du segment */
|
uint16_t xg; /*!< extrême gauche du segment */
|
||||||
};
|
};
|
||||||
@ -116,7 +115,7 @@ Image *newImage();
|
|||||||
/// \brief Destructeur d’une image
|
/// \brief Destructeur d’une image
|
||||||
void deleteImage(Image *t_self);
|
void deleteImage(Image *t_self);
|
||||||
/// \brief Constructeur d’un segment de couleur unie
|
/// \brief Constructeur d’un segment de couleur unie
|
||||||
Segment *newSegment(uint16_t t_y, uint16_t t_xd, uint16_t t_xg);
|
Segment *newSegment(uint16_t t_xd, uint16_t t_xg);
|
||||||
/// \brief Destructeur d’un segment de couleur unie
|
/// \brief Destructeur d’un segment de couleur unie
|
||||||
void deleteSegment(Segment *t_self);
|
void deleteSegment(Segment *t_self);
|
||||||
/// \brief Constructeur de conteneur de zone
|
/// \brief Constructeur de conteneur de zone
|
||||||
|
Loading…
Reference in New Issue
Block a user