Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

optimize png8:t=0 (no transparency mode for reduced color png) #1557

Closed
springmeyer opened this Issue Nov 4, 2012 · 3 comments

Comments

Projects
None yet
2 participants
Owner

springmeyer commented Nov 4, 2012

The PNG format is best for images with alpha (vs a format like jpeg which is great for non-alpha images).

However, in some cases encoding non-alpha images as PNG may be desirable and we should try to optimize this code path.

Currently this is supported for reduced color (octree/hextree) encoded PNG's, however:

  1. encoding speeds for t=0 are much slower than t=1 which should not be the case. I presume this is because this code path has never really been used much and various assumptions for handling alpha (like this break) are not hit when trans_mode=0 leading to more work being done.
  2. if t=0 then we can likely set PNG_COLOR_TYPE_RGB and PNG_TRANSFORM_STRIP_FILLER_AFTER which may give speed or size benefits for full color PNG s (24 bit)
Contributor

lightmare commented Nov 4, 2012

https://github.com/mapnik/mapnik/blob/master/include/mapnik/png_io.hpp#L294
this loop can be replaced with (probably won't solve the issue, but looks wasteful)

if (trans_mode == 0) {
  alphaHist[255] = width * height;
  meanAlpha = 255;
}
else {
  for <original loop>
  meanAlpha /= width * height;
}
Owner

springmeyer commented Nov 6, 2012

Thanks. I think the issue is that tree.quantize() is expensive and even if trans_mode == 0 more trees as built and processed than needed. However, the refactoring involved in messing with this is a bit narly.

springmeyer pushed a commit that referenced this issue Nov 8, 2012

springmeyer pushed a commit that referenced this issue Nov 8, 2012

@springmeyer springmeyer referenced this issue in tilemill-project/tilemill Dec 11, 2012

Closed

default to png8:m=h PNG format #1764

PetrDlouhy added a commit to PetrDlouhy/mapnik that referenced this issue Aug 22, 2013

PetrDlouhy added a commit to PetrDlouhy/mapnik that referenced this issue Aug 22, 2013

PetrDlouhy added a commit to PetrDlouhy/mapnik that referenced this issue Aug 22, 2013

Owner

springmeyer commented Oct 4, 2013

nothing more actionable here. t=0 is still slower than t>0 for png8 with both hextree and octree for blank images at least, but optimizing this is not critical.

@springmeyer springmeyer closed this Oct 4, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment