Esempio n. 1
0
/*
	PGMファイル読み込み

	fname:ファイルネーム
	pgm:PGMファイルポインタ

*/
int readPGMfile(char* fname,PGMFILE **pgm){
	FILE *fp;
	char fhead[256];	//ヘッドバッファ
	int ftype;			//ファイルタイプ
	int fx,fy;			//x,yのサイズ
	int fmax;			//最大光度
	double fratio;		//最大光度(255)のに対する割合
	BYTE *data;//データ量
	int i;

	/*ファイルをバイナリモードで読み込み*/
	fp = fopen(fname,"rb");
	if(fp==NULL){
		//printf("FileOpenError\n");
		return 1;
	}

	/*ファイルタイプ*/
	fgets(fhead,255,fp);
	if(fhead[0]!='P'){
		//printf("FileType1Error\n");
		return 2;
	}
	sscanf(fhead,"P%d",&ftype);
	if(ftype < 1 || ftype > 6){
		//printf("FileType2Error\n");
		return 3;
	}
	/*コメント*/
	do fgets(fhead,255,fp); while(fhead[0]=='#');

	/*ファイルサイズ*/
	sscanf(fhead,"%d%d",&fx,&fy);
	if(fx < 1 || fy < 1){
		//printf("FileSizeError\n");
		return 4;
	}

	if(ftype == 2 || ftype == 3 || ftype == 5 || ftype == 6){
		do fgets(fhead,255,fp); while(fhead[0]=='#');
		sscanf(fhead,"%d",&fmax);
		if(fmax < 1 || fmax > 255){
			//printf("LightRaleError\n");
			return 5;
		}
	}


	*pgm = createPGM(fx,fy,fmax,ftype);

	/*データ読み出し*/
	data = (*pgm)->data;
	for(i=0;i < fy*fx;i++){
			data[i] = (BYTE)fgetc(fp);
	}

	fclose(fp);
	return 0;
}
Esempio n. 2
0
//! @brief Executes a series of timing tests for metric collection
void runTimingTests()
{
	std::cout << "-------------- Timing Metrics ---------------\n";
	// Run timing tests and write to a CSV file [with AVERAGES - not all tests..]

	std::string resultFile = "timing-results.csv";
	std::ofstream output(resultFile.c_str());
	output << "width, height, total pixels, ";
	output << "ascii to binary average time (of 10 runs) in ms, ";
	output << "binary to ascii average time (of 10 runs) in ms\n";

	std::string test1 = "test.pgm";
	std::string test2 = "test_b.pgm";
	int maxSize = 500;
	for (int size = 50; size <= maxSize; size+=50)
	{
		long double msTotal1 = 0; // for ascii to binary
		long double msTotal2 = 0; // for binary to ascii
		int numRuns = 10;
		for (int times = 0; times < numRuns; ++times)
		{
			createPGM(test1.c_str(), size, size);

			std::clock_t start1 = std::clock();
			reducto::asciiToBinary(test1);
			std::clock_t end1 = std::clock();

			std::clock_t start2 = std::clock();
			reducto::binaryToAscii(test2);
			std::clock_t end2 = std::clock();

			remove(test1.c_str());
			remove(test2.c_str());
			msTotal1 += 1000.0 * (end1 - start1) / CLOCKS_PER_SEC;
			msTotal2 += 1000.0 * (end2 - start2) / CLOCKS_PER_SEC;
		}
		std::cerr << "Timing: " << size << " of " << maxSize << "\r";

		double average1 = msTotal1 / (double)numRuns;
		double average2 = msTotal2 / (double)numRuns;
		output << size << ", " << size << ", " << size * size << ", ";
		output << average1 << "," << average2 << "\n";
	}
	std::cerr << "\n";

	// Clean up
	int lastIndex = test1.find_last_of(".");
	std::string oFile = test1.substr(0, lastIndex) + "_b.pgm";
	remove(oFile.c_str());
	output.close();
}
Esempio n. 3
0
int main(int argc, char** argv) {

    //Checking given filepath
    short required = TESTING ? 1 : 2;
    
    if (argc != required) { //argc != 2
        char *progname = strrchr(argv[0], '/');
        printf("Uso correto: %s \"arquivo\"\n", &progname[1]);
        
        return 400;
    } else {
        filename = argv[1];
//        filename = "C:\\Users\\Bruno Pessoa\\Downloads\\wav-parser-master\\animals.wav";
//        filename = "C:\\Users\\gustavo\\sample.wav";
//        filename = "/Users/gustavo/Downloads/Silent8.wav";
        filename = TESTING ? "/Users/gustavo/Developer/SEMB/8k8bitpcm.wav" : filename;
//        filename = "/Users/gustavo/Developer/SEMB/JumpMono.wav";
        
        wavptr = fopen(filename, "r");
        
        /// Invalid file
        if (wavptr == NULL) {
            printf("ERROR: File not found.\n");
            return 404;
        }
        
        fillHeader();
        fillFormat();
        
        /// Unsupported sampleRate / resolution
        if (format.numChannels > 1 || format.bitsPerSample != 8) {
            printf("ERROR: Only works with 8-bit mono files\n");
            fclose(wavptr);
            return 403;
        }
        
//        byte sampley[data.chunkSize/(format.sampleRate/PPS)][2];
//        sampley[0][0] = 110;
//        sampley[100][1] = 110;
        
        fillData();
        createPGM();
        chooseSamples();
        fillPGM();
        fclose(pgmptr);
        fclose(wavptr);
    }
    
    return 0;
}
Esempio n. 4
0
//! @brief Executes a series of storage tests for metric collection
void runStorageTests()
{
	std::cout << "-------------- Storage Metrics --------------\n";
	// Run storage tests and write to a CSV file [with AVERAGES - not all tests..]

	int maxSize = 1000;
	int maxSVD  = 1000;
	int maxRank = 100;
	std::string test1 = "test.pgm";

	std::string resultFile = "storage-results.csv";
	std::ofstream output(resultFile.c_str());

	output << "total pixels, ";
	output << "size of ascii file (bytes), ";
	output << "size of compressed binary file (bytes), ";
	output << "size of decompressed ascii file (bytes), ";
	output << "size of SVD.txt (bytes), ";
	output << "rank, ";
	output << "size of compressed binary SVD file (bytes), ";
	output << "size of decompressed svd file ascii (bytes) \n";

	for (int size = 50; size <= maxSize; size+=50)
	{
		// total pixels
		output << size * size << ", ";

		// size of ascii file (bytes)
		createPGM(test1.c_str(), size, size);
		struct stat ifilestatus;
		stat(test1.c_str(), &ifilestatus);
		output << ifilestatus.st_size << ", ";
		reducto::asciiToBinary(test1);

		// size of compressed binary file (bytes)
		std::string oFile1 = "test_b.pgm";
		struct stat ofilestatus1;
		stat(oFile1.c_str(), &ofilestatus1);
		output << ofilestatus1.st_size << ", ";

		// size of decompressed ascii file (bytes)
		std::string oFile2 = "test2.pgm";
		reducto::binaryToAscii(oFile1);
		struct stat ofilestatus2;
		stat(oFile2.c_str(), &ofilestatus2);
		output << ofilestatus2.st_size << ", ";

		if (size <= maxSVD)
		{
			// size of SVD.txt (bytes)
			reducto::asciiToSvd(test1);
			std::string oFile3 = "test_svd.txt";
			struct stat ofilestatus3;
			stat(oFile3.c_str(), &ofilestatus3);
			output << ofilestatus3.st_size << ", ";

			for (int rank = 1; rank < maxRank; rank += 1)
			{
				// rank
				output << rank << ", ";

				// size of compressed binary SVD file (bytes)
				reducto::svdCompress("test_header.txt", oFile3, rank);
				std::string oFile4 = "image_b.pgm.svd";
				struct stat ofilestatus4;
				stat(oFile4.c_str(), &ofilestatus4);
				output << ofilestatus4.st_size << ", ";

				// size of decompressed svd file ascii (bytes)
				reducto::svdDecompress(oFile4);
				std::string oFile5 = "image_k.pgm";
				struct stat ofilestatus5;
				stat(oFile5.c_str(), &ofilestatus5);
				output << ofilestatus5.st_size << "\n";


				if (rank < maxRank - 1) 
				{
					output << size * size << ", ";
					output << ifilestatus.st_size << ", ";
					output << ofilestatus1.st_size << ", ";
					output << ofilestatus2.st_size << ", ";
					output << ofilestatus3.st_size << ", ";
				}

				remove(oFile4.c_str());
				remove(oFile5.c_str());
			}

			remove(oFile3.c_str());
		}
		else
		{
			// empty rank, size of compressed binary SVD file (bytes),
			// and size of decompressed svd file ascii (bytes)
			output << ", , \n";
		}

		std::cerr << "2. Storage: " << size << " of " << maxSize << "\r";

		remove(oFile1.c_str());
		remove(oFile2.c_str());
		
	}

	std::cerr << "\n";
	remove(test1.c_str());
	output.close();
}