From 5d776f15b6c6950d92c785033791e28d864ea02b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 29 Mar 2015 15:35:55 +0200 Subject: [PATCH] Create zlib_set_stream --- libretro-common/file/file_extract.c | 29 ++++++++++++++++++--- libretro-common/formats/png/rpng_decode.c | 10 ++++--- libretro-common/formats/png/rpng_encode.c | 10 ++++--- libretro-common/include/file/file_extract.h | 7 +++++ 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/libretro-common/file/file_extract.c b/libretro-common/file/file_extract.c index 761b518f2b..b28c52693b 100644 --- a/libretro-common/file/file_extract.c +++ b/libretro-common/file/file_extract.c @@ -349,10 +349,12 @@ bool zlib_inflate_data_to_file_init( if (!stream) goto error; - stream->next_in = (uint8_t*)cdata; - stream->avail_in = csize; - stream->next_out = handle->data; - stream->avail_out = size; + zlib_set_stream(stream, + csize, + size, + (const uint8_t*)cdata, + handle->data + ); return true; @@ -778,3 +780,22 @@ bool zlib_perform_mode(const char *path, const char *valid_exts, return true; } + +void zlib_set_stream(void *data, + uint32_t avail_in, + uint32_t avail_out, + const uint8_t *next_in, + uint8_t *next_out + ) +{ + z_stream *stream = (z_stream*)data; + + if (!stream) + return; + + stream->avail_in = avail_in; + stream->avail_out = avail_out; + + stream->next_in = (uint8_t*)next_in; + stream->next_out = next_out; +} diff --git a/libretro-common/formats/png/rpng_decode.c b/libretro-common/formats/png/rpng_decode.c index f858817dbd..28c84206dd 100644 --- a/libretro-common/formats/png/rpng_decode.c +++ b/libretro-common/formats/png/rpng_decode.c @@ -655,10 +655,12 @@ bool rpng_load_image_argb_process_init(struct rpng_t *rpng, if (!rpng->process.inflate_buf) return false; - rpng->process.stream.next_in = rpng->idat_buf.data; - rpng->process.stream.avail_in = rpng->idat_buf.size; - rpng->process.stream.avail_out = rpng->process.inflate_buf_size; - rpng->process.stream.next_out = rpng->process.inflate_buf; + zlib_set_stream( + &rpng->process.stream, + rpng->idat_buf.size, + rpng->process.inflate_buf_size, + rpng->idat_buf.data, + rpng->process.inflate_buf); rpng->process.initialized = true; diff --git a/libretro-common/formats/png/rpng_encode.c b/libretro-common/formats/png/rpng_encode.c index 433b2ca9cd..db55112280 100644 --- a/libretro-common/formats/png/rpng_encode.c +++ b/libretro-common/formats/png/rpng_encode.c @@ -310,10 +310,12 @@ static bool rpng_save_image(const char *path, if (!deflate_buf) GOTO_END_ERROR(); - stream.next_in = encode_buf; - stream.avail_in = encode_buf_size; - stream.next_out = deflate_buf + 8; - stream.avail_out = encode_buf_size * 2; + zlib_set_stream( + &stream, + encode_buf_size, + encode_buf_size * 2, + encode_buf, + deflate_buf + 8); deflateInit(&stream, 9); if (deflate(&stream, Z_FINISH) != Z_STREAM_END) diff --git a/libretro-common/include/file/file_extract.h b/libretro-common/include/file/file_extract.h index 8f8a5dc0b5..ae79cf3f0f 100644 --- a/libretro-common/include/file/file_extract.h +++ b/libretro-common/include/file/file_extract.h @@ -121,5 +121,12 @@ bool zlib_inflate_init(void *data); bool zlib_inflate_init2(void *data); +void zlib_set_stream(void *data, + uint32_t avail_in, + uint32_t avail_out, + const uint8_t *next_in, + uint8_t *next_out + ); + #endif