VP8GetInfo() + WebPResetDecParams()

- add an internal VP8GetInfo() to parse header
- add WebPResetDecParams() for proper initialization

Change-Id: Ic39ea634d1d8016d25bdcfef2cb0d00b6dad83e9
This commit is contained in:
Pascal Massimino
2011-05-19 19:07:01 -07:00
parent 416b7a6b95
commit 92e5c6e1d4
5 changed files with 75 additions and 52 deletions

View File

@ -74,6 +74,44 @@ int VP8SetError(VP8Decoder* const dec,
return 0;
}
//-----------------------------------------------------------------------------
int VP8GetInfo(const uint8_t* data, uint32_t chunk_size,
int *width, int *height) {
// check signature
if (data[3] != 0x9d || data[4] != 0x01 || data[5] != 0x2a) {
return 0; // Wrong signature.
} else {
const uint32_t bits = data[0] | (data[1] << 8) | (data[2] << 16);
const int key_frame = !(bits & 1);
const int w = ((data[7] << 8) | data[6]) & 0x3fff;
const int h = ((data[9] << 8) | data[8]) & 0x3fff;
if (!key_frame) { // Not a keyframe.
return 0;
}
if (((bits >> 1) & 7) > 3) {
return 0; // unknown profile
}
if (!((bits >> 4) & 1)) {
return 0; // first frame is invisible!
}
if (((bits >> 5)) >= chunk_size) { // partition_length
return 0; // inconsistent size information.
}
if (width) {
*width = w;
}
if (height) {
*height = h;
}
return 1;
}
}
//-----------------------------------------------------------------------------
// Header parsing