managing_image_files.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. .. _doc_managing_image_files:
  2. Managing image files
  3. ====================
  4. If you have read the previous tutorials on :ref:`doc_resources` and
  5. :ref:`doc_filesystem`, at this point you know that regular image files
  6. (.png, .jpg, etc.) are treated as regular resources in Godot.
  7. Unlike texture resources (.tex files), image files contain no extra
  8. information on tiling (texture repeat), mipmaps or filtering. Editing
  9. this information and saving the texture back will not have any effect,
  10. since such formats can't contain that information.
  11. Image loader
  12. ------------
  13. Loading of images is done by the image loader. The behavior of the
  14. loader for all image files can be changed in the Project Settings dialog
  15. (Scene -> Project Settings). There is a section with values that
  16. are used for all image resources:
  17. .. image:: /img/imgloader.png
  18. Image loader options
  19. --------------------
  20. Filter
  21. ~~~~~~
  22. Filter is used when the image is stretched more than its original size,
  23. so a texel in the image is bigger than a pixel on the screen. Turning
  24. off the filter produces a retro-like look:
  25. .. image:: /img/imagefilter.png
  26. Repeat
  27. ~~~~~~
  28. Repeat is mainly used for 3D textures, so it's off by default (textures
  29. are imported with the scenes and usually are not in the project as image
  30. files). When using UV coordinates (something not as common in 2D), and
  31. the UV value goes beyond the 0,0,1,1 rect, the texture repeats instead
  32. of clamping to the edge.
  33. Mipmaps
  34. ~~~~~~~
  35. When the mipmaps option is enabled, Godot will generate mipmaps.
  36. Mipmaps are versions of the image shrunk by half in both axes,
  37. recursively, until the image is 1 pixel of size. When the 3D hardware
  38. needs to shrink the image, it finds the largest mipmap it can scale
  39. from, and scales from there. This improves performance and image
  40. quality.
  41. .. image:: /img/mipmaps.png
  42. When mipmaps are disabled, images start distorting badly when shrunk
  43. excessively:
  44. .. image:: /img/imagemipmap.png
  45. Alpha blending
  46. ~~~~~~~~~~~~~~
  47. The `blending
  48. equation <http://en.wikipedia.org/wiki/Alpha_compositing>`__ used by
  49. applications like Photoshop is too complex for real-time. There are
  50. better approximations such as `pre-multiplied
  51. alpha <http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx?Redirected=true>`__,
  52. but they impose more stress in the asset pipeline. In the end, we are
  53. left with textures that have artifacts in the edges, because apps such
  54. as Photoshop store white pixels in completely transparent areas. Such
  55. white pixels end up showing thanks to the texture filter (when active).
  56. Godot has an option to fix the edges of the image (by painting invisible
  57. pixels the same color as the visible neighbours):
  58. .. image:: /img/fixedborder.png
  59. To do this, open the image from the resources tab, or edit it from the
  60. property editor from another node or resource, then go to the object
  61. options and select "Fix Alpha Edges", then save it.
  62. .. image:: /img/imagefixalpha.png
  63. Since fixing this in so many images can be a little annoying, both
  64. Texture Import and Image Export can also perform this operation.
  65. Texture import
  66. ~~~~~~~~~~~~~~
  67. Sometimes, it might be desirable to change the above settings per image.
  68. Unfortunately, the image loader settings are global. Texture flags also
  69. can't be saved in a regular .png or .jpg file.
  70. For such cases, the image can be imported as a texture (.tex), where the
  71. individual flags can be changed. Godot also keeps track of the original
  72. file and will re-import if it changes.
  73. Importing also allows conversion to other formats (WebP, or RAM
  74. compression) which might be of use in some cases. More information on
  75. the :ref:`doc_importing_textures` page.
  76. Image export
  77. ~~~~~~~~~~~~
  78. It is also possible to convert images to other formats (WebP or RAM
  79. compression) on export, as well as instructing the exporter to create an
  80. Atlas for a set of images. It is also possible to ask the exporter to
  81. scale all images (or selected groups).
  82. More information on the :ref:`doc_exporting_images` page.
  83. Fixing PNGs iCCP chunk
  84. ----------------------
  85. With the upgrade of libpng to 1.6.23, libpng became more strict in terms of
  86. enforcing iCC profile correctness. This means that it now warns when it comes
  87. across an image with a non-conforming iCC chunk.
  88. WARNING: _png_warn_function: iCCP: known incorrect sRGB profile
  89. This can be fixed by either using a tool that exports PNGs with the correct
  90. iCC profile (in some tools this profile can even be manually changed on export)
  91. or using a tool that removes/fixes the iCC chunks.
  92. Linux/Mac
  93. ~~~~~
  94. Using ImageMagicks ``convert`` or ``mogrify`` fixes these warnings.
  95. To fix all PNGs in a project folder do:
  96. .. code-block:: shell
  97. $ find . -type f -name "*.png" -exec convert {} {} \;
  98. ``pngcheck`` is also useful in locating the non-conforming images:
  99. .. code-block:: shell
  100. find . -type f -name "*.png" -exec pngcheck {} \;
  101. Windows
  102. ~~~~~~~
  103. Using `optiPNG <http://optipng.sourceforge.net/>` fixes these warnings on Windows.
  104. To fix a PNG inplace do:
  105. .. code-block:: shell
  106. optipng -clobber -strip all file.png