Mercurial > hg > aim92
view saitools/changeheader.c @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
line wrap: on
line source
/* Copyright (c) Applied Psychology Unit, Medical Research Council. 1993 =========================================================================== Permission to use, copy, modify, and distribute this software without fee is hereby granted for research purposes, provided that this copyright notice appears in all copies and in all supporting documentation, and that the software is not redistributed for any fee (except for a nominal shipping charge). Anyone wanting to incorporate all or part of this software in a commercial product must obtain a license from the Medical Research Council. The MRC makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* ------------------------------------------------------------------------*/ /* changeheader.c * ---------------- * * 'fakes' sai & nap headers. * * M.Akeroyd. Summer 1993. Revised 1994. */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include "tip.h" void reset_header_bytes(); void change_framebytes(); extern char progname[MAX_STRING_LENGTH]; extern char header[MAX_LINES_HEADER][MAX_LINE_LENGTH]; extern int verboseflag; extern int header_lines; /* number of lines in header */ /* .nap parameters */ extern int no_frames; extern int frameheight; /* number of channels */ extern int framewidth_samples; /* = 1 extern int frameshift_samples; /* = 1 */ extern int width_win; /* pixels */ extern int height_win; /* pixels */ extern long samplerate; /* samples per sec */ extern int mincf; /* Hz */ extern int maxcf; /* Hz */ extern int greyscaleflag; /* ON or OFF */ /* ------------------------------------------------------------------------*/ void changeheader(int no_frames, int new_pwidth, int new_nwidth, int framewidth_samples_output) { /* Reset various values: * * number of frames -> no_frames * pwidth -> new_pwidth * nwidth -> new_nwidth * framewidth -> (pwidth+nwidth * samplerate). in msecs * header_bytes * */ int new_header_length = 0; int counter; char tempstring[MAX_STRING_LENGTH]; char tempstring2[MAX_STRING_LENGTH]; /*-------------------------------- */ for(counter=1; counter<=header_lines; counter++){ /* frames */ if (strncmp(header[counter], "frames=", 7) == 0 ) { sprintf(header[counter], "frames=%d\n", no_frames);} /* pwidth */ if (strncmp(header[counter], "pwidth_aid=", 11) == 0 ) sprintf(header[counter], "pwidth_aid=%d\n", new_pwidth); /* nwidth */ /* include a gratuitous minus */ if (strncmp(header[counter], "nwidth_aid=", 11) == 0 ) if (new_nwidth < 0) sprintf(header[counter], "nwidth_aid=%d\n", new_nwidth); else sprintf(header[counter], "nwidth_aid=-%d\n", new_nwidth); /* framewidth */ if (strncmp(header[counter], "framewidth=", 11) == 0 ) sprintf(header[counter], "framewidth=%d\n", framewidth_samples_output); /*view=landscape */ if (greyscaleflag == ON) if (strncmp(header[counter], "view=landscape", 14) == 0 ) sprintf(header[counter], "view=greyscale\n"); } /* reset framebytes */ change_framebytes(); /* reset header */ reset_header_bytes; } /* ------------------------------------------------------------------------*/ void change_framebytes() { /* This is seperate beacuse it depends on lots of things * framebytes -> frameheight * framewidth *2 (bytes), I hope. */ int counter; char *p_equal=" "; /* pointer to where the '=' is in the headerline */ char tempstring[MAX_STRING_LENGTH]; int local_frameheight = 0; int local_framewidth = 0; /* find out the values */ for(counter=1; counter<=header_lines; counter++) { if (strncmp(header[counter], "frameheight=", 12) == 0 ) { p_equal = strchr(header[counter], '='); local_frameheight = atoi(++p_equal); } if (strncmp(header[counter], "framewidth=", 11) == 0 ) { p_equal = strchr(header[counter], '='); local_framewidth = atoi(++p_equal); }} /* put in new value */ for(counter=1; counter<=header_lines; counter++){ if (strncmp(header[counter], "framebytes=", 11) == 0 ) sprintf(header[counter], "framebytes=%d\n", (local_framewidth * local_frameheight *2)); } } /* ------------------------------------------------------------------------*/ void reset_header_bytes() { /* What this code does: * * My latest attempt to get the "header_bytes" field to be set to the * right number, well, one that AIM accepts. * * At the moment, it assumes * (1) all headers are an even number of bytes long * (2) the field is 7 characters long * (3) header_bytes = total length of all strings in header + 2 * */ int new_header_length = 0; int counter; char tempstring[MAX_STRING_LENGTH]; char tempstring2[MAX_STRING_LENGTH]; /* find out how many bytes there SHOULD be */ for(counter=0; counter<=header_lines; counter++) new_header_length = new_header_length + strlen(header[counter]); /* If this is odd, change to even.*/ if ((new_header_length % 2) == 1) new_header_length ++; /* add 2 to it */ new_header_length += 2; /* put lots of zeros on front */ sprintf(tempstring, "%d", new_header_length); /* add enough zero's on front to make it 7 chars long. * Since this was the length of the input's field, I don't need to * worry about it changing the true length of the header */ while (strlen(tempstring) != 7 ){ strcpy(tempstring2, "0"); strcat(tempstring2, tempstring); strcpy(tempstring, tempstring2);} /* use this value to reset header_bytes */ sprintf(header[0], "header_bytes=%s\n", tempstring); } /* ------------------------------------------------------------------------*/ void changeheader_B(int new_mincf, int new_maxcf, int new_channels) { /* Reset various values: * * mincf == new_mincf * maxcf == new_maxcf * channels = framehieght == new_channels * * NB This assumes "channels=" and "frameheight=" are both set to the * same value. I haven't yet seen a .sai in which they are * different, but I haven't looked too hard. * */ int new_header_length = 0; int counter; char tempstring[MAX_STRING_LENGTH]; char tempstring2[MAX_STRING_LENGTH]; for(counter=1; counter<=header_lines; counter++){ /* mincf */ if (strncmp(header[counter], "mincf_afb=", 10) == 0 ) { sprintf(header[counter], "mincf_afb=%d\n", new_mincf);} /* maxcf */ if (strncmp(header[counter], "maxcf_afb=", 10) == 0 ) { sprintf(header[counter], "maxcf_afb=%d\n", new_maxcf);} /* channels */ if (strncmp(header[counter], "channels_afb=", 12) == 0 ) { sprintf(header[counter], "channels_afb=%d\n", new_channels);} /* frameheight */ if (strncmp(header[counter], "frameheight=", 12) == 0 ) sprintf(header[counter], "frameheight=%d\n", new_channels); } /* reset framebytes */ change_framebytes(); /* reset header */ reset_header_bytes; } /* The End */ /* ------------------------------------------------------------------------*/