Home | History | Annotate | Download | only in dec
      1 // Copyright 2011 Google Inc.
      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 (at) 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 "webp/decode_vp8.h"
     20 
     21 //------------------------------------------------------------------------------
     22 // WebPDecParams: Decoding output parameters. Transcient internal object.
     23 
     24 typedef struct WebPDecParams WebPDecParams;
     25 typedef int (*OutputFunc)(const VP8Io* const io, WebPDecParams* const p);
     26 
     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 
     43 struct WebPDecParams {
     44   WebPDecBuffer* output;             // output buffer.
     45   uint8_t* tmp_y, *tmp_u, *tmp_v;    // cache for the fancy upsampler
     46                                      // or used for tmp rescaling
     47 
     48   int last_y;                 // coordinate of the line that was last output
     49   const WebPDecoderOptions* options;  // if not NULL, use alt decoding features
     50   // rescalers
     51   WebPRescaler scaler_y, scaler_u, scaler_v, scaler_a;
     52   void* memory;               // overall scratch memory for the output work.
     53   OutputFunc emit;            // output RGB or YUV samples
     54   OutputFunc emit_alpha;      // output alpha channel
     55 };
     56 
     57 // Should be called first, before any use of the WebPDecParams object.
     58 void WebPResetDecParams(WebPDecParams* const params);
     59 
     60 //------------------------------------------------------------------------------
     61 // Upsampler function to overwrite fancy upsampler.
     62 
     63 typedef void (*WebPUpsampleLinePairFunc)(
     64   const uint8_t* top_y, const uint8_t* bottom_y,
     65   const uint8_t* top_u, const uint8_t* top_v,
     66   const uint8_t* cur_u, const uint8_t* cur_v,
     67   uint8_t* top_dst, uint8_t* bottom_dst, int len);
     68 
     69 // Upsampler functions to be used to convert YUV to RGB(A) modes
     70 extern WebPUpsampleLinePairFunc WebPUpsamplers[MODE_LAST];
     71 extern WebPUpsampleLinePairFunc WebPUpsamplersKeepAlpha[MODE_LAST];
     72 
     73 // Initializes SSE2 version of the fancy upsamplers.
     74 void WebPInitUpsamplersSSE2(void);
     75 
     76 //------------------------------------------------------------------------------
     77 // Misc utils
     78 
     79 // If a RIFF container is detected, validate it and skip over it. Returns
     80 // VP8 bit-stream size if RIFF header is valid else returns 0
     81 uint32_t WebPCheckRIFFHeader(const uint8_t** data_ptr,
     82                              uint32_t* data_size_ptr);
     83 
     84 // Initializes VP8Io with custom setup, io and teardown functions. The default
     85 // hooks will use the supplied 'params' as io->opaque handle.
     86 void WebPInitCustomIo(WebPDecParams* const params, VP8Io* const io);
     87 
     88 //------------------------------------------------------------------------------
     89 // Internal functions regarding WebPDecBuffer memory (in buffer.c).
     90 // Don't really need to be externally visible for now.
     91 
     92 // Prepare 'buffer' with the requested initial dimensions width/height.
     93 // If no external storage is supplied, initializes buffer by allocating output
     94 // memory and setting up the stride information. Validate the parameters. Return
     95 // an error code in case of problem (no memory, or invalid stride / size /
     96 // dimension / etc.). If *options is not NULL, also verify that the options'
     97 // parameters are valid and apply them to the width/height dimensions of the
     98 // output buffer. This takes cropping / scaling / rotation into account.
     99 VP8StatusCode WebPAllocateDecBuffer(int width, int height,
    100                                     const WebPDecoderOptions* const options,
    101                                     WebPDecBuffer* const buffer);
    102 
    103 // Copy 'src' into 'dst' buffer, making sure 'dst' is not marked as owner of the
    104 // memory (still held by 'src').
    105 void WebPCopyDecBuffer(const WebPDecBuffer* const src,
    106                        WebPDecBuffer* const dst);
    107 
    108 // Copy and transfer ownership from src to dst (beware of parameter order!)
    109 void WebPGrabDecBuffer(WebPDecBuffer* const src, WebPDecBuffer* const dst);
    110 
    111 //------------------------------------------------------------------------------
    112 
    113 #if defined(__cplusplus) || defined(c_plusplus)
    114 }    // extern "C"
    115 #endif
    116 
    117 #endif  // WEBP_DEC_WEBPI_H
    118