浏览代码

WARNING: RENAMED: some parameters from length to size

When referring to byte array SIZE, I find it more clear than length
pull/2431/head
Ray 3 年前
父节点
当前提交
f71cc53bc9
共有 2 个文件被更改,包括 35 次插入35 次删除
  1. +4
    -4
      src/raylib.h
  2. +31
    -31
      src/rcore.c

+ 4
- 4
src/raylib.h 查看文件

@ -1063,10 +1063,10 @@ RLAPI void ClearDroppedFiles(void); // Clear dropp
RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time) RLAPI long GetFileModTime(const char *fileName); // Get file modification time (last write time)
// Compression/Encoding functionality // Compression/Encoding functionality
RLAPI unsigned char *CompressData(const unsigned char *data, int dataLength, int *compDataLength); // Compress data (DEFLATE algorithm)
RLAPI unsigned char *DecompressData(const unsigned char *compData, int compDataLength, int *dataLength); // Decompress data (DEFLATE algorithm)
RLAPI char *EncodeDataBase64(const unsigned char *data, int dataLength, int *outputLength); // Encode data to Base64 string
RLAPI unsigned char *DecodeDataBase64(const unsigned char *data, int *outputLength); // Decode Base64 string data
RLAPI unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize); // Compress data (DEFLATE algorithm)
RLAPI unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize); // Decompress data (DEFLATE algorithm)
RLAPI char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize); // Encode data to Base64 string
RLAPI unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize); // Decode Base64 string data
// Persistent storage management // Persistent storage management
RLAPI bool SaveStorageValue(unsigned int position, int value); // Save integer value to storage file (to defined position), returns true on success RLAPI bool SaveStorageValue(unsigned int position, int value); // Save integer value to storage file (to defined position), returns true on success

+ 31
- 31
src/rcore.c 查看文件

@ -3187,7 +3187,7 @@ long GetFileModTime(const char *fileName)
} }
// Compress data (DEFLATE algorythm) // Compress data (DEFLATE algorythm)
unsigned char *CompressData(const unsigned char *data, int dataLength, int *compDataLength)
unsigned char *CompressData(const unsigned char *data, int dataSize, int *compDataSize)
{ {
#define COMPRESSION_QUALITY_DEFLATE 8 #define COMPRESSION_QUALITY_DEFLATE 8
@ -3196,40 +3196,40 @@ unsigned char *CompressData(const unsigned char *data, int dataLength, int *comp
#if defined(SUPPORT_COMPRESSION_API) #if defined(SUPPORT_COMPRESSION_API)
// Compress data and generate a valid DEFLATE stream // Compress data and generate a valid DEFLATE stream
struct sdefl sdefl = { 0 }; struct sdefl sdefl = { 0 };
int bounds = sdefl_bound(dataLength);
int bounds = sdefl_bound(dataSize);
compData = (unsigned char *)RL_CALLOC(bounds, 1); compData = (unsigned char *)RL_CALLOC(bounds, 1);
*compDataLength = sdeflate(&sdefl, compData, data, dataLength, COMPRESSION_QUALITY_DEFLATE); // Compression level 8, same as stbwi
*compDataSize = sdeflate(&sdefl, compData, data, dataSize, COMPRESSION_QUALITY_DEFLATE); // Compression level 8, same as stbwi
TraceLog(LOG_INFO, "SYSTEM: Compress data: Original size: %i -> Comp. size: %i", dataLength, *compDataLength);
TraceLog(LOG_INFO, "SYSTEM: Compress data: Original size: %i -> Comp. size: %i", dataSize, *compDataSize);
#endif #endif
return compData; return compData;
} }
// Decompress data (DEFLATE algorythm) // Decompress data (DEFLATE algorythm)
unsigned char *DecompressData(const unsigned char *compData, int compDataLength, int *dataLength)
unsigned char *DecompressData(const unsigned char *compData, int compDataSize, int *dataSize)
{ {
unsigned char *data = NULL; unsigned char *data = NULL;
#if defined(SUPPORT_COMPRESSION_API) #if defined(SUPPORT_COMPRESSION_API)
// Decompress data from a valid DEFLATE stream // Decompress data from a valid DEFLATE stream
data = RL_CALLOC(MAX_DECOMPRESSION_SIZE*1024*1024, 1); data = RL_CALLOC(MAX_DECOMPRESSION_SIZE*1024*1024, 1);
int length = sinflate(data, MAX_DECOMPRESSION_SIZE, compData, compDataLength);
int length = sinflate(data, MAX_DECOMPRESSION_SIZE, compData, compDataSize);
unsigned char *temp = RL_REALLOC(data, length); unsigned char *temp = RL_REALLOC(data, length);
if (temp != NULL) data = temp; if (temp != NULL) data = temp;
else TRACELOG(LOG_WARNING, "SYSTEM: Failed to re-allocate required decompression memory"); else TRACELOG(LOG_WARNING, "SYSTEM: Failed to re-allocate required decompression memory");
*dataLength = length;
*dataSize = length;
TraceLog(LOG_INFO, "SYSTEM: Decompress data: Comp. size: %i -> Original size: %i", compDataLength, *dataLength);
TraceLog(LOG_INFO, "SYSTEM: Decompress data: Comp. size: %i -> Original size: %i", compDataSize, *dataSize);
#endif #endif
return data; return data;
} }
// Encode data to Base64 string // Encode data to Base64 string
char *EncodeDataBase64(const unsigned char *data, int dataLength, int *outputLength)
char *EncodeDataBase64(const unsigned char *data, int dataSize, int *outputSize)
{ {
static const unsigned char base64encodeTable[] = { static const unsigned char base64encodeTable[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
@ -3239,17 +3239,17 @@ char *EncodeDataBase64(const unsigned char *data, int dataLength, int *outputLen
static const int modTable[] = { 0, 2, 1 }; static const int modTable[] = { 0, 2, 1 };
*outputLength = 4*((dataLength + 2)/3);
*outputSize = 4*((dataSize + 2)/3);
char *encodedData = RL_MALLOC(*outputLength);
char *encodedData = RL_MALLOC(*outputSize);
if (encodedData == NULL) return NULL; if (encodedData == NULL) return NULL;
for (int i = 0, j = 0; i < dataLength;)
for (int i = 0, j = 0; i < dataSize;)
{ {
unsigned int octetA = (i < dataLength)? (unsigned char)data[i++] : 0;
unsigned int octetB = (i < dataLength)? (unsigned char)data[i++] : 0;
unsigned int octetC = (i < dataLength)? (unsigned char)data[i++] : 0;
unsigned int octetA = (i < dataSize)? (unsigned char)data[i++] : 0;
unsigned int octetB = (i < dataSize)? (unsigned char)data[i++] : 0;
unsigned int octetC = (i < dataSize)? (unsigned char)data[i++] : 0;
unsigned int triple = (octetA << 0x10) + (octetB << 0x08) + octetC; unsigned int triple = (octetA << 0x10) + (octetB << 0x08) + octetC;
@ -3259,13 +3259,13 @@ char *EncodeDataBase64(const unsigned char *data, int dataLength, int *outputLen
encodedData[j++] = base64encodeTable[(triple >> 0*6) & 0x3F]; encodedData[j++] = base64encodeTable[(triple >> 0*6) & 0x3F];
} }
for (int i = 0; i < modTable[dataLength%3]; i++) encodedData[*outputLength - 1 - i] = '='; // Padding character
for (int i = 0; i < modTable[dataSize%3]; i++) encodedData[*outputSize - 1 - i] = '='; // Padding character
return encodedData; return encodedData;
} }
// Decode Base64 string data // Decode Base64 string data
unsigned char *DecodeDataBase64(const unsigned char *data, int *outputLength)
unsigned char *DecodeDataBase64(const unsigned char *data, int *outputSize)
{ {
static const unsigned char base64decodeTable[] = { static const unsigned char base64decodeTable[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -3275,21 +3275,21 @@ unsigned char *DecodeDataBase64(const unsigned char *data, int *outputLength)
}; };
// Get output size of Base64 input data // Get output size of Base64 input data
int outLength = 0;
int outSize = 0;
for (int i = 0; data[4*i] != 0; i++) for (int i = 0; data[4*i] != 0; i++)
{ {
if (data[4*i + 3] == '=') if (data[4*i + 3] == '=')
{ {
if (data[4*i + 2] == '=') outLength += 1;
else outLength += 2;
if (data[4*i + 2] == '=') outSize += 1;
else outSize += 2;
} }
else outLength += 3;
else outSize += 3;
} }
// Allocate memory to store decoded Base64 data // Allocate memory to store decoded Base64 data
unsigned char *decodedData = (unsigned char *)RL_MALLOC(outLength);
unsigned char *decodedData = (unsigned char *)RL_MALLOC(outSize);
for (int i = 0; i < outLength/3; i++)
for (int i = 0; i < outSize/3; i++)
{ {
unsigned char a = base64decodeTable[(int)data[4*i]]; unsigned char a = base64decodeTable[(int)data[4*i]];
unsigned char b = base64decodeTable[(int)data[4*i + 1]]; unsigned char b = base64decodeTable[(int)data[4*i + 1]];
@ -3301,24 +3301,24 @@ unsigned char *DecodeDataBase64(const unsigned char *data, int *outputLength)
decodedData[3*i + 2] = (c << 6) | d; decodedData[3*i + 2] = (c << 6) | d;
} }
if (outLength%3 == 1)
if (outSize%3 == 1)
{ {
int n = outLength/3;
int n = outSize/3;
unsigned char a = base64decodeTable[(int)data[4*n]]; unsigned char a = base64decodeTable[(int)data[4*n]];
unsigned char b = base64decodeTable[(int)data[4*n + 1]]; unsigned char b = base64decodeTable[(int)data[4*n + 1]];
decodedData[outLength - 1] = (a << 2) | (b >> 4);
decodedData[outSize - 1] = (a << 2) | (b >> 4);
} }
else if (outLength%3 == 2)
else if (outSize%3 == 2)
{ {
int n = outLength/3;
int n = outSize/3;
unsigned char a = base64decodeTable[(int)data[4*n]]; unsigned char a = base64decodeTable[(int)data[4*n]];
unsigned char b = base64decodeTable[(int)data[4*n + 1]]; unsigned char b = base64decodeTable[(int)data[4*n + 1]];
unsigned char c = base64decodeTable[(int)data[4*n + 2]]; unsigned char c = base64decodeTable[(int)data[4*n + 2]];
decodedData[outLength - 2] = (a << 2) | (b >> 4);
decodedData[outLength - 1] = (b << 4) | (c >> 2);
decodedData[outSize - 2] = (a << 2) | (b >> 4);
decodedData[outSize - 1] = (b << 4) | (c >> 2);
} }
*outputLength = outLength;
*outputSize = outSize;
return decodedData; return decodedData;
} }

正在加载...
取消
保存