webp_processing.rst 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. .. _webp_processing:
  2. WebP Processing
  3. ===============
  4. **WebP achieves better compression rates by being more complex.
  5. The cost of this complexity is that it's slower, particularly at encoding.**
  6. *"Therefore, it's not usually advisable to convert images to WebP on the fly.
  7. WebP files should be generated in advance."*
  8. (`@webmproject.org <https://groups.google.com/a/webmproject.org/g/webp-discuss/c/Ad6rXupeWZ4>`_)
  9. Detailed information about this image format can be obtained from `Googles WebP Website <https://developers.google.com/speed/webp>`_ and the `WebP Discussion Group <https://groups.google.com/a/webmproject.org/g/webp-discuss>`_.
  10. A simpler representative representation can be found at
  11. `Learn Images! WebP <https://web.dev/learn/images/webp>`_.
  12. **Results based on the standard libraries and the ImageIO WebP extension**
  13. =================== ================== ======================= ========================
  14. tile size [pixel] ImageIO PNG [ms] ImageIO Ext WebP [ms] LibWebP encode [ms]
  15. =================== ================== ======================= ========================
  16. 128 5 67 11.2
  17. 256 15 304 30.1
  18. 512 64 1034 91.4
  19. 1024 177 2089 440.5
  20. 2048 1068 8027 1595.9
  21. =================== ================== ======================= ========================
  22. **Table 1**: Comparison of the processing time for different tile sizes and image formats.
  23. For the ImageIO images, the average of 1000 .write functions was calculated.
  24. With `LibWebP <https://storage.googleapis.com/downloads.webmproject.org/releases/webp/index.html>`_,
  25. the average of the encoding duration was calculated for 10 passes.
  26. For WebP processing, the default settings were used (lossy, q=75) and Version 1.0.0.
  27. `GeoserverRequest <http://localhost:8080/geoserver/tiger/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=tiger%3Apoly_landmarks%2Ctiger%3Atiger_roads&TILED=true&CRS=EPSG%3A4326&STYLES=&WIDTH=256&HEIGHT=256&BBOX=40.72317044999999%2C-74.01748242500003%2C40.80211814999999%2C-73.93853472500001>`_ for image (256*256).
  28. =================== ============== ============= ================== =================
  29. tile size [pixel] PNG original ImageIO PNG ImageIO Ext WebP LibWebP
  30. =================== ============== ============= ================== =================
  31. 128 14 13 5 5
  32. 256 64 60 25 25
  33. 512 223 204 106 106
  34. 1024 805 769 352 352
  35. 2048 2283 2171 1062 1062
  36. =================== ============== ============= ================== =================
  37. **Table 2**: Comparison of the size in KB for different tile sizes and image formats (see table above).
  38. It is obvious that WebP can never match the performance of PNG images due to its encoding time.
  39. However, this does not explain the much worse results of the ImageIO WebP extension.
  40. Unfortunately, the original repository is not available any more, and the main fork
  41. `webp_imageio <https://github.com/sejda-pdf/webp-imageio>`_ is outdated and unmaintained.
  42. The Geoserver plugin is based on the fork from `GOTSON <https://github.com/gotson/webp-imageio>`_.
  43. A hopeful new pure Java implementation is `TwelveMonkeysImageIO WebP <https://github.com/haraldk/TwelveMonkeys>`_,
  44. but so far only supports read access. `Scrimage Webp <https://sksamuel.github.io/scrimage/webp/>`_ produced
  45. mostly faster results, but does not fit in Geoservers ImageIO ecosystem.
  46. Google itself provides for Android `libwebp Java bindings <https://developers.google.com/speed/webp/faq#how_do_i_use_the_libwebp_java_bindings_in_my_android_project>`_.
  47. WebP supports lossless compression (for graphics) and lossy compression (for photos).
  48. Default is lossy with compression quality 75.
  49. * | Lossy compression: A small compression quality factor (q) produces a smaller file with lower quality (best quality q=100).
  50. * | Lossless compression: A small factor enables faster compression speed, but produces a larger file (maximum compression q=100).
  51. ===== =============== =============== ============ ============
  52. q lossless [ms] lossless [kb] lossy [ms] lossy [kb]
  53. ===== =============== =============== ============ ============
  54. 0.0 48 57 **18.6** **25**
  55. 0.1 48.8 57 19.5 26
  56. 0.2 48.7 57 19.7 27
  57. 0.3 82.6 45 20.4 27
  58. 0.4 84.6 45 20.6 28
  59. 0.5 85.6 45 20.8 29
  60. 0.6 89.1 45 20.8 29
  61. 0.7 93.9 45 21.2 30
  62. 0.8 99.3 45 21.4 32
  63. 0.9 99.3 45 22.5 36
  64. 1.0 1425 44 25.3 46
  65. ===== =============== =============== ============ ============
  66. **Table 3**: Comparison of the lossy/lossless mode and compression factor (q) for LibWebP encoding time and file size.
  67. Input image, see below. The average of the encoding duration was calculated for 10 passes.
  68. ===== =============== =============== ============ ============
  69. q lossless [ms] lossless [kb] lossy [ms] lossy [kb]
  70. ===== =============== =============== ============ ============
  71. 0.0 242 57 **113** **25**
  72. 0.1 211 57 145 26
  73. 0.2 236 57 137 27
  74. 0.3 370 45 150 27
  75. 0.4 376 45 140 28
  76. 0.5 308 45 128 29
  77. 0.6 375 45 123 29
  78. 0.7 529 45 126 30
  79. 0.8 468 45 125 32
  80. 0.9 424 45 130 36
  81. 1.0 3106 44 184 46
  82. ===== =============== =============== ============ ============
  83. **Table 4**: Comparison of the lossy/lossless mode and compression factor (q) for ImageIO WebP extension .write time and file size.
  84. Input image, see below. The average of 1000 .write functions was calculated.
  85. .. figure:: images/lossy_lossless.png
  86. **Figure 1**: Input image for comparison in table 3 and 4 (PNG 256 * 256 px, 73 kb).
  87. Unfortunately, the best result regarding speed and size is not really usable (see below).
  88. .. figure:: images/libweb_lossy_0_0.png
  89. **Figure 2**: Image of the best result (lossy, q=0).
  90. In general, the default values (lossy, q=0.75) are a good choice.
  91. The significantly longer duration regarding the ImageIO Extension cannot be explained
  92. by the writing process alone (compare tables 3 & 4).
  93. **Processing time & energy consumption**
  94. The increased processing time correlates with increased energy consumption.
  95. Measured with a commercial power meter on a local PC for one hour (multiple times).
  96. Stack:
  97. * | Windows10
  98. * | Java11
  99. * | Tomcat9
  100. * | Chrome Browser
  101. * | OpenLayers Client
  102. * | random WMS GetMap requests every 0.5 seconds
  103. Result:
  104. * | PNG 0.067 kWh
  105. * | WebP 0.071 kWh
  106. * | NoRequests 0.047 kWh
  107. This also applies to the JPEG format in a weakened way.
  108. **Browser rendering energy impact for different image formats**
  109. =================== ================
  110. Image Format Energie impact
  111. =================== ================
  112. WebP 0.4532
  113. PNG 0.4545
  114. PNG8 0.457
  115. JPEG 0.4414
  116. =================== ================
  117. **Table 5**: Comparison of the rendering energy consumption for different image formats in Firefox.
  118. Average of 1000 WMS GetMap requests.
  119. Firefox "Energy Impact" (about\:processes page) shows the processing power being used by the CPU.
  120. Despite the different file sizes of the image formats, no really significant differences can be seen.
  121. Of course, more complex coding also requires more complex decoding.