diff options
author | chai <chaifix@163.com> | 2019-07-31 21:35:12 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-07-31 21:35:12 +0800 |
commit | 084623519e95f0ab0cf4bc328b5fa736d679c5bd (patch) | |
tree | 9d409dceda50335e9fb881fc5107c9c1c561f988 /source/modules/asura-core/image | |
parent | 012a44bd13ab41d056e7d3884a39027b6cea62b5 (diff) |
*修改名称空间风格
Diffstat (limited to 'source/modules/asura-core/image')
-rw-r--r-- | source/modules/asura-core/image/binding/_image_data.cpp | 9 | ||||
-rw-r--r-- | source/modules/asura-core/image/binding/_image_decode_task.cpp | 9 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_data.cpp | 90 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_data.h | 94 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_decode_task.cpp | 24 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_decode_task.h | 41 | ||||
-rw-r--r-- | source/modules/asura-core/image/image_decoder.h | 38 | ||||
-rw-r--r-- | source/modules/asura-core/image/png_decoder.cpp | 24 | ||||
-rw-r--r-- | source/modules/asura-core/image/png_decoder.h | 28 | ||||
-rw-r--r-- | source/modules/asura-core/image/stb_decoder.cpp | 112 | ||||
-rw-r--r-- | source/modules/asura-core/image/stb_decoder.h | 30 |
11 files changed, 238 insertions, 261 deletions
diff --git a/source/modules/asura-core/image/binding/_image_data.cpp b/source/modules/asura-core/image/binding/_image_data.cpp index 1030e93..93e63ce 100644 --- a/source/modules/asura-core/image/binding/_image_data.cpp +++ b/source/modules/asura-core/image/binding/_image_data.cpp @@ -7,12 +7,9 @@ using namespace std; using namespace AEThreading; using namespace AEIO; -namespace AsuraEngine -{ - namespace Image - { - - LUAX_REGISTRY(ImageData) +namespace_begin(AsuraEngine) +namespace_begin(Image) +LUAX_REGISTRY(ImageData) { LUAX_REGISTER_METHODS(state, { "New", _New }, 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 a0caddf..0181628 100644 --- a/source/modules/asura-core/image/binding/_image_decode_task.cpp +++ b/source/modules/asura-core/image/binding/_image_decode_task.cpp @@ -2,12 +2,9 @@ using namespace std; -namespace AsuraEngine -{ - namespace Image - { - - LUAX_REGISTRY(ImageDecodeTask) +namespace_begin(AsuraEngine) +namespace_begin(Image) +LUAX_REGISTRY(ImageDecodeTask) { } diff --git a/source/modules/asura-core/image/image_data.cpp b/source/modules/asura-core/image/image_data.cpp index 883343c..1de70cd 100644 --- a/source/modules/asura-core/image/image_data.cpp +++ b/source/modules/asura-core/image/image_data.cpp @@ -7,58 +7,56 @@ using namespace std; using namespace AEGraphics; -namespace AsuraEngine +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) { - namespace 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; - } +ImageData::~ImageData() +{ + if (pixels) + delete[] pixels; +} - void ImageData::Decode(IO::DataBuffer& buffer) +void ImageData::Decode(IO::DataBuffer& buffer) +{ + for (ImageDecoder* decoder : ImageDecoders) + { + if (decoder->CanDecode(buffer)) { - for (ImageDecoder* decoder : ImageDecoders) - { - if (decoder->CanDecode(buffer)) - { - decoder->Decode(buffer, *this); - return; - } - } + decoder->Decode(buffer, *this); + return; } + } +} - Color ImageData::GetPixel(uint x, uint y) - { - return Color(); - } +Color ImageData::GetPixel(uint x, uint y) +{ + return Color(); +} - void ImageData::Lock() - { - m_Mutex.Lock(); - } +void ImageData::Lock() +{ + m_Mutex.Lock(); +} - void ImageData::Unlock() - { - m_Mutex.Unlock(); - } +void ImageData::Unlock() +{ + m_Mutex.Unlock(); +} - } -}
\ No newline at end of file +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 index 8b4f04a..93e3448 100644 --- a/source/modules/asura-core/image/image_data.h +++ b/source/modules/asura-core/image/image_data.h @@ -12,71 +12,69 @@ #include "../graphics/texture.h" #include "../graphics/color.h" -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - class ImageDecoder; +class ImageDecoder; - class ImageData ASURA_FINAL - : public Scripting::Portable<ImageData> - , public AEIO::DecodedData - { - public: +class ImageData ASURA_FINAL + : public Scripting::Portable<ImageData> + , public AEIO::DecodedData +{ +public: - /// - /// ͼƬļϢʧܣ׳쳣 - /// - ImageData(); - ~ImageData(); + /// + /// ͼƬļϢʧܣ׳쳣 + /// + ImageData(); + ~ImageData(); - void Decode(AEIO::DataBuffer& buffer) override; + void Decode(AEIO::DataBuffer& buffer) override; - void Lock(); - void Unlock(); + void Lock(); + void Unlock(); - AEGraphics::Color GetPixel(uint x, uint y); + AEGraphics::Color GetPixel(uint x, uint y); - //----------------------------------------------------------------------------// + //----------------------------------------------------------------------------// - uint width, height; // سߴ - AEGraphics::ColorFormat format; // ʽ - byte* pixels; // - std::size_t size; // ݳ + uint width, height; // سߴ + AEGraphics::ColorFormat format; // ʽ + byte* pixels; // + std::size_t size; // ݳ - //----------------------------------------------------------------------------// + //----------------------------------------------------------------------------// - private: +private: - /// - /// ڵһimage dataʱṩdecoderڼdecodersмѡԡ - /// - static std::list<ImageDecoder*> ImageDecoders; + /// + /// ڵһimage dataʱṩdecoderڼdecodersмѡԡ + /// + static std::list<ImageDecoder*> ImageDecoders; - /// - /// дݵ - /// - AEThreading::Mutex m_Mutex; + /// + /// дݵ + /// + AEThreading::Mutex m_Mutex; - luaxport: +luaxport: - LUAX_DECL_FACTORY(ImageData); + 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); + 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; diff --git a/source/modules/asura-core/image/image_decode_task.cpp b/source/modules/asura-core/image/image_decode_task.cpp index 954749a..3cadb43 100644 --- a/source/modules/asura-core/image/image_decode_task.cpp +++ b/source/modules/asura-core/image/image_decode_task.cpp @@ -1,19 +1,17 @@ #include "image_decode_task.h" -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - bool ImageDecodeTask::Execute() - { - return false; - } +bool ImageDecodeTask::Execute() +{ + return false; +} - void ImageDecodeTask::Invoke(lua_State* invokeThreaad) - { +void ImageDecodeTask::Invoke(lua_State* invokeThreaad) +{ - } +} - } -}
\ No newline at end of file +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 index 5108c23..3726514 100644 --- a/source/modules/asura-core/image/image_decode_task.h +++ b/source/modules/asura-core/image/image_decode_task.h @@ -3,34 +3,33 @@ #include <asura-utils/threading/task.h> #include <asura-utils/scripting/portable.hpp> +#include <asura-utils/classes.h> -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - class ImageDecodeTask - : public AEScripting::Portable<ImageDecodeTask, AEThreading::Task> - { - public: +class ImageDecodeTask + : public AEScripting::Portable<ImageDecodeTask, AEThreading::Task> +{ +public: - /// - /// ִɺtrueûص - /// - bool Execute() override; + /// + /// ִɺtrueûص + /// + bool Execute() override; - /// - /// ûصinvoke threadص - /// - void Invoke(lua_State* invokeThreaad) override; + /// + /// ûصinvoke threadص + /// + void Invoke(lua_State* invokeThreaad) override; - luaxport: +luaxport: - LUAX_DECL_FACTORY(ImageDecodeTask, AEThreading::Task); + 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 index 15efff7..30e65d3 100644 --- a/source/modules/asura-core/image/image_decoder.h +++ b/source/modules/asura-core/image/image_decoder.h @@ -5,31 +5,29 @@ #include "image_data.h" -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - ASURA_ABSTRACT class ImageDecoder - { - public: +ASURA_ABSTRACT class ImageDecoder +{ +public: - ImageDecoder() {}; - virtual ~ImageDecoder() {}; + ImageDecoder() {}; + virtual ~ImageDecoder() {}; - /// - /// жڴǷñdecoderѹ - /// - virtual bool CanDecode(AEIO::DataBuffer& input) = 0; + /// + /// жڴǷñdecoderѹ + /// + virtual bool CanDecode(AEIO::DataBuffer& input) = 0; - /// - /// һڴ棬һѹImage dataѹʧܷnullptr - /// - virtual void Decode(AEIO::DataBuffer& input, ImageData& target) = 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 index a76af80..bf33959 100644 --- a/source/modules/asura-core/image/png_decoder.cpp +++ b/source/modules/asura-core/image/png_decoder.cpp @@ -1,19 +1,17 @@ #include "png_decoder.h" -namespace AsuraEngine -{ - namespace Image - { - - bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) - { - return false; - } +namespace_begin(AsuraEngine) +namespace_begin(Image) - void PNGDecoder::Decode(AEIO::DataBuffer& buffer, ImageData& data) - { +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 index 24e40c5..af67186 100644 --- a/source/modules/asura-core/image/png_decoder.h +++ b/source/modules/asura-core/image/png_decoder.h @@ -3,25 +3,23 @@ #include "image_decoder.h" -namespace AsuraEngine -{ - namespace Image - { +namespace_begin(AsuraEngine) +namespace_begin(Image) - /// - /// ʹlodepngѹpngļ - /// - class PNGDecoder ASURA_FINAL: public ImageDecoder - { - public: +/// +/// ʹlodepngѹpngļ +/// +class PNGDecoder ASURA_FINAL: public ImageDecoder +{ +public: - bool CanDecode(AEIO::DataBuffer& buffer) override; + bool CanDecode(AEIO::DataBuffer& buffer) override; - void Decode(AEIO::DataBuffer& buffer, ImageData& data) 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 index add1c13..ed61aa4 100644 --- a/source/modules/asura-core/image/stb_decoder.cpp +++ b/source/modules/asura-core/image/stb_decoder.cpp @@ -7,69 +7,67 @@ using namespace AEGraphics; -namespace AsuraEngine -{ - namespace Image - { +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); +bool STBDecoder::CanDecode(IO::DataBuffer& buffer) +{ + int w = 0; + int h = 0; + int comp = 0; - return status == 1 && w > 0 && h > 0; - } + int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); - void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) - { - const stbi_uc *buffer = (const stbi_uc *)db.GetData(); - // databufferݳ - int bufferlen = db.GetSize(); + return status == 1 && w > 0 && h > 0; +} - int width, height; - int comp = 0; - byte* data = nullptr; - ColorFormat format = COLOR_FORMAT_UNKNOWN; - std::size_t size = 0; +void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) +{ + const stbi_uc *buffer = (const stbi_uc *)db.GetData(); + // databufferݳ + int bufferlen = db.GetSize(); - 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(); + int width, height; + int comp = 0; + byte* data = nullptr; + ColorFormat format = COLOR_FORMAT_UNKNOWN; + std::size_t size = 0; - if (imageData.pixels) - free(imageData.pixels); - imageData.pixels = (byte*)data; - imageData.format = format; - imageData.width = width; - imageData.height = height; - imageData.size = size; + 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(); - 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); - } - } + if (imageData.pixels) + free(imageData.pixels); + imageData.pixels = (byte*)data; + imageData.format = format; + imageData.width = width; + imageData.height = height; + imageData.size = size; + imageData.Unlock(); } -}
\ No newline at end of file + 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 index ad89214..6158b21 100644 --- a/source/modules/asura-core/image/stb_decoder.h +++ b/source/modules/asura-core/image/stb_decoder.h @@ -3,26 +3,24 @@ #include "image_decoder.h" -namespace AsuraEngine +namespace_begin(AsuraEngine) +namespace_begin(Image) + +/// +/// ʹstb_imageѹJPEGTGABMPļ +/// +class STBDecoder ASURA_FINAL + : public ImageDecoder { - namespace Image - { +public: - /// - /// ʹstb_imageѹJPEGTGABMPļ - /// - class STBDecoder ASURA_FINAL - : public ImageDecoder - { - public: + bool CanDecode(AEIO::DataBuffer& buffer) override; - bool CanDecode(AEIO::DataBuffer& buffer) override; + void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; +}; - }; - - } -} +namespace_end +namespace_end #endif
\ No newline at end of file |