Scroom 0.14-48-ga0fee447
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
 
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
 

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
136{
137 logger->debug("TiledBitmap: Destructing...");
138
139 coordinators.clear();
140 layers.clear();
141}
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
87 : bitmapWidth(bitmapWidth_)
88 , bitmapHeight(bitmapHeight_)
89 , ls(std::move(ls_))
91{
92}
static Ptr create()
Definition progressinterfacehelpers.cc:124
int bitmapHeight
Definition tiled-bitmap.hh:40
Scroom::Utils::ProgressInterfaceBroadcaster::Ptr progressBroadcaster
Definition tiled-bitmap.hh:49
int bitmapWidth
Definition tiled-bitmap.hh:39
LayerSpec ls
Definition tiled-bitmap.hh:41

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.

281{
282 boost::mutex::scoped_lock const lock(viewDataMutex);
283 TiledBitmapViewData::Ptr const tbvd = viewData[viewInterface];
284 if(tbvd)
285 {
286 tbvd->clearVolatileStuff();
287 }
288}
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.

305{
306 for(Layer::Ptr const& l: layers)
307 {
308 l->close(vi);
309 }
310
311 boost::mutex::scoped_lock const lock(viewDataMutex);
313 // Yuk. ProgressBroadcaster has a reference to viewData, so erasing it
314 // from the map isn't enough.
315 vd->token.reset();
316 viewData.erase(vi);
317}
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
144{
145 const int horTileCount = prevLayer->getHorTileCount();
146 const int verTileCount = prevLayer->getVerTileCount();
147
148 std::vector<LayerCoordinator::Ptr> coordinators_;
149
150 for(int j = 0; j < verTileCount; j++)
151 {
152 const int voffset = j % 8;
153 if(!voffset)
154 {
155 // New line of target tiles
156 coordinators_.clear();
157 CompressedTileLine const& tileLine = layer->getTileLine(j / 8);
158 for(auto& z: tileLine)
159 {
161 coordinators_.push_back(lc);
162 coordinators.push_back(lc);
163 }
164 }
165
166 for(int i = 0; i < horTileCount; i++)
167 {
168 const int hoffset = i % 8;
169 LayerCoordinator::Ptr const lc = coordinators_[i / 8];
170 lc->addSourceTile(hoffset, voffset, prevLayer->getTile(i, j));
171 }
172 }
173}
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
80{
81 TiledBitmap::Ptr result(new TiledBitmap(bottom->getWidth(), bottom->getHeight(), ls));
82 result->initialize(bottom);
83 return result;
84}
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
73{
75 result->initialize();
76 return result;
77}

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
186{
187 const int margin = 5;
188
189 if(viewArea.width() > 2 * margin && viewArea.height() > 2 * margin)
190 {
192 viewArea.x() + margin, viewArea.y() + margin, viewArea.width() - 2 * margin, viewArea.height() - 2 * margin
193 );
194
195 cairo_set_source_rgb(cr, 0, 0, 0); // Black
197
198 const std::string label = fmt::format("Layer {}, Tile ({}, {}), {} bpp", tile->depth, tile->x, tile->y, tile->bpp);
199 cairo_move_to(cr, rect.x() + 20, rect.y() + 20);
200 cairo_show_text(cr, label.c_str());
201 }
202}
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.

183{ return layers[0]; }

◆ 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:133

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

291{
292 boost::mutex::scoped_lock lock(viewDataMutex);
294 viewData[viewInterface] = vd;
295 vd->token.add(progressBroadcaster->subscribe(vd));
296 lock.unlock();
297
298 for(Layer::Ptr const& l: layers)
299 {
300 l->open(viewInterface);
301 }
302}
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
99{ 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.

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

179{
181}
Scroom::Utils::Stuff scheduleLoadingBitmap(const SourcePresentation::Ptr &sp, const Layer::Ptr &layer, const ProgressInterface::Ptr &progress)
Definition tiled-bitmap.cc:32
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.

322{ 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.

325{
326 boost::mutex::scoped_lock const lock(tileFinishedMutex);
329 {
330 defect_message("ERROR: Too many tiles are finished!");
331 }
332 else
333 {
335 [this]
336 {
339 {
340 progressBroadcaster->setFinished();
341 logger->info("Finished loading file");
342 }
343 }
344 );
345 }
346}
#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().

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