SDL  2.0
SDL_test_crc32.c File Reference
#include "SDL_config.h"
#include "SDL_test.h"
+ Include dependency graph for SDL_test_crc32.c:

Go to the source code of this file.

Functions

int SDLTest_Crc32Init (SDLTest_Crc32Context *crcContext)
 Initialize the CRC context. More...
 
int SDLTest_Crc32Calc (SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
 
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...
 

Function Documentation

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

Definition at line 73 of file SDL_test_crc32.c.

References SDLTest_Crc32CalcBuffer(), SDLTest_Crc32CalcEnd(), and SDLTest_Crc32CalcStart().

74 {
75  if (SDLTest_Crc32CalcStart(crcContext,crc32)) {
76  return -1;
77  }
78 
79  if (SDLTest_Crc32CalcBuffer(crcContext, inBuf, inLen, crc32)) {
80  return -1;
81  }
82 
83  if (SDLTest_Crc32CalcEnd(crcContext, crc32)) {
84  return -1;
85  }
86 
87  return 0;
88 }
int SDLTest_Crc32CalcEnd(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
int SDLTest_Crc32CalcBuffer(SDLTest_Crc32Context *crcContext, CrcUint8 *inBuf, CrcUint32 inLen, CrcUint32 *crc32)
int SDLTest_Crc32CalcStart(SDLTest_Crc32Context *crcContext, CrcUint32 *crc32)
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
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
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
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
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]
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:42
#define NULL
Definition: begin_code.h:143
#define CrcUint32
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:42