Page MenuHomePhabricator

PanoProjector -- equirectangular to rectilinear reprojection in C++
Open, HighPublic


I'm proposing to write a tool for reprojecting spherical images in C++, called PanoProjector.

T363891: Panoramic images tiling component would benefit from having a fast cube face extractor, integrated with tiling. Initial investigations show that it can be fast enough such that there is no need for an upload job. It can be handled like thumbnailing.

T363885: Panoramic images thumbnailing component would potentially also benefit, although downscaling needs a slightly different pipeline.


  • Given an equirectangular 360°x180° JPEG, produce a Pannellum-compatible pyramid for a specified face or list of faces. The output face width can be fixed to the Pannellum default.
  • From such an input image, and parameters yaw, pitch, roll, FOV, output width and height, produce a thumbnail image. Good-quality downscaling requires a blurring or block averaging step.

The peakvisor photo converter provided a starting point. I've already tested the following optimisations:

  • Consistent use of single-precision floating point.
  • Use of fmaf().
  • Compilation with -march=skylake allows several very impactful improvements, such as inlining of fmaf().
  • Use of a 6-term polynomial approximation to atan2, as suggested by Francesco Mazzoli.
  • Minor axis symmetry, filling in a row from both ends and meeting in the middle, allows half of the atan2() operations to be skipped.
  • Writing the destination image to disk as it is produced reduces memory usage to the source image surface alone.

The current prototype is about 2x faster than the peakvisor tool, and about 7x faster than Hugin.

Further ideas:

  • Skipping the decoding of unnecessary scanlines in the input image
  • Tile subset extraction with cropping of the input image. Since latency is related to the size of the task, the more you can split it up, the less latency you have.