Use get_pixel_address_fast() in ImageIterator

This commit is contained in:
David Capello 2015-06-11 18:59:51 -03:00
parent 2b104260f5
commit d732f5b05f
6 changed files with 61 additions and 28 deletions

View File

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

40
src/doc/image_impl.cpp Normal file
View File

@ -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<BitmapTraits> src_it(src, area.srcBounds(), area.src.x, area.src.y);
ImageIterator<BitmapTraits> 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<end_y;
++area.dst.y, ++area.src.y) {
for (int x=area.dst.x; x<end_x; ++x) {
*dst_it = *src_it;
++src_it;
++dst_it;
}
}
}
} // namespace doc

View File

@ -14,7 +14,6 @@
#include "doc/blend.h"
#include "doc/image.h"
#include "doc/image_bits.h"
#include "doc/image_iterator.h"
#include "doc/palette.h"
namespace doc {
@ -252,26 +251,10 @@ namespace doc {
}
}
void copy_bitmaps(Image* dst, const Image* src, gfx::Clip area);
template<>
inline void ImageImpl<BitmapTraits>::copy(const Image* src, gfx::Clip area) {
if (!area.clip(width(), height(), src->width(), src->height()))
return;
// Copy process
ImageConstIterator<BitmapTraits> src_it(src, area.srcBounds(), area.src.x, area.src.y);
ImageIterator<BitmapTraits> 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<end_y;
++area.dst.y, ++area.src.y) {
for (int x=area.dst.x; x<end_x; ++x) {
*dst_it = *src_it;
++src_it;
++dst_it;
}
}
copy_bitmaps(this, src, area);
}
} // namespace doc

View File

@ -8,11 +8,13 @@
#define DOC_IMAGE_ITERATOR_H_INCLUDED
#pragma once
#include "gfx/point.h"
#include "gfx/rect.h"
#include "doc/color.h"
#include "doc/image.h"
#include "doc/image_impl.h"
#include "doc/image_traits.h"
#include "doc/primitives_fast.h"
#include "gfx/point.h"
#include "gfx/rect.h"
#include <cstdlib>
#include <iterator>
@ -50,7 +52,7 @@ namespace doc {
ImageIteratorT(const Image* image, const gfx::Rect& bounds, int x, int y) :
m_image(const_cast<Image*>(image)),
m_ptr((pointer)image->getPixelAddress(x, y)),
m_ptr(get_pixel_address_fast<ImageTraits>(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<ImageTraits>(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*>(image)),
m_ptr((pointer)image->getPixelAddress(x, y)),
m_ptr(get_pixel_address_fast<BitmapTraits>(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<BitmapTraits>(m_image, m_x, m_y);
else
++m_ptr;
}

View File

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

View File

@ -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<class Traits>
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<Traits>*)image)->address(x, y));
}
template<class Traits>
inline typename Traits::pixel_t get_pixel_fast(const Image* image, int x, int y) {
ASSERT(x >= 0 && x < image->width());