Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
TiledBitmap Class Reference

#include <tiled-bitmap.hh>

Inheritance diagram for TiledBitmap:
Inheritance graph
Collaboration diagram for TiledBitmap:
Collaboration graph

Public Types

using Ptr = std::shared_ptr< TiledBitmap >
 
using WeakPtr = std::weak_ptr< TiledBitmap >
 
using ViewDataMap = Scroom::Utils::WeakKeyMap< ViewInterface::WeakPtr, TiledBitmapViewData::Ptr >
 
- Public Types inherited from TiledBitmapInterface
using Ptr = std::shared_ptr< TiledBitmapInterface >
 
- Public Types inherited from Viewable
using Ptr = std::shared_ptr< Viewable >
 
using WeakPtr = std::weak_ptr< Viewable >
 
- Public Types inherited from TileInitialisationObserver
using Ptr = std::shared_ptr< TileInitialisationObserver >
 
using WeakPtr = std::weak_ptr< TileInitialisationObserver >
 

Public Member Functions

 ~TiledBitmap () override
 
 TiledBitmap (const TiledBitmap &)=delete
 
 TiledBitmap (TiledBitmap &&)=delete
 
TiledBitmap operator= (const TiledBitmap &)=delete
 
TiledBitmap operator= (TiledBitmap &&)=delete
 
void setSource (SourcePresentation::Ptr sp) override
 
Layer::Ptr getBottomLayer () override
 
void open (ViewInterface::WeakPtr viewInterface) override
 
void close (ViewInterface::WeakPtr vi) override
 
void redraw (ViewInterface::Ptr const &vi, cairo_t *cr, Scroom::Utils::Rectangle< double > const &presentationArea, int zoom) override
 
void clearCaches (ViewInterface::Ptr vi) override
 
Scroom::Utils::Context::ConstPtr getContext () const override
 
void tileCreated (const CompressedTile::Ptr &tile) override
 
void tileFinished (const CompressedTile::Ptr &tile) override
 TileInitialisationObserver.
 
ProgressInterface::Ptr progressInterface ()
 
- 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
 

Static Public Member Functions

static Ptr create (int bitmapWidth, int bitmapHeight, LayerSpec const &ls)
 
static Ptr create (const Layer::Ptr &bottom, const LayerSpec &ls)
 

Private Member Functions

 TiledBitmap (int bitmapWidth, int bitmapHeight, LayerSpec ls)
 
void initialize ()
 
void initialize (const Layer::Ptr &bottom)
 
void connect (Layer::Ptr const &layer, Layer::Ptr const &prevLayer, const LayerOperations::Ptr &prevLo)
 

Static Private Member Functions

static void drawTile (cairo_t *cr, const CompressedTile::Ptr &tile, const Scroom::Utils::Rectangle< double > &viewArea)
 

Private Attributes

int bitmapWidth
 
int bitmapHeight
 
LayerSpec ls
 
std::vector< Layer::Ptrlayers
 
std::list< LayerCoordinator::Ptrcoordinators
 
boost::mutex viewDataMutex
 
ViewDataMap viewData
 
int tileCount {0}
 
boost::mutex tileFinishedMutex
 
int tileFinishedCount {0}
 
Scroom::Utils::ProgressInterfaceBroadcaster::Ptr progressBroadcaster
 
Scroom::Utils::StuffList registrations
 
Scroom::Logger logger
 
Scroom::Utils::Context::Ptr context
 

Member Typedef Documentation

◆ Ptr

using TiledBitmap::Ptr = std::shared_ptr<TiledBitmap>

◆ ViewDataMap

◆ WeakPtr

using TiledBitmap::WeakPtr = std::weak_ptr<TiledBitmap>

Constructor & Destructor Documentation

◆ ~TiledBitmap()

TiledBitmap::~TiledBitmap ( )
override
148{
149 logger->debug("TiledBitmap: Destructing...");
150
151 coordinators.clear();
152 layers.clear();
153}
std::vector< Layer::Ptr > layers
Definition tiled-bitmap.hh:42
Scroom::Logger logger
Definition tiled-bitmap.hh:51
std::list< LayerCoordinator::Ptr > coordinators
Definition tiled-bitmap.hh:43

◆ TiledBitmap() [1/3]

TiledBitmap::TiledBitmap ( const TiledBitmap )
delete

◆ TiledBitmap() [2/3]

TiledBitmap::TiledBitmap ( TiledBitmap &&  )
delete

◆ TiledBitmap() [3/3]

TiledBitmap::TiledBitmap ( int  bitmapWidth,
int  bitmapHeight,
LayerSpec  ls 
)
private
88 : bitmapWidth(bitmapWidth_)
89 , bitmapHeight(bitmapHeight_)
90 , ls(std::move(ls_))
93{
97 set(
98 context,
102 }
103 );
104}
map set(2, 5)
static Ptr create()
Definition context.cc:15
std::map< std::string, ITweakSelection::Ptr > Map
Definition tweak-view.hh:45
static Ptr create()
Definition progressinterfacehelpers.cc:124
static ITweakSelection::Ptr create(const Point< double > &aspectRatio_={1.0, 1.0})
Definition tweak-view.cc:153
static ITweakSelection::Ptr create(const Point< double > &aspectRatio_={1.0, 1.0})
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_={1.0, 1.0})
Definition tweak-view.cc:101
static ITweakRulers::Ptr create(const Point< double > &aspectRatio_={1.0, 1.0})
Definition tweak-view.cc:122
int bitmapHeight
Definition tiled-bitmap.hh:40
Scroom::Utils::ProgressInterfaceBroadcaster::Ptr progressBroadcaster
Definition tiled-bitmap.hh:49
int bitmapWidth
Definition tiled-bitmap.hh:39
Scroom::Utils::Context::Ptr context
Definition tiled-bitmap.hh:52
LayerSpec ls
Definition tiled-bitmap.hh:41
const std::string GRID("GridSelection")
const std::string PIXEL("PixelSelection")
Here is the call graph for this function:

Member Function Documentation

◆ clearCaches()

void TiledBitmap::clearCaches ( ViewInterface::Ptr  vi)
overridevirtual

Clear all bitmap caches related to the view.

You'd typically do this if the bitmap has somehow changed appearance, for example when switching to a new Colormap.

Parameters
viThe ViewInterface for which to clear the caches

Implements TiledBitmapInterface.

293{
294 boost::mutex::scoped_lock const lock(viewDataMutex);
295 TiledBitmapViewData::Ptr const tbvd = viewData[viewInterface];
296 if(tbvd)
297 {
298 tbvd->clearVolatileStuff();
299 }
300}
std::shared_ptr< TiledBitmapViewData > Ptr
Definition tiledbitmapviewdata.hh:25
ViewDataMap viewData
Definition tiled-bitmap.hh:45
boost::mutex viewDataMutex
Definition tiled-bitmap.hh:44

◆ close()

void TiledBitmap::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)

Implements Viewable.

319{
320 for(Layer::Ptr const& l: layers)
321 {
322 l->close(vi);
323 }
324
325 boost::mutex::scoped_lock const lock(viewDataMutex);
327 // Yuk. ProgressBroadcaster has a reference to viewData, so erasing it
328 // from the map isn't enough.
329 vd->token.reset();
330 viewData.erase(vi);
331}
std::shared_ptr< Layer > Ptr
Definition tiledbitmaplayer.hh:250
PageList const l
Definition compression-tests.cc:33
ViewInterface::Ptr const vi
Definition pipette-tests.cc:186

◆ connect()

void TiledBitmap::connect ( Layer::Ptr const &  layer,
Layer::Ptr const &  prevLayer,
const LayerOperations::Ptr prevLo 
)
private
156{
157 const int horTileCount = prevLayer->getHorTileCount();
158 const int verTileCount = prevLayer->getVerTileCount();
159
160 std::vector<LayerCoordinator::Ptr> coordinators_;
161
162 for(int j = 0; j < verTileCount; j++)
163 {
164 const int voffset = j % 8;
165 if(!voffset)
166 {
167 // New line of target tiles
168 coordinators_.clear();
169 CompressedTileLine const& tileLine = layer->getTileLine(j / 8);
170 for(auto& z: tileLine)
171 {
173 coordinators_.push_back(lc);
174 coordinators.push_back(lc);
175 }
176 }
177
178 for(int i = 0; i < horTileCount; i++)
179 {
180 const int hoffset = i % 8;
181 LayerCoordinator::Ptr const lc = coordinators_[i / 8];
182 lc->addSourceTile(hoffset, voffset, prevLayer->getTile(i, j));
183 }
184 }
185}
static Ptr create(CompressedTile::Ptr targetTile, LayerOperations::Ptr lo)
Definition layercoordinator.cc:18
std::shared_ptr< LayerCoordinator > Ptr
Definition layercoordinator.hh:32
std::vector< CompressedTile::Ptr > CompressedTileLine
Definition tiledbitmaplayer.hh:240

Referenced by initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create() [1/2]

TiledBitmap::Ptr TiledBitmap::create ( const Layer::Ptr bottom,
const LayerSpec ls 
)
static
81{
82 TiledBitmap::Ptr result(new TiledBitmap(bottom->getWidth(), bottom->getHeight(), ls));
83 result->initialize(bottom);
84 return result;
85}
Definition tiled-bitmap.hh:32
std::shared_ptr< TiledBitmap > Ptr
Definition tiled-bitmap.hh:34
SampleIterator< const uint8_t > result
Definition sampleiterator-tests.cc:94

◆ create() [2/2]

TiledBitmap::Ptr TiledBitmap::create ( int  bitmapWidth,
int  bitmapHeight,
LayerSpec const &  ls 
)
static
74{
76 result->initialize();
77 return result;
78}

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

Here is the caller graph for this function:

◆ drawTile()

void TiledBitmap::drawTile ( cairo_t *  cr,
const CompressedTile::Ptr tile,
const Scroom::Utils::Rectangle< double > &  viewArea 
)
staticprivate
198{
199 const int margin = 5;
200
201 if(viewArea.width() > 2 * margin && viewArea.height() > 2 * margin)
202 {
204 viewArea.x() + margin, viewArea.y() + margin, viewArea.width() - 2 * margin, viewArea.height() - 2 * margin
205 );
206
207 cairo_set_source_rgb(cr, 0, 0, 0); // Black
209
210 const std::string label = fmt::format("Layer {}, Tile ({}, {}), {} bpp", tile->depth, tile->x, tile->y, tile->bpp);
211 cairo_move_to(cr, rect.x() + 20, rect.y() + 20);
212 cairo_show_text(cr, label.c_str());
213 }
214}
void drawRectangleContour(cairo_t *cr, Scroom::Utils::Rectangle< double > const &viewArea)
Definition cairo-helpers.cc:31
Definition rectangle.hh:29
value_type height() const
Definition rectangle.hh:131
value_type y() const
Definition rectangle.hh:127
value_type x() const
Definition rectangle.hh:125
value_type width() const
Definition rectangle.hh:129
const auto rect
Definition rectangletests.cc:335
cairo_t * cr
Definition transformpresentation_test.cc:72

Referenced by redraw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getBottomLayer()

Layer::Ptr TiledBitmap::getBottomLayer ( )
overridevirtual

Retrieve the bottom layer of the TiledBitmap.

This allows you to fill the layer with data yourself, instead of relying on setSource()

See also
setSource()

Implements TiledBitmapInterface.

195{ return layers[0]; }

◆ getContext()

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

Implements TiledBitmapInterface.

302{ return context; }

◆ initialize() [1/2]

void TiledBitmap::initialize ( )
private
static Ptr create(int depth, int layerWidth, int layerHeight, int bpp, Scroom::MemoryBlobs::PageProvider::Ptr provider)
Definition layer.cc:101
void initialize()
Definition tiled-bitmap.cc:145

Referenced by initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialize() [2/2]

void TiledBitmap::initialize ( const Layer::Ptr bottom)
private
107{
108 int width = bitmapWidth;
109 int height = bitmapHeight;
110 unsigned int i = 0;
111 LayerOperations::Ptr lo = ls[i];
112 Scroom::MemoryBlobs::PageProvider::Ptr const provider = bottom->getPageProvider();
113
114 registrations.emplace_back(bottom->registerObserver(shared_from_this<TileInitialisationObserver>()));
115 layers.push_back(bottom);
116
117 Layer::Ptr prevLayer = bottom;
118 LayerOperations::Ptr prevLo = lo;
119
120 width = (width + 7) / 8; // Round up
121 height = (height + 7) / 8;
122 i++;
123
124 while(std::max(width, height) > TILESIZE / 4)
125 {
126 if(i < ls.size())
127 {
128 lo = ls[i];
129 }
130
131 Layer::Ptr const layer = Layer::create(i, width, height, lo->getBpp(), provider);
132 registrations.emplace_back(layer->registerObserver(shared_from_this<TileInitialisationObserver>()));
133 layers.push_back(layer);
134
135 connect(layer, prevLayer, prevLo);
136
137 prevLayer = layer;
138 prevLo = lo;
139 width = (width + 7) / 8; // Round up
140 height = (height + 7) / 8;
141 i++;
142 }
143}
PageProvider::Ptr provider
Definition blob-tests.cc:26
std::shared_ptr< LayerOperations > Ptr
Definition tiledbitmapinterface.hh:52
std::shared_ptr< PageProvider > Ptr
Definition memoryblobs.hh:40
Scroom::Utils::StuffList registrations
Definition tiled-bitmap.hh:50
void connect(Layer::Ptr const &layer, Layer::Ptr const &prevLayer, const LayerOperations::Ptr &prevLo)
Definition tiled-bitmap.cc:155
#define TILESIZE
Definition tiledbitmaplayer.hh:27
Here is the call graph for this function:

◆ open()

void TiledBitmap::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)

Implements Viewable.

305{
306 boost::mutex::scoped_lock lock(viewDataMutex);
308 viewData[viewInterface] = vd;
309 vd->token.add(progressBroadcaster->subscribe(vd));
310 lock.unlock();
311
312 for(Layer::Ptr const& l: layers)
313 {
314 l->open(viewInterface);
315 }
316}
static Ptr create(const ViewInterface::WeakPtr &viewInterface)
Definition tiledbitmapviewdata.cc:20
Here is the call graph for this function:

◆ operator=() [1/2]

TiledBitmap TiledBitmap::operator= ( const TiledBitmap )
delete

◆ operator=() [2/2]

TiledBitmap TiledBitmap::operator= ( TiledBitmap &&  )
delete

◆ progressInterface()

ProgressInterface::Ptr TiledBitmap::progressInterface ( )
inline
102{ return progressBroadcaster; }

◆ redraw()

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

Redraw a portion of the bitmap.

This is typically called from PresentationInterface::redraw()

See also
PresentationInterface::redraw()

Implements TiledBitmapInterface.

222{
223 TiledBitmapViewData::Ptr const viewData_ = viewData[vi];
224 auto scaledRequestedPresentationArea = presentationArea;
225
226 unsigned int layerNr = 0;
227 while(zoom <= -3 && layerNr < layers.size() - 1)
228 {
229 layerNr++;
230 zoom += 3;
231 scaledRequestedPresentationArea /= 8;
232 }
233 Layer::Ptr const layer = layers[layerNr];
234 LayerOperations::Ptr const layerOperations = ls[std::min(ls.size() - 1, static_cast<size_t>(layerNr))];
235
236 const Scroom::Utils::Rectangle<int> actualPresentationArea = layer->getRect();
237 const auto validPresentationArea = scaledRequestedPresentationArea.intersection(actualPresentationArea);
238
239 const int left = scaledRequestedPresentationArea.getLeft();
240 const int top = scaledRequestedPresentationArea.getTop();
241 const int right = scaledRequestedPresentationArea.getRight();
242 const int bottom = scaledRequestedPresentationArea.getBottom();
243
244 const int imin = std::max(0, left / TILESIZE);
245 const int imax = (right + TILESIZE - 1) / TILESIZE;
246 const int jmin = std::max(0, top / TILESIZE);
247 const int jmax = (bottom + TILESIZE - 1) / TILESIZE;
248
249 viewData_->setNeededTiles(layer, imin, imax, jmin, jmax, zoom, layerOperations);
250
251 const double pixelSize = pixelSizeFromZoom(zoom);
252
253 layerOperations->initializeCairo(cr);
254
255 const auto clippedRequestedPresentationArea =
256 scaledRequestedPresentationArea.above(validPresentationArea.getBottom()).leftOf(validPresentationArea.getRight());
257
258 for(int i = imin; i < imax; i++)
259 {
260 for(int j = jmin; j < jmax; j++)
261 {
262 Scroom::Utils::Point<int> const tileIndex(i, j);
263
264 const auto tileArea = TileAreaForIndex(tileIndex);
265 const auto visibleTileArea = tileArea.intersection(clippedRequestedPresentationArea);
266
267 const auto tileAreaRect = visibleTileArea - tileArea.getTopLeft();
268 const auto viewAreaRect = (visibleTileArea - clippedRequestedPresentationArea.getTopLeft()) * pixelSize;
269
270 CompressedTile::Ptr const tile = layer->getTile(i, j);
271 TileViewState::Ptr const tileViewState = tile->getViewState(vi);
272 Scroom::Utils::Stuff const cacheResult = tileViewState->getCacheResult();
273 ConstTile::Ptr const t = tile->getConstTileAsync();
274
275 if(t)
276 {
277 cairo_save(cr);
278 layerOperations->draw(cr, t, tileAreaRect, viewAreaRect, zoom, cacheResult);
279 cairo_restore(cr);
280 }
281 else
282 {
283 layerOperations->drawState(cr, tile->getState(), viewAreaRect);
284 }
285#ifdef DEBUG_TILES
286 drawTile(cr, tile, viewAreaRect);
287#endif
288 }
289 }
290}
double pixelSizeFromZoom(int zoom)
Definition cairo-helpers.cc:123
std::shared_ptr< CompressedTile > Ptr
Definition tiledbitmaplayer.hh:107
std::shared_ptr< ConstTile > Ptr
Definition tile.hh:45
Definition point.hh:28
Rectangle intersection(const Rectangle &other) const
Definition rectangle.hh:95
value_type getLeft() const
Definition rectangle.hh:110
std::shared_ptr< TileViewState > Ptr
Definition tileviewstate.hh:29
static void drawTile(cairo_t *cr, const CompressedTile::Ptr &tile, const Scroom::Utils::Rectangle< double > &viewArea)
Definition tiled-bitmap.cc:197
std::shared_ptr< void > Stuff
Definition stuff.hh:17
Segment< int > const right(3, 7)
ThreadPool t(0)
Scroom::Utils::Rectangle< int > TileAreaForIndex(Scroom::Utils::Point< int > tileIndex)
Definition tiled-bitmap.cc:65
Here is the call graph for this function:

◆ setSource()

void TiledBitmap::setSource ( SourcePresentation::Ptr  sp)
overridevirtual

Provide bitmap data to the TiledBitmap

Bitmap data will be loaded and pre-scaled in a fashion that least loads cpu and memory.

Parameters
spsource of the bitmap data

Implements TiledBitmapInterface.

191{
193}
Scroom::Utils::Stuff scheduleLoadingBitmap(const SourcePresentation::Ptr &sp, const Layer::Ptr &layer, const ProgressInterface::Ptr &progress)
Definition tiled-bitmap.cc:33
Here is the call graph for this function:

◆ tileCreated()

void TiledBitmap::tileCreated ( const CompressedTile::Ptr tile)
overridevirtual

The tile has been created.

This event will be sent as soon as the observer is registered (because obvously the tile has already been created beforehand).

Note
This event will be sent using the thread that is registering the observer. Be careful with your mutexes :-)

Reimplemented from TileInitialisationObserver.

336{ tileCount++; }
int tileCount
Definition tiled-bitmap.hh:46

◆ tileFinished()

void TiledBitmap::tileFinished ( const CompressedTile::Ptr tile)
overridevirtual

TileInitialisationObserver.

This event will be sent when the tile is completely filled with data. This would be a good time to update progress bars and start prescaling.

Note
This event will be sent on the thread that is filling the tile with data.

Reimplemented from TileInitialisationObserver.

339{
340 boost::mutex::scoped_lock const lock(tileFinishedMutex);
343 {
344 defect_message("ERROR: Too many tiles are finished!");
345 }
346 else
347 {
349 [this]
350 {
353 {
354 progressBroadcaster->setFinished();
355 logger->info("Finished loading file");
356 }
357 }
358 );
359 }
360}
#define defect_message(m)
Definition assertions.hh:49
boost::mutex tileFinishedMutex
Definition tiled-bitmap.hh:47
int tileFinishedCount
Definition tiled-bitmap.hh:48
void sync_on_ui_thread(T f)
Definition gtk-helpers.hh:59
Here is the call graph for this function:

Member Data Documentation

◆ bitmapHeight

int TiledBitmap::bitmapHeight
private

Referenced by create(), initialize(), and initialize().

◆ bitmapWidth

int TiledBitmap::bitmapWidth
private

Referenced by create(), initialize(), and initialize().

◆ context

Scroom::Utils::Context::Ptr TiledBitmap::context
private

Referenced by getContext(), and TiledBitmap().

◆ coordinators

std::list<LayerCoordinator::Ptr> TiledBitmap::coordinators
private

Referenced by connect(), and ~TiledBitmap().

◆ layers

std::vector<Layer::Ptr> TiledBitmap::layers
private

◆ logger

Scroom::Logger TiledBitmap::logger
private

Referenced by tileFinished(), and ~TiledBitmap().

◆ ls

LayerSpec TiledBitmap::ls
private

◆ progressBroadcaster

Scroom::Utils::ProgressInterfaceBroadcaster::Ptr TiledBitmap::progressBroadcaster
private

◆ registrations

Scroom::Utils::StuffList TiledBitmap::registrations
private

Referenced by initialize(), and setSource().

◆ tileCount

int TiledBitmap::tileCount {0}
private
46{0};

Referenced by tileCreated(), and tileFinished().

◆ tileFinishedCount

int TiledBitmap::tileFinishedCount {0}
private
48{0};

Referenced by tileFinished().

◆ tileFinishedMutex

boost::mutex TiledBitmap::tileFinishedMutex
private

Referenced by tileFinished().

◆ viewData

ViewDataMap TiledBitmap::viewData
private

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

◆ viewDataMutex

boost::mutex TiledBitmap::viewDataMutex
private

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


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