This commit is contained in:
twinaphex 2015-02-20 02:10:05 +01:00
parent 4cde17457a
commit 4d631cba30

View File

@ -22,12 +22,6 @@
#include <formats/rpng.h>
/*
* temporarily added by cxd4 (due to slowness at learning the NBIO API)
* In a future commit, this should be replaced with <file/nbio.h>.
*/
#include <file_ops.h>
#include <zlib.h>
#include <stdio.h>
@ -774,22 +768,22 @@ bool rpng_load_image_argb_process(uint8_t *inflate_buf,
return true;
}
static bool rpng_load_image_argb_init(
const char * path,
static bool rpng_load_image_argb_init(FILE *file,
uint32_t **data,
unsigned *width, unsigned *height,
ssize_t *file_len)
long *file_len)
{
uint8_t * header;
char header[8];
*data = NULL;
*width = 0;
*height = 0;
if (!read_file(path, (void **)&header, file_len))
return false;
fseek(file, 0, SEEK_END);
*file_len = ftell(file);
rewind(file);
if (*file_len < sizeof(png_magic))
if (fread(header, 1, sizeof(header), file) != sizeof(header))
return false;
if (memcmp(header, png_magic, sizeof(png_magic)) != 0)
@ -801,8 +795,7 @@ static bool rpng_load_image_argb_init(
bool rpng_load_image_argb(const char *path, uint32_t **data,
unsigned *width, unsigned *height)
{
ssize_t pos, file_len;
FILE * file;
long pos, file_len;
uint8_t *inflate_buf = NULL;
struct idat_buffer idat_buf = {0};
struct png_ihdr ihdr = {0};
@ -812,20 +805,20 @@ bool rpng_load_image_argb(const char *path, uint32_t **data,
bool has_iend = false;
bool has_plte = false;
bool ret = true;
FILE *file = fopen(path, "rb");
if (!rpng_load_image_argb_init(path, data, width, height, &file_len))
GOTO_END_ERROR();
/* feof() apparently isn't triggered after a seek (IEND). */
file = fopen(path, "rb");
if (file == NULL)
if (!file)
{
fprintf(stderr, "Tried to open file: %s\n", path);
GOTO_END_ERROR();
}
for (pos = 0; pos < file_len && pos >= 0; pos = (ssize_t)ftell(file))
if (!rpng_load_image_argb_init(file, data, width, height, &file_len))
GOTO_END_ERROR();
/* feof() apparently isn't triggered after a seek (IEND). */
for (pos = 0; pos < file_len && pos >= 0; pos = ftell(file))
{
size_t increment = 0;
struct png_chunk chunk = {0};
@ -1189,4 +1182,3 @@ bool rpng_save_image_bgr24(const char *path, const uint8_t *data,
}
#endif