From 0726204505660e039d2ec77ed8428ba861313d23 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 25 Mar 2012 22:19:36 +0200 Subject: [PATCH] If HAVE_ZLIB is set, use zlib internal crc32. --- movie.c | 18 +++++++++++++++--- movie.h | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/movie.c b/movie.c index adf50897b4..0948a06e12 100644 --- a/movie.c +++ b/movie.c @@ -22,8 +22,19 @@ #include "general.h" #include "dynamic.h" -// CRC32 implementation taken from BSNES source :) +#ifdef HAVE_ZLIB +#include "console/szlib/zlib.h" +uint32_t crc32_calculate(const uint8_t *data, size_t length) +{ + return crc32(0, data, length); +} +uint32_t crc32_adjust(uint32_t crc, uint8_t data) +{ + return crc32(crc, &data, 1); +} +#else +// Zlib crc32. static const uint32_t crc32_table[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, @@ -75,13 +86,14 @@ uint32_t crc32_adjust(uint32_t crc32, uint8_t input) return ((crc32 >> 8) & 0x00ffffff) ^ crc32_table[(crc32 ^ input) & 0xff]; } -uint32_t crc32_calculate(const uint8_t *data, unsigned length) +uint32_t crc32_calculate(const uint8_t *data, size_t length) { uint32_t crc32 = ~0; - for (unsigned i = 0; i < length; i++) + for (size_t i = 0; i < length; i++) crc32 = crc32_adjust(crc32, data[i]); return ~crc32; } +#endif struct bsv_movie { diff --git a/movie.h b/movie.h index 8d95e5b9a8..efd86c4eee 100644 --- a/movie.h +++ b/movie.h @@ -48,8 +48,8 @@ void bsv_movie_frame_rewind(bsv_movie_t *handle); void bsv_movie_free(bsv_movie_t *handle); -uint32_t crc32_calculate(const uint8_t *data, unsigned length); -uint32_t crc32_adjust(uint32_t crc32, uint8_t input); +uint32_t crc32_calculate(const uint8_t *data, size_t length); +uint32_t crc32_adjust(uint32_t crc, uint8_t data); #endif