void I_checker(Image *img, Color c1, Color c2, int step) { int x,y; for(x=0;x<img->_width;x++) for(y=0;y<img->_height;y++) { int n_x = x/step; int n_y = y/step; if((n_x+n_y)%2==0) _plot(img,x,y,c1); else _plot(img,x,y,c2); } }
void draw_line_antialias_(GBitmap* img, int16_t x1, int16_t y1, int16_t x2, int16_t y2, GColor8 color) { uint8_t* img_pixels = gbitmap_get_data(img); int16_t w = gbitmap_get_bounds(img).size.w; int16_t h = gbitmap_get_bounds(img).size.h; fixed dx = int_to_fixed(abs_(x1 - x2)); fixed dy = int_to_fixed(abs_(y1 - y2)); bool steep = dy > dx; if(steep){ swap_(x1, y1); swap_(x2, y2); } if(x1 > x2){ swap_(x1, x2); swap_(y1, y2); } dx = x2 - x1; dy = y2 - y1; fixed intery; int x; for(x=x1; x <= x2; x++) { intery = int_to_fixed(y1) + (int_to_fixed(x - x1) * dy / dx); if(x>=0){ if(steep){ _plot(img_pixels, w, h, ipart_(intery) , x, color, rfpart_(intery)); _plot(img_pixels, w, h, ipart_(intery) + 1, x, color, fpart_(intery)); } else { _plot(img_pixels, w, h, x, ipart_(intery) , color, rfpart_(intery)); _plot(img_pixels, w, h, x, ipart_(intery) + 1, color, fpart_(intery)); } } } }
Image* I_read(char *imagefilename) { Image *img; char command[100]; if(_isPpm(imagefilename)) sprintf(command,"cp %s input.ppm",imagefilename); else sprintf(command,"convert %s input.ppm",imagefilename); int stat = system(command); if(stat!=0) { fprintf(stderr,"Convert : %s -> input.ppm impossible conversion.\n", imagefilename); exit(1); } else { Ppm ppm = PPM_nouv("input.ppm", PPM_LECTURE); system("rm input.ppm"); fprintf(stderr,"%d x %d\n",PPM_largeur(ppm),PPM_hauteur(ppm)); if(ppm!=NULL) { img = I_new(PPM_largeur(ppm),PPM_hauteur(ppm)); int nb_bits=ppm->_nb_bits; int valmax = ppm->_valmax; int nb_pixels = img->_width*img->_height; if(nb_bits <= 8) { unsigned char *donnees = (unsigned char*)calloc(3*nb_pixels,sizeof(unsigned char)); PPM_lectureDonneesChar(ppm, donnees); int x,y; for(y=0;y<img->_height;y++) for(x=0;x<img->_width;x++) { int indice = (img->_height-y)*img->_width + x; Color c = C_new((1.0*donnees[3*indice ])/valmax, (1.0*donnees[3*indice+1])/valmax, (1.0*donnees[3*indice+2])/valmax); _plot(img,x,y,c); } } else { unsigned short *donnees = (unsigned short*)calloc(3*nb_pixels,sizeof(unsigned short)); PPM_lectureDonneesShort(ppm, donnees); int x,y; for(y=0;y<img->_height;y++) for(x=0;x<img->_width;x++) { int indice = (img->_height-y)*img->_width + x; Color c = C_new((1.0*donnees[3*indice ])/valmax, (1.0*donnees[3*indice+1])/valmax, (1.0*donnees[3*indice+2])/valmax); img->_buffer[x][y] = c; } } PPM_fermeture(ppm); return(img); } else return(NULL); } }