mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 14:34:33 +02:00
Change in lossless bit-stream.
Change the lossless signature to 0x2f Add 1 bit indicator for 'droppable (or trivial) alpha)'. Add 3 bit lossless version (for future extension like yuv support). Change the sub-resolution information to 3 bits implying range [2 .. 9] Change-Id: Ic7b8c069240bbcd326cf5d5d4cd2dde8667851e2
This commit is contained in:
@ -79,34 +79,37 @@ static int DecodeImageStream(int xsize, int ysize,
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int VP8LCheckSignature(const uint8_t* const data, size_t size) {
|
||||
return (size >= 1) &&
|
||||
(data[0] == VP8L_MAGIC_BYTE || data[0] == VP8L_MAGIC_BYTE_RSVD);
|
||||
return (size >= 1) && (data[0] == VP8L_MAGIC_BYTE);
|
||||
}
|
||||
|
||||
static int ReadImageSize(VP8LBitReader* const br,
|
||||
int* const width, int* const height) {
|
||||
static int ReadImageInfo(VP8LBitReader* const br,
|
||||
int* const width, int* const height,
|
||||
int* const has_alpha) {
|
||||
const uint8_t signature = VP8LReadBits(br, 8);
|
||||
if (!VP8LCheckSignature(&signature, 1)) {
|
||||
return 0;
|
||||
}
|
||||
*width = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1;
|
||||
*height = VP8LReadBits(br, VP8L_IMAGE_SIZE_BITS) + 1;
|
||||
*has_alpha = VP8LReadBits(br, 1);
|
||||
VP8LReadBits(br, VP8L_VERSION_BITS); // Read/ignore the version number.
|
||||
return 1;
|
||||
}
|
||||
|
||||
int VP8LGetInfo(const uint8_t* data, size_t data_size,
|
||||
int* const width, int* const height) {
|
||||
int* const width, int* const height, int* const has_alpha) {
|
||||
if (data == NULL || data_size < kHeaderBytes) {
|
||||
return 0; // not enough data
|
||||
} else {
|
||||
int w, h;
|
||||
int w, h, a;
|
||||
VP8LBitReader br;
|
||||
VP8LInitBitReader(&br, data, data_size);
|
||||
if (!ReadImageSize(&br, &w, &h)) {
|
||||
if (!ReadImageInfo(&br, &w, &h, &a)) {
|
||||
return 0;
|
||||
}
|
||||
if (width != NULL) *width = w;
|
||||
if (height != NULL) *height = h;
|
||||
if (has_alpha != NULL) *has_alpha = a;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -308,7 +311,7 @@ static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
|
||||
int num_htree_groups = 1;
|
||||
|
||||
if (VP8LReadBits(br, 1)) { // use meta Huffman codes
|
||||
const int huffman_precision = VP8LReadBits(br, 4);
|
||||
const int huffman_precision = VP8LReadBits(br, 3) + 2;
|
||||
const int huffman_xsize = VP8LSubSampleSize(xsize, huffman_precision);
|
||||
const int huffman_ysize = VP8LSubSampleSize(ysize, huffman_precision);
|
||||
const int huffman_pixs = huffman_xsize * huffman_ysize;
|
||||
@ -735,7 +738,7 @@ static int ReadTransform(int* const xsize, int const* ysize,
|
||||
switch (type) {
|
||||
case PREDICTOR_TRANSFORM:
|
||||
case CROSS_COLOR_TRANSFORM:
|
||||
transform->bits_ = VP8LReadBits(br, 4);
|
||||
transform->bits_ = VP8LReadBits(br, 3) + 2;
|
||||
ok = DecodeImageStream(VP8LSubSampleSize(transform->xsize_,
|
||||
transform->bits_),
|
||||
VP8LSubSampleSize(transform->ysize_,
|
||||
@ -1006,7 +1009,7 @@ int VP8LDecodeAlphaImageStream(int width, int height, const uint8_t* const data,
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io) {
|
||||
int width, height;
|
||||
int width, height, has_alpha;
|
||||
|
||||
if (dec == NULL) return 0;
|
||||
if (io == NULL) {
|
||||
@ -1017,7 +1020,7 @@ int VP8LDecodeHeader(VP8LDecoder* const dec, VP8Io* const io) {
|
||||
dec->io_ = io;
|
||||
dec->status_ = VP8_STATUS_OK;
|
||||
VP8LInitBitReader(&dec->br_, io->data, io->data_size);
|
||||
if (!ReadImageSize(&dec->br_, &width, &height)) {
|
||||
if (!ReadImageInfo(&dec->br_, &width, &height, &has_alpha)) {
|
||||
dec->status_ = VP8_STATUS_BITSTREAM_ERROR;
|
||||
goto Error;
|
||||
}
|
||||
|
@ -91,11 +91,10 @@ typedef struct {
|
||||
int VP8LCheckSignature(const uint8_t* const data, size_t size);
|
||||
|
||||
// Validates the VP8L data-header and retrieves basic header information viz
|
||||
// width and height. Returns 0 in case of formatting error. width/height
|
||||
// can be passed NULL.
|
||||
// width, height and alpha. Returns 0 in case of formatting error.
|
||||
// width/height/has_alpha can be passed NULL.
|
||||
int VP8LGetInfo(const uint8_t* data, size_t data_size, // data available so far
|
||||
int* const width, int* const height);
|
||||
|
||||
int* const width, int* const height, int* const has_alpha);
|
||||
|
||||
// Decodes a raw image stream (without header) and store the alpha data
|
||||
// into *output, which must be of size width x height. Returns false in case
|
||||
|
@ -577,11 +577,12 @@ static VP8StatusCode GetFeatures(const uint8_t* data, size_t data_size,
|
||||
return VP8_STATUS_BITSTREAM_ERROR;
|
||||
}
|
||||
} else {
|
||||
int has_alpha;
|
||||
// Validates raw VP8L data.
|
||||
if (!VP8LGetInfo(data, data_size, width, height)) {
|
||||
if (!VP8LGetInfo(data, data_size, width, height, &has_alpha)) {
|
||||
return VP8_STATUS_BITSTREAM_ERROR;
|
||||
}
|
||||
features->has_alpha = 1;
|
||||
features->has_alpha = has_alpha;
|
||||
}
|
||||
|
||||
return VP8_STATUS_OK; // Return features from VP8 header.
|
||||
|
Reference in New Issue
Block a user