class_image.rst 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/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. .. _class_Image_constant_COMPRESS_BPTC:
  388. .. rst-class:: classref-enumeration-constant
  389. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_BPTC** = ``5``
  390. Use BPTC compression.
  391. .. _class_Image_constant_COMPRESS_MAX:
  392. .. rst-class:: classref-enumeration-constant
  393. :ref:`CompressMode<enum_Image_CompressMode>` **COMPRESS_MAX** = ``6``
  394. Represents the size of the :ref:`CompressMode<enum_Image_CompressMode>` enum.
  395. .. rst-class:: classref-item-separator
  396. ----
  397. .. _enum_Image_CompressSource:
  398. .. rst-class:: classref-enumeration
  399. enum **CompressSource**:
  400. .. _class_Image_constant_COMPRESS_SOURCE_GENERIC:
  401. .. rst-class:: classref-enumeration-constant
  402. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_GENERIC** = ``0``
  403. Source texture (before compression) is a regular texture. Default for all textures.
  404. .. _class_Image_constant_COMPRESS_SOURCE_SRGB:
  405. .. rst-class:: classref-enumeration-constant
  406. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_SRGB** = ``1``
  407. Source texture (before compression) is in sRGB space.
  408. .. _class_Image_constant_COMPRESS_SOURCE_NORMAL:
  409. .. rst-class:: classref-enumeration-constant
  410. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_NORMAL** = ``2``
  411. Source texture (before compression) is a normal texture (e.g. it can be compressed into two channels).
  412. .. _class_Image_constant_COMPRESS_SOURCE_LAYERED:
  413. .. rst-class:: classref-enumeration-constant
  414. :ref:`CompressSource<enum_Image_CompressSource>` **COMPRESS_SOURCE_LAYERED** = ``3``
  415. Source texture (before compression) is a :ref:`TextureLayered<class_TextureLayered>`.
  416. .. rst-class:: classref-section-separator
  417. ----
  418. .. rst-class:: classref-descriptions-group
  419. Constants
  420. ---------
  421. .. _class_Image_constant_MAX_WIDTH:
  422. .. rst-class:: classref-constant
  423. **MAX_WIDTH** = ``16384``
  424. The maximal width allowed for **Image** resources.
  425. .. _class_Image_constant_MAX_HEIGHT:
  426. .. rst-class:: classref-constant
  427. **MAX_HEIGHT** = ``16384``
  428. The maximal height allowed for **Image** resources.
  429. .. rst-class:: classref-section-separator
  430. ----
  431. .. rst-class:: classref-descriptions-group
  432. Property Descriptions
  433. ---------------------
  434. .. _class_Image_property_data:
  435. .. rst-class:: classref-property
  436. :ref:`Dictionary<class_Dictionary>` **data** = ``{"data": PoolByteArray( ),"format": "Lum8","height": 0,"mipmaps": false,"width": 0}``
  437. Holds all the image's color data in a given format. See :ref:`Format<enum_Image_Format>` constants.
  438. .. rst-class:: classref-section-separator
  439. ----
  440. .. rst-class:: classref-descriptions-group
  441. Method Descriptions
  442. -------------------
  443. .. _class_Image_method_blend_rect:
  444. .. rst-class:: classref-method
  445. void **blend_rect** **(** :ref:`Image<class_Image>` src, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)**
  446. 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.
  447. .. rst-class:: classref-item-separator
  448. ----
  449. .. _class_Image_method_blend_rect_mask:
  450. .. rst-class:: classref-method
  451. 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 **)**
  452. 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.
  453. .. rst-class:: classref-item-separator
  454. ----
  455. .. _class_Image_method_blit_rect:
  456. .. rst-class:: classref-method
  457. void **blit_rect** **(** :ref:`Image<class_Image>` src, :ref:`Rect2<class_Rect2>` src_rect, :ref:`Vector2<class_Vector2>` dst **)**
  458. 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.
  459. .. rst-class:: classref-item-separator
  460. ----
  461. .. _class_Image_method_blit_rect_mask:
  462. .. rst-class:: classref-method
  463. 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 **)**
  464. 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.
  465. .. rst-class:: classref-item-separator
  466. ----
  467. .. _class_Image_method_bumpmap_to_normalmap:
  468. .. rst-class:: classref-method
  469. void **bumpmap_to_normalmap** **(** :ref:`float<class_float>` bump_scale=1.0 **)**
  470. Converts a bumpmap to a normalmap. A bumpmap provides a height offset per-pixel, while a normalmap provides a normal direction per pixel.
  471. .. rst-class:: classref-item-separator
  472. ----
  473. .. _class_Image_method_clear_mipmaps:
  474. .. rst-class:: classref-method
  475. void **clear_mipmaps** **(** **)**
  476. Removes the image's mipmaps.
  477. .. rst-class:: classref-item-separator
  478. ----
  479. .. _class_Image_method_compress:
  480. .. rst-class:: classref-method
  481. :ref:`Error<enum_@GlobalScope_Error>` **compress** **(** :ref:`CompressMode<enum_Image_CompressMode>` mode, :ref:`CompressSource<enum_Image_CompressSource>` source, :ref:`float<class_float>` lossy_quality **)**
  482. 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.
  483. .. rst-class:: classref-item-separator
  484. ----
  485. .. _class_Image_method_convert:
  486. .. rst-class:: classref-method
  487. void **convert** **(** :ref:`Format<enum_Image_Format>` format **)**
  488. Converts the image's format. See :ref:`Format<enum_Image_Format>` constants.
  489. .. rst-class:: classref-item-separator
  490. ----
  491. .. _class_Image_method_copy_from:
  492. .. rst-class:: classref-method
  493. void **copy_from** **(** :ref:`Image<class_Image>` src **)**
  494. Copies ``src`` image to this image.
  495. .. rst-class:: classref-item-separator
  496. ----
  497. .. _class_Image_method_create:
  498. .. rst-class:: classref-method
  499. void **create** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`bool<class_bool>` use_mipmaps, :ref:`Format<enum_Image_Format>` format **)**
  500. 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>`.
  501. .. rst-class:: classref-item-separator
  502. ----
  503. .. _class_Image_method_create_from_data:
  504. .. rst-class:: classref-method
  505. 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 **)**
  506. 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>`.
  507. .. rst-class:: classref-item-separator
  508. ----
  509. .. _class_Image_method_crop:
  510. .. rst-class:: classref-method
  511. void **crop** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height **)**
  512. 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.
  513. .. rst-class:: classref-item-separator
  514. ----
  515. .. _class_Image_method_decompress:
  516. .. rst-class:: classref-method
  517. :ref:`Error<enum_@GlobalScope_Error>` **decompress** **(** **)**
  518. Decompresses the image if it is compressed. Returns an error if decompress function is not available.
  519. .. rst-class:: classref-item-separator
  520. ----
  521. .. _class_Image_method_detect_alpha:
  522. .. rst-class:: classref-method
  523. :ref:`AlphaMode<enum_Image_AlphaMode>` **detect_alpha** **(** **)** |const|
  524. 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.
  525. .. rst-class:: classref-item-separator
  526. ----
  527. .. _class_Image_method_expand_x2_hq2x:
  528. .. rst-class:: classref-method
  529. void **expand_x2_hq2x** **(** **)**
  530. Stretches the image and enlarges it by a factor of 2. No interpolation is done.
  531. .. rst-class:: classref-item-separator
  532. ----
  533. .. _class_Image_method_fill:
  534. .. rst-class:: classref-method
  535. void **fill** **(** :ref:`Color<class_Color>` color **)**
  536. Fills the image with ``color``.
  537. .. rst-class:: classref-item-separator
  538. ----
  539. .. _class_Image_method_fill_rect:
  540. .. rst-class:: classref-method
  541. void **fill_rect** **(** :ref:`Rect2<class_Rect2>` rect, :ref:`Color<class_Color>` color **)**
  542. Fills ``rect`` with ``color``.
  543. .. rst-class:: classref-item-separator
  544. ----
  545. .. _class_Image_method_fix_alpha_edges:
  546. .. rst-class:: classref-method
  547. void **fix_alpha_edges** **(** **)**
  548. Blends low-alpha pixels with nearby pixels.
  549. .. rst-class:: classref-item-separator
  550. ----
  551. .. _class_Image_method_flip_x:
  552. .. rst-class:: classref-method
  553. void **flip_x** **(** **)**
  554. Flips the image horizontally.
  555. .. rst-class:: classref-item-separator
  556. ----
  557. .. _class_Image_method_flip_y:
  558. .. rst-class:: classref-method
  559. void **flip_y** **(** **)**
  560. Flips the image vertically.
  561. .. rst-class:: classref-item-separator
  562. ----
  563. .. _class_Image_method_generate_mipmaps:
  564. .. rst-class:: classref-method
  565. :ref:`Error<enum_@GlobalScope_Error>` **generate_mipmaps** **(** :ref:`bool<class_bool>` renormalize=false **)**
  566. 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``.
  567. \ **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>`.
  568. .. rst-class:: classref-item-separator
  569. ----
  570. .. _class_Image_method_get_data:
  571. .. rst-class:: classref-method
  572. :ref:`PoolByteArray<class_PoolByteArray>` **get_data** **(** **)** |const|
  573. Returns a copy of the image's raw data.
  574. .. rst-class:: classref-item-separator
  575. ----
  576. .. _class_Image_method_get_format:
  577. .. rst-class:: classref-method
  578. :ref:`Format<enum_Image_Format>` **get_format** **(** **)** |const|
  579. Returns the image's format. See :ref:`Format<enum_Image_Format>` constants.
  580. .. rst-class:: classref-item-separator
  581. ----
  582. .. _class_Image_method_get_height:
  583. .. rst-class:: classref-method
  584. :ref:`int<class_int>` **get_height** **(** **)** |const|
  585. Returns the image's height.
  586. .. rst-class:: classref-item-separator
  587. ----
  588. .. _class_Image_method_get_mipmap_offset:
  589. .. rst-class:: classref-method
  590. :ref:`int<class_int>` **get_mipmap_offset** **(** :ref:`int<class_int>` mipmap **)** |const|
  591. Returns the offset where the image's mipmap with index ``mipmap`` is stored in the ``data`` dictionary.
  592. .. rst-class:: classref-item-separator
  593. ----
  594. .. _class_Image_method_get_pixel:
  595. .. rst-class:: classref-method
  596. :ref:`Color<class_Color>` **get_pixel** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y **)** |const|
  597. 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.
  598. .. rst-class:: classref-item-separator
  599. ----
  600. .. _class_Image_method_get_pixelv:
  601. .. rst-class:: classref-method
  602. :ref:`Color<class_Color>` **get_pixelv** **(** :ref:`Vector2<class_Vector2>` src **)** |const|
  603. 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.
  604. .. rst-class:: classref-item-separator
  605. ----
  606. .. _class_Image_method_get_rect:
  607. .. rst-class:: classref-method
  608. :ref:`Image<class_Image>` **get_rect** **(** :ref:`Rect2<class_Rect2>` rect **)** |const|
  609. Returns a new image that is a copy of the image's area specified with ``rect``.
  610. .. rst-class:: classref-item-separator
  611. ----
  612. .. _class_Image_method_get_size:
  613. .. rst-class:: classref-method
  614. :ref:`Vector2<class_Vector2>` **get_size** **(** **)** |const|
  615. Returns the image's size (width and height).
  616. .. rst-class:: classref-item-separator
  617. ----
  618. .. _class_Image_method_get_used_rect:
  619. .. rst-class:: classref-method
  620. :ref:`Rect2<class_Rect2>` **get_used_rect** **(** **)** |const|
  621. Returns a :ref:`Rect2<class_Rect2>` enclosing the visible portion of the image, considering each pixel with a non-zero alpha channel as visible.
  622. .. rst-class:: classref-item-separator
  623. ----
  624. .. _class_Image_method_get_width:
  625. .. rst-class:: classref-method
  626. :ref:`int<class_int>` **get_width** **(** **)** |const|
  627. Returns the image's width.
  628. .. rst-class:: classref-item-separator
  629. ----
  630. .. _class_Image_method_has_mipmaps:
  631. .. rst-class:: classref-method
  632. :ref:`bool<class_bool>` **has_mipmaps** **(** **)** |const|
  633. Returns ``true`` if the image has generated mipmaps.
  634. .. rst-class:: classref-item-separator
  635. ----
  636. .. _class_Image_method_is_compressed:
  637. .. rst-class:: classref-method
  638. :ref:`bool<class_bool>` **is_compressed** **(** **)** |const|
  639. Returns ``true`` if the image is compressed.
  640. .. rst-class:: classref-item-separator
  641. ----
  642. .. _class_Image_method_is_empty:
  643. .. rst-class:: classref-method
  644. :ref:`bool<class_bool>` **is_empty** **(** **)** |const|
  645. Returns ``true`` if the image has no data.
  646. .. rst-class:: classref-item-separator
  647. ----
  648. .. _class_Image_method_is_invisible:
  649. .. rst-class:: classref-method
  650. :ref:`bool<class_bool>` **is_invisible** **(** **)** |const|
  651. 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.
  652. .. rst-class:: classref-item-separator
  653. ----
  654. .. _class_Image_method_load:
  655. .. rst-class:: classref-method
  656. :ref:`Error<enum_@GlobalScope_Error>` **load** **(** :ref:`String<class_String>` path **)**
  657. 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.
  658. \ **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.
  659. See also :ref:`ImageTexture<class_ImageTexture>` description for usage examples.
  660. .. rst-class:: classref-item-separator
  661. ----
  662. .. _class_Image_method_load_bmp_from_buffer:
  663. .. rst-class:: classref-method
  664. :ref:`Error<enum_@GlobalScope_Error>` **load_bmp_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  665. Loads an image from the binary contents of a BMP file.
  666. \ **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.
  667. .. rst-class:: classref-item-separator
  668. ----
  669. .. _class_Image_method_load_jpg_from_buffer:
  670. .. rst-class:: classref-method
  671. :ref:`Error<enum_@GlobalScope_Error>` **load_jpg_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  672. Loads an image from the binary contents of a JPEG file.
  673. .. rst-class:: classref-item-separator
  674. ----
  675. .. _class_Image_method_load_png_from_buffer:
  676. .. rst-class:: classref-method
  677. :ref:`Error<enum_@GlobalScope_Error>` **load_png_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  678. Loads an image from the binary contents of a PNG file.
  679. .. rst-class:: classref-item-separator
  680. ----
  681. .. _class_Image_method_load_tga_from_buffer:
  682. .. rst-class:: classref-method
  683. :ref:`Error<enum_@GlobalScope_Error>` **load_tga_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  684. Loads an image from the binary contents of a TGA file.
  685. .. rst-class:: classref-item-separator
  686. ----
  687. .. _class_Image_method_load_webp_from_buffer:
  688. .. rst-class:: classref-method
  689. :ref:`Error<enum_@GlobalScope_Error>` **load_webp_from_buffer** **(** :ref:`PoolByteArray<class_PoolByteArray>` buffer **)**
  690. Loads an image from the binary contents of a WebP file.
  691. .. rst-class:: classref-item-separator
  692. ----
  693. .. _class_Image_method_lock:
  694. .. rst-class:: classref-method
  695. void **lock** **(** **)**
  696. 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.
  697. .. rst-class:: classref-item-separator
  698. ----
  699. .. _class_Image_method_normalmap_to_xy:
  700. .. rst-class:: classref-method
  701. void **normalmap_to_xy** **(** **)**
  702. 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.
  703. .. rst-class:: classref-item-separator
  704. ----
  705. .. _class_Image_method_premultiply_alpha:
  706. .. rst-class:: classref-method
  707. void **premultiply_alpha** **(** **)**
  708. Multiplies color values with alpha values. Resulting color values for a pixel are ``(color * alpha)/256``.
  709. .. rst-class:: classref-item-separator
  710. ----
  711. .. _class_Image_method_resize:
  712. .. rst-class:: classref-method
  713. void **resize** **(** :ref:`int<class_int>` width, :ref:`int<class_int>` height, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)**
  714. 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.
  715. .. rst-class:: classref-item-separator
  716. ----
  717. .. _class_Image_method_resize_to_po2:
  718. .. rst-class:: classref-method
  719. void **resize_to_po2** **(** :ref:`bool<class_bool>` square=false, :ref:`Interpolation<enum_Image_Interpolation>` interpolation=1 **)**
  720. 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.
  721. .. rst-class:: classref-item-separator
  722. ----
  723. .. _class_Image_method_rgbe_to_srgb:
  724. .. rst-class:: classref-method
  725. :ref:`Image<class_Image>` **rgbe_to_srgb** **(** **)**
  726. Converts a standard RGBE (Red Green Blue Exponent) image to an sRGB image.
  727. .. rst-class:: classref-item-separator
  728. ----
  729. .. _class_Image_method_save_exr:
  730. .. rst-class:: classref-method
  731. :ref:`Error<enum_@GlobalScope_Error>` **save_exr** **(** :ref:`String<class_String>` path, :ref:`bool<class_bool>` grayscale=false **)** |const|
  732. 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.
  733. \ **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.
  734. .. rst-class:: classref-item-separator
  735. ----
  736. .. _class_Image_method_save_png:
  737. .. rst-class:: classref-method
  738. :ref:`Error<enum_@GlobalScope_Error>` **save_png** **(** :ref:`String<class_String>` path **)** |const|
  739. Saves the image as a PNG file to ``path``.
  740. .. rst-class:: classref-item-separator
  741. ----
  742. .. _class_Image_method_save_png_to_buffer:
  743. .. rst-class:: classref-method
  744. :ref:`PoolByteArray<class_PoolByteArray>` **save_png_to_buffer** **(** **)** |const|
  745. .. container:: contribute
  746. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  747. .. rst-class:: classref-item-separator
  748. ----
  749. .. _class_Image_method_set_pixel:
  750. .. rst-class:: classref-method
  751. void **set_pixel** **(** :ref:`int<class_int>` x, :ref:`int<class_int>` y, :ref:`Color<class_Color>` color **)**
  752. Sets the :ref:`Color<class_Color>` of the pixel at ``(x, y)`` if the image is locked. Example:
  753. ::
  754. var img = Image.new()
  755. img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
  756. img.lock()
  757. img.set_pixel(x, y, color) # Works
  758. img.unlock()
  759. img.set_pixel(x, y, color) # Does not have an effect
  760. \ **Note:** Some image methods can leave the image unlocked, making subsequent :ref:`set_pixel<class_Image_method_set_pixel>` calls fail unless the image is locked again. Methods potentially unlocking the image: :ref:`blend_rect<class_Image_method_blend_rect>`, :ref:`blend_rect_mask<class_Image_method_blend_rect_mask>`, :ref:`blit_rect_mask<class_Image_method_blit_rect_mask>`, :ref:`convert<class_Image_method_convert>`, :ref:`fill<class_Image_method_fill>`, :ref:`fill_rect<class_Image_method_fill_rect>`, :ref:`get_used_rect<class_Image_method_get_used_rect>`, and :ref:`rgbe_to_srgb<class_Image_method_rgbe_to_srgb>`.
  761. ::
  762. img.lock()
  763. img.set_pixel(x, y, color) # Works
  764. img.fill(color) # Unlocks the image
  765. img.set_pixel(x, y, color) # Does not have an effect
  766. .. rst-class:: classref-item-separator
  767. ----
  768. .. _class_Image_method_set_pixelv:
  769. .. rst-class:: classref-method
  770. void **set_pixelv** **(** :ref:`Vector2<class_Vector2>` dst, :ref:`Color<class_Color>` color **)**
  771. 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:
  772. ::
  773. var img = Image.new()
  774. img.create(img_width, img_height, false, Image.FORMAT_RGBA8)
  775. img.lock()
  776. img.set_pixelv(Vector2(x, y), color) # Works
  777. img.unlock()
  778. img.set_pixelv(Vector2(x, y), color) # Does not have an effect
  779. \ **Note:** Some image methods can leave the image unlocked, making subsequent :ref:`set_pixelv<class_Image_method_set_pixelv>` calls fail unless the image is locked again. Methods potentially unlocking the image: :ref:`blend_rect<class_Image_method_blend_rect>`, :ref:`blend_rect_mask<class_Image_method_blend_rect_mask>`, :ref:`blit_rect_mask<class_Image_method_blit_rect_mask>`, :ref:`convert<class_Image_method_convert>`, :ref:`fill<class_Image_method_fill>`, :ref:`fill_rect<class_Image_method_fill_rect>`, :ref:`get_used_rect<class_Image_method_get_used_rect>`, and :ref:`rgbe_to_srgb<class_Image_method_rgbe_to_srgb>`.
  780. ::
  781. img.lock()
  782. img.set_pixelv(Vector2(x, y), color) # Works
  783. img.fill(dcolor) # Unlocks the image
  784. img.set_pixelv(Vector2(x, y), color) # Does not have an effect
  785. .. rst-class:: classref-item-separator
  786. ----
  787. .. _class_Image_method_shrink_x2:
  788. .. rst-class:: classref-method
  789. void **shrink_x2** **(** **)**
  790. Shrinks the image by a factor of 2.
  791. .. rst-class:: classref-item-separator
  792. ----
  793. .. _class_Image_method_srgb_to_linear:
  794. .. rst-class:: classref-method
  795. void **srgb_to_linear** **(** **)**
  796. Converts the raw data from the sRGB colorspace to a linear scale.
  797. .. rst-class:: classref-item-separator
  798. ----
  799. .. _class_Image_method_unlock:
  800. .. rst-class:: classref-method
  801. void **unlock** **(** **)**
  802. Unlocks the data and prevents changes.
  803. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  804. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  805. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  806. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`