-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (63 loc) · 1.98 KB
/
Copy pathmain.cpp
File metadata and controls
74 lines (63 loc) · 1.98 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
#include <iostream>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#if __EMSCRIPTEN__
#include "emscripten/bind.h"
#include "emscripten/emscripten.h"
#else
#define EMSCRIPTEN_KEEPALIVE
#endif
int gWidth;
int gHeight;
int EMSCRIPTEN_KEEPALIVE generate_rendition_using_idb(std::string input_image_path, std::string output_image_path)
{
// load image
int width, height, channels;
unsigned char *img = stbi_load(input_image_path.c_str(), &width, &height, &channels, 0);
if (img == NULL)
{
std::cout << "STB error loading: " << output_image_path << std::endl;
return 2;
}
std::cout << "STB image loaded" << std::endl;
std::cout << "STB write output to: " << output_image_path << std::endl;
gWidth = width;
gHeight = height;
// return stbi_write_jpg(output_image_path.c_str(), width, height, channels, img, 100);
// stbi_write_png_compression_level = 20;
return stbi_write_png(output_image_path.c_str(), width, height, channels, img, 0);
}
int EMSCRIPTEN_KEEPALIVE get_width()
{
return gWidth;
}
int EMSCRIPTEN_KEEPALIVE get_height()
{
return gHeight;
}
#if __EMSCRIPTEN__
int EMSCRIPTEN_KEEPALIVE main(int argc, char *argv[])
{
std::cout << "STB c++ has loaded" << std::endl;
}
EMSCRIPTEN_BINDINGS(generate_rendition_using_idb)
{
emscripten::function("generate_rendition_using_idb", &generate_rendition_using_idb);
emscripten::function("get_width", &get_width);
emscripten::function("get_height", &get_height);
}
#else
int main(int argc, char* argv[]){
std::cout << "STB c++ has loaded" << std::endl;
if(argc < 3){
std::cout << "STB usage: ./app input.psd output.png" << std::endl;
return 1;
}
std::string input_image_path = std::string(argv[1]);
std::string output_image_path = std::string(argv[2]);
generate_rendition_using_idb(input_image_path, output_image_path);
return 0;
}
#endif //__EMSCRIPTEN__