summaryrefslogtreecommitdiffstats
path: root/contrib/libs/libwebp/src/dec/alpha_dec.c
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-07-24 10:07:25 +0300
committerrobot-piglet <[email protected]>2025-07-24 10:16:27 +0300
commit1c295121fa6a70a55c0ed79beb993761eac1fadc (patch)
tree0a3af4cf839ddc14d3d2829c3b224c1da409d80c /contrib/libs/libwebp/src/dec/alpha_dec.c
parent026ffc40392187f03308f5ae7445365ad4a1ef7f (diff)
Intermediate changes
commit_hash:9e9c04347de10235f77fcdaf62119e9b89e8bc59
Diffstat (limited to 'contrib/libs/libwebp/src/dec/alpha_dec.c')
-rw-r--r--contrib/libs/libwebp/src/dec/alpha_dec.c124
1 files changed, 64 insertions, 60 deletions
diff --git a/contrib/libs/libwebp/src/dec/alpha_dec.c b/contrib/libs/libwebp/src/dec/alpha_dec.c
index b6c874fb84d..d90bfd2be06 100644
--- a/contrib/libs/libwebp/src/dec/alpha_dec.c
+++ b/contrib/libs/libwebp/src/dec/alpha_dec.c
@@ -11,14 +11,18 @@
//
// Author: Skal ([email protected])
+#include <assert.h>
#include <stdlib.h>
+
#include "src/dec/alphai_dec.h"
#include "src/dec/vp8_dec.h"
#include "src/dec/vp8i_dec.h"
#include "src/dec/vp8li_dec.h"
+#include "src/dec/webpi_dec.h"
#include "src/dsp/dsp.h"
#include "src/utils/quant_levels_dec_utils.h"
#include "src/utils/utils.h"
+#include "src/webp/decode.h"
#include "src/webp/format_constants.h"
#include "src/webp/types.h"
@@ -34,8 +38,8 @@ WEBP_NODISCARD static ALPHDecoder* ALPHNew(void) {
// Clears and deallocates an alpha decoder instance.
static void ALPHDelete(ALPHDecoder* const dec) {
if (dec != NULL) {
- VP8LDelete(dec->vp8l_dec_);
- dec->vp8l_dec_ = NULL;
+ VP8LDelete(dec->vp8l_dec);
+ dec->vp8l_dec = NULL;
WebPSafeFree(dec);
}
}
@@ -54,28 +58,28 @@ WEBP_NODISCARD static int ALPHInit(ALPHDecoder* const dec, const uint8_t* data,
const uint8_t* const alpha_data = data + ALPHA_HEADER_LEN;
const size_t alpha_data_size = data_size - ALPHA_HEADER_LEN;
int rsrv;
- VP8Io* const io = &dec->io_;
+ VP8Io* const io = &dec->io;
assert(data != NULL && output != NULL && src_io != NULL);
VP8FiltersInit();
- dec->output_ = output;
- dec->width_ = src_io->width;
- dec->height_ = src_io->height;
- assert(dec->width_ > 0 && dec->height_ > 0);
+ dec->output = output;
+ dec->width = src_io->width;
+ dec->height = src_io->height;
+ assert(dec->width > 0 && dec->height > 0);
if (data_size <= ALPHA_HEADER_LEN) {
return 0;
}
- dec->method_ = (data[0] >> 0) & 0x03;
- dec->filter_ = (WEBP_FILTER_TYPE)((data[0] >> 2) & 0x03);
- dec->pre_processing_ = (data[0] >> 4) & 0x03;
+ dec->method = (data[0] >> 0) & 0x03;
+ dec->filter = (WEBP_FILTER_TYPE)((data[0] >> 2) & 0x03);
+ dec->pre_processing = (data[0] >> 4) & 0x03;
rsrv = (data[0] >> 6) & 0x03;
- if (dec->method_ < ALPHA_NO_COMPRESSION ||
- dec->method_ > ALPHA_LOSSLESS_COMPRESSION ||
- dec->filter_ >= WEBP_FILTER_LAST ||
- dec->pre_processing_ > ALPHA_PREPROCESSED_LEVELS ||
+ if (dec->method < ALPHA_NO_COMPRESSION ||
+ dec->method > ALPHA_LOSSLESS_COMPRESSION ||
+ dec->filter >= WEBP_FILTER_LAST ||
+ dec->pre_processing > ALPHA_PREPROCESSED_LEVELS ||
rsrv != 0) {
return 0;
}
@@ -96,11 +100,11 @@ WEBP_NODISCARD static int ALPHInit(ALPHDecoder* const dec, const uint8_t* data,
io->crop_bottom = src_io->crop_bottom;
// No need to copy the scaling parameters.
- if (dec->method_ == ALPHA_NO_COMPRESSION) {
- const size_t alpha_decoded_size = dec->width_ * dec->height_;
+ if (dec->method == ALPHA_NO_COMPRESSION) {
+ const size_t alpha_decoded_size = dec->width * dec->height;
ok = (alpha_data_size >= alpha_decoded_size);
} else {
- assert(dec->method_ == ALPHA_LOSSLESS_COMPRESSION);
+ assert(dec->method == ALPHA_LOSSLESS_COMPRESSION);
ok = VP8LDecodeAlphaHeader(dec, alpha_data, alpha_data_size);
}
@@ -113,32 +117,32 @@ WEBP_NODISCARD static int ALPHInit(ALPHDecoder* const dec, const uint8_t* data,
// Returns false in case of bitstream error.
WEBP_NODISCARD static int ALPHDecode(VP8Decoder* const dec, int row,
int num_rows) {
- ALPHDecoder* const alph_dec = dec->alph_dec_;
- const int width = alph_dec->width_;
- const int height = alph_dec->io_.crop_bottom;
- if (alph_dec->method_ == ALPHA_NO_COMPRESSION) {
+ ALPHDecoder* const alph_dec = dec->alph_dec;
+ const int width = alph_dec->width;
+ const int height = alph_dec->io.crop_bottom;
+ if (alph_dec->method == ALPHA_NO_COMPRESSION) {
int y;
- const uint8_t* prev_line = dec->alpha_prev_line_;
- const uint8_t* deltas = dec->alpha_data_ + ALPHA_HEADER_LEN + row * width;
- uint8_t* dst = dec->alpha_plane_ + row * width;
- assert(deltas <= &dec->alpha_data_[dec->alpha_data_size_]);
- assert(WebPUnfilters[alph_dec->filter_] != NULL);
+ const uint8_t* prev_line = dec->alpha_prev_line;
+ const uint8_t* deltas = dec->alpha_data + ALPHA_HEADER_LEN + row * width;
+ uint8_t* dst = dec->alpha_plane + row * width;
+ assert(deltas <= &dec->alpha_data[dec->alpha_data_size]);
+ assert(WebPUnfilters[alph_dec->filter] != NULL);
for (y = 0; y < num_rows; ++y) {
- WebPUnfilters[alph_dec->filter_](prev_line, deltas, dst, width);
+ WebPUnfilters[alph_dec->filter](prev_line, deltas, dst, width);
prev_line = dst;
dst += width;
deltas += width;
}
- dec->alpha_prev_line_ = prev_line;
- } else { // alph_dec->method_ == ALPHA_LOSSLESS_COMPRESSION
- assert(alph_dec->vp8l_dec_ != NULL);
+ dec->alpha_prev_line = prev_line;
+ } else { // alph_dec->method == ALPHA_LOSSLESS_COMPRESSION
+ assert(alph_dec->vp8l_dec != NULL);
if (!VP8LDecodeAlphaImageStream(alph_dec, row + num_rows)) {
return 0;
}
}
if (row + num_rows >= height) {
- dec->is_alpha_decoded_ = 1;
+ dec->is_alpha_decoded = 1;
}
return 1;
}
@@ -148,25 +152,25 @@ WEBP_NODISCARD static int AllocateAlphaPlane(VP8Decoder* const dec,
const int stride = io->width;
const int height = io->crop_bottom;
const uint64_t alpha_size = (uint64_t)stride * height;
- assert(dec->alpha_plane_mem_ == NULL);
- dec->alpha_plane_mem_ =
- (uint8_t*)WebPSafeMalloc(alpha_size, sizeof(*dec->alpha_plane_));
- if (dec->alpha_plane_mem_ == NULL) {
+ assert(dec->alpha_plane_mem == NULL);
+ dec->alpha_plane_mem =
+ (uint8_t*)WebPSafeMalloc(alpha_size, sizeof(*dec->alpha_plane));
+ if (dec->alpha_plane_mem == NULL) {
return VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY,
"Alpha decoder initialization failed.");
}
- dec->alpha_plane_ = dec->alpha_plane_mem_;
- dec->alpha_prev_line_ = NULL;
+ dec->alpha_plane = dec->alpha_plane_mem;
+ dec->alpha_prev_line = NULL;
return 1;
}
void WebPDeallocateAlphaMemory(VP8Decoder* const dec) {
assert(dec != NULL);
- WebPSafeFree(dec->alpha_plane_mem_);
- dec->alpha_plane_mem_ = NULL;
- dec->alpha_plane_ = NULL;
- ALPHDelete(dec->alph_dec_);
- dec->alph_dec_ = NULL;
+ WebPSafeFree(dec->alpha_plane_mem);
+ dec->alpha_plane_mem = NULL;
+ dec->alpha_plane = NULL;
+ ALPHDelete(dec->alph_dec);
+ dec->alph_dec = NULL;
}
//------------------------------------------------------------------------------
@@ -184,46 +188,46 @@ WEBP_NODISCARD const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
return NULL;
}
- if (!dec->is_alpha_decoded_) {
- if (dec->alph_dec_ == NULL) { // Initialize decoder.
- dec->alph_dec_ = ALPHNew();
- if (dec->alph_dec_ == NULL) {
+ if (!dec->is_alpha_decoded) {
+ if (dec->alph_dec == NULL) { // Initialize decoder.
+ dec->alph_dec = ALPHNew();
+ if (dec->alph_dec == NULL) {
VP8SetError(dec, VP8_STATUS_OUT_OF_MEMORY,
"Alpha decoder initialization failed.");
return NULL;
}
if (!AllocateAlphaPlane(dec, io)) goto Error;
- if (!ALPHInit(dec->alph_dec_, dec->alpha_data_, dec->alpha_data_size_,
- io, dec->alpha_plane_)) {
- VP8LDecoder* const vp8l_dec = dec->alph_dec_->vp8l_dec_;
+ if (!ALPHInit(dec->alph_dec, dec->alpha_data, dec->alpha_data_size,
+ io, dec->alpha_plane)) {
+ VP8LDecoder* const vp8l_dec = dec->alph_dec->vp8l_dec;
VP8SetError(dec,
(vp8l_dec == NULL) ? VP8_STATUS_OUT_OF_MEMORY
- : vp8l_dec->status_,
+ : vp8l_dec->status,
"Alpha decoder initialization failed.");
goto Error;
}
// if we allowed use of alpha dithering, check whether it's needed at all
- if (dec->alph_dec_->pre_processing_ != ALPHA_PREPROCESSED_LEVELS) {
- dec->alpha_dithering_ = 0; // disable dithering
+ if (dec->alph_dec->pre_processing != ALPHA_PREPROCESSED_LEVELS) {
+ dec->alpha_dithering = 0; // disable dithering
} else {
num_rows = height - row; // decode everything in one pass
}
}
- assert(dec->alph_dec_ != NULL);
+ assert(dec->alph_dec != NULL);
assert(row + num_rows <= height);
if (!ALPHDecode(dec, row, num_rows)) goto Error;
- if (dec->is_alpha_decoded_) { // finished?
- ALPHDelete(dec->alph_dec_);
- dec->alph_dec_ = NULL;
- if (dec->alpha_dithering_ > 0) {
- uint8_t* const alpha = dec->alpha_plane_ + io->crop_top * width
+ if (dec->is_alpha_decoded) { // finished?
+ ALPHDelete(dec->alph_dec);
+ dec->alph_dec = NULL;
+ if (dec->alpha_dithering > 0) {
+ uint8_t* const alpha = dec->alpha_plane + io->crop_top * width
+ io->crop_left;
if (!WebPDequantizeLevels(alpha,
io->crop_right - io->crop_left,
io->crop_bottom - io->crop_top,
- width, dec->alpha_dithering_)) {
+ width, dec->alpha_dithering)) {
goto Error;
}
}
@@ -231,7 +235,7 @@ WEBP_NODISCARD const uint8_t* VP8DecompressAlphaRows(VP8Decoder* const dec,
}
// Return a pointer to the current decoded row.
- return dec->alpha_plane_ + row * width;
+ return dec->alpha_plane + row * width;
Error:
WebPDeallocateAlphaMemory(dec);