/** \brief Flip a canvas horizontally. * * Flip a canvas horizontally, choosing characters that look like the * mirrored version wherever possible. Some characters will stay * unchanged by the process, but the operation is guaranteed to be * involutive: performing it again gives back the original canvas. * * This function never fails. * * \param cv The canvas to flip. * \return This function always returns 0. */ int caca_flip(caca_canvas_t *cv) { int y; for(y = 0; y < cv->height; y++) { uint32_t *cleft = cv->chars + y * cv->width; uint32_t *cright = cleft + cv->width - 1; uint32_t *aleft = cv->attrs + y * cv->width; uint32_t *aright = aleft + cv->width - 1; while(cleft < cright) { uint32_t ch; uint32_t attr; /* Swap attributes */ attr = *aright; *aright-- = *aleft; *aleft++ = attr; /* Swap characters */ ch = *cright; *cright-- = flipchar(*cleft); *cleft++ = flipchar(ch); } if(cleft == cright) *cleft = flipchar(*cleft); /* Fix fullwidth characters. Could it be done in one loop? */ cleft = cv->chars + y * cv->width; cright = cleft + cv->width - 1; for( ; cleft < cright; cleft++) { if(cleft[0] == CACA_MAGIC_FULLWIDTH) { cleft[0] = cleft[1]; cleft[1] = CACA_MAGIC_FULLWIDTH; cleft++; } } } if(!cv->dirty_disabled) caca_add_dirty_rect(cv, 0, 0, cv->width, cv->height); return 0; }
void scamp2fb(FILE *input, FILE *output) /* includefile */ { FILE *fpou; unsigned char *gulp,*spew,*flip,sumof[256]; float realtime; double junk; char string[80],schead[640]; int i,j,k,doit,idump=0,nread,opened=0,s,f, ntotal=0,nclipped=0,ichans,sum,clipmax; //if (scamp_chans != nchans) exit(0); /* allocated space to store incoming and outgoing data blocks */ gulp = (unsigned char *) malloc(scamp_block_size * sizeof(unsigned char)); flip = (unsigned char *) malloc(scamp_block_size * sizeof(unsigned char)); spew = (unsigned char *) malloc(8*scamp_block_size * sizeof(unsigned char)); if (headerfile) { /* write output ASCII header file */ fpou=open_file("head","w"); fprintf(fpou,"Original SCAMP file: %s\n",inpfile); fprintf(fpou,"Sample time (us): %f\n",tsamp*1.0e6); fprintf(fpou,"Center freq (MHz): %f\n",fch1+(float)scamp_chans*foff/2.0); fprintf(fpou,"Channel band (kHz): %f\n",fabs(foff)*1000.0); fprintf(fpou,"Time stamp (MJD): %18.12f\n",tstart); fprintf(fpou,"RA (J2000): %f\n",src_raj); fprintf(fpou,"DEC (J2000): %f\n",src_dej); fclose(fpou); } if (clip_threshold>0.0) { /* clip samples which deviate by more than clip_threshold sigma times the mean. For these data, mean=nchan/2 and sigma = sqrt(nchan) */ clipmax=(float)(scamp_chans)/2.0+clip_threshold*sqrt((float)scamp_chans); for (i=0;i<256;i++) sumof[i]=sumchar(i); /* look-up table of byte sums */ } while (!feof(input)) { /* read ina 48k block of data */ nread=fread(gulp,1,scamp_block_size,input); /* do the band inversion here if necessary DEDISPERSE requires that the first channel is the highest frequency */ if (invert_band) { for (i=0; i<scamp_block_size; i++) flip[i]=flipchar(gulp[i]); for (i=0; i<scamp_block_size/scamp_chans; i++) { s=i*scamp_chans; f=(i+1)*scamp_chans; k=0; for (j=s;j<f;j++) { gulp[j]=flip[f-1-k]; k++; } } } /* now do clipping if necessary */ if (clip_threshold>0.0) { ichans=sum=j=0; for (i=0; i<scamp_block_size; i++) { /* keep track of sum over each byte (8 channels!) */ sum+=sumof[gulp[i]]; ichans+=8; if (ichans==scamp_chans) { /* decide whether to clip this sample */ if (sum>clipmax) { nclipped++; for (k=j; k<=i; k++) gulp[k]=0; } ntotal++; j=i+1; sum=0; ichans=0; } } } if (scamp_rawdata) { /* read off the header from the data and proceed as normal */ fread(schead,sizeof(schead),1,input); } else { /* extra (FORTRAN!) junk that gets written after each block */ fread(&junk,8,1,input); } /* decide whether to write out this block */ realtime=tsamp*idump; if ((doit=process(realtime,start_time,final_time))==-1) break; if (doit) { if (idump%1024 == 0) { if (!opened) { open_log("filterbank.monitor"); opened=1; } sprintf(string,"time:%.1fs",realtime); update_log(string); } /* output as single bit (default) or single byte data */ switch (obits) { case 1: idump+=8*nread/scamp_chans; i=1; /* write out only segments not in scamp.ignore */ for (j=1;j<=nread;j++) { if (!scamp_ignore[i]) fwrite(&gulp[j-1],1,1,output); i++; if (i>scamp_chans/8) i=1; } /*fwrite(gulp,1,nread,output);*/ break; case 8: k=0; for (i=0; i<nread; i++) { for (j=0;j<8;j++) { spew[k]=gulp[i]&1; gulp[i]>>=1; k++; if (!(k%scamp_chans)) idump++; } } fwrite(spew,1,8*scamp_block_size,output); break; } } } /* write out clipping statistics to ASCII file clip.stats */ if (clip_threshold>0) { fpou=open_file("clip.stats","w"); fprintf(fpou,"threshold %.1f sigma (sum = %d)\n", clip_threshold,clipmax); fprintf(fpou,"samples clipped = %d (total = %d)\n", nclipped,ntotal); fclose(fpou); } free(gulp);free(flip);free(spew); }