1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
/*
* Conversion en format PPM*/
#include <string.h>
#include "image.h"
void extractPix(unsigned char* imgbuffer, int hauteur, int largeur, int num)
{
sprintf(nom_image,"Image_%.05d.ppm", num);
printf("nom_image = '%s'\n",nom_image);
fp = fopen(nom_image, "w");
if(fp==NULL)
{
printf("Impossible d'ouvrir le fichier\n");
exit(-1);
}
fprintf(fp, "P6\n%d %d\n255\n",largeur, hauteur);
p=1;
jDebut=1;
j = jDebut;
for(ligne=0;ligne<hauteur;ligne++)
{
if(ligne%2!=0)
j=jDebut;
else
jDebut=j;
for(colonne=0;colonne<largeur;colonne++)
{
b = 1.164*(imgbuffer[p]-16)+2.018*(imgbuffer[taille_totale+j]-128);p++;
g = 1.164*(imgbuffer[p]-16)-0.813*(imgbuffer[taille_totale+j]-128)-0.391*(imgbuffer[5*taille_totale/4+j]
r = 1.164*(imgbuffer[p]-16)+1.596*(imgbuffer[5*taille_totale/4+j]-128);
putc(r, fp);
putc(g, fp);
putc(b, fp);
if(colonne%2==0)
j++;
}
}
fflush(fp);
fclose(fp);
} |
Partager