⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 module_p.c

📁 code c++ qui r茅alise la squelettisation d une image
💻 C
字号:
/* module_p.c */
/* 24/10/95 */
/********************************************************************/
/*                     L E C T U R E - P P M . C                    */
/*                    jean.fruitet@univ-mlv                         */
/*------------------------------------------------------------------*/

/* -------------------------------------------------------------------*/
/* Un fichier PPM RAW binaire est constitute d'une entete :

P6\n# CREATOR: XV Version 3.00  Rev: 3/30/93\n320 280\n255

et des donnees :
R V B R V B ... avec R, V, B valeurs de 0..255 de chaque pixel

Pour passer du format PPM au format 1 octet par pixel pour squelettiser
l'image 
l'algorithme consiste a convertir chaque triplet en une valeur de 0..255
en recuperant 3 bits Rouge, 3 bits Vert et 2 bits bleu
Dans un deuxieme temps l'image ainsi obtenue est seuillee et 
binarisee...
*/
#define LONGENTETE 56  /* Longueur de l'entete PPM */
#define ENTETE_PPM "P6\n# CREATOR: XV Version 3.00 Rev: 3/30/93\n"
#define ENTETE_PPM2 "255\n"
char strprogppm[4];
char strcreatorppm[80];
char strligcolppm[12];
char strnbcoulppm[4];

/* ************ Prototypes de fonctions */

unsigned char lut(unsigned char r, unsigned char v, unsigned char b);
void  lire_entete_ppm(  FILE *f_in,  int *lig,  int *col);
void  ecrire_entete_ppm(FILE *f_out,  int lig,  int col);


/* ********************* Sources ************************* */
/* --------------------------------------------------------*/
unsigned char lut(unsigned char r, unsigned char v, unsigned char b)
/* Calcule une couleur 255 a partir de 3 composantes RVB
   en gardant 3 bits pour R et V et 2 bits pour B */
{
	return (unsigned char)((r/32)*32+(v/32)*4+b/64);
}

/* --------------------------------------------------------*/
void  lire_entete_ppm(  FILE *f_in,  int *lig,  int *col)
/* retourne les chaines strppm initialisees et le nombre de lignes
 et colonnes d'image*/
{
char strppm[80];
int ok=0;
int encore=0;
fgets ( strprogppm,4, f_in);
fgets ( strcreatorppm, 80, f_in);
do {
  fgets ( strppm, 80, f_in);
  ok=sscanf(strppm, "%d %d", col, lig); 
  encore++;
} while ((ok!=2) && (encore<=4));

if ( ok==2)
{
   fgets ( strnbcoulppm, 4,  f_in);
   printf("\nProg: %s Creat: %s\tLig:%d Col:%d\tCoul: %s\n", strprogppm, strcreatorppm, *lig,  *col, strnbcoulppm);
}
else
   {
	printf("Erreur de fichier entete \n");	
	exit(0);	
   }
}

/* --------------------------------------------------------*/
void  ecrire_entete_ppm(FILE *f_out,  int lig,  int col)
/* ecrit une entete de fichier ppm ligxcol ncoul */
{
char strppm[80];
sprintf (strppm,"%s%s%d %d\n%s\n",strprogppm, strcreatorppm, lig, col, strnbcoulppm);
fwrite(strppm,sizeof(char),strlen(strppm), f_out);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -