1 /** 2 Image datatype. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.image; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.resource; 24 import godot.reference; 25 /** 26 Image datatype. 27 28 Native image datatype. Contains image data, which can be converted to a $(D Texture), and several functions to interact with it. The maximum width and height for an `Image` is 16384 pixels. 29 */ 30 @GodotBaseClass struct Image 31 { 32 enum string _GODOT_internal_name = "Image"; 33 public: 34 @nogc nothrow: 35 union { godot_object _godot_object; Resource _GODOT_base; } 36 alias _GODOT_base this; 37 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 38 package(godot) __gshared bool _classBindingInitialized = false; 39 package(godot) static struct _classBinding 40 { 41 __gshared: 42 @GodotName("get_width") GodotMethod!(long) getWidth; 43 @GodotName("get_height") GodotMethod!(long) getHeight; 44 @GodotName("get_size") GodotMethod!(Vector2) getSize; 45 @GodotName("has_mipmaps") GodotMethod!(bool) hasMipmaps; 46 @GodotName("get_format") GodotMethod!(Image.Format) getFormat; 47 @GodotName("get_data") GodotMethod!(PoolByteArray) getData; 48 @GodotName("convert") GodotMethod!(void, long) convert; 49 @GodotName("get_mipmap_offset") GodotMethod!(long, long) getMipmapOffset; 50 @GodotName("resize_to_po2") GodotMethod!(void, bool) resizeToPo2; 51 @GodotName("resize") GodotMethod!(void, long, long, long) resize; 52 @GodotName("shrink_x2") GodotMethod!(void) shrinkX2; 53 @GodotName("expand_x2_hq2x") GodotMethod!(void) expandX2Hq2x; 54 @GodotName("crop") GodotMethod!(void, long, long) crop; 55 @GodotName("flip_x") GodotMethod!(void) flipX; 56 @GodotName("flip_y") GodotMethod!(void) flipY; 57 @GodotName("generate_mipmaps") GodotMethod!(GodotError, bool) generateMipmaps; 58 @GodotName("clear_mipmaps") GodotMethod!(void) clearMipmaps; 59 @GodotName("create") GodotMethod!(void, long, long, bool, long) create; 60 @GodotName("create_from_data") GodotMethod!(void, long, long, bool, long, PoolByteArray) createFromData; 61 @GodotName("is_empty") GodotMethod!(bool) isEmpty; 62 @GodotName("load") GodotMethod!(GodotError, String) load; 63 @GodotName("save_png") GodotMethod!(GodotError, String) savePng; 64 @GodotName("detect_alpha") GodotMethod!(Image.AlphaMode) detectAlpha; 65 @GodotName("is_invisible") GodotMethod!(bool) isInvisible; 66 @GodotName("compress") GodotMethod!(GodotError, long, long, double) compress; 67 @GodotName("decompress") GodotMethod!(GodotError) decompress; 68 @GodotName("is_compressed") GodotMethod!(bool) isCompressed; 69 @GodotName("fix_alpha_edges") GodotMethod!(void) fixAlphaEdges; 70 @GodotName("premultiply_alpha") GodotMethod!(void) premultiplyAlpha; 71 @GodotName("srgb_to_linear") GodotMethod!(void) srgbToLinear; 72 @GodotName("normalmap_to_xy") GodotMethod!(void) normalmapToXy; 73 @GodotName("rgbe_to_srgb") GodotMethod!(Image) rgbeToSrgb; 74 @GodotName("bumpmap_to_normalmap") GodotMethod!(void, double) bumpmapToNormalmap; 75 @GodotName("blit_rect") GodotMethod!(void, Image, Rect2, Vector2) blitRect; 76 @GodotName("blit_rect_mask") GodotMethod!(void, Image, Image, Rect2, Vector2) blitRectMask; 77 @GodotName("blend_rect") GodotMethod!(void, Image, Rect2, Vector2) blendRect; 78 @GodotName("blend_rect_mask") GodotMethod!(void, Image, Image, Rect2, Vector2) blendRectMask; 79 @GodotName("fill") GodotMethod!(void, Color) fill; 80 @GodotName("get_used_rect") GodotMethod!(Rect2) getUsedRect; 81 @GodotName("get_rect") GodotMethod!(Image, Rect2) getRect; 82 @GodotName("copy_from") GodotMethod!(void, Image) copyFrom; 83 @GodotName("_set_data") GodotMethod!(void, Dictionary) _setData; 84 @GodotName("_get_data") GodotMethod!(Dictionary) _getData; 85 @GodotName("lock") GodotMethod!(void) lock; 86 @GodotName("unlock") GodotMethod!(void) unlock; 87 @GodotName("get_pixelv") GodotMethod!(Color, Vector2) getPixelv; 88 @GodotName("get_pixel") GodotMethod!(Color, long, long) getPixel; 89 @GodotName("set_pixelv") GodotMethod!(void, Vector2, Color) setPixelv; 90 @GodotName("set_pixel") GodotMethod!(void, long, long, Color) setPixel; 91 @GodotName("load_png_from_buffer") GodotMethod!(GodotError, PoolByteArray) loadPngFromBuffer; 92 @GodotName("load_jpg_from_buffer") GodotMethod!(GodotError, PoolByteArray) loadJpgFromBuffer; 93 @GodotName("load_webp_from_buffer") GodotMethod!(GodotError, PoolByteArray) loadWebpFromBuffer; 94 } 95 bool opEquals(in Image other) const { return _godot_object.ptr is other._godot_object.ptr; } 96 Image opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 97 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 98 mixin baseCasts; 99 static Image _new() 100 { 101 static godot_class_constructor constructor; 102 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("Image"); 103 if(constructor is null) return typeof(this).init; 104 return cast(Image)(constructor()); 105 } 106 @disable new(size_t s); 107 /// 108 enum AlphaMode : int 109 { 110 /** 111 112 */ 113 alphaNone = 0, 114 /** 115 116 */ 117 alphaBit = 1, 118 /** 119 120 */ 121 alphaBlend = 2, 122 } 123 /// 124 enum CompressSource : int 125 { 126 /** 127 128 */ 129 compressSourceGeneric = 0, 130 /** 131 132 */ 133 compressSourceSrgb = 1, 134 /** 135 136 */ 137 compressSourceNormal = 2, 138 } 139 /// 140 enum Interpolation : int 141 { 142 /** 143 144 */ 145 interpolateNearest = 0, 146 /** 147 148 */ 149 interpolateBilinear = 1, 150 /** 151 152 */ 153 interpolateCubic = 2, 154 /** 155 Performs bilinear separately on the two most suited mipmap levels, then linearly interpolates between them. 156 It's slower than `INTERPOLATE_BILINEAR`, but produces higher quality results, with much less aliasing artifacts. 157 If the image does not have mipmaps, they will be generated and used internally, but no mipmaps will be generated on the resulting image. (Note that if you intend to scale multiple copies of the original image, it's better to call `generate_mipmaps` on it in advance, to avoid wasting processing power in generating them again and again.) 158 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. 159 */ 160 interpolateTrilinear = 3, 161 } 162 /// 163 enum CompressMode : int 164 { 165 /** 166 167 */ 168 compressS3tc = 0, 169 /** 170 171 */ 172 compressPvrtc2 = 1, 173 /** 174 175 */ 176 compressPvrtc4 = 2, 177 /** 178 179 */ 180 compressEtc = 3, 181 /** 182 183 */ 184 compressEtc2 = 4, 185 } 186 /// 187 enum Format : int 188 { 189 /** 190 191 */ 192 formatL8 = 0, 193 /** 194 195 */ 196 formatLa8 = 1, 197 /** 198 OpenGL texture format RED with a single component and a bitdepth of 8. 199 */ 200 formatR8 = 2, 201 /** 202 OpenGL texture format RG with two components and a bitdepth of 8 for each. 203 */ 204 formatRg8 = 3, 205 /** 206 OpenGL texture format RGB with three components, each with a bitdepth of 8. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 207 */ 208 formatRgb8 = 4, 209 /** 210 OpenGL texture format RGBA with four components, each with a bitdepth of 8. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 211 */ 212 formatRgba8 = 5, 213 /** 214 OpenGL texture format RGBA with four components, each with a bitdepth of 4. 215 */ 216 formatRgba4444 = 6, 217 /** 218 OpenGL texture format GL_RGB5_A1 where 5 bits of depth for each component of RGB and one bit for alpha. 219 */ 220 formatRgba5551 = 7, 221 /** 222 OpenGL texture format GL_R32F where there's one component, a 32-bit floating-point value. 223 */ 224 formatRf = 8, 225 /** 226 OpenGL texture format GL_RG32F where there are two components, each a 32-bit floating-point values. 227 */ 228 formatRgf = 9, 229 /** 230 OpenGL texture format GL_RGB32F where there are three components, each a 32-bit floating-point values. 231 */ 232 formatRgbf = 10, 233 /** 234 OpenGL texture format GL_RGBA32F where there are four components, each a 32-bit floating-point values. 235 */ 236 formatRgbaf = 11, 237 /** 238 OpenGL texture format GL_R32F where there's one component, a 16-bit "half-precision" floating-point value. 239 */ 240 formatRh = 12, 241 /** 242 OpenGL texture format GL_RG32F where there's two components, each a 16-bit "half-precision" floating-point value. 243 */ 244 formatRgh = 13, 245 /** 246 OpenGL texture format GL_RGB32F where there's three components, each a 16-bit "half-precision" floating-point value. 247 */ 248 formatRgbh = 14, 249 /** 250 OpenGL texture format GL_RGBA32F where there's four components, each a 16-bit "half-precision" floating-point value. 251 */ 252 formatRgbah = 15, 253 /** 254 A special OpenGL texture format where the three color components have 9 bits of precision and all three share a single exponent. 255 */ 256 formatRgbe9995 = 16, 257 /** 258 The S3TC 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. More information can be found at https://www.khronos.org/opengl/wiki/S3_Texture_Compression. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 259 */ 260 formatDxt1 = 17, 261 /** 262 The S3TC 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. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 263 */ 264 formatDxt3 = 18, 265 /** 266 The S3TC 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 transparency gradients than DXT3. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 267 */ 268 formatDxt5 = 19, 269 /** 270 Texture format that uses Red Green Texture Compression, normalizing the red channel data using the same compression algorithm that DXT5 uses for the alpha channel. More information can be found here https://www.khronos.org/opengl/wiki/Red_Green_Texture_Compression. 271 */ 272 formatRgtcR = 20, 273 /** 274 Texture format that uses Red Green Texture Compression, normalizing the red and green channel data using the same compression algorithm that DXT5 uses for the alpha channel. 275 */ 276 formatRgtcRg = 21, 277 /** 278 Texture format that uses BPTC compression with unsigned normalized RGBA components. More information can be found at https://www.khronos.org/opengl/wiki/BPTC_Texture_Compression. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 279 */ 280 formatBptcRgba = 22, 281 /** 282 Texture format that uses BPTC compression with signed floating-point RGB components. 283 */ 284 formatBptcRgbf = 23, 285 /** 286 Texture format that uses BPTC compression with unsigned floating-point RGB components. 287 */ 288 formatBptcRgbfu = 24, 289 /** 290 Texture format used on PowerVR-supported mobile platforms, uses 2 bit color depth with no alpha. More information on PVRTC can be found here https://en.wikipedia.org/wiki/PVRTC. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 291 */ 292 formatPvrtc2 = 25, 293 /** 294 Same as PVRTC2, but with an alpha component. 295 */ 296 formatPvrtc2a = 26, 297 /** 298 Similar to PVRTC2, but with 4 bit color depth and no alpha. 299 */ 300 formatPvrtc4 = 27, 301 /** 302 Same as PVRTC4, but with an alpha component. 303 */ 304 formatPvrtc4a = 28, 305 /** 306 Ericsson Texture Compression format, also referred to as 'ETC1', and is part of the OpenGL ES graphics standard. An overview of the format is given at https://en.wikipedia.org/wiki/Ericsson_Texture_Compression#ETC1. 307 */ 308 formatEtc = 29, 309 /** 310 Ericsson Texture Compression format 2 variant R11_EAC, which provides one channel of unsigned data. 311 */ 312 formatEtc2R11 = 30, 313 /** 314 Ericsson Texture Compression format 2 variant SIGNED_R11_EAC, which provides one channel of signed data. 315 */ 316 formatEtc2R11s = 31, 317 /** 318 Ericsson Texture Compression format 2 variant RG11_EAC, which provides two channels of unsigned data. 319 */ 320 formatEtc2Rg11 = 32, 321 /** 322 Ericsson Texture Compression format 2 variant SIGNED_RG11_EAC, which provides two channels of signed data. 323 */ 324 formatEtc2Rg11s = 33, 325 /** 326 Ericsson Texture Compression format 2 variant RGB8, which is a followup of ETC1 and compresses RGB888 data. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 327 */ 328 formatEtc2Rgb8 = 34, 329 /** 330 Ericsson Texture Compression format 2 variant RGBA8, which compresses RGBA8888 data with full alpha support. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 331 */ 332 formatEtc2Rgba8 = 35, 333 /** 334 Ericsson Texture Compression format 2 variant RGB8_PUNCHTHROUGH_ALPHA1, which compresses RGBA data to make alpha either fully transparent or fully opaque. Note that when creating an $(D ImageTexture), an sRGB to linear color space conversion is performed. 335 */ 336 formatEtc2Rgb8a1 = 36, 337 /** 338 339 */ 340 formatMax = 37, 341 } 342 /// 343 enum Constants : int 344 { 345 interpolateNearest = 0, 346 formatL8 = 0, 347 alphaNone = 0, 348 compressS3tc = 0, 349 compressSourceGeneric = 0, 350 compressSourceSrgb = 1, 351 alphaBit = 1, 352 interpolateBilinear = 1, 353 formatLa8 = 1, 354 compressPvrtc2 = 1, 355 compressSourceNormal = 2, 356 interpolateCubic = 2, 357 formatR8 = 2, 358 compressPvrtc4 = 2, 359 alphaBlend = 2, 360 compressEtc = 3, 361 formatRg8 = 3, 362 interpolateTrilinear = 3, 363 formatRgb8 = 4, 364 compressEtc2 = 4, 365 formatRgba8 = 5, 366 formatRgba4444 = 6, 367 formatRgba5551 = 7, 368 formatRf = 8, 369 formatRgf = 9, 370 formatRgbf = 10, 371 formatRgbaf = 11, 372 formatRh = 12, 373 formatRgh = 13, 374 formatRgbh = 14, 375 formatRgbah = 15, 376 formatRgbe9995 = 16, 377 formatDxt1 = 17, 378 formatDxt3 = 18, 379 formatDxt5 = 19, 380 formatRgtcR = 20, 381 formatRgtcRg = 21, 382 formatBptcRgba = 22, 383 formatBptcRgbf = 23, 384 formatBptcRgbfu = 24, 385 formatPvrtc2 = 25, 386 formatPvrtc2a = 26, 387 formatPvrtc4 = 27, 388 formatPvrtc4a = 28, 389 formatEtc = 29, 390 formatEtc2R11 = 30, 391 formatEtc2R11s = 31, 392 formatEtc2Rg11 = 32, 393 formatEtc2Rg11s = 33, 394 formatEtc2Rgb8 = 34, 395 formatEtc2Rgba8 = 35, 396 formatEtc2Rgb8a1 = 36, 397 formatMax = 37, 398 } 399 /** 400 Returns the image's width. 401 */ 402 long getWidth() const 403 { 404 checkClassBinding!(typeof(this))(); 405 return ptrcall!(long)(_classBinding.getWidth, _godot_object); 406 } 407 /** 408 Returns the image's height. 409 */ 410 long getHeight() const 411 { 412 checkClassBinding!(typeof(this))(); 413 return ptrcall!(long)(_classBinding.getHeight, _godot_object); 414 } 415 /** 416 Returns the image's size (width and height). 417 */ 418 Vector2 getSize() const 419 { 420 checkClassBinding!(typeof(this))(); 421 return ptrcall!(Vector2)(_classBinding.getSize, _godot_object); 422 } 423 /** 424 Returns `true` if the image has generated mipmaps. 425 */ 426 bool hasMipmaps() const 427 { 428 checkClassBinding!(typeof(this))(); 429 return ptrcall!(bool)(_classBinding.hasMipmaps, _godot_object); 430 } 431 /** 432 Returns the image’s format. See `FORMAT_*` constants. 433 */ 434 Image.Format getFormat() const 435 { 436 checkClassBinding!(typeof(this))(); 437 return ptrcall!(Image.Format)(_classBinding.getFormat, _godot_object); 438 } 439 /** 440 Returns the image's raw data. 441 */ 442 PoolByteArray getData() const 443 { 444 checkClassBinding!(typeof(this))(); 445 return ptrcall!(PoolByteArray)(_classBinding.getData, _godot_object); 446 } 447 /** 448 Converts the image's format. See `FORMAT_*` constants. 449 */ 450 void convert(in long format) 451 { 452 checkClassBinding!(typeof(this))(); 453 ptrcall!(void)(_classBinding.convert, _godot_object, format); 454 } 455 /** 456 Returns the offset where the image's mipmap with index `mipmap` is stored in the `data` dictionary. 457 */ 458 long getMipmapOffset(in long mipmap) const 459 { 460 checkClassBinding!(typeof(this))(); 461 return ptrcall!(long)(_classBinding.getMipmapOffset, _godot_object, mipmap); 462 } 463 /** 464 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. 465 */ 466 void resizeToPo2(in bool square = false) 467 { 468 checkClassBinding!(typeof(this))(); 469 ptrcall!(void)(_classBinding.resizeToPo2, _godot_object, square); 470 } 471 /** 472 Resizes the image to the given `width` and `height`. New pixels are calculated using `interpolation`. See `interpolation` constants. 473 */ 474 void resize(in long width, in long height, in long interpolation = 1) 475 { 476 checkClassBinding!(typeof(this))(); 477 ptrcall!(void)(_classBinding.resize, _godot_object, width, height, interpolation); 478 } 479 /** 480 Shrinks the image by a factor of 2. 481 */ 482 void shrinkX2() 483 { 484 checkClassBinding!(typeof(this))(); 485 ptrcall!(void)(_classBinding.shrinkX2, _godot_object); 486 } 487 /** 488 Stretches the image and enlarges it by a factor of 2. No interpolation is done. 489 */ 490 void expandX2Hq2x() 491 { 492 checkClassBinding!(typeof(this))(); 493 ptrcall!(void)(_classBinding.expandX2Hq2x, _godot_object); 494 } 495 /** 496 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. 497 */ 498 void crop(in long width, in long height) 499 { 500 checkClassBinding!(typeof(this))(); 501 ptrcall!(void)(_classBinding.crop, _godot_object, width, height); 502 } 503 /** 504 Flips the image horizontally. 505 */ 506 void flipX() 507 { 508 checkClassBinding!(typeof(this))(); 509 ptrcall!(void)(_classBinding.flipX, _godot_object); 510 } 511 /** 512 Flips the image vertically. 513 */ 514 void flipY() 515 { 516 checkClassBinding!(typeof(this))(); 517 ptrcall!(void)(_classBinding.flipY, _godot_object); 518 } 519 /** 520 Generates mipmaps for the image. Mipmaps are pre-calculated and lower resolution copies of the image. Mipmaps are automatically used if the image needs to be scaled down when rendered. This improves image quality and the performance of the rendering. Returns an error if the image is compressed, in a custom format or if the image's width/height is 0. 521 */ 522 GodotError generateMipmaps(in bool renormalize = false) 523 { 524 checkClassBinding!(typeof(this))(); 525 return ptrcall!(GodotError)(_classBinding.generateMipmaps, _godot_object, renormalize); 526 } 527 /** 528 Removes the image's mipmaps. 529 */ 530 void clearMipmaps() 531 { 532 checkClassBinding!(typeof(this))(); 533 ptrcall!(void)(_classBinding.clearMipmaps, _godot_object); 534 } 535 /** 536 Creates an empty image of given size and format. See `FORMAT_*` constants. If `use_mipmaps` is true then generate mipmaps for this image. See the `generate_mipmaps` method. 537 */ 538 void create(in long width, in long height, in bool use_mipmaps, in long format) 539 { 540 checkClassBinding!(typeof(this))(); 541 ptrcall!(void)(_classBinding.create, _godot_object, width, height, use_mipmaps, format); 542 } 543 /** 544 Creates a new image of given size and format. See `FORMAT_*` constants. Fills the image with the given raw data. If `use_mipmaps` is true then generate mipmaps for this image. See the `generate_mipmaps` method. 545 */ 546 void createFromData(in long width, in long height, in bool use_mipmaps, in long format, in PoolByteArray data) 547 { 548 checkClassBinding!(typeof(this))(); 549 ptrcall!(void)(_classBinding.createFromData, _godot_object, width, height, use_mipmaps, format, data); 550 } 551 /** 552 Returns `true` if the image has no data. 553 */ 554 bool isEmpty() const 555 { 556 checkClassBinding!(typeof(this))(); 557 return ptrcall!(bool)(_classBinding.isEmpty, _godot_object); 558 } 559 /** 560 Loads an image from file `path`. 561 */ 562 GodotError load(StringArg0)(in StringArg0 path) 563 { 564 checkClassBinding!(typeof(this))(); 565 return ptrcall!(GodotError)(_classBinding.load, _godot_object, path); 566 } 567 /** 568 Saves the image as a PNG file to `path`. 569 */ 570 GodotError savePng(StringArg0)(in StringArg0 path) const 571 { 572 checkClassBinding!(typeof(this))(); 573 return ptrcall!(GodotError)(_classBinding.savePng, _godot_object, path); 574 } 575 /** 576 Returns ALPHA_BLEND if the image has data for alpha values. Returns ALPHA_BIT if all the alpha values are below a certain threshold or the maximum value. Returns ALPHA_NONE if no data for alpha values is found. 577 */ 578 Image.AlphaMode detectAlpha() const 579 { 580 checkClassBinding!(typeof(this))(); 581 return ptrcall!(Image.AlphaMode)(_classBinding.detectAlpha, _godot_object); 582 } 583 /** 584 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. 585 */ 586 bool isInvisible() const 587 { 588 checkClassBinding!(typeof(this))(); 589 return ptrcall!(bool)(_classBinding.isInvisible, _godot_object); 590 } 591 /** 592 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 `COMPRESS_*` constants. 593 */ 594 GodotError compress(in long mode, in long source, in double lossy_quality) 595 { 596 checkClassBinding!(typeof(this))(); 597 return ptrcall!(GodotError)(_classBinding.compress, _godot_object, mode, source, lossy_quality); 598 } 599 /** 600 Decompresses the image if it is compressed. Returns an error if decompress function is not available. 601 */ 602 GodotError decompress() 603 { 604 checkClassBinding!(typeof(this))(); 605 return ptrcall!(GodotError)(_classBinding.decompress, _godot_object); 606 } 607 /** 608 Returns `true` if the image is compressed. 609 */ 610 bool isCompressed() const 611 { 612 checkClassBinding!(typeof(this))(); 613 return ptrcall!(bool)(_classBinding.isCompressed, _godot_object); 614 } 615 /** 616 Blends low-alpha pixels with nearby pixels. 617 */ 618 void fixAlphaEdges() 619 { 620 checkClassBinding!(typeof(this))(); 621 ptrcall!(void)(_classBinding.fixAlphaEdges, _godot_object); 622 } 623 /** 624 Multiplies color values with alpha values. Resulting color values for a pixel are `(color * alpha)/256`. 625 */ 626 void premultiplyAlpha() 627 { 628 checkClassBinding!(typeof(this))(); 629 ptrcall!(void)(_classBinding.premultiplyAlpha, _godot_object); 630 } 631 /** 632 Converts the raw data from the sRGB colorspace to a linear scale. 633 */ 634 void srgbToLinear() 635 { 636 checkClassBinding!(typeof(this))(); 637 ptrcall!(void)(_classBinding.srgbToLinear, _godot_object); 638 } 639 /** 640 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. 641 */ 642 void normalmapToXy() 643 { 644 checkClassBinding!(typeof(this))(); 645 ptrcall!(void)(_classBinding.normalmapToXy, _godot_object); 646 } 647 /** 648 649 */ 650 Ref!Image rgbeToSrgb() 651 { 652 checkClassBinding!(typeof(this))(); 653 return ptrcall!(Image)(_classBinding.rgbeToSrgb, _godot_object); 654 } 655 /** 656 657 */ 658 void bumpmapToNormalmap(in double bump_scale = 1) 659 { 660 checkClassBinding!(typeof(this))(); 661 ptrcall!(void)(_classBinding.bumpmapToNormalmap, _godot_object, bump_scale); 662 } 663 /** 664 Copies `src_rect` from `src` image to this image at coordinates `dst`. 665 */ 666 void blitRect(Image src, in Rect2 src_rect, in Vector2 dst) 667 { 668 checkClassBinding!(typeof(this))(); 669 ptrcall!(void)(_classBinding.blitRect, _godot_object, src, src_rect, dst); 670 } 671 /** 672 Blits `src_rect` area from `src` image to this image at the coordinates given by `dst`. `src` pixel is copied onto `dst` if the corresponding `mask` pixel's alpha value is not 0. `src` image and `mask` image $(B must) have the same size (width and height) but they can have different formats. 673 */ 674 void blitRectMask(Image src, Image mask, in Rect2 src_rect, in Vector2 dst) 675 { 676 checkClassBinding!(typeof(this))(); 677 ptrcall!(void)(_classBinding.blitRectMask, _godot_object, src, mask, src_rect, dst); 678 } 679 /** 680 Alpha-blends `src_rect` from `src` image to this image at coordinates `dest`. 681 */ 682 void blendRect(Image src, in Rect2 src_rect, in Vector2 dst) 683 { 684 checkClassBinding!(typeof(this))(); 685 ptrcall!(void)(_classBinding.blendRect, _godot_object, src, src_rect, dst); 686 } 687 /** 688 Alpha-blends `src_rect` from `src` image to this image using `mask` image at coordinates `dst`. 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. `src` image and `mask` image $(B must) have the same size (width and height) but they can have different formats. 689 */ 690 void blendRectMask(Image src, Image mask, in Rect2 src_rect, in Vector2 dst) 691 { 692 checkClassBinding!(typeof(this))(); 693 ptrcall!(void)(_classBinding.blendRectMask, _godot_object, src, mask, src_rect, dst); 694 } 695 /** 696 Fills the image with a given $(D Color). 697 */ 698 void fill(in Color color) 699 { 700 checkClassBinding!(typeof(this))(); 701 ptrcall!(void)(_classBinding.fill, _godot_object, color); 702 } 703 /** 704 Returns a $(D Rect2) enclosing the visible portion of the image. 705 */ 706 Rect2 getUsedRect() const 707 { 708 checkClassBinding!(typeof(this))(); 709 return ptrcall!(Rect2)(_classBinding.getUsedRect, _godot_object); 710 } 711 /** 712 Returns a new image that is a copy of the image's area specified with `rect`. 713 */ 714 Ref!Image getRect(in Rect2 rect) const 715 { 716 checkClassBinding!(typeof(this))(); 717 return ptrcall!(Image)(_classBinding.getRect, _godot_object, rect); 718 } 719 /** 720 Copies `src` image to this image. 721 */ 722 void copyFrom(Image src) 723 { 724 checkClassBinding!(typeof(this))(); 725 ptrcall!(void)(_classBinding.copyFrom, _godot_object, src); 726 } 727 /** 728 729 */ 730 void _setData(in Dictionary data) 731 { 732 Array _GODOT_args = Array.empty_array; 733 _GODOT_args.append(data); 734 String _GODOT_method_name = String("_set_data"); 735 this.callv(_GODOT_method_name, _GODOT_args); 736 } 737 /** 738 739 */ 740 Dictionary _getData() const 741 { 742 Array _GODOT_args = Array.empty_array; 743 String _GODOT_method_name = String("_get_data"); 744 return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!Dictionary); 745 } 746 /** 747 Locks the data for writing access. 748 */ 749 void lock() 750 { 751 checkClassBinding!(typeof(this))(); 752 ptrcall!(void)(_classBinding.lock, _godot_object); 753 } 754 /** 755 Unlocks the data and prevents changes. 756 */ 757 void unlock() 758 { 759 checkClassBinding!(typeof(this))(); 760 ptrcall!(void)(_classBinding.unlock, _godot_object); 761 } 762 /** 763 764 */ 765 Color getPixelv(in Vector2 src) const 766 { 767 checkClassBinding!(typeof(this))(); 768 return ptrcall!(Color)(_classBinding.getPixelv, _godot_object, src); 769 } 770 /** 771 Returns the color of the pixel at `(x, y)` if the image is locked. If the image is unlocked it always returns a $(D Color) with the value `(0, 0, 0, 1.0)`. 772 */ 773 Color getPixel(in long x, in long y) const 774 { 775 checkClassBinding!(typeof(this))(); 776 return ptrcall!(Color)(_classBinding.getPixel, _godot_object, x, y); 777 } 778 /** 779 780 */ 781 void setPixelv(in Vector2 dst, in Color color) 782 { 783 checkClassBinding!(typeof(this))(); 784 ptrcall!(void)(_classBinding.setPixelv, _godot_object, dst, color); 785 } 786 /** 787 Sets the $(D Color) of the pixel at `(x, y)` if the image is locked. Example: 788 789 790 var img = Image.new() 791 img.create(img_width, img_height, false, Image.FORMAT_RGBA8) 792 img.lock() 793 img.set_pixel(x, y, color) # Works 794 img.unlock() 795 img.set_pixel(x, y, color) # Does not have an effect 796 797 798 */ 799 void setPixel(in long x, in long y, in Color color) 800 { 801 checkClassBinding!(typeof(this))(); 802 ptrcall!(void)(_classBinding.setPixel, _godot_object, x, y, color); 803 } 804 /** 805 Loads an image from the binary contents of a PNG file. 806 */ 807 GodotError loadPngFromBuffer(in PoolByteArray buffer) 808 { 809 checkClassBinding!(typeof(this))(); 810 return ptrcall!(GodotError)(_classBinding.loadPngFromBuffer, _godot_object, buffer); 811 } 812 /** 813 Loads an image from the binary contents of a JPEG file. 814 */ 815 GodotError loadJpgFromBuffer(in PoolByteArray buffer) 816 { 817 checkClassBinding!(typeof(this))(); 818 return ptrcall!(GodotError)(_classBinding.loadJpgFromBuffer, _godot_object, buffer); 819 } 820 /** 821 Loads an image from the binary contents of a WebP file. 822 */ 823 GodotError loadWebpFromBuffer(in PoolByteArray buffer) 824 { 825 checkClassBinding!(typeof(this))(); 826 return ptrcall!(GodotError)(_classBinding.loadWebpFromBuffer, _godot_object, buffer); 827 } 828 /** 829 Holds all of the image's color data in a given format. See `FORMAT_*` constants. 830 */ 831 @property Dictionary data() 832 { 833 return _getData(); 834 } 835 /// ditto 836 @property void data(Dictionary v) 837 { 838 _setData(v); 839 } 840 }