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 (at) gmail.com) 11 // Jyrki Alakuijala (jyrki (at) 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'. 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, with the property of log2(0) == 0. 63 float VP8LFastLog2(int v); 64 // Fast calculation of v * log2(v) for integer input. 65 static WEBP_INLINE float VP8LFastSLog2(int v) { return VP8LFastLog2(v) * v; } 66 67 // In-place difference of each component with mod 256. 68 static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) { 69 const uint32_t alpha_and_green = 70 0x00ff00ffu + (a & 0xff00ff00u) - (b & 0xff00ff00u); 71 const uint32_t red_and_blue = 72 0xff00ff00u + (a & 0x00ff00ffu) - (b & 0x00ff00ffu); 73 return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu); 74 } 75 76 //------------------------------------------------------------------------------ 77 78 #if defined(__cplusplus) || defined(c_plusplus) 79 } // extern "C" 80 #endif 81 82 #endif // WEBP_DSP_LOSSLESS_H_ 83