SDL  2.0
SDL_test_crc32.h File Reference
#include "begin_code.h"
#include "close_code.h"
+ Include dependency graph for SDL_test_crc32.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SDLTest_Crc32Context
 

Macros

#define CrcUint32   unsigned int
 
#define CrcUint8   unsigned char
 
#define CRC32_POLY   0xEDB88320 /* Perl String::CRC32 compatible */
 

Functions

int SDLTest_Crc32Init (SDLTest_Crc32Context *crcContext)
 Initialize the CRC context. More...
 
int SDLTest_crc32Calc (SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
 calculate a crc32 from a data block More...
 
int SDLTest_Crc32CalcStart (SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
 
int SDLTest_Crc32CalcEnd (SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
 
int SDLTest_Crc32CalcBuffer (SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
 
int SDLTest_Crc32Done (SDLTest_Crc32Context *crcContext)
 clean up CRC context More...
 

Detailed Description

Include file for SDL test framework.

This code is a part of the SDL2_test library, not the main SDL library.

Definition in file SDL_test_crc32.h.

Macro Definition Documentation

§ CRC32_POLY

#define CRC32_POLY   0xEDB88320 /* Perl String::CRC32 compatible */

Definition at line 60 of file SDL_test_crc32.h.

Referenced by SDLTest_Crc32Init().

§ CrcUint32

#define CrcUint32   unsigned int

Definition at line 51 of file SDL_test_crc32.h.

Referenced by SDLTest_Crc32CalcBuffer(), and SDLTest_Crc32Init().

§ CrcUint8

#define CrcUint8   unsigned char

Definition at line 54 of file SDL_test_crc32.h.

Referenced by SDLTest_Crc32CalcBuffer().

Function Documentation

§ SDLTest_crc32Calc()

int SDLTest_crc32Calc ( SDLTest_Crc32Context crcContext,
CrcUint8 inBuf,
CrcUint32  inLen,
CrcUint32 crc32 
)

calculate a crc32 from a data block

Parameters
crcContextpointer to context variable
inBufinput buffer to checksum
inLenlength of input buffer
crc32pointer to Uint32 to store the final CRC into
Returns
0 for OK, -1 on error

§ SDLTest_Crc32CalcBuffer()

int SDLTest_Crc32CalcBuffer ( SDLTest_Crc32Context crcContext,
CrcUint8 inBuf,
CrcUint32  inLen,
CrcUint32 crc32 
)

Definition at line 128 of file SDL_test_crc32.c.

References SDLTest_Crc32Context::crc32_table, CrcUint32, CrcUint8, and NULL.

Referenced by SDLTest_Crc32Calc().

129 {
130  CrcUint8 *p;
131  register CrcUint32 crc;
132 
133  if (crcContext==NULL) {
134  *crc32=0;
135  return -1;
136  }
137 
138  if (inBuf==NULL) {
139  return -1;
140  }
141 
142  /*
143  * Calculate CRC from data
144  */
145  crc = *crc32;
146  for (p = inBuf; inLen > 0; ++p, --inLen) {
147 #ifdef ORIGINAL_METHOD
148  crc = (crc << 8) ^ crcContext->crc32_table[(crc >> 24) ^ *p];
149 #else
150  crc = ((crc >> 8) & 0x00FFFFFF) ^ crcContext->crc32_table[ (crc ^ *p) & 0xFF ];
151 #endif
152  }
153  *crc32 = crc;
154 
155  return 0;
156 }
GLfloat GLfloat p
CrcUint32 crc32_table[256]
#define NULL
Definition: begin_code.h:143
#define CrcUint32
#define CrcUint8

§ SDLTest_Crc32CalcEnd()

int SDLTest_Crc32CalcEnd ( SDLTest_Crc32Context crcContext,
CrcUint32 crc32 
)

Definition at line 110 of file SDL_test_crc32.c.

References NULL.

Referenced by SDLTest_Crc32Calc().

111 {
112  /* Sanity check pointers */
113  if (crcContext==NULL) {
114  *crc32=0;
115  return -1;
116  }
117 
118  /*
119  * Return complement, per CRC-32 spec
120  */
121  *crc32 = (~(*crc32));
122 
123  return 0;
124 }
#define NULL
Definition: begin_code.h:143

§ SDLTest_Crc32CalcStart()

int SDLTest_Crc32CalcStart ( SDLTest_Crc32Context crcContext,
CrcUint32 crc32 
)

Definition at line 92 of file SDL_test_crc32.c.

References NULL.

Referenced by SDLTest_Crc32Calc().

93 {
94  /* Sanity check pointers */
95  if (crcContext==NULL) {
96  *crc32=0;
97  return -1;
98  }
99 
100  /*
101  * Preload shift register, per CRC-32 spec
102  */
103  *crc32 = 0xffffffff;
104 
105  return 0;
106 }
#define NULL
Definition: begin_code.h:143

§ SDLTest_Crc32Done()

int SDLTest_Crc32Done ( SDLTest_Crc32Context crcContext)

clean up CRC context

Parameters
crcContextpointer to context variable
Returns
0 for OK, -1 on error

Definition at line 158 of file SDL_test_crc32.c.

References NULL.

159 {
160  if (crcContext==NULL) {
161  return -1;
162  }
163 
164  return 0;
165 }
#define NULL
Definition: begin_code.h:143

§ SDLTest_Crc32Init()

int SDLTest_Crc32Init ( SDLTest_Crc32Context crcContext)

Initialize the CRC context.

Note: The function initializes the crc table required for all crc calculations.

Parameters
crcContextpointer to context variable
Returns
0 for OK, -1 on error

Definition at line 34 of file SDL_test_crc32.c.

References CRC32_POLY, SDLTest_Crc32Context::crc32_table, CrcUint32, i, j, and NULL.

35 {
36  int i,j;
37  CrcUint32 c;
38 
39  /* Sanity check context pointer */
40  if (crcContext==NULL) {
41  return -1;
42  }
43 
44  /*
45  * Build auxiliary table for parallel byte-at-a-time CRC-32
46  */
47 #ifdef ORIGINAL_METHOD
48  for (i = 0; i < 256; ++i) {
49  for (c = i << 24, j = 8; j > 0; --j) {
50  c = c & 0x80000000 ? (c << 1) ^ CRC32_POLY : (c << 1);
51  }
52  crcContext->crc32_table[i] = c;
53  }
54 #else
55  for (i=0; i<256; i++) {
56  c = i;
57  for (j=8; j>0; j--) {
58  if (c & 1) {
59  c = (c >> 1) ^ CRC32_POLY;
60  } else {
61  c >>= 1;
62  }
63  }
64  crcContext->crc32_table[i] = c;
65  }
66 #endif
67 
68  return 0;
69 }
#define CRC32_POLY
CrcUint32 crc32_table[256]
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
Definition: SDL_x11sym.h:50
const GLubyte * c
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:143
#define CrcUint32