2008年9月17日水曜日

handling pgm data with c++

i m trying to get raw data from pgm file. if you calculate file size from width and height, if you like 16bit data, the file size will be double, you can find the header size. but how do we get heaer info without calculating?

following is a part of the code.



int width, height, brightness, counter;
std::ifstream ifs;
//initialize
width = height = brightness = counter = 0;
ifs.open(input_file_name, std::ios::in);

std::string filetype;
std::string filetype_str;
std::getline(ifs, filetype);

std::string size_str;
std::getline(ifs, size_str);
std::istringstream size_stream(size_str);
size_stream >> width >> height;

std::string brightness_str;
std::getline(ifs, brightness_str);
std::istringstream brightness_stream(brightness_str);
brightness_stream >> brightness;

std::string header_needless;
std::getline(ifs, header_needless);

std::cout << filetype << std::endl;
std::cout << width << std::endl;
std::cout << height << std::endl;
std::cout << brightness << std::endl;

this means there are 4 lines for a header.

0 件のコメント: