#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include "sharpyuv/sharpyuv.h"
#include "sharpyuv/sharpyuv_csp.h"
#include "src/enc/vp8i_enc.h"
#include "src/utils/random_utils.h"
#include "src/utils/utils.h"
#include "src/dsp/dsp.h"
#include "src/dsp/lossless.h"
#include "src/dsp/yuv.h"
#include "src/dsp/cpu.h"
#if defined(WEBP_USE_THREAD) && !defined(_WIN32)
#include <pthread.h>
#endif
#define USE_GAMMA_COMPRESSION
#define USE_INVERSE_ALPHA_TABLE
#ifdef WORDS_BIGENDIAN
#define CHANNEL_OFFSET …
#else
#define CHANNEL_OFFSET(i) …
#endif
#define ALPHA_OFFSET …
static int CheckNonOpaque(const uint8_t* alpha, int width, int height,
int x_step, int y_step) { … }
int WebPPictureHasTransparency(const WebPPicture* picture) { … }
#if defined(USE_GAMMA_COMPRESSION)
#define GAMMA_FIX …
#define GAMMA_TAB_FIX …
#define GAMMA_TAB_SIZE …
static const double kGamma = …;
static const int kGammaScale = …;
static const int kGammaTabScale = …;
static const int kGammaTabRounder = …;
static int kLinearToGammaTab[GAMMA_TAB_SIZE + 1];
static uint16_t kGammaToLinearTab[256];
static volatile int kGammaTablesOk = …;
static void InitGammaTables(void);
extern VP8CPUInfo VP8GetCPUInfo;
WEBP_DSP_INIT_FUNC(InitGammaTables) { … }
static WEBP_INLINE uint32_t GammaToLinear(uint8_t v) { … }
static WEBP_INLINE int Interpolate(int v) { … }
static WEBP_INLINE int LinearToGamma(uint32_t base_value, int shift) { … }
#else
static void InitGammaTables(void) {}
static WEBP_INLINE uint32_t GammaToLinear(uint8_t v) { return v; }
static WEBP_INLINE int LinearToGamma(uint32_t base_value, int shift) {
return (int)(base_value << shift);
}
#endif
static int RGBToY(int r, int g, int b, VP8Random* const rg) { … }
static int RGBToU(int r, int g, int b, VP8Random* const rg) { … }
static int RGBToV(int r, int g, int b, VP8Random* const rg) { … }
static const int kMinDimensionIterativeConversion = …;
static int PreprocessARGB(const uint8_t* r_ptr,
const uint8_t* g_ptr,
const uint8_t* b_ptr,
int step, int rgb_stride,
WebPPicture* const picture) { … }
#define SUM4 … \
#define SUM2 …
#define SUM2ALPHA …
#define SUM4ALPHA …
#if defined(USE_INVERSE_ALPHA_TABLE)
static const int kAlphaFix = …;
static const uint32_t kInvAlpha[4 * 0xff + 1] = …;
#define DIVIDE_BY_ALPHA(sum, a) …
#else
#define DIVIDE_BY_ALPHA …
#endif
static WEBP_INLINE int LinearToGammaWeighted(const uint8_t* src,
const uint8_t* a_ptr,
uint32_t total_a, int step,
int rgb_stride) { … }
static WEBP_INLINE void ConvertRowToY(const uint8_t* const r_ptr,
const uint8_t* const g_ptr,
const uint8_t* const b_ptr,
int step,
uint8_t* const dst_y,
int width,
VP8Random* const rg) { … }
static WEBP_INLINE void AccumulateRGBA(const uint8_t* const r_ptr,
const uint8_t* const g_ptr,
const uint8_t* const b_ptr,
const uint8_t* const a_ptr,
int rgb_stride,
uint16_t* dst, int width) { … }
static WEBP_INLINE void AccumulateRGB(const uint8_t* const r_ptr,
const uint8_t* const g_ptr,
const uint8_t* const b_ptr,
int step, int rgb_stride,
uint16_t* dst, int width) { … }
static WEBP_INLINE void ConvertRowsToUV(const uint16_t* rgb,
uint8_t* const dst_u,
uint8_t* const dst_v,
int width,
VP8Random* const rg) { … }
extern void SharpYuvInit(VP8CPUInfo cpu_info_func);
static int ImportYUVAFromRGBA(const uint8_t* r_ptr,
const uint8_t* g_ptr,
const uint8_t* b_ptr,
const uint8_t* a_ptr,
int step,
int rgb_stride,
float dithering,
int use_iterative_conversion,
WebPPicture* const picture) { … }
#undef SUM4
#undef SUM2
#undef SUM4ALPHA
#undef SUM2ALPHA
static int PictureARGBToYUVA(WebPPicture* picture, WebPEncCSP colorspace,
float dithering, int use_iterative_conversion) { … }
int WebPPictureARGBToYUVADithered(WebPPicture* picture, WebPEncCSP colorspace,
float dithering) { … }
int WebPPictureARGBToYUVA(WebPPicture* picture, WebPEncCSP colorspace) { … }
int WebPPictureSharpARGBToYUVA(WebPPicture* picture) { … }
int WebPPictureSmartARGBToYUVA(WebPPicture* picture) { … }
int WebPPictureYUVAToARGB(WebPPicture* picture) { … }
static int Import(WebPPicture* const picture,
const uint8_t* rgb, int rgb_stride,
int step, int swap_rb, int import_alpha) { … }
#if !defined(WEBP_REDUCE_CSP)
int WebPPictureImportBGR(WebPPicture* picture,
const uint8_t* bgr, int bgr_stride) { … }
int WebPPictureImportBGRA(WebPPicture* picture,
const uint8_t* bgra, int bgra_stride) { … }
int WebPPictureImportBGRX(WebPPicture* picture,
const uint8_t* bgrx, int bgrx_stride) { … }
#endif
int WebPPictureImportRGB(WebPPicture* picture,
const uint8_t* rgb, int rgb_stride) { … }
int WebPPictureImportRGBA(WebPPicture* picture,
const uint8_t* rgba, int rgba_stride) { … }
int WebPPictureImportRGBX(WebPPicture* picture,
const uint8_t* rgbx, int rgbx_stride) { … }