From bad78945ceba425f6a80e3b8dca2414d592970eb Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 2 Aug 2019 20:51:00 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../asura-core/image/binding/_image_data.cpp | 6 +- .../image/binding/_image_decode_task.cpp | 15 ++-- source/modules/asura-core/image/image_data.cpp | 62 ----------------- source/modules/asura-core/image/image_data.h | 81 ---------------------- .../modules/asura-core/image/image_decode_task.cpp | 17 ----- .../modules/asura-core/image/image_decode_task.h | 35 ---------- source/modules/asura-core/image/image_decoder.h | 33 --------- source/modules/asura-core/image/png_decoder.cpp | 17 ----- source/modules/asura-core/image/png_decoder.h | 25 ------- source/modules/asura-core/image/stb_decoder.cpp | 73 ------------------- source/modules/asura-core/image/stb_decoder.h | 26 ------- 11 files changed, 11 insertions(+), 379 deletions(-) delete mode 100644 source/modules/asura-core/image/image_data.cpp delete mode 100644 source/modules/asura-core/image/image_data.h delete mode 100644 source/modules/asura-core/image/image_decode_task.cpp delete mode 100644 source/modules/asura-core/image/image_decode_task.h delete mode 100644 source/modules/asura-core/image/image_decoder.h delete mode 100644 source/modules/asura-core/image/png_decoder.cpp delete mode 100644 source/modules/asura-core/image/png_decoder.h delete mode 100644 source/modules/asura-core/image/stb_decoder.cpp delete mode 100644 source/modules/asura-core/image/stb_decoder.h (limited to 'source/modules/asura-core/image') diff --git a/source/modules/asura-core/image/binding/_image_data.cpp b/source/modules/asura-core/image/binding/_image_data.cpp index 93e63ce..77f3a96 100644 --- a/source/modules/asura-core/image/binding/_image_data.cpp +++ b/source/modules/asura-core/image/binding/_image_data.cpp @@ -1,7 +1,7 @@ -#include -#include +#include +#include -#include "../image_data.h" +#include "../ImageData.h" using namespace std; using namespace AEThreading; diff --git a/source/modules/asura-core/image/binding/_image_decode_task.cpp b/source/modules/asura-core/image/binding/_image_decode_task.cpp index 0181628..3c8ed4b 100644 --- a/source/modules/asura-core/image/binding/_image_decode_task.cpp +++ b/source/modules/asura-core/image/binding/_image_decode_task.cpp @@ -1,18 +1,19 @@ -#include "../image_decode_task.h" +#include "../ImageDecodeTask.h" using namespace std; namespace_begin(AsuraEngine) namespace_begin(Image) + LUAX_REGISTRY(ImageDecodeTask) - { +{ - } +} - LUAX_POSTPROCESS(ImageDecodeTask) - { +LUAX_POSTPROCESS(ImageDecodeTask) +{ - } +} - } +} } diff --git a/source/modules/asura-core/image/image_data.cpp b/source/modules/asura-core/image/image_data.cpp deleted file mode 100644 index 1de70cd..0000000 --- a/source/modules/asura-core/image/image_data.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "image_data.h" -#include "png_decoder.h" -#include "stb_decoder.h" -#include "image_decoder.h" - -using namespace std; - -using namespace AEGraphics; - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -// 解析image的decoder,用来作为解析策略。 -list ImageData::ImageDecoders = { - new PNGDecoder(), // png - new STBDecoder() // jpeg, tga, bmp -}; - -ImageData::ImageData() - : pixels(nullptr) - , size(0) - , width(0) - , height(0) - , format(COLOR_FORMAT_UNKNOWN) -{ -} - -ImageData::~ImageData() -{ - if (pixels) - delete[] pixels; -} - -void ImageData::Decode(IO::DataBuffer& buffer) -{ - for (ImageDecoder* decoder : ImageDecoders) - { - if (decoder->CanDecode(buffer)) - { - decoder->Decode(buffer, *this); - return; - } - } -} - -Color ImageData::GetPixel(uint x, uint y) -{ - return Color(); -} - -void ImageData::Lock() -{ - m_Mutex.Lock(); -} - -void ImageData::Unlock() -{ - m_Mutex.Unlock(); -} - -namespace_end -namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/image/image_data.h b/source/modules/asura-core/image/image_data.h deleted file mode 100644 index 93e3448..0000000 --- a/source/modules/asura-core/image/image_data.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef __ASURA_ENGINE_IMAGEDATA_H__ -#define __ASURA_ENGINE_IMAGEDATA_H__ - -#include - -#include -#include -#include -#include -#include - -#include "../graphics/texture.h" -#include "../graphics/color.h" - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -class ImageDecoder; - -class ImageData ASURA_FINAL - : public Scripting::Portable - , public AEIO::DecodedData -{ -public: - - /// - /// 解析图片数据文件,并构建像素信息,如果解析失败,抛出异常 - /// - ImageData(); - ~ImageData(); - - void Decode(AEIO::DataBuffer& buffer) override; - - void Lock(); - void Unlock(); - - AEGraphics::Color GetPixel(uint x, uint y); - - //----------------------------------------------------------------------------// - - uint width, height; // 像素尺寸 - AEGraphics::ColorFormat format; // 格式 - byte* pixels; // 像素数据 - std::size_t size; // 数据长度 - - //----------------------------------------------------------------------------// - -private: - - /// - /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 - /// - static std::list ImageDecoders; - - /// - /// 写数据的锁。 - /// - AEThreading::Mutex m_Mutex; - -luaxport: - - LUAX_DECL_FACTORY(ImageData); - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_GetPixel); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetWidth); - LUAX_DECL_METHOD(_GetHeight); - LUAX_DECL_METHOD(_GetPixelFormat); - LUAX_DECL_METHOD(_Decode); - LUAX_DECL_METHOD(_DecodeAsync); - LUAX_DECL_METHOD(_IsAvailable); - -}; - -namespace_end -namespace_end - -namespace AEImage = AsuraEngine::Image; - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/image/image_decode_task.cpp b/source/modules/asura-core/image/image_decode_task.cpp deleted file mode 100644 index 3cadb43..0000000 --- a/source/modules/asura-core/image/image_decode_task.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "image_decode_task.h" - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -bool ImageDecodeTask::Execute() -{ - return false; -} - -void ImageDecodeTask::Invoke(lua_State* invokeThreaad) -{ - -} - -namespace_end -namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/image/image_decode_task.h b/source/modules/asura-core/image/image_decode_task.h deleted file mode 100644 index 3726514..0000000 --- a/source/modules/asura-core/image/image_decode_task.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __ASURA_IMAGE_DECODE_TASK_H__ -#define __ASURA_IMAGE_DECODE_TASK_H__ - -#include -#include -#include - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -class ImageDecodeTask - : public AEScripting::Portable -{ -public: - - /// - /// 执行任务,完成后返回true,调用回调函数。 - /// - bool Execute() override; - - /// - /// 调用回调。在invoke thread里面回调。 - /// - void Invoke(lua_State* invokeThreaad) override; - -luaxport: - - LUAX_DECL_FACTORY(ImageDecodeTask, AEThreading::Task); - -}; - -namespace_end -namespace_end - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/image/image_decoder.h b/source/modules/asura-core/image/image_decoder.h deleted file mode 100644 index 30e65d3..0000000 --- a/source/modules/asura-core/image/image_decoder.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __ASURA_ENGINE_IMAGE_DECODER_H__ -#define __ASURA_ENGINE_IMAGE_DECODER_H__ - -#include - -#include "image_data.h" - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -ASURA_ABSTRACT class ImageDecoder -{ -public: - - ImageDecoder() {}; - virtual ~ImageDecoder() {}; - - /// - /// 判断内存是否能用本decoder解压 - /// - virtual bool CanDecode(AEIO::DataBuffer& input) = 0; - - /// - /// 输入一个编码后的内存,输出一个解压后的Image data,如果解压失败返回nullptr - /// - virtual void Decode(AEIO::DataBuffer& input, ImageData& target) = 0; - -}; - -namespace_end -namespace_end - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/image/png_decoder.cpp b/source/modules/asura-core/image/png_decoder.cpp deleted file mode 100644 index bf33959..0000000 --- a/source/modules/asura-core/image/png_decoder.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "png_decoder.h" - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) -{ - return false; -} - -void PNGDecoder::Decode(AEIO::DataBuffer& buffer, ImageData& data) -{ - -} - -namespace_end -namespace_end diff --git a/source/modules/asura-core/image/png_decoder.h b/source/modules/asura-core/image/png_decoder.h deleted file mode 100644 index af67186..0000000 --- a/source/modules/asura-core/image/png_decoder.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __ASURA_ENGINE_PNGDECODER_H__ -#define __ASURA_ENGINE_PNGDECODER_H__ - -#include "image_decoder.h" - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -/// -/// 使用lodepng解压png文件 -/// -class PNGDecoder ASURA_FINAL: public ImageDecoder -{ -public: - - bool CanDecode(AEIO::DataBuffer& buffer) override; - - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - -}; - -namespace_end -namespace_end - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/image/stb_decoder.cpp b/source/modules/asura-core/image/stb_decoder.cpp deleted file mode 100644 index ed61aa4..0000000 --- a/source/modules/asura-core/image/stb_decoder.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include - -#include "stb_decoder.h" - -#define STB_IMAGE_IMPLEMENTATION -#include - -using namespace AEGraphics; - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -bool STBDecoder::CanDecode(IO::DataBuffer& buffer) -{ - int w = 0; - int h = 0; - int comp = 0; - - int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); - - return status == 1 && w > 0 && h > 0; -} - -void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) -{ - const stbi_uc *buffer = (const stbi_uc *)db.GetData(); - // databuffer数据长 - int bufferlen = db.GetSize(); - - int width, height; - int comp = 0; - byte* data = nullptr; - ColorFormat format = COLOR_FORMAT_UNKNOWN; - std::size_t size = 0; - - if (stbi_is_hdr_from_memory(buffer, bufferlen)) - { - // 4个channel都是float - data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA32F; - size = width * height * 4 * sizeof(float); - } - else - { - data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA8; - size = width * height * 4; - } - if (data) - { - imageData.Lock(); - - if (imageData.pixels) - free(imageData.pixels); - imageData.pixels = (byte*)data; - imageData.format = format; - imageData.width = width; - imageData.height = height; - imageData.size = size; - - imageData.Unlock(); - } - else - { - const char *err = stbi_failure_reason(); - if (err == nullptr) - err = "unknown error"; - throw Exception("Could not decode image with stb_image (%s).", err); - } -} - -namespace_end -namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/image/stb_decoder.h b/source/modules/asura-core/image/stb_decoder.h deleted file mode 100644 index 6158b21..0000000 --- a/source/modules/asura-core/image/stb_decoder.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __ASURA_ENGINE_STBDECODER_H__ -#define __ASURA_ENGINE_STBDECODER_H__ - -#include "image_decoder.h" - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -/// -/// 使用stb_image解压JPEG、TGA、BMP文件 -/// -class STBDecoder ASURA_FINAL - : public ImageDecoder -{ -public: - - bool CanDecode(AEIO::DataBuffer& buffer) override; - - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - -}; - -namespace_end -namespace_end - -#endif \ No newline at end of file -- cgit v1.1-26-g67d0