rdimage

Capsim Block Documentation

Short Description

Read an image from a file.

Top
Parameters
Num Description Type Name Default Value
0 File that contains image file file_name stdin
Top
States
Num Type Name Initial Value Description
0 int obufs
1 FILE* fp
2 int width
3 int height
4 int numberRowsRead
Top

Declarations


 

	int i,j;
	float x;
	FILE *fopen();



Top

Initialization Code



 

	if(strcmp(file_name,"stdin") == 0)
		fp = stdin;
	else if((fp = fopen(file_name,"r")) == NULL) {
		fprintf(stderr,"rdimage: cannot open file\n");
		return(1); /* file cannot be opened */
	}
	if( (obufs = NO_OUTPUT_BUFFERS()) < 1 ) {
		fprintf(stderr,"rdimage: no output buffers\n");
		return(2);
	}
	fscanf(fp,"%d %d",&width,&height);
	fprintf(stderr,"Image width= %d, height = %d \n",width,height);
	numberRowsRead =0;




Top

Main Code



 


   	if(numberRowsRead >= height) return(0); 
	/* 
	 * output a row 
	 */
	for(i=0; i < width; ++i) {

		/* Read input lines until EOF */
		if(fscanf(fp,"%f",&x) == EOF)
			break;

		/* input sample available: 
		 *
		 * increment time on output buffer(s) 
		 * and output a sample 
		 */
		for(j=0; j
    
Top

Wrapup Code



 

        if (fp != stdout)
             fclose(fp);
        return(0);




Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/*************************************************************
			rdimage()
***************************************************************
Programmer: Sasan Ardalan
Date: November 4, 1990 

rdimage


Read an image from a file.


Programmer: Sasan Ardalan
Date: November 4, 1990 

*/