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

#include <layeroperations.hh>

Inheritance diagram for Operations:
Inheritance graph
Collaboration diagram for Operations:
Collaboration graph

Public Member Functions

 Operations (ColormapProvider::Ptr colormapProvider, int bpp)
 
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, int bpp)
 
- 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)
 

Protected Attributes

ColormapProvider::Ptr colormapProvider
 
const unsigned bpp
 
const unsigned pixelsPerByte
 
const unsigned pixelOffset
 
const unsigned pixelMask
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ Operations()

Operations::Operations ( ColormapProvider::Ptr  colormapProvider,
int  bpp 
)
585 : colormapProvider(std::move(colormapProvider_))
586 , bpp(bpp_)
587 , pixelsPerByte(8 / bpp_)
588 , pixelOffset(bpp_)
589 , pixelMask((1 << bpp_) - 1)
590{
591}
const unsigned bpp
Definition layeroperations.hh:130
const unsigned pixelMask
Definition layeroperations.hh:133
ColormapProvider::Ptr colormapProvider
Definition layeroperations.hh:129
const unsigned pixelOffset
Definition layeroperations.hh:132
const unsigned pixelsPerByte
Definition layeroperations.hh:131

Member Function Documentation

◆ cache()

Scroom::Utils::Stuff Operations::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.

Reimplemented in OperationsColormapped.

596{
597 const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, tile->width);
598 std::shared_ptr<unsigned char> const data = shared_malloc(stride * tile->height);
599 Colormap::Ptr const colormap = colormapProvider->getColormap();
600
601 unsigned char* row = data.get();
602 for(int j = 0; j < tile->height; j++, row += stride)
603 {
604 SampleIterator<const byte> pixelIn(tile->data.get() + j * tile->width / pixelsPerByte, 0, bpp);
605
606 auto* pixelOut = reinterpret_cast<uint32_t*>(row);
607 for(int i = 0; i < tile->width; i++)
608 {
609 *pixelOut = colormap->colors[*pixelIn].getARGB32();
610 pixelOut++;
611 ++pixelIn;
612 }
613 }
614
615 return BitmapSurface::create(tile->width, tile->height, CAIRO_FORMAT_ARGB32, stride, data);
616}
uint8_t data
Definition blob-tests.cc:36
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
Definition bitmap-helpers.hh:62
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 Operations::create ( ColormapProvider::Ptr  colormapProvider,
int  bpp 
)
static
580{
581 return Ptr(new Operations(std::move(colormapProvider), bpp));
582}
std::shared_ptr< LayerOperations > Ptr
Definition tiledbitmapinterface.hh:52
Definition layeroperations.hh:127

Referenced by Scroom::TiledBitmap::ColormappedBitmap(), Scroom::TiledBitmap::GreyscaleBitmap(), setupTest2bpp(), setupTest4bpp(), and setupTest8bppColormapped().

Here is the caller graph for this function:

◆ draw()

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

690{
691 cairo_save(cr);
692 CommonOperations::draw(cr, tile, tileArea, viewArea, zoom, cache);
693 cairo_restore(cr);
694
695 // Draw pixelvalues at 32:1 zoom
696 if(zoom == 5)
697 {
698 const int multiplier = 1 << zoom;
699 const int stride = tile->width / pixelsPerByte;
700 cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
701 cairo_set_font_size(cr, 12.0);
702
703 Colormap::Ptr const colormap = colormapProvider->getColormap();
704
705 auto tileAreaInt = roundOutward(tileArea).to<int>();
706 auto offset = tileAreaInt.getTopLeft() - tileArea.getTopLeft();
707 viewArea += offset * multiplier;
708
709 for(int y = 0; y < tileAreaInt.height(); y++)
710 {
711 const byte* const data = tile->data.get();
712 SampleIterator<const byte> current(data + (tileAreaInt.y() + y) * stride, tileAreaInt.x(), bpp);
713
714 for(int x = 0; x < tileAreaInt.width(); x++, ++current)
715 {
716 const int value = *current;
717
718 cairo_save(cr);
720 cr, viewArea.x() + multiplier * x, viewArea.y() + multiplier * y, multiplier, value, colormap->colors[value]
721 );
722 cairo_restore(cr);
723 }
724 }
725 }
726}
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:595
value_type y() const
Definition rectangle.hh:127
value_type x() const
Definition rectangle.hh:125
xy_type getTopLeft() const
Definition rectangle.hh:133
static unsigned int current
Definition measure-framerate-callbacks.cc:15
Segment< double > roundOutward(Segment< double > s)
Definition linearsegment.hh:240
cairo_t * cr
Definition transformpresentation_test.cc:72
Here is the call graph for this function:

◆ getBpp()

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

Reimplemented in OperationsColormapped.

593{ return bpp; }

◆ reduce()

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

Reimplemented in OperationsColormapped.

619{
620 // Reducing by a factor 8. Target is 2*bpp and expects two indices into the colormap
621 const int sourceStride = source->width / pixelsPerByte;
622 const byte* sourceBase = source->data.get();
623
624 const int targetMultiplier = 2; // target is 2*bpp
625 const int targetStride = targetMultiplier * target->width / pixelsPerByte;
626 byte* targetBase =
627 target->data.get() + target->height * targetStride * y / 8 + targetMultiplier * target->width * x / 8 / pixelsPerByte;
628
629 for(int j = 0; j < source->height / 8; j++, targetBase += targetStride, sourceBase += sourceStride * 8)
630 {
631 // Iterate vertically over target
632 const byte* sourcePtr = sourceBase;
633 SampleIterator<uint16_t> targetPtr(reinterpret_cast<uint16_t*>(targetBase), 0, targetMultiplier * bpp);
634
635 for(int i = 0; i < source->width / 8; i++, sourcePtr += 8 / pixelsPerByte, ++targetPtr)
636 {
637 // Iterate horizontally over target
638
639 // Goal is to determine which values occurs most often in a 8*8
640 // rectangle, and pick the top two.
641 const byte* base = sourcePtr;
642 byte lookup[pixelMask + 1];
643 memset(lookup, 0, sizeof(lookup));
644
645 for(int k = 0; k < 8; k++, base += sourceStride)
646 {
648 for(int l = 0; l < 8; l++, ++current)
649 {
650 ++(lookup[*current]);
651 }
652 }
653 unsigned first = 0;
654 unsigned second = 1;
655 if(lookup[1] > lookup[0])
656 {
657 first = 1;
658 second = 0;
659 }
660 for(unsigned c = 2; c < pixelMask + 1; c++)
661 {
662 if(lookup[c] > lookup[first])
663 {
664 second = first;
665 first = c;
666 }
667 else if(lookup[c] > lookup[second])
668 {
669 second = c;
670 }
671 }
672 if(lookup[second] == 0)
673 {
674 second = first;
675 }
676
677 targetPtr.set(first << pixelOffset | second);
678 }
679 }
680}
memset(expected, value, blobSize)
PageList const l
Definition compression-tests.cc:33
Semaphore c(0)
Here is the call graph for this function:

Member Data Documentation

◆ bpp

◆ colormapProvider

ColormapProvider::Ptr Operations::colormapProvider
protected

◆ pixelMask

const unsigned Operations::pixelMask
protected

◆ pixelOffset

const unsigned Operations::pixelOffset
protected

◆ pixelsPerByte

const unsigned Operations::pixelsPerByte
protected

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