Duckstation/dep/stb/src/stb_image_write.c

29 lines
681 B
C
Raw Normal View History

2021-07-24 05:26:35 +00:00
#include <stdlib.h>
#include "zlib.h"
// https://github.com/nothings/stb/issues/113
static unsigned char* compress_for_stbiw(unsigned char* data, int data_len, int* out_len, int quality)
{
2021-07-25 15:34:15 +00:00
uLongf buf_size = compressBound(data_len);
2021-07-24 05:26:35 +00:00
// note that buf will be free'd by stb_image_write.h
// with STBIW_FREE() (plain free() by default)
2021-07-25 15:34:15 +00:00
unsigned char* buf = malloc(buf_size);
2021-07-24 05:26:35 +00:00
if (buf == NULL)
return NULL;
2021-07-25 15:34:15 +00:00
if (compress2(buf, &buf_size, data, data_len, quality) != Z_OK)
2021-07-24 05:26:35 +00:00
{
free(buf);
return NULL;
}
2021-07-25 15:34:15 +00:00
*out_len = buf_size;
2021-07-24 05:26:35 +00:00
return buf;
}
#define STBIW_ZLIB_COMPRESS compress_for_stbiw
2019-09-18 05:36:22 +00:00
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"