From d732f5b05f33ed1fce4c8b900a54f617bfb4c5ae Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 11 Jun 2015 18:59:51 -0300 Subject: [PATCH] Use get_pixel_address_fast() in ImageIterator --- src/doc/CMakeLists.txt | 1 + src/doc/image_impl.cpp | 40 +++++++++++++++++++++++++++++++++++++++ src/doc/image_impl.h | 21 ++------------------ src/doc/image_iterator.h | 14 ++++++++------ src/doc/image_traits.h | 4 ++-- src/doc/primitives_fast.h | 9 ++++++++- 6 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 src/doc/image_impl.cpp diff --git a/src/doc/CMakeLists.txt b/src/doc/CMakeLists.txt index 03bc7cb12..31fa7c5c1 100644 --- a/src/doc/CMakeLists.txt +++ b/src/doc/CMakeLists.txt @@ -31,6 +31,7 @@ add_library(doc-lib frame_tags.cpp handle_anidir.cpp image.cpp + image_impl.cpp image_io.cpp images_collector.cpp layer.cpp diff --git a/src/doc/image_impl.cpp b/src/doc/image_impl.cpp new file mode 100644 index 000000000..d5f63db76 --- /dev/null +++ b/src/doc/image_impl.cpp @@ -0,0 +1,40 @@ +// Aseprite Document Library +// Copyright (c) 2001-2015 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "doc/image_impl.h" + +#include "doc/image_iterator.h" +#include "doc/image_traits.h" + +namespace doc { + +void copy_bitmaps(Image* dst, const Image* src, gfx::Clip area) +{ + if (!area.clip(dst->width(), dst->height(), src->width(), src->height())) + return; + + // Copy process + ImageConstIterator src_it(src, area.srcBounds(), area.src.x, area.src.y); + ImageIterator dst_it(dst, area.dstBounds(), area.dst.x, area.dst.y); + + int end_x = area.dst.x+area.size.w; + + for (int end_y=area.dst.y+area.size.h; + area.dst.y inline void ImageImpl::copy(const Image* src, gfx::Clip area) { - if (!area.clip(width(), height(), src->width(), src->height())) - return; - - // Copy process - ImageConstIterator src_it(src, area.srcBounds(), area.src.x, area.src.y); - ImageIterator dst_it(this, area.dstBounds(), area.dst.x, area.dst.y); - - int end_x = area.dst.x+area.size.w; - - for (int end_y=area.dst.y+area.size.h; - area.dst.y #include @@ -50,7 +52,7 @@ namespace doc { ImageIteratorT(const Image* image, const gfx::Rect& bounds, int x, int y) : m_image(const_cast(image)), - m_ptr((pointer)image->getPixelAddress(x, y)), + m_ptr(get_pixel_address_fast(image, x, y)), m_x(x), m_y(y), m_xbegin(bounds.x), @@ -104,7 +106,7 @@ namespace doc { ++m_y; if (m_y < m_image->height()) - m_ptr = (pointer)m_image->getPixelAddress(m_x, m_y); + m_ptr = get_pixel_address_fast(m_image, m_x, m_y); } return *this; @@ -287,7 +289,7 @@ namespace doc { ImageIteratorT(const Image* image, const gfx::Rect& bounds, int x, int y) : m_image(const_cast(image)), - m_ptr((pointer)image->getPixelAddress(x, y)), + m_ptr(get_pixel_address_fast(image, x, y)), m_x(x), m_y(y), m_subPixel(x % 8), @@ -341,7 +343,7 @@ namespace doc { ++m_y; if (m_y < m_image->height()) - m_ptr = (pointer)m_image->getPixelAddress(m_x, m_y); + m_ptr = get_pixel_address_fast(m_image, m_x, m_y); else ++m_ptr; } diff --git a/src/doc/image_traits.h b/src/doc/image_traits.h index 5edc4dd95..e81c05862 100644 --- a/src/doc/image_traits.h +++ b/src/doc/image_traits.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -29,7 +29,7 @@ namespace doc { static const pixel_t min_value = 0x00000000l; static const pixel_t max_value = 0xffffffffl; - + static inline int getRowStrideBytes(int pixels_per_row) { return bytes_per_pixel * pixels_per_row; diff --git a/src/doc/primitives_fast.h b/src/doc/primitives_fast.h index debc5f428..d15054d89 100644 --- a/src/doc/primitives_fast.h +++ b/src/doc/primitives_fast.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -14,6 +14,13 @@ namespace doc { class Image; + template + inline typename Traits::address_t get_pixel_address_fast(const Image* image, int x, int y) { + ASSERT(x >= 0 && x < image->width()); + ASSERT(y >= 0 && y < image->height()); + return (((ImageImpl*)image)->address(x, y)); + } + template inline typename Traits::pixel_t get_pixel_fast(const Image* image, int x, int y) { ASSERT(x >= 0 && x < image->width());