drop basebmp entirely now
Change-Id: I534848c4be8eadf86b7f31ac742a80982405f56f
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
# -*- 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:
|
||||
@@ -1,53 +0,0 @@
|
||||
# -*- 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:
|
||||
@@ -1,14 +0,0 @@
|
||||
# -*- 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:
|
||||
@@ -1,26 +0,0 @@
|
||||
# -*- 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:
|
||||
@@ -1,9 +0,0 @@
|
||||
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].
|
||||
@@ -1,38 +0,0 @@
|
||||
# -*- 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:
|
||||
@@ -1,102 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,416 +0,0 @@
|
||||
/* -*- 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_ACCESSORADAPTERS_HXX
|
||||
#define INCLUDED_BASEBMP_INC_ACCESSORADAPTERS_HXX
|
||||
|
||||
#include <vigra/numerictraits.hxx>
|
||||
|
||||
namespace basebmp
|
||||
{
|
||||
|
||||
/** Interpose given accessor's set and get methods with two unary
|
||||
functors.
|
||||
|
||||
@tpl WrappedAccessor
|
||||
Wrapped type must provide the usual get and set accessor methods,
|
||||
with the usual signatures (see StandardAccessor for a conforming
|
||||
example).
|
||||
|
||||
@tpl GetterFunctor
|
||||
An Adaptable Unary Function (i.e. providing result_type and
|
||||
argument_type typedefs)
|
||||
|
||||
@tpl SetterFunctor
|
||||
An Adaptable Unary Function (i.e. providing result_type and
|
||||
argument_type typedefs)
|
||||
*/
|
||||
template< class WrappedAccessor,
|
||||
typename GetterFunctor,
|
||||
typename SetterFunctor > class UnaryFunctionAccessorAdapter
|
||||
{
|
||||
public:
|
||||
typedef typename GetterFunctor::result_type value_type;
|
||||
typedef typename SetterFunctor::argument_type argument_type;
|
||||
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
// making all members public, if no member template friends
|
||||
private:
|
||||
template<class A, typename G, typename S> friend class UnaryFunctionAccessorAdapter;
|
||||
#endif
|
||||
|
||||
// we don't derive from wrapped type, to avoid ambiguities
|
||||
// regarding templatized getter/setter methods.
|
||||
WrappedAccessor maAccessor;
|
||||
GetterFunctor maGetterFunctor;
|
||||
SetterFunctor maSetterFunctor;
|
||||
|
||||
public:
|
||||
UnaryFunctionAccessorAdapter() :
|
||||
maAccessor(),
|
||||
maGetterFunctor(),
|
||||
maSetterFunctor()
|
||||
{}
|
||||
|
||||
template< class A > explicit
|
||||
UnaryFunctionAccessorAdapter( UnaryFunctionAccessorAdapter< A,
|
||||
GetterFunctor,
|
||||
SetterFunctor > const& rSrc ) :
|
||||
maAccessor( rSrc.maAccessor ),
|
||||
maGetterFunctor( rSrc.maGetterFunctor ),
|
||||
maSetterFunctor( rSrc.maSetterFunctor )
|
||||
{}
|
||||
|
||||
template< class T > explicit UnaryFunctionAccessorAdapter( T const& accessor ) :
|
||||
maAccessor( accessor ),
|
||||
maGetterFunctor(),
|
||||
maSetterFunctor()
|
||||
{}
|
||||
|
||||
template< class T > UnaryFunctionAccessorAdapter( T accessor,
|
||||
GetterFunctor getterFunctor,
|
||||
SetterFunctor setterFunctor) :
|
||||
maAccessor( accessor ),
|
||||
maGetterFunctor( getterFunctor ),
|
||||
maSetterFunctor( setterFunctor )
|
||||
{}
|
||||
|
||||
|
||||
typename SetterFunctor::result_type setter(argument_type v) const
|
||||
{
|
||||
return maSetterFunctor(v);
|
||||
}
|
||||
|
||||
template< class Iterator >
|
||||
value_type operator()(Iterator const& i) const
|
||||
{
|
||||
return maGetterFunctor( maAccessor(i) );
|
||||
}
|
||||
|
||||
template< class Iterator, class Difference >
|
||||
value_type operator()(Iterator const& i, Difference const& diff) const
|
||||
{
|
||||
return maGetterFunctor( maAccessor(i,diff) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
template< typename V, class Iterator >
|
||||
void set(V const& value, Iterator const& i) const
|
||||
{
|
||||
maAccessor.set(
|
||||
maSetterFunctor(
|
||||
vigra::detail::RequiresExplicitCast<argument_type>::cast(value) ),
|
||||
i );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Interpose given accessor's set methods with a binary function,
|
||||
taking both old and new value.
|
||||
|
||||
The wrappee's getter methods kept as-is.
|
||||
|
||||
@tpl WrappedAccessor
|
||||
Wrapped type must provide the usual get and set accessor methods,
|
||||
with the usual signatures (see StandardAccessor for a conforming
|
||||
example). Furthermore, must provide a nested typedef value_type.
|
||||
|
||||
@tpl SetterFunctor
|
||||
An adaptable binary function (i.e. providing nested typedefs for
|
||||
result_type and first and second argument type)
|
||||
*/
|
||||
template< class WrappedAccessor,
|
||||
typename SetterFunctor > class BinarySetterFunctionAccessorAdapter
|
||||
{
|
||||
public:
|
||||
typedef typename WrappedAccessor::value_type value_type;
|
||||
typedef typename SetterFunctor::second_argument_type argument_type;
|
||||
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
// making all members public, if no member template friends
|
||||
private:
|
||||
template<class A, typename S> friend class BinarySetterFunctionAccessorAdapter;
|
||||
#endif
|
||||
|
||||
WrappedAccessor maAccessor;
|
||||
SetterFunctor maFunctor;
|
||||
|
||||
public:
|
||||
BinarySetterFunctionAccessorAdapter() :
|
||||
maAccessor(),
|
||||
maFunctor()
|
||||
{}
|
||||
|
||||
template< class A > explicit
|
||||
BinarySetterFunctionAccessorAdapter(
|
||||
BinarySetterFunctionAccessorAdapter< A,
|
||||
SetterFunctor > const& rSrc ) :
|
||||
maAccessor( rSrc.maAccessor ),
|
||||
maFunctor( rSrc.maFunctor )
|
||||
{}
|
||||
|
||||
template< class T > explicit BinarySetterFunctionAccessorAdapter( T const& accessor ) :
|
||||
maAccessor( accessor ),
|
||||
maFunctor()
|
||||
{}
|
||||
|
||||
template< class T > BinarySetterFunctionAccessorAdapter( T accessor,
|
||||
SetterFunctor functor ) :
|
||||
maAccessor( accessor ),
|
||||
maFunctor( functor )
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
template< class Iterator >
|
||||
value_type operator()(Iterator const& i) const
|
||||
{
|
||||
return maAccessor(i);
|
||||
}
|
||||
|
||||
template< class Iterator, class Difference >
|
||||
value_type operator()(Iterator const& i, Difference const& diff) const
|
||||
{
|
||||
return maAccessor(i,diff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template< typename V, class Iterator >
|
||||
void set(V const& value, Iterator const& i) const
|
||||
{
|
||||
maAccessor.set(
|
||||
maFunctor(maAccessor(i),
|
||||
vigra::detail::RequiresExplicitCast<argument_type>::cast(value)),
|
||||
i );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Write through a CompositeIterator's first wrapped iterator, by
|
||||
piping the first wrapped iterator value, the second iterator
|
||||
value, and the specified new value through a ternary function.
|
||||
|
||||
Passed iterator must fulfill the CompositeIterator concept. Note
|
||||
that the getter/setter methods are not templatized regarding the
|
||||
iterator type, to make the mask calculation optimization below
|
||||
safe (see the maskedAccessor template metafunction below)
|
||||
|
||||
@tpl WrappedAccessor1
|
||||
Wrapped type must provide the usual get and set accessor methods,
|
||||
with the usual signatures (see StandardAccessor for a conforming
|
||||
example). Furthermore, the type must provide a nested typedef
|
||||
value_type (the selection of WrappedAccessor1 as the provider for
|
||||
that typedef is rather arbitrary. Could have been
|
||||
WrappedAccessor2, too. So sue me)
|
||||
|
||||
@tpl Functor
|
||||
An adaptable ternary function (i.e. providing nested typedefs for
|
||||
result_type and first, second and third argument type)
|
||||
*/
|
||||
template< class WrappedAccessor1,
|
||||
class WrappedAccessor2,
|
||||
typename Functor > class TernarySetterFunctionAccessorAdapter
|
||||
{
|
||||
public:
|
||||
typedef typename WrappedAccessor1::value_type value_type;
|
||||
typedef typename Functor::third_argument_type argument_type;
|
||||
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
// making all members public, if no member template friends
|
||||
private:
|
||||
template<class A1, class A2, typename F> friend class TernarySetterFunctionAccessorAdapter;
|
||||
#endif
|
||||
|
||||
WrappedAccessor1 ma1stAccessor;
|
||||
WrappedAccessor2 ma2ndAccessor;
|
||||
Functor maFunctor;
|
||||
|
||||
public:
|
||||
TernarySetterFunctionAccessorAdapter() :
|
||||
ma1stAccessor(),
|
||||
ma2ndAccessor(),
|
||||
maFunctor()
|
||||
{}
|
||||
|
||||
template< class T > explicit TernarySetterFunctionAccessorAdapter( T const& accessor ) :
|
||||
ma1stAccessor( accessor ),
|
||||
ma2ndAccessor(),
|
||||
maFunctor()
|
||||
{}
|
||||
|
||||
template< class A1, class A2 > explicit
|
||||
TernarySetterFunctionAccessorAdapter(
|
||||
TernarySetterFunctionAccessorAdapter< A1,
|
||||
A2,
|
||||
Functor > const& rSrc ) :
|
||||
ma1stAccessor( rSrc.ma1stAccessor ),
|
||||
ma2ndAccessor( rSrc.ma2ndAccessor ),
|
||||
maFunctor( rSrc.maFunctor )
|
||||
{}
|
||||
|
||||
template< class T1, class T2 >
|
||||
TernarySetterFunctionAccessorAdapter( T1 accessor1,
|
||||
T2 accessor2 ) :
|
||||
ma1stAccessor( accessor1 ),
|
||||
ma2ndAccessor( accessor2 ),
|
||||
maFunctor()
|
||||
{}
|
||||
|
||||
template< class T1, class T2 >
|
||||
TernarySetterFunctionAccessorAdapter( T1 accessor1,
|
||||
T2 accessor2,
|
||||
Functor func ) :
|
||||
ma1stAccessor( accessor1 ),
|
||||
ma2ndAccessor( accessor2 ),
|
||||
maFunctor( func )
|
||||
{}
|
||||
|
||||
|
||||
|
||||
WrappedAccessor1 const& get1stWrappedAccessor() const { return ma1stAccessor; }
|
||||
WrappedAccessor1& get1stWrappedAccessor() { return ma1stAccessor; }
|
||||
|
||||
|
||||
|
||||
template< class Iterator >
|
||||
value_type operator()(Iterator const& i) const
|
||||
{
|
||||
return ma1stAccessor(i.first());
|
||||
}
|
||||
|
||||
template< class Iterator, class Difference >
|
||||
value_type operator()(Iterator const& i, Difference const& diff) const
|
||||
{
|
||||
return ma1stAccessor(i.second(),diff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template< typename V, class Iterator >
|
||||
void set(V const& value, Iterator const& i) const
|
||||
{
|
||||
ma1stAccessor.set(
|
||||
maFunctor(ma1stAccessor(i.first()),
|
||||
ma2ndAccessor(i.second()),
|
||||
vigra::detail::RequiresExplicitCast<argument_type>::cast(value)),
|
||||
i.first() );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Access two distinct images simultaneously
|
||||
|
||||
Passed iterator must fulfill the CompositeIterator concept
|
||||
(i.e. wrap the two image's iterators into one
|
||||
CompositeIterator). The getter and setter methods expect and
|
||||
return a pair of values, with types equal to the two accessors
|
||||
value types
|
||||
|
||||
@tpl WrappedAccessor1
|
||||
Wrapped type must provide the usual get and set accessor methods,
|
||||
with the usual signatures (see StandardAccessor for a conforming
|
||||
example). Furthermore, the type must provide a nested typedef
|
||||
value_type.
|
||||
|
||||
@tpl WrappedAccessor2
|
||||
Wrapped type must provide the usual get and set accessor methods,
|
||||
with the usual signatures (see StandardAccessor for a conforming
|
||||
example). Furthermore, the type must provide a nested typedef
|
||||
value_type.
|
||||
*/
|
||||
template< class WrappedAccessor1,
|
||||
class WrappedAccessor2 > class JoinImageAccessorAdapter
|
||||
{
|
||||
public:
|
||||
// TODO(F3): Need numeric traits and a few free functions to
|
||||
// actually calculate with a pair (semantic: apply every operation
|
||||
// individually to the contained types)
|
||||
typedef std::pair<typename WrappedAccessor1::value_type,
|
||||
typename WrappedAccessor2::value_type> value_type;
|
||||
|
||||
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
|
||||
// making all members public, if no member template friends
|
||||
private:
|
||||
template<class A1, class A2> friend class JoinImageAccessorAdapter;
|
||||
#endif
|
||||
|
||||
WrappedAccessor1 ma1stAccessor;
|
||||
WrappedAccessor2 ma2ndAccessor;
|
||||
|
||||
public:
|
||||
JoinImageAccessorAdapter() :
|
||||
ma1stAccessor(),
|
||||
ma2ndAccessor()
|
||||
{}
|
||||
|
||||
template< class T > explicit JoinImageAccessorAdapter( T const& accessor ) :
|
||||
ma1stAccessor( accessor ),
|
||||
ma2ndAccessor()
|
||||
{}
|
||||
|
||||
template< class A1, class A2 > explicit
|
||||
JoinImageAccessorAdapter(
|
||||
JoinImageAccessorAdapter< A1,
|
||||
A2 > const& rSrc ) :
|
||||
ma1stAccessor( rSrc.ma1stAccessor ),
|
||||
ma2ndAccessor( rSrc.ma2ndAccessor )
|
||||
{}
|
||||
|
||||
template< class T1, class T2 >
|
||||
JoinImageAccessorAdapter( T1 accessor1,
|
||||
T2 accessor2 ) :
|
||||
ma1stAccessor( accessor1 ),
|
||||
ma2ndAccessor( accessor2 )
|
||||
{}
|
||||
|
||||
|
||||
|
||||
|
||||
template< class Iterator >
|
||||
value_type operator()(Iterator const& i) const
|
||||
{
|
||||
return std::make_pair(ma1stAccessor(i.first()),
|
||||
ma2ndAccessor(i.second()));
|
||||
}
|
||||
|
||||
template< class Iterator, class Difference >
|
||||
value_type operator()(Iterator const& i, Difference const& diff) const
|
||||
{
|
||||
return std::make_pair(ma1stAccessor(i.first(),diff),
|
||||
ma2ndAccessor(i.second(),diff));
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace basebmp
|
||||
|
||||
#endif /* INCLUDED_BASEBMP_INC_ACCESSORADAPTERS_HXX */
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -1,169 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,125 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,173 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,125 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,371 +0,0 @@
|
||||
/* -*- 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_COMPOSITEITERATOR_HXX
|
||||
#define INCLUDED_BASEBMP_INC_COMPOSITEITERATOR_HXX
|
||||
|
||||
#include <sal/types.h>
|
||||
#include <osl/diagnose.h>
|
||||
|
||||
#include <nonstandarditerator.hxx>
|
||||
#include <vigra/tuple.hxx>
|
||||
#include <vigra/iteratortraits.hxx>
|
||||
|
||||
|
||||
namespace basebmp
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template< typename T1, typename T2 > class ArithmeticProxy
|
||||
{
|
||||
public:
|
||||
ArithmeticProxy(T1& val1, T2& val2) :
|
||||
mpVal1( &val1 ),
|
||||
mpVal2( &val2 )
|
||||
{}
|
||||
|
||||
void operator++() { ++(*mpVal1); ++(*mpVal2); }
|
||||
void operator++(int) { (*mpVal1)++; (*mpVal2)++; }
|
||||
void operator--() { --(*mpVal1); --(*mpVal2); }
|
||||
void operator--(int) { (*mpVal1)--; (*mpVal2)--; }
|
||||
void operator+=(int d) {*mpVal1+=d; *mpVal2+=d; }
|
||||
void operator-=(int d) {*mpVal1-=d; *mpVal2-=d; }
|
||||
|
||||
bool operator==(ArithmeticProxy const & rhs) const
|
||||
{ return *mpVal1==*rhs.mpVal1 && *mpVal2==*rhs.mpVal2; }
|
||||
|
||||
bool operator!=(ArithmeticProxy const & rhs) const
|
||||
{ return *mpVal1!=*rhs.mpVal1 || *mpVal2!=*rhs.mpVal2; }
|
||||
|
||||
bool operator<(ArithmeticProxy const & rhs) const
|
||||
{ return *mpVal1<*rhs.mpVal1 && *mpVal2<*rhs.mpVal2; }
|
||||
|
||||
bool operator<=(ArithmeticProxy const & rhs) const
|
||||
{ return *mpVal1<=*rhs.mpVal1 && *mpVal2<=*rhs.mpVal2; }
|
||||
|
||||
bool operator>(ArithmeticProxy const & rhs) const
|
||||
{ return *mpVal1>*rhs.mpVal1 && *mpVal2>*rhs.mpVal2; }
|
||||
|
||||
bool operator>=(ArithmeticProxy const & rhs) const
|
||||
{ return *mpVal1>=*rhs.mpVal1 && *mpVal2>=*rhs.mpVal2; }
|
||||
|
||||
int operator-(ArithmeticProxy const & rhs) const
|
||||
{ return *mpVal1 - *rhs.mpVal1; }
|
||||
|
||||
private:
|
||||
T1* mpVal1;
|
||||
T2* mpVal2;
|
||||
};
|
||||
|
||||
template< typename Iterator1,
|
||||
typename Iterator2,
|
||||
typename ValueType,
|
||||
typename DifferenceType,
|
||||
typename IteratorCategory,
|
||||
class Derived >
|
||||
class CompositeIteratorBase : public NonStandardIterator
|
||||
{
|
||||
public:
|
||||
typedef Iterator1 iterator1_type;
|
||||
typedef Iterator2 iterator2_type;
|
||||
typedef ValueType value_type;
|
||||
typedef DifferenceType difference_type;
|
||||
typedef IteratorCategory iterator_category;
|
||||
|
||||
struct Impl
|
||||
{
|
||||
iterator1_type maIter1;
|
||||
iterator2_type maIter2;
|
||||
Impl()
|
||||
: maIter1()
|
||||
, maIter2()
|
||||
{
|
||||
}
|
||||
Impl(const iterator1_type& rIter1, const iterator2_type& rIter2)
|
||||
: maIter1(rIter1)
|
||||
, maIter2(rIter2)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
protected:
|
||||
Impl* pImpl;
|
||||
|
||||
private:
|
||||
bool equal(CompositeIteratorBase const & rhs) const
|
||||
{
|
||||
return (pImpl->maIter1 == rhs.pImpl->maIter1) && (pImpl->maIter2 == rhs.pImpl->maIter2);
|
||||
}
|
||||
|
||||
public:
|
||||
CompositeIteratorBase()
|
||||
{
|
||||
pImpl = new Impl();
|
||||
}
|
||||
|
||||
CompositeIteratorBase(const iterator1_type& rIter1, const iterator2_type& rIter2)
|
||||
{
|
||||
pImpl = new Impl(rIter1, rIter2);
|
||||
}
|
||||
|
||||
CompositeIteratorBase(const CompositeIteratorBase& rOther)
|
||||
{
|
||||
pImpl = new Impl(rOther.pImpl->maIter1, rOther.pImpl->maIter2);
|
||||
}
|
||||
|
||||
~CompositeIteratorBase()
|
||||
{
|
||||
delete pImpl;
|
||||
}
|
||||
|
||||
bool operator==(Derived const & rhs) const
|
||||
{
|
||||
return equal(rhs);
|
||||
}
|
||||
|
||||
bool operator!=(Derived const & rhs) const
|
||||
{
|
||||
return !equal(rhs);
|
||||
}
|
||||
|
||||
difference_type operator-(Derived const & rhs) const
|
||||
{
|
||||
OSL_ASSERT(pImpl->maIter1 - rhs.pImpl->maIter1 == pImpl->maIter2 - rhs.pImpl->maIter2);
|
||||
return pImpl->maIter1 - rhs.pImpl->maIter1;
|
||||
}
|
||||
|
||||
Derived & operator+=(difference_type const & s)
|
||||
{
|
||||
pImpl->maIter1 += s;
|
||||
pImpl->maIter2 += s;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
|
||||
Derived & operator-=(difference_type const & s)
|
||||
{
|
||||
pImpl->maIter1 -= s;
|
||||
pImpl->maIter2 -= s;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
|
||||
Derived operator+(difference_type const & s) const
|
||||
{
|
||||
Derived ret(static_cast<Derived const&>(*this));
|
||||
ret += s;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Derived operator-(difference_type const & s) const
|
||||
{
|
||||
Derived ret(static_cast<Derived const&>(*this));
|
||||
ret -= s;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Derived& operator++()
|
||||
{
|
||||
++pImpl->maIter1;
|
||||
++pImpl->maIter2;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
|
||||
Derived& operator--()
|
||||
{
|
||||
--pImpl->maIter1;
|
||||
--pImpl->maIter2;
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
|
||||
Derived operator++(int)
|
||||
{
|
||||
Derived ret(static_cast<Derived const&>(*this));
|
||||
++pImpl->maIter1;
|
||||
++pImpl->maIter2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
Derived operator--(int)
|
||||
{
|
||||
Derived ret(static_cast<Derived const&>(*this));
|
||||
--pImpl->maIter1;
|
||||
--pImpl->maIter2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
CompositeIteratorBase& operator=(const CompositeIteratorBase& rNew)
|
||||
{
|
||||
this->pImpl->maIter1 = rNew.pImpl->maIter1;
|
||||
this->pImpl->maIter2 = rNew.pImpl->maIter2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const iterator1_type& first() const { return pImpl->maIter1; }
|
||||
iterator1_type& first() { return pImpl->maIter1; }
|
||||
|
||||
const iterator2_type& second() const { return pImpl->maIter2; }
|
||||
iterator2_type& second() { return pImpl->maIter2; }
|
||||
};
|
||||
}
|
||||
|
||||
/** Provide the composition of two 1D image iterators
|
||||
|
||||
Use this template to compose two iterators into one (e.g. image
|
||||
and mask). Operations are transitive, e.g. operator== only returns
|
||||
true, if both wrapped iterator operator== have yielded true.
|
||||
|
||||
Note that both iterators must have compatible difference types. To
|
||||
avoid funny effects, iterator ranges given by a CompositeIterator
|
||||
should consist of wrapped iterators of similar range
|
||||
*/
|
||||
template< typename Iterator1,
|
||||
typename Iterator2,
|
||||
typename ValueType,
|
||||
typename DifferenceType,
|
||||
typename IteratorCategory >
|
||||
class CompositeIterator1D :
|
||||
public detail::CompositeIteratorBase< Iterator1,
|
||||
Iterator2,
|
||||
ValueType,
|
||||
DifferenceType,
|
||||
IteratorCategory,
|
||||
CompositeIterator1D<Iterator1,
|
||||
Iterator2,
|
||||
ValueType,
|
||||
DifferenceType,
|
||||
IteratorCategory> >
|
||||
{
|
||||
typedef detail::CompositeIteratorBase< Iterator1,
|
||||
Iterator2,
|
||||
ValueType,
|
||||
DifferenceType,
|
||||
IteratorCategory,
|
||||
CompositeIterator1D<Iterator1,
|
||||
Iterator2,
|
||||
ValueType,
|
||||
DifferenceType,
|
||||
IteratorCategory> > base_type;
|
||||
public:
|
||||
CompositeIterator1D() :
|
||||
base_type()
|
||||
{}
|
||||
|
||||
CompositeIterator1D( const Iterator1& rIter1,
|
||||
const Iterator2& rIter2 ) :
|
||||
base_type( rIter1, rIter2 )
|
||||
{}
|
||||
};
|
||||
|
||||
/** Provide the composition of two 2D image iterators
|
||||
|
||||
Use this template to compose two iterators into one (e.g. image
|
||||
and mask). Operations are transitive, e.g. operator== only returns
|
||||
true, if both wrapped iterator operator== have yielded true.
|
||||
|
||||
Note that both iterators must have compatible difference types. To
|
||||
avoid funny effects, iterator ranges given by a CompositeIterator
|
||||
should consist of wrapped iterators of similar range
|
||||
*/
|
||||
template< typename Iterator1, typename Iterator2 > class CompositeIterator2D :
|
||||
public detail::CompositeIteratorBase< Iterator1,
|
||||
Iterator2,
|
||||
std::pair<
|
||||
typename vigra::IteratorTraits<Iterator1>::value_type,
|
||||
typename vigra::IteratorTraits<Iterator2>::value_type >,
|
||||
typename vigra::IteratorTraits<Iterator1>::difference_type,
|
||||
typename vigra::IteratorTraits<Iterator1>::iterator_category,
|
||||
CompositeIterator2D<Iterator1, Iterator2> >
|
||||
{
|
||||
typedef detail::CompositeIteratorBase< Iterator1,
|
||||
Iterator2,
|
||||
std::pair<
|
||||
typename vigra::IteratorTraits<Iterator1>::value_type,
|
||||
typename vigra::IteratorTraits<Iterator2>::value_type >,
|
||||
typename vigra::IteratorTraits<Iterator1>::difference_type,
|
||||
typename vigra::IteratorTraits<Iterator1>::iterator_category,
|
||||
CompositeIterator2D<Iterator1, Iterator2> > base_type;
|
||||
public:
|
||||
typedef CompositeIterator1D< typename Iterator1::row_iterator,
|
||||
typename Iterator2::row_iterator,
|
||||
typename base_type::value_type,
|
||||
int,
|
||||
typename base_type::iterator_category > row_iterator;
|
||||
typedef CompositeIterator1D< typename Iterator1::column_iterator,
|
||||
typename Iterator2::column_iterator,
|
||||
typename base_type::value_type,
|
||||
int,
|
||||
typename base_type::iterator_category > column_iterator;
|
||||
|
||||
typedef detail::ArithmeticProxy< typename Iterator1::MoveX,
|
||||
typename Iterator2::MoveX > MoveX;
|
||||
typedef detail::ArithmeticProxy< typename Iterator1::MoveY,
|
||||
typename Iterator2::MoveY > MoveY;
|
||||
|
||||
MoveX x;
|
||||
MoveY y;
|
||||
|
||||
CompositeIterator2D() :
|
||||
base_type(),
|
||||
x(this->pImpl->maIter1.x,this->pImpl->maIter2.x),
|
||||
y(this->pImpl->maIter1.y,this->pImpl->maIter2.y)
|
||||
{}
|
||||
|
||||
CompositeIterator2D( const Iterator1& rIter1, const Iterator2& rIter2 ) :
|
||||
base_type( rIter1, rIter2 ),
|
||||
x(this->pImpl->maIter1.x,this->pImpl->maIter2.x),
|
||||
y(this->pImpl->maIter1.y,this->pImpl->maIter2.y)
|
||||
{}
|
||||
|
||||
CompositeIterator2D( const CompositeIterator2D& rOld ) :
|
||||
base_type(rOld),
|
||||
x(this->pImpl->maIter1.x,this->pImpl->maIter2.x),
|
||||
y(this->pImpl->maIter1.y,this->pImpl->maIter2.y)
|
||||
{}
|
||||
|
||||
CompositeIterator2D& operator=( const CompositeIterator2D& rNew )
|
||||
{
|
||||
this->pImpl->maIter1 = rNew.pImpl->maIter1;
|
||||
this->pImpl->maIter2 = rNew.pImpl->maIter2;
|
||||
|
||||
x = MoveX(this->pImpl->maIter1.x,
|
||||
this->pImpl->maIter2.x);
|
||||
y = MoveY(this->pImpl->maIter1.y,
|
||||
this->pImpl->maIter2.y);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
row_iterator rowIterator() const
|
||||
{
|
||||
return row_iterator(this->pImpl->maIter1.rowIterator(),
|
||||
this->pImpl->maIter2.rowIterator());
|
||||
}
|
||||
|
||||
column_iterator columnIterator() const
|
||||
{
|
||||
return column_iterator(this->pImpl->maIter1.columnIterator(),
|
||||
this->pImpl->maIter2.columnIterator());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace basebmp
|
||||
|
||||
#endif /* INCLUDED_BASEBMP_INC_COMPOSITEITERATOR_HXX */
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -1,47 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,58 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,129 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,49 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,228 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,39 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,621 +0,0 @@
|
||||
/* -*- 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_PACKEDPIXELITERATOR_HXX
|
||||
#define INCLUDED_BASEBMP_INC_PACKEDPIXELITERATOR_HXX
|
||||
|
||||
#include <metafunctions.hxx>
|
||||
#include <stridedarrayiterator.hxx>
|
||||
#include <nonstandarditerator.hxx>
|
||||
#include <accessortraits.hxx>
|
||||
|
||||
#include <vigra/metaprogramming.hxx>
|
||||
#include <vigra/diff2d.hxx>
|
||||
|
||||
namespace basebmp
|
||||
{
|
||||
|
||||
/// Get bitmask for data at given intra-word position, for given bit depth
|
||||
template< typename value_type,
|
||||
int bits_per_pixel,
|
||||
bool MsbFirst,
|
||||
typename difference_type >
|
||||
inline value_type get_mask( difference_type d )
|
||||
{
|
||||
static_assert(bits_per_pixel > 0, "greater than 0");
|
||||
static_assert(sizeof(value_type)*8 % bits_per_pixel == 0, "value_type");
|
||||
static_assert(sizeof(value_type)*8 / bits_per_pixel > 1, "value_type");
|
||||
static_assert(vigra::TypeTraits<value_type>::isPOD::asBool, "isPOD");
|
||||
|
||||
const unsigned int nIntraWordPositions( sizeof(value_type)*8 / bits_per_pixel );
|
||||
|
||||
// create bits_per_pixel 1s shift to intra-word position
|
||||
return ((~(~0U << bits_per_pixel)) << bits_per_pixel*(MsbFirst ?
|
||||
(nIntraWordPositions-1 - (d % nIntraWordPositions)) :
|
||||
(d % nIntraWordPositions)));
|
||||
}
|
||||
|
||||
template< int num_intraword_positions, int bits_per_pixel, bool MsbFirst, typename difference_type > inline difference_type get_shift( difference_type remainder )
|
||||
{
|
||||
return bits_per_pixel*(MsbFirst ?
|
||||
(num_intraword_positions - 1 - remainder) :
|
||||
remainder);
|
||||
}
|
||||
|
||||
template< typename Valuetype,
|
||||
int bits_per_pixel,
|
||||
bool MsbFirst > class PackedPixelColumnIterator : public NonStandardIterator
|
||||
{
|
||||
public:
|
||||
// no reference, no index_reference type here
|
||||
typedef Valuetype value_type;
|
||||
typedef int difference_type;
|
||||
typedef image_traverser_tag iterator_category;
|
||||
|
||||
typedef typename remove_const<value_type>::type mask_type;
|
||||
typedef value_type* pointer;
|
||||
typedef StridedArrayIterator< value_type > MoveY;
|
||||
|
||||
enum {
|
||||
/** The number of pixel within a single value_type value
|
||||
*/
|
||||
num_intraword_positions=sizeof(value_type)*8/bits_per_pixel,
|
||||
/** Bit mask for one pixel (least significant bits)
|
||||
*/
|
||||
bit_mask=~(~0u << bits_per_pixel)
|
||||
};
|
||||
|
||||
private:
|
||||
MoveY y;
|
||||
mask_type mask_;
|
||||
difference_type shift_;
|
||||
|
||||
void inc()
|
||||
{
|
||||
++y;
|
||||
}
|
||||
|
||||
void dec()
|
||||
{
|
||||
--y;
|
||||
}
|
||||
|
||||
bool equal( PackedPixelColumnIterator const & rhs ) const
|
||||
{
|
||||
return rhs.y == y;
|
||||
}
|
||||
|
||||
bool less( PackedPixelColumnIterator const & rhs ) const
|
||||
{
|
||||
return y < rhs.y;
|
||||
}
|
||||
|
||||
public:
|
||||
PackedPixelColumnIterator() :
|
||||
y(0),
|
||||
mask_( get_mask<value_type, bits_per_pixel, MsbFirst, difference_type>(0) ),
|
||||
shift_( get_shift<num_intraword_positions, bits_per_pixel, MsbFirst, difference_type>(0) )
|
||||
{}
|
||||
|
||||
PackedPixelColumnIterator( const MoveY& base, difference_type remainder ) :
|
||||
y(base),
|
||||
mask_( get_mask<value_type, bits_per_pixel, MsbFirst>(remainder) ),
|
||||
shift_( get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder) )
|
||||
{}
|
||||
|
||||
PackedPixelColumnIterator& operator+=( difference_type d )
|
||||
{
|
||||
y += d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelColumnIterator& operator-=( difference_type d )
|
||||
{
|
||||
y -= d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelColumnIterator operator+( difference_type d )
|
||||
{
|
||||
PackedPixelColumnIterator res(*this);
|
||||
res += d;
|
||||
return res;
|
||||
}
|
||||
|
||||
PackedPixelColumnIterator operator-( difference_type d )
|
||||
{
|
||||
PackedPixelColumnIterator res(*this);
|
||||
res -= d;
|
||||
return res;
|
||||
}
|
||||
|
||||
PackedPixelColumnIterator& operator++()
|
||||
{
|
||||
inc();
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelColumnIterator& operator--()
|
||||
{
|
||||
dec();
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelColumnIterator operator++(int)
|
||||
{
|
||||
PackedPixelColumnIterator res(*this);
|
||||
inc();
|
||||
return res;
|
||||
}
|
||||
|
||||
PackedPixelColumnIterator operator--(int)
|
||||
{
|
||||
PackedPixelColumnIterator res(*this);
|
||||
dec();
|
||||
return res;
|
||||
}
|
||||
|
||||
bool operator==(PackedPixelColumnIterator const & rhs) const
|
||||
{
|
||||
return equal( rhs );
|
||||
}
|
||||
|
||||
bool operator!=(PackedPixelColumnIterator const & rhs) const
|
||||
{
|
||||
return !equal( rhs );
|
||||
}
|
||||
|
||||
bool operator<(PackedPixelColumnIterator const & rhs) const
|
||||
{
|
||||
return less(rhs);
|
||||
}
|
||||
|
||||
bool operator<=(PackedPixelColumnIterator const & rhs) const
|
||||
{
|
||||
return !rhs.less(*this);
|
||||
}
|
||||
|
||||
bool operator>(PackedPixelColumnIterator const & rhs) const
|
||||
{
|
||||
return rhs.less(*this);
|
||||
}
|
||||
|
||||
bool operator>=(PackedPixelColumnIterator const & rhs) const
|
||||
{
|
||||
return !less(rhs);
|
||||
}
|
||||
|
||||
difference_type operator-(PackedPixelColumnIterator const & rhs) const
|
||||
{
|
||||
return y - rhs.y;
|
||||
}
|
||||
|
||||
value_type get() const
|
||||
{
|
||||
return unsigned_cast<value_type>(*y() & mask_) >> shift_;
|
||||
}
|
||||
|
||||
void set( value_type v ) const
|
||||
{
|
||||
const value_type pixel_value( (v << shift_) & mask_ );
|
||||
*y() = (*y() & ~mask_) | pixel_value;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template< typename Valuetype,
|
||||
int bits_per_pixel,
|
||||
bool MsbFirst > class PackedPixelRowIterator : public NonStandardIterator
|
||||
{
|
||||
public:
|
||||
// no reference, no index_reference type here
|
||||
typedef Valuetype value_type;
|
||||
typedef int difference_type;
|
||||
typedef image_traverser_tag iterator_category;
|
||||
|
||||
typedef typename remove_const<value_type>::type mask_type;
|
||||
typedef value_type* pointer;
|
||||
|
||||
enum {
|
||||
/** The number of pixel within a single value_type value
|
||||
*/
|
||||
num_intraword_positions=sizeof(value_type)*8/bits_per_pixel,
|
||||
/** Bit mask for one pixel (least significant bits)
|
||||
*/
|
||||
bit_mask=~(~0u << bits_per_pixel)
|
||||
};
|
||||
|
||||
private:
|
||||
pointer data_;
|
||||
mask_type mask_;
|
||||
difference_type remainder_;
|
||||
|
||||
void update_mask()
|
||||
{
|
||||
mask_ = get_mask<value_type, bits_per_pixel, MsbFirst>(remainder_);
|
||||
}
|
||||
|
||||
void inc()
|
||||
{
|
||||
const difference_type newValue( remainder_ + 1 );
|
||||
const difference_type data_offset( newValue / num_intraword_positions );
|
||||
|
||||
data_ += data_offset;
|
||||
remainder_ = newValue % num_intraword_positions;
|
||||
|
||||
const mask_type shifted_mask(
|
||||
MsbFirst ?
|
||||
unsigned_cast<mask_type>(mask_) >> bits_per_pixel :
|
||||
mask_ << bits_per_pixel );
|
||||
|
||||
// data_offset is 0 for shifted mask, and 1 for wrapped-around mask
|
||||
mask_ = (1-data_offset)*shifted_mask + data_offset*(MsbFirst ?
|
||||
bit_mask << bits_per_pixel*(num_intraword_positions-1) :
|
||||
bit_mask);
|
||||
}
|
||||
|
||||
void dec()
|
||||
{
|
||||
const difference_type newValue( remainder_ - 1 );
|
||||
const bool isNegative( is_negative(newValue) );
|
||||
const difference_type newRemainder( newValue % num_intraword_positions );
|
||||
|
||||
// calc data_ += newValue / num_intraword_positions;
|
||||
// remainder_ = newRemainder;
|
||||
// for newValue >= 0, and
|
||||
// data_ += newValue / num_intraword_positions - 1;
|
||||
// remainder_ = num_intraword_positions - newRemainder;
|
||||
// (to force remainder_ to be positive).
|
||||
// This is branch-free, if is_negative() is branch-free
|
||||
const difference_type data_offset( newValue / num_intraword_positions - isNegative );
|
||||
data_ += data_offset;
|
||||
remainder_ = newRemainder + isNegative*num_intraword_positions;
|
||||
|
||||
const mask_type shifted_mask(
|
||||
MsbFirst ?
|
||||
mask_ << bits_per_pixel :
|
||||
unsigned_cast<mask_type>(mask_) >> bits_per_pixel );
|
||||
|
||||
// data_offset is 0 for shifted mask, and 1 for wrapped-around mask
|
||||
mask_ = (1-data_offset)*shifted_mask + data_offset*(MsbFirst ?
|
||||
bit_mask :
|
||||
bit_mask << bits_per_pixel*(num_intraword_positions-1));
|
||||
}
|
||||
|
||||
bool equal( PackedPixelRowIterator const & rhs ) const
|
||||
{
|
||||
return rhs.data_ == data_ && rhs.remainder_ == remainder_;
|
||||
}
|
||||
|
||||
bool less( PackedPixelRowIterator const & rhs ) const
|
||||
{
|
||||
return data_ == rhs.data_ ?
|
||||
(remainder_ < rhs.remainder_) :
|
||||
(data_ < rhs.data_);
|
||||
}
|
||||
|
||||
public:
|
||||
PackedPixelRowIterator() :
|
||||
data_(0),
|
||||
mask_( get_mask<value_type, bits_per_pixel, MsbFirst, difference_type>(0) ),
|
||||
remainder_(0)
|
||||
{}
|
||||
|
||||
explicit PackedPixelRowIterator( pointer base, int x ) :
|
||||
data_(base),
|
||||
mask_(0),
|
||||
remainder_(x % num_intraword_positions)
|
||||
{
|
||||
update_mask();
|
||||
}
|
||||
|
||||
PackedPixelRowIterator& operator+=( difference_type d )
|
||||
{
|
||||
const difference_type newValue( remainder_ + d );
|
||||
const bool isNegative( is_negative(newValue) );
|
||||
const difference_type newRemainder( newValue % num_intraword_positions );
|
||||
|
||||
// calc data_ += newValue / num_intraword_positions;
|
||||
// remainder_ = newRemainder;
|
||||
// for newValue >= 0, and
|
||||
// data_ += newValue / num_intraword_positions - 1;
|
||||
// remainder_ = newRemainder + num_intraword_positions;
|
||||
// (to force remainder_ to be positive).
|
||||
// This is branch-free, if is_negative() is branch-free
|
||||
data_ += newValue / num_intraword_positions - isNegative;
|
||||
remainder_ = newRemainder + isNegative*num_intraword_positions;
|
||||
update_mask();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelRowIterator& operator-=( difference_type d )
|
||||
{
|
||||
// forward to operator+= - which has to cope with negative
|
||||
// values, anyway.
|
||||
return *this += -d;
|
||||
}
|
||||
|
||||
PackedPixelRowIterator operator+( difference_type d )
|
||||
{
|
||||
PackedPixelRowIterator res(*this);
|
||||
res += d;
|
||||
return res;
|
||||
}
|
||||
|
||||
PackedPixelRowIterator operator-( difference_type d )
|
||||
{
|
||||
PackedPixelRowIterator res(*this);
|
||||
res -= d;
|
||||
return res;
|
||||
}
|
||||
|
||||
PackedPixelRowIterator& operator++()
|
||||
{
|
||||
inc();
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelRowIterator& operator--()
|
||||
{
|
||||
dec();
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelRowIterator operator++(int)
|
||||
{
|
||||
PackedPixelRowIterator res(*this);
|
||||
inc();
|
||||
return res;
|
||||
}
|
||||
|
||||
PackedPixelRowIterator operator--(int)
|
||||
{
|
||||
PackedPixelRowIterator res(*this);
|
||||
dec();
|
||||
return res;
|
||||
}
|
||||
|
||||
bool operator==(PackedPixelRowIterator const & rhs) const
|
||||
{
|
||||
return equal( rhs );
|
||||
}
|
||||
|
||||
bool operator!=(PackedPixelRowIterator const & rhs) const
|
||||
{
|
||||
return !equal( rhs );
|
||||
}
|
||||
|
||||
bool operator<(PackedPixelRowIterator const & rhs) const
|
||||
{
|
||||
return less(rhs);
|
||||
}
|
||||
|
||||
bool operator<=(PackedPixelRowIterator const & rhs) const
|
||||
{
|
||||
return !rhs.less(*this);
|
||||
}
|
||||
|
||||
bool operator>(PackedPixelRowIterator const & rhs) const
|
||||
{
|
||||
return rhs.less(*this);
|
||||
}
|
||||
|
||||
bool operator>=(PackedPixelRowIterator const & rhs) const
|
||||
{
|
||||
return !less(rhs);
|
||||
}
|
||||
|
||||
difference_type operator-(PackedPixelRowIterator const & rhs) const
|
||||
{
|
||||
return (data_ - rhs.data_)*num_intraword_positions + (remainder_ - rhs.remainder_);
|
||||
}
|
||||
|
||||
value_type get() const
|
||||
{
|
||||
return unsigned_cast<value_type>(*data_ & mask_) >>
|
||||
get_shift<num_intraword_positions,
|
||||
bits_per_pixel,
|
||||
MsbFirst>(remainder_);
|
||||
}
|
||||
|
||||
void set( value_type v ) const
|
||||
{
|
||||
const value_type pixel_value(
|
||||
(v <<
|
||||
get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder_))
|
||||
& mask_ );
|
||||
*data_ = (*data_ & ~mask_) | pixel_value;
|
||||
}
|
||||
};
|
||||
|
||||
/** 2D image iterator for packed pixel formats
|
||||
|
||||
This iterator can be used for image formats that pack more than
|
||||
one pixel into an machine data type (like one bit per pixel, eight
|
||||
of which packed into one char)
|
||||
*/
|
||||
template< typename Valuetype,
|
||||
int bits_per_pixel,
|
||||
bool MsbFirst > class PackedPixelIterator : public NonStandardIterator
|
||||
{
|
||||
public:
|
||||
// no reference, no index_reference type here
|
||||
typedef Valuetype value_type;
|
||||
typedef vigra::Diff2D difference_type;
|
||||
typedef image_traverser_tag iterator_category;
|
||||
typedef PackedPixelRowIterator<value_type,
|
||||
bits_per_pixel,
|
||||
MsbFirst> row_iterator;
|
||||
typedef PackedPixelColumnIterator<value_type,
|
||||
bits_per_pixel,
|
||||
MsbFirst> column_iterator;
|
||||
|
||||
typedef value_type* pointer;
|
||||
typedef int MoveX;
|
||||
typedef StridedArrayIterator< value_type > MoveY;
|
||||
|
||||
enum {
|
||||
/** The number of pixel within a single value_type value
|
||||
*/
|
||||
num_intraword_positions=sizeof(value_type)*8/bits_per_pixel,
|
||||
/** Bit mask for one pixel (least significant bits)
|
||||
*/
|
||||
bit_mask=~(~0u << bits_per_pixel)
|
||||
};
|
||||
|
||||
// TODO(F2): direction of iteration (ImageIterator can be made to
|
||||
// run backwards)
|
||||
|
||||
private:
|
||||
pointer current() const
|
||||
{
|
||||
return y() + (x / num_intraword_positions);
|
||||
}
|
||||
|
||||
bool equal(PackedPixelIterator const & rhs) const
|
||||
{
|
||||
return (x == rhs.x) && (y == rhs.y);
|
||||
}
|
||||
|
||||
public:
|
||||
PackedPixelIterator() :
|
||||
x(0),
|
||||
y(0)
|
||||
{}
|
||||
|
||||
PackedPixelIterator(pointer base, int ystride) :
|
||||
x(0),
|
||||
y(ystride,base)
|
||||
{}
|
||||
|
||||
bool operator==(PackedPixelIterator const & rhs) const
|
||||
{
|
||||
return equal(rhs);
|
||||
}
|
||||
|
||||
bool operator!=(PackedPixelIterator const & rhs) const
|
||||
{
|
||||
return !equal(rhs);
|
||||
}
|
||||
|
||||
difference_type operator-(PackedPixelIterator const & rhs) const
|
||||
{
|
||||
return difference_type(x - rhs.x, y - rhs.y);
|
||||
}
|
||||
|
||||
MoveX x;
|
||||
MoveY y;
|
||||
|
||||
PackedPixelIterator & operator+=(difference_type const & s)
|
||||
{
|
||||
x += s.x;
|
||||
y += s.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelIterator & operator-=(difference_type const & s)
|
||||
{
|
||||
x -= s.x;
|
||||
y -= s.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PackedPixelIterator operator+(difference_type const & s) const
|
||||
{
|
||||
PackedPixelIterator ret(*this);
|
||||
ret += s;
|
||||
return ret;
|
||||
}
|
||||
|
||||
PackedPixelIterator operator-(difference_type const & s) const
|
||||
{
|
||||
PackedPixelIterator ret(*this);
|
||||
ret -= s;
|
||||
return ret;
|
||||
}
|
||||
|
||||
row_iterator rowIterator() const
|
||||
{
|
||||
return row_iterator(current(),x);
|
||||
}
|
||||
|
||||
column_iterator columnIterator() const
|
||||
{
|
||||
return column_iterator(MoveY(y,
|
||||
x / num_intraword_positions),
|
||||
x % num_intraword_positions);
|
||||
}
|
||||
|
||||
value_type get() const
|
||||
{
|
||||
const int remainder( x % num_intraword_positions );
|
||||
|
||||
return (unsigned_cast<value_type>(*current() &
|
||||
get_mask<value_type, bits_per_pixel, MsbFirst>(remainder))
|
||||
>> get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder));
|
||||
}
|
||||
|
||||
void set( value_type v ) const
|
||||
{
|
||||
const int remainder( x % num_intraword_positions );
|
||||
const int mask( get_mask<value_type, bits_per_pixel, MsbFirst>(remainder) );
|
||||
const value_type pixel_value(
|
||||
(v <<
|
||||
get_shift<num_intraword_positions, bits_per_pixel, MsbFirst>(remainder))
|
||||
& mask );
|
||||
pointer p = current();
|
||||
*p = (*p & ~mask) | pixel_value;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// partial specialization for the accessor traits masked_accessor
|
||||
// selector metafunction - can employ fast mask functor for the 1bpp
|
||||
// case.
|
||||
template< class Accessor,
|
||||
class MaskAccessor,
|
||||
class Iterator,
|
||||
bool polarity,
|
||||
bool MsbFirst > struct maskedAccessorSelector< Accessor,
|
||||
MaskAccessor,
|
||||
Iterator,
|
||||
PackedPixelIterator< typename MaskAccessor::value_type,
|
||||
1,
|
||||
MsbFirst >,
|
||||
polarity >
|
||||
{
|
||||
typedef TernarySetterFunctionAccessorAdapter<
|
||||
Accessor,
|
||||
MaskAccessor,
|
||||
typename outputMaskFunctorSelector<
|
||||
typename Accessor::value_type,
|
||||
typename MaskAccessor::value_type,
|
||||
polarity,
|
||||
FastMask>::type >
|
||||
type;
|
||||
};
|
||||
|
||||
} // namespace basebmp
|
||||
|
||||
#endif /* INCLUDED_BASEBMP_INC_PACKEDPIXELITERATOR_HXX */
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -1,132 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,147 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,101 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,304 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,92 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,341 +0,0 @@
|
||||
/* -*- 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_RGBMASKPIXELFORMATS_HXX
|
||||
#define INCLUDED_BASEBMP_INC_RGBMASKPIXELFORMATS_HXX
|
||||
|
||||
#include <basebmp/color.hxx>
|
||||
#include <colortraits.hxx>
|
||||
#include <accessor.hxx>
|
||||
#include <pixeliterator.hxx>
|
||||
#include <pixelformatadapters.hxx>
|
||||
#include <metafunctions.hxx>
|
||||
#include <endian.hxx>
|
||||
|
||||
#include <vigra/numerictraits.hxx>
|
||||
#include <vigra/metaprogramming.hxx>
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace basebmp
|
||||
{
|
||||
|
||||
/** Base class operating on RGB truecolor mask pixel
|
||||
|
||||
Use this template, if you have an (integer) pixel type, and three
|
||||
bitmasks denoting where the channel bits are.
|
||||
|
||||
@tpl PixelType
|
||||
Input pixel type to operate on
|
||||
|
||||
@tpl ColorType
|
||||
Underlying color type, to convert the pixel values into
|
||||
|
||||
@tpl RedMask
|
||||
Bitmask, to access the red bits in the data type
|
||||
|
||||
@tpl GreenMask
|
||||
Bitmask, to access the green bits in the data type
|
||||
|
||||
@tpl BlueMask
|
||||
Bitmask, to access the blue bits in the data type
|
||||
|
||||
@tpl SwapBytes
|
||||
When true, the final pixel values will be byte-swapped before
|
||||
passed on.
|
||||
*/
|
||||
template< typename PixelType,
|
||||
typename ColorType,
|
||||
unsigned int RedMask,
|
||||
unsigned int GreenMask,
|
||||
unsigned int BlueMask,
|
||||
bool SwapBytes > struct RGBMaskFunctorBase
|
||||
{
|
||||
typedef PixelType pixel_type;
|
||||
typedef ColorType color_type;
|
||||
typedef typename make_unsigned<pixel_type>::type unsigned_pixel_type;
|
||||
typedef typename ColorTraits<ColorType>::component_type component_type;
|
||||
|
||||
// calc corrective shifts for all three channels in advance
|
||||
enum {
|
||||
red_shift = numberOfTrailingZeros<RedMask>::value,
|
||||
green_shift = numberOfTrailingZeros<GreenMask>::value,
|
||||
blue_shift = numberOfTrailingZeros<BlueMask>::value,
|
||||
|
||||
red_bits = bitcount<RedMask>::value,
|
||||
green_bits = bitcount<GreenMask>::value,
|
||||
blue_bits = bitcount<BlueMask>::value
|
||||
};
|
||||
};
|
||||
|
||||
template< typename PixelType,
|
||||
typename ColorType,
|
||||
unsigned int RedMask,
|
||||
unsigned int GreenMask,
|
||||
unsigned int BlueMask,
|
||||
bool SwapBytes > struct RGBMaskGetter :
|
||||
public RGBMaskFunctorBase<PixelType,
|
||||
ColorType,
|
||||
RedMask,
|
||||
GreenMask,
|
||||
BlueMask,
|
||||
SwapBytes>,
|
||||
public std::unary_function<PixelType, ColorType>
|
||||
{
|
||||
typedef RGBMaskFunctorBase<PixelType,
|
||||
ColorType,
|
||||
RedMask,
|
||||
GreenMask,
|
||||
BlueMask,
|
||||
SwapBytes> base_type;
|
||||
|
||||
ColorType operator()( PixelType v ) const
|
||||
{
|
||||
v = SwapBytes ? byteSwap(v) : v;
|
||||
|
||||
const typename base_type::unsigned_pixel_type red (v & RedMask);
|
||||
const typename base_type::unsigned_pixel_type green(v & GreenMask);
|
||||
const typename base_type::unsigned_pixel_type blue (v & BlueMask);
|
||||
|
||||
// shift color nibbles to right-aligned position. ORing it
|
||||
// channel value shifted twice the number of channel bits, to
|
||||
// spread the value into the component_type range
|
||||
ColorType res( (shiftRight(red,
|
||||
base_type::red_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
base_type::red_bits)) |
|
||||
(shiftRight(red,
|
||||
base_type::red_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
2*base_type::red_bits)),
|
||||
|
||||
(shiftRight(green,
|
||||
base_type::green_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
base_type::green_bits)) |
|
||||
(shiftRight(green,
|
||||
base_type::green_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
2*base_type::green_bits)),
|
||||
|
||||
(shiftRight(blue,
|
||||
base_type::blue_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
base_type::blue_bits)) |
|
||||
(shiftRight(blue,
|
||||
base_type::blue_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
2*base_type::blue_bits)) );
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
template< typename PixelType,
|
||||
typename ColorType,
|
||||
unsigned int BaseValue,
|
||||
unsigned int RedMask,
|
||||
unsigned int GreenMask,
|
||||
unsigned int BlueMask,
|
||||
bool SwapBytes > struct RGBMaskSetter :
|
||||
public RGBMaskFunctorBase<PixelType,
|
||||
ColorType,
|
||||
RedMask,
|
||||
GreenMask,
|
||||
BlueMask,
|
||||
SwapBytes>,
|
||||
public std::unary_function<ColorType, PixelType>
|
||||
{
|
||||
typedef RGBMaskFunctorBase<PixelType,
|
||||
ColorType,
|
||||
RedMask,
|
||||
GreenMask,
|
||||
BlueMask,
|
||||
SwapBytes> base_type;
|
||||
|
||||
PixelType operator()( ColorType const& c ) const
|
||||
{
|
||||
const typename base_type::unsigned_pixel_type red (c.getRed());
|
||||
const typename base_type::unsigned_pixel_type green(c.getGreen());
|
||||
const typename base_type::unsigned_pixel_type blue (c.getBlue());
|
||||
|
||||
typename base_type::unsigned_pixel_type res(
|
||||
BaseValue |
|
||||
(shiftLeft(red,
|
||||
base_type::red_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
base_type::red_bits) & RedMask) |
|
||||
(shiftLeft(green,
|
||||
base_type::green_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
base_type::green_bits) & GreenMask) |
|
||||
(shiftLeft(blue,
|
||||
base_type::blue_shift-8*
|
||||
static_cast<signed>(sizeof(typename base_type::component_type))+
|
||||
base_type::blue_bits) & BlueMask) );
|
||||
|
||||
return SwapBytes ? byteSwap(res) : res;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
template< typename PixelType,
|
||||
unsigned int BaseValue,
|
||||
unsigned int RedMask,
|
||||
unsigned int GreenMask,
|
||||
unsigned int BlueMask,
|
||||
bool SwapBytes > struct PixelFormatTraitsTemplate_RGBMask
|
||||
{
|
||||
typedef PixelType pixel_type;
|
||||
|
||||
typedef RGBMaskGetter<pixel_type,
|
||||
Color,
|
||||
RedMask,
|
||||
GreenMask,
|
||||
BlueMask,
|
||||
SwapBytes> getter_type;
|
||||
typedef RGBMaskSetter<pixel_type,
|
||||
Color,
|
||||
BaseValue,
|
||||
RedMask,
|
||||
GreenMask,
|
||||
BlueMask,
|
||||
SwapBytes> setter_type;
|
||||
|
||||
typedef PixelIterator<pixel_type> iterator_type;
|
||||
typedef StandardAccessor<pixel_type> raw_accessor_type;
|
||||
typedef AccessorSelector<
|
||||
getter_type, setter_type> accessor_selector;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Hopefully this is an understandable plaintext explanation that matches
|
||||
// reality...
|
||||
|
||||
// BASEBMP_TRUECOLORMASK_LSB_SWAP means that on a big-endian platform, a pixel
|
||||
// value when viewed as an integer (16 or 32 bits) has to be byte-swapped for
|
||||
// the channels to match the masks. Or equivalently (I think), on a big-endian
|
||||
// platform, the masks need to be byte-swapped to be correct.
|
||||
|
||||
// I.e. on a litte-endian platform the masks work as such.
|
||||
|
||||
// BASEBMP_TRUECOLORMASK_MSB_SWAP means the opposite. The masks work as such
|
||||
// on big-endian platforms, on little-endian platforms the pixel needs to be
|
||||
// byte-swapped for the masks to work.
|
||||
|
||||
// So in a sense these two names are "backward". It sounds to me as if
|
||||
// BASEBMP_TRUECOLORMASK_LSB_SWAP would mean "when on LSB, swap" ;)
|
||||
|
||||
#ifdef OSL_LITENDIAN
|
||||
# define BASEBMP_TRUECOLORMASK_LSB_SWAP false
|
||||
# define BASEBMP_TRUECOLORMASK_MSB_SWAP true
|
||||
#else
|
||||
# ifdef OSL_BIGENDIAN
|
||||
# define BASEBMP_TRUECOLORMASK_LSB_SWAP true
|
||||
# define BASEBMP_TRUECOLORMASK_MSB_SWAP false
|
||||
# else
|
||||
# error Undetermined endianness!
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// 16bpp MSB RGB
|
||||
typedef PixelFormatTraitsTemplate_RGBMask<
|
||||
sal_uInt16,
|
||||
0,
|
||||
0xF800,
|
||||
0x07E0,
|
||||
0x001F,
|
||||
BASEBMP_TRUECOLORMASK_MSB_SWAP > PixelFormatTraits_RGB16_565_MSB;
|
||||
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB16_565_MSB::getter_type,
|
||||
PixelFormatTraits_RGB16_565_MSB::setter_type);
|
||||
|
||||
// 16bpp LSB RGB
|
||||
typedef PixelFormatTraitsTemplate_RGBMask<
|
||||
sal_uInt16,
|
||||
0,
|
||||
0xF800,
|
||||
0x07E0,
|
||||
0x001F,
|
||||
BASEBMP_TRUECOLORMASK_LSB_SWAP > PixelFormatTraits_RGB16_565_LSB;
|
||||
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGB16_565_LSB::getter_type,
|
||||
PixelFormatTraits_RGB16_565_LSB::setter_type);
|
||||
|
||||
|
||||
// 32bpp formats
|
||||
|
||||
// The intent is that the order of channel names in the names of the 32bpp
|
||||
// format typedefs below correspond to the order of the channel bytes in
|
||||
// memory, if I understand correctly.... I think the point with the below
|
||||
// formats is that the channel byte order in memory is the same regardless of
|
||||
// platform byte order.
|
||||
|
||||
// This one used to be called PixelFormatTraits_RGB32_888.
|
||||
|
||||
typedef PixelFormatTraitsTemplate_RGBMask<
|
||||
sal_uInt32,
|
||||
0xFF000000,
|
||||
0x00FF0000,
|
||||
0x0000FF00,
|
||||
0x000000FF,
|
||||
BASEBMP_TRUECOLORMASK_LSB_SWAP > PixelFormatTraits_BGRA32_8888;
|
||||
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_BGRA32_8888::getter_type,
|
||||
PixelFormatTraits_BGRA32_8888::setter_type);
|
||||
|
||||
// This one used to be called PixelFormatTraits_BGR32_888.
|
||||
|
||||
typedef PixelFormatTraitsTemplate_RGBMask<
|
||||
sal_uInt32,
|
||||
0xFF000000,
|
||||
0x00FF0000,
|
||||
0x0000FF00,
|
||||
0x000000FF,
|
||||
BASEBMP_TRUECOLORMASK_MSB_SWAP > PixelFormatTraits_ARGB32_8888;
|
||||
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_ARGB32_8888::getter_type,
|
||||
PixelFormatTraits_ARGB32_8888::setter_type);
|
||||
|
||||
// The following two ones were added for Android needs and for completeness
|
||||
|
||||
typedef PixelFormatTraitsTemplate_RGBMask<
|
||||
sal_uInt32,
|
||||
0x000000FF,
|
||||
0xFF000000,
|
||||
0x00FF0000,
|
||||
0x0000FF00,
|
||||
BASEBMP_TRUECOLORMASK_LSB_SWAP > PixelFormatTraits_ABGR32_8888;
|
||||
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_ABGR32_8888::getter_type,
|
||||
PixelFormatTraits_ABGR32_8888::setter_type);
|
||||
|
||||
typedef PixelFormatTraitsTemplate_RGBMask<
|
||||
sal_uInt32,
|
||||
0x000000FF,
|
||||
0xFF000000,
|
||||
0x00FF0000,
|
||||
0x0000FF00,
|
||||
BASEBMP_TRUECOLORMASK_MSB_SWAP > PixelFormatTraits_RGBA32_8888;
|
||||
BASEBMP_SPECIALIZE_ACCESSORTRAITS(PixelFormatTraits_RGBA32_8888::getter_type,
|
||||
PixelFormatTraits_RGBA32_8888::setter_type);
|
||||
|
||||
} // namespace basebmp
|
||||
|
||||
#endif /* INCLUDED_BASEBMP_INC_RGBMASKPIXELFORMATS_HXX */
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -1,108 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,74 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,609 +0,0 @@
|
||||
/* -*- 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 <cassert>
|
||||
#include <string.h>
|
||||
|
||||
#include <basebmp/bitmapdevice.hxx>
|
||||
|
||||
#include <compositeiterator.hxx>
|
||||
#include <iteratortraits.hxx>
|
||||
|
||||
#include <accessor.hxx>
|
||||
#include <accessortraits.hxx>
|
||||
#include <accessoradapters.hxx>
|
||||
|
||||
#include <basebmp/color.hxx>
|
||||
#include <colormisc.hxx>
|
||||
|
||||
#include <greylevelformats.hxx>
|
||||
#include <paletteformats.hxx>
|
||||
#include <rgbmaskpixelformats.hxx>
|
||||
#include <rgb24pixelformats.hxx>
|
||||
|
||||
#include <basebmp/scanlineformats.hxx>
|
||||
#include <vigra/copyimage.hxx>
|
||||
#include <genericcolorimageaccessor.hxx>
|
||||
|
||||
#include <tools.hxx>
|
||||
|
||||
#include <rtl/alloc.h>
|
||||
#include <sal/log.hxx>
|
||||
#include <osl/diagnose.h>
|
||||
#include <o3tl/enumarray.hxx>
|
||||
|
||||
#include <basegfx/tools/tools.hxx>
|
||||
#include <basegfx/tools/canvastools.hxx>
|
||||
#include <basegfx/range/b2ibox.hxx>
|
||||
#include <basegfx/range/b2irange.hxx>
|
||||
#include <basegfx/range/b2drange.hxx>
|
||||
#include <basegfx/polygon/b2dpolygon.hxx>
|
||||
#include <basegfx/polygon/b2dpolygontools.hxx>
|
||||
#include <basegfx/polygon/b2dpolypolygontools.hxx>
|
||||
#include <basegfx/point/b2ipoint.hxx>
|
||||
#include <basegfx/vector/b2ivector.hxx>
|
||||
|
||||
namespace basebmp
|
||||
{
|
||||
|
||||
static const o3tl::enumarray<Format,sal_uInt8> bitsPerPixel =
|
||||
{
|
||||
0, // NONE
|
||||
1, // ONE_BIT_MSB_GREY
|
||||
1, // ONE_BIT_LSB_GREY
|
||||
1, // ONE_BIT_MSB_PAL
|
||||
1, // ONE_BIT_LSB_PAL
|
||||
4, // FOUR_BIT_MSB_GREY
|
||||
4, // FOUR_BIT_LSB_GREY
|
||||
4, // FOUR_BIT_MSB_PAL
|
||||
4, // FOUR_BIT_LSB_PAL
|
||||
8, // EIGHT_BIT_PAL
|
||||
8, // EIGHT_BIT_GREY
|
||||
16, // SIXTEEN_BIT_LSB_TC_MASK
|
||||
16, // SIXTEEN_BIT_MSB_TC_MASK
|
||||
24, // TWENTYFOUR_BIT_TC_MASK
|
||||
32, // THIRTYTWO_BIT_TC_MASK_BGRA
|
||||
32, // THIRTYTWO_BIT_TC_MASK_ARGB
|
||||
32, // THIRTYTWO_BIT_TC_MASK_ABGR
|
||||
32, // THIRTYTWO_BIT_TC_MASK_RGBA
|
||||
};
|
||||
|
||||
namespace
|
||||
{
|
||||
// Actual BitmapDevice implementation (templatized by accessor and iterator)
|
||||
|
||||
/** Implementation of the BitmapDevice interface
|
||||
|
||||
@tpl DestIterator
|
||||
Iterator to access bitmap memory
|
||||
|
||||
@tpl RawAccessor
|
||||
Raw accessor, to access pixel values directly
|
||||
|
||||
@tpl AccessorSelector
|
||||
Accessor adapter selector, which, when applying the nested
|
||||
template metafunction wrap_accessor to one of the raw bitmap
|
||||
accessors, yields a member type named 'type', which is a
|
||||
wrapped accessor that map color values.
|
||||
*/
|
||||
template< class DestIterator,
|
||||
class RawAccessor,
|
||||
class AccessorSelector > class BitmapRenderer :
|
||||
public BitmapDevice
|
||||
{
|
||||
public:
|
||||
typedef DestIterator dest_iterator_type;
|
||||
typedef RawAccessor raw_accessor_type;
|
||||
typedef AccessorSelector accessor_selector;
|
||||
|
||||
typedef typename AccessorSelector::template wrap_accessor<
|
||||
raw_accessor_type >::type dest_accessor_type;
|
||||
|
||||
dest_iterator_type maBegin;
|
||||
dest_accessor_type maAccessor;
|
||||
|
||||
BitmapRenderer( const basegfx::B2IBox& rBounds,
|
||||
Format nScanlineFormat,
|
||||
sal_Int32 nScanlineStride,
|
||||
sal_uInt8* pFirstScanline,
|
||||
dest_iterator_type begin,
|
||||
dest_accessor_type accessor,
|
||||
const RawMemorySharedArray& rMem,
|
||||
const PaletteMemorySharedVector& rPalette ) :
|
||||
BitmapDevice( rBounds, nScanlineFormat,
|
||||
nScanlineStride, pFirstScanline, rMem, rPalette ),
|
||||
maBegin( begin ),
|
||||
maAccessor( accessor )
|
||||
{}
|
||||
|
||||
private:
|
||||
|
||||
virtual Color getPixel_i(const basegfx::B2IPoint& rPt ) override
|
||||
{
|
||||
const DestIterator pixel( maBegin +
|
||||
vigra::Diff2D(rPt.getX(),
|
||||
rPt.getY()) );
|
||||
return maAccessor(pixel);
|
||||
}
|
||||
|
||||
template< typename Iterator, typename Acc > static
|
||||
void implDrawBitmapGeneric(const BitmapDeviceSharedPtr& rSrcBitmap,
|
||||
const Iterator& begin,
|
||||
const Acc& acc)
|
||||
{
|
||||
const basegfx::B2IVector& rSrcSize( rSrcBitmap->getSize() );
|
||||
const basegfx::B2IBox aRect(0, 0, rSrcSize.getX(),rSrcSize.getY());
|
||||
|
||||
GenericColorImageAccessor aSrcAcc( rSrcBitmap );
|
||||
|
||||
vigra::copyImage( vigra::Diff2D(), vigra::Diff2D() + bottomRight(aRect), aSrcAcc,
|
||||
begin, acc );
|
||||
}
|
||||
|
||||
virtual void convertBitmap_i(const BitmapDeviceSharedPtr& rSrcBitmap) override
|
||||
{
|
||||
implDrawBitmapGeneric(rSrcBitmap, maBegin, maAccessor);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
struct ImplBitmapDevice
|
||||
{
|
||||
/** Bitmap memory plus deleter.
|
||||
|
||||
Always points to the start of the mem
|
||||
*/
|
||||
RawMemorySharedArray mpMem;
|
||||
|
||||
/// Palette memory plus deleter (might be NULL)
|
||||
PaletteMemorySharedVector mpPalette;
|
||||
|
||||
/** Bounds of the device.
|
||||
|
||||
maBounds.getWidth()/getHeight() yield the true size of the
|
||||
device (i.e. the rectangle given by maBounds covers the device
|
||||
area under the including-the-bottommost-and-rightmost-pixels
|
||||
fill rule)
|
||||
*/
|
||||
basegfx::B2IBox maBounds;
|
||||
|
||||
/// Scanline format, as provided at the constructor
|
||||
Format mnScanlineFormat;
|
||||
|
||||
/// Scanline stride. Negative for bottom-to-top formats
|
||||
sal_Int32 mnScanlineStride;
|
||||
|
||||
/// raw ptr to 0th scanline. used for cloning a generic renderer
|
||||
sal_uInt8* mpFirstScanline;
|
||||
};
|
||||
|
||||
|
||||
BitmapDevice::BitmapDevice( const basegfx::B2IBox& rBounds,
|
||||
Format nScanlineFormat,
|
||||
sal_Int32 nScanlineStride,
|
||||
sal_uInt8* pFirstScanline,
|
||||
const RawMemorySharedArray& rMem,
|
||||
const PaletteMemorySharedVector& rPalette ) :
|
||||
mpImpl( new ImplBitmapDevice )
|
||||
{
|
||||
mpImpl->mpMem = rMem;
|
||||
mpImpl->mpPalette = rPalette;
|
||||
mpImpl->maBounds = rBounds;
|
||||
mpImpl->mnScanlineFormat = nScanlineFormat;
|
||||
mpImpl->mnScanlineStride = nScanlineStride;
|
||||
mpImpl->mpFirstScanline = pFirstScanline;
|
||||
}
|
||||
|
||||
BitmapDevice::~BitmapDevice()
|
||||
{
|
||||
// outline, because of internal ImplBitmapDevice
|
||||
SAL_INFO( "basebmp.bitmapdevice", "~BitmapDevice(" << this << ")" );
|
||||
}
|
||||
|
||||
basegfx::B2IVector BitmapDevice::getSize() const
|
||||
{
|
||||
return basegfx::B2IVector(
|
||||
mpImpl->maBounds.getMaxX() - mpImpl->maBounds.getMinX(),
|
||||
mpImpl->maBounds.getMaxY() - mpImpl->maBounds.getMinY() );
|
||||
}
|
||||
|
||||
Format BitmapDevice::getScanlineFormat() const
|
||||
{
|
||||
return mpImpl->mnScanlineFormat;
|
||||
}
|
||||
|
||||
sal_Int32 BitmapDevice::getScanlineStride() const
|
||||
{
|
||||
return mpImpl->mnScanlineStride;
|
||||
}
|
||||
|
||||
RawMemorySharedArray BitmapDevice::getBuffer() const
|
||||
{
|
||||
return mpImpl->mpMem;
|
||||
}
|
||||
|
||||
PaletteMemorySharedVector BitmapDevice::getPalette() const
|
||||
{
|
||||
return mpImpl->mpPalette;
|
||||
}
|
||||
|
||||
Color BitmapDevice::getPixel( const basegfx::B2IPoint& rPt )
|
||||
{
|
||||
if( mpImpl->maBounds.isInside(rPt) )
|
||||
return getPixel_i(rPt);
|
||||
|
||||
return Color();
|
||||
}
|
||||
|
||||
void BitmapDevice::convertBitmap( const BitmapDeviceSharedPtr& rSrcBitmap )
|
||||
{
|
||||
convertBitmap_i(rSrcBitmap);
|
||||
}
|
||||
|
||||
/// Produces a specialized renderer for the given pixel format
|
||||
template< class FormatTraits >
|
||||
BitmapDeviceSharedPtr createRenderer(
|
||||
const basegfx::B2IBox& rBounds,
|
||||
Format nScanlineFormat,
|
||||
sal_Int32 nScanlineStride,
|
||||
sal_uInt8* pFirstScanline,
|
||||
typename FormatTraits::accessor_selector::template wrap_accessor<
|
||||
typename FormatTraits::raw_accessor_type>::type const& rAccessor,
|
||||
boost::shared_array< sal_uInt8 > pMem,
|
||||
const PaletteMemorySharedVector& pPal )
|
||||
{
|
||||
typedef typename FormatTraits::iterator_type Iterator;
|
||||
typedef BitmapRenderer< Iterator,
|
||||
typename FormatTraits::raw_accessor_type,
|
||||
typename FormatTraits::accessor_selector
|
||||
> Renderer;
|
||||
|
||||
return BitmapDeviceSharedPtr(
|
||||
new Renderer( rBounds,
|
||||
nScanlineFormat,
|
||||
nScanlineStride,
|
||||
pFirstScanline,
|
||||
Iterator(
|
||||
reinterpret_cast<typename Iterator::value_type*>(
|
||||
pFirstScanline),
|
||||
nScanlineStride),
|
||||
rAccessor,
|
||||
pMem,
|
||||
pPal ));
|
||||
}
|
||||
|
||||
/// Create standard grey level palette
|
||||
PaletteMemorySharedVector createStandardPalette(
|
||||
const PaletteMemorySharedVector& pPal,
|
||||
sal_Int32 nNumEntries )
|
||||
{
|
||||
if( pPal || nNumEntries <= 0 )
|
||||
return pPal;
|
||||
|
||||
std::shared_ptr< std::vector<Color> > pLocalPal(
|
||||
new std::vector<Color>(nNumEntries) );
|
||||
|
||||
const sal_Int32 nIncrement( 0x00FFFFFF/nNumEntries );
|
||||
--nNumEntries;
|
||||
for( sal_Int32 i=0, c=0; i<nNumEntries; ++i,c+=nIncrement )
|
||||
pLocalPal->at(i) = Color(0xFF000000 | c);
|
||||
|
||||
pLocalPal->at(nNumEntries) = Color(0xFFFFFFFF);
|
||||
|
||||
return pLocalPal;
|
||||
}
|
||||
|
||||
template< class FormatTraits >
|
||||
BitmapDeviceSharedPtr createRenderer(
|
||||
const basegfx::B2IBox& rBounds,
|
||||
Format nScanlineFormat,
|
||||
sal_Int32 nScanlineStride,
|
||||
sal_uInt8* pFirstScanline,
|
||||
boost::shared_array< sal_uInt8 > pMem,
|
||||
const PaletteMemorySharedVector& pPal )
|
||||
{
|
||||
return createRenderer<FormatTraits>(rBounds,
|
||||
nScanlineFormat,
|
||||
nScanlineStride,
|
||||
pFirstScanline,
|
||||
typename FormatTraits::accessor_selector::template
|
||||
wrap_accessor<
|
||||
typename FormatTraits::raw_accessor_type>::type(),
|
||||
pMem,
|
||||
pPal );
|
||||
}
|
||||
|
||||
template< class FormatTraits >
|
||||
BitmapDeviceSharedPtr createRenderer(
|
||||
const basegfx::B2IBox& rBounds,
|
||||
Format nScanlineFormat,
|
||||
sal_Int32 nScanlineStride,
|
||||
sal_uInt8* pFirstScanline,
|
||||
boost::shared_array< sal_uInt8 > pMem,
|
||||
PaletteMemorySharedVector pPal,
|
||||
int nBitsPerPixel )
|
||||
{
|
||||
pPal = createStandardPalette(pPal,
|
||||
1UL << nBitsPerPixel);
|
||||
|
||||
OSL_ASSERT(pPal);
|
||||
return createRenderer<FormatTraits>(rBounds,
|
||||
nScanlineFormat,
|
||||
nScanlineStride,
|
||||
pFirstScanline,
|
||||
typename FormatTraits::accessor_selector::template
|
||||
wrap_accessor<
|
||||
typename FormatTraits::raw_accessor_type>::type(
|
||||
&pPal->at(0),
|
||||
pPal->size()),
|
||||
pMem,
|
||||
pPal );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
BitmapDeviceSharedPtr createBitmapDeviceImplInner( const basegfx::B2IVector& rSize,
|
||||
Format nScanlineFormat,
|
||||
boost::shared_array< sal_uInt8 > pMem,
|
||||
PaletteMemorySharedVector pPal )
|
||||
{
|
||||
OSL_ASSERT(rSize.getX() > 0 && rSize.getY() > 0);
|
||||
|
||||
if( nScanlineFormat <= Format::NONE ||
|
||||
nScanlineFormat > Format::LAST )
|
||||
return BitmapDeviceSharedPtr();
|
||||
|
||||
sal_uInt8 nBitsPerPixel = bitsPerPixel[nScanlineFormat];
|
||||
if (rSize.getX() > (SAL_MAX_INT32-7) / nBitsPerPixel)
|
||||
{
|
||||
SAL_WARN("basebmp", "suspicious bitmap width " <<
|
||||
rSize.getX() << " for depth " << nBitsPerPixel);
|
||||
return BitmapDeviceSharedPtr();
|
||||
}
|
||||
|
||||
const sal_uInt32 nScanlineStride = getBitmapDeviceStrideForWidth(nScanlineFormat, rSize.getX());
|
||||
|
||||
const sal_uInt32 nHeight(rSize.getY());
|
||||
|
||||
if (nHeight && nScanlineStride && nScanlineStride > SAL_MAX_INT32 / nHeight)
|
||||
{
|
||||
SAL_WARN( "basebmp", "suspicious massive alloc " << nScanlineStride << " * " << nHeight);
|
||||
return BitmapDeviceSharedPtr();
|
||||
}
|
||||
|
||||
const std::size_t nMemSize(nScanlineStride * nHeight);
|
||||
|
||||
if( !pMem )
|
||||
{
|
||||
pMem.reset(
|
||||
static_cast<sal_uInt8*>(rtl_allocateMemory( nMemSize )),
|
||||
&rtl_freeMemory );
|
||||
if (pMem.get() == nullptr && nMemSize != 0)
|
||||
return BitmapDeviceSharedPtr();
|
||||
memset(pMem.get(), 0, nMemSize);
|
||||
}
|
||||
|
||||
sal_uInt8* pFirstScanline = pMem.get();
|
||||
|
||||
basegfx::B2IBox aBounds(0,0,rSize.getX(),rSize.getY());
|
||||
|
||||
switch( nScanlineFormat )
|
||||
{
|
||||
|
||||
// one bit formats
|
||||
|
||||
case Format::OneBitMsbGrey:
|
||||
return createRenderer<PixelFormatTraits_GREY1_MSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::OneBitLsbGrey:
|
||||
return createRenderer<PixelFormatTraits_GREY1_LSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::OneBitMsbPal:
|
||||
return createRenderer<PixelFormatTraits_PAL1_MSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal,
|
||||
bitsPerPixel[nScanlineFormat] );
|
||||
|
||||
case Format::OneBitLsbPal:
|
||||
return createRenderer<PixelFormatTraits_PAL1_LSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal,
|
||||
bitsPerPixel[nScanlineFormat] );
|
||||
|
||||
|
||||
|
||||
// four bit formats
|
||||
|
||||
case Format::FourBitMsbGrey:
|
||||
return createRenderer<PixelFormatTraits_GREY4_MSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::FourBitLsbGrey:
|
||||
return createRenderer<PixelFormatTraits_GREY4_LSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::FourBitMsbPal:
|
||||
return createRenderer<PixelFormatTraits_PAL4_MSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal,
|
||||
bitsPerPixel[nScanlineFormat] );
|
||||
|
||||
case Format::FourBitLsbPal:
|
||||
return createRenderer<PixelFormatTraits_PAL4_LSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal,
|
||||
bitsPerPixel[nScanlineFormat] );
|
||||
|
||||
|
||||
|
||||
// eight bit formats
|
||||
|
||||
case Format::EightBitGrey:
|
||||
return createRenderer<PixelFormatTraits_GREY8>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::EightBitPal:
|
||||
return createRenderer<PixelFormatTraits_PAL8>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal,
|
||||
bitsPerPixel[nScanlineFormat] );
|
||||
|
||||
|
||||
|
||||
// sixteen bit formats
|
||||
|
||||
case Format::SixteenBitLsbTcMask:
|
||||
return createRenderer<PixelFormatTraits_RGB16_565_LSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::SixteenBitMsbTcMask:
|
||||
return createRenderer<PixelFormatTraits_RGB16_565_MSB>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
// twentyfour bit formats
|
||||
case Format::TwentyFourBitTcMask:
|
||||
return createRenderer<PixelFormatTraits_BGR24>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
// thirtytwo bit formats
|
||||
|
||||
case Format::ThirtyTwoBitTcMaskBGRA:
|
||||
return createRenderer<PixelFormatTraits_BGRA32_8888>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::ThirtyTwoBitTcMaskARGB:
|
||||
return createRenderer<PixelFormatTraits_ARGB32_8888>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::ThirtyTwoBitTcMaskABGR:
|
||||
return createRenderer<PixelFormatTraits_ABGR32_8888>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
case Format::ThirtyTwoBitTcMaskRGBA:
|
||||
return createRenderer<PixelFormatTraits_RGBA32_8888>(
|
||||
aBounds, nScanlineFormat, nScanlineStride,
|
||||
pFirstScanline, pMem, pPal );
|
||||
|
||||
default:
|
||||
assert(false); // this cannot happen
|
||||
}
|
||||
|
||||
// TODO(F3): other formats not yet implemented
|
||||
return BitmapDeviceSharedPtr();
|
||||
}
|
||||
|
||||
BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& rSize,
|
||||
Format nScanlineFormat,
|
||||
boost::shared_array< sal_uInt8 > pMem,
|
||||
PaletteMemorySharedVector pPal )
|
||||
{
|
||||
BitmapDeviceSharedPtr result( createBitmapDeviceImplInner( rSize, nScanlineFormat, pMem, pPal ) );
|
||||
|
||||
#ifdef SAL_LOG_INFO
|
||||
std::ostringstream subset;
|
||||
|
||||
SAL_INFO( "basebmp.bitmapdevice",
|
||||
"createBitmapDevice: "
|
||||
<< rSize.getX() << "x" << rSize.getY()
|
||||
<< subset.str()
|
||||
<< " = " << result.get() );
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
sal_Int32 getBitmapDeviceStrideForWidth(Format nScanlineFormat, sal_Int32 nWidth)
|
||||
{
|
||||
sal_uInt8 nBitsPerPixel = bitsPerPixel[nScanlineFormat];
|
||||
// round up to full 8 bit, divide by 8
|
||||
sal_Int32 nScanlineStride = (nWidth*nBitsPerPixel + 7) >> 3;
|
||||
|
||||
// pixman (cairo) and GDI (windows) pad to multiples of 32bits
|
||||
// so do the same to be easily compatible
|
||||
nScanlineStride = (nScanlineStride + 3) & ~0x3;
|
||||
|
||||
return nScanlineStride;
|
||||
}
|
||||
|
||||
BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize,
|
||||
Format nScanlineFormat )
|
||||
{
|
||||
return createBitmapDeviceImpl( rSize,
|
||||
nScanlineFormat,
|
||||
boost::shared_array< sal_uInt8 >(),
|
||||
PaletteMemorySharedVector() );
|
||||
}
|
||||
|
||||
BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize,
|
||||
Format nScanlineFormat,
|
||||
const PaletteMemorySharedVector& rPalette )
|
||||
{
|
||||
return createBitmapDeviceImpl( rSize,
|
||||
nScanlineFormat,
|
||||
boost::shared_array< sal_uInt8 >(),
|
||||
rPalette );
|
||||
}
|
||||
|
||||
BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize,
|
||||
Format nScanlineFormat,
|
||||
const RawMemorySharedArray& rMem,
|
||||
const PaletteMemorySharedVector& rPalette )
|
||||
{
|
||||
return createBitmapDeviceImpl( rSize,
|
||||
nScanlineFormat,
|
||||
rMem,
|
||||
rPalette );
|
||||
}
|
||||
|
||||
BitmapDeviceSharedPtr cloneBitmapDevice(const BitmapDeviceSharedPtr& rProto)
|
||||
{
|
||||
const basegfx::B2IVector& rSrcSize(rProto->getSize());
|
||||
|
||||
BitmapDeviceSharedPtr aCopy = createBitmapDeviceImpl(rSrcSize,
|
||||
rProto->getScanlineFormat(),
|
||||
boost::shared_array< sal_uInt8 >(),
|
||||
rProto->getPalette() );
|
||||
|
||||
const sal_Int32 nSrcHeight = rSrcSize.getY();
|
||||
char* dstBuf = reinterpret_cast<char*>(aCopy->getBuffer().get());
|
||||
char* srcBuf = reinterpret_cast<char*>(rProto->getBuffer().get());
|
||||
const sal_Int32 nStride = rProto->getScanlineStride();
|
||||
memcpy(dstBuf, srcBuf, nStride * nSrcHeight);
|
||||
|
||||
return aCopy;
|
||||
}
|
||||
|
||||
} // namespace basebmp
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -1,159 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,45 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -1,30 +0,0 @@
|
||||
/* -*- 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: */
|
||||
@@ -236,7 +236,6 @@ class Parser:
|
||||
"animations" : 1,
|
||||
"avmedia" : 1,
|
||||
"basctl" : 1,
|
||||
"basebmp" : 1,
|
||||
"basegfx" : 1,
|
||||
"basic" : 1,
|
||||
"binaryurp" : 1,
|
||||
|
||||
@@ -188,7 +188,6 @@ merge abp::OModuleResourceClient with abp::OABSPilotUno
|
||||
merge accessibility::GridControlAccessibleElement with accessibility::AccessibleGridControlTableBase
|
||||
merge accessibility::IComboListBoxHelper with VCLListBoxHelper
|
||||
merge basctl::docs::IDocumentDescriptorFilter with basctl::(anonymous namespace)::FilterDocuments
|
||||
merge basebmp::BitmapDevice with basebmp::(anonymous namespace)::BitmapRenderer
|
||||
merge basegfx::InterpolatorProvider3D with basegfx::RasterConverter3D
|
||||
merge bib::OComponentListener with bib::OLoadListener
|
||||
merge bib::OLoadListener with bib::FormControlContainer
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/* -*- 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_BASEBMPDLLAPI_H
|
||||
#define INCLUDED_BASEBMP_BASEBMPDLLAPI_H
|
||||
|
||||
#include <sal/types.h>
|
||||
|
||||
#if defined BASEBMP_DLLIMPLEMENTATION
|
||||
#define BASEBMP_DLLPUBLIC SAL_DLLPUBLIC_EXPORT
|
||||
#else
|
||||
#define BASEBMP_DLLPUBLIC SAL_DLLPUBLIC_IMPORT
|
||||
#endif
|
||||
#define BASEBMP_DLLPRIVATE SAL_DLLPRIVATE
|
||||
|
||||
#endif /* INCLUDED_BASEBMP_BASEBMPDLLAPI_H */
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -1,168 +0,0 @@
|
||||
/* -*- 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_BITMAPDEVICE_HXX
|
||||
#define INCLUDED_BASEBMP_BITMAPDEVICE_HXX
|
||||
|
||||
#include <sal/types.h>
|
||||
#include <basebmp/scanlineformats.hxx>
|
||||
#include <basebmp/basebmpdllapi.h>
|
||||
|
||||
#include <boost/shared_array.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace basegfx
|
||||
{
|
||||
class B2IPoint;
|
||||
class B2DPoint;
|
||||
class B2IVector;
|
||||
class B2IBox;
|
||||
}
|
||||
|
||||
namespace basebmp
|
||||
{
|
||||
|
||||
// Temporary. Use like the tools color object
|
||||
class Color;
|
||||
typedef std::shared_ptr< class BitmapDevice > BitmapDeviceSharedPtr;
|
||||
typedef boost::shared_array< sal_uInt8 > RawMemorySharedArray;
|
||||
typedef std::shared_ptr< const std::vector<Color> > PaletteMemorySharedVector;
|
||||
|
||||
struct ImplBitmapDevice;
|
||||
|
||||
/** Definition of BitmapDevice interface
|
||||
|
||||
Use the createBitmapDevice() function to create instances.
|
||||
|
||||
Implementation note: the clip mask and bitmap parameter instances
|
||||
of BitmapDevice that are passed to individual BitmapDevice
|
||||
instances work best with 1 bit grey masks for the clip and a
|
||||
format matching that of the target BitmapDevice for the other
|
||||
parameters.
|
||||
*/
|
||||
class BASEBMP_DLLPUBLIC BitmapDevice : public std::enable_shared_from_this<BitmapDevice>
|
||||
{
|
||||
public:
|
||||
/** Query size of device in pixel columns (X) and rows (Y, "scanlines")
|
||||
*/
|
||||
basegfx::B2IVector getSize() const;
|
||||
|
||||
/** Query type of scanline memory format
|
||||
*/
|
||||
Format getScanlineFormat() const;
|
||||
|
||||
/** Query byte offset to get from scanline n to scanline n+1
|
||||
|
||||
@return the scanline stride in bytes.
|
||||
*/
|
||||
sal_Int32 getScanlineStride() const;
|
||||
|
||||
/** Get pointer to frame buffer
|
||||
|
||||
@return a shared ptr to the bitmap buffer memory. As this is a
|
||||
shared ptr, you can freely store and use the pointer, even
|
||||
after this object has been deleted.
|
||||
*/
|
||||
RawMemorySharedArray getBuffer() const;
|
||||
|
||||
/** Get pointer to palette
|
||||
|
||||
The returned pointer is const on purpose, since the
|
||||
BitmapDevice might internally cache lookup information. Don't
|
||||
modify the returned data, unless you want to enter the realm
|
||||
of completely undefined behaviour.
|
||||
|
||||
@return shared pointer to vector of Color entries.
|
||||
*/
|
||||
PaletteMemorySharedVector getPalette() const;
|
||||
|
||||
/** Get color value at given pixel
|
||||
*/
|
||||
Color getPixel( const basegfx::B2IPoint& rPt );
|
||||
|
||||
/** Draw another bitmap into this device
|
||||
|
||||
@param rSrcBitmap
|
||||
Bitmap to render into this one.
|
||||
*/
|
||||
void convertBitmap( const BitmapDeviceSharedPtr& rSrcBitmap );
|
||||
|
||||
protected:
|
||||
BASEBMP_DLLPRIVATE BitmapDevice( const basegfx::B2IBox& rBounds,
|
||||
Format nScanlineFormat,
|
||||
sal_Int32 nScanlineStride,
|
||||
sal_uInt8* pFirstScanline,
|
||||
const RawMemorySharedArray& rMem,
|
||||
const PaletteMemorySharedVector& rPalette );
|
||||
BASEBMP_DLLPRIVATE virtual ~BitmapDevice();
|
||||
BitmapDevice(const BitmapDevice&) = delete;
|
||||
BitmapDevice& operator=( const BitmapDevice& ) = delete;
|
||||
|
||||
private:
|
||||
|
||||
BASEBMP_DLLPRIVATE virtual Color getPixel_i( const basegfx::B2IPoint& rPt ) = 0;
|
||||
|
||||
BASEBMP_DLLPRIVATE virtual void convertBitmap_i( const BitmapDeviceSharedPtr& rSrcBitmap ) = 0;
|
||||
|
||||
std::unique_ptr< ImplBitmapDevice > mpImpl;
|
||||
};
|
||||
|
||||
/** Function to calculate a suitable BitmapDevice Scanline Stride for a given scanline format and width
|
||||
* you can provide this value or any larger value.
|
||||
*/
|
||||
sal_Int32 BASEBMP_DLLPUBLIC getBitmapDeviceStrideForWidth(Format nScanlineFormat, sal_Int32 nWidth);
|
||||
|
||||
/** Function to create a BitmapDevice for given scanline format
|
||||
*/
|
||||
BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC createBitmapDevice( const basegfx::B2IVector& rSize,
|
||||
Format nScanlineFormat );
|
||||
|
||||
/** Function to create a BitmapDevice for given scanline format
|
||||
with the given palette
|
||||
|
||||
Note: the provided palette must have sufficient size, to satisfy
|
||||
lookups for the whole range of pixel values from the specified
|
||||
format.
|
||||
*/
|
||||
BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC createBitmapDevice( const basegfx::B2IVector& rSize,
|
||||
Format nScanlineFormat,
|
||||
const PaletteMemorySharedVector& rPalette );
|
||||
|
||||
/** Function to create a BitmapDevice for given scanline format
|
||||
from the given piece of raw memory and palette
|
||||
|
||||
Note: the provided memory must have sufficient size, to store the
|
||||
image of the specified area and format.
|
||||
*/
|
||||
BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC createBitmapDevice( const basegfx::B2IVector& rSize,
|
||||
Format nScanlineFormat,
|
||||
const RawMemorySharedArray& rMem,
|
||||
const PaletteMemorySharedVector& rPalette );
|
||||
|
||||
|
||||
/** Function to clone a BitmapDevice from a given prototype.
|
||||
*/
|
||||
BitmapDeviceSharedPtr BASEBMP_DLLPUBLIC cloneBitmapDevice(const BitmapDeviceSharedPtr& rProto);
|
||||
|
||||
}
|
||||
|
||||
#endif /* INCLUDED_BASEBMP_BITMAPDEVICE_HXX */
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -1,93 +0,0 @@
|
||||
/* -*- 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_COLOR_HXX
|
||||
#define INCLUDED_BASEBMP_COLOR_HXX
|
||||
|
||||
#include <sal/types.h>
|
||||
#include <rtl/math.hxx>
|
||||
|
||||
namespace basebmp
|
||||
{
|
||||
|
||||
class Color
|
||||
{
|
||||
private:
|
||||
sal_uInt32 mnColor;
|
||||
|
||||
public:
|
||||
typedef sal_uInt32 value_type;
|
||||
typedef sal_uInt8 component_type;
|
||||
|
||||
Color() : mnColor(0) {}
|
||||
explicit Color( sal_uInt32 nVal ) : mnColor(nVal) {}
|
||||
Color( sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue ) :
|
||||
mnColor( ((sal_uInt32)nRed << 16) | ((sal_uInt32)nGreen << 8) | nBlue )
|
||||
{}
|
||||
|
||||
void setRed( sal_uInt8 nRed ) { mnColor &= ~0x00FF0000UL; mnColor |= (sal_uInt32)nRed << 16; }
|
||||
void setGreen( sal_uInt8 nGreen ) { mnColor &= ~0x0000FF00UL; mnColor |= (sal_uInt32)nGreen << 8; }
|
||||
void setBlue( sal_uInt8 nBlue ) { mnColor &= ~0x000000FFUL; mnColor |= nBlue; }
|
||||
|
||||
void setGrey( sal_uInt8 nGreyVal ) { mnColor = (sal_uInt32)nGreyVal << 16 | (sal_uInt32)nGreyVal << 8 | nGreyVal; }
|
||||
|
||||
sal_uInt8 getRed() const { return 0xFF & (sal_uInt8)(mnColor >> 16); }
|
||||
sal_uInt8 getGreen() const { return 0xFF & (sal_uInt8)(mnColor >> 8); }
|
||||
sal_uInt8 getBlue() const { return 0xFF & (sal_uInt8)mnColor; }
|
||||
|
||||
sal_uInt8 getGreyscale() const { return (sal_uInt8)((getBlue()*28UL +
|
||||
getGreen()*151 +
|
||||
getRed()*77) / 256); }
|
||||
|
||||
sal_uInt32 toInt32() const { return mnColor; }
|
||||
|
||||
bool operator!() const { return mnColor == 0; }
|
||||
Color operator&( sal_uInt32 nMask ) const { return Color(mnColor & nMask); }
|
||||
Color operator^( Color col ) const { return Color(col.getRed()^getRed(),
|
||||
col.getGreen()^getGreen(),
|
||||
col.getBlue()^getBlue()); }
|
||||
Color operator-( Color col ) const { return Color((sal_uInt8)abs((int)getRed()-col.getRed()),
|
||||
(sal_uInt8)abs((int)getGreen()-col.getGreen()),
|
||||
(sal_uInt8)abs((int)getBlue()-col.getBlue())); }
|
||||
Color operator+( Color col ) const { return Color(getRed()+col.getRed(),
|
||||
getGreen()+col.getGreen(),
|
||||
getBlue()+col.getBlue()); }
|
||||
Color operator*( Color col ) const { return Color((sal_uInt8)((sal_uInt32)col.getRed()*getRed()/SAL_MAX_UINT8),
|
||||
(sal_uInt8)((sal_uInt32)col.getGreen()*getGreen()/SAL_MAX_UINT8),
|
||||
(sal_uInt8)((sal_uInt32)col.getBlue()*getBlue()/SAL_MAX_UINT8)); }
|
||||
Color operator*( sal_uInt8 n ) const { return Color((sal_uInt8)((sal_uInt32)n*getRed()/SAL_MAX_UINT8),
|
||||
(sal_uInt8)((sal_uInt32)n*getGreen()/SAL_MAX_UINT8),
|
||||
(sal_uInt8)((sal_uInt32)n*getBlue()/SAL_MAX_UINT8)); }
|
||||
Color operator*( double n ) const { return Color((sal_uInt8)(n*getRed()+.5),
|
||||
(sal_uInt8)(n*getGreen()+.5),
|
||||
(sal_uInt8)(n*getBlue()+.5)); }
|
||||
bool operator==( const Color& rhs ) const { return (getRed()==rhs.getRed() &&
|
||||
getGreen()==rhs.getGreen() &&
|
||||
getBlue()==rhs.getBlue()); }
|
||||
bool operator!=( const Color& rhs ) const { return !(*this==rhs); }
|
||||
double magnitude() const { return sqrt((double)getRed()*getRed()
|
||||
+ getGreen()*getGreen()
|
||||
+ getBlue()*getBlue()); }
|
||||
};
|
||||
|
||||
} // namespace basebmp
|
||||
|
||||
#endif /* INCLUDED_BASEBMP_COLOR_HXX */
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -1,60 +0,0 @@
|
||||
/* -*- 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_SCANLINEFORMATS_HXX
|
||||
#define INCLUDED_BASEBMP_SCANLINEFORMATS_HXX
|
||||
|
||||
#include <sal/config.h>
|
||||
|
||||
/* Definition of Scanline formats */
|
||||
|
||||
namespace basebmp {
|
||||
|
||||
enum class Format
|
||||
{
|
||||
NONE,
|
||||
OneBitMsbGrey,
|
||||
OneBitLsbGrey,
|
||||
OneBitMsbPal,
|
||||
OneBitLsbPal,
|
||||
FourBitMsbGrey,
|
||||
FourBitLsbGrey,
|
||||
FourBitMsbPal,
|
||||
FourBitLsbPal,
|
||||
EightBitPal,
|
||||
EightBitGrey,
|
||||
SixteenBitLsbTcMask,
|
||||
SixteenBitMsbTcMask,
|
||||
TwentyFourBitTcMask,
|
||||
// The order of the channels code letters indicates the order of the
|
||||
// channel bytes in memory
|
||||
ThirtyTwoBitTcMaskBGRA,
|
||||
ThirtyTwoBitTcMaskARGB,
|
||||
ThirtyTwoBitTcMaskABGR,
|
||||
ThirtyTwoBitTcMaskRGBA,
|
||||
LAST = ThirtyTwoBitTcMaskRGBA
|
||||
};
|
||||
|
||||
const char *formatName(Format nScanlineFormat);
|
||||
|
||||
}
|
||||
|
||||
#endif /* INCLUDED_BASEBMP_SCANLINEFORMATS_HXX */
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
@@ -35,10 +35,6 @@ certain functionality.
|
||||
|
||||
@li @c basctl.basicide
|
||||
|
||||
@section basebmp
|
||||
|
||||
@li @c basebmp.bitmapdevice
|
||||
|
||||
@section basic
|
||||
|
||||
@li @c basic
|
||||
@@ -521,7 +517,6 @@ certain functionality.
|
||||
@section other
|
||||
|
||||
@li @c accessibility
|
||||
@li @c basebmp
|
||||
@li @c basegfx
|
||||
@li @c binaryurp
|
||||
@li @c configmgr
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
# we link all object files from these libraries into one, merged library
|
||||
MERGE_LIBRARY_LIST := \
|
||||
avmedia \
|
||||
$(if $(filter $(OS),ANDROID),,basebmp) \
|
||||
basegfx \
|
||||
canvastools \
|
||||
comphelper \
|
||||
|
||||
Reference in New Issue
Block a user