mirror of
https://github.com/holub/mame
synced 2025-04-24 09:20:02 +03:00
that doesn't require an instance (nw)
This commit is contained in:
parent
978be5e357
commit
70279ab5a2
@ -815,8 +815,7 @@ ru_imgformat render_detect_image(emu_file &file, const char *dirname, const char
|
||||
return RENDUTIL_IMGFORMAT_ERROR;
|
||||
|
||||
// PNG: check for valid header
|
||||
png_info png;
|
||||
png_error const result = png.verify_header(file);
|
||||
png_error const result = png_info::verify_header(file);
|
||||
if (result == PNGERR_NONE)
|
||||
{
|
||||
file.close();
|
||||
|
@ -66,7 +66,7 @@ void png_info::free_data()
|
||||
|
||||
namespace {
|
||||
|
||||
#define PNG_Signature "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
|
||||
constexpr std::uint8_t PNG_SIGNATURE[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
||||
#define MNG_Signature "\x8A\x4D\x4E\x47\x0D\x0A\x1A\x0A"
|
||||
|
||||
// Chunk names
|
||||
@ -690,21 +690,6 @@ public:
|
||||
return PNGERR_NONE;
|
||||
}
|
||||
|
||||
png_error verify_header(util::core_file &fp)
|
||||
{
|
||||
uint8_t signature[8];
|
||||
|
||||
/* read 8 bytes */
|
||||
if (fp.read(signature, 8) != 8)
|
||||
return PNGERR_FILE_TRUNCATED;
|
||||
|
||||
/* return an error if we don't match */
|
||||
if (memcmp(signature, PNG_Signature, 8) != 0)
|
||||
return PNGERR_BAD_SIGNATURE;
|
||||
|
||||
return PNGERR_NONE;
|
||||
}
|
||||
|
||||
png_error read_file(util::core_file &fp)
|
||||
{
|
||||
// initialize the data structures
|
||||
@ -741,6 +726,21 @@ public:
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
static png_error verify_header(util::core_file &fp)
|
||||
{
|
||||
EQUIVALENT_ARRAY(PNG_SIGNATURE, std::uint8_t) signature;
|
||||
|
||||
// read 8 bytes
|
||||
if (fp.read(signature, sizeof(signature)) != sizeof(signature))
|
||||
return PNGERR_FILE_TRUNCATED;
|
||||
|
||||
// return an error if we don't match
|
||||
if (std::memcmp(signature, PNG_SIGNATURE, sizeof(PNG_SIGNATURE)))
|
||||
return PNGERR_BAD_SIGNATURE;
|
||||
|
||||
return PNGERR_NONE;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr unsigned png_private::ADAM7_X_BIAS[7];
|
||||
@ -762,7 +762,7 @@ constexpr unsigned png_private::ADAM7_Y_OFFS[7];
|
||||
|
||||
png_error png_info::verify_header(util::core_file &fp)
|
||||
{
|
||||
return png_private(*this).verify_header(fp);
|
||||
return png_private::verify_header(fp);
|
||||
}
|
||||
|
||||
|
||||
@ -1230,7 +1230,7 @@ png_error png_write_bitmap(util::core_file &fp, png_info *info, bitmap_t const &
|
||||
info = &pnginfo;
|
||||
|
||||
// write the PNG signature
|
||||
if (fp.write(PNG_Signature, 8) != 8)
|
||||
if (fp.write(PNG_SIGNATURE, sizeof(PNG_SIGNATURE)) != sizeof(PNG_SIGNATURE))
|
||||
return PNGERR_FILE_ERROR;
|
||||
|
||||
/* write the rest of the PNG data */
|
||||
|
@ -57,7 +57,6 @@ public:
|
||||
|
||||
~png_info() { free_data(); }
|
||||
|
||||
png_error verify_header(util::core_file &fp);
|
||||
png_error read_file(util::core_file &fp);
|
||||
png_error copy_to_bitmap(bitmap_argb32 &bitmap, bool &hasalpha);
|
||||
png_error expand_buffer_8bit();
|
||||
@ -67,6 +66,8 @@ public:
|
||||
void free_data();
|
||||
void reset() { free_data(); operator=(png_info()); }
|
||||
|
||||
static png_error verify_header(util::core_file &fp);
|
||||
|
||||
std::unique_ptr<std::uint8_t []> image;
|
||||
std::uint32_t width, height;
|
||||
std::uint32_t xres = 0, yres = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user