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

📄 image.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------+|									||   This material contains proprietary software of Entropic Speech,	||   Inc.  Any reproduction, distribution, or publication without the	||   prior written permission of Entropic Speech, Inc. is strictly	||   prohibited.  Any public distribution of copies of this work		||   authorized in writing by Entropic Speech, Inc. must bear the	||   notice								||									||         "Copyright (c) 1988, 1989, 1990 Entropic Speech, Inc.         ||                         All rights reserved."		                ||									|+-----------------------------------------------------------------------+|									||  Program: image.c							||									||  This program displays data from an ESPS file as a half-tone		||  gray-scale image.							||									||  Rodney W. Johnson, Entropic Speech, Inc.				||									|+----------------------------------------------------------------------*/#ifndef lintstatic char *sccs_id = "@(#)image.c	1.13 8/31/95 ESI";#endif#define VERSION "8/31/95"#define DATE "1.13"#include <stdio.h>#include <ctype.h>#include <esps/esps.h>#include <esps/unix.h>#include <esps/fea.h>#include <esps/feaspec.h>#include "image.h"#define REQUIRE(test,text) {if (!(test)) {(void) fprintf(stderr, \"%s: %s - exiting\n", ProgName, text); exit(1);}}#define SYNTAX \USAGE("image [-{ef} range]... [-l range][-o][-{prs} range][-t text]\n [-x debug_level][-A algorithm][-B scale][-C colormap][-D][-F function][-G range]\n [-L{prs}][-M mag][-P param][-S width[:height]][-T device][-V text] [-W geometry] file") \ ;/* Delete ; when esps.h fixed */#define DEF_FIELD "re_spec_val"#ifdef XWIN#define DEV_DEFAULT DEV_X11#else#define DEV_DEFAULT DEV_MCD#endif#define DATA_CHUNK 500double	log10(), log(), exp(), sqrt(), pow();void	lrange_switch();void	frange_switch();long	*grange_switch();long    get_fea_siz();long	get_fea_element();long	get_rec_len();char    *savestring();int	get_gen_recd();char	*get_cmd_line();char	*arr_alloc();void	addstr();long	*fld_range_switch();int	depth();int	(*read_cmap())[3];void	get_default_size();void	get_scale();void	set_margins();long	read_and_count();long	*fea_range();long	read_with_tag();void	put_with_tag();char	*allo_buf();void	reallo_data();void	interp(), pick_nearest();void	gain_adj();void	dev_init(), dev_fin();void	dot_init(), dot_row(), dot_fin();void	text();void	axes_and_titles();void	pr_larray();extern void	(*dev_plotline)();extern void	(*dev_initbits)();char	*ProgName = "image";char	*Version = VERSION;char	*Date = DATE;int	debug_level = 0;long	lmarg,	rmarg,	tmarg,	bmarg;	/* left, right, top, bottom margins */int	scale;long    width, height;	/* dimensions of pixel array */long    nrows, ncols;	/* width, height in default orientation;			   height, width in rotated orientation */int	oflag = NO;	/* -o option specified? */int	dev;		/* output device code */static char *devices[] = DEV_NAMES;int	alg;		/* halftone algorithm */static char *algorithms[] = HT_NAMES;int	fun;		/* preprocessing function */static char *functions[] = FN_NAMES;int	Dflag = NO;	/* -D option specified? */int 	Mflag = NO;	/* -M option specified? */int	mag = 1;	/* pixel magnification */int	gray_bits;	/* number of bits gray-scale resolution required */int	Bflag = NO;	/* B option specified? */int	(*cmap)[3];	/* array of RGB triples */int	cmap_len;	/* number of colormap entries */int	Lflag = NO;	/* -L option specified? */char	lbl_units;	/* mark axis in samples, records, or seconds? */long    startrec;	/* first record to plot */long    endrec;		/* last record to plot */double  src_sf;		/* sampling freq. of source sampled data --			 * used in relating tags to times.			 */int	src_sf_def = NO;/* have valid value for src_sf? */double  start_time;	/* starting time of file */double  record_freq;	/* record freq of source file --			 * used in relating record numbers to times.			 */int	rec_fr_def = NO;/* have valid value for record_freq? */long    *elem_array;	/* numbers of record elements to display */int	Gflag = NO;double	gainlolim, gainhilim;int	pwr_flag = NO;	/* convert FEA_SPEC data to power */int	spectype;float   **data;		/* data array */long    data_size;	/* number of data array rows allocated */long    data_dim[2];	/* dimensions of chunk of data array */double  *x, *y;		/* row and col coordinates of data array */double	xmin, xmax;	/* coords of ends of axis */long    nrecs;		/* number of records to plot */long    nelem;		/* number of elements to plot in each record */double  zmin, zmax;	/* limits of data range for full gray-scale */char    *h_ttl_text;	/* text string for labeling horizontal axis */char    *v_ttl_text;	/* text string for labeling vertical axis */char    *geometry;      /* holds geomtry string from command line(imdevx11.c)*/int     Wflag = 0;      /* W option flag (imdevx11.c)*/int	Argc;		/* make available in imdevx11.c */char	**Argv;		/* make available in imdevx11.c *//* * MAIN PROGRAM */main(argc, argv)    int  argc;    char **argv;{    extern int	    optind;		/* for use of getopt() */    extern char	    *optarg;		/* for use of getopt() */    int	    ch;			/* command-line option letter */    int	    eflag = NO;		/* -e option specified? */    char    *erange = NULL;	/* element range ("grange" form) */    char    **fea_fields;	/* field specification given with -e */    int	    nfld = 0;		/* number of named feature fields */    int	    lflag = NO;		/* -l option specified? */    char    *lrange;		/* data range for full gray-scale */    int	    pflag = NO;		/* -p option specified? */    char    *prange;		/* range of tags to plot */    long    starttag;		/* first tag to plot */    long    endtag;		/* last tag to plot */        int	    rflag = NO;		/* -r option specified? */    char    *rrange;		/* range of records to plot */    int	    sflag = NO;		/* -s option specified? */    char    *srange;		/* range of times to plot */    double  starttim;		/* first time to plot */    double  endtim;		/* last time to plot */        int	    tflag = NO;		/* -t option specified? */    int	    Aflag = NO;		/* -A option specified? */    int	    Cflag = NO;		/* -C option specified? */    char    *cmap_filename;	/* name of colormap file */    int	    Fflag = NO;		/* -F option specified? */    char    *param_name = NULL;				/* parameter file name */    int	    Sflag = NO;		/* -S option specified? */    char    *Srange;		/* arguments to -S option */    int	    Tflag = NO;		/* -T option specified? */    int	    Vflag = NO;		/* -V option specified? */    char    *iname;		/* input file name */    FILE    *ifile;		/* input stream */    struct header	    *ihd;		/* input file header */    double  datamin, datamax;	/* max and min data values */    long    i, j;		/* data indices *//* make argc and argv available in imdevx11.c */    Argc = argc;    Argv = argv;/* Parse command-line arguments */    fea_fields = (char **) malloc(sizeof(char *));    spsassert(fea_fields, "can't allocate space for field name list");    fea_fields[0] = NULL;    while ((ch = getopt(argc, argv, "e:f:l:op:r:s:t:x:A:B:C:DF:G:L:M:P:S:T:V:W:")) != EOF)	switch (ch)	{	case 'e':	case 'f':	    eflag = YES;	    if (isalpha(optarg[0]))	    {		nfld++;		addstr(optarg, &fea_fields);	    }	    else erange = optarg;	    break;	case 'l':	    lflag = YES;	    lrange = optarg;	    break;	case 'o':	    oflag = YES;	    break;	case 'p':	    pflag = YES;	    prange = optarg;	    break;	case 'r':	    rflag = YES;	    rrange = optarg;	    break;	case 's':	    sflag = YES;	    srange = optarg;	    break;	case 't':	    tflag = YES;	    h_ttl_text = optarg;	    break;	case 'x':	    debug_level = atoi(optarg);	    break;	case 'A':	    Aflag = YES;	    alg = lin_search2(algorithms, optarg);	    break;	case 'B':	    Bflag = YES;	    scale = atoi(optarg);	    break;	case 'C':	    Cflag = YES;	    cmap_filename = optarg;	    break;	case 'D':	    Dflag = YES;	    break;	case 'F':	    Fflag = YES;	    fun = lin_search2(functions, optarg);	    break;	case 'G':	    Gflag = YES;	    frange_switch(optarg, &gainlolim, &gainhilim);	    break;	case 'L':	    Lflag = YES;	    lbl_units = *optarg;	    break;	case 'M':	    Mflag = YES;	    mag = atoi(optarg);	    break;	case 'P':	    param_name = optarg;	    break;	case 'S':	    Sflag = YES;	    Srange = optarg;	    break;	case 'T':	    Tflag = YES;    	    dev = lin_search2(devices, optarg);	    break;	case 'V':	    Vflag = YES;	    v_ttl_text = optarg;	    break;        case 'W':	    Wflag++;	    geometry = optarg;	    break;	default:	    SYNTAX	    break;	}/* Process file name and open file. */    if (argc - optind > 1)    {	Fprintf(stderr,	    "%s: too many file names specified.\n", ProgName);	SYNTAX    }    if (argc - optind < 1)    {	Fprintf(stderr,	    "%s: no input file name specified.\n", ProgName);	SYNTAX    }    iname = eopen(ProgName, argv[optind], "r", NONE, NONE, &ihd, &ifile);    if (debug_level)	Fprintf(stderr, "Input file: %s\n", iname);/* Consistency checks */    REQUIRE(pflag + rflag + sflag <= 1,		"only one of -p, -r, and -s may be used at one time");    REQUIRE(nfld == 0 || ihd->common.type == FT_FEA,		"named fields allowed only with FEA files");    REQUIRE(nfld == 0 || erange == NULL,		"if any -e option argument has a field name, all must.");/* Get parameter values. */    (void) read_params(param_name, SC_NOCOMMON, (char *) NULL);    if (!Fflag)    {	if (symtype("function") != ST_UNDEF)	{	    fun = lin_search2(functions, getsym_s("function"));	    Fflag = YES;	}	else	    fun = NONE;    }    switch (fun)    {    case NONE:    case FN_LOG:    case FN_EXP:    case FN_SQ:    case FN_SQRT:	break;    default:	Fprintf(stderr, "%s: unrecognized function name.\n",		ProgName);	exit(1);	break;    }    if (eflag && nfld == 0)    {	REQUIRE(!is_file_complex(ihd),	"-e[grange] not supported with complex files\n - real FEA fields may be specified by name\n");	elem_array = grange_switch(erange, &nelem);    }    else    if (!eflag && symtype("elements") != ST_UNDEF)    {	int	*elems = malloc_i((unsigned) get_rec_len(ihd));	spsassert(elems,	    "can't allocate space for element array from symbol table");	nelem = getsym_ia("elements", elems, (int) get_rec_len(ihd));	spsassert(nelem,	    "can't get \"elements\" parameter--may be too long");	REQUIRE(!is_file_complex(ihd),	"\"elements\" parameter not supported with complex files\n - real FEA fields may be specified by name\n");	elem_array = malloc_l((unsigned) nelem);	spsassert(elem_array,	    "can't allocate space for array of element numbers");	for (i = 0; i < nelem; i++)	    elem_array[i] = elems[i];	free((char *) elems);    }    else    {	switch (ihd->common.type)	{	case FT_FEA:	    if (ihd->hd.fea->fea_type == FEA_SPEC && !eflag)	    {		pwr_flag = YES;		REQUIRE(genhd_type("spec_type", (int *) NULL, ihd) == CODED,			"header item \"spec_type\" undefined or not CODED");		spectype = *get_genhd_s("spec_type", ihd);		switch (spectype)		{		case SPTYP_PWR:		case SPTYP_DB:		case SPTYP_REAL:		case SPTYP_CPLX:		    break;		default:		    Fprintf(stderr, "%s: unknown spectral type\n", ProgName);		    exit(1);		    break;		}		if (!Fflag) fun = FN_LOG;		REQUIRE(genhd_type("num_freqs", (int *) NULL, ihd) == LONG,			"header item \"num_freqs\" undefined or not LONG");		nelem = *get_genhd_l("num_freqs", ihd);	    }	    else	    {		if (!eflag)		{		    nfld = 1;		    addstr(DEF_FIELD, &fea_fields);		}		elem_array = fea_range(fea_fields, ihd, &nelem);		break;	    }	    break;	default:	    Fprintf(stderr,		"%s: use -e[grange] option unless file is FEA file.\n",		ProgName);	    exit(1);	    break;	}    }    if (!pwr_flag && debug_level > 1)    {	fprintf(stderr, "%ld elements:\n", nelem);	pr_larray("elements", nelem, elem_array);    }    if (!Lflag && symtype("label_units") != ST_UNDEF)    {	Lflag = YES;	lbl_units = getsym_c("label_units");    }    if (Lflag)	switch (lbl_units)	{	case 'p':	case 'r':	case 's':	    break;	default:	    Fprintf(stderr,		    "%s: axis label units must be given as p, r, or s.\n",		    ProgName);	    exit(1);	}    else if (pflag) lbl_units = 'p';    else if (rflag) lbl_units = 'r';    else if (sflag) lbl_units = 's';    else lbl_units = 'r';    if (pflag || lbl_units == 'p')	REQUIRE(ihd->common.tag,		"-p option or axis labeling in points requires tagged file");	    if (sflag || lbl_units == 's')    {	if (ihd->common.tag	    && ((src_sf = get_genhd_val("src_sf", ihd, 0.0)) != 0.0		|| (ihd->common.type == FT_FEA		    && ihd->hd.fea->fea_type == FEA_SPEC		    && (src_sf = get_genhd_val("sf", ihd, 0.0)) != 0.0)))	{	    start_time = 0.0;	    src_sf_def = YES;	}	else if ((record_freq = get_genhd_val("record_freq", ihd, 0.0)) != 0.0)	{	    start_time = get_genhd_val("start_time", ihd, 0.0);	    rec_fr_def = YES;	}	REQUIRE(src_sf_def || rec_fr_def,		"-s option or axis labeling in seconds\n\trequires nonzero sampling or record frequency.");    }    if (pflag)    {	starttag = 1;	endtag = LONG_MAX;	lrange_switch(prange, &starttag, &endtag, 0);	REQUIRE(starttag >= 1, "initial tag not positive");	REQUIRE(starttag < endtag, "initial tag not less than final tag");	if (debug_level > 1)	    Fprintf(stderr, "Initial and final tags from -p: %d, %d\n",		    starttag, endtag);    }    else    if (rflag)    {    	startrec = 1;	endrec = LONG_MAX;	lrange_switch(rrange, &startrec, &endrec, 0);	REQUIRE(startrec >= 1, "initial record number not positive");	REQUIRE(startrec < endrec,	    "initial record number not less than final record number");	if (debug_level > 1)	    Fprintf(stderr,		"inital and final record numbers from -r: %d, %d\n",		 startrec, endrec);    }    else    if (sflag)    {	starttim = start_time;	endtim =

⌨️ 快捷键说明

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