mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Reorganize ImageData:set/mapPixel code so less of it is in the Lua wrapper and more of it is in the ImageData class itself.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "common/int.h"
|
||||
#include "common/pixelformat.h"
|
||||
#include "common/floattypes.h"
|
||||
#include "common/Color.h"
|
||||
#include "filesystem/FileData.h"
|
||||
#include "thread/threads.h"
|
||||
#include "ImageDataBase.h"
|
||||
@@ -38,16 +39,6 @@ namespace love
|
||||
namespace image
|
||||
{
|
||||
|
||||
union Pixel
|
||||
{
|
||||
uint8 rgba8[4];
|
||||
uint16 rgba16[4];
|
||||
float16 rgba16f[4];
|
||||
float rgba32f[4];
|
||||
uint16 packed16;
|
||||
uint32 packed32;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents raw pixel data.
|
||||
**/
|
||||
@@ -55,6 +46,19 @@ class ImageData : public ImageDataBase
|
||||
{
|
||||
public:
|
||||
|
||||
union Pixel
|
||||
{
|
||||
uint8 rgba8[4];
|
||||
uint16 rgba16[4];
|
||||
float16 rgba16f[4];
|
||||
float rgba32f[4];
|
||||
uint16 packed16;
|
||||
uint32 packed32;
|
||||
};
|
||||
|
||||
typedef void (*PixelSetFunction)(const Colorf &c, Pixel *p);
|
||||
typedef void (*PixelGetFunction)(const Pixel *p, Colorf &c);
|
||||
|
||||
static love::Type type;
|
||||
|
||||
ImageData(Data *data);
|
||||
@@ -88,7 +92,7 @@ public:
|
||||
* @param y The location along the y-axis.
|
||||
* @param p The color to use for the given location.
|
||||
**/
|
||||
void setPixel(int x, int y, const Pixel &p);
|
||||
void setPixel(int x, int y, const Colorf &p);
|
||||
|
||||
/**
|
||||
* Gets the pixel at location (x,y).
|
||||
@@ -96,7 +100,8 @@ public:
|
||||
* @param y The location along the y-axis.
|
||||
* @return The color for the given location.
|
||||
**/
|
||||
void getPixel(int x, int y, Pixel &p) const;
|
||||
void getPixel(int x, int y, Colorf &c) const;
|
||||
Colorf getPixel(int x, int y) const;
|
||||
|
||||
/**
|
||||
* Encodes raw pixel data into a given format.
|
||||
@@ -115,9 +120,15 @@ public:
|
||||
|
||||
size_t getPixelSize() const;
|
||||
|
||||
PixelSetFunction getPixelSetFunction() const { return pixelSetFunction; }
|
||||
PixelGetFunction getPixelGetFunction() const { return pixelGetFunction; }
|
||||
|
||||
static bool validPixelFormat(PixelFormat format);
|
||||
static bool canPaste(PixelFormat src, PixelFormat dst);
|
||||
|
||||
static PixelSetFunction getPixelSetFunction(PixelFormat format);
|
||||
static PixelGetFunction getPixelGetFunction(PixelFormat format);
|
||||
|
||||
static bool getConstant(const char *in, FormatHandler::EncodedFormat &out);
|
||||
static bool getConstant(FormatHandler::EncodedFormat in, const char *&out);
|
||||
static std::vector<std::string> getConstants(FormatHandler::EncodedFormat);
|
||||
@@ -139,6 +150,9 @@ private:
|
||||
// this so we can properly delete memory allocated by the decoder.
|
||||
StrongRef<FormatHandler> decodeHandler;
|
||||
|
||||
PixelSetFunction pixelSetFunction;
|
||||
PixelGetFunction pixelGetFunction;
|
||||
|
||||
static StringMap<FormatHandler::EncodedFormat, FormatHandler::ENCODED_MAX_ENUM>::Entry encodedFormatEntries[];
|
||||
static StringMap<FormatHandler::EncodedFormat, FormatHandler::ENCODED_MAX_ENUM> encodedFormats;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user