Scroom 0.14-49-gb7ae7a6d
Loading...
Searching...
No Matches
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 = std::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 
)
737 : Operations(std::move(colormapProvider_), bpp_)
738{
739}
Definition layeroperations.hh:127

Member Function Documentation

◆ cache()

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

744{
745 const int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, tile->width);
746 std::shared_ptr<unsigned char> const data = shared_malloc(stride * tile->height);
747 Colormap::Ptr const colormap = colormapProvider->getColormap();
748 const int multiplier = 2; // data is 2*bpp, containing 2 colors
749
750 unsigned char* row = data.get();
751 for(int j = 0; j < tile->height; j++, row += stride)
752 {
754 reinterpret_cast<uint16_t const*>(tile->data.get() + j * multiplier * tile->width / pixelsPerByte), 0, multiplier * bpp
755 );
756 auto* pixelOut = reinterpret_cast<uint32_t*>(row);
757 for(int i = 0; i < tile->width; i++)
758 {
759 *pixelOut = mix(colormap->colors[*pixelIn & pixelMask], colormap->colors[*pixelIn >> pixelOffset], 0.5).getARGB32();
760
761 pixelOut++;
762 ++pixelIn;
763 }
764 }
765
766 return BitmapSurface::create(tile->width, tile->height, CAIRO_FORMAT_ARGB32, stride, data);
767}
uint8_t data
Definition blob-tests.cc:36
uint32_t getARGB32() const
Definition color.hh:112
std::shared_ptr< Colormap > Ptr
Definition colormappable.hh:29
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
static Ptr create(int width, int height, cairo_format_t format)
Definition bitmap-helpers.cc:13
Definition bitmap-helpers.hh:62
Color mix(const Color &a, const Color &b, double alpha)
Definition color.hh:133
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 OperationsColormapped::create ( ColormapProvider::Ptr  colormapProvider,
int  bpp 
)
static
732{
733 return Ptr(new OperationsColormapped(std::move(colormapProvider), bpp));
734}
std::shared_ptr< LayerOperations > Ptr
Definition tiledbitmapinterface.hh:52
Definition layeroperations.hh:157

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

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.

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

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

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