diff options
author | Thorsten Behrens <thb@openoffice.org> | 2006-07-14 13:22:58 +0000 |
---|---|---|
committer | Thorsten Behrens <thb@openoffice.org> | 2006-07-14 13:22:58 +0000 |
commit | 631f64a3946c0a31ceeb8d94624d0ed332e9a737 (patch) | |
tree | 7365e42e3c0f671afea2c1739ff595289aae4732 /basebmp | |
parent | 57ad79523830268ef4de18dea4659cfdf2d53df5 (diff) |
#i65904# Replaced vigra::resizeImageNoInterpolation() with own scaleImage() - the case size <2 does happen sometimes
Diffstat (limited to 'basebmp')
-rw-r--r-- | basebmp/inc/basebmp/scaleimage.hxx | 156 | ||||
-rw-r--r-- | basebmp/source/bitmapdevice.cxx | 22 |
2 files changed, 167 insertions, 11 deletions
diff --git a/basebmp/inc/basebmp/scaleimage.hxx b/basebmp/inc/basebmp/scaleimage.hxx new file mode 100644 index 000000000000..f3231dec2e9b --- /dev/null +++ b/basebmp/inc/basebmp/scaleimage.hxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: scaleimage.hxx,v $ + * + * $Revision: 1.1 $ + * + * last change: $Author: thb $ $Date: 2006-07-14 14:22:58 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef INCLUDED_BASEBIMAGE_SCALEIMAGE_HXX +#define INCLUDED_BASEBIMAGE_SCALEIMAGE_HXX + +#include <osl/diagnose.h> + +#include <vigra/tuple.hxx> +#include <vigra/basicimage.hxx> +#include <vigra/iteratortraits.hxx> + +namespace basebmp +{ + +template< class SourceIter, class SourceAcc, + class DestIter, class DestAcc > +inline void scaleLine( SourceIter s_begin, + SourceIter s_end, + SourceAcc s_acc, + DestIter d_begin, + DestIter d_end, + DestAcc d_acc ) +{ + const int src_width = s_end - s_begin; + const int dest_width = d_end - d_begin; + + OSL_ASSERT( src_width > 0 && dest_width > 0 ); + + if( src_width >= dest_width ) + { + // shrink + int rem = 0; + while( s_begin != s_end ) + { + if( rem >= 0 ) + { + d_acc.set( s_acc(s_begin), d_begin ); + + rem -= src_width; + ++d_begin; + } + + rem += dest_width; + ++s_begin; + } + } + else + { + // enlarge + int rem = -dest_width; + while( d_begin != d_end ) + { + if( rem >= 0 ) + { + rem -= dest_width; + ++s_begin; + } + + d_acc.set( s_acc(s_begin), d_begin ); + + rem += src_width; + ++d_begin; + } + } +} + +template< class SourceIter, class SourceAcc, + class DestIter, class DestAcc > +inline void scaleImage( SourceIter s_begin, + SourceIter s_end, + SourceAcc s_acc, + DestIter d_begin, + DestIter d_end, + DestAcc d_acc ) +{ + const int src_width ( s_end.x - s_begin.x ); + const int src_height( s_end.y - s_begin.y ); + + const int dest_width ( d_end.x - d_begin.x ); + const int dest_height( d_end.y - d_begin.y ); + + typedef vigra::BasicImage<typename SourceAcc::value_type> TmpImage; + typedef typename TmpImage::traverser TmpImageIter; + + TmpImage tmp_image(src_width, + dest_height); + TmpImageIter t_begin = tmp_image.upperLeft(); + + // scale in y direction + for( int x=0; x<src_width; ++x, ++s_begin.x, ++t_begin.x ) + { + typename SourceIter::column_iterator s_cbegin = s_begin.columnIterator(); + typename TmpImageIter::column_iterator t_cbegin = t_begin.columnIterator(); + + scaleLine(s_cbegin, s_cbegin+src_height, s_acc, + t_cbegin, t_cbegin+dest_height, tmp_image.accessor()); + } + + t_begin = tmp_image.upperLeft(); + + // scale in x direction + for( int y=0; y<dest_height; ++y, ++d_begin.y, ++t_begin.y ) + { + typename DestIter::row_iterator d_rbegin = d_begin.rowIterator(); + typename TmpImageIter::row_iterator t_rbegin = t_begin.rowIterator(); + + scaleLine(t_rbegin, t_rbegin+src_width, tmp_image.accessor(), + d_rbegin, d_rbegin+dest_width, d_acc); + } +} + +template< class SourceIter, class SourceAcc, + class DestIter, class DestAcc > +inline void scaleImage( vigra::triple<SourceIter,SourceIter,SourceAcc> const& src, + vigra::triple<DestIter,DestIter,DestAcc> const& dst ) +{ + scaleImage(src.first,src.second,src.third, + dst.first,dst.second,dst.third); +} + +} + +#endif /* INCLUDED_BASEBIMAGE_SCALEIMAGE_HXX */ diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx index aa6c72348907..d43056b7a6a1 100644 --- a/basebmp/source/bitmapdevice.cxx +++ b/basebmp/source/bitmapdevice.cxx @@ -4,9 +4,9 @@ * * $RCSfile: bitmapdevice.cxx,v $ * - * $Revision: 1.21 $ + * $Revision: 1.22 $ * - * last change: $Author: thb $ $Date: 2006-07-13 12:03:26 $ + * last change: $Author: thb $ $Date: 2006-07-14 14:22:58 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -54,6 +54,7 @@ #include "basebmp/scanlineformats.hxx" #include "basebmp/fillimage.hxx" +#include "basebmp/scaleimage.hxx" #include "basebmp/clippedlinerenderer.hxx" //#include "basebmp/genericintegerimageaccessor.hxx" @@ -77,7 +78,6 @@ #include <vigra/iteratortraits.hxx> #include <vigra/rgbvalue.hxx> -#include <vigra/resizeimage.hxx> #include <vigra/copyimage.hxx> #include <vigra/tuple.hxx> @@ -738,9 +738,9 @@ namespace boost::shared_ptr<BitmapRenderer> pSrcBmp( getCompatibleBitmap(rSrcBitmap) ); OSL_ASSERT( pSrcBmp ); - // since resizeImageNoInterpolation() internally copyies + // since scaleImage() internally copyies // to a temporary buffer, also works with *this == rSrcBitmap - vigra::resizeImageNoInterpolation( + scaleImage( srcIterRange(pSrcBmp->maBegin, pSrcBmp->maRawAccessor, rSrcRect), @@ -759,9 +759,9 @@ namespace { GenericImageAccessor aSrcAcc( rSrcBitmap ); - // since resizeImageNoInterpolation() internally copyies + // since scaleImage() internally copyies // to a temporary buffer, also works with *this == rSrcBitmap - vigra::resizeImageNoInterpolation( + scaleImage( srcIterRange(vigra::Diff2D(), aSrcAcc, rSrcRect), @@ -929,9 +929,9 @@ namespace boost::shared_ptr<mask_bitmap_type> pMask( getCompatibleClipMask(rMask) ); OSL_ASSERT( pMask && pSrcBmp ); - // since resizeImageNoInterpolation() internally copyies + // since scaleImage() internally copyies // to a temporary buffer, also works with *this == rSrcBitmap - vigra::resizeImageNoInterpolation( + scaleImage( srcIterRange(composite_iterator_type( pSrcBmp->maBegin, pMask->maBegin), @@ -964,9 +964,9 @@ namespace rSrcRect.getMinY()); const vigra::Diff2D aBottomRight(rSrcRect.getMaxX(), rSrcRect.getMaxY()); - // since resizeImageNoInterpolation() internally copyies + // since scaleImage() internally copyies // to a temporary buffer, also works with *this == rSrcBitmap - vigra::resizeImageNoInterpolation( + scaleImage( vigra::make_triple( generic_composite_iterator_type( aTopLeft,aTopLeft), |