(RPNG) Use retro_file for rpng_encode.c

This commit is contained in:
twinaphex 2015-09-19 01:47:03 +02:00
parent 181219ea32
commit 714b3e3126
2 changed files with 13 additions and 13 deletions

View File

@ -1016,4 +1016,3 @@ end:
free(*data);
return ret;
}

View File

@ -24,6 +24,8 @@
#include <stdlib.h>
#include <string.h>
#include <retro_file.h>
#include "rpng_internal.h"
#undef GOTO_END_ERROR
@ -43,16 +45,16 @@ static void dword_write_be(uint8_t *buf, uint32_t val)
*buf++ = (uint8_t)(val >> 0);
}
static bool png_write_crc(FILE *file, const uint8_t *data, size_t size)
static bool png_write_crc(RFILE *file, const uint8_t *data, size_t size)
{
uint8_t crc_raw[4] = {0};
uint32_t crc = zlib_crc32_calculate(data, size);
dword_write_be(crc_raw, crc);
return fwrite(crc_raw, 1, sizeof(crc_raw), file) == sizeof(crc_raw);
return retro_fwrite(file, crc_raw, sizeof(crc_raw)) == sizeof(crc_raw);
}
static bool png_write_ihdr(FILE *file, const struct png_ihdr *ihdr)
static bool png_write_ihdr(RFILE *file, const struct png_ihdr *ihdr)
{
uint8_t ihdr_raw[21];
@ -81,7 +83,7 @@ static bool png_write_ihdr(FILE *file, const struct png_ihdr *ihdr)
dword_write_be(ihdr_raw + 0, sizeof(ihdr_raw) - 8);
dword_write_be(ihdr_raw + 8, ihdr->width);
dword_write_be(ihdr_raw + 12, ihdr->height);
if (fwrite(ihdr_raw, 1, sizeof(ihdr_raw), file) != sizeof(ihdr_raw))
if (retro_fwrite(file, ihdr_raw, sizeof(ihdr_raw)) != sizeof(ihdr_raw))
return false;
if (!png_write_crc(file, ihdr_raw + sizeof(uint32_t),
@ -91,9 +93,9 @@ static bool png_write_ihdr(FILE *file, const struct png_ihdr *ihdr)
return true;
}
static bool png_write_idat(FILE *file, const uint8_t *data, size_t size)
static bool png_write_idat(RFILE *file, const uint8_t *data, size_t size)
{
if (fwrite(data, 1, size, file) != size)
if (retro_fwrite(file, data, size) != size)
return false;
if (!png_write_crc(file, data + sizeof(uint32_t), size - sizeof(uint32_t)))
@ -102,14 +104,14 @@ static bool png_write_idat(FILE *file, const uint8_t *data, size_t size)
return true;
}
static bool png_write_iend(FILE *file)
static bool png_write_iend(RFILE *file)
{
const uint8_t data[] = {
0, 0, 0, 0,
'I', 'E', 'N', 'D',
};
if (fwrite(data, 1, sizeof(data), file) != sizeof(data))
if (retro_fwrite(file, data, sizeof(data)) != sizeof(data))
return false;
if (!png_write_crc(file, data + sizeof(uint32_t),
@ -223,11 +225,11 @@ static bool rpng_save_image(const char *path,
uint8_t *encode_target = NULL;
void *stream = NULL;
FILE *file = fopen(path, "wb");
RFILE *file = retro_fopen(path, RFILE_MODE_WRITE, -1);
if (!file)
GOTO_END_ERROR();
if (fwrite(png_magic, 1, sizeof(png_magic), file) != sizeof(png_magic))
if (retro_fwrite(file, png_magic, sizeof(png_magic)) != sizeof(png_magic))
GOTO_END_ERROR();
ihdr.width = width;
@ -350,8 +352,7 @@ static bool rpng_save_image(const char *path,
GOTO_END_ERROR();
end:
if (file)
fclose(file);
retro_fclose(file);
free(encode_buf);
free(deflate_buf);
free(rgba_line);