1 // Copyright 2011 Google Inc. All Rights Reserved. 2 // 3 // This code is licensed under the same terms as WebM: 4 // Software License Agreement: http://www.webmproject.org/license/software/ 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ 6 // ----------------------------------------------------------------------------- 7 // 8 // Internal header: WebP decoding parameters and custom IO on buffer 9 // 10 // Author: somnath@google.com (Somnath Banerjee) 11 12 #ifndef WEBP_DEC_WEBPI_H_ 13 #define WEBP_DEC_WEBPI_H_ 14 15 #if defined(__cplusplus) || defined(c_plusplus) 16 extern "C" { 17 #endif 18 19 #include "../utils/rescaler.h" 20 #include "./decode_vp8.h" 21 22 //------------------------------------------------------------------------------ 23 // WebPDecParams: Decoding output parameters. Transient internal object. 24 25 typedef struct WebPDecParams WebPDecParams; 26 typedef int (*OutputFunc)(const VP8Io* const io, WebPDecParams* const p); 27 typedef int (*OutputRowFunc)(WebPDecParams* const p, int y_pos); 28 29 struct WebPDecParams { 30 WebPDecBuffer* output; // output buffer. 31 uint8_t* tmp_y, *tmp_u, *tmp_v; // cache for the fancy upsampler 32 // or used for tmp rescaling 33 34 int last_y; // coordinate of the line that was last output 35 const WebPDecoderOptions* options; // if not NULL, use alt decoding features 36 // rescalers 37 WebPRescaler scaler_y, scaler_u, scaler_v, scaler_a; 38 void* memory; // overall scratch memory for the output work. 39 40 OutputFunc emit; // output RGB or YUV samples 41 OutputFunc emit_alpha; // output alpha channel 42 OutputRowFunc emit_alpha_row; // output one line of rescaled alpha values 43 }; 44 45 // Should be called first, before any use of the WebPDecParams object. 46 void WebPResetDecParams(WebPDecParams* const params); 47 48 //------------------------------------------------------------------------------ 49 // Header parsing helpers 50 51 // Structure storing a description of the RIFF headers. 52 typedef struct { 53 const uint8_t* data; // input buffer 54 size_t data_size; // input buffer size 55 size_t offset; // offset to main data chunk (VP8 or VP8L) 56 const uint8_t* alpha_data; // points to alpha chunk (if present) 57 size_t alpha_data_size; // alpha chunk size 58 size_t compressed_size; // VP8/VP8L compressed data size 59 size_t riff_size; // size of the riff payload (or 0 if absent) 60 int is_lossless; // true if a VP8L chunk is present 61 } WebPHeaderStructure; 62 63 // Skips over all valid chunks prior to the first VP8/VP8L frame header. 64 // Returns VP8_STATUS_OK on success, 65 // VP8_STATUS_BITSTREAM_ERROR if an invalid header/chunk is found, and 66 // VP8_STATUS_NOT_ENOUGH_DATA if case of insufficient data. 67 // In 'headers', compressed_size, offset, alpha_data, alpha_size and lossless 68 // fields are updated appropriately upon success. 69 VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers); 70 71 //------------------------------------------------------------------------------ 72 // Misc utils 73 74 // Initializes VP8Io with custom setup, io and teardown functions. The default 75 // hooks will use the supplied 'params' as io->opaque handle. 76 void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io); 77 78 // Setup crop_xxx fields, mb_w and mb_h in io. 'src_colorspace' refers 79 // to the *compressed* format, not the output one. 80 int WebPIoInitFromOptions(const WebPDecoderOptions* const options, 81 VP8Io* const io, WEBP_CSP_MODE src_colorspace); 82 83 //------------------------------------------------------------------------------ 84 // Internal functions regarding WebPDecBuffer memory (in buffer.c). 85 // Don't really need to be externally visible for now. 86 87 // Prepare 'buffer' with the requested initial dimensions width/height. 88 // If no external storage is supplied, initializes buffer by allocating output 89 // memory and setting up the stride information. Validate the parameters. Return 90 // an error code in case of problem (no memory, or invalid stride / size / 91 // dimension / etc.). If *options is not NULL, also verify that the options' 92 // parameters are valid and apply them to the width/height dimensions of the 93 // output buffer. This takes cropping / scaling / rotation into account. 94 VP8StatusCode WebPAllocateDecBuffer(int width, int height, 95 const WebPDecoderOptions* const options, 96 WebPDecBuffer* const buffer); 97 98 // Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the 99 // memory (still held by 'src'). 100 void WebPCopyDecBuffer(const WebPDecBuffer* const src, 101 WebPDecBuffer* const dst); 102 103 // Copy and transfer ownership from src to dst (beware of parameter order!) 104 void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst); 105 106 107 108 //------------------------------------------------------------------------------ 109 110 #if defined(__cplusplus) || defined(c_plusplus) 111 } // extern "C" 112 #endif 113 114 #endif /* WEBP_DEC_WEBPI_H_ */ 115