mirror of
https://github.com/love2d/love.git
synced 2026-08-18 11:44:15 +02:00
Finally abstracted constants properly. Changed how the event module works; wasn't really abstract before. Removed libs we're not going to use: native, signal.
This commit is contained in:
@@ -24,22 +24,43 @@ namespace love
|
||||
{
|
||||
namespace image
|
||||
{
|
||||
EncodedImageData::EncodedImageData(void * d, Image::ImageFormat f, int s) {
|
||||
data = d;
|
||||
format = f;
|
||||
size = s;
|
||||
EncodedImageData::EncodedImageData(void * d, Format f, int s)
|
||||
: data(d), format(f), size(s)
|
||||
{
|
||||
}
|
||||
|
||||
void * EncodedImageData::getData() const {
|
||||
void * EncodedImageData::getData() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
Image::ImageFormat EncodedImageData::getFormat() {
|
||||
EncodedImageData::Format EncodedImageData::getFormat() const
|
||||
{
|
||||
return format;
|
||||
}
|
||||
|
||||
int EncodedImageData::getSize() const {
|
||||
int EncodedImageData::getSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
bool EncodedImageData::getConstant(const char * in, EncodedImageData::Format & out)
|
||||
{
|
||||
return formats.find(in, out);
|
||||
}
|
||||
|
||||
bool EncodedImageData::getConstant(EncodedImageData::Format in, const char *& out)
|
||||
{
|
||||
return formats.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<EncodedImageData::Format, EncodedImageData::FORMAT_MAX_ENUM>::Entry EncodedImageData::formatEntries[] =
|
||||
{
|
||||
{"tga", EncodedImageData::FORMAT_TGA},
|
||||
{"bmp", EncodedImageData::FORMAT_BMP},
|
||||
};
|
||||
|
||||
StringMap<EncodedImageData::Format, EncodedImageData::FORMAT_MAX_ENUM> EncodedImageData::formats(EncodedImageData::formatEntries, sizeof(EncodedImageData::formatEntries));
|
||||
|
||||
} // image
|
||||
} // love
|
||||
|
||||
@@ -23,60 +23,73 @@
|
||||
|
||||
// LOVE
|
||||
#include <common/Data.h>
|
||||
#include <common/StringMap.h>
|
||||
|
||||
#include "Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace image
|
||||
namespace image
|
||||
{
|
||||
/**
|
||||
* Represents encoded pixel data.
|
||||
**/
|
||||
class EncodedImageData : public Data
|
||||
{
|
||||
/**
|
||||
* Represents encoded pixel data.
|
||||
**/
|
||||
class EncodedImageData : public Data
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
**/
|
||||
EncodedImageData(void * data, Image::ImageFormat format, int size);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~EncodedImageData(){};
|
||||
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
/**
|
||||
* Get the format the data is encoded in.
|
||||
**/
|
||||
|
||||
Image::ImageFormat getFormat();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Actual data.
|
||||
**/
|
||||
void * data;
|
||||
|
||||
/**
|
||||
* Size of the data.
|
||||
**/
|
||||
int size;
|
||||
|
||||
/**
|
||||
* Image format.
|
||||
**/
|
||||
Image::ImageFormat format;
|
||||
|
||||
}; // EncodedImageData
|
||||
public:
|
||||
|
||||
} // image
|
||||
enum Format
|
||||
{
|
||||
FORMAT_TGA = 1,
|
||||
FORMAT_BMP,
|
||||
FORMAT_MAX_ENUM
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
**/
|
||||
EncodedImageData(void * data, Format format, int size);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~EncodedImageData(){};
|
||||
|
||||
// Implements Data.
|
||||
void * getData() const;
|
||||
int getSize() const;
|
||||
|
||||
/**
|
||||
* Get the format the data is encoded in.
|
||||
**/
|
||||
Format getFormat() const;
|
||||
|
||||
static bool getConstant(const char * in, Format & out);
|
||||
static bool getConstant(Format in, const char *& out);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Actual data.
|
||||
**/
|
||||
void * data;
|
||||
|
||||
/**
|
||||
* Size of the data.
|
||||
**/
|
||||
int size;
|
||||
|
||||
/**
|
||||
* Image format.
|
||||
**/
|
||||
Format format;
|
||||
|
||||
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
|
||||
static StringMap<Format, FORMAT_MAX_ENUM> formats;
|
||||
|
||||
}; // EncodedImageData
|
||||
|
||||
} // image
|
||||
} // love
|
||||
|
||||
#endif // LOVE_IMAGE_ENCODED_IMAGE_DATA_H
|
||||
|
||||
@@ -76,11 +76,6 @@ namespace image
|
||||
* @return The new ImageData.
|
||||
**/
|
||||
virtual ImageData * newImageData(int width, int height, void *data) = 0;
|
||||
|
||||
enum ImageFormat {
|
||||
FORMAT_TGA,
|
||||
FORMAT_BMP
|
||||
};
|
||||
|
||||
}; // Image
|
||||
|
||||
|
||||
@@ -165,13 +165,13 @@ namespace devil
|
||||
return pixels[y*width+x];
|
||||
}
|
||||
|
||||
love::image::EncodedImageData * ImageData::encodeImageData(love::image::ImageData * d, love::image::Image::ImageFormat f) {
|
||||
love::image::EncodedImageData * ImageData::encodeImageData(love::image::ImageData * d, EncodedImageData::Format f) {
|
||||
ILubyte * data;
|
||||
ILuint w = d->getWidth();
|
||||
int h = d->getHeight(); // has to be a signed int so we can make it negative for BMPs
|
||||
int headerLen, bpp, row, size, padding, filesize;
|
||||
switch (f) {
|
||||
case Image::FORMAT_BMP:
|
||||
case EncodedImageData::FORMAT_BMP:
|
||||
headerLen = 54;
|
||||
bpp = 3;
|
||||
row = w * bpp;
|
||||
@@ -231,7 +231,7 @@ namespace devil
|
||||
}
|
||||
data -= filesize;
|
||||
break;
|
||||
case Image::FORMAT_TGA:
|
||||
case EncodedImageData::FORMAT_TGA:
|
||||
default: // TGA is the default format
|
||||
headerLen = 18;
|
||||
bpp = 3;
|
||||
@@ -263,7 +263,7 @@ namespace devil
|
||||
ILubyte * temp = new ILubyte[row];
|
||||
ILubyte * src = data - row;
|
||||
ILubyte * dst = data + size;
|
||||
for (unsigned i = 0; i < (h >> 1); i++) {
|
||||
for (int i = 0; i < (h >> 1); i++) {
|
||||
memcpy(temp,src+=row,row);
|
||||
memcpy(src,dst-=row,row);
|
||||
memcpy(dst,temp,row);
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace devil
|
||||
* @param f The format to convert to.
|
||||
* @return A pointer to the encoded image data.
|
||||
**/
|
||||
static love::image::EncodedImageData * encodeImageData(love::image::ImageData * d, love::image::Image::ImageFormat f);
|
||||
static love::image::EncodedImageData * encodeImageData(love::image::ImageData * d, EncodedImageData::Format f);
|
||||
|
||||
}; // ImageData
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "wrap_Image.h"
|
||||
|
||||
#include <common/Data.h>
|
||||
#include <common/StringMap.h>
|
||||
|
||||
#include "devil/Image.h"
|
||||
#include "devil/ImageData.h"
|
||||
@@ -30,7 +31,7 @@ namespace love
|
||||
namespace image
|
||||
{
|
||||
static Image * instance = 0;
|
||||
|
||||
|
||||
int w_newImageData(lua_State * L)
|
||||
{
|
||||
|
||||
@@ -72,7 +73,8 @@ namespace image
|
||||
|
||||
int w_newEncodedImageData(lua_State * L) {
|
||||
ImageData * t = luax_checkimagedata(L, 1);
|
||||
Image::ImageFormat format = (Image::ImageFormat)luaL_optint(L, 2, Image::FORMAT_TGA);
|
||||
EncodedImageData::Format format;
|
||||
EncodedImageData::getConstant(luaL_checkstring(L, 2), format);
|
||||
EncodedImageData * e = love::image::devil::ImageData::encodeImageData(t, format);
|
||||
luax_newtype(L, "Data", DATA_T, (void*)e); // since we don't need any of EncodedImageData's features
|
||||
return 1;
|
||||
@@ -89,12 +91,6 @@ namespace image
|
||||
luaopen_imagedata,
|
||||
0
|
||||
};
|
||||
|
||||
static const Constant constants[] = {
|
||||
{ "format_tga", Image::FORMAT_TGA },
|
||||
{ "format_bmp", Image::FORMAT_BMP },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_love_image(lua_State * L)
|
||||
{
|
||||
@@ -116,7 +112,6 @@ namespace image
|
||||
w.flags = MODULE_IMAGE_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user