1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef INCLUDED_BASEBMP_FILLIMAGE_HXX
25 #define INCLUDED_BASEBMP_FILLIMAGE_HXX
26
27 #include <vigra/tuple.hxx>
28 #include <vigra/iteratortraits.hxx>
29
30 namespace basebmp
31 {
32
33 template< class DestIterator, class DestAccessor, typename T >
fillImage(DestIterator begin,DestIterator end,DestAccessor ad,T fillVal)34 void fillImage( DestIterator begin,
35 DestIterator end,
36 DestAccessor ad,
37 T fillVal )
38 {
39 const int width ( end.x - begin.x );
40 const int height( end.y - begin.y );
41
42 for( int y=0; y<height; ++y, ++begin.y )
43 {
44 typename vigra::IteratorTraits<DestIterator>::row_iterator
45 rowIter( begin.rowIterator() );
46 const typename vigra::IteratorTraits<DestIterator>::row_iterator
47 rowEnd( rowIter + width );
48
49 // TODO(P2): Provide specialized span fill methods on the
50 // iterator/accessor
51 while( rowIter != rowEnd )
52 ad.set(fillVal, rowIter++);
53 }
54 }
55
56 template< class DestIterator, class DestAccessor, typename T >
fillImage(vigra::triple<DestIterator,DestIterator,DestAccessor> const & src,T fillVal)57 inline void fillImage( vigra::triple<DestIterator,DestIterator,DestAccessor> const& src,
58 T fillVal )
59 {
60 fillImage(src.first,src.second,src.third,fillVal);
61 }
62
63 } // namespace basebmp
64
65 #endif /* INCLUDED_BASEBMP_FILLIMAGE_HXX */
66