removed y from segments and fixed their pixel indexing

This commit is contained in:
Phuntsok Drak-pa 2018-11-23 10:32:49 +01:00
parent 87dfa5b2a6
commit d34e106a4f
No known key found for this signature in database
GPG Key ID: 9CB34B6827C66D22
3 changed files with 6 additions and 9 deletions

View File

@ -32,9 +32,8 @@ bool sameColor(Pixel* t_pixel, Zone* t_zone) {
* \param[out] t_zone Zone à laquelle sera potentiellement ajouté le pixel
*/
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;
current_pixel = darrayGet(t_img->pixels, t_idx);
if (current_pixel->visited || t_idx >= (int)darraySize(t_img->pixels) ||
t_idx < 0 || !sameColor(current_pixel, t_zone)) {
return;
@ -42,20 +41,20 @@ void addPixelToSelectedZone(Image* t_img, int t_idx, Zone* t_zone) {
(*current_pixel).visited = true;
for(xd = t_idx; xd % (int)t_img->x != 0; ++xd) { /* fetch right limit of segment */
current_pixel = darrayGet(t_img->pixels, xd);
if(!sameColor(current_pixel, t_zone)) {
if(current_pixel->visited || !sameColor(current_pixel, t_zone)) {
break;
}
(*current_pixel).visited = true;
}
for(xg = t_idx; xg - y >= 0; --xg) { /* fetch right limit of segment */
current_pixel = darrayGet(t_img->pixels, xd);
if(!sameColor(current_pixel, t_zone)) {
if(current_pixel->visited || !sameColor(current_pixel, t_zone)) {
break;
}
(*current_pixel).visited = true;
}
/* 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 */
addPixelToSelectedZone(t_img, t_idx + t_img->x, t_zone);
}

View File

@ -80,10 +80,9 @@ void deleteImage(Image *t_self) {
* \param[in] xg Abscisse extrême gauche du 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;
res = (Segment *)malloc(sizeof(Segment));
res->y = t_y;
res->xd = t_xd;
res->xg = t_xg;
return res;

View File

@ -98,7 +98,6 @@ struct Zone {
* à son extrême droite et à son extrême gauche.
*/
struct Segment {
uint16_t y; /*!< ligne du segment */
uint16_t xd; /*!< extrême droit du segment */
uint16_t xg; /*!< extrême gauche du segment */
};
@ -116,7 +115,7 @@ Image *newImage();
/// \brief Destructeur dune image
void deleteImage(Image *t_self);
/// \brief Constructeur dun 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 dun segment de couleur unie
void deleteSegment(Segment *t_self);
/// \brief Constructeur de conteneur de zone