-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspngt_lodepng.c
43 lines (30 loc) · 973 Bytes
/
spngt_lodepng.c
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
#include "spngt.h"
#include "lodepng.h"
void spngt_print_version_lodepng(void)
{
printf("lodepng %s\n", LODEPNG_VERSION_STRING);
}
int spngt_encode_lodepng(struct spngt_params *params)
{
return SPNGT_ENOTSUPP;
unsigned char *out;
size_t encoded_size;
unsigned int e;
int width = params->ihdr.width;
int height = params->ihdr.height;
e = lodepng_encode_memory(&out, &encoded_size, params->image, width, height, params->ihdr.color_type, params->ihdr.bit_depth);
if(e) return SPNGT_ERROR;
return 0;
}
int spngt_decode_lodepng(struct spngt_params *params)
{
if(params->fmt != SPNG_FMT_RGBA8) return SPNGT_ENOTSUPP;
unsigned int width, height;
unsigned char *img_out = NULL;
unsigned int e = lodepng_decode32(&img_out, &width, &height, params->png, params->png_size);
if(e) return SPNGT_ERROR;
params->image = img_out;
params->ihdr.width = width;
params->ihdr.height = height;
return 0;
}