godot/thirdparty/libwebp/src/utils/bit_reader_utils.c

// Copyright 2010 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.
// -----------------------------------------------------------------------------
//
// Boolean decoder non-inlined methods
//
// Author: Skal ([email protected])

#ifdef HAVE_CONFIG_H
#include "src/webp/config.h"
#endif

#include "src/dsp/cpu.h"
#include "src/utils/bit_reader_inl_utils.h"
#include "src/utils/utils.h"

//------------------------------------------------------------------------------
// VP8BitReader

void VP8BitReaderSetBuffer(VP8BitReader* const br,
                           const uint8_t* const start,
                           size_t size) {}

void VP8InitBitReader(VP8BitReader* const br,
                      const uint8_t* const start, size_t size) {}

void VP8RemapBitReader(VP8BitReader* const br, ptrdiff_t offset) {}

const uint8_t kVP8Log2Range[128] =;

// range = ((range - 1) << kVP8Log2Range[range]) + 1
const uint8_t kVP8NewRange[128] =;

void VP8LoadFinalBytes(VP8BitReader* const br) {}

//------------------------------------------------------------------------------
// Higher-level calls

uint32_t VP8GetValue(VP8BitReader* const br, int bits, const char label[]) {}

int32_t VP8GetSignedValue(VP8BitReader* const br, int bits,
                          const char label[]) {}

//------------------------------------------------------------------------------
// VP8LBitReader

#define VP8L_LOG8_WBITS

#if defined(__arm__) || defined(_M_ARM) || WEBP_AARCH64 || \
    defined(__i386__) || defined(_M_IX86) || \
    defined(__x86_64__) || defined(_M_X64)
#define VP8L_USE_FAST_LOAD
#endif

static const uint32_t kBitMask[VP8L_MAX_NUM_BIT_READ + 1] =;

void VP8LInitBitReader(VP8LBitReader* const br, const uint8_t* const start,
                       size_t length) {}

void VP8LBitReaderSetBuffer(VP8LBitReader* const br,
                            const uint8_t* const buf, size_t len) {}

static void VP8LSetEndOfStream(VP8LBitReader* const br) {}

// If not at EOS, reload up to VP8L_LBITS byte-by-byte
static void ShiftBytes(VP8LBitReader* const br) {}

void VP8LDoFillBitWindow(VP8LBitReader* const br) {}

uint32_t VP8LReadBits(VP8LBitReader* const br, int n_bits) {}

//------------------------------------------------------------------------------
// Bit-tracing tool

#if (BITTRACE > 0)

#include <stdlib.h>   // for atexit()
#include <stdio.h>
#include <string.h>

#define MAX_NUM_LABELS
static struct {
  const char* label;
  int size;
  int count;
} kLabels[MAX_NUM_LABELS];

static int last_label = 0;
static int last_pos = 0;
static const uint8_t* buf_start = NULL;
static int init_done = 0;

static void PrintBitTraces(void) {
  int i;
  int scale = 1;
  int total = 0;
  const char* units = "bits";
#if (BITTRACE == 2)
  scale = 8;
  units = "bytes";
#endif
  for (i = 0; i < last_label; ++i) total += kLabels[i].size;
  if (total < 1) total = 1;   // avoid rounding errors
  printf("=== Bit traces ===\n");
  for (i = 0; i < last_label; ++i) {
    const int skip = 16 - (int)strlen(kLabels[i].label);
    const int value = (kLabels[i].size + scale - 1) / scale;
    assert(skip > 0);
    printf("%s \%*s: %6d %s   \t[%5.2f%%] [count: %7d]\n",
           kLabels[i].label, skip, "", value, units,
           100.f * kLabels[i].size / total,
           kLabels[i].count);
  }
  total = (total + scale - 1) / scale;
  printf("Total: %d %s\n", total, units);
}

void BitTrace(const struct VP8BitReader* const br, const char label[]) {
  int i, pos;
  if (!init_done) {
    memset(kLabels, 0, sizeof(kLabels));
    atexit(PrintBitTraces);
    buf_start = br->buf_;
    init_done = 1;
  }
  pos = (int)(br->buf_ - buf_start) * 8 - br->bits_;
  // if there's a too large jump, we've changed partition -> reset counter
  if (abs(pos - last_pos) > 32) {
    buf_start = br->buf_;
    pos = 0;
    last_pos = 0;
  }
  if (br->range_ >= 0x7f) pos += kVP8Log2Range[br->range_ - 0x7f];
  for (i = 0; i < last_label; ++i) {
    if (!strcmp(label, kLabels[i].label)) break;
  }
  if (i == MAX_NUM_LABELS) abort();   // overflow!
  kLabels[i].label = label;
  kLabels[i].size += pos - last_pos;
  kLabels[i].count += 1;
  if (i == last_label) ++last_label;
  last_pos = pos;
}

#endif  // BITTRACE > 0

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