Doxygen Source Code Documentation
ppmtocmap.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Defines | |
#define | MAXCOL 255 |
#define | ASP(x, y) ( (x)[0]=(y)[0] , (x)[1]=(y)[1] , (x)[2]=(y)[2] ) |
#define | EQP(x, y) ( (x)[0]==(y)[0] && (x)[1]==(y)[1] && (x)[2]==(y)[2] ) |
Functions | |
int | main (int argc, char *argv[]) |
Variables | |
byte | rgb [3 *MAXCOL] |
int | ncol = 0 |
Define Documentation
|
Definition at line 13 of file ppmtocmap.c. Referenced by main(). |
|
Definition at line 14 of file ppmtocmap.c. Referenced by main(). |
|
Definition at line 9 of file ppmtocmap.c. Referenced by main(). |
Function Documentation
|
\** File : SUMA.c
Input paramters :
Definition at line 16 of file ppmtocmap.c. References argc, ASP, EQP, MAXCOL, MRI_BYTE_PTR, mri_new(), mri_read_ppm(), MRI_RGB_PTR, ncol, MRI_IMAGE::nvox, MRI_IMAGE::nx, and MRI_IMAGE::ny.
00017 { 00018 int makemap , iarg , ii,jj ; 00019 char * mapfile = NULL ; 00020 MRI_IMAGE * mapim = NULL , * ppmim = NULL , * qqim = NULL ; 00021 byte * ppmar , * mapar , * qqar ; 00022 00023 if( argc < 2 || strncmp(argv[1],"-help",5)==0 ){ 00024 printf("Usage 1: Make a map of the colors in a ppm raw file\n" 00025 " ppmtocmap -make ppmfile\n" 00026 "\n" 00027 "Usage 2: Make a color mapped pgm file from a map and a raw ppm file\n" 00028 " ppmtocmap -map mapfile ppmfile\n" 00029 "\n" 00030 "Both usages write to stdout.\n" 00031 ) ; 00032 exit(0) ; 00033 } 00034 00035 iarg = 1 ; 00036 if( strncmp(argv[1],"-make",5) == 0 ){ 00037 makemap = 1 ; iarg++ ; 00038 } else if( strncmp(argv[1],"-map",4) == 0 ){ 00039 makemap = 0 ; iarg++ ; 00040 if( iarg >= argc ){ fprintf(stderr,"No file after -map\n") ; exit(1) ; } 00041 mapfile = argv[iarg++] ; 00042 mapim = mri_read_ppm( mapfile ) ; 00043 if( mapim == NULL ){fprintf(stderr,"Can't read -map file %s\n",mapfile);exit(1);} 00044 mapar = MRI_RGB_PTR(ppmim) ; 00045 } else { 00046 fprintf(stderr,"Illegal first switch: %s\n",argv[1]) ; 00047 exit(1) ; 00048 } 00049 00050 if( iarg >= argc ){ fprintf(stderr,"No input ppmfile?\n") ; exit(1) ; } 00051 00052 ppmim = mri_read_ppm( argv[iarg] ) ; 00053 if( ppmim == NULL ){fprintf(stderr,"Can't read ppmfile %s\n",argv[iarg]);exit(1);} 00054 ppmar = MRI_RGB_PTR(ppmim) ; 00055 00056 qqim = (makemap) ? ppmim : mapim ; 00057 qqar = MRI_RGB_PTR(qqim) ; 00058 00059 ASP( rgb , qqar ) ; ncol = 1 ; 00060 for( ii=1 ; ii < qqim->nvox ; ii++ ){ 00061 for( jj=0 ; jj < ncol ; jj++ ) 00062 if( EQP(rgb+3*jj,qqar+3*ii) ) break ; 00063 00064 if( jj == ncol ){ 00065 ASP( rgb+3*ncol , qqar+3*ii ) ; 00066 ncol++ ; 00067 if( ncol > MAXCOL ){ 00068 fprintf(stderr,"More than %d colors at pixel %d\n",MAXCOL,ii) ; 00069 exit(1) ; 00070 } 00071 } 00072 } 00073 fprintf(stderr,"found %d colors\n",ncol) ; 00074 00075 if( makemap ){ 00076 printf("P6 %d 1 255\n" , ncol ) ; 00077 fwrite( rgb , 1 , 3*ncol , stdout ) ; 00078 exit(0) ; 00079 } 00080 00081 qqim = mri_new( ppmim->nx , ppmim->ny , MRI_byte ) ; 00082 qqar = MRI_BYTE_PTR(qqim) ; 00083 00084 for( ii=0 ; ii < ppmim->nvox ; ii++ ){ 00085 for( jj=0 ; jj < ncol ; jj++ ) 00086 if( EQP(rgb+3*jj,ppmar+3*ii) ) break ; 00087 00088 if( jj < ncol ) qqar[ii] = jj ; 00089 else { fprintf(stderr,"Unmatched color at pixel %d\n",ii) ; exit(1) ; } 00090 } 00091 00092 printf("P5 %d %d 255\n" , ppmim->nx , ppmim->ny ) ; 00093 fwrite( qqar , 1 , ppmim->nx * ppmim->ny , stdout ) ; 00094 exit(0) ; 00095 } |
Variable Documentation
|
|
Definition at line 10 of file ppmtocmap.c. |