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

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

Definition at line 60 of file SDL_test_crc32.h.

Referenced by SDLTest_Crc32Init().

#define CrcUint32   unsigned int

Definition at line 51 of file SDL_test_crc32.h.

Referenced by SDLTest_Crc32CalcBuffer(), and SDLTest_Crc32Init().

#define CrcUint8   unsigned char

Definition at line 54 of file SDL_test_crc32.h.

Referenced by SDLTest_Crc32CalcBuffer().

Function Documentation

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
int SDLTest_Crc32CalcBuffer ( SDLTest_Crc32Context crcContext,
CrcUint8 inBuf,
CrcUint32  inLen,
CrcUint32 crc32 
)

Definition at line 129 of file SDL_test_crc32.c.

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

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

Definition at line 111 of file SDL_test_crc32.c.

References NULL.

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

Definition at line 93 of file SDL_test_crc32.c.

References NULL.

94 {
95  /* Sanity check pointers */
96  if (crcContext==NULL) {
97  *crc32=0;
98  return -1;
99  }
100 
101  /*
102  * Preload shift register, per CRC-32 spec
103  */
104  *crc32 = 0xffffffff;
105 
106  return 0;
107 }
#define NULL
Definition: begin_code.h:164
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 159 of file SDL_test_crc32.c.

References NULL.

160 {
161  if (crcContext==NULL) {
162  return -1;
163  }
164 
165  return 0;
166 }
#define NULL
Definition: begin_code.h:164
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 in i)
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 int in j)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:164
#define CrcUint32