Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

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

#define ASP x,
y       ( (x)[0]=(y)[0] , (x)[1]=(y)[1] , (x)[2]=(y)[2] )
 

Definition at line 13 of file ppmtocmap.c.

Referenced by main().

#define EQP x,
y       ( (x)[0]==(y)[0] && (x)[1]==(y)[1] && (x)[2]==(y)[2] )
 

Definition at line 14 of file ppmtocmap.c.

Referenced by main().

#define MAXCOL   255
 

Definition at line 9 of file ppmtocmap.c.

Referenced by main().


Function Documentation

int main int    argc,
char *    argv[]
 

\** File : SUMA.c

Author:
: Ziad Saad Date : Thu Dec 27 16:21:01 EST 2001
Purpose :

Input paramters :

Parameters:
param  Usage : SUMA ( )
Returns :
Returns:
Support :
See also:
OpenGL prog. Guide 3rd edition , varray.c from book's sample code
Side effects :

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

int ncol = 0
 

Definition at line 11 of file ppmtocmap.c.

Referenced by AFNI_plugin_button(), color_(), colormap_image_posterize(), CREN_set_rgbmap(), decode_linebuf(), ensure_slot_255(), get_color_table_size(), hash_color(), histogram(), main(), MAIN__(), mark_used_colors(), MCW_choose_string(), MCW_new_DC(), merge_image(), MREN_set_rgbmap(), mri_quantize(), mri_read_ascii(), mri_read_ascii_ragged(), prepare_colormap_map(), read_glt_matrix(), read_image(), read_logical_screen_descriptor(), read_text_colormap(), SUMA_cmap_wid_input(), SUMA_M2M_interpolate(), SUMA_MaskedCopyofDset(), SUMA_OpenDrawnROI_1D(), SUMA_Read_IRGB_file(), SUMA_readFScurv(), SUMA_ReadSegDO(), and write_color_table().

byte rgb[3*MAXCOL]
 

Definition at line 10 of file ppmtocmap.c.

 

Powered by Plone

This site conforms to the following standards: