-
Notifications
You must be signed in to change notification settings - Fork 4
/
jpeg_wrapper.cpp
43 lines (34 loc) · 968 Bytes
/
jpeg_wrapper.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
// +build jpegcpp
#include "jpeg_wrapper.h"
#include "jpgd.h"
#include "jpge.h"
extern "C" void
cleanupString(char *c)
{
free(c);
}
extern "C" int
decodeEncodeWrite(unsigned char *ci, int ciLen, int quality, char *filename)
{
static const int requestedComps = 3; // RGB
int actualComps, w, h;
// decompress
unsigned char *decodedBytes = jpgd::decompress_jpeg_image_from_memory(
ci, ciLen, &w, &h, &actualComps, requestedComps);
if (decodedBytes != NULL) {
// default params are OK for color images
jpge::params p;
p.m_quality = quality;
// compress using requested quality
bool result = jpge::compress_image_to_jpeg_file(
filename, w, h, actualComps,
decodedBytes, p);
free(decodedBytes);
if (!result) {
return 1;
}
} else {
return 1;
}
return 0;
}