webpi_dec.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2011 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. // Internal header: WebP decoding parameters and custom IO on buffer
  11. //
  12. // Author: somnath@google.com (Somnath Banerjee)
  13. #ifndef WEBP_DEC_WEBPI_DEC_H_
  14. #define WEBP_DEC_WEBPI_DEC_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "../utils/rescaler_utils.h"
  19. #include "./vp8_dec.h"
  20. //------------------------------------------------------------------------------
  21. // WebPDecParams: Decoding output parameters. Transient internal object.
  22. typedef struct WebPDecParams WebPDecParams;
  23. typedef int (*OutputFunc)(const VP8Io* const io, WebPDecParams* const p);
  24. typedef int (*OutputAlphaFunc)(const VP8Io* const io, WebPDecParams* const p,
  25. int expected_num_out_lines);
  26. typedef int (*OutputRowFunc)(WebPDecParams* const p, int y_pos,
  27. int max_out_lines);
  28. struct WebPDecParams {
  29. WebPDecBuffer* output; // output buffer.
  30. uint8_t* tmp_y, *tmp_u, *tmp_v; // cache for the fancy upsampler
  31. // or used for tmp rescaling
  32. int last_y; // coordinate of the line that was last output
  33. const WebPDecoderOptions* options; // if not NULL, use alt decoding features
  34. WebPRescaler* scaler_y, *scaler_u, *scaler_v, *scaler_a; // rescalers
  35. void* memory; // overall scratch memory for the output work.
  36. OutputFunc emit; // output RGB or YUV samples
  37. OutputAlphaFunc emit_alpha; // output alpha channel
  38. OutputRowFunc emit_alpha_row; // output one line of rescaled alpha values
  39. };
  40. // Should be called first, before any use of the WebPDecParams object.
  41. void WebPResetDecParams(WebPDecParams* const params);
  42. //------------------------------------------------------------------------------
  43. // Header parsing helpers
  44. // Structure storing a description of the RIFF headers.
  45. typedef struct {
  46. const uint8_t* data; // input buffer
  47. size_t data_size; // input buffer size
  48. int have_all_data; // true if all data is known to be available
  49. size_t offset; // offset to main data chunk (VP8 or VP8L)
  50. const uint8_t* alpha_data; // points to alpha chunk (if present)
  51. size_t alpha_data_size; // alpha chunk size
  52. size_t compressed_size; // VP8/VP8L compressed data size
  53. size_t riff_size; // size of the riff payload (or 0 if absent)
  54. int is_lossless; // true if a VP8L chunk is present
  55. } WebPHeaderStructure;
  56. // Skips over all valid chunks prior to the first VP8/VP8L frame header.
  57. // Returns: VP8_STATUS_OK, VP8_STATUS_BITSTREAM_ERROR (invalid header/chunk),
  58. // VP8_STATUS_NOT_ENOUGH_DATA (partial input) or VP8_STATUS_UNSUPPORTED_FEATURE
  59. // in the case of non-decodable features (animation for instance).
  60. // In 'headers', compressed_size, offset, alpha_data, alpha_size, and lossless
  61. // fields are updated appropriately upon success.
  62. VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers);
  63. //------------------------------------------------------------------------------
  64. // Misc utils
  65. // Returns true if crop dimensions are within image bounds.
  66. int WebPCheckCropDimensions(int image_width, int image_height,
  67. int x, int y, int w, int h);
  68. // Initializes VP8Io with custom setup, io and teardown functions. The default
  69. // hooks will use the supplied 'params' as io->opaque handle.
  70. void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io);
  71. // Setup crop_xxx fields, mb_w and mb_h in io. 'src_colorspace' refers
  72. // to the *compressed* format, not the output one.
  73. int WebPIoInitFromOptions(const WebPDecoderOptions* const options,
  74. VP8Io* const io, WEBP_CSP_MODE src_colorspace);
  75. //------------------------------------------------------------------------------
  76. // Internal functions regarding WebPDecBuffer memory (in buffer.c).
  77. // Don't really need to be externally visible for now.
  78. // Prepare 'buffer' with the requested initial dimensions width/height.
  79. // If no external storage is supplied, initializes buffer by allocating output
  80. // memory and setting up the stride information. Validate the parameters. Return
  81. // an error code in case of problem (no memory, or invalid stride / size /
  82. // dimension / etc.). If *options is not NULL, also verify that the options'
  83. // parameters are valid and apply them to the width/height dimensions of the
  84. // output buffer. This takes cropping / scaling / rotation into account.
  85. // Also incorporates the options->flip flag to flip the buffer parameters if
  86. // needed.
  87. VP8StatusCode WebPAllocateDecBuffer(int width, int height,
  88. const WebPDecoderOptions* const options,
  89. WebPDecBuffer* const buffer);
  90. // Flip buffer vertically by negating the various strides.
  91. VP8StatusCode WebPFlipBuffer(WebPDecBuffer* const buffer);
  92. // Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the
  93. // memory (still held by 'src'). No pixels are copied.
  94. void WebPCopyDecBuffer(const WebPDecBuffer* const src,
  95. WebPDecBuffer* const dst);
  96. // Copy and transfer ownership from src to dst (beware of parameter order!)
  97. void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst);
  98. // Copy pixels from 'src' into a *preallocated* 'dst' buffer. Returns
  99. // VP8_STATUS_INVALID_PARAM if the 'dst' is not set up correctly for the copy.
  100. VP8StatusCode WebPCopyDecBufferPixels(const WebPDecBuffer* const src,
  101. WebPDecBuffer* const dst);
  102. // Returns true if decoding will be slow with the current configuration
  103. // and bitstream features.
  104. int WebPAvoidSlowMemory(const WebPDecBuffer* const output,
  105. const WebPBitstreamFeatures* const features);
  106. //------------------------------------------------------------------------------
  107. #ifdef __cplusplus
  108. } // extern "C"
  109. #endif
  110. #endif // WEBP_DEC_WEBPI_DEC_H_