2021.05.02 00:36 "[Tiff] SIMD optimizations", by Larry Bank

2021.05.02 17:20 "Re: [Tiff] SIMD optimizations", by Even Rouault

Attached the source code of the bench program I'm using. The image Larry mentions is https://sentinel-cogs.s3.amazonaws.com/sentinel-s2-l2a-cogs/2017/S2A_38PLU_20170615_0_L2A/B02.tif.

On my PC, I get an improvement in the 7-12% range on it (like 25.2s optimized vs 28.4s non-optimized, but timings can vary between successive runs), when using zlib as the deflate subcodec. Around 8% with libdeflate (16.7s vs 18.2s)

What is your CPU spec and OS (Ubuntu 20.04 here)?

At least in my domain of use (geospatial), libtiff is massively used.

PNG/libpng is also used for tile-serving applications, using client-server protocols such as WMTS ( https://www.ogc.org/standards/wmts )

http://www.spatialys.com
My software is free, but my time generally not.

#include "tiffio.h"
#include <stdlib.h>
#include <stdint.h>

int main(int argc, char* argv[])
{
    if( argc != 2 )
    {
        fprintf(stderr, "Usage: ./bench my.tif\n");
        exit(1);
    }
    TIFF* tif = TIFFOpen(argv[1], "r");
    if( tif == NULL )
    {
        fprintf(stderr, "Cannot open %s\n", argv[1]);
        exit(1);
    }
    if( !TIFFIsTiled(tif) )
    {
        fprintf(stderr, "Only tiled image supported\n");
        exit(1);
    }
    int tilesize = (int)TIFFTileSize(tif);
    char* c = malloc(tilesize);
    if( c == NULL )
    {
        fprintf(stderr, "Out of memory\n");
        exit(1);
    }
    const uint32_t numtiles = TIFFNumberOfTiles(tif);
    int numloops = 10 * (int)(1e9 / ((double)tilesize * numtiles));
    //printf("Number of loops: %d\n", numloops);
    for(int i =0; i< numloops; i++)
    {
        for(uint32_t tileindex = 0; tileindex < numtiles; tileindex++ )
        {
            TIFFReadEncodedTile(tif, tileindex, c, tilesize);
        }
    }
    free(c);
    TIFFClose(tif);
    return 0;
}