Scroom  0.14
Operations1bpp Class Reference

#include <layeroperations.hh>

Inheritance diagram for Operations1bpp:
Inheritance graph
Collaboration diagram for Operations1bpp:
Collaboration graph

Public Member Functions

 Operations1bpp (ColormapProvider::Ptr colormapProvider)
 
int getBpp () override
 
Scroom::Utils::Stuff cache (const ConstTile::Ptr &tile) override
 
void reduce (Tile::Ptr target, ConstTile::Ptr source, int x, int y) override
 
void draw (cairo_t *cr, const ConstTile::Ptr &tile, Scroom::Utils::Rectangle< double > tileArea, Scroom::Utils::Rectangle< double > viewArea, int zoom, Scroom::Utils::Stuff cache) override
 
- Public Member Functions inherited from CommonOperations
void initializeCairo (cairo_t *cr) override
 
void drawState (cairo_t *cr, TileState s, Scroom::Utils::Rectangle< double > viewArea) override
 
Scroom::Utils::Stuff cacheZoom (const ConstTile::Ptr &tile, int zoom, Scroom::Utils::Stuff &cache) override
 

Static Public Member Functions

static Ptr create (ColormapProvider::Ptr colormapProvider)
 
- Static Public Member Functions inherited from CommonOperations
static void drawPixelValue (cairo_t *cr, int x, int y, int size, int value)
 
static void drawPixelValue (cairo_t *cr, int x, int y, int size, int value, Color const &bgColor)
 

Private Attributes

ColormapProvider::Ptr colormapProvider
 

Additional Inherited Members

- Public Types inherited from LayerOperations
using Ptr = boost::shared_ptr< LayerOperations >
 

Constructor & Destructor Documentation

◆ Operations1bpp()

Operations1bpp::Operations1bpp ( ColormapProvider::Ptr  colormapProvider)
explicit
268  : colormapProvider(std::move(colormapProvider_))
269 {
270 }

Member Function Documentation

◆ cache()

Scroom::Utils::Stuff Operations1bpp::cache ( const ConstTile::Ptr tile)
overridevirtual

Cache data for use during later cacheZoom() calls.

This function is called for a given tile, and then the results are passed to the cacheZoom() function. Because draw() is called relatively frequently (i.e. when scrolling), it is recommended to do cpu-intensive work in the cache() and cacheZoom() functions, and then re-use the data to make the draw() faster.

The default implementation returns an empty reference, meaning nothing is cached. As a result, the draw() function will receive an empty reference.

Parameters
tilethe Tile for which caching is requested

Reimplemented from LayerOperations.

275 {
276  const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, tile->width);
277  boost::shared_ptr<unsigned char> const data = shared_malloc(stride * tile->height);
278  Colormap::Ptr const colormap = colormapProvider->getColormap();
279 
280  unsigned char* row = data.get();
281  for(int j = 0; j < tile->height; j++, row += stride)
282  {
283  SampleIterator<const byte> bit(tile->data.get() + j * tile->width / 8, 0);
284  auto* pixel = reinterpret_cast<uint32_t*>(row);
285  for(int i = 0; i < tile->width; i++)
286  {
287  *pixel = colormap->colors[*bit].getARGB32();
288  pixel++;
289  ++bit;
290  }
291  }
292 
293  return BitmapSurface::create(tile->width, tile->height, CAIRO_FORMAT_ARGB32, stride, data);
294 }

Referenced by draw().

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

◆ create()

LayerOperations::Ptr Operations1bpp::create ( ColormapProvider::Ptr  colormapProvider)
static
263 {
264  return Ptr(new Operations1bpp(std::move(colormapProvider)));
265 }

Referenced by Scroom::TiledBitmap::GreyscaleBitmap(), and setupTest1bpp().

Here is the caller graph for this function:

◆ draw()

void Operations1bpp::draw ( cairo_t *  cr,
const ConstTile::Ptr tile,
Scroom::Utils::Rectangle< double >  tileArea,
Scroom::Utils::Rectangle< double >  viewArea,
int  zoom,
Scroom::Utils::Stuff  cache 
)
overridevirtual

Draw the given tileArea into the given viewArea at the requested zoom level

Parameters
crThe canvas on which to draw
tileThe tile to take data from
tileAreaArea of the tile that needs to be drawn
viewAreaArea of the canvas that the tile needs to be drawn in
zoomThe requested zoom level. One pixel of your presentation should have size 2**zoom when drawn. zoom will be negative for all but the first layer.
cacheDepending on whether the cacheZoom() function finished already, this may either be an empty reference, or a reference to the value returned by cacheZoom()

Reimplemented from CommonOperations.

338 {
339  cairo_save(cr);
340  CommonOperations::draw(cr, tile, tileArea, viewArea, zoom, cache);
341  cairo_restore(cr);
342 
343  // Draw pixelvalues at 32:1 zoom
344  if(zoom == 5)
345  {
346  const int multiplier = 1 << zoom;
347  const int stride = tile->width / 8;
348  cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
349  cairo_set_font_size(cr, 12.0);
350 
351  Colormap::Ptr const colormap = colormapProvider->getColormap();
352 
353  auto tileAreaInt = roundOutward(tileArea).to<int>();
354  auto offset = tileAreaInt.getTopLeft() - tileArea.getTopLeft();
355  viewArea += offset * multiplier;
356 
357  for(int y = 0; y < tileAreaInt.getHeight(); y++)
358  {
359  const byte* const data = tile->data.get();
360  SampleIterator<const byte> current(data + (tileAreaInt.getTop() + y) * stride, tileAreaInt.getLeft(), 1);
361 
362  for(int x = 0; x < tileAreaInt.getWidth(); x++, ++current)
363  {
364  const int value = *current;
365 
366  cairo_save(cr);
368  cr, viewArea.x() + multiplier * x, viewArea.y() + multiplier * y, multiplier, value, colormap->colors[value]);
369  cairo_restore(cr);
370  }
371  }
372  }
373 }
Here is the call graph for this function:

◆ getBpp()

int Operations1bpp::getBpp ( )
overridevirtual

Return the number of bits per pixel that the layer will use.

This number will be used to compute the amount of memory required to store one tile

Implements LayerOperations.

272 { return 1; }

◆ reduce()

void Operations1bpp::reduce ( Tile::Ptr  target,
ConstTile::Ptr  source,
int  x,
int  y 
)
overridevirtual

Reduce the source tile by a factor of 8

The target tile will contain data for 8*8 source tiles. Offsets x and y indicate which of those 64 source tiles is currently being processed

Parameters
targetTile that will contain the reduced bitmap
sourceTile that is to be reduced
xx-offset (0..7) of the source tile in the target tile
yy-offset (0..7) of the source tile in the target tile
Note
The target tile belongs to a different layer, and hence possibly has a different bpp than the current one, depending on the LayerSpec given to createTiledBitmap()

Implements LayerOperations.

297 {
298  // Reducing by a factor 8. Source tile is 1bpp. Target tile is 8bpp
299  const int sourceStride = source->width / 8;
300  const byte* sourceBase = source->data.get();
301 
302  const int targetStride = target->width;
303  byte* targetBase = target->data.get() + target->height * y * targetStride / 8 + target->width * x / 8;
304 
305  for(int j = 0; j < source->height / 8; j++, targetBase += targetStride, sourceBase += sourceStride * 8)
306  {
307  // Iterate vertically over target
308  const byte* sourcePtr = sourceBase;
309  byte* targetPtr = targetBase;
310 
311  for(int i = 0; i < source->width / 8; i++, sourcePtr++, targetPtr++)
312  {
313  // Iterate horizontally over target
314 
315  // Goal is to compute a 8-bit grey value from a 8*8 black/white
316  // image. To do so, we take each of the 8 bytes, count the
317  // number of 1's in each, and add them. Finally, we divide that
318  // by 64 (the maximum number of ones in that area
319 
320  const byte* current = sourcePtr;
321  int sum = 0;
322  for(int k = 0; k < 8; k++, current += sourceStride)
323  {
324  sum += bcl.lookup(*current);
325  }
326 
327  *targetPtr = sum * 255 / 64;
328  }
329  }
330 }
Here is the call graph for this function:

Member Data Documentation

◆ colormapProvider

ColormapProvider::Ptr Operations1bpp::colormapProvider
private

Referenced by cache(), and draw().


The documentation for this class was generated from the following files:
Scroom::Utils::Rectangle::getTopLeft
xy_type getTopLeft() const
Definition: rectangle.hh:133
Scroom::Utils::Rectangle::x
value_type x() const
Definition: rectangle.hh:125
BitCountLut::lookup
byte lookup(byte index)
Definition: layeroperations.cc:61
Scroom::Bitmap::SampleIterator
Definition: bitmap-helpers.hh:61
CommonOperations::draw
void draw(cairo_t *cr, const ConstTile::Ptr &tile, Scroom::Utils::Rectangle< double > tileArea, Scroom::Utils::Rectangle< double > viewArea, int zoom, Scroom::Utils::Stuff cache) override
Definition: layeroperations.cc:161
Operations1bpp::Operations1bpp
Operations1bpp(ColormapProvider::Ptr colormapProvider)
Definition: layeroperations.cc:267
current
static unsigned int current
Definition: measure-framerate-callbacks.cc:17
Operations1bpp::colormapProvider
ColormapProvider::Ptr colormapProvider
Definition: layeroperations.hh:70
Colormap::Ptr
boost::shared_ptr< Colormap > Ptr
Definition: colormappable.hh:31
colormap
const Colormap::Ptr colormap
Definition: colormaphelpers_test.cc:54
Operations1bpp::cache
Scroom::Utils::Stuff cache(const ConstTile::Ptr &tile) override
Definition: layeroperations.cc:274
CommonOperations::drawPixelValue
static void drawPixelValue(cairo_t *cr, int x, int y, int size, int value)
Definition: layeroperations.cc:96
LayerOperations::Ptr
boost::shared_ptr< LayerOperations > Ptr
Definition: tiledbitmapinterface.hh:53
Scroom::Utils::Rectangle::y
value_type y() const
Definition: rectangle.hh:127
anonymous_namespace{layeroperations.cc}::shared_malloc
boost::shared_ptr< unsigned char > shared_malloc(size_t size)
Definition: layeroperations.cc:28
bcl
BitCountLut bcl
Definition: layeroperations.cc:45
Scroom::Utils::roundOutward
Segment< double > roundOutward(Segment< double > s)
Definition: linearsegment.hh:240
create
void create(NewPresentationInterface *interface)
Definition: loader.cc:175