Move stream to process_t handle
This commit is contained in:
parent
b6e4266a3d
commit
05e33f1ac4
|
@ -103,7 +103,7 @@ static bool png_reverse_filter(uint32_t *data, const struct png_ihdr *ihdr,
|
||||||
|
|
||||||
png_pass_geom(ihdr, ihdr->width, ihdr->height, &bpp, &pitch, &pass_size);
|
png_pass_geom(ihdr, ihdr->width, ihdr->height, &bpp, &pitch, &pass_size);
|
||||||
|
|
||||||
if (pngp->total_out < pass_size)
|
if (pngp->stream.total_out < pass_size)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
prev_scanline = (uint8_t*)calloc(1, pitch);
|
prev_scanline = (uint8_t*)calloc(1, pitch);
|
||||||
|
@ -227,7 +227,7 @@ static bool png_reverse_filter_adam7(uint32_t *data,
|
||||||
png_pass_geom(&tmp_ihdr, pass_width,
|
png_pass_geom(&tmp_ihdr, pass_width,
|
||||||
pass_height, NULL, NULL, &pass_size);
|
pass_height, NULL, NULL, &pass_size);
|
||||||
|
|
||||||
if (pass_size > pngp->total_out)
|
if (pass_size > pngp->stream.total_out)
|
||||||
{
|
{
|
||||||
free(tmp_data);
|
free(tmp_data);
|
||||||
return false;
|
return false;
|
||||||
|
@ -240,8 +240,8 @@ static bool png_reverse_filter_adam7(uint32_t *data,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inflate_buf += pass_size;
|
inflate_buf += pass_size;
|
||||||
pngp->total_out -= pass_size;
|
pngp->stream.total_out -= pass_size;
|
||||||
|
|
||||||
deinterlace_pass(data,
|
deinterlace_pass(data,
|
||||||
ihdr, tmp_data, pass_width, pass_height, &passes[pass]);
|
ihdr, tmp_data, pass_width, pass_height, &passes[pass]);
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
#include <formats/rpng.h>
|
#include <formats/rpng.h>
|
||||||
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -213,9 +211,8 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||||
long pos, file_len;
|
long pos, file_len;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char header[8];
|
char header[8];
|
||||||
z_stream stream = {0};
|
|
||||||
struct rpng_t rpng = {0};
|
struct rpng_t rpng = {0};
|
||||||
struct rpng_process_t process = {0};
|
struct rpng_process_t process = {{0}};
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
|
|
||||||
*data = NULL;
|
*data = NULL;
|
||||||
|
@ -304,7 +301,7 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||||
if (!rpng.has_ihdr || !rpng.has_idat || !rpng.has_iend)
|
if (!rpng.has_ihdr || !rpng.has_idat || !rpng.has_iend)
|
||||||
GOTO_END_ERROR();
|
GOTO_END_ERROR();
|
||||||
|
|
||||||
if (inflateInit(&stream) != Z_OK)
|
if (inflateInit(&process.stream) != Z_OK)
|
||||||
GOTO_END_ERROR();
|
GOTO_END_ERROR();
|
||||||
|
|
||||||
png_pass_geom(&rpng.ihdr, rpng.ihdr.width, rpng.ihdr.height, NULL, NULL, &rpng.inflate_buf_size);
|
png_pass_geom(&rpng.ihdr, rpng.ihdr.width, rpng.ihdr.height, NULL, NULL, &rpng.inflate_buf_size);
|
||||||
|
@ -315,17 +312,17 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||||
if (!rpng.inflate_buf)
|
if (!rpng.inflate_buf)
|
||||||
GOTO_END_ERROR();
|
GOTO_END_ERROR();
|
||||||
|
|
||||||
stream.next_in = rpng.idat_buf.data;
|
process.stream.next_in = rpng.idat_buf.data;
|
||||||
stream.avail_in = rpng.idat_buf.size;
|
process.stream.avail_in = rpng.idat_buf.size;
|
||||||
stream.avail_out = rpng.inflate_buf_size;
|
process.stream.avail_out = rpng.inflate_buf_size;
|
||||||
stream.next_out = rpng.inflate_buf;
|
process.stream.next_out = rpng.inflate_buf;
|
||||||
|
|
||||||
if (inflate(&stream, Z_FINISH) != Z_STREAM_END)
|
if (inflate(&process.stream, Z_FINISH) != Z_STREAM_END)
|
||||||
{
|
{
|
||||||
inflateEnd(&stream);
|
inflateEnd(&process.stream);
|
||||||
GOTO_END_ERROR();
|
GOTO_END_ERROR();
|
||||||
}
|
}
|
||||||
inflateEnd(&stream);
|
inflateEnd(&process.stream);
|
||||||
|
|
||||||
*width = rpng.ihdr.width;
|
*width = rpng.ihdr.width;
|
||||||
*height = rpng.ihdr.height;
|
*height = rpng.ihdr.height;
|
||||||
|
@ -338,8 +335,6 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
|
||||||
if (!*data)
|
if (!*data)
|
||||||
GOTO_END_ERROR();
|
GOTO_END_ERROR();
|
||||||
|
|
||||||
process.total_out = stream.total_out;
|
|
||||||
|
|
||||||
if (rpng.ihdr.interlace == 1)
|
if (rpng.ihdr.interlace == 1)
|
||||||
{
|
{
|
||||||
if (!png_reverse_filter_adam7(*data,
|
if (!png_reverse_filter_adam7(*data,
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
#include <formats/rpng.h>
|
#include <formats/rpng.h>
|
||||||
|
|
||||||
#include <zlib.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -257,10 +255,9 @@ bool rpng_nbio_load_image_argb_iterate(uint8_t *buf, struct rpng_t *rpng)
|
||||||
bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
|
bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
|
||||||
uint32_t **data, unsigned *width, unsigned *height)
|
uint32_t **data, unsigned *width, unsigned *height)
|
||||||
{
|
{
|
||||||
struct rpng_process_t process = {0};
|
struct rpng_process_t process = {{0}};
|
||||||
z_stream stream = {0};
|
|
||||||
|
|
||||||
if (inflateInit(&stream) != Z_OK)
|
if (inflateInit(&process.stream) != Z_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
png_pass_geom(&rpng->ihdr, rpng->ihdr.width,
|
png_pass_geom(&rpng->ihdr, rpng->ihdr.width,
|
||||||
|
@ -272,17 +269,17 @@ bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
|
||||||
if (!rpng->inflate_buf)
|
if (!rpng->inflate_buf)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
stream.next_in = rpng->idat_buf.data;
|
process.stream.next_in = rpng->idat_buf.data;
|
||||||
stream.avail_in = rpng->idat_buf.size;
|
process.stream.avail_in = rpng->idat_buf.size;
|
||||||
stream.avail_out = rpng->inflate_buf_size;
|
process.stream.avail_out = rpng->inflate_buf_size;
|
||||||
stream.next_out = rpng->inflate_buf;
|
process.stream.next_out = rpng->inflate_buf;
|
||||||
|
|
||||||
if (inflate(&stream, Z_FINISH) != Z_STREAM_END)
|
if (inflate(&process.stream, Z_FINISH) != Z_STREAM_END)
|
||||||
{
|
{
|
||||||
inflateEnd(&stream);
|
inflateEnd(&process.stream);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
inflateEnd(&stream);
|
inflateEnd(&process.stream);
|
||||||
|
|
||||||
*width = rpng->ihdr.width;
|
*width = rpng->ihdr.width;
|
||||||
*height = rpng->ihdr.height;
|
*height = rpng->ihdr.height;
|
||||||
|
@ -297,8 +294,6 @@ bool rpng_nbio_load_image_argb_process(struct rpng_t *rpng,
|
||||||
if (!*data)
|
if (!*data)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
process.total_out = stream.total_out;
|
|
||||||
|
|
||||||
if (rpng->ihdr.interlace == 1)
|
if (rpng->ihdr.interlace == 1)
|
||||||
{
|
{
|
||||||
if (!png_reverse_filter_adam7(*data,
|
if (!png_reverse_filter_adam7(*data,
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
|
#include <zlib.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "../../config.h"
|
#include "../../config.h"
|
||||||
|
@ -62,7 +63,7 @@ struct png_ihdr
|
||||||
|
|
||||||
struct rpng_process_t
|
struct rpng_process_t
|
||||||
{
|
{
|
||||||
size_t total_out;
|
z_stream stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rpng_t
|
struct rpng_t
|
||||||
|
|
Loading…
Reference in New Issue