| OLD | NEW |
| 1 // Copyright 2011 Google Inc. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // This code is licensed under the same terms as WebM: | 3 // This code is licensed under the same terms as WebM: |
| 4 // Software License Agreement: http://www.webmproject.org/license/software/ | 4 // Software License Agreement: http://www.webmproject.org/license/software/ |
| 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ | 5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/ |
| 6 // ----------------------------------------------------------------------------- | 6 // ----------------------------------------------------------------------------- |
| 7 // | 7 // |
| 8 // Internal header: WebP decoding parameters and custom IO on buffer | 8 // Internal header: WebP decoding parameters and custom IO on buffer |
| 9 // | 9 // |
| 10 // Author: somnath@google.com (Somnath Banerjee) | 10 // Author: somnath@google.com (Somnath Banerjee) |
| 11 | 11 |
| 12 #ifndef WEBP_DEC_WEBPI_H_ | 12 #ifndef WEBP_DEC_WEBPI_H_ |
| 13 #define WEBP_DEC_WEBPI_H_ | 13 #define WEBP_DEC_WEBPI_H_ |
| 14 | 14 |
| 15 #if defined(__cplusplus) || defined(c_plusplus) | 15 #if defined(__cplusplus) || defined(c_plusplus) |
| 16 extern "C" { | 16 extern "C" { |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 #include "../webp/decode_vp8.h" | 19 #include "../utils/rescaler.h" |
| 20 #include "./decode_vp8.h" |
| 20 | 21 |
| 21 //------------------------------------------------------------------------------ | 22 //------------------------------------------------------------------------------ |
| 22 // WebPDecParams: Decoding output parameters. Transient internal object. | 23 // WebPDecParams: Decoding output parameters. Transient internal object. |
| 23 | 24 |
| 24 typedef struct WebPDecParams WebPDecParams; | 25 typedef struct WebPDecParams WebPDecParams; |
| 25 typedef int (*OutputFunc)(const VP8Io* const io, WebPDecParams* const p); | 26 typedef int (*OutputFunc)(const VP8Io* const io, WebPDecParams* const p); |
| 26 | 27 typedef int (*OutputRowFunc)(WebPDecParams* const p, int y_pos); |
| 27 // Structure use for on-the-fly rescaling | |
| 28 typedef struct { | |
| 29 int x_expand; // true if we're expanding in the x direction | |
| 30 int fy_scale, fx_scale; // fixed-point scaling factor | |
| 31 int64_t fxy_scale; // '' | |
| 32 // we need hpel-precise add/sub increments, for the downsampled U/V planes. | |
| 33 int y_accum; // vertical accumulator | |
| 34 int y_add, y_sub; // vertical increments (add ~= src, sub ~= dst) | |
| 35 int x_add, x_sub; // horizontal increments (add ~= src, sub ~= dst) | |
| 36 int src_width, src_height; // source dimensions | |
| 37 int dst_width, dst_height; // destination dimensions | |
| 38 uint8_t* dst; | |
| 39 int dst_stride; | |
| 40 int32_t* irow, *frow; // work buffer | |
| 41 } WebPRescaler; | |
| 42 | 28 |
| 43 struct WebPDecParams { | 29 struct WebPDecParams { |
| 44 WebPDecBuffer* output; // output buffer. | 30 WebPDecBuffer* output; // output buffer. |
| 45 uint8_t* tmp_y, *tmp_u, *tmp_v; // cache for the fancy upsampler | 31 uint8_t* tmp_y, *tmp_u, *tmp_v; // cache for the fancy upsampler |
| 46 // or used for tmp rescaling | 32 // or used for tmp rescaling |
| 47 | 33 |
| 48 int last_y; // coordinate of the line that was last output | 34 int last_y; // coordinate of the line that was last output |
| 49 const WebPDecoderOptions* options; // if not NULL, use alt decoding features | 35 const WebPDecoderOptions* options; // if not NULL, use alt decoding features |
| 50 // rescalers | 36 // rescalers |
| 51 WebPRescaler scaler_y, scaler_u, scaler_v, scaler_a; | 37 WebPRescaler scaler_y, scaler_u, scaler_v, scaler_a; |
| 52 void* memory; // overall scratch memory for the output work. | 38 void* memory; // overall scratch memory for the output work. |
| 53 OutputFunc emit; // output RGB or YUV samples | 39 |
| 54 OutputFunc emit_alpha; // output alpha channel | 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 |
| 55 }; | 43 }; |
| 56 | 44 |
| 57 // Should be called first, before any use of the WebPDecParams object. | 45 // Should be called first, before any use of the WebPDecParams object. |
| 58 void WebPResetDecParams(WebPDecParams* const params); | 46 void WebPResetDecParams(WebPDecParams* const params); |
| 59 | 47 |
| 60 //------------------------------------------------------------------------------ | 48 //------------------------------------------------------------------------------ |
| 61 // Header parsing helpers | 49 // Header parsing helpers |
| 62 | 50 |
| 63 #define TAG_SIZE 4 | 51 // Structure storing a description of the RIFF headers. |
| 64 #define CHUNK_HEADER_SIZE 8 | 52 typedef struct { |
| 65 #define RIFF_HEADER_SIZE 12 | 53 const uint8_t* data; // input buffer |
| 66 #define FRAME_CHUNK_SIZE 20 | 54 size_t data_size; // input buffer size |
| 67 #define LOOP_CHUNK_SIZE 4 | 55 size_t offset; // offset to main data chunk (VP8 or VP8L) |
| 68 #define TILE_CHUNK_SIZE 8 | 56 const uint8_t* alpha_data; // points to alpha chunk (if present) |
| 69 #define VP8X_CHUNK_SIZE 12 | 57 size_t alpha_data_size; // alpha chunk size |
| 70 #define VP8_FRAME_HEADER_SIZE 10 // Size of the frame header within VP8 data. | 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; |
| 71 | 62 |
| 72 // Validates the RIFF container (if detected) and skips over it. | 63 // Skips over all valid chunks prior to the first VP8/VP8L frame header. |
| 73 // If a RIFF container is detected, | |
| 74 // Returns VP8_STATUS_BITSTREAM_ERROR for invalid header, and | |
| 75 // VP8_STATUS_OK otherwise. | |
| 76 // In case there are not enough bytes (partial RIFF container), return 0 for | |
| 77 // riff_size. Else return the riff_size extracted from the header. | |
| 78 VP8StatusCode WebPParseRIFF(const uint8_t** data, uint32_t* data_size, | |
| 79 uint32_t* riff_size); | |
| 80 | |
| 81 // Validates the VP8X Header and skips over it. | |
| 82 // Returns VP8_STATUS_BITSTREAM_ERROR for invalid VP8X header, | |
| 83 // VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and | |
| 84 // VP8_STATUS_OK otherwise. | |
| 85 // If a VP8 chunk is found, bytes_skipped is set to the total number of bytes | |
| 86 // that are skipped; also Width, Height & Flags are set to the corresponding | |
| 87 // fields extracted from the VP8X chunk. | |
| 88 VP8StatusCode WebPParseVP8X(const uint8_t** data, uint32_t* data_size, | |
| 89 uint32_t* bytes_skipped, | |
| 90 int* width, int* height, uint32_t* flags); | |
| 91 | |
| 92 // Skips to the next VP8 chunk header in the data given the size of the RIFF | |
| 93 // chunk 'riff_size'. | |
| 94 // Returns VP8_STATUS_BITSTREAM_ERROR if any invalid chunk size is encountered, | |
| 95 // VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and | |
| 96 // VP8_STATUS_OK otherwise. | |
| 97 // If a VP8 chunk is found, bytes_skipped is set to the total number of bytes | |
| 98 // that are skipped. | |
| 99 VP8StatusCode WebPParseOptionalChunks(const uint8_t** data, uint32_t* data_size, | |
| 100 uint32_t riff_size, | |
| 101 uint32_t* bytes_skipped); | |
| 102 | |
| 103 // Validates the VP8 Header ("VP8 nnnn") and skips over it. | |
| 104 // Returns VP8_STATUS_BITSTREAM_ERROR for invalid (vp8_chunk_size greater than | |
| 105 // riff_size) VP8 header, | |
| 106 // VP8_STATUS_NOT_ENOUGH_DATA in case of insufficient data, and | |
| 107 // VP8_STATUS_OK otherwise. | |
| 108 // If a VP8 chunk is found, bytes_skipped is set to the total number of bytes | |
| 109 // that are skipped and vp8_chunk_size is set to the corresponding size | |
| 110 // extracted from the VP8 chunk header. | |
| 111 // For a partial VP8 chunk, vp8_chunk_size is set to 0. | |
| 112 VP8StatusCode WebPParseVP8Header(const uint8_t** data, uint32_t* data_size, | |
| 113 uint32_t riff_size, uint32_t* bytes_skipped, | |
| 114 uint32_t* vp8_chunk_size); | |
| 115 | |
| 116 // Skips over all valid chunks prior to the first VP8 frame header. | |
| 117 // Returns VP8_STATUS_OK on success, | 64 // Returns VP8_STATUS_OK on success, |
| 118 // VP8_STATUS_BITSTREAM_ERROR if an invalid header/chunk is found, and | 65 // VP8_STATUS_BITSTREAM_ERROR if an invalid header/chunk is found, and |
| 119 // VP8_STATUS_NOT_ENOUGH_DATA if case of insufficient data. | 66 // VP8_STATUS_NOT_ENOUGH_DATA if case of insufficient data. |
| 120 // Also, data, data_size, vp8_size & bytes_skipped are updated appropriately | 67 // In 'headers', compressed_size, offset, alpha_data, alpha_size and lossless |
| 121 // on success, where | 68 // fields are updated appropriately upon success. |
| 122 // vp8_size is the size of VP8 chunk data (extracted from VP8 chunk header) and | 69 VP8StatusCode WebPParseHeaders(WebPHeaderStructure* const headers); |
| 123 // bytes_skipped is set to the total number of bytes that are skipped. | |
| 124 VP8StatusCode WebPParseHeaders(const uint8_t** data, uint32_t* data_size, | |
| 125 uint32_t* vp8_size, uint32_t* bytes_skipped); | |
| 126 | 70 |
| 127 //------------------------------------------------------------------------------ | 71 //------------------------------------------------------------------------------ |
| 128 // Misc utils | 72 // Misc utils |
| 129 | 73 |
| 130 // Initializes VP8Io with custom setup, io and teardown functions. The default | 74 // Initializes VP8Io with custom setup, io and teardown functions. The default |
| 131 // hooks will use the supplied 'params' as io->opaque handle. | 75 // hooks will use the supplied 'params' as io->opaque handle. |
| 132 void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io); | 76 void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io); |
| 133 | 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 |
| 134 //------------------------------------------------------------------------------ | 83 //------------------------------------------------------------------------------ |
| 135 // Internal functions regarding WebPDecBuffer memory (in buffer.c). | 84 // Internal functions regarding WebPDecBuffer memory (in buffer.c). |
| 136 // Don't really need to be externally visible for now. | 85 // Don't really need to be externally visible for now. |
| 137 | 86 |
| 138 // Prepare 'buffer' with the requested initial dimensions width/height. | 87 // Prepare 'buffer' with the requested initial dimensions width/height. |
| 139 // If no external storage is supplied, initializes buffer by allocating output | 88 // If no external storage is supplied, initializes buffer by allocating output |
| 140 // memory and setting up the stride information. Validate the parameters. Return | 89 // memory and setting up the stride information. Validate the parameters. Return |
| 141 // an error code in case of problem (no memory, or invalid stride / size / | 90 // an error code in case of problem (no memory, or invalid stride / size / |
| 142 // dimension / etc.). If *options is not NULL, also verify that the options' | 91 // dimension / etc.). If *options is not NULL, also verify that the options' |
| 143 // parameters are valid and apply them to the width/height dimensions of the | 92 // parameters are valid and apply them to the width/height dimensions of the |
| 144 // output buffer. This takes cropping / scaling / rotation into account. | 93 // output buffer. This takes cropping / scaling / rotation into account. |
| 145 VP8StatusCode WebPAllocateDecBuffer(int width, int height, | 94 VP8StatusCode WebPAllocateDecBuffer(int width, int height, |
| 146 const WebPDecoderOptions* const options, | 95 const WebPDecoderOptions* const options, |
| 147 WebPDecBuffer* const buffer); | 96 WebPDecBuffer* const buffer); |
| 148 | 97 |
| 149 // Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the | 98 // Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the |
| 150 // memory (still held by 'src'). | 99 // memory (still held by 'src'). |
| 151 void WebPCopyDecBuffer(const WebPDecBuffer* const src, | 100 void WebPCopyDecBuffer(const WebPDecBuffer* const src, |
| 152 WebPDecBuffer* const dst); | 101 WebPDecBuffer* const dst); |
| 153 | 102 |
| 154 // Copy and transfer ownership from src to dst (beware of parameter order!) | 103 // Copy and transfer ownership from src to dst (beware of parameter order!) |
| 155 void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst); | 104 void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst); |
| 156 | 105 |
| 106 |
| 107 |
| 157 //------------------------------------------------------------------------------ | 108 //------------------------------------------------------------------------------ |
| 158 | 109 |
| 159 #if defined(__cplusplus) || defined(c_plusplus) | 110 #if defined(__cplusplus) || defined(c_plusplus) |
| 160 } // extern "C" | 111 } // extern "C" |
| 161 #endif | 112 #endif |
| 162 | 113 |
| 163 #endif /* WEBP_DEC_WEBPI_H_ */ | 114 #endif /* WEBP_DEC_WEBPI_H_ */ |
| OLD | NEW |