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