github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/webp/libwebp/src/dsp/dsp.h (about)

     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  //   Speed-critical functions.
    11  //
    12  // Author: Skal (pascal.massimino@gmail.com)
    13  
    14  #ifndef WEBP_DSP_DSP_H_
    15  #define WEBP_DSP_DSP_H_
    16  
    17  #include "../webp/types.h"
    18  
    19  #ifdef __cplusplus
    20  extern "C" {
    21  #endif
    22  
    23  //------------------------------------------------------------------------------
    24  // CPU detection
    25  
    26  #if defined(_MSC_VER) && _MSC_VER > 1310 && \
    27      (defined(_M_X64) || defined(_M_IX86))
    28  #define WEBP_MSC_SSE2  // Visual C++ SSE2 targets
    29  #endif
    30  
    31  #if defined(__SSE2__) || defined(WEBP_MSC_SSE2)
    32  #define WEBP_USE_SSE2
    33  #endif
    34  
    35  #if defined(__ANDROID__) && defined(__ARM_ARCH_7A__)
    36  #define WEBP_ANDROID_NEON  // Android targets that might support NEON
    37  #endif
    38  
    39  #if defined(__ARM_NEON__) || defined(WEBP_ANDROID_NEON)
    40  #define WEBP_USE_NEON
    41  #endif
    42  
    43  typedef enum {
    44    kSSE2,
    45    kSSE3,
    46    kNEON
    47  } CPUFeature;
    48  // returns true if the CPU supports the feature.
    49  typedef int (*VP8CPUInfo)(CPUFeature feature);
    50  extern VP8CPUInfo VP8GetCPUInfo;
    51  
    52  //------------------------------------------------------------------------------
    53  // Encoding
    54  
    55  // Transforms
    56  // VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
    57  //          will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
    58  typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst,
    59                          int do_two);
    60  typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out);
    61  typedef void (*VP8WHT)(const int16_t* in, int16_t* out);
    62  extern VP8Idct VP8ITransform;
    63  extern VP8Fdct VP8FTransform;
    64  extern VP8WHT VP8ITransformWHT;
    65  extern VP8WHT VP8FTransformWHT;
    66  // Predictions
    67  // *dst is the destination block. *top and *left can be NULL.
    68  typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left,
    69                                const uint8_t* top);
    70  typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top);
    71  extern VP8Intra4Preds VP8EncPredLuma4;
    72  extern VP8IntraPreds VP8EncPredLuma16;
    73  extern VP8IntraPreds VP8EncPredChroma8;
    74  
    75  typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref);
    76  extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4;
    77  typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref,
    78                            const uint16_t* const weights);
    79  extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16;
    80  
    81  typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst);
    82  extern VP8BlockCopy VP8Copy4x4;
    83  // Quantization
    84  struct VP8Matrix;   // forward declaration
    85  typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16],
    86                                  int n, const struct VP8Matrix* const mtx);
    87  extern VP8QuantizeBlock VP8EncQuantizeBlock;
    88  
    89  // specific to 2nd transform:
    90  typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16],
    91                                     const struct VP8Matrix* const mtx);
    92  extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT;
    93  
    94  // Collect histogram for susceptibility calculation and accumulate in histo[].
    95  struct VP8Histogram;
    96  typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred,
    97                            int start_block, int end_block,
    98                            struct VP8Histogram* const histo);
    99  extern const int VP8DspScan[16 + 4 + 4];
   100  extern VP8CHisto VP8CollectHistogram;
   101  
   102  void VP8EncDspInit(void);   // must be called before using any of the above
   103  
   104  //------------------------------------------------------------------------------
   105  // Decoding
   106  
   107  typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst);
   108  // when doing two transforms, coeffs is actually int16_t[2][16].
   109  typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two);
   110  extern VP8DecIdct2 VP8Transform;
   111  extern VP8DecIdct VP8TransformAC3;
   112  extern VP8DecIdct VP8TransformUV;
   113  extern VP8DecIdct VP8TransformDC;
   114  extern VP8DecIdct VP8TransformDCUV;
   115  extern VP8WHT VP8TransformWHT;
   116  
   117  // *dst is the destination block, with stride BPS. Boundary samples are
   118  // assumed accessible when needed.
   119  typedef void (*VP8PredFunc)(uint8_t* dst);
   120  extern const VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */];
   121  extern const VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */];
   122  extern const VP8PredFunc VP8PredLuma4[/* NUM_BMODES */];
   123  
   124  // simple filter (only for luma)
   125  typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh);
   126  extern VP8SimpleFilterFunc VP8SimpleVFilter16;
   127  extern VP8SimpleFilterFunc VP8SimpleHFilter16;
   128  extern VP8SimpleFilterFunc VP8SimpleVFilter16i;  // filter 3 inner edges
   129  extern VP8SimpleFilterFunc VP8SimpleHFilter16i;
   130  
   131  // regular filter (on both macroblock edges and inner edges)
   132  typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride,
   133                                    int thresh, int ithresh, int hev_t);
   134  typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride,
   135                                      int thresh, int ithresh, int hev_t);
   136  // on outer edge
   137  extern VP8LumaFilterFunc VP8VFilter16;
   138  extern VP8LumaFilterFunc VP8HFilter16;
   139  extern VP8ChromaFilterFunc VP8VFilter8;
   140  extern VP8ChromaFilterFunc VP8HFilter8;
   141  
   142  // on inner edge
   143  extern VP8LumaFilterFunc VP8VFilter16i;   // filtering 3 inner edges altogether
   144  extern VP8LumaFilterFunc VP8HFilter16i;
   145  extern VP8ChromaFilterFunc VP8VFilter8i;  // filtering u and v altogether
   146  extern VP8ChromaFilterFunc VP8HFilter8i;
   147  
   148  // must be called before anything using the above
   149  void VP8DspInit(void);
   150  
   151  //------------------------------------------------------------------------------
   152  // WebP I/O
   153  
   154  #define FANCY_UPSAMPLING   // undefined to remove fancy upsampling support
   155  
   156  // Convert a pair of y/u/v lines together to the output rgb/a colorspace.
   157  // bottom_y can be NULL if only one line of output is needed (at top/bottom).
   158  typedef void (*WebPUpsampleLinePairFunc)(
   159      const uint8_t* top_y, const uint8_t* bottom_y,
   160      const uint8_t* top_u, const uint8_t* top_v,
   161      const uint8_t* cur_u, const uint8_t* cur_v,
   162      uint8_t* top_dst, uint8_t* bottom_dst, int len);
   163  
   164  #ifdef FANCY_UPSAMPLING
   165  
   166  // Fancy upsampling functions to convert YUV to RGB(A) modes
   167  extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */];
   168  
   169  // Initializes SSE2 version of the fancy upsamplers.
   170  void WebPInitUpsamplersSSE2(void);
   171  
   172  // NEON version
   173  void WebPInitUpsamplersNEON(void);
   174  
   175  #endif    // FANCY_UPSAMPLING
   176  
   177  // Point-sampling methods.
   178  typedef void (*WebPSampleLinePairFunc)(
   179      const uint8_t* top_y, const uint8_t* bottom_y,
   180      const uint8_t* u, const uint8_t* v,
   181      uint8_t* top_dst, uint8_t* bottom_dst, int len);
   182  
   183  extern const WebPSampleLinePairFunc WebPSamplers[/* MODE_LAST */];
   184  
   185  // General function for converting two lines of ARGB or RGBA.
   186  // 'alpha_is_last' should be true if 0xff000000 is stored in memory as
   187  // as 0x00, 0x00, 0x00, 0xff (little endian).
   188  WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last);
   189  
   190  // YUV444->RGB converters
   191  typedef void (*WebPYUV444Converter)(const uint8_t* y,
   192                                      const uint8_t* u, const uint8_t* v,
   193                                      uint8_t* dst, int len);
   194  
   195  extern const WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */];
   196  
   197  // Main function to be called
   198  void WebPInitUpsamplers(void);
   199  
   200  //------------------------------------------------------------------------------
   201  // Pre-multiply planes with alpha values
   202  
   203  // Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h.
   204  // alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last).
   205  extern void (*WebPApplyAlphaMultiply)(
   206      uint8_t* rgba, int alpha_first, int w, int h, int stride);
   207  
   208  // Same, buf specifically for RGBA4444 format
   209  extern void (*WebPApplyAlphaMultiply4444)(
   210      uint8_t* rgba4444, int w, int h, int stride);
   211  
   212  // To be called first before using the above.
   213  void WebPInitPremultiply(void);
   214  
   215  void WebPInitPremultiplySSE2(void);   // should not be called directly.
   216  void WebPInitPremultiplyNEON(void);
   217  
   218  //------------------------------------------------------------------------------
   219  
   220  #ifdef __cplusplus
   221  }    // extern "C"
   222  #endif
   223  
   224  #endif  /* WEBP_DSP_DSP_H_ */