mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-06 11:28:17 +00:00
ADDED small compression API
- ADDED: CompressData() - ADDED: DecompressData()
This commit is contained in:
@@ -56,7 +56,8 @@
|
|||||||
#define SUPPORT_GIF_RECORDING 1
|
#define SUPPORT_GIF_RECORDING 1
|
||||||
// Allow scale all the drawn content to match the high-DPI equivalent size (only PLATFORM_DESKTOP)
|
// Allow scale all the drawn content to match the high-DPI equivalent size (only PLATFORM_DESKTOP)
|
||||||
//#define SUPPORT_HIGH_DPI 1
|
//#define SUPPORT_HIGH_DPI 1
|
||||||
|
// Support CompressData() and DecompressData() functions
|
||||||
|
#define SUPPORT_COMPRESSION_API 1
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Module: rlgl - Configuration Flags
|
// Module: rlgl - Configuration Flags
|
||||||
|
@@ -19,6 +19,8 @@
|
|||||||
#cmakedefine SUPPORT_GIF_RECORDING 1
|
#cmakedefine SUPPORT_GIF_RECORDING 1
|
||||||
// Support high DPI displays
|
// Support high DPI displays
|
||||||
#cmakedefine SUPPORT_HIGH_DPI 1
|
#cmakedefine SUPPORT_HIGH_DPI 1
|
||||||
|
// Support CompressData() and DecompressData() functions
|
||||||
|
#cmakedefine SUPPORT_COMPRESSION_API 1
|
||||||
|
|
||||||
// rlgl.h
|
// rlgl.h
|
||||||
// Support VR simulation functionality (stereo rendering)
|
// Support VR simulation functionality (stereo rendering)
|
||||||
|
37
src/core.c
37
src/core.c
@@ -74,6 +74,11 @@
|
|||||||
* Allow scale all the drawn content to match the high-DPI equivalent size (only PLATFORM_DESKTOP)
|
* Allow scale all the drawn content to match the high-DPI equivalent size (only PLATFORM_DESKTOP)
|
||||||
* NOTE: This flag is forced on macOS, since most displays are high-DPI
|
* NOTE: This flag is forced on macOS, since most displays are high-DPI
|
||||||
*
|
*
|
||||||
|
* #define SUPPORT_COMPRESSION_API
|
||||||
|
* Support CompressData() and DecompressData() functions, those functions use zlib implementation
|
||||||
|
* provided by stb_image and stb_image_write libraries, so, those libraries must be enabled on textures module
|
||||||
|
* for linkage
|
||||||
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* rglfw - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX. FreeBSD, OpenBSD, NetBSD, DragonFly)
|
* rglfw - Manage graphic device, OpenGL context and inputs on PLATFORM_DESKTOP (Windows, Linux, OSX. FreeBSD, OpenBSD, NetBSD, DragonFly)
|
||||||
* raymath - 3D math functionality (Vector2, Vector3, Matrix, Quaternion)
|
* raymath - 3D math functionality (Vector2, Vector3, Matrix, Quaternion)
|
||||||
@@ -252,6 +257,12 @@
|
|||||||
#include <emscripten/html5.h> // Emscripten HTML5 library
|
#include <emscripten/html5.h> // Emscripten HTML5 library
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_COMPRESSION_API)
|
||||||
|
// NOTE: Those declarations require stb_image and stb_image_write definitions, included in textures module
|
||||||
|
unsigned char *stbi_zlib_compress(unsigned char *data, int data_len, int *out_len, int quality);
|
||||||
|
char *stbi_zlib_decode_malloc(char const *buffer, int len, int *outlen);
|
||||||
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
@@ -2019,6 +2030,32 @@ long GetFileModTime(const char *fileName)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compress data (DEFLATE algorythm)
|
||||||
|
unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLength)
|
||||||
|
{
|
||||||
|
#define COMPRESSION_QUALITY_DEFLATE 8
|
||||||
|
|
||||||
|
unsigned char *compData = NULL;
|
||||||
|
|
||||||
|
#if defined(SUPPORT_COMPRESSION_API)
|
||||||
|
compData = stbi_zlib_compress(data, dataLength, compDataLength, COMPRESSION_QUALITY_DEFLATE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return compData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decompress data (DEFLATE algorythm)
|
||||||
|
char *DecompressData(char *compData, int compDataLength, int *dataLength)
|
||||||
|
{
|
||||||
|
char *data = NULL;
|
||||||
|
|
||||||
|
#if defined(SUPPORT_COMPRESSION_API)
|
||||||
|
data = stbi_zlib_decode_malloc(compData, compDataLength, dataLength);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
// Save integer value to storage file (to defined position)
|
// Save integer value to storage file (to defined position)
|
||||||
// NOTE: Storage positions is directly related to file memory layout (4 bytes each integer)
|
// NOTE: Storage positions is directly related to file memory layout (4 bytes each integer)
|
||||||
void StorageSaveValue(int position, int value)
|
void StorageSaveValue(int position, int value)
|
||||||
|
@@ -955,6 +955,9 @@ RLAPI char **GetDroppedFiles(int *count); // Get dropped
|
|||||||
RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer (free memory)
|
RLAPI void ClearDroppedFiles(void); // Clear dropped files paths buffer (free memory)
|
||||||
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)
|
||||||
|
|
||||||
|
RLAPI unsigned char *CompressData(unsigned char *data, int dataLength, int *compDataLength); // Compress data (DEFLATE algorythm)
|
||||||
|
RLAPI char *DecompressData(char *compData, int compDataLength, int *dataLength); // Decompress data (DEFLATE algorythm)
|
||||||
|
|
||||||
// Persistent storage management
|
// Persistent storage management
|
||||||
RLAPI void StorageSaveValue(int position, int value); // Save integer value to storage file (to defined position)
|
RLAPI void StorageSaveValue(int position, int value); // Save integer value to storage file (to defined position)
|
||||||
RLAPI int StorageLoadValue(int position); // Load integer value from storage file (from defined position)
|
RLAPI int StorageLoadValue(int position); // Load integer value from storage file (from defined position)
|
||||||
|
Reference in New Issue
Block a user