Home | History | Annotate | Download | only in dsp
      1 // Copyright 2012 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 // Image transforms and color space conversion methods for lossless decoder.
     11 //
     12 // Authors: Vikas Arora (vikaas.arora (at) gmail.com)
     13 //          Jyrki Alakuijala (jyrki (at) google.com)
     14 
     15 #ifndef WEBP_DSP_LOSSLESS_H_
     16 #define WEBP_DSP_LOSSLESS_H_
     17 
     18 #include "../webp/types.h"
     19 #include "../webp/decode.h"
     20 
     21 #if defined(__cplusplus) || defined(c_plusplus)
     22 extern "C" {
     23 #endif
     24 
     25 //------------------------------------------------------------------------------
     26 // Image transforms.
     27 
     28 struct VP8LTransform;  // Defined in dec/vp8li.h.
     29 
     30 // Performs inverse transform of data given transform information, start and end
     31 // rows. Transform will be applied to rows [row_start, row_end[.
     32 // The *in and *out pointers refer to source and destination data respectively
     33 // corresponding to the intermediate row (row_start).
     34 void VP8LInverseTransform(const struct VP8LTransform* const transform,
     35                           int row_start, int row_end,
     36                           const uint32_t* const in, uint32_t* const out);
     37 
     38 // Similar to the static method ColorIndexInverseTransform() that is part of
     39 // lossless.c, but used only for alpha decoding. It takes uint8_t (rather than
     40 // uint32_t) arguments for 'src' and 'dst'.
     41 void VP8LColorIndexInverseTransformAlpha(
     42     const struct VP8LTransform* const transform, int y_start, int y_end,
     43     const uint8_t* src, uint8_t* dst);
     44 
     45 // Subtracts green from blue and red channels.
     46 void VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs);
     47 
     48 void VP8LResidualImage(int width, int height, int bits,
     49                        uint32_t* const argb, uint32_t* const argb_scratch,
     50                        uint32_t* const image);
     51 
     52 void VP8LColorSpaceTransform(int width, int height, int bits, int step,
     53                              uint32_t* const argb, uint32_t* image);
     54 
     55 //------------------------------------------------------------------------------
     56 // Color space conversion.
     57 
     58 // Converts from BGRA to other color spaces.
     59 void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,
     60                          WEBP_CSP_MODE out_colorspace, uint8_t* const rgba);
     61 
     62 //------------------------------------------------------------------------------
     63 // Misc methods.
     64 
     65 // Computes sampled size of 'size' when sampling using 'sampling bits'.
     66 static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size,
     67                                               uint32_t sampling_bits) {
     68   return (size + (1 << sampling_bits) - 1) >> sampling_bits;
     69 }
     70 
     71 // Faster logarithm for integers. Small values use a look-up table.
     72 #define LOG_LOOKUP_IDX_MAX 256
     73 extern const float kLog2Table[LOG_LOOKUP_IDX_MAX];
     74 extern const float kSLog2Table[LOG_LOOKUP_IDX_MAX];
     75 extern float VP8LFastLog2Slow(int v);
     76 extern float VP8LFastSLog2Slow(int v);
     77 static WEBP_INLINE float VP8LFastLog2(int v) {
     78   return (v < LOG_LOOKUP_IDX_MAX) ? kLog2Table[v] : VP8LFastLog2Slow(v);
     79 }
     80 // Fast calculation of v * log2(v) for integer input.
     81 static WEBP_INLINE float VP8LFastSLog2(int v) {
     82   return (v < LOG_LOOKUP_IDX_MAX) ? kSLog2Table[v] : VP8LFastSLog2Slow(v);
     83 }
     84 
     85 
     86 // In-place difference of each component with mod 256.
     87 static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
     88   const uint32_t alpha_and_green =
     89       0x00ff00ffu + (a & 0xff00ff00u) - (b & 0xff00ff00u);
     90   const uint32_t red_and_blue =
     91       0xff00ff00u + (a & 0x00ff00ffu) - (b & 0x00ff00ffu);
     92   return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
     93 }
     94 
     95 void VP8LBundleColorMap(const uint8_t* const row, int width,
     96                         int xbits, uint32_t* const dst);
     97 
     98 //------------------------------------------------------------------------------
     99 
    100 #if defined(__cplusplus) || defined(c_plusplus)
    101 }    // extern "C"
    102 #endif
    103 
    104 #endif  // WEBP_DSP_LOSSLESS_H_
    105