mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Add zlib_stream_new to file_archive_zlib.c
This commit is contained in:
parent
021d8e6af8
commit
9a23d95846
@ -415,12 +415,6 @@ static int file_archive_parse_file_init(zlib_transfer_t *state,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void *zlib_stream_new(void)
|
||||
{
|
||||
return (z_stream*)calloc(1, sizeof(z_stream));
|
||||
}
|
||||
|
||||
void zlib_deflate_init(void *data, int level)
|
||||
{
|
||||
z_stream *stream = (z_stream*)data;
|
||||
@ -463,7 +457,10 @@ bool file_archive_inflate_data_to_file_init(
|
||||
if (!handle)
|
||||
return false;
|
||||
|
||||
if (!(handle->stream = (z_stream*)zlib_stream_new()))
|
||||
if (!handle->backend)
|
||||
handle->backend = file_archive_get_default_file_backend();
|
||||
|
||||
if (!(handle->stream = (z_stream*)handle->backend->stream_new()))
|
||||
goto error;
|
||||
|
||||
if (!(zlib_inflate_init2(handle->stream)))
|
||||
|
@ -26,6 +26,12 @@
|
||||
#include <file/file_archive.h>
|
||||
#include <retro_file.h>
|
||||
|
||||
static void *zlib_stream_new(void)
|
||||
{
|
||||
return (z_stream*)calloc(1, sizeof(z_stream));
|
||||
}
|
||||
|
||||
const struct zlib_file_backend zlib_backend = {
|
||||
zlib_stream_new,
|
||||
"zlib"
|
||||
};
|
||||
|
@ -786,7 +786,7 @@ static bool rpng_load_image_argb_process_init(rpng_t *rpng,
|
||||
if (rpng->ihdr.interlace == 1) /* To be sure. */
|
||||
rpng->process.inflate_buf_size *= 2;
|
||||
|
||||
rpng->process.stream = zlib_stream_new();
|
||||
rpng->process.stream = rpng->process.stream_backend->stream_new();
|
||||
|
||||
if (!rpng->process.stream)
|
||||
return false;
|
||||
|
@ -213,6 +213,7 @@ static bool rpng_save_image(const char *path,
|
||||
bool ret = true;
|
||||
struct png_ihdr ihdr = {0};
|
||||
|
||||
const struct zlib_file_backend *stream_backend = NULL;
|
||||
size_t encode_buf_size = 0;
|
||||
uint8_t *encode_buf = NULL;
|
||||
uint8_t *deflate_buf = NULL;
|
||||
@ -224,11 +225,12 @@ static bool rpng_save_image(const char *path,
|
||||
uint8_t *prev_encoded = NULL;
|
||||
uint8_t *encode_target = NULL;
|
||||
void *stream = NULL;
|
||||
|
||||
RFILE *file = retro_fopen(path, RFILE_MODE_WRITE, -1);
|
||||
RFILE *file = retro_fopen(path, RFILE_MODE_WRITE, -1);
|
||||
if (!file)
|
||||
GOTO_END_ERROR();
|
||||
|
||||
stream_backend = file_archive_get_default_file_backend();
|
||||
|
||||
if (retro_fwrite(file, png_magic, sizeof(png_magic)) != sizeof(png_magic))
|
||||
GOTO_END_ERROR();
|
||||
|
||||
@ -321,7 +323,7 @@ static bool rpng_save_image(const char *path,
|
||||
if (!deflate_buf)
|
||||
GOTO_END_ERROR();
|
||||
|
||||
stream = zlib_stream_new();
|
||||
stream = stream_backend->stream_new();
|
||||
|
||||
if (!stream)
|
||||
GOTO_END_ERROR();
|
||||
|
@ -28,13 +28,6 @@
|
||||
|
||||
#include <boolean.h>
|
||||
|
||||
typedef struct zlib_handle
|
||||
{
|
||||
void *stream;
|
||||
uint8_t *data;
|
||||
uint32_t real_checksum;
|
||||
} zlib_file_handle_t;
|
||||
|
||||
enum zlib_transfer_type
|
||||
{
|
||||
ZLIB_TRANSFER_NONE = 0,
|
||||
@ -44,6 +37,12 @@ enum zlib_transfer_type
|
||||
ZLIB_TRANSFER_DEINIT_ERROR
|
||||
};
|
||||
|
||||
struct zlib_file_backend
|
||||
{
|
||||
void *(*stream_new)(void);
|
||||
const char *ident;
|
||||
};
|
||||
|
||||
typedef struct zlib_transfer
|
||||
{
|
||||
void *handle;
|
||||
@ -55,15 +54,16 @@ typedef struct zlib_transfer
|
||||
const struct zlib_file_backend *backend;
|
||||
} zlib_transfer_t;
|
||||
|
||||
/* File backends. Can be fleshed out later, but keep it simple for now.
|
||||
* The file is mapped to memory directly (via mmap() or just
|
||||
* plain retro_read_file()).
|
||||
*/
|
||||
|
||||
struct zlib_file_backend
|
||||
typedef struct zlib_handle
|
||||
{
|
||||
const char *ident;
|
||||
};
|
||||
void *stream;
|
||||
uint8_t *data;
|
||||
uint32_t real_checksum;
|
||||
const struct zlib_file_backend *backend;
|
||||
} zlib_file_handle_t;
|
||||
|
||||
|
||||
|
||||
|
||||
/* Returns true when parsing should continue. False to stop. */
|
||||
typedef int (*file_archive_file_cb)(const char *name, const char *valid_exts,
|
||||
@ -155,8 +155,6 @@ bool file_archive_perform_mode(const char *name, const char *valid_exts,
|
||||
struct string_list *compressed_file_list_new(const char *filename,
|
||||
const char* ext);
|
||||
|
||||
void *zlib_stream_new(void);
|
||||
|
||||
void zlib_stream_free(void *data);
|
||||
|
||||
void zlib_deflate_init(void *data, int level);
|
||||
|
Loading…
x
Reference in New Issue
Block a user