include/SDL_test_crc32.h
changeset 6713 fa17a97389ed
child 6885 700f1b25f77f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/SDL_test_crc32.h	Wed Nov 28 19:19:57 2012 -0800
     1.3 @@ -0,0 +1,128 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +
    1.25 +/**
    1.26 + *  \file SDL_test_crc32.h
    1.27 + *  
    1.28 + *  Include file for SDL test framework.
    1.29 + *
    1.30 + *  This code is a part of the SDL2_test library, not the main SDL library.
    1.31 + */
    1.32 +
    1.33 +/* 
    1.34 +
    1.35 + Implements CRC32 calculations (default output is Perl String::CRC32 compatible).
    1.36 +  
    1.37 +*/
    1.38 +
    1.39 +#ifndef _SDL_test_crc32_h
    1.40 +#define _SDL_test_crc32_h
    1.41 +
    1.42 +#include "begin_code.h"
    1.43 +/* Set up for C function definitions, even when using C++ */
    1.44 +#ifdef __cplusplus
    1.45 +/* *INDENT-OFF* */
    1.46 +extern "C" {
    1.47 +/* *INDENT-ON* */
    1.48 +#endif
    1.49 +
    1.50 +
    1.51 +/* ------------ Definitions --------- */
    1.52 +
    1.53 +/* Definition shared by all CRC routines */
    1.54 +
    1.55 +#ifndef CrcUint32
    1.56 + #define CrcUint32	unsigned int
    1.57 +#endif
    1.58 +#ifndef CrcUint8
    1.59 + #define CrcUint8	unsigned char
    1.60 +#endif
    1.61 +
    1.62 +#ifdef ORIGINAL_METHOD
    1.63 + #define CRC32_POLY 0x04c11db7 	 /* AUTODIN II, Ethernet, & FDDI */
    1.64 +#else
    1.65 + #define CRC32_POLY 0xEDB88320   /* Perl String::CRC32 compatible */
    1.66 +#endif
    1.67 +
    1.68 +/** 
    1.69 + * Data structure for CRC32 (checksum) computation 
    1.70 + */
    1.71 +  typedef struct {
    1.72 +    CrcUint32    crc32_table[256]; /* CRC table */
    1.73 +  } SDLTest_Crc32Context;
    1.74 +
    1.75 +/* ---------- Function Prototypes ------------- */
    1.76 +
    1.77 +/** 
    1.78 + * /brief Initialize the CRC context
    1.79 + *
    1.80 + * Note: The function initializes the crc table required for all crc calculations.
    1.81 + *
    1.82 + * /param crcContext		pointer to context variable
    1.83 + *
    1.84 + * /returns 0 for OK, -1 on error
    1.85 + *
    1.86 + */
    1.87 + int SDLTest_Crc32Init(SDLTest_Crc32Context * crcContext);
    1.88 +
    1.89 +
    1.90 +/**
    1.91 + * /brief calculate a crc32 from a data block
    1.92 + * 
    1.93 + * /param crcContext	     pointer to context variable
    1.94 + * /param inBuf              input buffer to checksum
    1.95 + * /param inLen              length of input buffer
    1.96 + * /param crc32              pointer to Uint32 to store the final CRC into
    1.97 + *
    1.98 + * /returns 0 for OK, -1 on error
    1.99 + *
   1.100 + */
   1.101 +int SDLTest_crc32Calc(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
   1.102 +
   1.103 +/* Same routine broken down into three steps */
   1.104 +int SDLTest_Crc32CalcStart(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
   1.105 +int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context * crcContext, CrcUint32 *crc32);
   1.106 +int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context * crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32);
   1.107 +
   1.108 +
   1.109 +/**
   1.110 + * /brief clean up CRC context
   1.111 + *
   1.112 + * /param crcContext		pointer to context variable
   1.113 + *
   1.114 + * /returns 0 for OK, -1 on error
   1.115 + *
   1.116 +*/
   1.117 +
   1.118 +int SDLTest_Crc32Done(SDLTest_Crc32Context * crcContext);
   1.119 +
   1.120 +
   1.121 +/* Ends C function definitions when using C++ */
   1.122 +#ifdef __cplusplus
   1.123 +/* *INDENT-OFF* */
   1.124 +}
   1.125 +/* *INDENT-ON* */
   1.126 +#endif
   1.127 +#include "close_code.h"
   1.128 +
   1.129 +#endif /* _SDL_test_crc32_h */
   1.130 +
   1.131 +/* vi: set ts=4 sw=4 expandtab: */