decode_vp8.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // Copyright 2010 Google Inc. All Rights Reserved.
  2. //
  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. // -----------------------------------------------------------------------------
  9. //
  10. // Low-level API for VP8 decoder
  11. //
  12. // Author: Skal (pascal.massimino@gmail.com)
  13. #ifndef WEBP_WEBP_DECODE_VP8_H_
  14. #define WEBP_WEBP_DECODE_VP8_H_
  15. #include "../webp/decode.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. //------------------------------------------------------------------------------
  20. // Lower-level API
  21. //
  22. // These functions provide fine-grained control of the decoding process.
  23. // The call flow should resemble:
  24. //
  25. // VP8Io io;
  26. // VP8InitIo(&io);
  27. // io.data = data;
  28. // io.data_size = size;
  29. // /* customize io's functions (setup()/put()/teardown()) if needed. */
  30. //
  31. // VP8Decoder* dec = VP8New();
  32. // bool ok = VP8Decode(dec);
  33. // if (!ok) printf("Error: %s\n", VP8StatusMessage(dec));
  34. // VP8Delete(dec);
  35. // return ok;
  36. // Input / Output
  37. typedef struct VP8Io VP8Io;
  38. typedef int (*VP8IoPutHook)(const VP8Io* io);
  39. typedef int (*VP8IoSetupHook)(VP8Io* io);
  40. typedef void (*VP8IoTeardownHook)(const VP8Io* io);
  41. struct VP8Io {
  42. // set by VP8GetHeaders()
  43. int width, height; // picture dimensions, in pixels (invariable).
  44. // These are the original, uncropped dimensions.
  45. // The actual area passed to put() is stored
  46. // in mb_w / mb_h fields.
  47. // set before calling put()
  48. int mb_y; // position of the current rows (in pixels)
  49. int mb_w; // number of columns in the sample
  50. int mb_h; // number of rows in the sample
  51. const uint8_t* y, *u, *v; // rows to copy (in yuv420 format)
  52. int y_stride; // row stride for luma
  53. int uv_stride; // row stride for chroma
  54. void* opaque; // user data
  55. // called when fresh samples are available. Currently, samples are in
  56. // YUV420 format, and can be up to width x 24 in size (depending on the
  57. // in-loop filtering level, e.g.). Should return false in case of error
  58. // or abort request. The actual size of the area to update is mb_w x mb_h
  59. // in size, taking cropping into account.
  60. VP8IoPutHook put;
  61. // called just before starting to decode the blocks.
  62. // Must return false in case of setup error, true otherwise. If false is
  63. // returned, teardown() will NOT be called. But if the setup succeeded
  64. // and true is returned, then teardown() will always be called afterward.
  65. VP8IoSetupHook setup;
  66. // Called just after block decoding is finished (or when an error occurred
  67. // during put()). Is NOT called if setup() failed.
  68. VP8IoTeardownHook teardown;
  69. // this is a recommendation for the user-side yuv->rgb converter. This flag
  70. // is set when calling setup() hook and can be overwritten by it. It then
  71. // can be taken into consideration during the put() method.
  72. int fancy_upsampling;
  73. // Input buffer.
  74. size_t data_size;
  75. const uint8_t* data;
  76. // If true, in-loop filtering will not be performed even if present in the
  77. // bitstream. Switching off filtering may speed up decoding at the expense
  78. // of more visible blocking. Note that output will also be non-compliant
  79. // with the VP8 specifications.
  80. int bypass_filtering;
  81. // Cropping parameters.
  82. int use_cropping;
  83. int crop_left, crop_right, crop_top, crop_bottom;
  84. // Scaling parameters.
  85. int use_scaling;
  86. int scaled_width, scaled_height;
  87. // If non NULL, pointer to the alpha data (if present) corresponding to the
  88. // start of the current row (That is: it is pre-offset by mb_y and takes
  89. // cropping into account).
  90. const uint8_t* a;
  91. };
  92. // Internal, version-checked, entry point
  93. int VP8InitIoInternal(VP8Io* const, int);
  94. // Set the custom IO function pointers and user-data. The setter for IO hooks
  95. // should be called before initiating incremental decoding. Returns true if
  96. // WebPIDecoder object is successfully modified, false otherwise.
  97. int WebPISetIOHooks(WebPIDecoder* const idec,
  98. VP8IoPutHook put,
  99. VP8IoSetupHook setup,
  100. VP8IoTeardownHook teardown,
  101. void* user_data);
  102. // Main decoding object. This is an opaque structure.
  103. typedef struct VP8Decoder VP8Decoder;
  104. // Create a new decoder object.
  105. VP8Decoder* VP8New(void);
  106. // Must be called to make sure 'io' is initialized properly.
  107. // Returns false in case of version mismatch. Upon such failure, no other
  108. // decoding function should be called (VP8Decode, VP8GetHeaders, ...)
  109. static WEBP_INLINE int VP8InitIo(VP8Io* const io) {
  110. return VP8InitIoInternal(io, WEBP_DECODER_ABI_VERSION);
  111. }
  112. // Decode the VP8 frame header. Returns true if ok.
  113. // Note: 'io->data' must be pointing to the start of the VP8 frame header.
  114. int VP8GetHeaders(VP8Decoder* const dec, VP8Io* const io);
  115. // Decode a picture. Will call VP8GetHeaders() if it wasn't done already.
  116. // Returns false in case of error.
  117. int VP8Decode(VP8Decoder* const dec, VP8Io* const io);
  118. // Return current status of the decoder:
  119. VP8StatusCode VP8Status(VP8Decoder* const dec);
  120. // return readable string corresponding to the last status.
  121. const char* VP8StatusMessage(VP8Decoder* const dec);
  122. // Resets the decoder in its initial state, reclaiming memory.
  123. // Not a mandatory call between calls to VP8Decode().
  124. void VP8Clear(VP8Decoder* const dec);
  125. // Destroy the decoder object.
  126. void VP8Delete(VP8Decoder* const dec);
  127. //------------------------------------------------------------------------------
  128. // Miscellaneous VP8/VP8L bitstream probing functions.
  129. // Returns true if the next 3 bytes in data contain the VP8 signature.
  130. WEBP_EXTERN(int) VP8CheckSignature(const uint8_t* const data, size_t data_size);
  131. // Validates the VP8 data-header and retrieves basic header information viz
  132. // width and height. Returns 0 in case of formatting error. *width/*height
  133. // can be passed NULL.
  134. WEBP_EXTERN(int) VP8GetInfo(
  135. const uint8_t* data,
  136. size_t data_size, // data available so far
  137. size_t chunk_size, // total data size expected in the chunk
  138. int* const width, int* const height);
  139. // Returns true if the next byte(s) in data is a VP8L signature.
  140. WEBP_EXTERN(int) VP8LCheckSignature(const uint8_t* const data, size_t size);
  141. // Validates the VP8L data-header and retrieves basic header information viz
  142. // width, height and alpha. Returns 0 in case of formatting error.
  143. // width/height/has_alpha can be passed NULL.
  144. WEBP_EXTERN(int) VP8LGetInfo(
  145. const uint8_t* data, size_t data_size, // data available so far
  146. int* const width, int* const height, int* const has_alpha);
  147. #ifdef __cplusplus
  148. } // extern "C"
  149. #endif
  150. #endif /* WEBP_WEBP_DECODE_VP8_H_ */