updated webp to version 0.3.1
This commit is contained in:
62
3rdparty/libwebp/dec/alpha.c
vendored
62
3rdparty/libwebp/dec/alpha.c
vendored
@@ -1,8 +1,10 @@
|
||||
// Copyright 2011 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// This code is licensed under the same terms as WebM:
|
||||
// Software License Agreement: http://www.webmproject.org/license/software/
|
||||
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
||||
// Use of this source code is governed by a BSD-style license
|
||||
// that can be found in the COPYING file in the root of the source
|
||||
// tree. An additional intellectual property rights grant can be found
|
||||
// in the file PATENTS. All contributing project authors may
|
||||
// be found in the AUTHORS file in the root of the source tree.
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// Alpha-plane decompression.
|
||||
@@ -20,20 +22,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// TODO(skal): move to dsp/ ?
|
||||
static void CopyPlane(const uint8_t* src, int src_stride,
|
||||
uint8_t* dst, int dst_stride, int width, int height) {
|
||||
while (height-- > 0) {
|
||||
memcpy(dst, src, width);
|
||||
src += src_stride;
|
||||
dst += dst_stride;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Decodes the compressed data 'data' of size 'data_size' into the 'output'.
|
||||
// The 'output' buffer should be pre-allocated and must be of the same
|
||||
// dimension 'height'x'stride', as that of the image.
|
||||
// dimension 'height'x'width', as that of the image.
|
||||
//
|
||||
// Returns 1 on successfully decoding the compressed alpha and
|
||||
// 0 if either:
|
||||
@@ -41,16 +33,16 @@ static void CopyPlane(const uint8_t* src, int src_stride,
|
||||
// error returned by appropriate compression method.
|
||||
|
||||
static int DecodeAlpha(const uint8_t* data, size_t data_size,
|
||||
int width, int height, int stride, uint8_t* output) {
|
||||
uint8_t* decoded_data = NULL;
|
||||
const size_t decoded_size = height * width;
|
||||
int width, int height, uint8_t* output) {
|
||||
WEBP_FILTER_TYPE filter;
|
||||
int pre_processing;
|
||||
int rsrv;
|
||||
int ok = 0;
|
||||
int method;
|
||||
const uint8_t* const alpha_data = data + ALPHA_HEADER_LEN;
|
||||
const size_t alpha_data_size = data_size - ALPHA_HEADER_LEN;
|
||||
|
||||
assert(width > 0 && height > 0 && stride >= width);
|
||||
assert(width > 0 && height > 0);
|
||||
assert(data != NULL && output != NULL);
|
||||
|
||||
if (data_size <= ALPHA_HEADER_LEN) {
|
||||
@@ -70,15 +62,12 @@ static int DecodeAlpha(const uint8_t* data, size_t data_size,
|
||||
}
|
||||
|
||||
if (method == ALPHA_NO_COMPRESSION) {
|
||||
ok = (data_size >= decoded_size);
|
||||
decoded_data = (uint8_t*)data + ALPHA_HEADER_LEN;
|
||||
const size_t alpha_decoded_size = height * width;
|
||||
ok = (alpha_data_size >= alpha_decoded_size);
|
||||
if (ok) memcpy(output, alpha_data, alpha_decoded_size);
|
||||
} else {
|
||||
decoded_data = (uint8_t*)malloc(decoded_size);
|
||||
if (decoded_data == NULL) return 0;
|
||||
ok = VP8LDecodeAlphaImageStream(width, height,
|
||||
data + ALPHA_HEADER_LEN,
|
||||
data_size - ALPHA_HEADER_LEN,
|
||||
decoded_data);
|
||||
ok = VP8LDecodeAlphaImageStream(width, height, alpha_data, alpha_data_size,
|
||||
output);
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
@@ -86,18 +75,13 @@ static int DecodeAlpha(const uint8_t* data, size_t data_size,
|
||||
if (unfilter_func != NULL) {
|
||||
// TODO(vikas): Implement on-the-fly decoding & filter mechanism to decode
|
||||
// and apply filter per image-row.
|
||||
unfilter_func(width, height, width, decoded_data);
|
||||
unfilter_func(width, height, width, output);
|
||||
}
|
||||
// Construct raw_data (height x stride) from alpha data (height x width).
|
||||
CopyPlane(decoded_data, width, output, stride, width, height);
|
||||
if (pre_processing == ALPHA_PREPROCESSED_LEVELS) {
|
||||
ok = DequantizeLevels(decoded_data, width, height);
|
||||
ok = DequantizeLevels(output, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
if (method != ALPHA_NO_COMPRESSION) {
|
||||
free(decoded_data);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -105,23 +89,25 @@ static int DecodeAlpha(const uint8_t* data, size_t data_size,
|
||||
|
||||
const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
|
||||
int row, int num_rows) {
|
||||
const int stride = dec->pic_hdr_.width_;
|
||||
const int width = dec->pic_hdr_.width_;
|
||||
const int height = dec->pic_hdr_.height_;
|
||||
|
||||
if (row < 0 || num_rows < 0 || row + num_rows > dec->pic_hdr_.height_) {
|
||||
if (row < 0 || num_rows < 0 || row + num_rows > height) {
|
||||
return NULL; // sanity check.
|
||||
}
|
||||
|
||||
if (row == 0) {
|
||||
// Decode everything during the first call.
|
||||
assert(!dec->is_alpha_decoded_);
|
||||
if (!DecodeAlpha(dec->alpha_data_, (size_t)dec->alpha_data_size_,
|
||||
dec->pic_hdr_.width_, dec->pic_hdr_.height_, stride,
|
||||
dec->alpha_plane_)) {
|
||||
width, height, dec->alpha_plane_)) {
|
||||
return NULL; // Error.
|
||||
}
|
||||
dec->is_alpha_decoded_ = 1;
|
||||
}
|
||||
|
||||
// Return a pointer to the current decoded row.
|
||||
return dec->alpha_plane_ + row * stride;
|
||||
return dec->alpha_plane_ + row * width;
|
||||
}
|
||||
|
||||
#if defined(__cplusplus) || defined(c_plusplus)
|
||||
|
Reference in New Issue
Block a user