Scroom  0.14
TiledBitmap Class Reference

#include <tiled-bitmap.hh>

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

Public Types

using Ptr = boost::shared_ptr< TiledBitmap >
 
using WeakPtr = boost::weak_ptr< TiledBitmap >
 
using ViewDataMap = std::map< ViewInterface::WeakPtr, TiledBitmapViewData::Ptr >
 
- Public Types inherited from TiledBitmapInterface
using Ptr = boost::shared_ptr< TiledBitmapInterface >
 
- Public Types inherited from Viewable
using Ptr = boost::shared_ptr< Viewable >
 
using WeakPtr = boost::weak_ptr< Viewable >
 
- Public Types inherited from TileInitialisationObserver
using Ptr = boost::shared_ptr< TileInitialisationObserver >
 
using WeakPtr = boost::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
 
void tileCreated (const CompressedTile::Ptr &tile) override
 
void tileFinished (const CompressedTile::Ptr &tile) override
 
ProgressInterface::Ptr progressInterface ()
 
- Public Member Functions inherited from TileInitialisationObserver
virtual void tileCreated (const boost::shared_ptr< CompressedTile > &tile)
 
virtual void tileFinished (const boost::shared_ptr< CompressedTile > &tile)
 TileInitialisationObserver. More...
 
- 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 >
boost::shared_ptr< R > shared_from_this ()
 
template<typename R >
boost::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
 

Member Typedef Documentation

◆ Ptr

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

◆ ViewDataMap

◆ WeakPtr

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

Constructor & Destructor Documentation

◆ ~TiledBitmap()

TiledBitmap::~TiledBitmap ( )
override
134 {
135  spdlog::debug("TiledBitmap: Destructing...");
136 
137  coordinators.clear();
138  layers.clear();
139 }

◆ TiledBitmap() [1/3]

TiledBitmap::TiledBitmap ( const TiledBitmap )
delete

Referenced by create().

Here is the caller graph for this function:

◆ TiledBitmap() [2/3]

TiledBitmap::TiledBitmap ( TiledBitmap &&  )
delete

◆ TiledBitmap() [3/3]

TiledBitmap::TiledBitmap ( int  bitmapWidth,
int  bitmapHeight,
LayerSpec  ls 
)
private
85  : bitmapWidth(bitmapWidth_)
86  , bitmapHeight(bitmapHeight_)
87  , ls(std::move(ls_))
89 {
90 }

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.

276 {
277  boost::mutex::scoped_lock const lock(viewDataMutex);
278  TiledBitmapViewData::Ptr const tbvd = viewData[viewInterface];
279  if(tbvd)
280  {
281  tbvd->clearVolatileStuff();
282  }
283 }

◆ 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.

300 {
301  for(Layer::Ptr const& l: layers)
302  {
303  l->close(vi);
304  }
305 
306  boost::mutex::scoped_lock const lock(viewDataMutex);
307  TiledBitmapViewData::Ptr const vd = viewData[vi];
308  // Yuk. ProgressBroadcaster has a reference to viewData, so erasing it
309  // from the map isn't enough.
310  vd->token.reset();
311  viewData.erase(vi);
312 }

◆ connect()

void TiledBitmap::connect ( Layer::Ptr const &  layer,
Layer::Ptr const &  prevLayer,
const LayerOperations::Ptr prevLo 
)
private
142 {
143  const int horTileCount = prevLayer->getHorTileCount();
144  const int verTileCount = prevLayer->getVerTileCount();
145 
146  std::vector<LayerCoordinator::Ptr> coordinators_;
147 
148  for(int j = 0; j < verTileCount; j++)
149  {
150  const int voffset = j % 8;
151  if(!voffset)
152  {
153  // New line of target tiles
154  coordinators_.clear();
155  CompressedTileLine const& tileLine = layer->getTileLine(j / 8);
156  for(auto& z: tileLine)
157  {
158  LayerCoordinator::Ptr const lc = LayerCoordinator::create(z, prevLo);
159  coordinators_.push_back(lc);
160  coordinators.push_back(lc);
161  }
162  }
163 
164  for(int i = 0; i < horTileCount; i++)
165  {
166  const int hoffset = i % 8;
167  LayerCoordinator::Ptr const lc = coordinators_[i / 8];
168  lc->addSourceTile(hoffset, voffset, prevLayer->getTile(i, j));
169  }
170  }
171 }

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
78 {
79  TiledBitmap::Ptr result(new TiledBitmap(bottom->getWidth(), bottom->getHeight(), ls));
80  result->initialize(bottom);
81  return result;
82 }
Here is the call graph for this function:

◆ create() [2/2]

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

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

Here is the call graph for this function:
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
184 {
185  const int margin = 5;
186 
187  if(viewArea.width() > 2 * margin && viewArea.height() > 2 * margin)
188  {
190  viewArea.x() + margin, viewArea.y() + margin, viewArea.width() - 2 * margin, viewArea.height() - 2 * margin);
191 
192  cairo_set_source_rgb(cr, 0, 0, 0); // Black
193  drawRectangleContour(cr, rect);
194 
195  const std::string label = fmt::format("Layer {}, Tile ({}, {}), {} bpp", tile->depth, tile->x, tile->y, tile->bpp);
196  cairo_move_to(cr, rect.x() + 20, rect.y() + 20);
197  cairo_show_text(cr, label.c_str());
198  }
199 }

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.

181 { return layers[0]; }

◆ initialize() [1/2]

void TiledBitmap::initialize ( )
private
131 { initialize(Layer::create(bitmapWidth, bitmapHeight, ls[0]->getBpp())); }
Here is the call graph for this function:

◆ initialize() [2/2]

void TiledBitmap::initialize ( const Layer::Ptr bottom)
private
93 {
94  int width = bitmapWidth;
95  int height = bitmapHeight;
96  unsigned int i = 0;
97  LayerOperations::Ptr lo = ls[i];
98  Scroom::MemoryBlobs::PageProvider::Ptr const provider = bottom->getPageProvider();
99 
100  registrations.emplace_back(bottom->registerObserver(shared_from_this<TileInitialisationObserver>()));
101  layers.push_back(bottom);
102 
103  Layer::Ptr prevLayer = bottom;
104  LayerOperations::Ptr prevLo = lo;
105 
106  width = (width + 7) / 8; // Round up
107  height = (height + 7) / 8;
108  i++;
109 
110  while(std::max(width, height) > TILESIZE / 4)
111  {
112  if(i < ls.size())
113  {
114  lo = ls[i];
115  }
116 
117  Layer::Ptr const layer = Layer::create(i, width, height, lo->getBpp(), provider);
118  registrations.emplace_back(layer->registerObserver(shared_from_this<TileInitialisationObserver>()));
119  layers.push_back(layer);
120 
121  connect(layer, prevLayer, prevLo);
122 
123  prevLayer = layer;
124  prevLo = lo;
125  width = (width + 7) / 8; // Round up
126  height = (height + 7) / 8;
127  i++;
128  }
129 }
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.

286 {
287  boost::mutex::scoped_lock lock(viewDataMutex);
288  TiledBitmapViewData::Ptr const vd = TiledBitmapViewData::create(viewInterface);
289  viewData[viewInterface] = vd;
290  vd->token.add(progressBroadcaster->subscribe(vd));
291  lock.unlock();
292 
293  for(Layer::Ptr const& l: layers)
294  {
295  l->open(viewInterface);
296  }
297 }
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
96 { 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.

205 {
206  TiledBitmapViewData::Ptr const viewData_ = viewData[vi];
207  auto scaledRequestedPresentationArea = presentationArea;
208 
209  unsigned int layerNr = 0;
210  while(zoom <= -3 && layerNr < layers.size() - 1)
211  {
212  layerNr++;
213  zoom += 3;
214  scaledRequestedPresentationArea /= 8;
215  }
216  Layer::Ptr const layer = layers[layerNr];
217  LayerOperations::Ptr const layerOperations = ls[std::min(ls.size() - 1, static_cast<size_t>(layerNr))];
218 
219  const Scroom::Utils::Rectangle<int> actualPresentationArea = layer->getRect();
220  const auto validPresentationArea = scaledRequestedPresentationArea.intersection(actualPresentationArea);
221 
222  const int left = scaledRequestedPresentationArea.getLeft();
223  const int top = scaledRequestedPresentationArea.getTop();
224  const int right = scaledRequestedPresentationArea.getRight();
225  const int bottom = scaledRequestedPresentationArea.getBottom();
226 
227  const int imin = std::max(0, left / TILESIZE);
228  const int imax = (right + TILESIZE - 1) / TILESIZE;
229  const int jmin = std::max(0, top / TILESIZE);
230  const int jmax = (bottom + TILESIZE - 1) / TILESIZE;
231 
232  viewData_->setNeededTiles(layer, imin, imax, jmin, jmax, zoom, layerOperations);
233 
234  const double pixelSize = pixelSizeFromZoom(zoom);
235 
236  layerOperations->initializeCairo(cr);
237 
238  const auto clippedRequestedPresentationArea =
239  scaledRequestedPresentationArea.above(validPresentationArea.getBottom()).leftOf(validPresentationArea.getRight());
240 
241  for(int i = imin; i < imax; i++)
242  {
243  for(int j = jmin; j < jmax; j++)
244  {
245  Scroom::Utils::Point<int> const tileIndex(i, j);
246 
247  const auto tileArea = TileAreaForIndex(tileIndex);
248  const auto visibleTileArea = tileArea.intersection(clippedRequestedPresentationArea);
249 
250  const auto tileAreaRect = visibleTileArea - tileArea.getTopLeft();
251  const auto viewAreaRect = (visibleTileArea - clippedRequestedPresentationArea.getTopLeft()) * pixelSize;
252 
253  CompressedTile::Ptr const tile = layer->getTile(i, j);
254  TileViewState::Ptr const tileViewState = tile->getViewState(vi);
255  Scroom::Utils::Stuff const cacheResult = tileViewState->getCacheResult();
256  ConstTile::Ptr const t = tile->getConstTileAsync();
257 
258  if(t)
259  {
260  cairo_save(cr);
261  layerOperations->draw(cr, t, tileAreaRect, viewAreaRect, zoom, cacheResult);
262  cairo_restore(cr);
263  }
264  else
265  {
266  layerOperations->drawState(cr, tile->getState(), viewAreaRect);
267  }
268 #ifdef DEBUG_TILES
269  drawTile(cr, tile, viewAreaRect);
270 #endif
271  }
272  }
273 }
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.

Here is the call graph for this function:

◆ tileCreated()

void TiledBitmap::tileCreated ( const CompressedTile::Ptr tile)
override
318 {
319  UNUSED(tile);
320  tileCount++;
321 }

◆ tileFinished()

void TiledBitmap::tileFinished ( const CompressedTile::Ptr tile)
override
324 {
325  UNUSED(tile);
326  boost::mutex::scoped_lock const lock(tileFinishedMutex);
329  {
330  defect_message("ERROR: Too many tiles are finished!");
331  }
332  else
333  {
335  [=]
336  {
337  progressBroadcaster->setWorking(1.0 * tileFinishedCount / tileCount);
339  {
340  progressBroadcaster->setFinished();
341  spdlog::info("Finished loading file");
342  }
343  });
344  }
345 }
Here is the call graph for this function:

Member Data Documentation

◆ bitmapHeight

int TiledBitmap::bitmapHeight
private

Referenced by create(), and initialize().

◆ bitmapWidth

int TiledBitmap::bitmapWidth
private

Referenced by create(), and initialize().

◆ coordinators

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

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

◆ layers

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

◆ ls

LayerSpec TiledBitmap::ls
private

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

◆ 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

Referenced by tileCreated(), and tileFinished().

◆ tileFinishedCount

int TiledBitmap::tileFinishedCount {0}
private

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:
UNUSED
#define UNUSED(x)
Definition: unused.hh:10
Scroom::MemoryBlobs::PageProvider::Ptr
boost::shared_ptr< PageProvider > Ptr
Definition: memoryblobs.hh:41
Scroom::Utils::Rectangle::x
value_type x() const
Definition: rectangle.hh:125
TiledBitmap::tileCount
int tileCount
Definition: tiled-bitmap.hh:46
Layer::Ptr
boost::shared_ptr< Layer > Ptr
Definition: tiledbitmaplayer.hh:247
TiledBitmap::bitmapWidth
int bitmapWidth
Definition: tiled-bitmap.hh:39
Scroom::Utils::Rectangle::width
value_type width() const
Definition: rectangle.hh:129
TiledBitmap::ls
LayerSpec ls
Definition: tiled-bitmap.hh:41
Scroom::TiledBitmap::scheduleLoadingBitmap
Scroom::Utils::Stuff scheduleLoadingBitmap(const SourcePresentation::Ptr &sp, const Layer::Ptr &layer, const ProgressInterface::Ptr &progress)
Definition: tiled-bitmap.cc:33
TiledBitmap::tileFinishedCount
int tileFinishedCount
Definition: tiled-bitmap.hh:48
TiledBitmap::initialize
void initialize()
Definition: tiled-bitmap.cc:131
TiledBitmap::registrations
Scroom::Utils::StuffList registrations
Definition: tiled-bitmap.hh:50
ConstTile::Ptr
boost::shared_ptr< ConstTile > Ptr
Definition: tile.hh:47
TileAreaForIndex
Scroom::Utils::Rectangle< int > TileAreaForIndex(Scroom::Utils::Point< int > tileIndex)
Definition: tiled-bitmap.cc:62
TiledBitmapViewData::Ptr
boost::shared_ptr< TiledBitmapViewData > Ptr
Definition: tiledbitmapviewdata.hh:25
Scroom::Utils::Rectangle::intersection
Rectangle intersection(const Rectangle &other) const
Definition: rectangle.hh:95
TiledBitmap::tileFinishedMutex
boost::mutex tileFinishedMutex
Definition: tiled-bitmap.hh:47
TileViewState::Ptr
boost::shared_ptr< TileViewState > Ptr
Definition: tileviewstate.hh:27
TiledBitmap::viewData
ViewDataMap viewData
Definition: tiled-bitmap.hh:45
Scroom::GtkHelpers::sync_on_ui_thread
void sync_on_ui_thread(T f)
Definition: gtk-helpers.hh:59
Scroom::Utils::ProgressInterfaceBroadcaster::create
static Ptr create()
Definition: progressinterfacehelpers.cc:122
TiledBitmap::bitmapHeight
int bitmapHeight
Definition: tiled-bitmap.hh:40
TiledBitmap::connect
void connect(Layer::Ptr const &layer, Layer::Ptr const &prevLayer, const LayerOperations::Ptr &prevLo)
Definition: tiled-bitmap.cc:141
TiledBitmapViewData::create
static Ptr create(const ViewInterface::WeakPtr &viewInterface)
Definition: tiledbitmapviewdata.cc:20
TiledBitmap::Ptr
boost::shared_ptr< TiledBitmap > Ptr
Definition: tiled-bitmap.hh:34
LayerCoordinator::create
static Ptr create(CompressedTile::Ptr targetTile, LayerOperations::Ptr lo)
Definition: layercoordinator.cc:19
TiledBitmap::coordinators
std::list< LayerCoordinator::Ptr > coordinators
Definition: tiled-bitmap.hh:43
Scroom::Utils::Stuff
boost::shared_ptr< void > Stuff
Definition: stuff.hh:18
TiledBitmap::progressBroadcaster
Scroom::Utils::ProgressInterfaceBroadcaster::Ptr progressBroadcaster
Definition: tiled-bitmap.hh:49
TiledBitmap::layers
std::vector< Layer::Ptr > layers
Definition: tiled-bitmap.hh:42
Scroom::Utils::Rectangle::getLeft
value_type getLeft() const
Definition: rectangle.hh:110
TiledBitmap::viewDataMutex
boost::mutex viewDataMutex
Definition: tiled-bitmap.hh:44
pixelSizeFromZoom
double pixelSizeFromZoom(int zoom)
Definition: cairo-helpers.cc:112
Scroom::Utils::Rectangle::height
value_type height() const
Definition: rectangle.hh:131
drawRectangleContour
void drawRectangleContour(cairo_t *cr, Scroom::Utils::Rectangle< double > const &viewArea)
Definition: cairo-helpers.cc:31
LayerCoordinator::Ptr
boost::shared_ptr< LayerCoordinator > Ptr
Definition: layercoordinator.hh:33
TiledBitmap::TiledBitmap
TiledBitmap(const TiledBitmap &)=delete
CompressedTile::Ptr
boost::shared_ptr< CompressedTile > Ptr
Definition: tiledbitmaplayer.hh:108
TILESIZE
#define TILESIZE
Definition: tiledbitmaplayer.hh:28
LayerOperations::Ptr
boost::shared_ptr< LayerOperations > Ptr
Definition: tiledbitmapinterface.hh:53
TiledBitmap::drawTile
static void drawTile(cairo_t *cr, const CompressedTile::Ptr &tile, const Scroom::Utils::Rectangle< double > &viewArea)
Definition: tiled-bitmap.cc:183
defect_message
#define defect_message(m)
Definition: assertions.hh:43
Layer::create
static Ptr create(int depth, int layerWidth, int layerHeight, int bpp, Scroom::MemoryBlobs::PageProvider::Ptr provider)
Definition: layer.cc:98
CompressedTileLine
std::vector< CompressedTile::Ptr > CompressedTileLine
Definition: tiledbitmaplayer.hh:237
Scroom::Utils::Rectangle::y
value_type y() const
Definition: rectangle.hh:127
Scroom::Utils::Rectangle< double >
Scroom::Utils::Point< int >