update image

This commit is contained in:
sunxfancy committed 2024-06-13 15:31:49 -07:00
1 parent b7d172ea83
commit b8426c1b48
6 files changed
+60 -56

No files matched your search

+1 -1
View File
@@ -22,7 +22,7 @@ EVEngine整体架构
### 核心特性
1. 类似love的简版引擎,无节点树支持
1. 类似love的简版引擎,可选节点树支持
2. 解释运行,在文件夹中放好脚本和资源,直接在当前目录就可以用引擎运行游戏
3. 热重载,随时监听文件系统变动,脚本和资源改变时可以不重启引擎直接刷新
4. 状态热更新,代码修改时,对应被影响到的游戏状态机会自动刷新
+2
View File
@@ -0,0 +1,2 @@
这个目录存放的都是平台相关的项目文件,主要是用来在各个平台打包引擎,用于生成最终的游戏。
+2 -1
View File
@@ -5,4 +5,5 @@ create_module(EVWindow window)
create_module(EVEvent event)
create_module(EVMouse mouse)
create_module(EVTouch touch)
create_module(EVData data)
create_module(EVData data)
# create_module(EVImage image)
+26 -34
View File
@@ -18,31 +18,29 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "Image.h"
#include "common/config.h"
#include "magpie/PNGHandler.h"
#include "magpie/STBHandler.h"
#include "magpie/EXRHandler.h"
#include "medialoader/image/PNGHandler.h"
#include "medialoader/image/STBHandler.h"
#include "medialoader/image/EXRHandler.h"
#include "magpie/ddsHandler.h"
#include "magpie/PVRHandler.h"
#include "magpie/KTXHandler.h"
#include "magpie/PKMHandler.h"
#include "magpie/ASTCHandler.h"
#include "medialoader/image/ddsHandler.h"
#include "medialoader/image/PVRHandler.h"
#include "medialoader/image/KTXHandler.h"
#include "medialoader/image/PKMHandler.h"
#include "medialoader/image/ASTCHandler.h"
namespace eve
{
namespace image
{
Module_IMPL(Filesystem, new physfs::Filesystem());
Module_IMPL(Image, new Image());
Image::Image()
{
using namespace magpie;
using namespace medialoader;
float16Init(); // Makes sure half-float conversions can be used.
@@ -62,47 +60,41 @@ Image::~Image()
{
// ImageData objects reference the FormatHandlers in our list, so we should
// release them instead of deleting them completely here.
for (FormatHandler *handler : formatHandlers)
handler->release();
// TODO: Check if this is necessary
// for (FormatHandler *handler : formatHandlers)
// handler->release();
}
const char *Image::getName() const
{
return "love.image.magpie";
}
love::image::ImageData *Image::newImageData(Data *data)
ImageData *Image::newImageData(Data *data)
{
return new ImageData(data);
}
love::image::ImageData *Image::newImageData(int width, int height, PixelFormat format)
ImageData *Image::newImageData(int width, int height, std::string format)
{
return new ImageData(width, height, format);
}
love::image::ImageData *Image::newImageData(int width, int height, PixelFormat format, void *data, bool own)
ImageData *Image::newImageData(int width, int height, std::string format, void *data, bool own)
{
return new ImageData(width, height, format, data, own);
}
love::image::CompressedImageData *Image::newCompressedData(Data *data)
{
return new CompressedImageData(formatHandlers, data);
}
bool Image::isCompressed(Data *data)
{
for (FormatHandler *handler : formatHandlers)
{
if (handler->canParseCompressed(data))
if (handler->canParseCompressed((const char*)data->getData(), data->getSize()))
return true;
}
return false;
}
const std::list<FormatHandler *> &Image::getFormatHandlers() const
const std::list<medialoader::FormatHandler *> &Image::getFormatHandlers() const
{
return formatHandlers;
}
@@ -114,7 +106,7 @@ ImageData *Image::newPastedImageData(ImageData *src, int sx, int sy, int w, int
{
res->paste(src, 0, 0, sx, sy, w, h);
}
catch (love::Exception &)
catch (eve::Exception &)
{
res->release();
throw;
@@ -122,10 +114,10 @@ ImageData *Image::newPastedImageData(ImageData *src, int sx, int sy, int w, int
return res;
}
std::vector<StrongRef<ImageData>> Image::newCubeFaces(love::image::ImageData *src)
std::vector<eve::ref<ImageData>> Image::newCubeFaces(ImageData *src)
{
// The faces array is always ordered +x, -x, +y, -y, +z, -z.
std::vector<StrongRef<ImageData>> faces;
std::vector<eve::ref<ImageData>> faces;
int totalW = src->getWidth();
int totalH = src->getHeight();
@@ -189,14 +181,14 @@ std::vector<StrongRef<ImageData>> Image::newCubeFaces(love::image::ImageData *sr
faces.emplace_back(newPastedImageData(src, i * w, 0, w, h), Acquire::NORETAIN);
}
else
throw love::Exception("Unknown cubemap image dimensions!");
throw eve::Exception("Unknown cubemap image dimensions!");
return faces;
}
std::vector<StrongRef<ImageData>> Image::newVolumeLayers(ImageData *src)
std::vector<eve::ref<ImageData>> Image::newVolumeLayers(ImageData *src)
{
std::vector<StrongRef<ImageData>> layers;
std::vector<eve::ref<ImageData>> layers;
int totalW = src->getWidth();
int totalH = src->getHeight();
@@ -212,7 +204,7 @@ std::vector<StrongRef<ImageData>> Image::newVolumeLayers(ImageData *src)
layers.emplace_back(newPastedImageData(src, 0, i * totalW, totalW, totalW), Acquire::NORETAIN);
}
else
throw love::Exception("Cannot extract volume layers from source ImageData.");
throw eve::Exception("Cannot extract volume layers from source ImageData.");
return layers;
}
+4 -2
View File
@@ -21,6 +21,8 @@ namespace image
class Image : public Module
{
public:
using FormatHandler = medialoader::FormatHandler;
Module_REG(Image);
Image();
@@ -39,7 +41,7 @@ public:
* @param height The height of the ImageData.
* @return The new ImageData.
**/
ImageData *newImageData(int width, int height, PixelFormat format = PIXELFORMAT_RGBA8);
ImageData *newImageData(int width, int height, std::string format = "RGBA8");
/**
* Creates empty ImageData with the given size.
@@ -50,7 +52,7 @@ public:
* copy it.
* @return The new ImageData.
**/
ImageData *newImageData(int width, int height, PixelFormat format, void *data, bool own = false);
ImageData *newImageData(int width, int height, std::string format, void *data, bool own = false);
/**
* Creates new CompressedImageData from FileData.
+25 -18
View File
@@ -2,12 +2,16 @@
#pragma once
#include "common/Data.h"
#include "common/pixelformat.h"
#include "common/Color.h"
#include "common/Resource.h"
#include "medialoader/image/pixelformat.h"
#include "medialoader/image/floattypes.h"
#include "medialoader/image/Color.h"
#include "medialoader/image/FormatHandler.h"
#include "filesystem/FileData.h"
#include "thread/threads.h"
#include "ImageDataBase.h"
#include "FormatHandler.h"
#include <cstdint>
namespace eve
{
@@ -20,15 +24,18 @@ namespace image
class ImageData : public Resource
{
public:
using float16 = medialoader::float16;
using Colorf = medialoader::Colorf;
using FormatHandler = medialoader::FormatHandler;
union Pixel
{
uint8 rgba8[4];
uint16 rgba16[4];
float16 rgba16f[4];
float rgba32f[4];
uint16 packed16;
uint32 packed32;
uint8_t rgba8[4];
uint16_t rgba16[4];
float16 rgba16f[4];
float rgba32f[4];
uint16_t packed16;
uint32_t packed32;
};
typedef void (*PixelSetFunction)(const Colorf &c, Pixel *p);
@@ -83,13 +90,13 @@ public:
**/
filesystem::FileData *encode(FormatHandler::EncodedFormat format, const char *filename, bool writefile) const;
love::thread::Mutex *getMutex() const;
// Implements ImageDataBase.
ImageData *clone() const override;
void *getData() const override;
size_t getSize() const override;
bool isSRGB() const override;
ImageData *clone() const;
void *getData() const;
size_t getSize() const;
bool isSRGB() const;
std::string getFormat() const;
size_t getPixelSize() const;
@@ -119,7 +126,7 @@ private:
// The format handler that was used to decode the ImageData. We need to know
// this so we can properly delete memory allocated by the decoder.
StrongRef<FormatHandler> decodeHandler;
eve::ref<FormatHandler> decodeHandler;
PixelSetFunction pixelSetFunction;
PixelGetFunction pixelGetFunction;