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.
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);
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
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
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