godot/thirdparty/libwebp/src/mux/anim_encode.c

// Copyright 2014 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
//  AnimEncoder implementation.
//

#include <assert.h>
#include <limits.h>
#include <math.h>    // for pow()
#include <stdio.h>
#include <stdlib.h>  // for abs()

#include "src/mux/animi.h"
#include "src/utils/utils.h"
#include "src/webp/decode.h"
#include "src/webp/encode.h"
#include "src/webp/format_constants.h"
#include "src/webp/mux.h"
#include "src/webp/types.h"

#if defined(_MSC_VER) && _MSC_VER < 1900
#define snprintf
#endif

#define ERROR_STR_MAX_LENGTH

//------------------------------------------------------------------------------
// Internal structs.

// Stores frame rectangle dimensions.
FrameRectangle;

// Used to store two candidates of encoded data for an animation frame. One of
// the two will be chosen later.
EncodedFrame;

struct WebPAnimEncoder {};

// -----------------------------------------------------------------------------
// Life of WebPAnimEncoder object.

#define DELTA_INFINITY
#define KEYFRAME_NONE

// Reset the counters in the WebPAnimEncoder.
static void ResetCounters(WebPAnimEncoder* const enc) {}

static void DisableKeyframes(WebPAnimEncoderOptions* const enc_options) {}

#define MAX_CACHED_FRAMES

static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) {}

#undef MAX_CACHED_FRAMES

static void DefaultEncoderOptions(WebPAnimEncoderOptions* const enc_options) {}

int WebPAnimEncoderOptionsInitInternal(WebPAnimEncoderOptions* enc_options,
                                       int abi_version) {}

// This starting value is more fit to WebPCleanupTransparentAreaLossless().
#define TRANSPARENT_COLOR

static void ClearRectangle(WebPPicture* const picture,
                           int left, int top, int width, int height) {}

static void WebPUtilClearPic(WebPPicture* const picture,
                             const FrameRectangle* const rect) {}

static void MarkNoError(WebPAnimEncoder* const enc) {}

static void MarkError(WebPAnimEncoder* const enc, const char* str) {}

static void MarkError2(WebPAnimEncoder* const enc,
                       const char* str, int error_code) {}

WebPAnimEncoder* WebPAnimEncoderNewInternal(
    int width, int height, const WebPAnimEncoderOptions* enc_options,
    int abi_version) {}

// Release the data contained by 'encoded_frame'.
static void FrameRelease(EncodedFrame* const encoded_frame) {}

void WebPAnimEncoderDelete(WebPAnimEncoder* enc) {}

// -----------------------------------------------------------------------------
// Frame addition.

// Returns cached frame at the given 'position'.
static EncodedFrame* GetFrame(const WebPAnimEncoder* const enc,
                              size_t position) {}

ComparePixelsFunc;

// Returns true if 'length' number of pixels in 'src' and 'dst' are equal,
// assuming the given step sizes between pixels.
// 'max_allowed_diff' is unused and only there to allow function pointer use.
static WEBP_INLINE int ComparePixelsLossless(const uint32_t* src, int src_step,
                                             const uint32_t* dst, int dst_step,
                                             int length, int max_allowed_diff) {}

// Helper to check if each channel in 'src' and 'dst' is at most off by
// 'max_allowed_diff'.
static WEBP_INLINE int PixelsAreSimilar(uint32_t src, uint32_t dst,
                                        int max_allowed_diff) {}

// Returns true if 'length' number of pixels in 'src' and 'dst' are within an
// error bound, assuming the given step sizes between pixels.
static WEBP_INLINE int ComparePixelsLossy(const uint32_t* src, int src_step,
                                          const uint32_t* dst, int dst_step,
                                          int length, int max_allowed_diff) {}

static int IsEmptyRect(const FrameRectangle* const rect) {}

static int QualityToMaxDiff(float quality) {}

// Assumes that an initial valid guess of change rectangle 'rect' is passed.
static void MinimizeChangeRectangle(const WebPPicture* const src,
                                    const WebPPicture* const dst,
                                    FrameRectangle* const rect,
                                    int is_lossless, float quality) {}

// Snap rectangle to even offsets (and adjust dimensions if needed).
static WEBP_INLINE void SnapToEvenOffsets(FrameRectangle* const rect) {}

SubFrameParams;

static int SubFrameParamsInit(SubFrameParams* const params,
                              int should_try, int empty_rect_allowed) {}

static void SubFrameParamsFree(SubFrameParams* const params) {}

// Given previous and current canvas, picks the optimal rectangle for the
// current frame based on 'is_lossless' and other parameters. Assumes that the
// initial guess 'rect' is valid.
static int GetSubRect(const WebPPicture* const prev_canvas,
                      const WebPPicture* const curr_canvas, int is_key_frame,
                      int is_first_frame, int empty_rect_allowed,
                      int is_lossless, float quality,
                      FrameRectangle* const rect,
                      WebPPicture* const sub_frame) {}

// Picks optimal frame rectangle for both lossless and lossy compression. The
// initial guess for frame rectangles will be the full canvas.
static int GetSubRects(const WebPPicture* const prev_canvas,
                       const WebPPicture* const curr_canvas, int is_key_frame,
                       int is_first_frame, float quality,
                       SubFrameParams* const params) {}

static WEBP_INLINE int clip(int v, int min_v, int max_v) {}

int WebPAnimEncoderRefineRect(
    const WebPPicture* const prev_canvas, const WebPPicture* const curr_canvas,
    int is_lossless, float quality, int* const x_offset, int* const y_offset,
    int* const width, int* const height) {}

static void DisposeFrameRectangle(int dispose_method,
                                  const FrameRectangle* const rect,
                                  WebPPicture* const curr_canvas) {}

static uint32_t RectArea(const FrameRectangle* const rect) {}

static int IsLosslessBlendingPossible(const WebPPicture* const src,
                                      const WebPPicture* const dst,
                                      const FrameRectangle* const rect) {}

static int IsLossyBlendingPossible(const WebPPicture* const src,
                                   const WebPPicture* const dst,
                                   const FrameRectangle* const rect,
                                   float quality) {}

// For pixels in 'rect', replace those pixels in 'dst' that are same as 'src' by
// transparent pixels.
// Returns true if at least one pixel gets modified.
static int IncreaseTransparency(const WebPPicture* const src,
                                const FrameRectangle* const rect,
                                WebPPicture* const dst) {}

#undef TRANSPARENT_COLOR

// Replace similar blocks of pixels by a 'see-through' transparent block
// with uniform average color.
// Assumes lossy compression is being used.
// Returns true if at least one pixel gets modified.
static int FlattenSimilarBlocks(const WebPPicture* const src,
                                const FrameRectangle* const rect,
                                WebPPicture* const dst, float quality) {}

static int EncodeFrame(const WebPConfig* const config, WebPPicture* const pic,
                       WebPMemoryWriter* const memory) {}

// Struct representing a candidate encoded frame including its metadata.
Candidate;

// Generates a candidate encoded frame given a picture and metadata.
static WebPEncodingError EncodeCandidate(WebPPicture* const sub_frame,
                                         const FrameRectangle* const rect,
                                         const WebPConfig* const encoder_config,
                                         int use_blending,
                                         Candidate* const candidate) {}

static void CopyCurrentCanvas(WebPAnimEncoder* const enc) {}

enum {};

#define MIN_COLORS_LOSSY
#define MAX_COLORS_LOSSLESS

// Generates candidates for a given dispose method given pre-filled sub-frame
// 'params'.
static WebPEncodingError GenerateCandidates(
    WebPAnimEncoder* const enc, Candidate candidates[CANDIDATE_COUNT],
    WebPMuxAnimDispose dispose_method, int is_lossless, int is_key_frame,
    SubFrameParams* const params,
    const WebPConfig* const config_ll, const WebPConfig* const config_lossy) {}

#undef MIN_COLORS_LOSSY
#undef MAX_COLORS_LOSSLESS

static void GetEncodedData(const WebPMemoryWriter* const memory,
                           WebPData* const encoded_data) {}

// Sets dispose method of the previous frame to be 'dispose_method'.
static void SetPreviousDisposeMethod(WebPAnimEncoder* const enc,
                                     WebPMuxAnimDispose dispose_method) {}

static int IncreasePreviousDuration(WebPAnimEncoder* const enc, int duration) {}

// Pick the candidate encoded frame with smallest size and release other
// candidates.
// TODO(later): Perhaps a rough SSIM/PSNR produced by the encoder should
// also be a criteria, in addition to sizes.
static void PickBestCandidate(WebPAnimEncoder* const enc,
                              Candidate* const candidates, int is_key_frame,
                              EncodedFrame* const encoded_frame) {}

// Depending on the configuration, tries different compressions
// (lossy/lossless), dispose methods, blending methods etc to encode the current
// frame and outputs the best one in 'encoded_frame'.
// 'frame_skipped' will be set to true if this frame should actually be skipped.
static WebPEncodingError SetFrame(WebPAnimEncoder* const enc,
                                  const WebPConfig* const config,
                                  int is_key_frame,
                                  EncodedFrame* const encoded_frame,
                                  int* const frame_skipped) {}

// Calculate the penalty incurred if we encode given frame as a key frame
// instead of a sub-frame.
static int64_t KeyFramePenalty(const EncodedFrame* const encoded_frame) {}

static int CacheFrame(WebPAnimEncoder* const enc,
                      const WebPConfig* const config) {}

static int FlushFrames(WebPAnimEncoder* const enc) {}

#undef DELTA_INFINITY
#undef KEYFRAME_NONE

int WebPAnimEncoderAdd(WebPAnimEncoder* enc, WebPPicture* frame, int timestamp,
                       const WebPConfig* encoder_config) {}

// -----------------------------------------------------------------------------
// Bitstream assembly.

WEBP_NODISCARD static int DecodeFrameOntoCanvas(
    const WebPMuxFrameInfo* const frame, WebPPicture* const canvas) {}

static int FrameToFullCanvas(WebPAnimEncoder* const enc,
                             const WebPMuxFrameInfo* const frame,
                             WebPData* const full_image) {}

// Convert a single-frame animation to a non-animated image if appropriate.
// TODO(urvang): Can we pick one of the two heuristically (based on frame
// rectangle and/or presence of alpha)?
static WebPMuxError OptimizeSingleFrame(WebPAnimEncoder* const enc,
                                        WebPData* const webp_data) {}

int WebPAnimEncoderAssemble(WebPAnimEncoder* enc, WebPData* webp_data) {}

const char* WebPAnimEncoderGetError(WebPAnimEncoder* enc) {}

WebPMuxError WebPAnimEncoderSetChunk(
    WebPAnimEncoder* enc, const char fourcc[4], const WebPData* chunk_data,
    int copy_data) {}

WebPMuxError WebPAnimEncoderGetChunk(
    const WebPAnimEncoder* enc, const char fourcc[4], WebPData* chunk_data) {}

WebPMuxError WebPAnimEncoderDeleteChunk(
    WebPAnimEncoder* enc, const char fourcc[4]) {}

// -----------------------------------------------------------------------------