image::paste throws exception if graphics or image is empty
This commit is contained in:
@@ -201,7 +201,7 @@ namespace nana
|
||||
case frame::kind::oneshot:
|
||||
_m_render(outs, [&frmobj](paint::graphics& tar, const nana::point& pos)
|
||||
{
|
||||
frmobj.u.oneshot->paste(tar, pos.x, pos.y);
|
||||
frmobj.u.oneshot->paste(tar, pos);
|
||||
});
|
||||
break;
|
||||
case frame::kind::framebuilder:
|
||||
@@ -230,7 +230,7 @@ namespace nana
|
||||
switch(frmobj.type)
|
||||
{
|
||||
case frame::kind::oneshot:
|
||||
frmobj.u.oneshot->paste(graph, pos.x, pos.y);
|
||||
frmobj.u.oneshot->paste(graph, pos);
|
||||
break;
|
||||
case frame::kind::framebuilder:
|
||||
if(rebuild_frame)
|
||||
|
||||
@@ -258,7 +258,7 @@ namespace nana{ namespace drawerbase
|
||||
}
|
||||
|
||||
if(attr_.icon)
|
||||
attr_.icon->paste(graph, 3, (gsize.height - icon_sz.height) / 2);
|
||||
attr_.icon->paste(graph, point{ 3, static_cast<int>(gsize.height - icon_sz.height) / 2 });
|
||||
}
|
||||
|
||||
void trigger::_m_draw(graph_reference graph)
|
||||
|
||||
@@ -1263,7 +1263,7 @@ namespace nana
|
||||
img->stretch(::nana::rectangle{ size }, graph, attr.area);
|
||||
}
|
||||
else
|
||||
img->paste(graph, attr.area.x + static_cast<int>(attr.area.width - size.width) / 2, attr.area.y + static_cast<int>(attr.area.height - size.height) / 2);
|
||||
img->paste(graph, point{ attr.area.x + static_cast<int>(attr.area.width - size.width) / 2, attr.area.y + static_cast<int>(attr.area.height - size.height) / 2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,8 +100,8 @@ namespace detail
|
||||
|
||||
void blend(drawable_type dw, const rectangle& area, pixel_color_t color, double fade_rate)
|
||||
{
|
||||
if(fade_rate <= 0) return;
|
||||
if(fade_rate > 1) fade_rate = 1;
|
||||
if (fade_rate <= 0) return;
|
||||
if (fade_rate > 1) fade_rate = 1;
|
||||
|
||||
rectangle r;
|
||||
if (false == ::nana::overlap(rectangle{ drawable_size(dw) }, area, r))
|
||||
@@ -114,11 +114,11 @@ namespace detail
|
||||
double lrate = 1 - fade_rate;
|
||||
pixel_buffer pixbuf(dw, r.y, r.height);
|
||||
|
||||
for(std::size_t row = 0; row < r.height; ++row)
|
||||
for (std::size_t row = 0; row < r.height; ++row)
|
||||
{
|
||||
auto i = pixbuf.raw_ptr(row) + r.x;
|
||||
const auto end = i + r.width;
|
||||
for(; i < end; ++i)
|
||||
for (; i < end; ++i)
|
||||
{
|
||||
unsigned px_r = ((static_cast<unsigned>((i->value & 0xFF0000) * lrate) + red) & 0xFF0000);
|
||||
unsigned px_g = ((static_cast<unsigned>((i->value & 0xFF00) * lrate) + green) & 0xFF00);
|
||||
@@ -126,7 +126,7 @@ namespace detail
|
||||
i->value = (px_r | px_g | px_b);
|
||||
}
|
||||
}
|
||||
pixbuf.paste(nana::rectangle(r.x, 0, r.width, r.height), dw, r.x, r.y);
|
||||
pixbuf.paste(nana::rectangle(r.x, 0, r.width, r.height), dw, point{r.x, r.y});
|
||||
}
|
||||
|
||||
nana::size raw_text_extent_size(drawable_type dw, const nana::char_t* text, std::size_t len)
|
||||
|
||||
@@ -618,7 +618,7 @@ namespace paint
|
||||
{
|
||||
pixel_buffer pixbuf(handle_, 0, 0);
|
||||
pixbuf.blur(r, radius);
|
||||
pixbuf.paste(handle_, 0, 0);
|
||||
pixbuf.paste(handle_, point{});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -677,7 +677,7 @@ namespace paint
|
||||
}
|
||||
delete [] tablebuf;
|
||||
|
||||
pixbuf.paste(handle_, 0, 0);
|
||||
pixbuf.paste(handle_, point{});
|
||||
if(changed_ == false) changed_ = true;
|
||||
}
|
||||
}
|
||||
@@ -1074,7 +1074,7 @@ namespace paint
|
||||
if (pxbuf_.open(handle_))
|
||||
{
|
||||
pxbuf_.gradual_rectangle(rct, from, to, 0.0, vertical);
|
||||
pxbuf_.paste(handle_, 0, 0);
|
||||
pxbuf_.paste(handle_, point{});
|
||||
}
|
||||
#elif defined(NANA_X11)
|
||||
if (nullptr == handle_) return;
|
||||
|
||||
@@ -16,14 +16,15 @@
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <nana/paint/detail/image_impl_interface.hpp>
|
||||
#include <nana/paint/pixel_buffer.hpp>
|
||||
#if defined(NANA_ENABLE_PNG)
|
||||
#include <nana/paint/detail/image_png.hpp>
|
||||
#include "detail/image_png.hpp"
|
||||
#endif
|
||||
#include <nana/paint/detail/image_bmp.hpp>
|
||||
#include <nana/paint/detail/image_ico.hpp>
|
||||
#include "detail/image_bmp.hpp"
|
||||
#include "detail/image_ico.hpp"
|
||||
|
||||
namespace nana
|
||||
{
|
||||
@@ -89,12 +90,12 @@ namespace paint
|
||||
return size_;
|
||||
}
|
||||
|
||||
void image_ico::paste(const nana::rectangle& src_r, graph_reference graph, int x, int y) const
|
||||
void image_ico::paste(const nana::rectangle& src_r, graph_reference graph, const point& p_dst) const
|
||||
{
|
||||
if(ptr_ && (graph.empty() == false))
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
::DrawIconEx(graph.handle()->context, x, y, *ptr_, src_r.width, src_r.height, 0, 0, DI_NORMAL);
|
||||
::DrawIconEx(graph.handle()->context, p_dst.x, p_dst.y, *ptr_, src_r.width, src_r.height, 0, 0, DI_NORMAL);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -260,22 +261,40 @@ namespace paint
|
||||
return (image_ptr_ ? image_ptr_->size() : nana::size());
|
||||
}
|
||||
|
||||
void image::paste(graphics& dst, int x, int y) const
|
||||
void image::paste(graphics& dst, const point& p_dst) const
|
||||
{
|
||||
if(image_ptr_)
|
||||
image_ptr_->paste(::nana::rectangle{ image_ptr_->size() }, dst, x, y);
|
||||
if(image_ptr_ && !dst.empty())
|
||||
image_ptr_->paste(::nana::rectangle{ image_ptr_->size() }, dst, p_dst);
|
||||
|
||||
if (!image_ptr_)
|
||||
throw std::runtime_error("image is empty");
|
||||
|
||||
if (dst.empty())
|
||||
throw std::invalid_argument("graphics is empty");
|
||||
}
|
||||
|
||||
void image::paste(const nana::rectangle& r_src, graphics & dst, const nana::point& p_dst) const
|
||||
{
|
||||
if(image_ptr_)
|
||||
image_ptr_->paste(r_src, dst, p_dst.x, p_dst.y);
|
||||
if(image_ptr_ && !dst.empty())
|
||||
image_ptr_->paste(r_src, dst, p_dst);
|
||||
|
||||
if (!image_ptr_)
|
||||
throw std::runtime_error("image is empty");
|
||||
|
||||
if (dst.empty())
|
||||
throw std::invalid_argument("graphics is empty");
|
||||
}
|
||||
|
||||
void image::stretch(const nana::rectangle& r_src, graphics& dst, const nana::rectangle & r_dst) const
|
||||
{
|
||||
if(image_ptr_)
|
||||
image_ptr_->stretch(r_src, dst, r_dst);
|
||||
if(image_ptr_ && !dst.empty())
|
||||
image_ptr_->stretch(r_src, dst, r_dst);
|
||||
|
||||
if (!image_ptr_)
|
||||
throw std::runtime_error("image is empty");
|
||||
|
||||
if (dst.empty())
|
||||
throw std::invalid_argument("graphics is empty");
|
||||
}
|
||||
//end class image
|
||||
|
||||
|
||||
@@ -633,13 +633,13 @@ namespace nana{ namespace paint
|
||||
*reinterpret_cast<pixel_color_t*>(reinterpret_cast<char*>(sp->raw_pixel_buffer + x) + y * sp->bytes_per_line) = px;
|
||||
}
|
||||
|
||||
void pixel_buffer::paste(drawable_type drawable, int x, int y) const
|
||||
void pixel_buffer::paste(drawable_type drawable, const point& p_dst) const
|
||||
{
|
||||
if(storage_)
|
||||
paste(nana::rectangle(storage_->pixel_size), drawable, x, y);
|
||||
paste(nana::rectangle(storage_->pixel_size), drawable, p_dst);
|
||||
}
|
||||
|
||||
void pixel_buffer::paste(const nana::rectangle& src_r, drawable_type drawable, int x, int y) const
|
||||
void pixel_buffer::paste(const nana::rectangle& src_r, drawable_type drawable, const point& p_dst) const
|
||||
{
|
||||
auto sp = storage_.get();
|
||||
if(drawable && sp)
|
||||
@@ -647,7 +647,7 @@ namespace nana{ namespace paint
|
||||
if(sp->alpha_channel)
|
||||
{
|
||||
nana::rectangle s_good_r, d_good_r;
|
||||
if(overlap(src_r, sp->pixel_size, nana::rectangle(x, y, src_r.width, src_r.height), paint::detail::drawable_size(drawable), s_good_r, d_good_r))
|
||||
if(overlap(src_r, sp->pixel_size, nana::rectangle(p_dst.x, p_dst.y, src_r.width, src_r.height), paint::detail::drawable_size(drawable), s_good_r, d_good_r))
|
||||
{
|
||||
pixel_buffer d_pixbuf;
|
||||
d_pixbuf.attach(drawable, d_good_r);
|
||||
@@ -660,16 +660,16 @@ namespace nana{ namespace paint
|
||||
assign_windows_bitmapinfo(sp->pixel_size, bi);
|
||||
|
||||
::SetDIBitsToDevice(drawable->context,
|
||||
x, y, src_r.width, src_r.height,
|
||||
p_dst.x, p_dst.y, src_r.width, src_r.height,
|
||||
src_r.x, static_cast<int>(sp->pixel_size.height) - src_r.y - src_r.height, 0, sp->pixel_size.height,
|
||||
sp->raw_pixel_buffer, &bi, DIB_RGB_COLORS);
|
||||
#elif defined(NANA_X11)
|
||||
sp->put(drawable->pixmap, drawable->context, src_r.x, src_r.y, x, y, src_r.width, src_r.height);
|
||||
sp->put(drawable->pixmap, drawable->context, src_r.x, src_r.y, p_dst.x, p_dst.y, src_r.width, src_r.height);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void pixel_buffer::paste(native_window_type wd, int x, int y) const
|
||||
void pixel_buffer::paste(native_window_type wd, const point& p_dst) const
|
||||
{
|
||||
auto sp = storage_.get();
|
||||
if(nullptr == wd || nullptr == sp) return;
|
||||
@@ -681,7 +681,7 @@ namespace nana{ namespace paint
|
||||
assign_windows_bitmapinfo(sp->pixel_size, bi);
|
||||
|
||||
::SetDIBitsToDevice(handle,
|
||||
x, y, sp->pixel_size.width, sp->pixel_size.height,
|
||||
p_dst.x, p_dst.y, sp->pixel_size.width, sp->pixel_size.height,
|
||||
0, 0, 0, sp->pixel_size.height,
|
||||
sp->raw_pixel_buffer, &bi, DIB_RGB_COLORS);
|
||||
|
||||
@@ -690,7 +690,7 @@ namespace nana{ namespace paint
|
||||
#elif defined(NANA_X11)
|
||||
auto & spec = nana::detail::platform_spec::instance();
|
||||
Display * disp = spec.open_display();
|
||||
sp->put(reinterpret_cast<Window>(wd), XDefaultGC(disp, XDefaultScreen(disp)), 0, 0, x, y, sp->pixel_size.width, sp->pixel_size.height);
|
||||
sp->put(reinterpret_cast<Window>(wd), XDefaultGC(disp, XDefaultScreen(disp)), 0, 0, p_dst.x, p_dst.y, sp->pixel_size.width, sp->pixel_size.height);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user