mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 14:34:33 +02:00
Merge "introduce WebPMemToUint32 and WebPUint32ToMem for memory access"
This commit is contained in:
@ -199,7 +199,7 @@ void VP8LDoFillBitWindow(VP8LBitReader* const br) {
|
||||
br->bit_pos_ -= VP8L_WBITS;
|
||||
// The expression below needs a little-endian arch to work correctly.
|
||||
// This gives a large speedup for decoding speed.
|
||||
br->val_ |= (vp8l_val_t)*(const uint32_t*)(br->buf_ + br->pos_) <<
|
||||
br->val_ |= (vp8l_val_t)WebPMemToUint32(br->buf_ + br->pos_) <<
|
||||
(VP8L_LBITS - VP8L_WBITS);
|
||||
br->pos_ += VP8L_LOG8_WBITS;
|
||||
return;
|
||||
|
@ -15,6 +15,10 @@
|
||||
#ifndef WEBP_UTILS_UTILS_H_
|
||||
#define WEBP_UTILS_UTILS_H_
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../webp/config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "../webp/types.h"
|
||||
@ -49,6 +53,26 @@ WEBP_EXTERN(void) WebPSafeFree(void* const ptr);
|
||||
#define WEBP_ALIGN_CST 31
|
||||
#define WEBP_ALIGN(PTR) ((uintptr_t)((PTR) + WEBP_ALIGN_CST) & ~WEBP_ALIGN_CST)
|
||||
|
||||
#if defined(WEBP_FORCE_ALIGNED)
|
||||
#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, (const int*)ptr, sizeof(A));
|
||||
return A;
|
||||
}
|
||||
static WEBP_INLINE void WebPUint32ToMem(uint8_t* const ptr, uint32_t val) {
|
||||
memcpy(ptr, &val, sizeof(val));
|
||||
}
|
||||
#else
|
||||
static WEBP_INLINE uint32_t WebPMemToUint32(const uint8_t* const ptr) {
|
||||
return *(const uint32_t*)ptr;
|
||||
}
|
||||
static WEBP_INLINE void WebPUint32ToMem(uint8_t* const ptr, uint32_t val) {
|
||||
*(uint32_t*)ptr = val;
|
||||
}
|
||||
#endif
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Reading/writing data.
|
||||
|
||||
|
Reference in New Issue
Block a user