1a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Copyright 2012 Google Inc. All Rights Reserved. 2a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 30406ce1417f76f2034833414dcecc9f56253640cVikas Arora// Use of this source code is governed by a BSD-style license 40406ce1417f76f2034833414dcecc9f56253640cVikas Arora// that can be found in the COPYING file in the root of the source 50406ce1417f76f2034833414dcecc9f56253640cVikas Arora// tree. An additional intellectual property rights grant can be found 60406ce1417f76f2034833414dcecc9f56253640cVikas Arora// in the file PATENTS. All contributing project authors may 70406ce1417f76f2034833414dcecc9f56253640cVikas Arora// be found in the AUTHORS file in the root of the source tree. 8a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// ----------------------------------------------------------------------------- 9a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 10a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Image transforms and color space conversion methods for lossless decoder. 11a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// 12a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Authors: Vikas Arora (vikaas.arora@gmail.com) 13a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Jyrki Alakuijala (jyrki@google.com) 14a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 15a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#ifndef WEBP_DSP_LOSSLESS_H_ 16a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#define WEBP_DSP_LOSSLESS_H_ 17a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 18a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#include "webp/types.h" 19a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#include "webp/decode.h" 20a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 21a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#if defined(__cplusplus) || defined(c_plusplus) 22a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroraextern "C" { 23a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 24a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 25a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 26a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Image transforms. 27a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 28a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastruct VP8LTransform; // Defined in dec/vp8li.h. 29a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 30a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Performs inverse transform of data given transform information, start and end 31a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// rows. Transform will be applied to rows [row_start, row_end[. 32a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// The *in and *out pointers refer to source and destination data respectively 33a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// corresponding to the intermediate row (row_start). 34a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid VP8LInverseTransform(const struct VP8LTransform* const transform, 35a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora int row_start, int row_end, 36a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint32_t* const in, uint32_t* const out); 37a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 380406ce1417f76f2034833414dcecc9f56253640cVikas Arora// Similar to the static method ColorIndexInverseTransform() that is part of 390406ce1417f76f2034833414dcecc9f56253640cVikas Arora// lossless.c, but used only for alpha decoding. It takes uint8_t (rather than 400406ce1417f76f2034833414dcecc9f56253640cVikas Arora// uint32_t) arguments for 'src' and 'dst'. 410406ce1417f76f2034833414dcecc9f56253640cVikas Aroravoid VP8LColorIndexInverseTransformAlpha( 420406ce1417f76f2034833414dcecc9f56253640cVikas Arora const struct VP8LTransform* const transform, int y_start, int y_end, 430406ce1417f76f2034833414dcecc9f56253640cVikas Arora const uint8_t* src, uint8_t* dst); 440406ce1417f76f2034833414dcecc9f56253640cVikas Arora 45a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Subtracts green from blue and red channels. 46a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid VP8LSubtractGreenFromBlueAndRed(uint32_t* argb_data, int num_pixs); 47a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 48a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid VP8LResidualImage(int width, int height, int bits, 49a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora uint32_t* const argb, uint32_t* const argb_scratch, 50a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora uint32_t* const image); 51a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 52a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid VP8LColorSpaceTransform(int width, int height, int bits, int step, 53a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora uint32_t* const argb, uint32_t* image); 54a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 55a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 56a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Color space conversion. 57a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 58a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Converts from BGRA to other color spaces. 59a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Aroravoid VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels, 60a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora WEBP_CSP_MODE out_colorspace, uint8_t* const rgba); 61a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 62a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 63a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Misc methods. 64a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 65a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Computes sampled size of 'size' when sampling using 'sampling bits'. 66a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size, 67a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora uint32_t sampling_bits) { 68a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora return (size + (1 << sampling_bits) - 1) >> sampling_bits; 69a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} 70a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 711e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora// Faster logarithm for integers. Small values use a look-up table. 721e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora#define LOG_LOOKUP_IDX_MAX 256 731e7bf8805bd030c19924a5306837ecd72c295751Vikas Aroraextern const float kLog2Table[LOG_LOOKUP_IDX_MAX]; 741e7bf8805bd030c19924a5306837ecd72c295751Vikas Aroraextern const float kSLog2Table[LOG_LOOKUP_IDX_MAX]; 751e7bf8805bd030c19924a5306837ecd72c295751Vikas Aroraextern float VP8LFastLog2Slow(int v); 761e7bf8805bd030c19924a5306837ecd72c295751Vikas Aroraextern float VP8LFastSLog2Slow(int v); 771e7bf8805bd030c19924a5306837ecd72c295751Vikas Arorastatic WEBP_INLINE float VP8LFastLog2(int v) { 781e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora return (v < LOG_LOOKUP_IDX_MAX) ? kLog2Table[v] : VP8LFastLog2Slow(v); 791e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora} 80a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// Fast calculation of v * log2(v) for integer input. 811e7bf8805bd030c19924a5306837ecd72c295751Vikas Arorastatic WEBP_INLINE float VP8LFastSLog2(int v) { 821e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora return (v < LOG_LOOKUP_IDX_MAX) ? kSLog2Table[v] : VP8LFastSLog2Slow(v); 831e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora} 841e7bf8805bd030c19924a5306837ecd72c295751Vikas Arora 85a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 86a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora// In-place difference of each component with mod 256. 87a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arorastatic WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) { 88a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint32_t alpha_and_green = 89a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 0x00ff00ffu + (a & 0xff00ff00u) - (b & 0xff00ff00u); 90a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora const uint32_t red_and_blue = 91a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 0xff00ff00u + (a & 0x00ff00ffu) - (b & 0x00ff00ffu); 92a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu); 93a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} 94a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 950406ce1417f76f2034833414dcecc9f56253640cVikas Aroravoid VP8LBundleColorMap(const uint8_t* const row, int width, 960406ce1417f76f2034833414dcecc9f56253640cVikas Arora int xbits, uint32_t* const dst); 970406ce1417f76f2034833414dcecc9f56253640cVikas Arora 98a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora//------------------------------------------------------------------------------ 99a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 100a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#if defined(__cplusplus) || defined(c_plusplus) 101a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora} // extern "C" 102a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif 103a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora 104a2415724fb3466168b2af5b08bd94ba732c0e753Vikas Arora#endif // WEBP_DSP_LOSSLESS_H_ 105