Scroom  0.14
Operations24bpp Class Reference

#include <layeroperations.hh>

Inheritance diagram for Operations24bpp:
Inheritance graph
Collaboration diagram for Operations24bpp:
Collaboration graph

Public Member Functions

 Operations24bpp ()
 
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
 
- Public Member Functions inherited from PipetteCommonOperationsRGB
 PipetteCommonOperationsRGB (int bps_)
 
PipetteLayerOperations::PipetteColor sumPixelValues (Scroom::Utils::Rectangle< int > area, const ConstTile::Ptr &tile) override
 
- 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
 
- 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
 
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
 

Static Public Member Functions

static Ptr create ()
 
- 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)
 

Additional Inherited Members

- Public Types inherited from PipetteCommonOperationsRGB
using Ptr = boost::shared_ptr< PipetteCommonOperationsRGB >
 
- Public Types inherited from PipetteLayerOperations
using Ptr = boost::shared_ptr< PipetteLayerOperations >
 
using PipetteColor = std::vector< std::pair< std::string, double > >
 
- Public Types inherited from LayerOperations
using Ptr = boost::shared_ptr< LayerOperations >
 
- Protected Attributes inherited from PipetteCommonOperationsRGB
int bps
 

Constructor & Destructor Documentation

◆ Operations24bpp()

Operations24bpp::Operations24bpp ( )
502 {
503 }

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ cache()

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

508 {
509  const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, tile->width);
510  boost::shared_ptr<unsigned char> const data = shared_malloc(stride * tile->height);
511  unsigned char* row = data.get();
512  for(int j = 0; j < tile->height; j++, row += stride)
513  {
514  const byte* cur = tile->data.get() + 3 * j * tile->width;
515 
516  auto* pixel = reinterpret_cast<uint32_t*>(row);
517  for(int i = 0; i < tile->width; i++)
518  {
519  // A R G B
520  *pixel = 0xFF000000 | cur[0] << 16 | cur[1] << 8 | cur[2];
521 
522  pixel++;
523  cur += 3;
524  }
525  }
526 
527  return BitmapSurface::create(tile->width, tile->height, CAIRO_FORMAT_ARGB32, stride, data);
528 }
Here is the call graph for this function:

◆ create()

PipetteCommonOperationsRGB::Ptr Operations24bpp::create ( )
static

Referenced by Scroom::TiledBitmap::RGBBitmap().

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

◆ getBpp()

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

505 { return 24; }

◆ reduce()

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

531 {
532  // Reducing by a factor 8. Source tile is 24bpp. Target tile is 24bpp
533  const int sourceStride = 3 * source->width; // stride in bytes
534  const byte* sourceBase = source->data.get();
535 
536  const int targetStride = 3 * target->width; // stride in bytes
537  byte* targetBase = target->data.get() + target->height * y * targetStride / 8 + targetStride * x / 8;
538 
539  for(int j = 0; j < source->height / 8; j++, targetBase += targetStride, sourceBase += sourceStride * 8)
540  {
541  // Iterate vertically over target
542  const byte* sourcePtr = sourceBase;
543  byte* targetPtr = targetBase;
544 
545  for(int i = 0; i < source->width / 8; i++, sourcePtr += 8 * 3, targetPtr += 3)
546  {
547  // Iterate horizontally over target
548 
549  // Goal is to compute a average RGB value from a 8*8 RGB image.
550  const byte* base = sourcePtr;
551  int sum_r = 0;
552  int sum_g = 0;
553  int sum_b = 0;
554  for(int k = 0; k < 8; k++, base += sourceStride)
555  {
556  const byte* current = base;
557  for(int l = 0; l < 8; l++, current += 3)
558  {
559  sum_r += current[0];
560  sum_g += current[1];
561  sum_b += current[2];
562  }
563  }
564  targetPtr[0] = sum_r / 64;
565  targetPtr[1] = sum_g / 64;
566  targetPtr[2] = sum_b / 64;
567  }
568  }
569 }

The documentation for this class was generated from the following files:
current
static unsigned int current
Definition: measure-framerate-callbacks.cc:17
PipetteCommonOperationsRGB::PipetteCommonOperationsRGB
PipetteCommonOperationsRGB(int bps_)
Definition: layeroperations.hh:61
Operations24bpp::Operations24bpp
Operations24bpp()
Definition: layeroperations.cc:500
anonymous_namespace{layeroperations.cc}::shared_malloc
boost::shared_ptr< unsigned char > shared_malloc(size_t size)
Definition: layeroperations.cc:28
PipetteCommonOperationsRGB::Ptr
boost::shared_ptr< PipetteCommonOperationsRGB > Ptr
Definition: layeroperations.hh:58
create
void create(NewPresentationInterface *interface)
Definition: loader.cc:175