24 #define DBG_PROGNAME "OPENCBM.DLL"
82 size_t sourceLength,
size_t destLength)
88 DBG_ASSERT( (source != NULL ) && (sourceLength > 0) );
89 DBG_ASSERT( (dest != NULL ) && (destLength > 0) );
90 DBG_ASSERT( (dest < (source + 2)) || (dest > (source+4)) );
94 DBG_WARN((
DBG_PREFIX "*** source buffer is less than 5 bytes, only partial decoding done!"));
98 DBG_WARN((
DBG_PREFIX "*** destination buffer is less than 4 bytes, only partial decoding done!"));
101 if( (source == NULL) || (dest == NULL) || (sourceLength<=0) )
110 static const unsigned char decodeGCR[32] =
111 {255,255,255,255,255,255,255,255,255, 8, 0, 1,255, 12, 4, 5,
112 255,255, 2, 3,255, 15, 6, 7,255, 9, 10, 11,255, 13, 14,255 };
115 register unsigned int tdest, nybble;
122 for(i = 5; (i < 13) && (destLength > 0); i += 2, dest++, destLength--)
124 source++, sourceLength--;
127 tdest |= ((
unsigned int)(*source)) << i;
135 if ( 0 == ((tdest >> 16) & 0x3ff) )
break;
141 nybble = decodeGCR[ (tdest >> 16) & 0x1f ];
142 if(nybble > 15) rv |= 2;
146 nybble = decodeGCR[ (tdest >> 16) & 0x1f ];
147 if(nybble > 15) rv |= 1;
148 *dest |= (nybble & 0x0f);
207 size_t sourceLength,
size_t destLength)
213 DBG_ASSERT( (source != NULL ) && (sourceLength > 0) );
214 DBG_ASSERT( (dest != NULL ) && (destLength > 0) );
215 DBG_ASSERT( (dest <= source ) || (dest > (source+3)) );
217 if (sourceLength < 4)
219 DBG_WARN((
DBG_PREFIX "*** source buffer is less than 4 bytes, only partial decoding done!"));
223 DBG_WARN((
DBG_PREFIX "*** destination buffer is less than 5 bytes, only partial decoding done!"));
226 if( (source == NULL) || (dest == NULL) || (sourceLength<=0) )
232 static const unsigned char encodeGCR[16] =
233 { 10, 11, 18, 19, 14, 15, 22, 23, 9, 25, 26, 27, 13, 29, 30, 21 };
236 register unsigned int tdest = 0;
241 (i < 10) && (sourceLength > 0) && (destLength > 0);
242 i += 2, source++, sourceLength--, dest++, destLength--)
245 tdest |= encodeGCR[ (*source) >> 4 ];
248 tdest |= encodeGCR[ (*source) & 0x0f ];
250 *dest = (
unsigned char)(tdest >> i);
261 *dest = ((
unsigned char)(tdest)) << ((10-i) & 0x07);
#define FUNC_LEAVE_INT(_xxx)
Define makros for debugging purposes.
int CBMAPIDECL gcr_4_to_5_encode(const unsigned char *source, unsigned char *dest, size_t sourceLength, size_t destLength)
Encode GCR data.
DLL interface for accessing the driver.
int CBMAPIDECL gcr_5_to_4_decode(const unsigned char *source, unsigned char *dest, size_t sourceLength, size_t destLength)
Decode GCR data.