|
|
@@ -2261,13 +2261,13 @@ static void init_defaults(void) |
|
|
|
int stbi_png_partial; // a quick hack to only allow decoding some of a PNG... I should implement real streaming support instead
|
|
|
|
static int parse_zlib(zbuf *a, int parse_header)
|
|
|
|
{
|
|
|
|
int final, type;
|
|
|
|
int final_, type;
|
|
|
|
if (parse_header)
|
|
|
|
if (!parse_zlib_header(a)) return 0;
|
|
|
|
a->num_bits = 0;
|
|
|
|
a->code_buffer = 0;
|
|
|
|
do {
|
|
|
|
final = zreceive(a,1);
|
|
|
|
final_ = zreceive(a,1);
|
|
|
|
type = zreceive(a,2);
|
|
|
|
if (type == 0) {
|
|
|
|
if (!parse_uncompressed_block(a)) return 0;
|
|
|
@@ -2286,7 +2286,7 @@ static int parse_zlib(zbuf *a, int parse_header) |
|
|
|
}
|
|
|
|
if (stbi_png_partial && a->zout - a->zout_start > 65536)
|
|
|
|
break;
|
|
|
|
} while (!final);
|
|
|
|
} while (!final_);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
@@ -2519,7 +2519,7 @@ static int create_png_image_raw(png *a, uint8 *raw, uint32 raw_len, int out_n, u |
|
|
|
|
|
|
|
static int create_png_image(png *a, uint8 *raw, uint32 raw_len, int out_n, int interlaced)
|
|
|
|
{
|
|
|
|
uint8 *final;
|
|
|
|
uint8 *final_;
|
|
|
|
int p;
|
|
|
|
int save;
|
|
|
|
if (!interlaced)
|
|
|
@@ -2528,7 +2528,7 @@ static int create_png_image(png *a, uint8 *raw, uint32 raw_len, int out_n, int i |
|
|
|
stbi_png_partial = 0;
|
|
|
|
|
|
|
|
// de-interlacing
|
|
|
|
final = (uint8 *) malloc(a->s->img_x * a->s->img_y * out_n);
|
|
|
|
final_ = (uint8 *) malloc(a->s->img_x * a->s->img_y * out_n);
|
|
|
|
for (p=0; p < 7; ++p) {
|
|
|
|
int xorig[] = { 0,4,0,2,0,1,0 };
|
|
|
|
int yorig[] = { 0,0,4,0,2,0,1 };
|
|
|
@@ -2540,19 +2540,19 @@ static int create_png_image(png *a, uint8 *raw, uint32 raw_len, int out_n, int i |
|
|
|
y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p];
|
|
|
|
if (x && y) {
|
|
|
|
if (!create_png_image_raw(a, raw, raw_len, out_n, x, y)) {
|
|
|
|
free(final);
|
|
|
|
free(final_);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
for (j=0; j < y; ++j)
|
|
|
|
for (i=0; i < x; ++i)
|
|
|
|
memcpy(final + (j*yspc[p]+yorig[p])*a->s->img_x*out_n + (i*xspc[p]+xorig[p])*out_n,
|
|
|
|
memcpy(final_ + (j*yspc[p]+yorig[p])*a->s->img_x*out_n + (i*xspc[p]+xorig[p])*out_n,
|
|
|
|
a->out + (j*x+i)*out_n, out_n);
|
|
|
|
free(a->out);
|
|
|
|
raw += (x*out_n+1)*y;
|
|
|
|
raw_len -= (x*out_n+1)*y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
a->out = final;
|
|
|
|
a->out = final_;
|
|
|
|
|
|
|
|
stbi_png_partial = save;
|
|
|
|
return 1;
|
|
|
|