make width/height coding match the spec

* width/height in VP8X chunk is 24bit now
* Added some more constants #defines

Change-Id: I2f8ca7f965a247bccd341dd079ed2abf549c39d7
This commit is contained in:
Pascal Massimino
2012-06-28 00:20:28 -07:00
parent 637a314f97
commit e012dfd90f
7 changed files with 59 additions and 30 deletions

View File

@ -133,9 +133,19 @@ static WEBP_INLINE uint8_t GetByte(MemBuffer* const mem) {
return byte;
}
static WEBP_INLINE int ReadLE24s(const uint8_t* const data) {
return (int)(data[0] << 0) | (data[1] << 8) | (data[2] << 16);
}
static WEBP_INLINE uint32_t ReadLE32(const uint8_t* const data) {
return (uint32_t)(data[0] << 0 | (data[1] << 8) |
(data[2] << 16) | (data[3] << 24));
return (uint32_t)ReadLE24s(data) | (data[3] << 24);
}
static WEBP_INLINE int GetLE24s(MemBuffer* const mem) {
const uint8_t* const data = mem->buf_ + mem->start_;
const uint32_t val = ReadLE24s(data);
Skip(mem, 3);
return val;
}
static WEBP_INLINE uint32_t GetLE32(MemBuffer* const mem) {
@ -432,8 +442,8 @@ static ParseStatus ParseVP8X(WebPDemuxer* const dmux) {
dmux->feature_flags_ = GetByte(mem);
Skip(mem, 3); // Reserved.
dmux->canvas_width_ = GetLE32s(mem);
dmux->canvas_height_ = GetLE32s(mem);
dmux->canvas_width_ = 1 + GetLE24s(mem);
dmux->canvas_height_ = 1 + GetLE24s(mem);
Skip(mem, vp8x_size - VP8X_CHUNK_SIZE); // skip any trailing data.
dmux->state_ = WEBP_DEMUX_PARSED_HEADER;

View File

@ -569,10 +569,10 @@ static WebPMuxError GetImageCanvasWidthHeight(
}
// VP8X format:
// Total Size : 12,
// Total Size : 10,
// Flags : 4 bytes,
// Width : 4 bytes,
// Height : 4 bytes.
// Width : 3 bytes,
// Height : 3 bytes.
static WebPMuxError CreateVP8XChunk(WebPMux* const mux) {
WebPMuxError err = WEBP_MUX_OK;
uint32_t flags = 0;
@ -635,8 +635,8 @@ static WebPMuxError CreateVP8XChunk(WebPMux* const mux) {
}
PutLE32(data + 0, flags); // VP8X chunk flags.
PutLE32(data + 4, width); // canvas width.
PutLE32(data + 8, height); // canvas height.
PutLE24(data + 4, width - 1); // canvas width.
PutLE24(data + 7, height - 1); // canvas height.
err = MuxAddChunk(mux, 1, kChunks[IDX_VP8X].tag, data, data_size, NULL, 1);
return err;

View File

@ -108,11 +108,16 @@ static WEBP_INLINE uint32_t GetLE32(const uint8_t* const data) {
return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
}
static WEBP_INLINE void PutLE16(uint8_t* const data, uint16_t val) {
static WEBP_INLINE void PutLE16(uint8_t* const data, uint32_t val) {
data[0] = (val >> 0) & 0xff;
data[1] = (val >> 8) & 0xff;
}
static WEBP_INLINE void PutLE24(uint8_t* const data, uint32_t val) {
PutLE16(data, val);
data[2] = (val >> 16);
}
static WEBP_INLINE void PutLE32(uint8_t* const data, uint32_t val) {
PutLE16(data, val);
PutLE16(data + 2, val >> 16);

View File

@ -215,11 +215,13 @@ WebPMuxError WebPMuxGetFeatures(const WebPMux* const mux, uint32_t* flags) {
static uint8_t* EmitVP8XChunk(uint8_t* const dst, uint32_t width,
uint32_t height, uint32_t flags) {
const size_t vp8x_size = CHUNK_HEADER_SIZE + VP8X_CHUNK_SIZE;
assert(width >= 1 && height >= 1);
assert(width <= MAX_CANVAS_SIZE && height <= MAX_CANVAS_SIZE);
PutLE32(dst, mktag('V', 'P', '8', 'X'));
PutLE32(dst + TAG_SIZE, VP8X_CHUNK_SIZE);
PutLE32(dst + CHUNK_HEADER_SIZE, flags);
PutLE32(dst + CHUNK_HEADER_SIZE + 4, width);
PutLE32(dst + CHUNK_HEADER_SIZE + 8, height);
PutLE24(dst + CHUNK_HEADER_SIZE + 4, width - 1);
PutLE24(dst + CHUNK_HEADER_SIZE + 7, height - 1);
return dst + vp8x_size;
}