Merge "introduce WebPMemToUint32 and WebPUint32ToMem for memory access"

This commit is contained in:
Pascal Massimino
2015-12-08 11:32:05 +00:00
committed by Gerrit Code Review
11 changed files with 112 additions and 108 deletions

View File

@ -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;

View File

@ -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.