mirror of
https://github.com/love2d/love.git
synced 2026-08-15 07:41:11 +02:00
Added love.math.compress(data, format [, level]) and love.math.decompress(compresseddata) / love.math.decompress(compressedstring, format).
Renamed the love.image CompressedData type to CompressedImageData. love.math.compress returns a love.math CompressedData object which holds the newly compressed data. Currently supported formats are "lz4" and "zlib". Note that the formats are not file formats and don't compress filesystem hierarchies.
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2015 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_MATH_COMPRESSOR_H
|
||||
#define LOVE_MATH_COMPRESSOR_H
|
||||
|
||||
// LOVE
|
||||
#include "common/StringMap.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace math
|
||||
{
|
||||
|
||||
/**
|
||||
* Base class for backends for different compression formats.
|
||||
**/
|
||||
class Compressor
|
||||
{
|
||||
public:
|
||||
|
||||
enum Format
|
||||
{
|
||||
FORMAT_LZ4,
|
||||
FORMAT_ZLIB,
|
||||
FORMAT_MAX_ENUM
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new Compressor that can compress and decompress a specific
|
||||
* format.
|
||||
**/
|
||||
static Compressor *Create(Format format);
|
||||
|
||||
virtual ~Compressor() {}
|
||||
|
||||
/**
|
||||
* Compresses input data, and returns the compressed result.
|
||||
*
|
||||
* @param[in] data The input (uncompressed) data.
|
||||
* @param[in] dataSize The size in bytes of the input data.
|
||||
* @param[in] level The amount of compression to apply (between 0 and 9.)
|
||||
* A value of -1 indicates the default amount of compression.
|
||||
* Specific formats may not use every level.
|
||||
* @param[out] compressedSize The size in bytes of the compressed result.
|
||||
*
|
||||
* @return The newly compressed data (allocated with new[]).
|
||||
**/
|
||||
virtual char *compress(const char *data, size_t dataSize, int level, size_t &compressedSize) = 0;
|
||||
|
||||
/**
|
||||
* Decompresses compressed data, and returns the decompressed result.
|
||||
*
|
||||
* @param[in] data The input (compressed) data.
|
||||
* @param[in] dataSize The size in bytes of the compressed data.
|
||||
* @param[inout] decompressedSize On input, the size in bytes of the
|
||||
* original uncompressed data, or 0 if unknown. On return, the
|
||||
* size in bytes of the decompressed data.
|
||||
*
|
||||
* @return The decompressed data (allocated with new[]).
|
||||
**/
|
||||
virtual char *decompress(const char *data, size_t dataSize, size_t &decompressedSize) = 0;
|
||||
|
||||
/**
|
||||
* Gets the compression format implemented by this backend.
|
||||
*
|
||||
* @return The supported format.
|
||||
**/
|
||||
virtual Format getFormat() const = 0;
|
||||
|
||||
static bool getConstant(const char *in, Format &out);
|
||||
static bool getConstant(Format in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
|
||||
static StringMap<Format, FORMAT_MAX_ENUM> formatNames;
|
||||
|
||||
}; // Compressor
|
||||
|
||||
} // math
|
||||
} // love
|
||||
|
||||
#endif // LOVE_MATH_COMPRESSOR_H
|
||||
Reference in New Issue
Block a user