/* * Atpdec * Copyright (c) 2003 by Thierry Leconte (F4DWV) * * $Id$ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program 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 Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include #include #include #include #include #include extern getpixelrow(float *pixelv); static SNDFILE *inwav; static int initsnd(char *filename) { SF_INFO infwav; /* open wav input file */ infwav.format=0; inwav=sf_open(filename,SFM_READ,&infwav); if (inwav==NULL) { fprintf(stderr,"could not open %s\n",filename); return(1); } if(infwav.samplerate !=11025) { fprintf(stderr,"Bad Input File sample rate: %d. Must be 11025\n",infwav.samplerate); return(1); } if(infwav.channels !=1) { fprintf(stderr,"Too many channels in input file : %d\n",infwav.channels); return(1); } return(0); } int getsample(float *sample,int nb) { return(sf_read_float(inwav,sample,nb)); } png_text text_ptr[2]={ { PNG_TEXT_COMPRESSION_NONE, "Software", "Created by Thierry Leconte's atpdec",35 } }; static int ImageOut(char *filename,float **prow,int nrow,int width,int offset) { FILE *pngfile; png_infop info_ptr; png_structp png_ptr; int n; pngfile=fopen(filename,"w"); if (pngfile==NULL) { fprintf(stderr,"could not open %s\n",filename); return(1); } /* init png lib */ png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { fprintf(stderr,"could not open create png_ptr\n"); return(1); } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { png_destroy_write_struct(&png_ptr, (png_infopp)NULL); fprintf(stderr,"could not open create info_ptr\n"); return(1); } png_init_io(png_ptr,pngfile); png_set_IHDR(png_ptr, info_ptr, width, nrow, 8, PNG_COLOR_TYPE_GRAY, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_set_text(png_ptr, info_ptr, text_ptr, 1); printf("Writing %s\n",filename); png_write_info(png_ptr,info_ptr); for(n=0;n255) x=255; if(x<0) x=0; if(y>255) y=255; if(y<0) y=0; distrib[y][x]+=1; if(distrib[y][x]> max) max=distrib[y][x]; } } df=fopen(filename,"w"); fprintf(df,"P2\n#max %d\n",max); fprintf(df,"256 256\n255\n"); for(y=0;y<256;y++) for(x=0;x<256;x++) fprintf(df,"%d\n",(int)((255.0*(double)(distrib[y][x]))/(double)max)); fclose(df); } #endif extern int Calibrate(float **prow,int nrow,int offset); extern int optind,opterr; extern char *optarg; main(int argc, char **argv) { char pngfilename[1024]; char name[1024]; char *pngdirname=NULL; char imgopt[20]="abc"; float *prow[3000]; const char *chid[6]={ "1","2","3A","4","5","3B"}; int n,nrow; int ch; int c; opterr=0; while ((c=getopt(argc,argv,"c:d:i:"))!=EOF) { switch(c) { case 'd': pngdirname=optarg; break; case 'c': readcmap(optarg); break; case 'i': strcpy(imgopt,optarg); break; } } for(nrow=0;nrow<3000;nrow++) prow[nrow]=NULL; for (;optind0) { a=1; if(strchr(imgopt,(int)'a')!=NULL) { sprintf(pngfilename,"%s/%s-%s.png",pngdirname,name,chid[ch]); ImageOut(pngfilename,prow,nrow,954,85); } } } /* Channel B */ if(((strchr(imgopt,(int)'b')!=NULL) || (strchr(imgopt,(int)'c')!=NULL))) { ch=Calibrate(prow,nrow,1125); if(ch>0) { b=1; if(strchr(imgopt,(int)'b')!=NULL) { sprintf(pngfilename,"%s/%s-%s.png",pngdirname,name,chid[ch]); ImageOut(pngfilename,prow,nrow,954,1125); } } } #ifdef DEBUG sprintf(pngfilename,"%s/%s-d.pnm",pngdirname,name); Distrib(pngfilename,prow,nrow); #endif /* color image */ if(a && b && strchr(imgopt,(int)'c')!=NULL){ sprintf(pngfilename,"%s/%s-c.png",pngdirname,name); ImageColorOut(pngfilename,prow,nrow); } } exit (0); }