//*************************************// //******** created by mamo139 *********// //*** http://mamo139.altervista.org ***// //*************************************// #include #include #include #include //*** strumenti gestione file bmp ***// char *** crea_bmp(char *nome, long x, long y); void disegna_bmp(char *nome, char *** array, long x, long y); //*** strumenti gestione colori ***// struct rgb { int red; int green; int blue; }; struct rgb_d { double red; double green; double blue; }; struct hsv { int hue; int saturation; int value; }; struct rgb hsv_rgb(struct hsv hsv_map); //*** MAIN ***// int main (void){ char nomefiledb[100]; printf("nome del database (la matrice deve essere quadrata):"); scanf("%s",nomefiledb); printf("lettura file: %s!\n",nomefiledb); getchar(); long x,y,d,i; FILE * st; st = fopen(nomefiledb,"rb"); fseek(st,0,SEEK_END); long filesize = ftell(st); rewind(st); long numero_dati=0, altezza, larghezza; char * number; number = (char *) malloc (100 * sizeof(char)); char * buffer; buffer = (char *) malloc (filesize * sizeof(char)); long readed = fread(buffer,1,filesize,st); rewind(st); printf("filesize: %d letto:%d\n",filesize,readed); for(x=0;x255) d=255; colore = d; /* rgb.blue = colore; rgb.green = colore; rgb.red = colore; */ hsv.hue = (int) 300-colore; hsv.saturation = 200; hsv.value = colore; rgb = hsv_rgb(hsv); //controllo punto dell'insieme di mendelbrot if(d==0) { matrice[x][y][0]=0; matrice[x][y][1]=0; matrice[x][y][2]=0; } else { //scrittura del colore matrice[x][y][0]=rgb.blue; //blu: colore matrice[x][y][1]=rgb.green; //verde: comportamento opposto al blu matrice[x][y][2]=rgb.red; //rosso: costante } } //printf("%d%%\n",x*100/larghezza); } printf("Fine ciclo di disegno.\n\nScrittura file in corso...\n"); disegna_bmp(image_name,matrice,larghezza,altezza); printf("fine!"); system(image_name); //getchar(); return 0; } //****** FUNZIONI *******// char *** crea_bmp(char *nome, long x, long y){ FILE *stream, *cavia; stream = fopen(nome,"wb"); cavia = fopen("cavia","rb"); char *buffer; buffer = (char *)malloc(54 * sizeof(char)); long b = fread( buffer, 1, 54, cavia); buffer[18] = x%256;//asse x buffer[19] = x/256; buffer[22] = y%256;//asse y buffer[23] = y/256; fwrite(buffer, 1, b, stream); fclose(stream); char *** array; int i, j, h; array = (char***)malloc(x * sizeof(char *)); for(i=0; i=0; i2--) for(i1=0; i1