-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfif2png.cpp
More file actions
52 lines (44 loc) · 1.31 KB
/
fif2png.cpp
File metadata and controls
52 lines (44 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//C++ FastIF decoder
//Copyright (C) 2020 I.C.
#include <iostream>
#include <fstream>
#include <png++/png.hpp>
#include "fif_decoder.h"
int main(int argc, char** args) {
if(argc != 3) {
std::cout << "Usage: " << args[0] << " [FIF input file] [PNG output file]\n";
return 0;
}
FIF* fif = new FIF;
std::ifstream ifile(args[1],std::ios::in|std::ios::binary|std::ios::ate);
if(!ifile.is_open()) {
perror(args[1]);
exit(1);
} else {
std::streampos size = ifile.tellg();
ifile.seekg(0);
fif->data = new unsigned char[size];
ifile.read((char*)fif->data,size);
ifile.close();
}
//Read FIF
signed int res = 0;
while((res = FIF_read(fif))) {
if(res == 0) break;
if(res < 0) {
std::cout << "FIF error " << (int)res << ".\n";
exit(2);
}
}
//Write output
png::image<png::rgb_pixel> image(fif->width,fif->height);
for(unsigned int y=0;y<fif->height;y++) {
for(unsigned int x=0;x<fif->width;x++) {
image[y][x] = png::rgb_pixel(fif->decoded_data[y*fif->width+x].r,fif->decoded_data[y*fif->width+x].g,fif->decoded_data[y*fif->width+x].b);
}
}
image.write(args[2]);
FIF_free(fif);
delete fif;
return 0;
}