added base for compressing function
This commit is contained in:
parent
07c5c1c28f
commit
33d8e8aac5
17
src/common.c
17
src/common.c
@ -1,4 +1,5 @@
|
||||
#include "common.h"
|
||||
#include "ppm.h"
|
||||
|
||||
bool sameColor(Pixel_t t_pixel, Zone_t t_zone) {
|
||||
return t_pixel->r == t_zone->r && t_pixel->g == t_zone->g &&
|
||||
@ -10,7 +11,7 @@ bool sameColor(Pixel_t t_pixel, Zone_t t_zone) {
|
||||
original as parts of the segment and add the segment itself to the zone */
|
||||
void addPixelToSelectedZone(Image_t t_img, int t_idx, Zone_t t_zone) {
|
||||
Pixel_t current_pixel;
|
||||
int xd, xg;
|
||||
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)) {
|
||||
@ -24,7 +25,7 @@ void addPixelToSelectedZone(Image_t t_img, int t_idx, Zone_t t_zone) {
|
||||
}
|
||||
(*current_pixel).visited = true;
|
||||
}
|
||||
for(xg = t_idx; xg % t_img->x >= 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);
|
||||
if(!sameColor(current_pixel, t_zone)) {
|
||||
break;
|
||||
@ -32,7 +33,7 @@ void addPixelToSelectedZone(Image_t t_img, int t_idx, Zone_t t_zone) {
|
||||
(*current_pixel).visited = true;
|
||||
}
|
||||
/* Add segment to its zone */
|
||||
darrayPushBack(t_zone->segments, newSegment(t_idx / t_img->x, xd, xg));
|
||||
darrayPushBack(t_zone->segments, newSegment(y, xd, xg));
|
||||
for(; xg <= xd; ++xg) { /* process every pixel up and down the segment */
|
||||
addPixelToSelectedZone(t_img, t_idx + t_img->x, t_zone);
|
||||
}
|
||||
@ -68,3 +69,13 @@ darray_t imgToZones(Image_t t_img) {
|
||||
}
|
||||
return zones;
|
||||
}
|
||||
|
||||
void compress(char *input_file) {
|
||||
Image_t img;
|
||||
darray_t zones;
|
||||
img = newImage();
|
||||
imageLoadPPM(input_file, img);
|
||||
zones = imgToZones(img);
|
||||
darrayDelete(zones);
|
||||
deleteImage(img);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user