1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 // -----------------------------------------------------------------------------
10 // Internal header: WebP decoding parameters and custom IO on buffer
12 // Author: somnath@google.com (Somnath Banerjee)
14 #ifndef WEBP_DEC_WEBPI_H_
15 #define WEBP_DEC_WEBPI_H_
21 #include "../utils/rescaler.h"
22 #include "./decode_vp8.h"
24 //------------------------------------------------------------------------------
25 // WebPDecParams: Decoding output parameters. Transient internal object.
27 typedef struct WebPDecParams WebPDecParams
;
28 typedef int (*OutputFunc
)(const VP8Io
* const io
, WebPDecParams
* const p
);
29 typedef int (*OutputRowFunc
)(WebPDecParams
* const p
, int y_pos
);
31 struct WebPDecParams
{
32 WebPDecBuffer
* output
; // output buffer.
33 uint8_t* tmp_y
, *tmp_u
, *tmp_v
; // cache for the fancy upsampler
34 // or used for tmp rescaling
36 int last_y
; // coordinate of the line that was last output
37 const WebPDecoderOptions
* options
; // if not NULL, use alt decoding features
39 WebPRescaler scaler_y
, scaler_u
, scaler_v
, scaler_a
;
40 void* memory
; // overall scratch memory for the output work.
42 OutputFunc emit
; // output RGB or YUV samples
43 OutputFunc emit_alpha
; // output alpha channel
44 OutputRowFunc emit_alpha_row
; // output one line of rescaled alpha values
47 // Should be called first, before any use of the WebPDecParams object.
48 void WebPResetDecParams(WebPDecParams
* const params
);
50 //------------------------------------------------------------------------------
51 // Header parsing helpers
53 // Structure storing a description of the RIFF headers.
55 const uint8_t* data
; // input buffer
56 size_t data_size
; // input buffer size
57 size_t offset
; // offset to main data chunk (VP8 or VP8L)
58 const uint8_t* alpha_data
; // points to alpha chunk (if present)
59 size_t alpha_data_size
; // alpha chunk size
60 size_t compressed_size
; // VP8/VP8L compressed data size
61 size_t riff_size
; // size of the riff payload (or 0 if absent)
62 int is_lossless
; // true if a VP8L chunk is present
63 } WebPHeaderStructure
;
65 // Skips over all valid chunks prior to the first VP8/VP8L frame header.
66 // Returns: VP8_STATUS_OK, VP8_STATUS_BITSTREAM_ERROR (invalid header/chunk),
67 // VP8_STATUS_NOT_ENOUGH_DATA (partial input) or VP8_STATUS_UNSUPPORTED_FEATURE
68 // in the case of non-decodable features (animation for instance).
69 // In 'headers', compressed_size, offset, alpha_data, alpha_size, and lossless
70 // fields are updated appropriately upon success.
71 VP8StatusCode
WebPParseHeaders(WebPHeaderStructure
* const headers
);
73 //------------------------------------------------------------------------------
76 // Initializes VP8Io with custom setup, io and teardown functions. The default
77 // hooks will use the supplied 'params' as io->opaque handle.
78 void WebPInitCustomIo(WebPDecParams
* const params
, VP8Io
* const io
);
80 // Setup crop_xxx fields, mb_w and mb_h in io. 'src_colorspace' refers
81 // to the *compressed* format, not the output one.
82 int WebPIoInitFromOptions(const WebPDecoderOptions
* const options
,
83 VP8Io
* const io
, WEBP_CSP_MODE src_colorspace
);
85 //------------------------------------------------------------------------------
86 // Internal functions regarding WebPDecBuffer memory (in buffer.c).
87 // Don't really need to be externally visible for now.
89 // Prepare 'buffer' with the requested initial dimensions width/height.
90 // If no external storage is supplied, initializes buffer by allocating output
91 // memory and setting up the stride information. Validate the parameters. Return
92 // an error code in case of problem (no memory, or invalid stride / size /
93 // dimension / etc.). If *options is not NULL, also verify that the options'
94 // parameters are valid and apply them to the width/height dimensions of the
95 // output buffer. This takes cropping / scaling / rotation into account.
96 VP8StatusCode
WebPAllocateDecBuffer(int width
, int height
,
97 const WebPDecoderOptions
* const options
,
98 WebPDecBuffer
* const buffer
);
100 // Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the
101 // memory (still held by 'src').
102 void WebPCopyDecBuffer(const WebPDecBuffer
* const src
,
103 WebPDecBuffer
* const dst
);
105 // Copy and transfer ownership from src to dst (beware of parameter order!)
106 void WebPGrabDecBuffer(WebPDecBuffer
* const src
, WebPDecBuffer
* const dst
);
110 //------------------------------------------------------------------------------
116 #endif /* WEBP_DEC_WEBPI_H_ */