|
Packit |
9c6abc |
// Copyright 2011 Google Inc. All Rights Reserved.
|
|
Packit |
9c6abc |
//
|
|
Packit |
9c6abc |
// Use of this source code is governed by a BSD-style license
|
|
Packit |
9c6abc |
// that can be found in the COPYING file in the root of the source
|
|
Packit |
9c6abc |
// tree. An additional intellectual property rights grant can be found
|
|
Packit |
9c6abc |
// in the file PATENTS. All contributing project authors may
|
|
Packit |
9c6abc |
// be found in the AUTHORS file in the root of the source tree.
|
|
Packit |
9c6abc |
// -----------------------------------------------------------------------------
|
|
Packit |
9c6abc |
//
|
|
Packit |
9c6abc |
// Internal header: WebP decoding parameters and custom IO on buffer
|
|
Packit |
9c6abc |
//
|
|
Packit |
9c6abc |
// Author: somnath@google.com (Somnath Banerjee)
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#ifndef WEBP_DEC_WEBPI_DEC_H_
|
|
Packit |
9c6abc |
#define WEBP_DEC_WEBPI_DEC_H_
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#ifdef __cplusplus
|
|
Packit |
9c6abc |
extern "C" {
|
|
Packit |
9c6abc |
#endif
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#include "src/utils/rescaler_utils.h"
|
|
Packit |
9c6abc |
#include "src/dec/vp8_dec.h"
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
//------------------------------------------------------------------------------
|
|
Packit |
9c6abc |
// WebPDecParams: Decoding output parameters. Transient internal object.
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
typedef struct WebPDecParams WebPDecParams;
|
|
Packit |
9c6abc |
typedef int (*OutputFunc)(const VP8Io* const io, WebPDecParams* const p);
|
|
Packit |
9c6abc |
typedef int (*OutputAlphaFunc)(const VP8Io* const io, WebPDecParams* const p,
|
|
Packit |
9c6abc |
int expected_num_out_lines);
|
|
Packit |
9c6abc |
typedef int (*OutputRowFunc)(WebPDecParams* const p, int y_pos,
|
|
Packit |
9c6abc |
int max_out_lines);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
struct WebPDecParams {
|
|
Packit |
9c6abc |
WebPDecBuffer* output; // output buffer.
|
|
Packit |
9c6abc |
uint8_t* tmp_y, *tmp_u, *tmp_v; // cache for the fancy upsampler
|
|
Packit |
9c6abc |
// or used for tmp rescaling
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
int last_y; // coordinate of the line that was last output
|
|
Packit |
9c6abc |
const WebPDecoderOptions* options; // if not NULL, use alt decoding features
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
WebPRescaler* scaler_y, *scaler_u, *scaler_v, *scaler_a; // rescalers
|
|
Packit |
9c6abc |
void* memory; // overall scratch memory for the output work.
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
OutputFunc emit; // output RGB or YUV samples
|
|
Packit |
9c6abc |
OutputAlphaFunc emit_alpha; // output alpha channel
|
|
Packit |
9c6abc |
OutputRowFunc emit_alpha_row; // output one line of rescaled alpha values
|
|
Packit |
9c6abc |
};
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Should be called first, before any use of the WebPDecParams object.
|
|
Packit |
9c6abc |
void WebPResetDecParams(WebPDecParams* const params);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
//------------------------------------------------------------------------------
|
|
Packit |
9c6abc |
// Header parsing helpers
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Structure storing a description of the RIFF headers.
|
|
Packit |
9c6abc |
typedef struct {
|
|
Packit |
9c6abc |
const uint8_t* data; // input buffer
|
|
Packit |
9c6abc |
size_t data_size; // input buffer size
|
|
Packit |
9c6abc |
int have_all_data; // true if all data is known to be available
|
|
Packit |
9c6abc |
size_t offset; // offset to main data chunk (VP8 or VP8L)
|
|
Packit |
9c6abc |
const uint8_t* alpha_data; // points to alpha chunk (if present)
|
|
Packit |
9c6abc |
size_t alpha_data_size; // alpha chunk size
|
|
Packit |
9c6abc |
size_t compressed_size; // VP8/VP8L compressed data size
|
|
Packit |
9c6abc |
size_t riff_size; // size of the riff payload (or 0 if absent)
|
|
Packit |
9c6abc |
int is_lossless; // true if a VP8L chunk is present
|
|
Packit |
9c6abc |
} WebPHeaderStructure;
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Skips over all valid chunks prior to the first VP8/VP8L frame header.
|
|
Packit |
9c6abc |
// Returns: VP8_STATUS_OK, VP8_STATUS_BITSTREAM_ERROR (invalid header/chunk),
|
|
Packit |
9c6abc |
// VP8_STATUS_NOT_ENOUGH_DATA (partial input) or VP8_STATUS_UNSUPPORTED_FEATURE
|
|
Packit |
9c6abc |
// in the case of non-decodable features (animation for instance).
|
|
Packit |
9c6abc |
// In 'headers', compressed_size, offset, alpha_data, alpha_size, and lossless
|
|
Packit |
9c6abc |
// fields are updated appropriately upon success.
|
|
Packit |
9c6abc |
VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
//------------------------------------------------------------------------------
|
|
Packit |
9c6abc |
// Misc utils
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Initializes VP8Io with custom setup, io and teardown functions. The default
|
|
Packit |
9c6abc |
// hooks will use the supplied 'params' as io->opaque handle.
|
|
Packit |
9c6abc |
void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Setup crop_xxx fields, mb_w and mb_h in io. 'src_colorspace' refers
|
|
Packit |
9c6abc |
// to the *compressed* format, not the output one.
|
|
Packit |
9c6abc |
int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
|
|
Packit |
9c6abc |
VP8Io* const io, WEBP_CSP_MODE src_colorspace);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
//------------------------------------------------------------------------------
|
|
Packit |
9c6abc |
// Internal functions regarding WebPDecBuffer memory (in buffer.c).
|
|
Packit |
9c6abc |
// Don't really need to be externally visible for now.
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Prepare 'buffer' with the requested initial dimensions width/height.
|
|
Packit |
9c6abc |
// If no external storage is supplied, initializes buffer by allocating output
|
|
Packit |
9c6abc |
// memory and setting up the stride information. Validate the parameters. Return
|
|
Packit |
9c6abc |
// an error code in case of problem (no memory, or invalid stride / size /
|
|
Packit |
9c6abc |
// dimension / etc.). If *options is not NULL, also verify that the options'
|
|
Packit |
9c6abc |
// parameters are valid and apply them to the width/height dimensions of the
|
|
Packit |
9c6abc |
// output buffer. This takes cropping / scaling / rotation into account.
|
|
Packit |
9c6abc |
// Also incorporates the options->flip flag to flip the buffer parameters if
|
|
Packit |
9c6abc |
// needed.
|
|
Packit |
9c6abc |
VP8StatusCode WebPAllocateDecBuffer(int width, int height,
|
|
Packit |
9c6abc |
const WebPDecoderOptions* const options,
|
|
Packit |
9c6abc |
WebPDecBuffer* const buffer);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Flip buffer vertically by negating the various strides.
|
|
Packit |
9c6abc |
VP8StatusCode WebPFlipBuffer(WebPDecBuffer* const buffer);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the
|
|
Packit |
9c6abc |
// memory (still held by 'src'). No pixels are copied.
|
|
Packit |
9c6abc |
void WebPCopyDecBuffer(const WebPDecBuffer* const src,
|
|
Packit |
9c6abc |
WebPDecBuffer* const dst);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Copy and transfer ownership from src to dst (beware of parameter order!)
|
|
Packit |
9c6abc |
void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Copy pixels from 'src' into a *preallocated* 'dst' buffer. Returns
|
|
Packit |
9c6abc |
// VP8_STATUS_INVALID_PARAM if the 'dst' is not set up correctly for the copy.
|
|
Packit |
9c6abc |
VP8StatusCode WebPCopyDecBufferPixels(const WebPDecBuffer* const src,
|
|
Packit |
9c6abc |
WebPDecBuffer* const dst);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
// Returns true if decoding will be slow with the current configuration
|
|
Packit |
9c6abc |
// and bitstream features.
|
|
Packit |
9c6abc |
int WebPAvoidSlowMemory(const WebPDecBuffer* const output,
|
|
Packit |
9c6abc |
const WebPBitstreamFeatures* const features);
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
//------------------------------------------------------------------------------
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#ifdef __cplusplus
|
|
Packit |
9c6abc |
} // extern "C"
|
|
Packit |
9c6abc |
#endif
|
|
Packit |
9c6abc |
|
|
Packit |
9c6abc |
#endif /* WEBP_DEC_WEBPI_DEC_H_ */
|