diff options
Diffstat (limited to 'source/modules/asura-core/image')
-rw-r--r-- | source/modules/asura-core/image/binding/_image_data.cpp | 6 | ||||
-rw-r--r-- | source/modules/asura-core/image/binding/_image_decode_task.cpp | 15 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_data.cpp | 62 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_data.h | 81 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_decode_task.cpp | 17 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_decode_task.h | 35 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_decoder.h | 33 | ||||
-rw-r--r-- | source/modules/asura-core/image/png_decoder.cpp | 17 | ||||
-rw-r--r-- | source/modules/asura-core/image/png_decoder.h | 25 | ||||
-rw-r--r-- | source/modules/asura-core/image/stb_decoder.cpp | 73 | ||||
-rw-r--r-- | source/modules/asura-core/image/stb_decoder.h | 26 |
11 files changed, 11 insertions, 379 deletions
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 <asura-utils/threading/thread.h> -#include <asura-utils/io/data_buffer.h> +#include <asura-utils/Threads/Thread.h> +#include <asura-utils/IO/DataBuffer.h> -#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) - -// imagedecoderΪԡ -list<ImageDecoder*> 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 <list> - -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/io/decoded_data.h> -#include <asura-utils/io/data_buffer.h> -#include <asura-utils/threading/thread.h> -#include <asura-utils/threading/mutex.h> - -#include "../graphics/texture.h" -#include "../graphics/color.h" - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -class ImageDecoder; - -class ImageData ASURA_FINAL - : public Scripting::Portable<ImageData> - , 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<ImageDecoder*> 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 <asura-utils/threading/task.h> -#include <asura-utils/scripting/portable.hpp> -#include <asura-utils/classes.h> - -namespace_begin(AsuraEngine) -namespace_begin(Image) - -class ImageDecodeTask - : public AEScripting::Portable<ImageDecodeTask, AEThreading::Task> -{ -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 <asura-utils/io/data_buffer.h> - -#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 <asura-utils/exceptions/exception.h> - -#include "stb_decoder.h" - -#define STB_IMAGE_IMPLEMENTATION -#include <stb/stb_image.h> - -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)) - { - // 4channelfloat - 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ѹJPEGTGABMPļ -/// -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 |