Path: blob/master/thirdparty/libwebp/src/dec/webpi_dec.h
21423 views
// Copyright 2011 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Internal header: WebP decoding parameters and custom IO on buffer10//11// Author: [email protected] (Somnath Banerjee)1213#ifndef WEBP_DEC_WEBPI_DEC_H_14#define WEBP_DEC_WEBPI_DEC_H_1516#ifdef __cplusplus17extern "C" {18#endif1920#include <stddef.h>2122#include "src/dec/vp8_dec.h"23#include "src/utils/rescaler_utils.h"24#include "src/webp/decode.h"25#include "src/webp/types.h"2627//------------------------------------------------------------------------------28// WebPDecParams: Decoding output parameters. Transient internal object.2930typedef struct WebPDecParams WebPDecParams;31typedef int (*OutputFunc)(const VP8Io* const io, WebPDecParams* const p);32typedef int (*OutputAlphaFunc)(const VP8Io* const io, WebPDecParams* const p,33int expected_num_out_lines);34typedef int (*OutputRowFunc)(WebPDecParams* const p, int y_pos,35int max_out_lines);3637struct WebPDecParams {38WebPDecBuffer* output; // output buffer.39uint8_t* tmp_y, *tmp_u, *tmp_v; // cache for the fancy upsampler40// or used for tmp rescaling4142int last_y; // coordinate of the line that was last output43const WebPDecoderOptions* options; // if not NULL, use alt decoding features4445WebPRescaler* scaler_y, *scaler_u, *scaler_v, *scaler_a; // rescalers46void* memory; // overall scratch memory for the output work.4748OutputFunc emit; // output RGB or YUV samples49OutputAlphaFunc emit_alpha; // output alpha channel50OutputRowFunc emit_alpha_row; // output one line of rescaled alpha values51};5253// Should be called first, before any use of the WebPDecParams object.54void WebPResetDecParams(WebPDecParams* const params);5556//------------------------------------------------------------------------------57// Header parsing helpers5859// Structure storing a description of the RIFF headers.60typedef struct {61const uint8_t* data; // input buffer62size_t data_size; // input buffer size63int have_all_data; // true if all data is known to be available64size_t offset; // offset to main data chunk (VP8 or VP8L)65const uint8_t* alpha_data; // points to alpha chunk (if present)66size_t alpha_data_size; // alpha chunk size67size_t compressed_size; // VP8/VP8L compressed data size68size_t riff_size; // size of the riff payload (or 0 if absent)69int is_lossless; // true if a VP8L chunk is present70} WebPHeaderStructure;7172// Skips over all valid chunks prior to the first VP8/VP8L frame header.73// Returns: VP8_STATUS_OK, VP8_STATUS_BITSTREAM_ERROR (invalid header/chunk),74// VP8_STATUS_NOT_ENOUGH_DATA (partial input) or VP8_STATUS_UNSUPPORTED_FEATURE75// in the case of non-decodable features (animation for instance).76// In 'headers', compressed_size, offset, alpha_data, alpha_size, and lossless77// fields are updated appropriately upon success.78VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers);7980//------------------------------------------------------------------------------81// Misc utils8283// Returns true if crop dimensions are within image bounds.84int WebPCheckCropDimensions(int image_width, int image_height,85int x, int y, int w, int h);8687// Initializes VP8Io with custom setup, io and teardown functions. The default88// hooks will use the supplied 'params' as io->opaque handle.89void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io);9091// Setup crop_xxx fields, mb_w and mb_h in io. 'src_colorspace' refers92// to the *compressed* format, not the output one.93WEBP_NODISCARD int WebPIoInitFromOptions(94const WebPDecoderOptions* const options, VP8Io* const io,95WEBP_CSP_MODE src_colorspace);9697//------------------------------------------------------------------------------98// Internal functions regarding WebPDecBuffer memory (in buffer.c).99// Don't really need to be externally visible for now.100101// Prepare 'buffer' with the requested initial dimensions width/height.102// If no external storage is supplied, initializes buffer by allocating output103// memory and setting up the stride information. Validate the parameters. Return104// an error code in case of problem (no memory, or invalid stride / size /105// dimension / etc.). If *options is not NULL, also verify that the options'106// parameters are valid and apply them to the width/height dimensions of the107// output buffer. This takes cropping / scaling / rotation into account.108// Also incorporates the options->flip flag to flip the buffer parameters if109// needed.110VP8StatusCode WebPAllocateDecBuffer(int width, int height,111const WebPDecoderOptions* const options,112WebPDecBuffer* const buffer);113114// Flip buffer vertically by negating the various strides.115VP8StatusCode WebPFlipBuffer(WebPDecBuffer* const buffer);116117// Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the118// memory (still held by 'src'). No pixels are copied.119void WebPCopyDecBuffer(const WebPDecBuffer* const src,120WebPDecBuffer* const dst);121122// Copy and transfer ownership from src to dst (beware of parameter order!)123void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst);124125// Copy pixels from 'src' into a *preallocated* 'dst' buffer. Returns126// VP8_STATUS_INVALID_PARAM if the 'dst' is not set up correctly for the copy.127VP8StatusCode WebPCopyDecBufferPixels(const WebPDecBuffer* const src,128WebPDecBuffer* const dst);129130// Returns true if decoding will be slow with the current configuration131// and bitstream features.132int WebPAvoidSlowMemory(const WebPDecBuffer* const output,133const WebPBitstreamFeatures* const features);134135//------------------------------------------------------------------------------136137#ifdef __cplusplus138} // extern "C"139#endif140141#endif // WEBP_DEC_WEBPI_DEC_H_142143144