Kaydet (Commit) 4ebe2491 authored tarafından Caolán McNamara's avatar Caolán McNamara

drop basebmp entirely now

Change-Id: I534848c4be8eadf86b7f31ac742a80982405f56f
üst 62ea0ef8
......@@ -63,7 +63,6 @@ There are several other libraries that are helpful from a graphical perspective:
Module | Description
----------|-------------------------------------------------
basebmp/ | enables a VCL compatible rendering API to render to bitmaps, as used for LibreOffice Online, Android, iOS, etc.
basegfx/ | algorithms and data-types for graphics as used in the canvas
canvas/ | new (UNO) canvas rendering model with various backends
cppcanvas/ | C++ helper classes for using the UNO canvas
......
......@@ -281,9 +281,6 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \
basctl \
basprov \
) \
$(if $(filter $(OS),ANDROID),, \
basebmp \
) \
basegfx \
bib \
$(if $(ENABLE_CAIRO_CANVAS),cairocanvas) \
......
......@@ -59,7 +59,6 @@ $(eval $(call gb_Module_add_moduledirs,cross_toolset,\
$(call gb_Helper_optional_for_host,DESKTOP, \
$(if $(WITH_GALLERY_BUILD), \
avmedia \
basebmp \
basic \
canvas \
configmgr \
......
......@@ -27,7 +27,6 @@ $(eval $(call gb_Module_add_moduledirs,libreoffice,\
apple_remote \
$(call gb_Helper_optional,AVMEDIA,avmedia) \
basctl \
basebmp \
basegfx \
basic \
bean \
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_CppunitTest_CppunitTest,basebmp))
$(eval $(call gb_CppunitTest_use_sdk_api,basebmp))
$(eval $(call gb_CppunitTest_use_external,basebmp,boost_headers))
$(eval $(call gb_CppunitTest_use_libraries,basebmp,\
basebmp \
))
$(eval $(call gb_CppunitTest_use_libraries,basebmp,\
basegfx \
sal \
$(gb_UWINAPI) \
))
$(eval $(call gb_CppunitTest_add_exception_objects,basebmp,\
basebmp/test/basictest \
basebmp/test/tools \
))
# vim: set noet sw=4 ts=4:
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_Library_Library,basebmp))
$(eval $(call gb_Library_use_sdk_api,basebmp))
$(eval $(call gb_Library_set_include,basebmp,\
-I$(SRCDIR)/basebmp/inc \
$$(INCLUDE) \
))
$(eval $(call gb_Library_use_externals,basebmp,\
boost_headers \
vigra_headers \
))
$(eval $(call gb_Library_use_libraries,basebmp,\
basegfx \
sal \
$(gb_UWINAPI) \
))
$(eval $(call gb_Library_add_defs,basebmp,\
-DBASEBMP_DLLIMPLEMENTATION \
))
# TODO(davido): This is failing only in release mode with:
#
# Compilation of bitmapdevice.cxx is failing in release mode:
#
# Fatal Error C1128: number of sections exceeded object file
# format limit : compile with /bigobj
#
ifeq ($(COM),MSC)
ifeq ($(CPUNAME),X86_64)
$(eval $(call gb_Library_add_cxxflags,basebmp, \
-bigobj \
))
endif
endif
$(eval $(call gb_Library_add_exception_objects,basebmp,\
basebmp/source/bitmapdevice \
))
# vim: set noet sw=4 ts=4:
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
include $(module_directory)/../solenv/gbuild/partial_build.mk
# vim: set noet sw=4 ts=4:
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_Module_Module,basebmp))
ifeq ($(OS),ANDROID)
$(eval $(call gb_Module_add_targets,basebmp,\
StaticLibrary_basebmp \
))
else
$(eval $(call gb_Module_add_targets,basebmp,\
Library_basebmp \
))
endif
$(eval $(call gb_Module_add_check_targets,basebmp,\
CppunitTest_basebmp \
))
# vim: set noet sw=4 ts=4:
Provides a BitmapDevice: the vcl software renderer
Provides algorithms and data types for bitmap graphics e.g. line and fill
polygon scan conversion, bitmap format iterators, and a SalGraphics-compatible
software renderer
Used for example for wmf / svm files. E.g. used when you do --headless, and
have no DISPLAY set - it's an all-software backend for the LibO graphic
backend. also see [git:vcl/headless].
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_StaticLibrary_StaticLibrary,basebmp))
$(eval $(call gb_StaticLibrary_use_sdk_api,basebmp))
$(eval $(call gb_StaticLibrary_set_include,basebmp,\
-I$(SRCDIR)/basebmp/inc \
$$(INCLUDE) \
))
$(eval $(call gb_StaticLibrary_use_externals,basebmp,\
boost_headers \
vigra_headers \
))
$(eval $(call gb_StaticLibrary_use_libraries,basebmp,\
basegfx \
sal \
$(gb_UWINAPI) \
))
$(eval $(call gb_StaticLibrary_add_defs,basebmp,\
-DBASEBMP_DLLIMPLEMENTATION \
))
$(eval $(call gb_StaticLibrary_add_exception_objects,basebmp,\
basebmp/source/bitmapdevice \
))
# vim: set noet sw=4 ts=4:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_ACCESSOR_HXX
#define INCLUDED_BASEBMP_INC_ACCESSOR_HXX
#include <vigra/numerictraits.hxx>
namespace basebmp
{
/** Standard accessor type
Accesses the iterator values the standard way (i.e. via
*operator()/operator[])
*/
template<typename ValueType> class StandardAccessor
{
public:
typedef ValueType value_type;
template< class Iterator >
value_type operator()(Iterator const& i) const
{
return *i;
}
template< class Iterator, class Difference >
value_type operator()(Iterator const& i, Difference const& diff) const
{
return i[diff];
}
template< typename V, class Iterator >
void set(V const& value, Iterator const& i) const
{
*i = vigra::detail::RequiresExplicitCast<value_type>::cast(value);
}
};
/** Non-standard accessor type
Uses getter/setter methods at the given iterator type, to access
the underlying values.
*/
template<typename ValueType> class NonStandardAccessor
{
public:
typedef ValueType value_type;
template< class Iterator >
value_type operator()(Iterator const& i) const
{
return i.get();
}
template< class Iterator, class Difference >
value_type operator()(Iterator const& i, Difference const& diff) const
{
return i.get(diff);
}
template< typename V, class Iterator >
void set(V const& value, Iterator const& i) const
{
i.set( vigra::detail::RequiresExplicitCast<value_type>::cast(value) );
}
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_ACCESSOR_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_ACCESSORFUNCTORS_HXX
#define INCLUDED_BASEBMP_INC_ACCESSORFUNCTORS_HXX
#include <osl/diagnose.h>
#include <metafunctions.hxx>
#include <functional>
namespace basebmp
{
/// Base class, passing on the arg types
template< typename T, typename M > struct MaskFunctorBase :
public TernaryFunctorBase<T,M,T,T> {};
/** Let a mask flag decide between two values
@tpl polarity
Mask polarity. When true, a false in the mask denotes
transparency, i.e. the original value will display. And vice
versa.
*/
template< typename T,
typename M,
bool polarity > struct GenericOutputMaskFunctor : public MaskFunctorBase<T,M>
{
/// Ternary mask operation - selects v1 for !m == polarity, v2 otherwise
T operator()( T v1, M m, T v2 ) const
{
return !m == polarity ? v1 : v2;
}
};
/** Let a mask bit decide between two values (specialization for
integer mask types)
*/
template< typename T,
typename M,
bool polarity > struct IntegerOutputMaskFunctor;
template< typename T,
typename M > struct IntegerOutputMaskFunctor<T,M,true> : public MaskFunctorBase<T,M>
{
/** Mask v with state of m
@return v2, if m != 0, v1 otherwise.
*/
T operator()( T v1, M m, T v2 ) const
{
typedef typename make_unsigned<T>::type unsigned_T;
// mask will be 0, iff m == 0, and 1 otherwise
const T mask( unsigned_cast<T>(m | -m) >> (sizeof(unsigned_T)*8 - 1) );
return v1*static_cast<M>(1-mask) + v2*mask;
}
};
template< typename T,
typename M > struct IntegerOutputMaskFunctor<T,M,false> : public MaskFunctorBase<T,M>
{
/** Mask v with state of m
@return v2, if m != 0, v1 otherwise.
*/
T operator()( T v1, M m, T v2 ) const
{
typedef typename make_unsigned<T>::type unsigned_T;
// mask will be 0, iff m == 0, and 1 otherwise
const T mask( unsigned_cast<T>(m | -m) >> (sizeof(unsigned_T)*8 - 1) );
return v1*mask + v2*static_cast<M>(1-mask);
}
};
/** Let a mask bit decide between two values (specialization for
binary-valued mask types)
*/
template< typename T, typename M, bool polarity > struct FastIntegerOutputMaskFunctor;
template< typename T, typename M > struct FastIntegerOutputMaskFunctor<T,M,true> :
public MaskFunctorBase<T,M>
{
/// Specialization, only valid if mask can only attain 0 or 1
T operator()( T v1, M m, T v2 ) const
{
OSL_ASSERT(m<=1);
return v1*static_cast<M>(1-m) + v2*m;
}
};
template< typename T, typename M > struct FastIntegerOutputMaskFunctor<T,M,false> :
public MaskFunctorBase<T,M>
{
/// Specialization, only valid if mask can only attain 0 or 1
T operator()( T v1, M m, T v2 ) const
{
OSL_ASSERT(m<=1);
return v1*m + v2*static_cast<M>(1-m);
}
};
/** Split a pair value from a JoinImageAccessorAdapter into its
individual values, and pass it on to a ternary functor
This wrapper is an adaptable binary functor, and can thus be used
with a BinarySetterFunctionAccessorAdapter. Useful e.g. for
out-of-image alpha channel, or a masked image.
@tpl Functor
An adaptable ternary functor (as can e.g. be passed to the
TernarySetterFunctionAccessorAdapter)
*/
template< typename Functor > struct BinaryFunctorSplittingWrapper :
public std::binary_function<typename Functor::first_argument_type,
std::pair<typename Functor::third_argument_type,
typename Functor::second_argument_type>,
typename Functor::result_type>
{
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
// making all members public, if no member template friends
private:
template<class A> friend struct BinaryFunctorSplittingWrapper;
#endif
Functor maFunctor;
public:
BinaryFunctorSplittingWrapper() : maFunctor() {}
template< class A > explicit
BinaryFunctorSplittingWrapper(
BinaryFunctorSplittingWrapper<A> const& src ) : maFunctor(src.maFunctor) {}
template< class F > explicit
BinaryFunctorSplittingWrapper( F const& func ) : maFunctor(func) {}
typename Functor::result_type operator()(
typename Functor::first_argument_type v1,
std::pair< typename Functor::third_argument_type,
typename Functor::second_argument_type > const& v2 ) const
{
return maFunctor( v1, v2.second, v2.first );
}
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_ACCESSORFUNCTORS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_ACCESSORTRAITS_HXX
#define INCLUDED_BASEBMP_INC_ACCESSORTRAITS_HXX
#include <accessorfunctors.hxx>
#include <accessoradapters.hxx>
#include <metafunctions.hxx>
namespace basebmp
{
struct FastMask;
struct NoFastMask;
/// Metafunction to select output mask functor from iterator and mask value type
template< typename T, typename M, bool polarity, typename DUMMY > struct outputMaskFunctorSelector : public
ifBothScalarIntegral< T, M,
IntegerOutputMaskFunctor< T, M, polarity >,
GenericOutputMaskFunctor< T, M, polarity > >
{
};
template< typename T, typename M, bool polarity > struct outputMaskFunctorSelector< T, M, polarity, FastMask > : public
ifBothScalarIntegral< T, M,
FastIntegerOutputMaskFunctor< T, M, polarity >,
GenericOutputMaskFunctor< T, M, polarity > >
{
};
/** Metafunction providing a point of configuration for iterators
capable of employing the fast output mask functor.
Specialize this metafunction for your case, and pass FastMask to
the outputMaskFunctorSelector.
*/
template< class Accessor,
class MaskAccessor,
class Iterator,
class MaskIterator,
bool polarity > struct maskedAccessorSelector
{
typedef TernarySetterFunctionAccessorAdapter<
Accessor,
MaskAccessor,
typename outputMaskFunctorSelector<
typename Accessor::value_type,
typename MaskAccessor::value_type,
polarity,
NoFastMask > ::type >
type;
};
/// given an Accessor and its value type return its value_type
template< typename Accessor > struct ColorPassThrough
{
typename Accessor::value_type operator()( const Accessor&,
const typename Accessor::value_type& x ) const
{
return x;
}
};
/** Traits template for Accessor
Provides wrapped types for color lookup, raw pixel access, xor and
mask accessors.
*/
template< class Accessor > struct AccessorTraits
{
/// value type of described accessor
typedef typename Accessor::value_type value_type;
/// Retrieve stand-alone color lookup function for given Accessor type
typedef ColorPassThrough< Accessor > color_lookup;
/// Retrieve raw pixel data accessor for given Accessor type
typedef Accessor raw_accessor;
/** Retrieve masked accessor for given types
A masked accessor works like a filter, where the mask gates
the accessor's setter methods (if the mask contains a 0 at a
given iterator position, the original value is
preserved. Otherwise, the new value gets set).
@attention be careful when retrieving a masked accessor for a
set of types, and using it for a different one - there are
partial specializations that take an optimized functor for
certain mask accessors.
*/
template< class MaskAccessor,
class Iterator,
class MaskIterator,
bool polarity > struct masked_accessor :
public maskedAccessorSelector< Accessor,
MaskAccessor,
Iterator,
MaskIterator,
polarity >
{};
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_ACCESSORTRAITS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_COLORMISC_HXX
#define INCLUDED_BASEBMP_INC_COLORMISC_HXX
#include <osl/diagnose.h>
#include <basebmp/color.hxx>
#include <colortraits.hxx>
#include <accessortraits.hxx>
#include <vigra/mathutil.hxx>
// Contents of this header moved out of color.hxx, as it is not useful
// for the general public (drags in vigra and other template
// functionality, that shouldn't be necessary for the ordinary client
// of BitmapDevice etc.)
namespace basebmp
{
template< bool polarity > struct ColorBitmaskOutputMaskFunctor;
template<> struct ColorBitmaskOutputMaskFunctor<true> : MaskFunctorBase<Color,sal_uInt8>
{
Color operator()( Color v1, sal_uInt8 m, Color v2 ) const
{
OSL_ASSERT(m<=1);
return Color(v1.toInt32()*(sal_uInt8)(1-m) + v2.toInt32()*m);
}
};
template<> struct ColorBitmaskOutputMaskFunctor<false> : MaskFunctorBase<Color,sal_uInt8>
{
Color operator()( Color v1, sal_uInt8 m, Color v2 ) const
{
OSL_ASSERT(m<=1);
return Color(v1.toInt32()*m + v2.toInt32()*(sal_uInt8)(1-m));
}
};
/// Specialized output mask functor for Color value type
template<bool polarity> struct outputMaskFunctorSelector< Color, sal_uInt8, polarity, FastMask >
{
typedef ColorBitmaskOutputMaskFunctor<polarity> type;
};
template< bool polarity > struct ColorBlendFunctor8
: public TernaryFunctorBase<sal_uInt8,Color,Color,Color>
{
Color operator()( sal_uInt8 alpha,
Color v1,
Color v2 ) const
{
alpha = polarity ? alpha : 255 - alpha;
const sal_uInt8 v1_red( v1.getRed() );
const sal_uInt8 v1_green( v1.getGreen() );
const sal_uInt8 v1_blue( v1.getBlue() );
// using '>> 8' instead of '/ 0x100' is ill-advised (shifted
// value might be negative). Better rely on decent optimizer
// here...
return Color(((((sal_Int32)v2.getRed() - v1_red)*alpha) / 0x100) + v1_red,
((((sal_Int32)v2.getGreen() - v1_green)*alpha) / 0x100) + v1_green,
((((sal_Int32)v2.getBlue() - v1_blue)*alpha) / 0x100) + v1_blue);
}
};
template< bool polarity > struct ColorBlendFunctor32
: public TernaryFunctorBase<Color,Color,Color,Color>
{
Color operator()( Color input,
Color v1,
Color v2 ) const
{
sal_uInt8 alpha = input.getGreyscale();
alpha = polarity ? alpha : 255 - alpha;
const sal_uInt8 v1_red( v1.getRed() );
const sal_uInt8 v1_green( v1.getGreen() );
const sal_uInt8 v1_blue( v1.getBlue() );
// using '>> 8' instead of '/ 0x100' is ill-advised (shifted
// value might be negative). Better rely on decent optimizer
// here...
return Color(((((sal_Int32)v2.getRed() - v1_red)*alpha) / 0x100) + v1_red,
((((sal_Int32)v2.getGreen() - v1_green)*alpha) / 0x100) + v1_green,
((((sal_Int32)v2.getBlue() - v1_blue)*alpha) / 0x100) + v1_blue);
}
};
template<> struct ColorTraits< Color >
{
/// Type of a color component (i.e. the type of an individual channel)
typedef sal_uInt8 component_type;
/// Metafunction to select blend functor from color and alpha type
template< typename AlphaType, bool polarity > struct blend_functor;
/// Calculate normalized distance between color c1 and c2
static inline double distance( const Color& c1,
const Color& c2 )
{
return (c1 - c2).magnitude();
}
static inline component_type toGreyscale( const Color& c )
{
return c.getGreyscale();
}
static inline Color fromGreyscale( component_type c )
{
return Color(c,c,c);
}
};
/// The version for plain 8 bit alpha
template<bool polarity> struct ColorTraits< Color >::blend_functor< sal_uInt8, polarity >
{
typedef ColorBlendFunctor8<polarity> type;
};
/// The version taking grey value of a Color
template<bool polarity> struct ColorTraits< Color >::blend_functor< Color, polarity >
{
typedef ColorBlendFunctor32<polarity> type;
};
} // namespace basebmp
namespace vigra
{
template<>
struct NumericTraits<basebmp::Color>
{
typedef basebmp::Color Type;
typedef basebmp::Color Promote;
typedef basebmp::Color RealPromote;
typedef std::complex<basebmp::Color> ComplexPromote;
typedef sal_uInt8 ValueType;
typedef VigraTrueType isIntegral;
typedef VigraFalseType isScalar;
typedef VigraTrueType isSigned;
typedef VigraTrueType isOrdered;
typedef VigraFalseType isComplex;
};
} // namespace vigra
#endif /* INCLUDED_BASEBMP_INC_COLORMISC_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_COLORTRAITS_HXX
#define INCLUDED_BASEBMP_INC_COLORTRAITS_HXX
#include <accessoradapters.hxx>
#include <metafunctions.hxx>
#include <vigra/mathutil.hxx>
namespace basebmp
{
/** Functor template, to calculate alpha blending between two
values. Float case.
@tpl polarity
When true, 0 means fully transparent, and 1 fully opaque. And vice
versa.
*/
template< typename ValueType,
typename AlphaType,
bool polarity > struct BlendFunctor;
template< typename ValueType,
typename AlphaType > struct BlendFunctor<ValueType,AlphaType,true>
: public TernaryFunctorBase<AlphaType,ValueType,ValueType,ValueType>
{
ValueType operator()( AlphaType alpha,
ValueType v1,
ValueType v2 ) const
{
const typename vigra::NumericTraits<AlphaType>::RealPromote fAlpha(
vigra::NumericTraits<AlphaType>::toRealPromote(alpha));
return (vigra::NumericTraits<AlphaType>::one()-fAlpha)*v1 + fAlpha*v2;
}
};
template< typename ValueType,
typename AlphaType > struct BlendFunctor<ValueType,AlphaType,false>
: public TernaryFunctorBase<AlphaType,ValueType,ValueType,ValueType>
{
ValueType operator()( AlphaType alpha,
ValueType v1,
ValueType v2 ) const
{
const typename vigra::NumericTraits<AlphaType>::RealPromote fAlpha(
vigra::NumericTraits<AlphaType>::toRealPromote(alpha));
return fAlpha*v1 + (vigra::NumericTraits<AlphaType>::one()-fAlpha)*v2;
}
};
/** Functor template, to calculate alpha blending between two
values. Integer case.
@tpl polarity
When true, 0 means fully transparent, and 1 fully opaque. And vice
versa.
*/
template< typename ValueType,
typename AlphaType,
bool polarity > struct IntegerBlendFunctor;
template< typename ValueType,
typename AlphaType > struct IntegerBlendFunctor<ValueType,AlphaType,true>
: public TernaryFunctorBase<AlphaType,ValueType,ValueType,ValueType>
{
ValueType operator()( AlphaType alpha,
ValueType v1,
ValueType v2 ) const
{
return (vigra::NumericTraits<AlphaType>::toPromote(
vigra::NumericTraits<AlphaType>::max()-alpha)*v1 + alpha*v2) /
vigra::NumericTraits<AlphaType>::max();
}
};
template< typename ValueType,
typename AlphaType > struct IntegerBlendFunctor<ValueType,AlphaType,false>
: public TernaryFunctorBase<AlphaType,ValueType,ValueType,ValueType>
{
ValueType operator()( AlphaType alpha,
ValueType v1,
ValueType v2 ) const
{
return (alpha*v1 +
vigra::NumericTraits<AlphaType>::toPromote(
vigra::NumericTraits<AlphaType>::max()-alpha)*v2) /
vigra::NumericTraits<AlphaType>::max();
}
};
template< typename ColorType > struct ColorTraits
{
/// Metafunction to select blend functor from color and alpha type
template< typename AlphaType, bool polarity > struct blend_functor : public
ifScalarIntegral< AlphaType,
IntegerBlendFunctor< ColorType, AlphaType, polarity >,
BlendFunctor< ColorType, AlphaType, polarity > > {};
/// Type of a color component (i.e. the type of an individual channel)
typedef ColorType component_type;
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_COLORTRAITS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_ENDIAN_HXX
#define INCLUDED_BASEBMP_INC_ENDIAN_HXX
#include <osl/endian.h>
namespace basebmp
{
/// Swap the order of bytes for the given POD type
template< typename T > inline T byteSwap( T );
#define BASEBMP_BYTE_SWAP(Type,SwapFunc) \
template<> inline Type byteSwap<Type>( Type v ) \
{ \
return SwapFunc(v); \
}
// byteSwap<T> shall fail for any type T not in the list below
BASEBMP_BYTE_SWAP(sal_uInt16,OSL_SWAPWORD)
BASEBMP_BYTE_SWAP(sal_uInt32,OSL_SWAPDWORD)
#undef BASEBMP_BYTE_SWAP
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_ENDIAN_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_GENERICCOLORIMAGEACCESSOR_HXX
#define INCLUDED_BASEBMP_INC_GENERICCOLORIMAGEACCESSOR_HXX
#include <basebmp/color.hxx>
#include <basebmp/bitmapdevice.hxx>
namespace basebmp
{
/** Access a BitmapDevice generically
This accessor deals with an opaque BitmapDevice generically,
via getPixel()/setPixel() at the published interface.
*/
class GenericColorImageAccessor
{
BitmapDeviceSharedPtr mpDevice;
public:
typedef Color value_type;
explicit GenericColorImageAccessor( BitmapDeviceSharedPtr const& rTarget ) :
mpDevice(rTarget)
{}
template< typename Iterator >
Color operator()( Iterator const& i ) const
{ return mpDevice->getPixel( basegfx::B2IPoint( i->x,i->y ) ); }
template< typename Iterator, typename Difference >
Color operator()( Iterator const& i, Difference const& diff) const
{ return mpDevice->getPixel( basegfx::B2IPoint( i[diff]->x,
i[diff]->y ) ); }
};
}
#endif /* INCLUDED_BASEBMP_INC_GENERICCOLORIMAGEACCESSOR_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_GREYLEVELFORMATS_HXX
#define INCLUDED_BASEBMP_INC_GREYLEVELFORMATS_HXX
#include <basebmp/color.hxx>
#include <colortraits.hxx>
#include <accessor.hxx>
#include <pixeliterator.hxx>
#include <packedpixeliterator.hxx>
#include <pixelformatadapters.hxx>
#include <metafunctions.hxx>
#include <vigra/numerictraits.hxx>
#include <vigra/metaprogramming.hxx>
#include <functional>
namespace basebmp
{
template< typename PixelType,
typename ColorType,
int UsedRange > struct GreylevelGetter :
public std::unary_function<PixelType, ColorType>
{
ColorType operator()( PixelType const& c ) const
{
return ColorTraits<ColorType>::fromGreyscale(
vigra::NumericTraits<PixelType>::toPromote(c) *
vigra::NumericTraits<PixelType>::maxConst / UsedRange );
}
};
template< typename PixelType,
typename ColorType,
int UsedRange > struct GreylevelSetter :
public std::unary_function<ColorType, PixelType>
{
PixelType operator()( ColorType const& c ) const
{
return vigra::NumericTraits<PixelType>::toPromote(
ColorTraits<ColorType>::toGreyscale(c)) *
UsedRange /
vigra::NumericTraits<PixelType>::maxConst;
}
};
template< class Iterator,
class Accessor,
int UsedRange > struct PixelFormatTraitsTemplate_Greylevel
{
typedef typename Iterator::value_type pixel_type;
typedef GreylevelGetter<pixel_type,
Color,
UsedRange> getter_type;
typedef GreylevelSetter<pixel_type,
Color,
UsedRange> setter_type;
typedef Iterator iterator_type;
typedef Accessor raw_accessor_type;
typedef AccessorSelector<
getter_type,
setter_type > accessor_selector;
};
template< int BitsPerPixel,
bool MsbFirst > struct PixelFormatTraitsTemplate_PackedGreylevel :
public PixelFormatTraitsTemplate_Greylevel<
PackedPixelIterator< sal_uInt8,
BitsPerPixel,
true >,
NonStandardAccessor< sal_uInt8 >,
(1UL << BitsPerPixel)-1 >
{};
// 1bpp MSB
typedef PixelFormatTraitsTemplate_PackedGreylevel<1, true> PixelFormatTraits_GREY1_MSB;
// 1bpp LSB
typedef PixelFormatTraitsTemplate_PackedGreylevel<1, false> PixelFormatTraits_GREY1_LSB;
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY1_MSB::getter_type,
PixelFormatTraits_GREY1_MSB::setter_type);
// 4bpp MSB
typedef PixelFormatTraitsTemplate_PackedGreylevel<4, true> PixelFormatTraits_GREY4_MSB;
// 4bpp LSB
typedef PixelFormatTraitsTemplate_PackedGreylevel<4, false> PixelFormatTraits_GREY4_LSB;
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY4_MSB::getter_type,
PixelFormatTraits_GREY4_MSB::setter_type);
// 8bpp
typedef PixelFormatTraitsTemplate_Greylevel<
PixelIterator< sal_uInt8 >,
StandardAccessor< sal_uInt8 >,
255 > PixelFormatTraits_GREY8;
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_GREY8::getter_type,
PixelFormatTraits_GREY8::setter_type);
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_GREYLEVELFORMATS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_ITERATORTRAITS_HXX
#define INCLUDED_BASEBMP_INC_ITERATORTRAITS_HXX
#include <accessor.hxx>
#include <nonstandarditerator.hxx>
namespace basebmp
{
template< class Iterator > struct IteratorTraits
{
/// VigraTrueType, if iterator does not provide *operator()/operator[] methods
typedef typename vigra::IsDerivedFrom<Iterator,NonStandardIterator>::result
isNonStandardIterator;
/// Retrieve default accessor for this iterator (and given value type)
template< typename ValueType > struct defaultAccessor : public
// select according to non-standardness of iterator type
vigra::If< isNonStandardIterator,
NonStandardAccessor< ValueType >,
StandardAccessor< ValueType > >
{};
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_ITERATORTRAITS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_METAFUNCTIONS_HXX
#define INCLUDED_BASEBMP_INC_METAFUNCTIONS_HXX
#include <boost/mpl/integral_c.hpp>
#include <vigra/metaprogramming.hxx>
#include <vigra/numerictraits.hxx>
#include <functional>
#include <limits>
#include <type_traits>
namespace basebmp
{
// TODO(Q3): move to generic place (o3tl?)
/** template meta function: add const qualifier to 2nd type, if given
1st type has it
*/
template<typename A, typename B> struct clone_const
{
typedef B type;
};
template<typename A, typename B> struct clone_const<const A,B>
{
typedef const B type;
};
/** template meta function: add const qualifier to plain type (if not
already there)
*/
template <typename T> struct add_const
{
typedef const T type;
};
template <typename T> struct add_const<const T>
{
typedef const T type;
};
/// template meta function: remove const qualifier from plain type
template <typename T> struct remove_const
{
typedef T type;
};
template <typename T> struct remove_const<const T>
{
typedef T type;
};
/// Base class for an adaptable ternary functor
template< typename A1, typename A2, typename A3, typename R > struct TernaryFunctorBase
{
typedef A1 first_argument_type;
typedef A2 second_argument_type;
typedef A3 third_argument_type;
typedef R result_type;
};
/** template meta function: ensure that given integer type is unsigned
If given integer type is already unsigned, return as-is -
otherwise, convert to unsigned type of same or greater range.
*/
template< typename T > struct make_unsigned;
#define BASEBMP_MAKE_UNSIGNED(T,U) \
template<> struct make_unsigned<T> { \
typedef U type; \
};
BASEBMP_MAKE_UNSIGNED(signed char,unsigned char)
BASEBMP_MAKE_UNSIGNED(unsigned char,unsigned char)
BASEBMP_MAKE_UNSIGNED(short,unsigned short)
BASEBMP_MAKE_UNSIGNED(unsigned short,unsigned short)
BASEBMP_MAKE_UNSIGNED(int,unsigned int)
BASEBMP_MAKE_UNSIGNED(unsigned int,unsigned int)
BASEBMP_MAKE_UNSIGNED(long,unsigned long)
BASEBMP_MAKE_UNSIGNED(unsigned long,unsigned long)
#undef BASEBMP_MAKE_UNSIGNED
/// cast integer to unsigned type of similar size
template< typename T > inline typename make_unsigned<T>::type unsigned_cast( T value )
{
return static_cast< typename make_unsigned<T>::type >(value);
}
/// returns true, if given number is strictly less than 0
template< typename T > inline bool is_negative( T x )
{
return x < 0;
}
/// Overload for ints (branch-free)
inline bool is_negative( int x )
{
// force logic shift (result for signed shift right is undefined)
return static_cast<unsigned int>(x) >> (sizeof(int)*8-1);
}
/// Results in VigraTrueType, if T is of integer type and scalar
template< typename T, typename trueCase, typename falseCase >
struct ifScalarIntegral
{
typedef
typename vigra::If<
typename vigra::NumericTraits< T >::isIntegral,
typename vigra::If<
typename vigra::NumericTraits< T >::isScalar,
trueCase,
falseCase >::type,
falseCase >::type type;
};
/// Results in VigraTrueType, if T is of non-integer type and scalar
template< typename T, typename trueCase, typename falseCase >
struct ifScalarNonIntegral
{
typedef
typename vigra::If<
typename vigra::NumericTraits< T >::isIntegral,
falseCase,
typename vigra::If<
typename vigra::NumericTraits< T >::isScalar,
trueCase,
falseCase >::type >::type type;
};
/// Results in VigraTrueType, if both T1 and T2 are of integer type and scalar
template< typename T1, typename T2, typename trueCase, typename falseCase >
struct ifBothScalarIntegral
{
typedef
typename ifScalarIntegral<
T1,
typename ifScalarIntegral<
T2,
trueCase,
falseCase >::type,
falseCase >::type type;
};
/// Count number of trailing zeros
template< unsigned int val > struct numberOfTrailingZeros
{
enum { next = val >> 1 };
enum { value = vigra::IfBool< (val & 1) == 0,
numberOfTrailingZeros<next>,
boost::mpl::integral_c< int,-1 > > ::type::value + 1 };
};
template<> struct numberOfTrailingZeros<0>
{
enum { value = 0 };
};
/// Count number of one bits
template< unsigned int val > struct bitcount
{
enum { next = val >> 1 };
enum { value = bitcount<next>::value + (val & 1) };
};
template<> struct bitcount<0>
{
enum { value = 0 };
};
/// Shift left for positive shift value, and right otherwise
template< typename T > inline T shiftLeft( T v, int shift )
{
return shift > 0 ? v << shift : v >> (-shift);
}
/// Shift right for positive shift value, and left otherwise
template< typename T > inline T shiftRight( T v, int shift )
{
// Avoid undefined behavior and only shift by less than the length in bits
// of the promoted left operand:
static_assert(
std::is_unsigned<T>::value,
"must be unsigned for promotedBits and the below ': 0' to be correct");
using Promoted = decltype(+T());
auto const promotedBits = std::numeric_limits<Promoted>::digits;
return shift >= 0
? shift < promotedBits ? Promoted(v) >> shift : 0
: -shift < promotedBits ? Promoted(v) << (-shift) : 0;
}
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_METAFUNCTIONS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_NONSTANDARDITERATOR_HXX
#define INCLUDED_BASEBMP_INC_NONSTANDARDITERATOR_HXX
#include <vigra/metaprogramming.hxx>
namespace basebmp
{
/// Base class defining pointer and reference types as VigraFalseType
struct NonStandardIterator
{
typedef vigra::VigraFalseType reference;
typedef vigra::VigraFalseType index_reference;
typedef vigra::VigraFalseType pointer;
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_NONSTANDARDITERATOR_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_PALETTEFORMATS_HXX
#define INCLUDED_BASEBMP_INC_PALETTEFORMATS_HXX
#include <basebmp/color.hxx>
#include <colortraits.hxx>
#include <accessor.hxx>
#include <pixeliterator.hxx>
#include <packedpixeliterator.hxx>
#include <pixelformatadapters.hxx>
#include <paletteimageaccessor.hxx>
#include <metafunctions.hxx>
#include <vigra/numerictraits.hxx>
#include <vigra/metaprogramming.hxx>
namespace basebmp
{
/** Lookup index value for given color value in a PaletteImageAccessor
*/
template< class Accessor > struct ColorLookup
{
typename Accessor::data_type operator()( const Accessor& acc,
typename Accessor::value_type v ) const
{
return acc.lookup(v);
}
};
// partial specialization of AccessorTraits for PaletteAccessor
template< class Accessor, typename ColorType > struct AccessorTraits<
PaletteImageAccessor< Accessor, ColorType > >
{
/// value type of described accessor
typedef typename PaletteImageAccessor< Accessor, ColorType >::value_type value_type;
/// Retrieve stand-alone color lookup function for given Accessor type
typedef ColorLookup< PaletteImageAccessor< Accessor, ColorType > > color_lookup;
/// Retrieve raw pixel data accessor for given Accessor type
typedef Accessor raw_accessor;
/** accessor for masked setter access is disabled, since the
* results are usually completely unintended - you'll usually
* want to wrap a masked_accessor with a PaletteAccessor, not the
* other way around.
*/
template< class MaskAccessor,
class Iterator,
class MaskIterator > struct masked_accessor
{
typedef vigra::VigraFalseType type;
};
};
template< typename ColorType > struct PaletteAccessorSelector
{
template< class Accessor > struct wrap_accessor
{
typedef PaletteImageAccessor< Accessor, ColorType > type;
};
};
template< class Iterator,
class Accessor > struct PixelFormatTraitsTemplate_Palette
{
typedef typename Iterator::value_type pixel_type;
typedef Iterator iterator_type;
typedef Accessor raw_accessor_type;
typedef PaletteAccessorSelector<Color> accessor_selector;
};
template< int BitsPerPixel,
bool MsbFirst > struct PixelFormatTraitsTemplate_PackedPalette :
public PixelFormatTraitsTemplate_Palette<
PackedPixelIterator< sal_uInt8,
BitsPerPixel,
MsbFirst >,
NonStandardAccessor< sal_uInt8 > >
{};
// 1bpp MSB
typedef PixelFormatTraitsTemplate_PackedPalette<1, true> PixelFormatTraits_PAL1_MSB;
// 1bpp LSB
typedef PixelFormatTraitsTemplate_PackedPalette<1, false> PixelFormatTraits_PAL1_LSB;
// 4bpp MSB
typedef PixelFormatTraitsTemplate_PackedPalette<4, true> PixelFormatTraits_PAL4_MSB;
// 4bpp LSB
typedef PixelFormatTraitsTemplate_PackedPalette<4, false> PixelFormatTraits_PAL4_LSB;
// 8bpp
typedef PixelFormatTraitsTemplate_Palette<
PixelIterator< sal_uInt8 >,
StandardAccessor< sal_uInt8 > > PixelFormatTraits_PAL8;
} // namespace basebmp
#endif // INCLUDED_BASEBMP_INC_PALETTEFORMATS_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_PALETTEIMAGEACCESSOR_HXX
#define INCLUDED_BASEBMP_INC_PALETTEIMAGEACCESSOR_HXX
#include <colortraits.hxx>
#include <accessortraits.hxx>
#include <vigra/numerictraits.hxx>
#include <vigra/metaprogramming.hxx>
#include <algorithm>
#include <functional>
namespace basebmp
{
/** Access pixel data via palette indirection
@tpl Accessor
Raw accessor, to be used to actually access the pixel values
@tpl ColorType
The color value type to use - e.g. the palette is an array of that
type
*/
template< class Accessor, typename ColorType > class PaletteImageAccessor
{
public:
typedef typename Accessor::value_type data_type;
typedef ColorType value_type;
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
// making all members public, if no member template friends
private:
template<class A, typename C> friend class PaletteImageAccessor;
#endif
Accessor maAccessor;
const value_type* mpPalette;
std::size_t mnNumEntries;
public:
PaletteImageAccessor() :
maAccessor(),
mpPalette(0),
mnNumEntries(0)
{}
template< class A > explicit
PaletteImageAccessor( PaletteImageAccessor<A,ColorType> const& rSrc ) :
maAccessor( rSrc.maAccessor ),
mpPalette( rSrc.mpPalette ),
mnNumEntries( rSrc.mnNumEntries )
{}
PaletteImageAccessor( const value_type* pPalette,
std::size_t numEntries ) :
maAccessor(),
mpPalette(pPalette),
mnNumEntries(numEntries)
{}
template< class T > PaletteImageAccessor( T accessor,
const value_type* pPalette,
std::size_t numEntries ) :
maAccessor(accessor),
mpPalette(pPalette),
mnNumEntries(numEntries)
{}
data_type lookup(value_type const& v) const
{
// TODO(P3): use table-based/octree approach here!
const value_type* best_entry;
const value_type* palette_end( mpPalette+mnNumEntries );
if( (best_entry=std::find( mpPalette, palette_end, v)) != palette_end )
return best_entry-mpPalette;
const value_type* curr_entry( mpPalette );
best_entry = curr_entry;
while( curr_entry != palette_end )
{
if( ColorTraits<value_type>::distance(*curr_entry,
*best_entry)
> ColorTraits<value_type>::distance(*curr_entry,
v) )
{
best_entry = curr_entry;
}
++curr_entry;
}
return best_entry-mpPalette;
}
template< class Iterator >
value_type operator()(Iterator const& i) const
{
return mpPalette[ maAccessor(i) ];
}
template< class Iterator, class Difference >
value_type operator()(Iterator const& i, Difference const& diff) const
{
return mpPalette[ maAccessor(i,diff) ];
}
template< typename V, class Iterator >
void set(V const& value, Iterator const& i) const
{
maAccessor.set(
lookup(
vigra::detail::RequiresExplicitCast<value_type>::cast(value) ),
i );
}
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_PALETTEIMAGEACCESSOR_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_PIXELFORMATADAPTERS_HXX
#define INCLUDED_BASEBMP_INC_PIXELFORMATADAPTERS_HXX
#include <accessortraits.hxx>
#include <accessoradapters.hxx>
#include <vigra/metaprogramming.hxx>
namespace basebmp
{
// convenience functionality, providing everything necessary for a new
// pixel format. simply plug in two conversion functors from/to a
// common color format.
/** Accessor selection metafunction, used to wrap a given accessor
with one converting between the pixel and color types
Use the nested template's typedef type, to retrieve an
AccessorAdapter which operates on a pixel value accessor, and
provides color values to the outside.
Nested like this, to avoid template template parameters at other
places: an instantiated version of AccessorSelector can be passed
to other templates, which in turn can invoke the nested meta
function.
*/
template< typename Getter,
typename Setter > struct AccessorSelector
{
template< typename Accessor > struct wrap_accessor
{
typedef UnaryFunctionAccessorAdapter< Accessor,
Getter,
Setter > type;
};
};
/** Convert color value to pixel data type
*/
template< class Accessor, typename DataType > struct ColorConvert
{
DataType operator()( const Accessor& acc,
typename Accessor::value_type v ) const
{
return acc.setter(v);
}
};
/** Macro generates partial specialization for color-conversion
UnaryFunctionAccessorAdapter, and the given getter/setter functors
*/
#define BASEBMP_SPECIALIZE_ACCESSORTRAITS(Getter,Setter) \
template< class Accessor > struct AccessorTraits< \
UnaryFunctionAccessorAdapter< Accessor, \
Getter, \
Setter > > \
{ \
typedef typename Accessor::value_type data_type; \
typedef UnaryFunctionAccessorAdapter< \
Accessor, \
Getter, \
Setter > accessor_type; \
typedef typename accessor_type::value_type value_type; \
typedef ColorConvert< accessor_type, \
data_type > color_lookup; \
typedef Accessor raw_accessor; \
template< class MaskAccessor, \
class Iterator, \
class MaskIterator > struct masked_accessor\
{ typedef vigra::VigraFalseType type; }; \
}
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_PIXELFORMATADAPTERS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_PIXELITERATOR_HXX
#define INCLUDED_BASEBMP_INC_PIXELITERATOR_HXX
#include <metafunctions.hxx>
#include <stridedarrayiterator.hxx>
#include <vigra/metaprogramming.hxx>
#include <vigra/diff2d.hxx>
namespace basebmp
{
template< typename Valuetype > class PixelColumnIterator
{
public:
typedef Valuetype value_type;
typedef Valuetype& reference;
typedef reference index_reference;
typedef Valuetype* pointer;
typedef int difference_type;
typedef image_traverser_tag iterator_category;
typedef StridedArrayIterator< value_type > MoveY;
private:
MoveY y;
bool equal( PixelColumnIterator const & rhs ) const
{
return rhs.y == y;
}
bool less( PixelColumnIterator const & rhs ) const
{
return y < rhs.y;
}
public:
PixelColumnIterator() :
y(0)
{}
explicit PixelColumnIterator( const MoveY& pos ) :
y(pos)
{}
PixelColumnIterator( const MoveY& pos, int x ) :
y(pos,x)
{}
PixelColumnIterator& operator+=( difference_type d )
{
y += d;
return *this;
}
PixelColumnIterator& operator-=( difference_type d )
{
y -= d;
return *this;
}
PixelColumnIterator operator+( difference_type d )
{
PixelColumnIterator res(*this);
res += d;
return res;
}
PixelColumnIterator operator-( difference_type d )
{
PixelColumnIterator res(*this);
res -= d;
return res;
}
PixelColumnIterator& operator++()
{
++y;
return *this;
}
PixelColumnIterator& operator--()
{
--y;
return *this;
}
PixelColumnIterator operator++(int)
{
PixelColumnIterator res(*this);
++y;
return res;
}
PixelColumnIterator operator--(int)
{
PixelColumnIterator res(*this);
--y;
return res;
}
bool operator==(PixelColumnIterator const & rhs) const
{
return equal( rhs );
}
bool operator!=(PixelColumnIterator const & rhs) const
{
return !equal( rhs );
}
bool operator<(PixelColumnIterator const & rhs) const
{
return less(rhs);
}
bool operator<=(PixelColumnIterator const & rhs) const
{
return !rhs.less(*this);
}
bool operator>(PixelColumnIterator const & rhs) const
{
return rhs.less(*this);
}
bool operator>=(PixelColumnIterator const & rhs) const
{
return !less(rhs);
}
difference_type operator-(PixelColumnIterator const & rhs) const
{
return y - rhs.y;
}
reference operator*() const
{
return *y();
}
pointer operator->() const
{
return y();
}
reference operator[](difference_type d) const
{
return *y(d);
}
reference operator()(int dy) const
{
return *y(dy);
}
};
template< typename Valuetype > class PixelIterator
{
public:
typedef Valuetype value_type;
typedef Valuetype& reference;
typedef reference index_reference;
typedef Valuetype* pointer;
typedef vigra::Diff2D difference_type;
typedef image_traverser_tag iterator_category;
typedef pointer row_iterator;
typedef PixelColumnIterator<value_type> column_iterator;
typedef int MoveX;
typedef StridedArrayIterator< value_type > MoveY;
// TODO(F2): direction of iteration (ImageIterator can be made to
// run backwards)
private:
bool equal(PixelIterator const & rhs) const
{
return (x == rhs.x) && (y == rhs.y);
}
pointer current() const
{
return y() + x;
}
public:
PixelIterator() :
x(0),
y(0)
{}
PixelIterator(pointer base, int ystride) :
x(0),
y(ystride,base)
{}
bool operator==(PixelIterator const & rhs) const
{
return equal(rhs);
}
bool operator!=(PixelIterator const & rhs) const
{
return !equal(rhs);
}
difference_type operator-(PixelIterator const & rhs) const
{
return difference_type(x - rhs.x, y - rhs.y);
}
MoveX x;
MoveY y;
PixelIterator & operator+=(difference_type const & s)
{
x += s.x;
y += s.y;
return *this;
}
PixelIterator & operator-=(difference_type const & s)
{
x -= s.x;
y -= s.y;
return *this;
}
PixelIterator operator+(difference_type const & s) const
{
PixelIterator ret(*this);
ret += s;
return ret;
}
PixelIterator operator-(difference_type const & s) const
{
PixelIterator ret(*this);
ret -= s;
return ret;
}
row_iterator rowIterator() const
{
return row_iterator(y()+x);
}
column_iterator columnIterator() const
{
return column_iterator(y,x);
}
reference operator*() const
{
return *current();
}
pointer operator->() const
{
return current();
}
reference operator[]( const vigra::Diff2D& d ) const
{
return *current(d.x,d.y);
}
reference operator()(int dx, int dy) const
{
return *current(dx,dy);
}
pointer operator[](int dy) const
{
return y(dy) + x;
}
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_PIXELITERATOR_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_RGB24PIXELFORMATS_HXX
#define INCLUDED_BASEBMP_INC_RGB24PIXELFORMATS_HXX
#include <basebmp/color.hxx>
#include <accessor.hxx>
#include <pixeliterator.hxx>
#include <pixelformatadapters.hxx>
#include <vigra/rgbvalue.hxx>
#include <functional>
namespace basebmp
{
template< typename PixelType, typename ColorType > struct RGBValueGetter :
public std::unary_function<PixelType, ColorType>
{
ColorType operator()( PixelType const& c ) const
{
return ColorType(c.red(),c.green(),c.blue());
}
};
template< typename PixelType, typename ColorType > struct RGBValueSetter :
public std::unary_function<ColorType, PixelType>
{
PixelType operator()( ColorType const& c ) const
{
PixelType res;
res.setRed(c.getRed());
res.setGreen(c.getGreen());
res.setBlue(c.getBlue());
return res;
}
};
template< typename PixelType > struct PixelFormatTraitsTemplate_RGBValue
{
typedef PixelType pixel_type;
typedef RGBValueGetter<pixel_type,
Color> getter_type;
typedef RGBValueSetter<pixel_type,
Color> setter_type;
typedef PixelIterator<pixel_type> iterator_type;
typedef StandardAccessor<pixel_type> raw_accessor_type;
typedef AccessorSelector<
getter_type, setter_type> accessor_selector;
};
// 24bpp RGB
typedef PixelFormatTraitsTemplate_RGBValue<
vigra::RGBValue<sal_uInt8> > PixelFormatTraits_RGB24;
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB24::getter_type,
PixelFormatTraits_RGB24::setter_type);
// 24bpp BGR
typedef PixelFormatTraitsTemplate_RGBValue<
vigra::RGBValue<sal_uInt8,2,1,0> > PixelFormatTraits_BGR24;
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_BGR24::getter_type,
PixelFormatTraits_BGR24::setter_type);
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_RGB24PIXELFORMATS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_STRIDEDARRAYITERATOR_HXX
#define INCLUDED_BASEBMP_INC_STRIDEDARRAYITERATOR_HXX
#include <metafunctions.hxx>
namespace basebmp
{
/** Like vigra::StridedArrayIterator
Changed semantics re. DirectionSelector<StridedArrayTag>: stride
now counts in <em>raw</em> bytes
Adapts given ptr, in a way that iterator increments move forward
in strided steps. Stride can, by the way, also be negative
*/
template< typename T > class StridedArrayIterator
{
public:
typedef typename clone_const<T, unsigned char>::type internal_type;
/** Create iterator
@param stride
Stride in bytes. Given value should better match memory layout
of T, as memory gets reinterpret-casted.
*/
explicit StridedArrayIterator(int stride, T* ptr = 0) :
stride_(stride),
current_(reinterpret_cast<internal_type*>(ptr))
{}
/** Copy from other StridedArrayIterator, plus given offset
@param offset
Offset in bytes
*/
StridedArrayIterator( StridedArrayIterator const& rSrc,
int offset ) :
stride_(rSrc.stride_),
current_(reinterpret_cast<internal_type*>(
reinterpret_cast<T*>(rSrc.current_)+offset))
{}
void operator++() {current_ += stride_; }
void operator++(int) {current_ += stride_; }
void operator--() {current_ -= stride_; }
void operator--(int) {current_ -= stride_; }
void operator+=(int dy) {current_ += dy*stride_; }
void operator-=(int dy) {current_ -= dy*stride_; }
int operator-(StridedArrayIterator const & rhs) const
{ return (current_ - rhs.current_) / stride_; }
bool operator==(StridedArrayIterator const & rhs) const
{ return current_ == rhs.current_; }
bool operator!=(StridedArrayIterator const & rhs) const
{ return current_ != rhs.current_; }
bool operator<(StridedArrayIterator const & rhs) const
{ return *this - rhs < 0; }
bool operator<=(StridedArrayIterator const & rhs) const
{ return *this - rhs <= 0; }
bool operator>(StridedArrayIterator const & rhs) const
{ return *this - rhs > 0; }
bool operator>=(StridedArrayIterator const & rhs) const
{ return *this - rhs >= 0; }
T* operator()() const
{ return reinterpret_cast<T*>(current_); }
T* operator()(int d) const
{ return reinterpret_cast<T*>(current_ + d*stride_); }
private:
int stride_;
internal_type* current_;
};
} // namespace basebmp
#endif /* INCLUDED_BASEBMP_INC_STRIDEDARRAYITERATOR_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_INC_TOOLS_HXX
#define INCLUDED_BASEBMP_INC_TOOLS_HXX
#include <basegfx/range/b2ibox.hxx>
#include <basegfx/point/b2ipoint.hxx>
#include <vigra/tuple.hxx>
#include <vigra/diff2d.hxx>
namespace basebmp
{
inline vigra::Diff2D topLeft( const basegfx::B2IBox& rRange )
{ return vigra::Diff2D(rRange.getMinX(),rRange.getMinY()); }
inline vigra::Diff2D bottomRight( const basegfx::B2IBox& rRange )
{ return vigra::Diff2D(rRange.getMaxX(),rRange.getMaxY()); }
template< class Iterator, class Accessor >
inline vigra::triple<Iterator,Iterator,Accessor>
destIterRange(Iterator const& begin,
Accessor const& accessor,
const basegfx::B2IBox& rRange)
{
return vigra::triple<Iterator,Iterator,Accessor>(
begin + topLeft(rRange),
begin + bottomRight(rRange),
accessor);
}
template< class Iterator, class Accessor >
inline vigra::triple<Iterator,Iterator,Accessor>
srcIterRange(Iterator const& begin,
Accessor const& accessor,
const basegfx::B2IBox& rRange)
{
return vigra::triple<Iterator,Iterator,Accessor>(
begin + topLeft(rRange),
begin + bottomRight(rRange),
accessor);
}
template< class Iterator, class Accessor >
inline vigra::pair<Iterator,Accessor>
destIter(Iterator const& begin,
Accessor const& accessor,
const basegfx::B2IPoint& rPt)
{
return vigra::pair<Iterator,Accessor>(
begin + vigra::Diff2D(rPt.getX(),rPt.getY()),
accessor);
}
}
#endif /* INCLUDED_BASEBMP_INC_TOOLS_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include <iomanip>
#include <ios>
#include <ostream>
#include <type_traits>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <basegfx/vector/b2isize.hxx>
#include <basegfx/point/b2ipoint.hxx>
#include <basebmp/color.hxx>
#include <basebmp/scanlineformats.hxx>
#include <basebmp/bitmapdevice.hxx>
#include "tools.hxx"
using namespace ::basebmp;
namespace basebmp {
template<typename charT, typename traits>
std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, Color const & value)
{
auto f = stream.flags();
return stream
<< std::hex << std::uppercase << std::setw(8) << std::setfill('0')
<< value.toInt32() << std::setiosflags(f);
}
template<typename charT, typename traits>
std::basic_ostream<charT, traits> & operator <<(
std::basic_ostream<charT, traits> & stream, Format value)
{
return stream
<< static_cast<typename std::underlying_type<Format>::type>(value);
}
}
namespace
{
class BasicTest : public CppUnit::TestFixture
{
public:
void colorTest()
{
Color aTestColor;
aTestColor = Color(0xDEADBEEF);
CPPUNIT_ASSERT_EQUAL_MESSAGE("unary constructor",
sal_uInt32(0xDEADBEEF), aTestColor.toInt32() );
aTestColor = Color( 0x10, 0x20, 0xFF );
CPPUNIT_ASSERT_EQUAL_MESSAGE("ternary constructor",
sal_uInt32(0x001020FF), aTestColor.toInt32() );
aTestColor.setRed( 0x0F );
CPPUNIT_ASSERT_EQUAL_MESSAGE("setRed()",
sal_uInt32(0x00F20FF), aTestColor.toInt32() );
aTestColor.setGreen( 0x0F );
CPPUNIT_ASSERT_EQUAL_MESSAGE("setGreen()",
sal_uInt32(0x00F0FFF), aTestColor.toInt32() );
aTestColor.setBlue( 0x10 );
CPPUNIT_ASSERT_EQUAL_MESSAGE("setBlue()",
sal_uInt32(0x00F0F10), aTestColor.toInt32() );
aTestColor.setGrey( 0x13 );
CPPUNIT_ASSERT_EQUAL_MESSAGE("setGrey()",
sal_uInt32(0x00131313), aTestColor.toInt32() );
aTestColor = Color( 0x10, 0x20, 0xFF );
CPPUNIT_ASSERT_EQUAL_MESSAGE("getRed()",
sal_uInt8(0x10), aTestColor.getRed() );
CPPUNIT_ASSERT_EQUAL_MESSAGE("getGreen()",
sal_uInt8(0x20), aTestColor.getGreen() );
CPPUNIT_ASSERT_EQUAL_MESSAGE("getBlue()",
sal_uInt8(0xFF), aTestColor.getBlue() );
}
void testConstruction()
{
const basegfx::B2ISize aSize(101,101);
basegfx::B2ISize aSize2(aSize);
BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
Format::OneBitMsbPal ) );
CPPUNIT_ASSERT_EQUAL_MESSAGE("right size",
aSize2, pDevice->getSize() );
CPPUNIT_ASSERT_EQUAL_MESSAGE("Scanline format",
Format::OneBitMsbPal, pDevice->getScanlineFormat() );
sal_Int32 nExpectedStride = (aSize2.getY() + 7)/8;
sal_Int32 nAlign = sizeof(sal_uInt32);
nExpectedStride = ((nExpectedStride + nAlign-1) / nAlign) * nAlign;
CPPUNIT_ASSERT_EQUAL_MESSAGE("Scanline len",
nExpectedStride, pDevice->getScanlineStride() );
CPPUNIT_ASSERT_MESSAGE("Palette existence",
pDevice->getPalette() );
CPPUNIT_ASSERT_EQUAL_MESSAGE("Palette entry 0 is black",
Color(0), (*pDevice->getPalette())[0] );
CPPUNIT_ASSERT_EQUAL_MESSAGE("Palette entry 1 is white",
Color(0xFFFFFFFF), (*pDevice->getPalette())[1] );
}
void testClone()
{
const basegfx::B2ISize aSize(101,101);
BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
Format::OneBitMsbPal ) );
BitmapDeviceSharedPtr pClone( cloneBitmapDevice(
pDevice ));
CPPUNIT_ASSERT_EQUAL_MESSAGE("right size",
aSize, pClone->getSize() );
}
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
// because these macros are need by auto register mechanism.
CPPUNIT_TEST_SUITE(BasicTest);
CPPUNIT_TEST(colorTest);
CPPUNIT_TEST(testConstruction);
CPPUNIT_TEST(testClone);
CPPUNIT_TEST_SUITE_END();
};
CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// autogenerated file with codegen.pl
#include <basegfx/vector/b2isize.hxx>
#include <basegfx/point/b2ipoint.hxx>
#include <basebmp/color.hxx>
#include <basebmp/bitmapdevice.hxx>
#include <tools.hxx>
using namespace ::basebmp;
int countPixel( const BitmapDeviceSharedPtr& rDevice,
Color checkColor )
{
int count(0);
const basegfx::B2ISize& rSize( rDevice->getSize() );
for( sal_Int32 y=0; y<rSize.getY(); ++y )
for( sal_Int32 x=0; x<rSize.getX(); ++x )
if( rDevice->getPixel( basegfx::B2IPoint(x,y) ) == checkColor )
++count;
return count;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASEBMP_TEST_TOOLS_HXX
#define INCLUDED_BASEBMP_TEST_TOOLS_HXX
#include <basebmp/bitmapdevice.hxx>
int countPixel( const basebmp::BitmapDeviceSharedPtr& rDevice,
basebmp::Color checkColor );
#endif // INCLUDED_BASEBMP_TEST_TOOLS_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment