Scroom  0.14
Operations1bppClipped Class Reference

#include <layeroperations.hh>

Inheritance diagram for Operations1bppClipped:
Inheritance graph
Collaboration diagram for Operations1bppClipped:
Collaboration graph

Public Member Functions

 Operations1bppClipped (ColormapProvider::Ptr colormapProvider)
 
int getBpp () override
 
Scroom::Utils::Stuff cacheZoom (const ConstTile::Ptr &tile, int zoom, Scroom::Utils::Stuff &cache) override
 
void reduce (Tile::Ptr target, ConstTile::Ptr source, int x, int y) 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
 
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 LayerOperations
virtual Scroom::Utils::Stuff cache (const ConstTile::Ptr &tile)
 

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

◆ Operations1bppClipped()

Operations1bppClipped::Operations1bppClipped ( ColormapProvider::Ptr  colormapProvider)
explicit
834  : colormapProvider(std::move(colormapProvider_))
835 {
836 }

Referenced by create().

Here is the caller graph for this function:

Member Function Documentation

◆ cacheZoom()

Scroom::Utils::Stuff Operations1bppClipped::cacheZoom ( const ConstTile::Ptr tile,
int  zoom,
Scroom::Utils::Stuff cache 
)
overridevirtual

Cache data for use during later draw() calls.

This function is called for a given tile and zoom level, and then the results are passed to the draw() 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
zoomthe requested zoom level
cachethe output of cache(const ConstTile::Ptr)

Reimplemented from CommonOperations.

841 {
842  UNUSED(cache);
843 
844  if(zoom >= 0)
845  {
846  zoom = 0;
847  }
848 
849  const int pixelSize = 1 << (-zoom);
850  const int outputWidth = tile->width / pixelSize;
851  const int outputHeight = tile->height / pixelSize;
852 
853  const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, outputWidth);
854  boost::shared_ptr<unsigned char> const data = shared_malloc(stride * outputHeight);
855  Colormap::Ptr const colormap = colormapProvider->getColormap();
856 
857  unsigned char* row = data.get();
858  for(int j = 0; j < outputHeight; j++, row += stride)
859  {
860  auto* pixel = reinterpret_cast<uint32_t*>(row);
861  for(int i = 0; i < outputWidth; i++)
862  {
863  int sum = 0;
864 
865  for(int y = 0; y < pixelSize; y++)
866  {
867  const byte* inputByte = tile->data.get() + (j * pixelSize + y) * tile->width / 8 + pixelSize * i / 8;
868  byte const inputBit = pixelSize * i % 8;
869 
870  SampleIterator<const byte> bit(inputByte, inputBit);
871 
872  for(int x = 0; x < pixelSize; x++, ++bit)
873  {
874  if(*bit)
875  {
876  sum++;
877  }
878  }
879  }
880 
881  if(sum > 0)
882  {
883  sum = 1;
884  }
885  *pixel = colormap->colors[sum].getARGB32();
886  pixel++;
887  }
888  }
889 
890  return BitmapSurface::create(outputWidth, outputHeight, CAIRO_FORMAT_ARGB32, stride, data);
891 }
Here is the call graph for this function:

◆ create()

LayerOperations::Ptr Operations1bppClipped::create ( ColormapProvider::Ptr  colormapProvider)
static
829 {
830  return Ptr(new Operations1bppClipped(std::move(colormapProvider)));
831 }
Here is the call graph for this function:

◆ getBpp()

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

838 { return 1; }

◆ reduce()

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

894 {
895  // Reducing by a factor 8. Source tile is 1bpp. Target tile is 1bpp
896  const int sourceStride = source->width / 8;
897  const byte* sourceBase = source->data.get();
898 
899  const int targetStride = target->width / 8;
900  byte* targetBase = target->data.get() + target->height * y * targetStride / 8 + target->width * x / 8 / 8;
901 
902  for(int j = 0; j < source->height / 8; j++, targetBase += targetStride, sourceBase += sourceStride * 8)
903  {
904  // Iterate vertically over target
905  const byte* sourcePtr = sourceBase;
906  SampleIterator<byte> targetPtr(targetBase, 0);
907 
908  for(int i = 0; i < source->width / 8; i++, sourcePtr++, targetPtr++)
909  {
910  // Iterate horizontally over target
911 
912  // Goal is to compute a 8-bit grey value from a 8*8 black/white
913  // image. To do so, we take each of the 8 bytes, count the
914  // number of 1's in each, and add them. Finally, we divide that
915  // by 64 (the maximum number of ones in that area
916 
917  const byte* current = sourcePtr;
918  int sum = 0;
919  for(int k = 0; k < 8; k++, current += sourceStride)
920  {
921  sum += bcl.lookup(*current);
922  }
923 
924  targetPtr.set((sum > 0) ? 1 : 0);
925  }
926  }
927 }
Here is the call graph for this function:

Member Data Documentation

◆ colormapProvider

ColormapProvider::Ptr Operations1bppClipped::colormapProvider
private

Referenced by cacheZoom(), and create().


The documentation for this class was generated from the following files:
UNUSED
#define UNUSED(x)
Definition: unused.hh:10
BitCountLut::lookup
byte lookup(byte index)
Definition: layeroperations.cc:61
Operations1bppClipped::colormapProvider
ColormapProvider::Ptr colormapProvider
Definition: layeroperations.hh:162
Scroom::Bitmap::SampleIterator
Definition: bitmap-helpers.hh:61
current
static unsigned int current
Definition: measure-framerate-callbacks.cc:17
Operations1bppClipped::Operations1bppClipped
Operations1bppClipped(ColormapProvider::Ptr colormapProvider)
Definition: layeroperations.cc:833
Colormap::Ptr
boost::shared_ptr< Colormap > Ptr
Definition: colormappable.hh:31
colormap
const Colormap::Ptr colormap
Definition: colormaphelpers_test.cc:54
LayerOperations::cache
virtual Scroom::Utils::Stuff cache(const ConstTile::Ptr &tile)
Definition: tiledbitmapinterface.hh:126
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
bcl
BitCountLut bcl
Definition: layeroperations.cc:45
create
void create(NewPresentationInterface *interface)
Definition: loader.cc:175