Blame src/dec/vp8_dec.h

Packit 9c6abc
// Copyright 2010 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
//  Low-level API for VP8 decoder
Packit 9c6abc
//
Packit 9c6abc
// Author: Skal (pascal.massimino@gmail.com)
Packit 9c6abc
Packit 9c6abc
#ifndef WEBP_DEC_VP8_DEC_H_
Packit 9c6abc
#define WEBP_DEC_VP8_DEC_H_
Packit 9c6abc
Packit 9c6abc
#include "src/webp/decode.h"
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
extern "C" {
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Lower-level API
Packit 9c6abc
//
Packit 9c6abc
// These functions provide fine-grained control of the decoding process.
Packit 9c6abc
// The call flow should resemble:
Packit 9c6abc
//
Packit 9c6abc
//   VP8Io io;
Packit 9c6abc
//   VP8InitIo(&io);
Packit 9c6abc
//   io.data = data;
Packit 9c6abc
//   io.data_size = size;
Packit 9c6abc
//   /* customize io's functions (setup()/put()/teardown()) if needed. */
Packit 9c6abc
//
Packit 9c6abc
//   VP8Decoder* dec = VP8New();
Packit 9c6abc
//   int ok = VP8Decode(dec, &io);
Packit 9c6abc
//   if (!ok) printf("Error: %s\n", VP8StatusMessage(dec));
Packit 9c6abc
//   VP8Delete(dec);
Packit 9c6abc
//   return ok;
Packit 9c6abc
Packit 9c6abc
// Input / Output
Packit 9c6abc
typedef struct VP8Io VP8Io;
Packit 9c6abc
typedef int (*VP8IoPutHook)(const VP8Io* io);
Packit 9c6abc
typedef int (*VP8IoSetupHook)(VP8Io* io);
Packit 9c6abc
typedef void (*VP8IoTeardownHook)(const VP8Io* io);
Packit 9c6abc
Packit 9c6abc
struct VP8Io {
Packit 9c6abc
  // set by VP8GetHeaders()
Packit 9c6abc
  int width, height;         // picture dimensions, in pixels (invariable).
Packit 9c6abc
                             // These are the original, uncropped dimensions.
Packit 9c6abc
                             // The actual area passed to put() is stored
Packit 9c6abc
                             // in mb_w / mb_h fields.
Packit 9c6abc
Packit 9c6abc
  // set before calling put()
Packit 9c6abc
  int mb_y;                  // position of the current rows (in pixels)
Packit 9c6abc
  int mb_w;                  // number of columns in the sample
Packit 9c6abc
  int mb_h;                  // number of rows in the sample
Packit 9c6abc
  const uint8_t* y, *u, *v;  // rows to copy (in yuv420 format)
Packit 9c6abc
  int y_stride;              // row stride for luma
Packit 9c6abc
  int uv_stride;             // row stride for chroma
Packit 9c6abc
Packit 9c6abc
  void* opaque;              // user data
Packit 9c6abc
Packit 9c6abc
  // called when fresh samples are available. Currently, samples are in
Packit 9c6abc
  // YUV420 format, and can be up to width x 24 in size (depending on the
Packit 9c6abc
  // in-loop filtering level, e.g.). Should return false in case of error
Packit 9c6abc
  // or abort request. The actual size of the area to update is mb_w x mb_h
Packit 9c6abc
  // in size, taking cropping into account.
Packit 9c6abc
  VP8IoPutHook put;
Packit 9c6abc
Packit 9c6abc
  // called just before starting to decode the blocks.
Packit 9c6abc
  // Must return false in case of setup error, true otherwise. If false is
Packit 9c6abc
  // returned, teardown() will NOT be called. But if the setup succeeded
Packit 9c6abc
  // and true is returned, then teardown() will always be called afterward.
Packit 9c6abc
  VP8IoSetupHook setup;
Packit 9c6abc
Packit 9c6abc
  // Called just after block decoding is finished (or when an error occurred
Packit 9c6abc
  // during put()). Is NOT called if setup() failed.
Packit 9c6abc
  VP8IoTeardownHook teardown;
Packit 9c6abc
Packit 9c6abc
  // this is a recommendation for the user-side yuv->rgb converter. This flag
Packit 9c6abc
  // is set when calling setup() hook and can be overwritten by it. It then
Packit 9c6abc
  // can be taken into consideration during the put() method.
Packit 9c6abc
  int fancy_upsampling;
Packit 9c6abc
Packit 9c6abc
  // Input buffer.
Packit 9c6abc
  size_t data_size;
Packit 9c6abc
  const uint8_t* data;
Packit 9c6abc
Packit 9c6abc
  // If true, in-loop filtering will not be performed even if present in the
Packit 9c6abc
  // bitstream. Switching off filtering may speed up decoding at the expense
Packit 9c6abc
  // of more visible blocking. Note that output will also be non-compliant
Packit 9c6abc
  // with the VP8 specifications.
Packit 9c6abc
  int bypass_filtering;
Packit 9c6abc
Packit 9c6abc
  // Cropping parameters.
Packit 9c6abc
  int use_cropping;
Packit 9c6abc
  int crop_left, crop_right, crop_top, crop_bottom;
Packit 9c6abc
Packit 9c6abc
  // Scaling parameters.
Packit 9c6abc
  int use_scaling;
Packit 9c6abc
  int scaled_width, scaled_height;
Packit 9c6abc
Packit 9c6abc
  // If non NULL, pointer to the alpha data (if present) corresponding to the
Packit 9c6abc
  // start of the current row (That is: it is pre-offset by mb_y and takes
Packit 9c6abc
  // cropping into account).
Packit 9c6abc
  const uint8_t* a;
Packit 9c6abc
};
Packit 9c6abc
Packit 9c6abc
// Internal, version-checked, entry point
Packit 9c6abc
int VP8InitIoInternal(VP8Io* const, int);
Packit 9c6abc
Packit 9c6abc
// Set the custom IO function pointers and user-data. The setter for IO hooks
Packit 9c6abc
// should be called before initiating incremental decoding. Returns true if
Packit 9c6abc
// WebPIDecoder object is successfully modified, false otherwise.
Packit 9c6abc
int WebPISetIOHooks(WebPIDecoder* const idec,
Packit 9c6abc
                    VP8IoPutHook put,
Packit 9c6abc
                    VP8IoSetupHook setup,
Packit 9c6abc
                    VP8IoTeardownHook teardown,
Packit 9c6abc
                    void* user_data);
Packit 9c6abc
Packit 9c6abc
// Main decoding object. This is an opaque structure.
Packit 9c6abc
typedef struct VP8Decoder VP8Decoder;
Packit 9c6abc
Packit 9c6abc
// Create a new decoder object.
Packit 9c6abc
VP8Decoder* VP8New(void);
Packit 9c6abc
Packit 9c6abc
// Must be called to make sure 'io' is initialized properly.
Packit 9c6abc
// Returns false in case of version mismatch. Upon such failure, no other
Packit 9c6abc
// decoding function should be called (VP8Decode, VP8GetHeaders, ...)
Packit 9c6abc
static WEBP_INLINE int VP8InitIo(VP8Io* const io) {
Packit 9c6abc
  return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION);
Packit 9c6abc
}
Packit 9c6abc
Packit 9c6abc
// Decode the VP8 frame header. Returns true if ok.
Packit 9c6abc
// Note: 'io->data' must be pointing to the start of the VP8 frame header.
Packit 9c6abc
int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io);
Packit 9c6abc
Packit 9c6abc
// Decode a picture. Will call VP8GetHeaders() if it wasn't done already.
Packit 9c6abc
// Returns false in case of error.
Packit 9c6abc
int VP8Decode(VP8Decoder* const dec, VP8Io* const io);
Packit 9c6abc
Packit 9c6abc
// Return current status of the decoder:
Packit 9c6abc
VP8StatusCode VP8Status(VP8Decoder* const dec);
Packit 9c6abc
Packit 9c6abc
// return readable string corresponding to the last status.
Packit 9c6abc
const char* VP8StatusMessage(VP8Decoder* const dec);
Packit 9c6abc
Packit 9c6abc
// Resets the decoder in its initial state, reclaiming memory.
Packit 9c6abc
// Not a mandatory call between calls to VP8Decode().
Packit 9c6abc
void VP8Clear(VP8Decoder* const dec);
Packit 9c6abc
Packit 9c6abc
// Destroy the decoder object.
Packit 9c6abc
void VP8Delete(VP8Decoder* const dec);
Packit 9c6abc
Packit 9c6abc
//------------------------------------------------------------------------------
Packit 9c6abc
// Miscellaneous VP8/VP8L bitstream probing functions.
Packit 9c6abc
Packit 9c6abc
// Returns true if the next 3 bytes in data contain the VP8 signature.
Packit 9c6abc
WEBP_EXTERN int VP8CheckSignature(const uint8_t* const data, size_t data_size);
Packit 9c6abc
Packit 9c6abc
// Validates the VP8 data-header and retrieves basic header information viz
Packit 9c6abc
// width and height. Returns 0 in case of formatting error. *width/*height
Packit 9c6abc
// can be passed NULL.
Packit 9c6abc
WEBP_EXTERN int VP8GetInfo(
Packit 9c6abc
    const uint8_t* data,
Packit 9c6abc
    size_t data_size,    // data available so far
Packit 9c6abc
    size_t chunk_size,   // total data size expected in the chunk
Packit 9c6abc
    int* const width, int* const height);
Packit 9c6abc
Packit 9c6abc
// Returns true if the next byte(s) in data is a VP8L signature.
Packit 9c6abc
WEBP_EXTERN int VP8LCheckSignature(const uint8_t* const data, size_t size);
Packit 9c6abc
Packit 9c6abc
// Validates the VP8L data-header and retrieves basic header information viz
Packit 9c6abc
// width, height and alpha. Returns 0 in case of formatting error.
Packit 9c6abc
// width/height/has_alpha can be passed NULL.
Packit 9c6abc
WEBP_EXTERN int VP8LGetInfo(
Packit 9c6abc
    const uint8_t* data, size_t data_size,  // data available so far
Packit 9c6abc
    int* const width, int* const height, int* const has_alpha);
Packit 9c6abc
Packit 9c6abc
#ifdef __cplusplus
Packit 9c6abc
}    // extern "C"
Packit 9c6abc
#endif
Packit 9c6abc
Packit 9c6abc
#endif  /* WEBP_DEC_VP8_DEC_H_ */