Scroom  0.14
OperationsColormapped Class Reference

#include <layeroperations.hh>

Inheritance diagram for OperationsColormapped:
Inheritance graph
Collaboration diagram for OperationsColormapped:
Collaboration graph

Public Member Functions

 OperationsColormapped (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
 
- Public Member Functions inherited from Operations
 Operations (ColormapProvider::Ptr colormapProvider, int bpp)
 
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 Operations
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)
 

Additional Inherited Members

- Public Types inherited from LayerOperations
using Ptr = boost::shared_ptr< LayerOperations >
 
- Protected Attributes inherited from Operations
ColormapProvider::Ptr colormapProvider
 
const unsigned bpp
 
const unsigned pixelsPerByte
 
const unsigned pixelOffset
 
const unsigned pixelMask
 

Constructor & Destructor Documentation

◆ OperationsColormapped()

OperationsColormapped::OperationsColormapped ( ColormapProvider::Ptr  colormapProvider,
int  bpp 
)
729  : Operations(std::move(colormapProvider_), bpp_)
730 {
731 }

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ cache()

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

736 {
737  const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, tile->width);
738  boost::shared_ptr<unsigned char> const data = shared_malloc(stride * tile->height);
739  Colormap::Ptr const colormap = colormapProvider->getColormap();
740  const int multiplier = 2; // data is 2*bpp, containing 2 colors
741 
742  unsigned char* row = data.get();
743  for(int j = 0; j < tile->height; j++, row += stride)
744  {
746  reinterpret_cast<uint16_t const*>(tile->data.get() + j * multiplier * tile->width / pixelsPerByte), 0, multiplier * bpp);
747  auto* pixelOut = reinterpret_cast<uint32_t*>(row);
748  for(int i = 0; i < tile->width; i++)
749  {
750  *pixelOut = mix(colormap->colors[*pixelIn & pixelMask], colormap->colors[*pixelIn >> pixelOffset], 0.5).getARGB32();
751 
752  pixelOut++;
753  ++pixelIn;
754  }
755  }
756 
757  return BitmapSurface::create(tile->width, tile->height, CAIRO_FORMAT_ARGB32, stride, data);
758 }
Here is the call graph for this function:

◆ create()

LayerOperations::Ptr OperationsColormapped::create ( ColormapProvider::Ptr  colormapProvider,
int  bpp 
)
static
724 {
725  return Ptr(new OperationsColormapped(std::move(colormapProvider), bpp));
726 }

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

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

◆ getBpp()

int OperationsColormapped::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

Reimplemented from Operations.

733 { return 2 * bpp; }

◆ reduce()

void OperationsColormapped::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()

Reimplemented from Operations.

761 {
762  // Reducing by a factor 8. Source and target both 2*bpp, containing 2 colors
763  const int multiplier = 2; // data is 2*bpp, containing 2 colors
764  const int sourceStride = multiplier * source->width / pixelsPerByte;
765  const byte* sourceBase = source->data.get();
766 
767  const int targetStride = multiplier * target->width / pixelsPerByte;
768  byte* targetBase =
769  target->data.get() + target->height * y * targetStride / 8 + multiplier * target->width * x / 8 / pixelsPerByte;
770 
771  for(int j = 0; j < source->height / 8; j++, targetBase += targetStride, sourceBase += sourceStride * 8)
772  {
773  // Iterate vertically over target
774  const byte* sourcePtr = sourceBase;
775  SampleIterator<uint16_t> targetPtr(reinterpret_cast<uint16_t*>(targetBase), 0, multiplier * bpp);
776 
777  for(int i = 0; i < source->width / 8; i++, sourcePtr += 8 * multiplier / pixelsPerByte, ++targetPtr)
778  {
779  // Iterate horizontally over target
780 
781  // Goal is to determine which value occurs most often in a 8*8
782  // rectangle, and pick that value.
783  const byte* base = sourcePtr;
784  byte lookup[pixelMask + 1];
785  memset(lookup, 0, sizeof(lookup));
786 
787  for(int k = 0; k < 8; k++, base += sourceStride)
788  {
789  SampleIterator<const uint16_t> current(reinterpret_cast<uint16_t const*>(base), 0, multiplier * bpp);
790  for(int l = 0; l < 8; l++, ++current)
791  {
792  ++lookup[*current & pixelMask];
793  ++lookup[*current >> pixelOffset];
794  }
795  }
796  unsigned first = 0;
797  unsigned second = 1;
798  if(lookup[1] > lookup[0])
799  {
800  first = 1;
801  second = 0;
802  }
803  for(unsigned c = 2; c < pixelMask + 1; c++)
804  {
805  if(lookup[c] > lookup[first])
806  {
807  second = first;
808  first = c;
809  }
810  else if(lookup[c] > lookup[second])
811  {
812  second = c;
813  }
814  }
815  if(lookup[second] == 0)
816  {
817  second = first;
818  }
819 
820  targetPtr.set(first << pixelOffset | second);
821  }
822  }
823 }
Here is the call graph for this function:

The documentation for this class was generated from the following files:
Operations::pixelOffset
const unsigned pixelOffset
Definition: layeroperations.hh:126
Operations::bpp
const unsigned bpp
Definition: layeroperations.hh:124
OperationsColormapped::OperationsColormapped
OperationsColormapped(ColormapProvider::Ptr colormapProvider, int bpp)
Definition: layeroperations.cc:728
Operations::pixelsPerByte
const unsigned pixelsPerByte
Definition: layeroperations.hh:125
Scroom::Bitmap::SampleIterator
Definition: bitmap-helpers.hh:61
Operations::pixelMask
const unsigned pixelMask
Definition: layeroperations.hh:127
mix
Color mix(const Color &a, const Color &b, double alpha)
Definition: color.hh:133
current
static unsigned int current
Definition: measure-framerate-callbacks.cc:17
Color::getARGB32
uint32_t getARGB32() const
Definition: color.hh:112
Operations::Operations
Operations(ColormapProvider::Ptr colormapProvider, int bpp)
Definition: layeroperations.cc:579
Colormap::Ptr
boost::shared_ptr< Colormap > Ptr
Definition: colormappable.hh:31
colormap
const Colormap::Ptr colormap
Definition: colormaphelpers_test.cc:54
LayerOperations::Ptr
boost::shared_ptr< LayerOperations > Ptr
Definition: tiledbitmapinterface.hh:53
anonymous_namespace{layeroperations.cc}::shared_malloc
boost::shared_ptr< unsigned char > shared_malloc(size_t size)
Definition: layeroperations.cc:28
Operations::colormapProvider
ColormapProvider::Ptr colormapProvider
Definition: layeroperations.hh:123
create
void create(NewPresentationInterface *interface)
Definition: loader.cc:175