コード例 #1
0
ファイル: audio_fx.c プロジェクト: avafinger/guvcview_2.0.4
/*
 * Fuzz distortion
 * args:
 *   audio_ctx - audio context
 *   data - audio buffer to be processed
 *
 * asserts:
 *    audio_ctx is not null
 *
 * returns: none
 */
static void audio_fx_fuzz (audio_context_t *audio_ctx, sample_t *data)
{
	/*assertions*/
	assert(audio_ctx != NULL);

	int samp=0;
	for(samp = 0; samp < audio_ctx->capture_buff_size; samp++)
		data[samp] = FUZZ(data[samp]);
	HPF(audio_ctx, data, 1000, 0.9);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: RexxarCHL/Intro2Programming
int main(int argc, char* argv[]){
    if(argc != 3){
        printf("Useage: input_name output_name");
        exit(0);
    }
    
    char file_answer;
    
    printf("Select mode:\n"
           "1.bin to bmp\n"
           "2.bmp to bmp\n"
           "3.bin to bin\n");
    file_answer=getchar();
    fflush(stdin);
    
    char *Input=argv[1], *Output=argv[2];//retrive input/output name from commandline
    BmpHead *pBmpHeader = new BmpHead;
    unsigned char **pucImageData; 
    char *pcColorMap=NULL;
           
    if((file_answer == '1')||(file_answer == '3')){   //read bin file
        system("cls");
        
        //assign header information courtersy of Lena.bin
	    (*pBmpHeader).bfType=19778;
	    (*pBmpHeader).bfSize=54 + 1024+ 512*512 ; // raw data size = 512*512 = 262144 bytes, modify when necessary
	    (*pBmpHeader).bfReserved=0;
	    (*pBmpHeader).bfOffBits=1078;
	    (*pBmpHeader).biSize=40;
	    (*pBmpHeader).biWidth= 512;		//number of columns of the image
	    (*pBmpHeader).biHeight= 512;		//number of rows of the image
	    (*pBmpHeader).biPlanes=1;
	    (*pBmpHeader).biBitCount=8;
	    (*pBmpHeader).biCompression=0;
	    (*pBmpHeader).biSizeImage= 512*512;	//raw data size = 512*512 = 26144 bytes, modify when necessary, e.g., a 256x256 image: raw data size = 256*256
	    (*pBmpHeader).biXPelsPerMeter=2834;
	    (*pBmpHeader).biYpelsPerMeter=2834;
	    (*pBmpHeader).biClrUsed=0;
	    (*pBmpHeader).biClrImportant=0;
        
        //read provided colormap
        FILE *colormap=NULL;
        pcColorMap = new char [1024];
        if((colormap=fopen("colormap.bin", "rb")) == NULL){
            printf("Failed to find colormap.bin\n");
            exit(0);
        }
        fread(pcColorMap, sizeof(char), pBmpHeader->bfOffBits-64, colormap);
        fclose(colormap);
        
        //read raw data fron input
        pucImageData = ReadImage( Input, pBmpHeader->biWidth, 0);
        
        printf("successfully read raw data from %s.\n\n", Input);
    }
     
    else if(file_answer == '2'){  //read bmp file
        system("cls");
        
        //read input header infomation
        pBmpHeader=ReadBmpHeader(Input);
        printf("raw data size: %d\n", pBmpHeader->biSizeImage);
        printf("Image Width: %d\n", pBmpHeader->biWidth);
        printf("Image Height %d\n", pBmpHeader->biHeight);
	    printf("Header occupies 54 bytes\n");
        printf("Color map occupies 1024 bytes\n");	
        
        //read input colormap
        pcColorMap=ReadColorMap(Input, 1024);
        
        //read raw data from input
                                                    //set offset=1024+54
        pucImageData=ReadImage(Input, pBmpHeader->biWidth, 1078);
        printf("successfully read raw data from %s.\n\n", Input);
    }
    
    srand(time(NULL));//plant random seed
    
    //function menu
    char fx_answer;
    int width, cutoff;
    do{
        printf(
           "Select function:\n"
           "A.Turn Lena upside down\n"
           "B.Turn Lena around\n"
           "C.Rotate Lena by 45 deg clockwise\n"
           "D.Shrink Lena by half\n"
           "E.Invert Lena\n"
           "F.Add normal noise to Lena\n"
           "G.Add impluse noise to Lena\n"
           "H.Moving average filtering\n"
           "I.Midian filtering\n"
           "J.Differential flitering\n"
           "K.LPF\n"
           "L.HPF\n"
           "\n0.Exit\n");
        printf("Your choice: [_]\b\b");
        fx_answer = getchar();
        fx_answer = tolower(fx_answer);
        fflush(stdin);
        
        switch(fx_answer){//savefile(): ask user to save as picture or not
            case 'a':// selected: turn lena upside down
                UpsideDown(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
            
            case 'b'://selected: turn lena around
                LeftRight(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'c'://selected: rotate lena
                ImgRotate(pucImageData, pBmpHeader->biWidth, 45);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
            
            case 'd'://selected: shrink lena
                Shrink(pucImageData, pBmpHeader->biWidth, pBmpHeader, 2);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'e'://selected: invert lena
                Invert(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'f'://selected: add noise
                NormalNoise(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'g'://selected: add paper n salt noise
                ImpluseNoise(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'h'://selected: moving average filter
                //ask user to input sampling width
                printf("Enter sampling width:");
                scanf("%d", &width);
                fflush(stdin);
                MAF(pucImageData, pBmpHeader->biWidth, width);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'i'://selected: moving midian filter
                //ask user to input sampling width
                printf("Enter sampling width:");
                scanf("%d", &width);
                fflush(stdin);
                MF(pucImageData, pBmpHeader->biWidth, width);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'j'://selected: differential filter
                DIF(pucImageData, pBmpHeader->biWidth);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'k'://selected: low-pass filter
                //ask user to input cutoff frequency
                printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2);
                scanf("%d", &cutoff);
                fflush(stdin);
                LPF(pucImageData, pBmpHeader->biWidth, cutoff);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case 'l'://selected: high-pass filter
                //ask user to input cutoff frequency
                printf("Enter cutoff frenquency(0~%d):", (int)pBmpHeader->biWidth/2);
                scanf("%d", &cutoff);
                fflush(stdin);
                HPF(pucImageData, pBmpHeader->biWidth, cutoff);
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            case '0'://selected: exit
                //ask one last time whether user want to save or not
                savefile(Output, pucImageData, file_answer, pBmpHeader, pcColorMap);
                break;
                 
            default:
                system("cls");
                printf("Your choice is not in the list!\n");
                break;
            
        }
        
        if(fx_answer == 0)
            break;//selected: exit. break the loop
        
        
    } while(fx_answer != '0');
    
    //returning dynamic allocated memory
    delete [] pcColorMap;
    delete [] pucImageData;
    delete pBmpHeader;
    pcColorMap=NULL;
    pucImageData=NULL;
    pBmpHeader=NULL;
    
    printf("EOP\n");
}