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_GENERICCOLORIMAGEACCESSOR_HXX 25 #define INCLUDED_BASEBMP_GENERICCOLORIMAGEACCESSOR_HXX 26 27 #include <basebmp/color.hxx> 28 #include <basebmp/bitmapdevice.hxx> 29 30 namespace basebmp 31 { 32 /** Access a BitmapDevice generically 33 34 This accessor deals with an opaque BitmapDevice generically, 35 via getPixel()/setPixel() at the published interface. 36 */ 37 class GenericColorImageAccessor 38 { 39 BitmapDeviceSharedPtr mpDevice; 40 DrawMode meDrawMode; 41 42 public: 43 typedef Color value_type; 44 GenericColorImageAccessor(BitmapDeviceSharedPtr const & rTarget)45 explicit GenericColorImageAccessor( BitmapDeviceSharedPtr const& rTarget ) : 46 mpDevice(rTarget), 47 meDrawMode(DrawMode_PAINT) 48 {} 49 GenericColorImageAccessor(BitmapDeviceSharedPtr const & rTarget,DrawMode eDrawMode)50 GenericColorImageAccessor( BitmapDeviceSharedPtr const& rTarget, 51 DrawMode eDrawMode ) : 52 mpDevice(rTarget), 53 meDrawMode(eDrawMode) 54 {} 55 56 template< typename Iterator > operator ()(Iterator const & i) const57 Color operator()( Iterator const& i ) const 58 { return mpDevice->getPixel( basegfx::B2IPoint( i->x,i->y ) ); } 59 60 template< typename Iterator, typename Difference > operator ()(Iterator const & i,Difference const & diff) const61 Color operator()( Iterator const& i, Difference const& diff) const 62 { return mpDevice->getPixel( basegfx::B2IPoint( i[diff]->x, 63 i[diff]->y ) ); } 64 65 template< typename Iterator > set(Color const & value,Iterator const & i) const66 void set(Color const& value, Iterator const& i) const 67 { return mpDevice->setPixel( basegfx::B2IPoint( i->x,i->y ), 68 value, meDrawMode ); } 69 70 template< class Iterator, class Difference > set(value_type const & value,Iterator const & i,Difference const & diff) const71 void set(value_type const& value, Iterator const& i, Difference const& diff) const 72 { return mpDevice->setPixel( basegfx::B2IPoint( i[diff]->x, 73 i[diff]->y ), 74 value, meDrawMode ); } 75 }; 76 } 77 78 #endif /* INCLUDED_BASEBMP_GENERICCOLORIMAGEACCESSOR_HXX */ 79