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