-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
116 lines (87 loc) · 3.24 KB
/
test.cpp
File metadata and controls
116 lines (87 loc) · 3.24 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "img.h"
#include "AsciiArt.h"
#include "conio.h"
#include "filesystem"
#include "sstream"
#include "signal.h"
// minimum filename length (for frames)
#define MIN_NUM_LENGTH 4
void _sig_Siginthand(int signal){
AsciiArt::SafeStopDrawing();
}
int main(){
signal(SIGINT, _sig_Siginthand);
std::cout << "Choose what to convert:\n1. Pictures\n2. Frames (pictures from video) (with filename as number starting with 0000 (as like blender rendered pictures))" << std::endl;
std::cout << "\nFiles extensions currently supported: " << SupportedFileTypeStr << std::endl;
int option = _getch();
switch(option){
break; case '1':{
std::string datapath;
std::cout << "Enter path to file: " << std::flush;
std::cin >> datapath;
BmpOpener bmp;
int errcode = bmp.Open(datapath);
if(errcode != ERR_BMP_SUCCESS){
std::cout << "Error opening file: ";
switch(errcode){
break; case ERR_BMP_WRONGID:
std::cout << "Not a bmp file." << std::endl;
break; default:
std::cout << "errcode: " << errcode << std::endl;
}
return errcode;
}
ImageData imgdat = bmp.GetImageData();
AsciiArt::SetImage(imgdat);
}
// maybe add some extension checking
break; case '2':{
std::string filepath;
std::cout << "Enter path to first frame picture: " << std::flush;
std::cin >> filepath;
float framerate = 0;
std::cout << "Enter framerate (can be float): " << std::flush;
std::cin >> framerate;
std::size_t extensionOffset = filepath.find_last_of('.');
std::size_t nameOffset = filepath.find_last_of('/');
std::string extensionName = filepath.substr(extensionOffset+1);
std::string folderPath = filepath.substr(0, nameOffset);
std::string firstFileName = filepath.substr(nameOffset+1, extensionOffset);
std::size_t imgdataslen = 0;
ImageData **imgdatas = (ImageData**)malloc(0);
BitmapFileData currentBitmap;
size_t framecount = 0;
std::stringstream strnumi(firstFileName);
strnumi >> framecount;
while(true){
std::stringstream ss("");
ss << framecount;
std::string newFilename = ss.str();
if(newFilename.length() < MIN_NUM_LENGTH){
std::string filler(MIN_NUM_LENGTH-newFilename.length(), '0');
newFilename = filler+newFilename;
}
std::ifstream ifs{};
std::string newfilename = folderPath+"/"+newFilename+"."+extensionName;
ifs.open(newfilename);
if(ifs.fail())
break;
int errcode = BmpOpener::Open(ifs, currentBitmap);
if(errcode != 0){
std::cout << "Failed opening a file, errcode: " << errcode << std::endl;
}else{
imgdatas = (ImageData**)realloc(imgdatas, sizeof(ImageData*)*(++imgdataslen));
ImageData *newImage = new ImageData{currentBitmap};
imgdatas[imgdataslen-1] = newImage;
}
framecount++;
}
AsciiArt::DrawImage(imgdatas, imgdataslen, framerate);
for(int i = 0; i < imgdataslen; i++)
delete imgdatas[i];
free(imgdatas);
}
break; default:
std::cout << "Wrong option." << std::endl;
}
}