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

#include <layeroperations.hh>

Inheritance diagram for Operations8bpp:
Inheritance graph
Collaboration diagram for Operations8bpp:
Collaboration graph

Public Member Functions

 Operations8bpp (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 = std::shared_ptr< LayerOperations >
 

Constructor & Destructor Documentation

◆ Operations8bpp()

Operations8bpp::Operations8bpp ( ColormapProvider::Ptr  colormapProvider)
explicit
387 : colormapProvider(std::move(colormapProvider_))
388{
389}
ColormapProvider::Ptr colormapProvider
Definition layeroperations.hh:95

Member Function Documentation

◆ cache()

Scroom::Utils::Stuff Operations8bpp::cache ( const ConstTile::Ptr )
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.

394{
395 const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, tile->width);
396 std::shared_ptr<unsigned char> const data = shared_malloc(stride * tile->height);
397 Colormap::Ptr const colormap = colormapProvider->getColormap();
398 const Color& c1 = colormap->colors[0];
399 const Color& c2 = colormap->colors[1];
400
401 unsigned char* row = data.get();
402 for(int j = 0; j < tile->height; j++, row += stride)
403 {
404 const byte* cur = tile->data.get() + j * tile->width;
405
406 auto* pixel = reinterpret_cast<uint32_t*>(row);
407 for(int i = 0; i < tile->width; i++)
408 {
409 *pixel = mix(c2, c1, 1.0 * *cur / 255).getARGB32();
410
411 pixel++;
412 ++cur;
413 }
414 }
415
416 return BitmapSurface::create(tile->width, tile->height, CAIRO_FORMAT_ARGB32, stride, data);
417}
uint8_t data
Definition blob-tests.cc:36
Definition color.hh:37
uint32_t getARGB32() const
Definition color.hh:112
std::shared_ptr< Colormap > Ptr
Definition colormappable.hh:29
static Ptr create(int width, int height, cairo_format_t format)
Definition bitmap-helpers.cc:13
Color mix(const Color &a, const Color &b, double alpha)
Definition color.hh:133
Colormap::Ptr const colormap
Definition colormaphelpers_test.cc:55
std::shared_ptr< unsigned char > shared_malloc(size_t size)
Definition layeroperations.cc:28

Referenced by draw().

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

◆ create()

LayerOperations::Ptr Operations8bpp::create ( ColormapProvider::Ptr  colormapProvider)
static
382{
383 return Ptr(new Operations8bpp(std::move(colormapProvider)));
384}
std::shared_ptr< LayerOperations > Ptr
Definition tiledbitmapinterface.hh:52
Definition layeroperations.hh:93

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

Here is the caller graph for this function:

◆ draw()

void Operations8bpp::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.

463{
464 cairo_save(cr);
465 CommonOperations::draw(cr, tile, tileArea, viewArea, zoom, cache);
466 cairo_restore(cr);
467
468 // Draw pixelvalues at 32:1 zoom
469 if(zoom == 5)
470 {
471 const int multiplier = 1 << zoom;
472 const int stride = tile->width;
473 cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
474 cairo_set_font_size(cr, 12.0);
475
476 Colormap::Ptr const colormap = colormapProvider->getColormap();
477 const Color& c1 = colormap->colors[0];
478 const Color& c2 = colormap->colors[1];
479 const byte* const data = tile->data.get();
480
481 auto tileAreaInt = roundOutward(tileArea).to<int>();
482 auto offset = tileAreaInt.getTopLeft() - tileArea.getTopLeft();
483 viewArea += offset * multiplier;
484
485 for(int x = 0; x < tileAreaInt.width(); x++)
486 {
487 for(int y = 0; y < tileAreaInt.height(); y++)
488 {
489 const int value = data[(tileAreaInt.y() + y) * stride + tileAreaInt.x() + x];
490 Color const c = mix(c2, c1, 1.0 * value / 255);
491
492 cairo_save(cr);
493 drawPixelValue(cr, viewArea.x() + multiplier * x, viewArea.y() + multiplier * y, multiplier, value, c);
494 cairo_restore(cr);
495 }
496 }
497 }
498}
const uint8_t value
Definition blob-tests.cc:114
static void drawPixelValue(cairo_t *cr, int x, int y, int size, int value)
Definition layeroperations.cc:96
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
Scroom::Utils::Stuff cache(const ConstTile::Ptr &tile) override
Definition layeroperations.cc:393
value_type y() const
Definition rectangle.hh:127
value_type x() const
Definition rectangle.hh:125
xy_type getTopLeft() const
Definition rectangle.hh:133
Segment< double > roundOutward(Segment< double > s)
Definition linearsegment.hh:240
Semaphore c(0)
cairo_t * cr
Definition transformpresentation_test.cc:72
Here is the call graph for this function:

◆ getBpp()

int Operations8bpp::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.

391{ return 8; }

◆ reduce()

void Operations8bpp::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.

420{
421 // Reducing by a factor 8. Source tile is 8bpp. Target tile is 8bpp
422 const int sourceStride = source->width;
423 const byte* sourceBase = source->data.get();
424
425 const int targetStride = target->width;
426 byte* targetBase = target->data.get() + target->height * y * targetStride / 8 + target->width * x / 8;
427
428 for(int j = 0; j < source->height / 8; j++, targetBase += targetStride, sourceBase += sourceStride * 8)
429 {
430 // Iterate vertically over target
431 const byte* sourcePtr = sourceBase;
432 byte* targetPtr = targetBase;
433
434 for(int i = 0; i < source->width / 8; i++, sourcePtr += 8, targetPtr++)
435 {
436 // Iterate horizontally over target
437
438 // Goal is to compute a 8-bit grey value from a 8*8 grey image.
439 const byte* base = sourcePtr;
440 int sum = 0;
441 for(int k = 0; k < 8; k++, base += sourceStride)
442 {
443 const byte* current = base;
444 for(int l = 0; l < 8; l++, current++)
445 {
446 sum += *current;
447 }
448 }
449
450 *targetPtr = sum / 64;
451 }
452 }
453}
PageList const l
Definition compression-tests.cc:33
static unsigned int current
Definition measure-framerate-callbacks.cc:15

Member Data Documentation

◆ colormapProvider

ColormapProvider::Ptr Operations8bpp::colormapProvider
private

Referenced by cache(), create(), and draw().


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