| 7 | using namespace std; |
| 8 | |
| 9 | void loadFile(vector<unsigned char> & buffer, |
| 10 | string const & filename) // designed for loading files from hard disk in an std::vector |
| 11 | { |
| 12 | ifstream file(filename.c_str(), ios::in | ios::binary | ios::ate); |
| 13 | |
| 14 | // get filesize |
| 15 | streamsize size = 0; |
| 16 | if (file.seekg(0, ios::end).good()) |
| 17 | size = file.tellg(); |
| 18 | if (file.seekg(0, ios::beg).good()) |
| 19 | size -= file.tellg(); |
| 20 | |
| 21 | // read contents of the file into the vector |
| 22 | if (size > 0) |
| 23 | { |
| 24 | buffer.resize((size_t)size); |
| 25 | file.read((char *)(&buffer[0]), size); |
| 26 | } |
| 27 | else |
| 28 | buffer.clear(); |
| 29 | } |
| 30 | |
| 31 | UNIT_TEST(PngDecode) |
| 32 | { |