forked from EyalAr/lwip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.cpp
103 lines (89 loc) · 3.02 KB
/
init.cpp
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
#include "encoder.h"
// encoder.jpeg(pixbuf, width, height, quality, callback)
NAN_METHOD(encodeToJpegBuffer) {
NanScope();
Local<Object> buff = args[0].As<Object>();
size_t width = args[1].As<Integer>()->Value();
size_t height = args[2].As<Integer>()->Value();
int quality = args[3].As<Integer>()->Value();
NanCallback * callback = new NanCallback(args[4].As<Function>());
NanAsyncQueueWorker(
new EncodeToJpegBufferWorker(
buff,
width,
height,
quality,
callback
));
NanReturnUndefined();
}
// encoder.png(pixbuf, width, height, compression, interlaced, trans, metadata, callback)
NAN_METHOD(encodeToPngBuffer) {
NanScope();
Local<Object> buff = args[0].As<Object>();
size_t width = args[1].As<Integer>()->Value();
size_t height = args[2].As<Integer>()->Value();
int compression = args[3].As<Integer>()->Value();
bool interlaced = args[4]->BooleanValue();
bool trans = args[5]->BooleanValue();
char * metadata;
if (args[6]->IsNull() || args[6]->IsUndefined()) {
metadata = NULL;
} else {
int metadata_len = args[6].As<String>()->Utf8Length();
metadata = (char *)malloc((metadata_len + 1) * sizeof(char));
args[6].As<String>()->WriteUtf8(metadata);
}
NanCallback * callback = new NanCallback(args[7].As<Function>());
NanAsyncQueueWorker(
new EncodeToPngBufferWorker(
buff,
width,
height,
compression,
interlaced,
trans,
metadata,
callback
)
);
NanReturnUndefined();
}
// encoder.gif(pixbuf, width, height, cmapSize, colors, interlaced, trans, threshold, callback)
NAN_METHOD(encodeToGifBuffer) {
NanScope();
Local<Object> buff = args[0].As<Object>();
size_t width = args[1].As<Integer>()->Value();
size_t height = args[2].As<Integer>()->Value();
int cmapSize = args[3].As<Integer>()->Value();
int colors = args[4].As<Integer>()->Value();
bool interlaced = args[5]->BooleanValue();
bool trans = args[6]->BooleanValue();
int threshold = args[7].As<Integer>()->Value();
NanCallback * callback = new NanCallback(args[8].As<Function>());
NanAsyncQueueWorker(
new EncodeToGifBufferWorker(
buff,
width,
height,
cmapSize,
colors,
interlaced,
trans,
threshold,
callback
)
);
NanReturnUndefined();
}
// create an init function for our node module
void InitAll(Handle<Object> exports) {
exports->Set(NanNew("jpeg"),
NanNew<FunctionTemplate>(encodeToJpegBuffer)->GetFunction());
exports->Set(NanNew("png"),
NanNew<FunctionTemplate>(encodeToPngBuffer)->GetFunction());
exports->Set(NanNew("gif"),
NanNew<FunctionTemplate>(encodeToGifBuffer)->GetFunction());
}
// use NODE_MODULE macro to register our module:
NODE_MODULE(lwip_encoder, InitAll)