improve image and pixel_buffer

This commit is contained in:
Jinhao
2015-10-17 14:42:07 +08:00
parent 8f59ccfbf6
commit 7f4cc3f6d9
13 changed files with 216 additions and 266 deletions

View File

@@ -20,9 +20,12 @@
#include <nana/paint/detail/image_impl_interface.hpp>
#include <nana/paint/pixel_buffer.hpp>
#if defined(NANA_ENABLE_PNG)
#include "detail/image_png.hpp"
#endif
#include "detail/image_bmp.hpp"
#include "detail/image_ico.hpp"
@@ -155,16 +158,17 @@ namespace paint
image::image_impl_interface::~image_impl_interface()
{}
namespace detail
/*
namespace detail
{
int toupper(int c)
int toupper(int c) //deprecated
{
return (('a' <= c && c <= 'z') ?
c - ('a' - 'A')
: c);
}
}//end namespace detail
//*/
//class image
image::image()
@@ -216,25 +220,48 @@ namespace paint
if(filename.size())
{
nana::string fn;
std::transform(filename.cbegin(), filename.cend(), std::back_inserter(fn), detail::toupper);
if(filename.size() >= 4)
auto dotpos = filename.find_last_of('.');
if (dotpos != filename.npos)
{
nana::string suffix = fn.substr(fn.size() - 4);
if(STR(".ICO") == suffix)
auto type_str = ::nana::cistring(filename.substr(dotpos + 1).data());
do
{
if (STR("ICO") == type_str)
{
#if defined(NANA_WINDOWS)
helper = new detail::image_ico(true);
helper = new detail::image_ico(true);
#else
return false;
#endif
}
break;
}
if (STR("PNG") == type_str)
{
#if defined(NANA_ENABLE_PNG)
else if(STR(".PNG") == suffix)
helper = new detail::image_png;
helper = new detail::image_png;
#else
return false;
#endif
break;
}
if (STR("JPG") == type_str || STR("JPEG") == type_str)
{
#if defined(NANA_ENABLE_JPEG)
helper = new detail::image_jpeg;
#else
return false;
#endif
break;
}
} while (false);
}
if(0 == helper)
//Check for BMP
if(!helper)
{
#if defined(NANA_UNICODE)
std::ifstream ifs(std::string(nana::charset(filename)).c_str(), std::ios::binary);