mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
Tweak magic_number_guess_fourcc negative codes
This commit is contained in:
1 parent
f40ef01244
commit
badce3ffa4
2 files changed
+36
-20
No files matched your search
@@ -22,19 +22,22 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
|||||||
//
|
//
|
||||||
// Keep it sorted by magic[1], then magic[0] descending and finally by
|
// Keep it sorted by magic[1], then magic[0] descending and finally by
|
||||||
// magic[2:]. When multiple entries match, the longest one wins.
|
// magic[2:]. When multiple entries match, the longest one wins.
|
||||||
|
//
|
||||||
|
// The fourcc field might be negated, in which case there's further
|
||||||
|
// specialization (see § below).
|
||||||
static struct {
|
static struct {
|
||||||
int32_t fourcc;
|
int32_t fourcc;
|
||||||
const char* magic;
|
const char* magic;
|
||||||
} table[] = {
|
} table[] = {
|
||||||
{0x30302020, "\x01\x00\x00"}, // '00 'be (see § below)
|
{-0x30302020, "\x01\x00\x00"}, // '00 'be
|
||||||
{0x424D5020, "\x01\x42\x4D"}, // BMP
|
{+0x424D5020, "\x01\x42\x4D"}, // BMP
|
||||||
{0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
|
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
|
||||||
{0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
|
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
|
||||||
{0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||||
{0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF (see § below)
|
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
|
||||||
{0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
||||||
{0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||||
{0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||||
};
|
};
|
||||||
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
||||||
|
|
||||||
@@ -75,7 +78,10 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
match:
|
match:
|
||||||
// Some FourCC values (see § above) are further specialized.
|
// Negative FourCC values (see § above) are further specialized.
|
||||||
|
if (fourcc < 0) {
|
||||||
|
fourcc = -fourcc;
|
||||||
|
|
||||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||||
if (prefix.len < 16) {
|
if (prefix.len < 16) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -89,6 +95,7 @@ match:
|
|||||||
return 0x5750384C; // 'WP8L'be
|
return 0x5750384C; // 'WP8L'be
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (fourcc == 0x30302020) { // '00 'be
|
} else if (fourcc == 0x30302020) { // '00 'be
|
||||||
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
||||||
if (prefix.len < 4) {
|
if (prefix.len < 4) {
|
||||||
@@ -104,5 +111,6 @@ match:
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return fourcc;
|
return fourcc;
|
||||||
}
|
}
|
||||||
@@ -15427,19 +15427,22 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
|||||||
//
|
//
|
||||||
// Keep it sorted by magic[1], then magic[0] descending and finally by
|
// Keep it sorted by magic[1], then magic[0] descending and finally by
|
||||||
// magic[2:]. When multiple entries match, the longest one wins.
|
// magic[2:]. When multiple entries match, the longest one wins.
|
||||||
|
//
|
||||||
|
// The fourcc field might be negated, in which case there's further
|
||||||
|
// specialization (see § below).
|
||||||
static struct {
|
static struct {
|
||||||
int32_t fourcc;
|
int32_t fourcc;
|
||||||
const char* magic;
|
const char* magic;
|
||||||
} table[] = {
|
} table[] = {
|
||||||
{0x30302020, "\x01\x00\x00"}, // '00 'be (see § below)
|
{-0x30302020, "\x01\x00\x00"}, // '00 'be
|
||||||
{0x424D5020, "\x01\x42\x4D"}, // BMP
|
{+0x424D5020, "\x01\x42\x4D"}, // BMP
|
||||||
{0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
|
{+0x47494620, "\x03\x47\x49\x46\x38"}, // GIF
|
||||||
{0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
|
{+0x54494646, "\x03\x49\x49\x2A\x00"}, // TIFF (little-endian)
|
||||||
{0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
{+0x54494646, "\x03\x4D\x4D\x00\x2A"}, // TIFF (big-endian)
|
||||||
{0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF (see § below)
|
{-0x52494646, "\x03\x52\x49\x46\x46"}, // RIFF
|
||||||
{0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
{+0x4E494520, "\x02\x6E\xC3\xAF"}, // NIE
|
||||||
{0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
{+0x504E4720, "\x03\x89\x50\x4E\x47"}, // PNG
|
||||||
{0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
{+0x4A504547, "\x01\xFF\xD8"}, // JPEG
|
||||||
};
|
};
|
||||||
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
static const size_t table_len = sizeof(table) / sizeof(table[0]);
|
||||||
|
|
||||||
@@ -15480,7 +15483,10 @@ wuffs_base__magic_number_guess_fourcc(wuffs_base__slice_u8 prefix) {
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
match:
|
match:
|
||||||
// Some FourCC values (see § above) are further specialized.
|
// Negative FourCC values (see § above) are further specialized.
|
||||||
|
if (fourcc < 0) {
|
||||||
|
fourcc = -fourcc;
|
||||||
|
|
||||||
if (fourcc == 0x52494646) { // 'RIFF'be
|
if (fourcc == 0x52494646) { // 'RIFF'be
|
||||||
if (prefix.len < 16) {
|
if (prefix.len < 16) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -15494,6 +15500,7 @@ match:
|
|||||||
return 0x5750384C; // 'WP8L'be
|
return 0x5750384C; // 'WP8L'be
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (fourcc == 0x30302020) { // '00 'be
|
} else if (fourcc == 0x30302020) { // '00 'be
|
||||||
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
// Binary data starting with multiple 0x00 NUL bytes is quite common.
|
||||||
if (prefix.len < 4) {
|
if (prefix.len < 4) {
|
||||||
@@ -15509,6 +15516,7 @@ match:
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return fourcc;
|
return fourcc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user