2012-01-06 23:49:06 +01:00
|
|
|
// Copyright 2010 Google Inc. All Rights Reserved.
|
2010-09-30 15:34:38 +02:00
|
|
|
//
|
|
|
|
// 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/
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Low-level API for VP8 decoder
|
|
|
|
//
|
|
|
|
// Author: Skal (pascal.massimino@gmail.com)
|
|
|
|
|
2011-02-01 07:00:33 +01:00
|
|
|
#ifndef WEBP_WEBP_DECODE_VP8_H_
|
|
|
|
#define WEBP_WEBP_DECODE_VP8_H_
|
2010-09-30 15:34:38 +02:00
|
|
|
|
2012-07-17 07:12:59 +02:00
|
|
|
#include "../webp/decode.h"
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2010-09-30 15:34:38 +02:00
|
|
|
// Lower-level API
|
|
|
|
//
|
2011-07-16 03:58:56 +02:00
|
|
|
// These functions provide fine-grained control of the decoding process.
|
2010-09-30 15:34:38 +02:00
|
|
|
// The call flow should resemble:
|
|
|
|
//
|
|
|
|
// VP8Io io;
|
|
|
|
// VP8InitIo(&io);
|
|
|
|
// io.data = data;
|
|
|
|
// io.data_size = size;
|
|
|
|
// /* customize io's functions (setup()/put()/teardown()) if needed. */
|
|
|
|
//
|
|
|
|
// VP8Decoder* dec = VP8New();
|
|
|
|
// bool ok = VP8Decode(dec);
|
|
|
|
// if (!ok) printf("Error: %s\n", VP8StatusMessage(dec));
|
|
|
|
// VP8Delete(dec);
|
|
|
|
// return ok;
|
|
|
|
|
|
|
|
// Input / Output
|
|
|
|
typedef struct VP8Io VP8Io;
|
2011-07-08 01:38:03 +02:00
|
|
|
typedef int (*VP8IoPutHook)(const VP8Io* io);
|
|
|
|
typedef int (*VP8IoSetupHook)(VP8Io* io);
|
|
|
|
typedef void (*VP8IoTeardownHook)(const VP8Io* io);
|
|
|
|
|
2010-09-30 15:34:38 +02:00
|
|
|
struct VP8Io {
|
|
|
|
// set by VP8GetHeaders()
|
2011-06-20 09:45:15 +02:00
|
|
|
int width, height; // picture dimensions, in pixels (invariable).
|
|
|
|
// These are the original, uncropped dimensions.
|
|
|
|
// The actual area passed to put() is stored
|
|
|
|
// in mb_w / mb_h fields.
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
// set before calling put()
|
2010-11-03 22:27:51 +01:00
|
|
|
int mb_y; // position of the current rows (in pixels)
|
2011-06-20 09:45:15 +02:00
|
|
|
int mb_w; // number of columns in the sample
|
2010-11-03 22:27:51 +01:00
|
|
|
int mb_h; // number of rows in the sample
|
2011-06-20 09:45:15 +02:00
|
|
|
const uint8_t* y, *u, *v; // rows to copy (in yuv420 format)
|
2010-11-03 22:27:51 +01:00
|
|
|
int y_stride; // row stride for luma
|
|
|
|
int uv_stride; // row stride for chroma
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
void* opaque; // user data
|
|
|
|
|
2010-11-03 22:27:51 +01:00
|
|
|
// called when fresh samples are available. Currently, samples are in
|
|
|
|
// YUV420 format, and can be up to width x 24 in size (depending on the
|
2011-02-16 23:33:16 +01:00
|
|
|
// in-loop filtering level, e.g.). Should return false in case of error
|
2011-06-20 09:45:15 +02:00
|
|
|
// or abort request. The actual size of the area to update is mb_w x mb_h
|
|
|
|
// in size, taking cropping into account.
|
2011-07-08 01:38:03 +02:00
|
|
|
VP8IoPutHook put;
|
2010-09-30 15:34:38 +02:00
|
|
|
|
2010-11-03 22:27:51 +01:00
|
|
|
// called just before starting to decode the blocks.
|
2011-07-22 22:09:10 +02:00
|
|
|
// Must return false in case of setup error, true otherwise. If false is
|
|
|
|
// returned, teardown() will NOT be called. But if the setup succeeded
|
|
|
|
// and true is returned, then teardown() will always be called afterward.
|
2011-07-08 01:38:03 +02:00
|
|
|
VP8IoSetupHook setup;
|
2010-09-30 15:34:38 +02:00
|
|
|
|
2011-07-22 22:09:10 +02:00
|
|
|
// Called just after block decoding is finished (or when an error occurred
|
|
|
|
// during put()). Is NOT called if setup() failed.
|
2011-07-08 01:38:03 +02:00
|
|
|
VP8IoTeardownHook teardown;
|
2010-09-30 15:34:38 +02:00
|
|
|
|
2010-11-03 22:27:51 +01:00
|
|
|
// this is a recommendation for the user-side yuv->rgb converter. This flag
|
|
|
|
// is set when calling setup() hook and can be overwritten by it. It then
|
|
|
|
// can be taken into consideration during the put() method.
|
2011-06-20 09:45:15 +02:00
|
|
|
int fancy_upsampling;
|
2010-11-03 22:27:51 +01:00
|
|
|
|
2010-09-30 15:34:38 +02:00
|
|
|
// Input buffer.
|
2012-04-12 22:43:37 +02:00
|
|
|
size_t data_size;
|
2010-09-30 15:34:38 +02:00
|
|
|
const uint8_t* data;
|
2011-02-27 19:51:01 +01:00
|
|
|
|
|
|
|
// If true, in-loop filtering will not be performed even if present in the
|
|
|
|
// bitstream. Switching off filtering may speed up decoding at the expense
|
|
|
|
// of more visible blocking. Note that output will also be non-compliant
|
|
|
|
// with the VP8 specifications.
|
|
|
|
int bypass_filtering;
|
EXPERIMENTAL: add support for alpha channel
This is a (minor) bitstream change: if the 'color_space' bit is set to '1'
(which is normally an undefined/invalid behaviour), we add extra data at the
end of partition #0 (so-called 'extensions')
Namely, we add the size of the extension data as 3 bytes (little-endian),
followed by a set of bits telling which extensions we're incorporating.
The data then _preceeds_ this trailing tags.
This is all experimental, and you'll need to have
'#define WEBP_EXPERIMENTAL_FEATURES' in webp/types.h to enable this code
(at your own risk! :))
Still, this hack produces almost-valid WebP file for decoders that don't
check this color_space bit. In particular, previous 'dwebp' (and for instance
Chrome) will recognize this files and decode them, but without the alpha
of course. Other decoder will just see random extra stuff at the end of
partition #0.
To experiment with the alpha-channel, you need to compile on Unix platform
and use PNGs for input/output.
If 'alpha.png' is a source with alpha channel, then you can try (on Unix):
cwebp alpha.png -o alpha.webp
dwebp alpha.webp -o test.png
cwebp now has a '-noalpha' flag to ignore any alpha information from the
source, if present.
More hacking and experimenting welcome!
Change-Id: I3c7b1fd8411c9e7a9f77690e898479ad85c52f3e
2011-04-26 01:58:04 +02:00
|
|
|
|
2011-06-20 09:45:15 +02:00
|
|
|
// Cropping parameters.
|
|
|
|
int use_cropping;
|
|
|
|
int crop_left, crop_right, crop_top, crop_bottom;
|
|
|
|
|
|
|
|
// Scaling parameters.
|
|
|
|
int use_scaling;
|
|
|
|
int scaled_width, scaled_height;
|
|
|
|
|
2012-06-04 16:40:32 +02:00
|
|
|
// If non NULL, pointer to the alpha data (if present) corresponding to the
|
|
|
|
// start of the current row (That is: it is pre-offset by mb_y and takes
|
|
|
|
// cropping into account).
|
EXPERIMENTAL: add support for alpha channel
This is a (minor) bitstream change: if the 'color_space' bit is set to '1'
(which is normally an undefined/invalid behaviour), we add extra data at the
end of partition #0 (so-called 'extensions')
Namely, we add the size of the extension data as 3 bytes (little-endian),
followed by a set of bits telling which extensions we're incorporating.
The data then _preceeds_ this trailing tags.
This is all experimental, and you'll need to have
'#define WEBP_EXPERIMENTAL_FEATURES' in webp/types.h to enable this code
(at your own risk! :))
Still, this hack produces almost-valid WebP file for decoders that don't
check this color_space bit. In particular, previous 'dwebp' (and for instance
Chrome) will recognize this files and decode them, but without the alpha
of course. Other decoder will just see random extra stuff at the end of
partition #0.
To experiment with the alpha-channel, you need to compile on Unix platform
and use PNGs for input/output.
If 'alpha.png' is a source with alpha channel, then you can try (on Unix):
cwebp alpha.png -o alpha.webp
dwebp alpha.webp -o test.png
cwebp now has a '-noalpha' flag to ignore any alpha information from the
source, if present.
More hacking and experimenting welcome!
Change-Id: I3c7b1fd8411c9e7a9f77690e898479ad85c52f3e
2011-04-26 01:58:04 +02:00
|
|
|
const uint8_t* a;
|
2010-09-30 15:34:38 +02:00
|
|
|
};
|
|
|
|
|
2011-02-27 19:51:01 +01:00
|
|
|
// Internal, version-checked, entry point
|
2012-07-14 05:36:14 +02:00
|
|
|
int VP8InitIoInternal(VP8Io* const, int);
|
2011-02-27 19:51:01 +01:00
|
|
|
|
2011-07-08 01:38:03 +02:00
|
|
|
// Set the custom IO function pointers and user-data. The setter for IO hooks
|
|
|
|
// should be called before initiating incremental decoding. Returns true if
|
2011-07-16 03:58:56 +02:00
|
|
|
// WebPIDecoder object is successfully modified, false otherwise.
|
2012-07-14 05:36:14 +02:00
|
|
|
int WebPISetIOHooks(WebPIDecoder* const idec,
|
|
|
|
VP8IoPutHook put,
|
|
|
|
VP8IoSetupHook setup,
|
|
|
|
VP8IoTeardownHook teardown,
|
|
|
|
void* user_data);
|
2011-07-08 01:38:03 +02:00
|
|
|
|
2010-09-30 15:34:38 +02:00
|
|
|
// Main decoding object. This is an opaque structure.
|
|
|
|
typedef struct VP8Decoder VP8Decoder;
|
|
|
|
|
|
|
|
// Create a new decoder object.
|
2012-07-14 05:36:14 +02:00
|
|
|
VP8Decoder* VP8New(void);
|
2010-09-30 15:34:38 +02:00
|
|
|
|
2011-02-27 19:51:01 +01:00
|
|
|
// Must be called to make sure 'io' is initialized properly.
|
|
|
|
// Returns false in case of version mismatch. Upon such failure, no other
|
|
|
|
// decoding function should be called (VP8Decode, VP8GetHeaders, ...)
|
2011-11-05 03:44:57 +01:00
|
|
|
static WEBP_INLINE int VP8InitIo(VP8Io* const io) {
|
2011-02-27 19:51:01 +01:00
|
|
|
return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION);
|
|
|
|
}
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
// Start decoding a new picture. Returns true if ok.
|
2012-07-14 05:36:14 +02:00
|
|
|
int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io);
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
// Decode a picture. Will call VP8GetHeaders() if it wasn't done already.
|
2011-02-16 23:33:16 +01:00
|
|
|
// Returns false in case of error.
|
2012-07-14 05:36:14 +02:00
|
|
|
int VP8Decode(VP8Decoder* const dec, VP8Io* const io);
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
// Return current status of the decoder:
|
2012-07-14 05:36:14 +02:00
|
|
|
VP8StatusCode VP8Status(VP8Decoder* const dec);
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
// return readable string corresponding to the last status.
|
2012-07-14 05:36:14 +02:00
|
|
|
const char* VP8StatusMessage(VP8Decoder* const dec);
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
// Resets the decoder in its initial state, reclaiming memory.
|
|
|
|
// Not a mandatory call between calls to VP8Decode().
|
2012-07-14 05:36:14 +02:00
|
|
|
void VP8Clear(VP8Decoder* const dec);
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
// Destroy the decoder object.
|
2012-07-14 05:36:14 +02:00
|
|
|
void VP8Delete(VP8Decoder* const dec);
|
2010-09-30 15:34:38 +02:00
|
|
|
|
2011-08-25 23:22:32 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2012-04-25 03:04:38 +02:00
|
|
|
// Miscellaneous VP8/VP8L bitstream probing functions.
|
|
|
|
|
|
|
|
// Returns true if the next 3 bytes in data contain the VP8 signature.
|
|
|
|
WEBP_EXTERN(int) VP8CheckSignature(const uint8_t* const data, size_t data_size);
|
|
|
|
|
|
|
|
// Validates the VP8 data-header and retrieves basic header information viz
|
|
|
|
// width and height. Returns 0 in case of formatting error. *width/*height
|
|
|
|
// can be passed NULL.
|
|
|
|
WEBP_EXTERN(int) VP8GetInfo(
|
|
|
|
const uint8_t* data,
|
|
|
|
size_t data_size, // data available so far
|
|
|
|
size_t chunk_size, // total data size expected in the chunk
|
|
|
|
int* const width, int* const height);
|
|
|
|
|
|
|
|
// Returns true if the next byte(s) in data is a VP8L signature.
|
|
|
|
WEBP_EXTERN(int) VP8LCheckSignature(const uint8_t* const data, size_t size);
|
|
|
|
|
|
|
|
// Validates the VP8L data-header and retrieves basic header information viz
|
|
|
|
// width, height and alpha. Returns 0 in case of formatting error.
|
|
|
|
// width/height/has_alpha can be passed NULL.
|
|
|
|
WEBP_EXTERN(int) VP8LGetInfo(
|
|
|
|
const uint8_t* data, size_t data_size, // data available so far
|
|
|
|
int* const width, int* const height, int* const has_alpha);
|
2010-09-30 15:34:38 +02:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2011-02-16 23:33:16 +01:00
|
|
|
#endif /* WEBP_WEBP_DECODE_VP8_H_ */
|