summaryrefslogtreecommitdiffstats
path: root/drivers/webp/utils/utils.h
diff options
context:
space:
mode:
authorvolzhs <volzhs@gmail.com>2016-07-08 19:29:58 +0900
committervolzhs <volzhs@gmail.com>2016-07-08 21:44:40 +0900
commitddd446f274d33d8624da3fd842c23e9ede0e6b11 (patch)
treef3b5de16472af57350b4f1de8d40b64365423b90 /drivers/webp/utils/utils.h
parentdc58be9f3542d640771722187959f56f042b5baa (diff)
downloadredot-engine-ddd446f274d33d8624da3fd842c23e9ede0e6b11.tar.gz
Update webp driver to 0.5.1 (upstream)
Diffstat (limited to 'drivers/webp/utils/utils.h')
-rw-r--r--drivers/webp/utils/utils.h44
1 files changed, 42 insertions, 2 deletions
diff --git a/drivers/webp/utils/utils.h b/drivers/webp/utils/utils.h
index d0e1cb250a..e0a81126df 100644
--- a/drivers/webp/utils/utils.h
+++ b/drivers/webp/utils/utils.h
@@ -15,9 +15,14 @@
#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"
+#include "../dsp/dsp.h"
+#include "../webp/types.h"
#ifdef __cplusplus
extern "C" {
@@ -47,7 +52,29 @@ WEBP_EXTERN(void) WebPSafeFree(void* const ptr);
// Alignment
#define WEBP_ALIGN_CST 31
-#define WEBP_ALIGN(PTR) ((uintptr_t)((PTR) + WEBP_ALIGN_CST) & ~WEBP_ALIGN_CST)
+#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_UBSAN_IGNORE_UNDEF WEBP_INLINE
+uint32_t WebPMemToUint32(const uint8_t* const ptr) {
+ return *(const uint32_t*)ptr;
+}
+static WEBP_UBSAN_IGNORE_UNDEF WEBP_INLINE
+void WebPUint32ToMem(uint8_t* const ptr, uint32_t val) {
+ *(uint32_t*)ptr = val;
+}
+#endif
//------------------------------------------------------------------------------
// Reading/writing data.
@@ -134,6 +161,19 @@ WEBP_EXTERN(void) WebPCopyPixels(const struct WebPPicture* const src,
struct WebPPicture* const dst);
//------------------------------------------------------------------------------
+// Unique colors.
+
+// Returns count of unique colors in 'pic', assuming pic->use_argb is true.
+// If the unique color count is more than MAX_COLOR_COUNT, returns
+// MAX_COLOR_COUNT+1.
+// If 'palette' is not NULL and number of unique colors is less than or equal to
+// MAX_COLOR_COUNT, also outputs the actual unique colors into 'palette'.
+// Note: 'palette' is assumed to be an array already allocated with at least
+// MAX_COLOR_COUNT elements.
+WEBP_EXTERN(int) WebPGetColorPalette(const struct WebPPicture* const pic,
+ uint32_t* const palette);
+
+//------------------------------------------------------------------------------
#ifdef __cplusplus
} // extern "C"