Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
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 &)
 

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

◆ Operations1bppClipped()

Operations1bppClipped::Operations1bppClipped ( ColormapProvider::Ptr  colormapProvider)
explicit
843 : colormapProvider(std::move(colormapProvider_))
844{
845}
ColormapProvider::Ptr colormapProvider
Definition layeroperations.hh:170

Member Function Documentation

◆ cacheZoom()

Scroom::Utils::Stuff Operations1bppClipped::cacheZoom ( const ConstTile::Ptr ,
int  ,
Scroom::Utils::Stuff  
)
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.

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

◆ create()

LayerOperations::Ptr Operations1bppClipped::create ( ColormapProvider::Ptr  colormapProvider)
static
838{
839 return Ptr(new Operations1bppClipped(std::move(colormapProvider)));
840}
std::shared_ptr< LayerOperations > Ptr
Definition tiledbitmapinterface.hh:52
Definition layeroperations.hh:168

◆ 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.

847{ 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.

901{
902 // Reducing by a factor 8. Source tile is 1bpp. Target tile is 1bpp
903 const int sourceStride = source->width / 8;
904 const byte* sourceBase = source->data.get();
905
906 const int targetStride = target->width / 8;
907 byte* targetBase = target->data.get() + target->height * y * targetStride / 8 + target->width * x / 8 / 8;
908
909 for(int j = 0; j < source->height / 8; j++, targetBase += targetStride, sourceBase += sourceStride * 8)
910 {
911 // Iterate vertically over target
912 const byte* sourcePtr = sourceBase;
913 SampleIterator<byte> targetPtr(targetBase, 0);
914
915 for(int i = 0; i < source->width / 8; i++, sourcePtr++, targetPtr++)
916 {
917 // Iterate horizontally over target
918
919 // Goal is to compute a 8-bit grey value from a 8*8 black/white
920 // image. To do so, we take each of the 8 bytes, count the
921 // number of 1's in each, and add them. Finally, we divide that
922 // by 64 (the maximum number of ones in that area
923
924 const byte* current = sourcePtr;
925 int sum = 0;
926 for(int k = 0; k < 8; k++, current += sourceStride)
927 {
928 sum += bcl.lookup(*current);
929 }
930
931 targetPtr.set((sum > 0) ? 1 : 0);
932 }
933 }
934}
byte lookup(byte index)
Definition layeroperations.cc:61
BitCountLut bcl
Definition layeroperations.cc:45
static unsigned int current
Definition measure-framerate-callbacks.cc:15
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: