class_image.rst 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.5/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.5/doc/classes/Image.xml.
  6. .. _class_Image:
  7. Image
  8. =====
  9. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Image datatype.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Native image datatype. Contains image data which can be converted to an :ref:`ImageTexture<class_ImageTexture>` and provides commonly used *image processing* methods. The maximum width and height for an **Image** are :ref:`MAX_WIDTH<class_Image_constant_MAX_WIDTH>` and :ref:`MAX_HEIGHT<class_Image_constant_MAX_HEIGHT>`.
  15. An **Image** cannot be assigned to a ``texture`` property of an object directly (such as :ref:`Sprite<class_Sprite>`), and has to be converted manually to an :ref:`ImageTexture<class_ImageTexture>` first.
  16. \ **Note:** The maximum image size is 16384×16384 pixels due to graphics hardware limitations. Larger images may fail to import.
  17. .. rst-class:: classref-introduction-group
  18. Tutorials
  19. ---------
  20. - :doc:`Importing images <../tutorials/assets_pipeline/importing_images>`
  21. .. rst-class:: classref-reftable-group
  22. Properties
  23. ----------
  24. .. table::
  25. :widths: auto
  26. +-------------------------------------+----------------------------------------+------------------------------------------------------------------------------------------+
  27. | :ref:`Dictionary<class_Dictionary>` | :ref:`data<class_Image_property_data>` | ``{"data": PoolByteArray( ),"format": "Lum8","height": 0,"mipmaps": false,"width": 0}`` |
  28. +-------------------------------------+----------------------------------------+------------------------------------------------------------------------------------------+
  29. .. rst-class:: classref-reftable-group
  30. Methods
  31. -------
  32. .. table::
  33. :widths: auto
  34. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | void | :ref:`blend_rect<class_Image_method_blend_rect>` **(** :ref:`Image<class_Image>` src, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)** |
  36. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`blend_rect_mask<class_Image_method_blend_rect_mask>` **(** :ref:`Image<class_Image>` src, :ref:`Image<class_Image>` mask, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)** |
  38. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | void | :ref:`blit_rect<class_Image_method_blit_rect>` **(** :ref:`Image<class_Image>` src, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)** |
  40. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`blit_rect_mask<class_Image_method_blit_rect_mask>` **(** :ref:`Image<class_Image>` src, :ref:`Image<class_Image>` mask, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)** |
  42. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`bumpmap_to_normalmap<class_Image_method_bumpmap_to_normalmap>` **(** :ref:`float<class_float>` bump_scale=1.0 **)** |
  44. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`clear_mipmaps<class_Image_method_clear_mipmaps>` **(** **)** |
  46. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`compress<class_Image_method_compress>` **(** :ref:`CompressMode<enum_Image_CompressMode>` mode, :ref:`CompressSource<enum_Image_CompressSource>` source, :ref:`float<class_float>` lossy_quality **)** |
  48. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`convert<class_Image_method_convert>` **(** :ref:`Format<enum_Image_Format>` format **)** |
  50. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`copy_from<class_Image_method_copy_from>` **(** :ref:`Image<class_Image>` src **)** |
  52. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`create<class_Image_method_create>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format **)** |
  54. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`create_from_data<class_Image_method_create_from_data>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format, :ref:`PoolByteArray<class_PoolByteArray>` data **)** |
  56. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`crop<class_Image_method_crop>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height **)** |
  58. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`decompress<class_Image_method_decompress>` **(** **)** |
  60. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`AlphaMode<enum_Image_AlphaMode>` | :ref:`detect_alpha<class_Image_method_detect_alpha>` **(** **)** |const| |
  62. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`expand_x2_hq2x<class_Image_method_expand_x2_hq2x>` **(** **)** |
  64. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`fill<class_Image_method_fill>` **(** :ref:`Color<class_Color>` color **)** |
  66. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`fill_rect<class_Image_method_fill_rect>` **(** :ref:`Rect2<class_Rect2>` rect, :ref:`Color<class_Color>` color **)** |
  68. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`fix_alpha_edges<class_Image_method_fix_alpha_edges>` **(** **)** |
  70. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`flip_x<class_Image_method_flip_x>` **(** **)** |
  72. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`flip_y<class_Image_method_flip_y>` **(** **)** |
  74. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>` **(** :ref:`bool<class_bool>` renormalize=false **)** |
  76. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`get_data<class_Image_method_get_data>` **(** **)** |const| |
  78. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`Format<enum_Image_Format>` | :ref:`get_format<class_Image_method_get_format>` **(** **)** |const| |
  80. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`int<class_int>` | :ref:`get_height<class_Image_method_get_height>` **(** **)** |const| |
  82. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`int<class_int>` | :ref:`get_mipmap_offset<class_Image_method_get_mipmap_offset>` **(** :ref:`int<class_int>` mipmap **)** |const| |
  84. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`Color<class_Color>` | :ref:`get_pixel<class_Image_method_get_pixel>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const| |
  86. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`Color<class_Color>` | :ref:`get_pixelv<class_Image_method_get_pixelv>` **(** :ref:`Vector2<class_Vector2>` src **)** |const| |
  88. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`Image<class_Image>` | :ref:`get_rect<class_Image_method_get_rect>` **(** :ref:`Rect2<class_Rect2>` rect **)** |const| |
  90. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Vector2<class_Vector2>` | :ref:`get_size<class_Image_method_get_size>` **(** **)** |const| |
  92. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`Rect2<class_Rect2>` | :ref:`get_used_rect<class_Image_method_get_used_rect>` **(** **)** |const| |
  94. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`int<class_int>` | :ref:`get_width<class_Image_method_get_width>` **(** **)** |const| |
  96. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`bool<class_bool>` | :ref:`has_mipmaps<class_Image_method_has_mipmaps>` **(** **)** |const| |
  98. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. | :ref:`bool<class_bool>` | :ref:`is_compressed<class_Image_method_is_compressed>` **(** **)** |const| |
  100. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  101. | :ref:`bool<class_bool>` | :ref:`is_empty<class_Image_method_is_empty>` **(** **)** |const| |
  102. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  103. | :ref:`bool<class_bool>` | :ref:`is_invisible<class_Image_method_is_invisible>` **(** **)** |const| |
  104. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load<class_Image_method_load>` **(** :ref:`String<class_String>` path **)** |
  106. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_bmp_from_buffer<class_Image_method_load_bmp_from_buffer>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  108. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_jpg_from_buffer<class_Image_method_load_jpg_from_buffer>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  110. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  111. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_png_from_buffer<class_Image_method_load_png_from_buffer>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  112. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  113. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_tga_from_buffer<class_Image_method_load_tga_from_buffer>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  114. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  115. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`load_webp_from_buffer<class_Image_method_load_webp_from_buffer>` **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)** |
  116. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  117. | void | :ref:`lock<class_Image_method_lock>` **(** **)** |
  118. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  119. | void | :ref:`normalmap_to_xy<class_Image_method_normalmap_to_xy>` **(** **)** |
  120. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  121. | void | :ref:`premultiply_alpha<class_Image_method_premultiply_alpha>` **(** **)** |
  122. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  123. | void | :ref:`resize<class_Image_method_resize>` **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)** |
  124. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  125. | void | :ref:`resize_to_po2<class_Image_method_resize_to_po2>` **(** :ref:`bool<class_bool>` square=false, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)** |
  126. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | :ref:`Image<class_Image>` | :ref:`rgbe_to_srgb<class_Image_method_rgbe_to_srgb>` **(** **)** |
  128. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_exr<class_Image_method_save_exr>` **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` grayscale=false **)** |const| |
  130. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  131. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`save_png<class_Image_method_save_png>` **(** :ref:`String<class_String>` path **)** |const| |
  132. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  133. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`save_png_to_buffer<class_Image_method_save_png_to_buffer>` **(** **)** |const| |
  134. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | void | :ref:`set_pixel<class_Image_method_set_pixel>` **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`Color<class_Color>` color **)** |
  136. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | void | :ref:`set_pixelv<class_Image_method_set_pixelv>` **(** :ref:`Vector2<class_Vector2>` dst, :ref:`Color<class_Color>` color **)** |
  138. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | void | :ref:`shrink_x2<class_Image_method_shrink_x2>` **(** **)** |
  140. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  141. | void | :ref:`srgb_to_linear<class_Image_method_srgb_to_linear>` **(** **)** |
  142. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  143. | void | :ref:`unlock<class_Image_method_unlock>` **(** **)** |
  144. +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  145. .. rst-class:: classref-section-separator
  146. ----
  147. .. rst-class:: classref-descriptions-group
  148. Enumerations
  149. ------------
  150. .. _enum_Image_Format:
  151. .. rst-class:: classref-enumeration
  152. enum **Format**:
  153. .. _class_Image_constant_FORMAT_L8:
  154. .. rst-class:: classref-enumeration-constant
  155. :ref:`Format<enum_Image_Format>` **FORMAT_L8** = ``0``
  156. Texture format with a single 8-bit depth representing luminance.
  157. .. _class_Image_constant_FORMAT_LA8:
  158. .. rst-class:: classref-enumeration-constant
  159. :ref:`Format<enum_Image_Format>` **FORMAT_LA8** = ``1``
  160. OpenGL texture format with two values, luminance and alpha each stored with 8 bits.
  161. .. _class_Image_constant_FORMAT_R8:
  162. .. rst-class:: classref-enumeration-constant
  163. :ref:`Format<enum_Image_Format>` **FORMAT_R8** = ``2``
  164. OpenGL texture format ``RED`` with a single component and a bitdepth of 8.
  165. \ **Note:** When using the GLES2 backend, this uses the alpha channel instead of the red channel for storage.
  166. .. _class_Image_constant_FORMAT_RG8:
  167. .. rst-class:: classref-enumeration-constant
  168. :ref:`Format<enum_Image_Format>` **FORMAT_RG8** = ``3``
  169. OpenGL texture format ``RG`` with two components and a bitdepth of 8 for each.
  170. .. _class_Image_constant_FORMAT_RGB8:
  171. .. rst-class:: classref-enumeration-constant
  172. :ref:`Format<enum_Image_Format>` **FORMAT_RGB8** = ``4``
  173. OpenGL texture format ``RGB`` with three components, each with a bitdepth of 8.
  174. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  175. .. _class_Image_constant_FORMAT_RGBA8:
  176. .. rst-class:: classref-enumeration-constant
  177. :ref:`Format<enum_Image_Format>` **FORMAT_RGBA8** = ``5``
  178. OpenGL texture format ``RGBA`` with four components, each with a bitdepth of 8.
  179. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  180. .. _class_Image_constant_FORMAT_RGBA4444:
  181. .. rst-class:: classref-enumeration-constant
  182. :ref:`Format<enum_Image_Format>` **FORMAT_RGBA4444** = ``6``
  183. OpenGL texture format ``RGBA`` with four components, each with a bitdepth of 4.
  184. .. _class_Image_constant_FORMAT_RGBA5551:
  185. .. rst-class:: classref-enumeration-constant
  186. :ref:`Format<enum_Image_Format>` **FORMAT_RGBA5551** = ``7``
  187. OpenGL texture format ``GL_RGB5_A1`` where 5 bits of depth for each component of RGB and one bit for alpha.
  188. .. _class_Image_constant_FORMAT_RF:
  189. .. rst-class:: classref-enumeration-constant
  190. :ref:`Format<enum_Image_Format>` **FORMAT_RF** = ``8``
  191. OpenGL texture format ``GL_R32F`` where there's one component, a 32-bit floating-point value.
  192. .. _class_Image_constant_FORMAT_RGF:
  193. .. rst-class:: classref-enumeration-constant
  194. :ref:`Format<enum_Image_Format>` **FORMAT_RGF** = ``9``
  195. OpenGL texture format ``GL_RG32F`` where there are two components, each a 32-bit floating-point values.
  196. .. _class_Image_constant_FORMAT_RGBF:
  197. .. rst-class:: classref-enumeration-constant
  198. :ref:`Format<enum_Image_Format>` **FORMAT_RGBF** = ``10``
  199. OpenGL texture format ``GL_RGB32F`` where there are three components, each a 32-bit floating-point values.
  200. .. _class_Image_constant_FORMAT_RGBAF:
  201. .. rst-class:: classref-enumeration-constant
  202. :ref:`Format<enum_Image_Format>` **FORMAT_RGBAF** = ``11``
  203. OpenGL texture format ``GL_RGBA32F`` where there are four components, each a 32-bit floating-point values.
  204. .. _class_Image_constant_FORMAT_RH:
  205. .. rst-class:: classref-enumeration-constant
  206. :ref:`Format<enum_Image_Format>` **FORMAT_RH** = ``12``
  207. OpenGL texture format ``GL_R32F`` where there's one component, a 16-bit "half-precision" floating-point value.
  208. .. _class_Image_constant_FORMAT_RGH:
  209. .. rst-class:: classref-enumeration-constant
  210. :ref:`Format<enum_Image_Format>` **FORMAT_RGH** = ``13``
  211. OpenGL texture format ``GL_RG32F`` where there are two components, each a 16-bit "half-precision" floating-point value.
  212. .. _class_Image_constant_FORMAT_RGBH:
  213. .. rst-class:: classref-enumeration-constant
  214. :ref:`Format<enum_Image_Format>` **FORMAT_RGBH** = ``14``
  215. OpenGL texture format ``GL_RGB32F`` where there are three components, each a 16-bit "half-precision" floating-point value.
  216. .. _class_Image_constant_FORMAT_RGBAH:
  217. .. rst-class:: classref-enumeration-constant
  218. :ref:`Format<enum_Image_Format>` **FORMAT_RGBAH** = ``15``
  219. OpenGL texture format ``GL_RGBA32F`` where there are four components, each a 16-bit "half-precision" floating-point value.
  220. .. _class_Image_constant_FORMAT_RGBE9995:
  221. .. rst-class:: classref-enumeration-constant
  222. :ref:`Format<enum_Image_Format>` **FORMAT_RGBE9995** = ``16``
  223. A special OpenGL texture format where the three color components have 9 bits of precision and all three share a single 5-bit exponent.
  224. .. _class_Image_constant_FORMAT_DXT1:
  225. .. rst-class:: classref-enumeration-constant
  226. :ref:`Format<enum_Image_Format>` **FORMAT_DXT1** = ``17``
  227. The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ texture format that uses Block Compression 1, and is the smallest variation of S3TC, only providing 1 bit of alpha and color data being premultiplied with alpha.
  228. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  229. .. _class_Image_constant_FORMAT_DXT3:
  230. .. rst-class:: classref-enumeration-constant
  231. :ref:`Format<enum_Image_Format>` **FORMAT_DXT3** = ``18``
  232. The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ texture format that uses Block Compression 2, and color data is interpreted as not having been premultiplied by alpha. Well suited for images with sharp alpha transitions between translucent and opaque areas.
  233. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  234. .. _class_Image_constant_FORMAT_DXT5:
  235. .. rst-class:: classref-enumeration-constant
  236. :ref:`Format<enum_Image_Format>` **FORMAT_DXT5** = ``19``
  237. The `S3TC <https://en.wikipedia.org/wiki/S3_Texture_Compression>`__ texture format also known as Block Compression 3 or BC3 that contains 64 bits of alpha channel data followed by 64 bits of DXT1-encoded color data. Color data is not premultiplied by alpha, same as DXT3. DXT5 generally produces superior results for transparent gradients compared to DXT3.
  238. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  239. .. _class_Image_constant_FORMAT_RGTC_R:
  240. .. rst-class:: classref-enumeration-constant
  241. :ref:`Format<enum_Image_Format>` **FORMAT_RGTC_R** = ``20``
  242. Texture format that uses `Red Green Texture Compression <https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression>`__, normalizing the red channel data using the same compression algorithm that DXT5 uses for the alpha channel.
  243. .. _class_Image_constant_FORMAT_RGTC_RG:
  244. .. rst-class:: classref-enumeration-constant
  245. :ref:`Format<enum_Image_Format>` **FORMAT_RGTC_RG** = ``21``
  246. Texture format that uses `Red Green Texture Compression <https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression>`__, normalizing the red and green channel data using the same compression algorithm that DXT5 uses for the alpha channel.
  247. .. _class_Image_constant_FORMAT_BPTC_RGBA:
  248. .. rst-class:: classref-enumeration-constant
  249. :ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBA** = ``22``
  250. Texture format that uses `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ compression with unsigned normalized RGBA components.
  251. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  252. .. _class_Image_constant_FORMAT_BPTC_RGBF:
  253. .. rst-class:: classref-enumeration-constant
  254. :ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBF** = ``23``
  255. Texture format that uses `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ compression with signed floating-point RGB components.
  256. .. _class_Image_constant_FORMAT_BPTC_RGBFU:
  257. .. rst-class:: classref-enumeration-constant
  258. :ref:`Format<enum_Image_Format>` **FORMAT_BPTC_RGBFU** = ``24``
  259. Texture format that uses `BPTC <https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression>`__ compression with unsigned floating-point RGB components.
  260. .. _class_Image_constant_FORMAT_PVRTC2:
  261. .. rst-class:: classref-enumeration-constant
  262. :ref:`Format<enum_Image_Format>` **FORMAT_PVRTC2** = ``25``
  263. Texture format used on PowerVR-supported mobile platforms, uses 2-bit color depth with no alpha. More information can be found `here <https://en.wikipedia.org/wiki/PVRTC>`__.
  264. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  265. .. _class_Image_constant_FORMAT_PVRTC2A:
  266. .. rst-class:: classref-enumeration-constant
  267. :ref:`Format<enum_Image_Format>` **FORMAT_PVRTC2A** = ``26``
  268. Same as `PVRTC2 <https://en.wikipedia.org/wiki/PVRTC>`__, but with an alpha component.
  269. .. _class_Image_constant_FORMAT_PVRTC4:
  270. .. rst-class:: classref-enumeration-constant
  271. :ref:`Format<enum_Image_Format>` **FORMAT_PVRTC4** = ``27``
  272. Similar to `PVRTC2 <https://en.wikipedia.org/wiki/PVRTC>`__, but with 4-bit color depth and no alpha.
  273. .. _class_Image_constant_FORMAT_PVRTC4A:
  274. .. rst-class:: classref-enumeration-constant
  275. :ref:`Format<enum_Image_Format>` **FORMAT_PVRTC4A** = ``28``
  276. Same as `PVRTC4 <https://en.wikipedia.org/wiki/PVRTC>`__, but with an alpha component.
  277. .. _class_Image_constant_FORMAT_ETC:
  278. .. rst-class:: classref-enumeration-constant
  279. :ref:`Format<enum_Image_Format>` **FORMAT_ETC** = ``29``
  280. `Ericsson Texture Compression format 1 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC1>`__, also referred to as "ETC1", and is part of the OpenGL ES graphics standard. This format cannot store an alpha channel.
  281. .. _class_Image_constant_FORMAT_ETC2_R11:
  282. .. rst-class:: classref-enumeration-constant
  283. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_R11** = ``30``
  284. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``R11_EAC`` variant), which provides one channel of unsigned data.
  285. .. _class_Image_constant_FORMAT_ETC2_R11S:
  286. .. rst-class:: classref-enumeration-constant
  287. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_R11S** = ``31``
  288. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``SIGNED_R11_EAC`` variant), which provides one channel of signed data.
  289. .. _class_Image_constant_FORMAT_ETC2_RG11:
  290. .. rst-class:: classref-enumeration-constant
  291. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RG11** = ``32``
  292. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RG11_EAC`` variant), which provides two channels of unsigned data.
  293. .. _class_Image_constant_FORMAT_ETC2_RG11S:
  294. .. rst-class:: classref-enumeration-constant
  295. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RG11S** = ``33``
  296. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``SIGNED_RG11_EAC`` variant), which provides two channels of signed data.
  297. .. _class_Image_constant_FORMAT_ETC2_RGB8:
  298. .. rst-class:: classref-enumeration-constant
  299. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGB8** = ``34``
  300. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGB8`` variant), which is a follow-up of ETC1 and compresses RGB888 data.
  301. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  302. .. _class_Image_constant_FORMAT_ETC2_RGBA8:
  303. .. rst-class:: classref-enumeration-constant
  304. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGBA8** = ``35``
  305. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGBA8``\ variant), which compresses RGBA8888 data with full alpha support.
  306. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  307. .. _class_Image_constant_FORMAT_ETC2_RGB8A1:
  308. .. rst-class:: classref-enumeration-constant
  309. :ref:`Format<enum_Image_Format>` **FORMAT_ETC2_RGB8A1** = ``36``
  310. `Ericsson Texture Compression format 2 <https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC2_and_EAC>`__ (``RGB8_PUNCHTHROUGH_ALPHA1`` variant), which compresses RGBA data to make alpha either fully transparent or fully opaque.
  311. \ **Note:** When creating an :ref:`ImageTexture<class_ImageTexture>`, an sRGB to linear color space conversion is performed.
  312. .. _class_Image_constant_FORMAT_MAX:
  313. .. rst-class:: classref-enumeration-constant
  314. :ref:`Format<enum_Image_Format>` **FORMAT_MAX** = ``37``
  315. Represents the size of the :ref:`Format<enum_Image_Format>` enum.
  316. .. rst-class:: classref-item-separator
  317. ----
  318. .. _enum_Image_Interpolation:
  319. .. rst-class:: classref-enumeration
  320. enum **Interpolation**:
  321. .. _class_Image_constant_INTERPOLATE_NEAREST:
  322. .. rst-class:: classref-enumeration-constant
  323. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_NEAREST** = ``0``
  324. Performs nearest-neighbor interpolation. If the image is resized, it will be pixelated.
  325. .. _class_Image_constant_INTERPOLATE_BILINEAR:
  326. .. rst-class:: classref-enumeration-constant
  327. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_BILINEAR** = ``1``
  328. Performs bilinear interpolation. If the image is resized, it will be blurry. This mode is faster than :ref:`INTERPOLATE_CUBIC<class_Image_constant_INTERPOLATE_CUBIC>`, but it results in lower quality.
  329. .. _class_Image_constant_INTERPOLATE_CUBIC:
  330. .. rst-class:: classref-enumeration-constant
  331. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_CUBIC** = ``2``
  332. Performs cubic interpolation. If the image is resized, it will be blurry. This mode often gives better results compared to :ref:`INTERPOLATE_BILINEAR<class_Image_constant_INTERPOLATE_BILINEAR>`, at the cost of being slower.
  333. .. _class_Image_constant_INTERPOLATE_TRILINEAR:
  334. .. rst-class:: classref-enumeration-constant
  335. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_TRILINEAR** = ``3``
  336. Performs bilinear separately on the two most-suited mipmap levels, then linearly interpolates between them.
  337. It's slower than :ref:`INTERPOLATE_BILINEAR<class_Image_constant_INTERPOLATE_BILINEAR>`, but produces higher-quality results with far fewer aliasing artifacts.
  338. If the image does not have mipmaps, they will be generated and used internally, but no mipmaps will be generated on the resulting image.
  339. \ **Note:** If you intend to scale multiple copies of the original image, it's better to call :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>`] on it in advance, to avoid wasting processing power in generating them again and again.
  340. On the other hand, if the image already has mipmaps, they will be used, and a new set will be generated for the resulting image.
  341. .. _class_Image_constant_INTERPOLATE_LANCZOS:
  342. .. rst-class:: classref-enumeration-constant
  343. :ref:`Interpolation<enum_Image_Interpolation>` **INTERPOLATE_LANCZOS** = ``4``
  344. Performs Lanczos interpolation. This is the slowest image resizing mode, but it typically gives the best results, especially when downscalng images.
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _enum_Image_AlphaMode:
  348. .. rst-class:: classref-enumeration
  349. enum **AlphaMode**:
  350. .. _class_Image_constant_ALPHA_NONE:
  351. .. rst-class:: classref-enumeration-constant
  352. :ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_NONE** = ``0``
  353. Image does not have alpha.
  354. .. _class_Image_constant_ALPHA_BIT:
  355. .. rst-class:: classref-enumeration-constant
  356. :ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_BIT** = ``1``
  357. Image stores alpha in a single bit.
  358. .. _class_Image_constant_ALPHA_BLEND:
  359. .. rst-class:: classref-enumeration-constant
  360. :ref:`AlphaMode<enum_Image_AlphaMode>` **ALPHA_BLEND** = ``2``
  361. Image uses alpha.
  362. .. rst-class:: classref-item-separator
  363. ----
  364. .. _enum_Image_CompressMode:
  365. .. rst-class:: classref-enumeration
  366. enum **CompressMode**:
  367. .. _class_Image_constant_COMPRESS_S3TC:
  368. .. rst-class:: classref-enumeration-constant
  369. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_S3TC** = ``0``
  370. Use S3TC compression.
  371. .. _class_Image_constant_COMPRESS_PVRTC2:
  372. .. rst-class:: classref-enumeration-constant
  373. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_PVRTC2** = ``1``
  374. Use PVRTC2 compression.
  375. .. _class_Image_constant_COMPRESS_PVRTC4:
  376. .. rst-class:: classref-enumeration-constant
  377. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_PVRTC4** = ``2``
  378. Use PVRTC4 compression.
  379. .. _class_Image_constant_COMPRESS_ETC:
  380. .. rst-class:: classref-enumeration-constant
  381. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_ETC** = ``3``
  382. Use ETC compression.
  383. .. _class_Image_constant_COMPRESS_ETC2:
  384. .. rst-class:: classref-enumeration-constant
  385. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_ETC2** = ``4``
  386. Use ETC2 compression.
  387. .. rst-class:: classref-item-separator
  388. ----
  389. .. _enum_Image_CompressSource:
  390. .. rst-class:: classref-enumeration
  391. enum **CompressSource**:
  392. .. _class_Image_constant_COMPRESS_SOURCE_GENERIC:
  393. .. rst-class:: classref-enumeration-constant
  394. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_GENERIC** = ``0``
  395. Source texture (before compression) is a regular texture. Default for all textures.
  396. .. _class_Image_constant_COMPRESS_SOURCE_SRGB:
  397. .. rst-class:: classref-enumeration-constant
  398. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_SRGB** = ``1``
  399. Source texture (before compression) is in sRGB space.
  400. .. _class_Image_constant_COMPRESS_SOURCE_NORMAL:
  401. .. rst-class:: classref-enumeration-constant
  402. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_NORMAL** = ``2``
  403. Source texture (before compression) is a normal texture (e.g. it can be compressed into two channels).
  404. .. _class_Image_constant_COMPRESS_SOURCE_LAYERED:
  405. .. rst-class:: classref-enumeration-constant
  406. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_LAYERED** = ``3``
  407. Source texture (before compression) is a :ref:`TextureLayered<class_TextureLayered>`.
  408. .. rst-class:: classref-section-separator
  409. ----
  410. .. rst-class:: classref-descriptions-group
  411. Constants
  412. ---------
  413. .. _class_Image_constant_MAX_WIDTH:
  414. .. rst-class:: classref-constant
  415. **MAX_WIDTH** = ``16384``
  416. The maximal width allowed for **Image** resources.
  417. .. _class_Image_constant_MAX_HEIGHT:
  418. .. rst-class:: classref-constant
  419. **MAX_HEIGHT** = ``16384``
  420. The maximal height allowed for **Image** resources.
  421. .. rst-class:: classref-section-separator
  422. ----
  423. .. rst-class:: classref-descriptions-group
  424. Property Descriptions
  425. ---------------------
  426. .. _class_Image_property_data:
  427. .. rst-class:: classref-property
  428. :ref:`Dictionary<class_Dictionary>` **data** = ``{"data": PoolByteArray( ),"format": "Lum8","height": 0,"mipmaps": false,"width": 0}``
  429. Holds all the image's color data in a given format. See :ref:`Format<enum_Image_Format>` constants.
  430. .. rst-class:: classref-section-separator
  431. ----
  432. .. rst-class:: classref-descriptions-group
  433. Method Descriptions
  434. -------------------
  435. .. _class_Image_method_blend_rect:
  436. .. rst-class:: classref-method
  437. void **blend_rect** **(** :ref:`Image<class_Image>` src, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)**
  438. Alpha-blends ``src_rect`` from ``src`` image to this image at coordinates ``dest``, clipped accordingly to both image bounds. This image and ``src`` image **must** have the same format. ``src_rect`` with not positive size is treated as empty.
  439. .. rst-class:: classref-item-separator
  440. ----
  441. .. _class_Image_method_blend_rect_mask:
  442. .. rst-class:: classref-method
  443. void **blend_rect_mask** **(** :ref:`Image<class_Image>` src, :ref:`Image<class_Image>` mask, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)**
  444. Alpha-blends ``src_rect`` from ``src`` image to this image using ``mask`` image at coordinates ``dst``, clipped accordingly to both image bounds. Alpha channels are required for both ``src`` and ``mask``. ``dst`` pixels and ``src`` pixels will blend if the corresponding mask pixel's alpha value is not 0. This image and ``src`` image **must** have the same format. ``src`` image and ``mask`` image **must** have the same size (width and height) but they can have different formats. ``src_rect`` with not positive size is treated as empty.
  445. .. rst-class:: classref-item-separator
  446. ----
  447. .. _class_Image_method_blit_rect:
  448. .. rst-class:: classref-method
  449. void **blit_rect** **(** :ref:`Image<class_Image>` src, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)**
  450. Copies ``src_rect`` from ``src`` image to this image at coordinates ``dst``, clipped accordingly to both image bounds. This image and ``src`` image **must** have the same format. ``src_rect`` with not positive size is treated as empty.
  451. .. rst-class:: classref-item-separator
  452. ----
  453. .. _class_Image_method_blit_rect_mask:
  454. .. rst-class:: classref-method
  455. void **blit_rect_mask** **(** :ref:`Image<class_Image>` src, :ref:`Image<class_Image>` mask, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)**
  456. Blits ``src_rect`` area from ``src`` image to this image at the coordinates given by ``dst``, clipped accordingly to both image bounds. ``src`` pixel is copied onto ``dst`` if the corresponding ``mask`` pixel's alpha value is not 0. This image and ``src`` image **must** have the same format. ``src`` image and ``mask`` image **must** have the same size (width and height) but they can have different formats. ``src_rect`` with not positive size is treated as empty.
  457. .. rst-class:: classref-item-separator
  458. ----
  459. .. _class_Image_method_bumpmap_to_normalmap:
  460. .. rst-class:: classref-method
  461. void **bumpmap_to_normalmap** **(** :ref:`float<class_float>` bump_scale=1.0 **)**
  462. Converts a bumpmap to a normalmap. A bumpmap provides a height offset per-pixel, while a normalmap provides a normal direction per pixel.
  463. .. rst-class:: classref-item-separator
  464. ----
  465. .. _class_Image_method_clear_mipmaps:
  466. .. rst-class:: classref-method
  467. void **clear_mipmaps** **(** **)**
  468. Removes the image's mipmaps.
  469. .. rst-class:: classref-item-separator
  470. ----
  471. .. _class_Image_method_compress:
  472. .. rst-class:: classref-method
  473. :ref:`Error<enum_@GlobalScope_Error>` **compress** **(** :ref:`CompressMode<enum_Image_CompressMode>` mode, :ref:`CompressSource<enum_Image_CompressSource>` source, :ref:`float<class_float>` lossy_quality **)**
  474. Compresses the image to use less memory. Can not directly access pixel data while the image is compressed. Returns error if the chosen compression mode is not available. See :ref:`CompressMode<enum_Image_CompressMode>` and :ref:`CompressSource<enum_Image_CompressSource>` constants.
  475. .. rst-class:: classref-item-separator
  476. ----
  477. .. _class_Image_method_convert:
  478. .. rst-class:: classref-method
  479. void **convert** **(** :ref:`Format<enum_Image_Format>` format **)**
  480. Converts the image's format. See :ref:`Format<enum_Image_Format>` constants.
  481. .. rst-class:: classref-item-separator
  482. ----
  483. .. _class_Image_method_copy_from:
  484. .. rst-class:: classref-method
  485. void **copy_from** **(** :ref:`Image<class_Image>` src **)**
  486. Copies ``src`` image to this image.
  487. .. rst-class:: classref-item-separator
  488. ----
  489. .. _class_Image_method_create:
  490. .. rst-class:: classref-method
  491. void **create** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format **)**
  492. Creates an empty image of given size and format. See :ref:`Format<enum_Image_Format>` constants. If ``use_mipmaps`` is ``true`` then generate mipmaps for this image. See the :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>`.
  493. .. rst-class:: classref-item-separator
  494. ----
  495. .. _class_Image_method_create_from_data:
  496. .. rst-class:: classref-method
  497. void **create_from_data** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format, :ref:`PoolByteArray<class_PoolByteArray>` data **)**
  498. Creates a new image of given size and format. See :ref:`Format<enum_Image_Format>` constants. Fills the image with the given raw data. If ``use_mipmaps`` is ``true`` then loads mipmaps for this image from ``data``. See :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>`.
  499. .. rst-class:: classref-item-separator
  500. ----
  501. .. _class_Image_method_crop:
  502. .. rst-class:: classref-method
  503. void **crop** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height **)**
  504. Crops the image to the given ``width`` and ``height``. If the specified size is larger than the current size, the extra area is filled with black pixels.
  505. .. rst-class:: classref-item-separator
  506. ----
  507. .. _class_Image_method_decompress:
  508. .. rst-class:: classref-method
  509. :ref:`Error<enum_@GlobalScope_Error>` **decompress** **(** **)**
  510. Decompresses the image if it is compressed. Returns an error if decompress function is not available.
  511. .. rst-class:: classref-item-separator
  512. ----
  513. .. _class_Image_method_detect_alpha:
  514. .. rst-class:: classref-method
  515. :ref:`AlphaMode<enum_Image_AlphaMode>` **detect_alpha** **(** **)** |const|
  516. Returns :ref:`ALPHA_BLEND<class_Image_constant_ALPHA_BLEND>` if the image has data for alpha values. Returns :ref:`ALPHA_BIT<class_Image_constant_ALPHA_BIT>` if all the alpha values are stored in a single bit. Returns :ref:`ALPHA_NONE<class_Image_constant_ALPHA_NONE>` if no data for alpha values is found.
  517. .. rst-class:: classref-item-separator
  518. ----
  519. .. _class_Image_method_expand_x2_hq2x:
  520. .. rst-class:: classref-method
  521. void **expand_x2_hq2x** **(** **)**
  522. Stretches the image and enlarges it by a factor of 2. No interpolation is done.
  523. .. rst-class:: classref-item-separator
  524. ----
  525. .. _class_Image_method_fill:
  526. .. rst-class:: classref-method
  527. void **fill** **(** :ref:`Color<class_Color>` color **)**
  528. Fills the image with ``color``.
  529. .. rst-class:: classref-item-separator
  530. ----
  531. .. _class_Image_method_fill_rect:
  532. .. rst-class:: classref-method
  533. void **fill_rect** **(** :ref:`Rect2<class_Rect2>` rect, :ref:`Color<class_Color>` color **)**
  534. Fills ``rect`` with ``color``.
  535. .. rst-class:: classref-item-separator
  536. ----
  537. .. _class_Image_method_fix_alpha_edges:
  538. .. rst-class:: classref-method
  539. void **fix_alpha_edges** **(** **)**
  540. Blends low-alpha pixels with nearby pixels.
  541. .. rst-class:: classref-item-separator
  542. ----
  543. .. _class_Image_method_flip_x:
  544. .. rst-class:: classref-method
  545. void **flip_x** **(** **)**
  546. Flips the image horizontally.
  547. .. rst-class:: classref-item-separator
  548. ----
  549. .. _class_Image_method_flip_y:
  550. .. rst-class:: classref-method
  551. void **flip_y** **(** **)**
  552. Flips the image vertically.
  553. .. rst-class:: classref-item-separator
  554. ----
  555. .. _class_Image_method_generate_mipmaps:
  556. .. rst-class:: classref-method
  557. :ref:`Error<enum_@GlobalScope_Error>` **generate_mipmaps** **(** :ref:`bool<class_bool>` renormalize=false **)**
  558. Generates mipmaps for the image. Mipmaps are precalculated lower-resolution copies of the image that are automatically used if the image needs to be scaled down when rendered. They help improve image quality and performance when rendering. This method returns an error if the image is compressed, in a custom format, or if the image's width/height is ``0``.
  559. \ **Note:** Mipmap generation is done on the CPU, is single-threaded and is *always* done on the main thread. This means generating mipmaps will result in noticeable stuttering during gameplay, even if :ref:`generate_mipmaps<class_Image_method_generate_mipmaps>` is called from a :ref:`Thread<class_Thread>`.
  560. .. rst-class:: classref-item-separator
  561. ----
  562. .. _class_Image_method_get_data:
  563. .. rst-class:: classref-method
  564. :ref:`PoolByteArray<class_PoolByteArray>` **get_data** **(** **)** |const|
  565. Returns a copy of the image's raw data.
  566. .. rst-class:: classref-item-separator
  567. ----
  568. .. _class_Image_method_get_format:
  569. .. rst-class:: classref-method
  570. :ref:`Format<enum_Image_Format>` **get_format** **(** **)** |const|
  571. Returns the image's format. See :ref:`Format<enum_Image_Format>` constants.
  572. .. rst-class:: classref-item-separator
  573. ----
  574. .. _class_Image_method_get_height:
  575. .. rst-class:: classref-method
  576. :ref:`int<class_int>` **get_height** **(** **)** |const|
  577. Returns the image's height.
  578. .. rst-class:: classref-item-separator
  579. ----
  580. .. _class_Image_method_get_mipmap_offset:
  581. .. rst-class:: classref-method
  582. :ref:`int<class_int>` **get_mipmap_offset** **(** :ref:`int<class_int>` mipmap **)** |const|
  583. Returns the offset where the image's mipmap with index ``mipmap`` is stored in the ``data`` dictionary.
  584. .. rst-class:: classref-item-separator
  585. ----
  586. .. _class_Image_method_get_pixel:
  587. .. rst-class:: classref-method
  588. :ref:`Color<class_Color>` **get_pixel** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  589. Returns the color of the pixel at ``(x, y)`` if the image is locked. If the image is unlocked, it always returns a :ref:`Color<class_Color>` with the value ``(0, 0, 0, 1.0)``. This is the same as :ref:`get_pixelv<class_Image_method_get_pixelv>`, but two integer arguments instead of a Vector2 argument.
  590. .. rst-class:: classref-item-separator
  591. ----
  592. .. _class_Image_method_get_pixelv:
  593. .. rst-class:: classref-method
  594. :ref:`Color<class_Color>` **get_pixelv** **(** :ref:`Vector2<class_Vector2>` src **)** |const|
  595. Returns the color of the pixel at ``src`` if the image is locked. If the image is unlocked, it always returns a :ref:`Color<class_Color>` with the value ``(0, 0, 0, 1.0)``. This is the same as :ref:`get_pixel<class_Image_method_get_pixel>`, but with a Vector2 argument instead of two integer arguments.
  596. .. rst-class:: classref-item-separator
  597. ----
  598. .. _class_Image_method_get_rect:
  599. .. rst-class:: classref-method
  600. :ref:`Image<class_Image>` **get_rect** **(** :ref:`Rect2<class_Rect2>` rect **)** |const|
  601. Returns a new image that is a copy of the image's area specified with ``rect``.
  602. .. rst-class:: classref-item-separator
  603. ----
  604. .. _class_Image_method_get_size:
  605. .. rst-class:: classref-method
  606. :ref:`Vector2<class_Vector2>` **get_size** **(** **)** |const|
  607. Returns the image's size (width and height).
  608. .. rst-class:: classref-item-separator
  609. ----
  610. .. _class_Image_method_get_used_rect:
  611. .. rst-class:: classref-method
  612. :ref:`Rect2<class_Rect2>` **get_used_rect** **(** **)** |const|
  613. Returns a :ref:`Rect2<class_Rect2>` enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
  614. .. rst-class:: classref-item-separator
  615. ----
  616. .. _class_Image_method_get_width:
  617. .. rst-class:: classref-method
  618. :ref:`int<class_int>` **get_width** **(** **)** |const|
  619. Returns the image's width.
  620. .. rst-class:: classref-item-separator
  621. ----
  622. .. _class_Image_method_has_mipmaps:
  623. .. rst-class:: classref-method
  624. :ref:`bool<class_bool>` **has_mipmaps** **(** **)** |const|
  625. Returns ``true`` if the image has generated mipmaps.
  626. .. rst-class:: classref-item-separator
  627. ----
  628. .. _class_Image_method_is_compressed:
  629. .. rst-class:: classref-method
  630. :ref:`bool<class_bool>` **is_compressed** **(** **)** |const|
  631. Returns ``true`` if the image is compressed.
  632. .. rst-class:: classref-item-separator
  633. ----
  634. .. _class_Image_method_is_empty:
  635. .. rst-class:: classref-method
  636. :ref:`bool<class_bool>` **is_empty** **(** **)** |const|
  637. Returns ``true`` if the image has no data.
  638. .. rst-class:: classref-item-separator
  639. ----
  640. .. _class_Image_method_is_invisible:
  641. .. rst-class:: classref-method
  642. :ref:`bool<class_bool>` **is_invisible** **(** **)** |const|
  643. Returns ``true`` if all the image's pixels have an alpha value of 0. Returns ``false`` if any pixel has an alpha value higher than 0.
  644. .. rst-class:: classref-item-separator
  645. ----
  646. .. _class_Image_method_load:
  647. .. rst-class:: classref-method
  648. :ref:`Error<enum_@GlobalScope_Error>` **load** **(** :ref:`String<class_String>` path **)**
  649. Loads an image from file ``path``. See `Supported image formats <../tutorials/assets_pipeline/importing_images.html#supported-image-formats>`__ for a list of supported image formats and limitations.
  650. \ **Warning:** This method should only be used in the editor or in cases when you need to load external images at run-time, such as images located at the ``user://`` directory, and may not work in exported projects.
  651. See also :ref:`ImageTexture<class_ImageTexture>` description for usage examples.
  652. .. rst-class:: classref-item-separator
  653. ----
  654. .. _class_Image_method_load_bmp_from_buffer:
  655. .. rst-class:: classref-method
  656. :ref:`Error<enum_@GlobalScope_Error>` **load_bmp_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  657. Loads an image from the binary contents of a BMP file.
  658. \ **Note:** Godot's BMP module doesn't support 16-bit per pixel images. Only 1-bit, 4-bit, 8-bit, 24-bit, and 32-bit per pixel images are supported.
  659. .. rst-class:: classref-item-separator
  660. ----
  661. .. _class_Image_method_load_jpg_from_buffer:
  662. .. rst-class:: classref-method
  663. :ref:`Error<enum_@GlobalScope_Error>` **load_jpg_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  664. Loads an image from the binary contents of a JPEG file.
  665. .. rst-class:: classref-item-separator
  666. ----
  667. .. _class_Image_method_load_png_from_buffer:
  668. .. rst-class:: classref-method
  669. :ref:`Error<enum_@GlobalScope_Error>` **load_png_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  670. Loads an image from the binary contents of a PNG file.
  671. .. rst-class:: classref-item-separator
  672. ----
  673. .. _class_Image_method_load_tga_from_buffer:
  674. .. rst-class:: classref-method
  675. :ref:`Error<enum_@GlobalScope_Error>` **load_tga_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  676. Loads an image from the binary contents of a TGA file.
  677. .. rst-class:: classref-item-separator
  678. ----
  679. .. _class_Image_method_load_webp_from_buffer:
  680. .. rst-class:: classref-method
  681. :ref:`Error<enum_@GlobalScope_Error>` **load_webp_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  682. Loads an image from the binary contents of a WebP file.
  683. .. rst-class:: classref-item-separator
  684. ----
  685. .. _class_Image_method_lock:
  686. .. rst-class:: classref-method
  687. void **lock** **(** **)**
  688. Locks the data for reading and writing access. Sends an error to the console if the image is not locked when reading or writing a pixel.
  689. .. rst-class:: classref-item-separator
  690. ----
  691. .. _class_Image_method_normalmap_to_xy:
  692. .. rst-class:: classref-method
  693. void **normalmap_to_xy** **(** **)**
  694. Converts the image's data to represent coordinates on a 3D plane. This is used when the image represents a normalmap. A normalmap can add lots of detail to a 3D surface without increasing the polygon count.
  695. .. rst-class:: classref-item-separator
  696. ----
  697. .. _class_Image_method_premultiply_alpha:
  698. .. rst-class:: classref-method
  699. void **premultiply_alpha** **(** **)**
  700. Multiplies color values with alpha values. Resulting color values for a pixel are ``(color * alpha)/256``.
  701. .. rst-class:: classref-item-separator
  702. ----
  703. .. _class_Image_method_resize:
  704. .. rst-class:: classref-method
  705. void **resize** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)**
  706. Resizes the image to the given ``width`` and ``height``. New pixels are calculated using the ``interpolation`` mode defined via :ref:`Interpolation<enum_Image_Interpolation>` constants.
  707. .. rst-class:: classref-item-separator
  708. ----
  709. .. _class_Image_method_resize_to_po2:
  710. .. rst-class:: classref-method
  711. void **resize_to_po2** **(** :ref:`bool<class_bool>` square=false, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)**
  712. Resizes the image to the nearest power of 2 for the width and height. If ``square`` is ``true`` then set width and height to be the same. New pixels are calculated using the ``interpolation`` mode defined via :ref:`Interpolation<enum_Image_Interpolation>` constants.
  713. .. rst-class:: classref-item-separator
  714. ----
  715. .. _class_Image_method_rgbe_to_srgb:
  716. .. rst-class:: classref-method
  717. :ref:`Image<class_Image>` **rgbe_to_srgb** **(** **)**
  718. Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
  719. .. rst-class:: classref-item-separator
  720. ----
  721. .. _class_Image_method_save_exr:
  722. .. rst-class:: classref-method
  723. :ref:`Error<enum_@GlobalScope_Error>` **save_exr** **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` grayscale=false **)** |const|
  724. Saves the image as an EXR file to ``path``. If ``grayscale`` is ``true`` and the image has only one channel, it will be saved explicitly as monochrome rather than one red channel. This function will return :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>` if Godot was compiled without the TinyEXR module.
  725. \ **Note:** The TinyEXR module is disabled in non-editor builds, which means :ref:`save_exr<class_Image_method_save_exr>` will return :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>` when it is called from an exported project.
  726. .. rst-class:: classref-item-separator
  727. ----
  728. .. _class_Image_method_save_png:
  729. .. rst-class:: classref-method
  730. :ref:`Error<enum_@GlobalScope_Error>` **save_png** **(** :ref:`String<class_String>` path **)** |const|
  731. Saves the image as a PNG file to ``path``.
  732. .. rst-class:: classref-item-separator
  733. ----
  734. .. _class_Image_method_save_png_to_buffer:
  735. .. rst-class:: classref-method
  736. :ref:`PoolByteArray<class_PoolByteArray>` **save_png_to_buffer** **(** **)** |const|
  737. .. container:: contribute
  738. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  739. .. rst-class:: classref-item-separator
  740. ----
  741. .. _class_Image_method_set_pixel:
  742. .. rst-class:: classref-method
  743. void **set_pixel** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`Color<class_Color>` color **)**
  744. Sets the :ref:`Color<class_Color>` of the pixel at ``(x, y)`` if the image is locked. Example:
  745. ::
  746. var img = Image.new()
  747. img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
  748. img.lock()
  749. img.set_pixel(x, y, color) # Works
  750. img.unlock()
  751. img.set_pixel(x, y, color) # Does not have an effect
  752. .. rst-class:: classref-item-separator
  753. ----
  754. .. _class_Image_method_set_pixelv:
  755. .. rst-class:: classref-method
  756. void **set_pixelv** **(** :ref:`Vector2<class_Vector2>` dst, :ref:`Color<class_Color>` color **)**
  757. Sets the :ref:`Color<class_Color>` of the pixel at ``(dst.x, dst.y)`` if the image is locked. Note that the ``dst`` values must be integers. Example:
  758. ::
  759. var img = Image.new()
  760. img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
  761. img.lock()
  762. img.set_pixelv(Vector2(x, y), color) # Works
  763. img.unlock()
  764. img.set_pixelv(Vector2(x, y), color) # Does not have an effect
  765. .. rst-class:: classref-item-separator
  766. ----
  767. .. _class_Image_method_shrink_x2:
  768. .. rst-class:: classref-method
  769. void **shrink_x2** **(** **)**
  770. Shrinks the image by a factor of 2.
  771. .. rst-class:: classref-item-separator
  772. ----
  773. .. _class_Image_method_srgb_to_linear:
  774. .. rst-class:: classref-method
  775. void **srgb_to_linear** **(** **)**
  776. Converts the raw data from the sRGB colorspace to a linear scale.
  777. .. rst-class:: classref-item-separator
  778. ----
  779. .. _class_Image_method_unlock:
  780. .. rst-class:: classref-method
  781. void **unlock** **(** **)**
  782. Unlocks the data and prevents changes.
  783. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  784. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  785. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  786. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`