open png/jpg image with memory buffer
This commit is contained in:
@@ -163,7 +163,7 @@ namespace paint
|
||||
{}
|
||||
|
||||
//class image
|
||||
image::image()
|
||||
image::image() noexcept
|
||||
{}
|
||||
|
||||
image::image(const image& rhs)
|
||||
@@ -245,7 +245,7 @@ namespace paint
|
||||
if (ext_png == ext)
|
||||
{
|
||||
#if defined(NANA_ENABLE_PNG)
|
||||
ptr = std::make_shared<detail::image_png>;
|
||||
ptr = std::make_shared<detail::image_png>();
|
||||
#else
|
||||
return ptr;
|
||||
#endif
|
||||
@@ -299,14 +299,53 @@ namespace paint
|
||||
return (image_ptr_ ? image_ptr_->open(path) : false);
|
||||
}
|
||||
|
||||
bool image::open_icon(const void* data, std::size_t bytes)
|
||||
bool image::open(const void* data, std::size_t bytes)
|
||||
{
|
||||
image::image_impl_interface * helper = new detail::image_ico(true);
|
||||
image_ptr_ = std::shared_ptr<image_impl_interface>(helper);
|
||||
return helper->open(data, bytes);
|
||||
close();
|
||||
|
||||
if (bytes > 2)
|
||||
{
|
||||
std::shared_ptr<image::image_impl_interface> ptr;
|
||||
|
||||
auto meta = *reinterpret_cast<const unsigned short*>(data);
|
||||
|
||||
if (*reinterpret_cast<const short*>("BM") == meta)
|
||||
ptr = std::make_shared<detail::image_bmp>();
|
||||
else if (*reinterpret_cast<const short*>("MZ") == meta)
|
||||
ptr = std::make_shared<detail::image_ico>(false);
|
||||
else
|
||||
{
|
||||
if (bytes > 8 && (0x474e5089 == *reinterpret_cast<const unsigned*>(data)))
|
||||
{
|
||||
#if defined(NANA_ENABLE_PNG)
|
||||
ptr = std::make_shared<detail::image_png>();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(NANA_ENABLE_JPEG)
|
||||
//JFIF
|
||||
if (bytes > 11 && (0xe0ffd8ff == *reinterpret_cast<const unsigned*>(data)) && 0x4649464A == *reinterpret_cast<const unsigned*>(reinterpret_cast<const char*>(data)+6))
|
||||
ptr = std::make_shared<detail::image_jpeg>();
|
||||
else if (bytes > 9 && (0x66697845 == *reinterpret_cast<const unsigned*>(reinterpret_cast<const char*>(data)+5))) //Exif
|
||||
ptr = std::make_shared<detail::image_jpeg>();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
image_ptr_.swap(ptr);
|
||||
return image_ptr_->open(data, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool image::empty() const
|
||||
|
||||
bool image::empty() const noexcept
|
||||
{
|
||||
return ((nullptr == image_ptr_) || image_ptr_->empty());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user