mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 20:44:52 +00:00

The google's libwebp source uses aligned memory access. This patch is that applies the two commits below to our static lib code. refer to: [Remove WEBP_FORCE_ALIGNED and use memcpy() instead]3884972e3f
[bit_reader.c: s/VP8L_USE_UNALIGNED_LOAD/VP8L_USE_FAST_LOAD/]ac49e4e4dc
source : https://chromium.googlesource.com/webm/libwebp/+/refs/heads/main/src/utils/bit_reader_inl_utils.h#80 related issue: https://github.com/thorvg/thorvg/issues/2006
80 lines
2.2 KiB
C
80 lines
2.2 KiB
C
// Copyright 2012 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.
|
|
// -----------------------------------------------------------------------------
|
|
//
|
|
// Misc. common utility functions
|
|
//
|
|
// Authors: Skal (pascal.massimino@gmail.com)
|
|
// Urvang (urvang@google.com)
|
|
|
|
#ifndef WEBP_UTILS_UTILS_H_
|
|
#define WEBP_UTILS_UTILS_H_
|
|
|
|
#include <assert.h>
|
|
|
|
#include "../webp/types.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Returns (int)floor(log2(n)). n must be > 0.
|
|
// use GNU builtins where available.
|
|
#if defined(__GNUC__) && \
|
|
((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ >= 4)
|
|
static WEBP_INLINE int BitsLog2Floor(uint32_t n) {
|
|
return 31 ^ __builtin_clz(n);
|
|
}
|
|
#elif defined(_MSC_VER) && _MSC_VER > 1310 && \
|
|
(defined(_M_X64) || defined(_M_IX86))
|
|
#include <intrin.h>
|
|
#pragma intrinsic(_BitScanReverse)
|
|
|
|
static WEBP_INLINE int BitsLog2Floor(uint32_t n) {
|
|
uint32_t first_set_bit;
|
|
_BitScanReverse((unsigned long*)&first_set_bit, n);
|
|
return first_set_bit;
|
|
}
|
|
#else
|
|
static WEBP_INLINE int BitsLog2Floor(uint32_t n) {
|
|
int log = 0;
|
|
uint32_t value = n;
|
|
int i;
|
|
|
|
for (i = 4; i >= 0; --i) {
|
|
const int shift = (1 << i);
|
|
const uint32_t x = value >> shift;
|
|
if (x != 0) {
|
|
value = x;
|
|
log += shift;
|
|
}
|
|
}
|
|
return log;
|
|
}
|
|
#endif
|
|
|
|
//------------------------------------------------------------------------------
|
|
//------------------------------------------------------------------------------
|
|
// Alignment
|
|
|
|
#include <string.h>
|
|
// memcpy() is the safe way of moving potentially unaligned 32b memory.
|
|
static WEBP_INLINE uint32_t WebPMemToUint32(const uint8_t* const ptr) {
|
|
uint32_t A;
|
|
memcpy(&A, ptr, sizeof(A));
|
|
return A;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif
|
|
|
|
#endif /* WEBP_UTILS_UTILS_H_ */
|