Use zlib for compression of png screenshots

This commit is contained in:
Nick Whitlock 2023-05-23 01:29:17 -04:00
parent c86cb9a982
commit b880e8625b

View file

@ -47,7 +47,27 @@ If you have questions concerning this license or the applicable additional terms
#include "sys/win32/win_local.h"
#endif
#include <zlib.h>
unsigned char* compress_for_stbiw(unsigned char* data, int data_len, int* out_len, int quality)
{
uLongf bufSize = compressBound(data_len);
// note that buf will be free'd by stb_image_write.h
// with STBIW_FREE() (plain free() by default)
unsigned char* buf = (unsigned char*)malloc(bufSize);
if (buf == NULL) return NULL;
if (compress2(buf, &bufSize, data, data_len, quality) != Z_OK)
{
free(buf);
return NULL;
}
*out_len = bufSize;
return buf;
}
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define STBIW_ZLIB_COMPRESS compress_for_stbiw
#include "stb_image_write.h"
// functions that are not called every frame