...as present in MS TrueType files. Since this table is optional,
the new stbtt_GetFontVMetricsOS2 has a return value and can fail.
This is a replacement for pull request #463.
Fixes#463.
This incorporates #462, but also factors everything into one
function that is shared between 8-bit integer, 16-bit integer, and
float pixels (vertical flip operates on rows of bytes and doesn't
really care), and finally always uses a 2k on-stack buffer without
dynamic memory allocation, doing multiple memcpys per row if
necessary. Not only does this remove an out-of-memory failure mode,
it is also preferable for large images, since it's more
L1-cache-firendly this way.
Fixes#462.
1. const char* for __FILE__ (string literals are const)
2. Use %zd to print size_t where available; the only real problem
here is Visual C++. Use long long on the VC++ vers that support
64-bit targets but not %zd, int on the even older 32-bit-only
VC++ vers that don't support "long long" either.
Fixes#459. I think. (It's hard to be sure since the issue doesn't
state the exact warning message.)
We used to require exact match between img_len and raw_len for
non-interlaced PNGs, but the PNG in issue #276 has extra bytes
(all zeros) at the end of the compressed DEFLATE stream.
The PNG spec doesn't have anything to say about it (that I
can tell), and if libpng accepts this, who are we to judge.
Fixes issue #276.
The builtin stbi_zlib_compress does not compress as well as zlib or
miniz (which is not too surprising as it's <200 LOC), thus PNGs created
by stb_image_write are about 20-50% bigger than PNGs compressed with
libpng.
This change lets the user supply a custom deflate/zlib-style compress
function, which improves compression a lot. This was requested in #113.
Example for zlib:
#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 = 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 STBIW_ZLIB_COMPRESS compress_for_stbiw
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
// ...
clang says:
error: non-constant-expression cannot be narrowed from type 'int'
to 'unsigned char' in initializer list [-Wc++11-narrowing]
so I explicitly cast affected stuff to unsigned char.