Scroom 0.14-48-ga0fee447
Loading...
Searching...
No Matches
TransformPresentation Class Reference

#include <transformpresentation.hh>

Inheritance diagram for TransformPresentation:
Inheritance graph
Collaboration diagram for TransformPresentation:
Collaboration graph

Public Types

using Ptr = std::shared_ptr< TransformPresentation >
 
- Public Types inherited from PresentationInterface
using Ptr = std::shared_ptr< PresentationInterface >
 
using WeakPtr = std::weak_ptr< PresentationInterface >
 
- Public Types inherited from Viewable
using Ptr = std::shared_ptr< Viewable >
 
using WeakPtr = std::weak_ptr< Viewable >
 
- Public Types inherited from Scroom::Utils::Observable< T >
using Observer = std::shared_ptr< T >
 
using Ptr = std::shared_ptr< Observable< T > >
 
- Public Types inherited from Colormappable
using Ptr = std::shared_ptr< Colormappable >
 
using WeakPtr = std::weak_ptr< Colormappable >
 
- Public Types inherited from PipetteViewInterface
using Ptr = std::shared_ptr< PipetteViewInterface >
 
- Public Types inherited from ShowMetadataInterface
using Ptr = std::shared_ptr< ShowMetadataInterface >
 

Public Member Functions

void open (ViewInterface::WeakPtr vi) override
 
void close (ViewInterface::WeakPtr vi) override
 
Scroom::Utils::Rectangle< double > getRect () override
 
void redraw (ViewInterface::Ptr const &vi, cairo_t *cr, Scroom::Utils::Rectangle< double > presentationArea, int zoom) override
 
bool getProperty (const std::string &name, std::string &value) override
 
bool isPropertyDefined (const std::string &name) override
 
std::string getTitle () override
 
Scroom::Utils::Context::ConstPtr getContext () const override
 
PipetteLayerOperations::PipetteColor getPixelAverages (Scroom::Utils::Rectangle< double > area) override
 
void setColormap (Colormap::Ptr colormap) override
 
Colormap::Ptr getOriginalColormap () override
 
int getNumberOfColors () override
 
Color getMonochromeColor () override
 
void setMonochromeColor (const Color &c) override
 
void setTransparentBackground () override
 
void disableTransparentBackground () override
 
bool getTransparentBackground () override
 
void showMetadata (GtkWindow *parent) override
 
- Public Member Functions inherited from Scroom::Utils::Observable< T >
 Observable ()
 
 ~Observable () override
 
 Observable (const Observable &)=delete
 
 Observable (Observable &&)=delete
 
Observable operator= (const Observable &)=delete
 
Observable operator= (Observable &&)=delete
 
Scroom::Bookkeeping::Token registerStrongObserver (Observer const &observer)
 
Scroom::Bookkeeping::Token registerObserver (ObserverWeak const &observer)
 
- Public Member Functions inherited from Scroom::Utils::Base
 Base ()=default
 
 Base (const Base &)=delete
 
 Base (Base &&)=delete
 
Baseoperator= (const Base &)=delete
 
Baseoperator= (Base &&)=delete
 
virtual ~Base ()=default
 
template<typename R >
std::shared_ptr< R > shared_from_this ()
 
template<typename R >
std::shared_ptr< R const > shared_from_this () const
 
For monochrome presentations: Set/Get the current color
Manipulate the "Transparent Background" setting of the presentation

Static Public Member Functions

static Ptr create (PresentationInterface::Ptr const &presentation, TransformationData::Ptr const &transformationData)
 

Private Member Functions

 TransformPresentation (PresentationInterface::Ptr const &presentation, TransformationData::Ptr transformationData)
 

Private Attributes

TransformationData::Ptr transformationData
 
PresentationInterface::Ptr presentation
 
Colormappable::Ptr colormappable
 
ShowMetadataInterface::Ptr showMetaDataInterface
 
Scroom::Utils::WeakKeyMap< ViewInterface::WeakPtr, Detail::ViewData::PtrviewData
 
Scroom::Utils::RecursiveContext::Ptr context
 

Additional Inherited Members

- Protected Member Functions inherited from PresentationBase
void observerAdded (Viewable::Ptr const &viewable, Scroom::Bookkeeping::Token const &t) override
 
- Protected Member Functions inherited from Scroom::Utils::Observable< T >
std::list< ObservergetObservers ()
 
virtual void observerAdded (Observer const &observer, Scroom::Bookkeeping::Token const &token)
 

Member Typedef Documentation

◆ Ptr

Constructor & Destructor Documentation

◆ TransformPresentation()

TransformPresentation::TransformPresentation ( PresentationInterface::Ptr const &  presentation,
TransformationData::Ptr  transformationData 
)
private
47 : transformationData(std::move(transformationData_))
48 , presentation(presentation_)
49 , colormappable(std::dynamic_pointer_cast<Colormappable>(presentation_))
50 , showMetaDataInterface(std::dynamic_pointer_cast<ShowMetadataInterface>(presentation_))
52{
53 context->add(presentation->getContext());
54 auto aspectRatio = transformationData->getAspectRatio();
55
59 set(
60 context,
64 }
65 );
67}
map set(2, 5)
std::map< std::string, ITweakSelection::Ptr > Map
Definition tweak-view.hh:45
static Ptr create()
Definition context.cc:16
static ITweakSelection::Ptr create(const Point< double > &aspectRatio_)
Definition tweak-view.cc:153
static ITweakSelection::Ptr create(const Point< double > &aspectRatio_)
Definition tweak-view.cc:165
static ITweakPositionTextBox::Ptr create(const Point< double > &aspectRatio_={1.0, 1.0})
Definition tweak-view.cc:182
static ITweakPresentationPosition::Ptr create(const Point< double > &aspectRatio_)
Definition tweak-view.cc:101
static ITweakRulers::Ptr create(const Point< double > &aspectRatio_={1.0, 1.0})
Definition tweak-view.cc:122
ShowMetadataInterface::Ptr showMetaDataInterface
Definition transformpresentation.hh:89
PresentationInterface::Ptr presentation
Definition transformpresentation.hh:87
Scroom::Utils::RecursiveContext::Ptr context
Definition transformpresentation.hh:91
Colormappable::Ptr colormappable
Definition transformpresentation.hh:88
TransformationData::Ptr transformationData
Definition transformpresentation.hh:86
const std::string GRID("GridSelection")
const std::string PIXEL("PixelSelection")
Here is the call graph for this function:

Member Function Documentation

◆ close()

void TransformPresentation::close ( ViewInterface::WeakPtr  vi)
overridevirtual

Gets called just before the View is destroyed

Precondition
Should be called from within a Gdk critical section (i.e. between gdk_threads_enter() and gdk_threads_leave() calls)

Reimplemented from PresentationBase.

91{
92 auto data = viewData.at(viewInterface);
93 viewData.erase(viewInterface);
94
95 PresentationBase::close(viewInterface);
96 presentation->close(data);
97}
uint8_t data
Definition blob-tests.cc:36
void close(ViewInterface::WeakPtr vi) override
Definition presentationinterface.cc:23
Scroom::Utils::WeakKeyMap< ViewInterface::WeakPtr, Detail::ViewData::Ptr > viewData
Definition transformpresentation.hh:90
Here is the call graph for this function:

◆ create()

TransformPresentation::Ptr TransformPresentation::create ( PresentationInterface::Ptr const &  presentation,
TransformationData::Ptr const &  transformationData 
)
static
71{
73}
Definition transformpresentation.hh:81
std::shared_ptr< TransformPresentation > Ptr
Definition transformpresentation.hh:83

Referenced by anonymous_namespace{tiledbitmappresentation.cc}::OpenTiledBitmapAsPresentation::open().

Here is the caller graph for this function:

◆ disableTransparentBackground()

void TransformPresentation::disableTransparentBackground ( )
overridevirtual

Implements Colormappable.

156{ colormappable->disableTransparentBackground(); }

◆ getContext()

Scroom::Utils::Context::ConstPtr TransformPresentation::getContext ( ) const
overridevirtual

Implements PresentationInterface.

176{ return context; }

◆ getMonochromeColor()

Color TransformPresentation::getMonochromeColor ( )
overridevirtual

Implements Colormappable.

150{ return colormappable->getMonochromeColor(); }

◆ getNumberOfColors()

int TransformPresentation::getNumberOfColors ( )
overridevirtual

Retrieve the number of colors in use by the presentation

Implements Colormappable.

148{ return colormappable->getNumberOfColors(); }

◆ getOriginalColormap()

Colormap::Ptr TransformPresentation::getOriginalColormap ( )
overridevirtual

Retrieve the images colormap (if any)

Implements Colormappable.

146{ return colormappable->getOriginalColormap(); }

◆ getPixelAverages()

PipetteLayerOperations::PipetteColor TransformPresentation::getPixelAverages ( Scroom::Utils::Rectangle< double >  area)
overridevirtual

Returns the average pixel values for each component, contained in the area.

Parameters
areaselected area to get the pixel values from.

Implements PipetteViewInterface.

170{
171 PipetteViewInterface::Ptr const pipettePresentation = std::dynamic_pointer_cast<PipetteViewInterface>(presentation);
172 require(pipettePresentation);
173 return pipettePresentation->getPixelAverages(area / transformationData->getAspectRatio());
174}
#define require(expr)
Definition assertions.hh:30
std::shared_ptr< PipetteViewInterface > Ptr
Definition pipetteviewinterface.hh:21

◆ getProperty()

bool TransformPresentation::getProperty ( const std::string &  name,
std::string &  value 
)
overridevirtual

Return the value of the requested property

Parameters
[in]nameThe name of the requested property
[out]valueThe value of the requested property
Return values
trueif the property existed
falseif the property didn't exist

Implements PresentationInterface.

136{
137 return presentation->getProperty(name, value);
138}
const uint8_t value
Definition blob-tests.cc:114

◆ getRect()

Scroom::Utils::Rectangle< double > TransformPresentation::getRect ( )
overridevirtual

Return the dimensions of your presentation

Implements PresentationInterface.

76{
77 return presentation->getRect() * transformationData->getAspectRatio();
78}

◆ getTitle()

std::string TransformPresentation::getTitle ( )
overridevirtual

Return the title of the presentation

Implements PresentationInterface.

142{ return presentation->getTitle(); }

◆ getTransparentBackground()

bool TransformPresentation::getTransparentBackground ( )
overridevirtual

Implements Colormappable.

158{ return colormappable->getTransparentBackground(); }

◆ isPropertyDefined()

bool TransformPresentation::isPropertyDefined ( const std::string &  name)
overridevirtual

Return true if the named property exists

Implements PresentationInterface.

140{ return presentation->isPropertyDefined(name); }

◆ open()

void TransformPresentation::open ( ViewInterface::WeakPtr  vi)
overridevirtual

Gets called just after the View is created

Precondition
Should be called from within a Gdk critical section (i.e. between gdk_threads_enter() and gdk_threads_leave() calls)

Reimplemented from PresentationBase.

81{
82 auto [it, inserted] = viewData.insert({viewInterface, Detail::ViewData::create(viewInterface)});
83 require(inserted);
84 auto& [_, data] = *it;
85
86 presentation->open(data);
87 PresentationBase::open(viewInterface);
88}
static ViewData::Ptr create(const ViewInterface::WeakPtr &parent)
Definition transformpresentation.cc:203
void open(ViewInterface::WeakPtr vi) override
Definition presentationinterface.cc:11
SampleIterator< const uint8_t > it(testData, 0, bps)
Here is the call graph for this function:

◆ redraw()

void TransformPresentation::redraw ( ViewInterface::Ptr const &  vi,
cairo_t *  cr,
Scroom::Utils::Rectangle< double >  presentationArea,
int  zoom 
)
overridevirtual

Draw the requested ara at the requested zoom level

Parameters
viThe ViewInterface on whose behalf the request is made
crThe context to draw the area on
presentationAreathe area that is to be drawn. The given x and y coordinates should map on 0,0 of the given context cr.
zoomThe requested zoom level. One pixel of your presentation should have size 2**zoom when drawn. zoom may be negative.

Implements PresentationInterface.

105{
106 Scroom::Utils::Point<double> const aspectRatio = transformationData->getAspectRatio();
107 const auto data = viewData.at(vi);
108
109 if(data->presentationArea != presentationArea || data->zoom != zoom)
110 {
111 data->image.reset();
112 }
113 if(!data->image)
114 {
115 auto pixelSize = pixelSizeFromZoom(zoom);
116 auto viewArea = ceil((presentationArea * pixelSize / aspectRatio).getSize()).to<int>();
117
118 data->image = Scroom::Bitmap::BitmapSurface::create(viewArea.x, viewArea.y, CAIRO_FORMAT_ARGB32);
119
120 cairo_surface_t* surface = data->image->get();
121 cairo_t* image_cr = cairo_create(surface);
122
123 presentation->redraw(data, image_cr, presentationArea / aspectRatio, zoom);
124
125 cairo_destroy(image_cr);
126 }
127
128 cairo_save(cr);
129 cairo_scale(cr, aspectRatio.x, aspectRatio.y);
130 cairo_set_source_surface(cr, data->image->get(), 0, 0);
131 cairo_paint(cr);
132 cairo_restore(cr);
133}
double pixelSizeFromZoom(int zoom)
Definition cairo-helpers.cc:123
static Ptr create(int width, int height, cairo_format_t format)
Definition bitmap-helpers.cc:13
Definition point.hh:28
value_type y
Definition point.hh:112
value_type x
Definition point.hh:111
Point< T > ceil(Point< T > p)
Definition point.hh:228
ViewInterface::Ptr const vi
Definition pipette-tests.cc:186
cairo_destroy(cr)
cairo_surface_t * surface
Definition transformpresentation_test.cc:71
cairo_t * cr
Definition transformpresentation_test.cc:72
Here is the call graph for this function:

◆ setColormap()

void TransformPresentation::setColormap ( Colormap::Ptr  colormap)
overridevirtual

Request that the presentation use the given colormap

Implements Colormappable.

144{ colormappable->setColormap(colormap); }
Colormap::Ptr const colormap
Definition colormaphelpers_test.cc:55

◆ setMonochromeColor()

void TransformPresentation::setMonochromeColor ( const Color c)
overridevirtual

Implements Colormappable.

152{ colormappable->setMonochromeColor(c); }
Semaphore c(0)

◆ setTransparentBackground()

void TransformPresentation::setTransparentBackground ( )
overridevirtual

Implements Colormappable.

154{ colormappable->setTransparentBackground(); }

◆ showMetadata()

void TransformPresentation::showMetadata ( GtkWindow *  parent)
overridevirtual

Request to show a window containing the presentation metadata

Parameters
parentthe parent window, if found. Nullptr otherwise

Implements ShowMetadataInterface.

160{ showMetaDataInterface->showMetadata(parent); }

Member Data Documentation

◆ colormappable

◆ context

Scroom::Utils::RecursiveContext::Ptr TransformPresentation::context
private

◆ presentation

◆ showMetaDataInterface

ShowMetadataInterface::Ptr TransformPresentation::showMetaDataInterface
private

Referenced by showMetadata().

◆ transformationData

TransformationData::Ptr TransformPresentation::transformationData
private

◆ viewData

Scroom::Utils::WeakKeyMap<ViewInterface::WeakPtr, Detail::ViewData::Ptr> TransformPresentation::viewData
private

Referenced by close(), open(), and redraw().


The documentation for this class was generated from the following files: