image::paste throws exception if graphics or image is empty

This commit is contained in:
Jinhao
2015-07-13 00:23:54 +08:00
parent 17556cae99
commit 1eb76307e4
15 changed files with 59 additions and 642 deletions

View File

@@ -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
}