2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* image.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef IMAGE_H
|
|
|
|
#define IMAGE_H
|
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/io/resource.h"
|
|
|
|
#include "core/math/color.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/math/rect2.h"
|
2017-05-17 12:36:47 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
|
|
|
* Image storage class. This is used to store an image in user memory, as well as
|
|
|
|
* providing some basic methods for image manipulation.
|
|
|
|
* Images can be loaded from a file, or registered into the Render object as textures.
|
2021-10-28 15:43:36 +02:00
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-11-13 04:53:12 +01:00
|
|
|
class Image;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
typedef Error (*SavePNGFunc)(const String &p_path, const Ref<Image> &p_img);
|
2020-02-17 22:06:54 +01:00
|
|
|
typedef Vector<uint8_t> (*SavePNGBufferFunc)(const Ref<Image> &p_img);
|
Implement Running Godot as Movie Writer
* Allows running the game in "movie writer" mode.
* It ensures entirely stable framerate, so your run can be saved stable and with proper sound (which is impossible if your CPU/GPU can't sustain doing this in real-time).
* If disabling vsync, it can save movies faster than the game is run, but if you want to control the interaction it can get difficult.
* Implements a simple, default MJPEG writer.
This new features has two main use cases, which have high demand:
* Saving game videos in high quality and ensuring the frame rate is *completely* stable, always.
* Using Godot as a tool to make movies and animations (which is ideal if you want interaction, or creating them procedurally. No other software is as good for this).
**Note**: This feature **IS NOT** for capturing real-time footage. Use something like OBS, SimpleScreenRecorder or FRAPS to achieve that, as they do a much better job at intercepting the compositor than Godot can probably do using Vulkan or OpenGL natively. If your game runs near real-time when capturing, you can still use this feature but it will play no sound (sound will be saved directly).
Usage:
$ godot --write-movie movie.avi [scene_file.tscn]
Missing:
* Options for configuring video writing via GLOBAL_DEF
* UI Menu for launching with this mode from the editor.
* Add to list of command line options.
* Add a feature tag to override configurations when movie writing (fantastic for saving videos with highest quality settings).
2022-06-17 00:55:19 +02:00
|
|
|
typedef Error (*SaveJPGFunc)(const String &p_path, const Ref<Image> &p_img, float p_quality);
|
|
|
|
typedef Vector<uint8_t> (*SaveJPGBufferFunc)(const Ref<Image> &p_img, float p_quality);
|
2018-07-14 19:42:37 +02:00
|
|
|
typedef Ref<Image> (*ImageMemLoadFunc)(const uint8_t *p_png, int p_size);
|
2023-06-15 01:27:56 +02:00
|
|
|
typedef Ref<Image> (*ScalableImageMemLoadFunc)(const uint8_t *p_data, int p_size, float p_scale);
|
2022-06-04 23:05:55 +02:00
|
|
|
typedef Error (*SaveWebPFunc)(const String &p_path, const Ref<Image> &p_img, const bool p_lossy, const float p_quality);
|
|
|
|
typedef Vector<uint8_t> (*SaveWebPBufferFunc)(const Ref<Image> &p_img, const bool p_lossy, const float p_quality);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-08-03 02:07:13 +02:00
|
|
|
typedef Error (*SaveEXRFunc)(const String &p_path, const Ref<Image> &p_img, bool p_grayscale);
|
2022-06-20 03:55:47 +02:00
|
|
|
typedef Vector<uint8_t> (*SaveEXRBufferFunc)(const Ref<Image> &p_img, bool p_grayscale);
|
2019-08-03 02:07:13 +02:00
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
class Image : public Resource {
|
|
|
|
GDCLASS(Image, Resource);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-01-28 15:33:56 +01:00
|
|
|
public:
|
|
|
|
static SavePNGFunc save_png_func;
|
Implement Running Godot as Movie Writer
* Allows running the game in "movie writer" mode.
* It ensures entirely stable framerate, so your run can be saved stable and with proper sound (which is impossible if your CPU/GPU can't sustain doing this in real-time).
* If disabling vsync, it can save movies faster than the game is run, but if you want to control the interaction it can get difficult.
* Implements a simple, default MJPEG writer.
This new features has two main use cases, which have high demand:
* Saving game videos in high quality and ensuring the frame rate is *completely* stable, always.
* Using Godot as a tool to make movies and animations (which is ideal if you want interaction, or creating them procedurally. No other software is as good for this).
**Note**: This feature **IS NOT** for capturing real-time footage. Use something like OBS, SimpleScreenRecorder or FRAPS to achieve that, as they do a much better job at intercepting the compositor than Godot can probably do using Vulkan or OpenGL natively. If your game runs near real-time when capturing, you can still use this feature but it will play no sound (sound will be saved directly).
Usage:
$ godot --write-movie movie.avi [scene_file.tscn]
Missing:
* Options for configuring video writing via GLOBAL_DEF
* UI Menu for launching with this mode from the editor.
* Add to list of command line options.
* Add a feature tag to override configurations when movie writing (fantastic for saving videos with highest quality settings).
2022-06-17 00:55:19 +02:00
|
|
|
static SaveJPGFunc save_jpg_func;
|
2019-08-03 02:07:13 +02:00
|
|
|
static SaveEXRFunc save_exr_func;
|
2019-10-31 23:54:21 +01:00
|
|
|
static SavePNGBufferFunc save_png_buffer_func;
|
2022-06-20 03:55:47 +02:00
|
|
|
static SaveEXRBufferFunc save_exr_buffer_func;
|
Implement Running Godot as Movie Writer
* Allows running the game in "movie writer" mode.
* It ensures entirely stable framerate, so your run can be saved stable and with proper sound (which is impossible if your CPU/GPU can't sustain doing this in real-time).
* If disabling vsync, it can save movies faster than the game is run, but if you want to control the interaction it can get difficult.
* Implements a simple, default MJPEG writer.
This new features has two main use cases, which have high demand:
* Saving game videos in high quality and ensuring the frame rate is *completely* stable, always.
* Using Godot as a tool to make movies and animations (which is ideal if you want interaction, or creating them procedurally. No other software is as good for this).
**Note**: This feature **IS NOT** for capturing real-time footage. Use something like OBS, SimpleScreenRecorder or FRAPS to achieve that, as they do a much better job at intercepting the compositor than Godot can probably do using Vulkan or OpenGL natively. If your game runs near real-time when capturing, you can still use this feature but it will play no sound (sound will be saved directly).
Usage:
$ godot --write-movie movie.avi [scene_file.tscn]
Missing:
* Options for configuring video writing via GLOBAL_DEF
* UI Menu for launching with this mode from the editor.
* Add to list of command line options.
* Add a feature tag to override configurations when movie writing (fantastic for saving videos with highest quality settings).
2022-06-17 00:55:19 +02:00
|
|
|
static SaveJPGBufferFunc save_jpg_buffer_func;
|
2022-06-04 23:05:55 +02:00
|
|
|
static SaveWebPFunc save_webp_func;
|
|
|
|
static SaveWebPBufferFunc save_webp_buffer_func;
|
2019-01-28 15:33:56 +01:00
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
enum {
|
2019-10-31 23:54:21 +01:00
|
|
|
MAX_WIDTH = (1 << 24), // force a limit somehow
|
|
|
|
MAX_HEIGHT = (1 << 24), // force a limit somehow
|
|
|
|
MAX_PIXELS = 268435456
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Format {
|
2016-10-03 21:33:42 +02:00
|
|
|
FORMAT_L8, //luminance
|
|
|
|
FORMAT_LA8, //luminance-alpha
|
|
|
|
FORMAT_R8,
|
|
|
|
FORMAT_RG8,
|
|
|
|
FORMAT_RGB8,
|
|
|
|
FORMAT_RGBA8,
|
|
|
|
FORMAT_RGBA4444,
|
2019-09-27 04:16:44 +02:00
|
|
|
FORMAT_RGB565,
|
2016-10-03 21:33:42 +02:00
|
|
|
FORMAT_RF, //float
|
|
|
|
FORMAT_RGF,
|
|
|
|
FORMAT_RGBF,
|
|
|
|
FORMAT_RGBAF,
|
|
|
|
FORMAT_RH, //half float
|
|
|
|
FORMAT_RGH,
|
|
|
|
FORMAT_RGBH,
|
|
|
|
FORMAT_RGBAH,
|
2017-05-27 02:49:49 +02:00
|
|
|
FORMAT_RGBE9995,
|
2016-10-03 21:33:42 +02:00
|
|
|
FORMAT_DXT1, //s3tc bc1
|
|
|
|
FORMAT_DXT3, //bc2
|
|
|
|
FORMAT_DXT5, //bc3
|
2017-05-27 02:49:49 +02:00
|
|
|
FORMAT_RGTC_R,
|
|
|
|
FORMAT_RGTC_RG,
|
|
|
|
FORMAT_BPTC_RGBA, //btpc bc7
|
|
|
|
FORMAT_BPTC_RGBF, //float bc6h
|
|
|
|
FORMAT_BPTC_RGBFU, //unsigned float bc6hu
|
2016-10-03 21:33:42 +02:00
|
|
|
FORMAT_ETC, //etc1
|
|
|
|
FORMAT_ETC2_R11, //etc2
|
|
|
|
FORMAT_ETC2_R11S, //signed, NOT srgb.
|
|
|
|
FORMAT_ETC2_RG11,
|
|
|
|
FORMAT_ETC2_RG11S,
|
|
|
|
FORMAT_ETC2_RGB8,
|
|
|
|
FORMAT_ETC2_RGBA8,
|
|
|
|
FORMAT_ETC2_RGB8A1,
|
2019-09-27 04:16:44 +02:00
|
|
|
FORMAT_ETC2_RA_AS_RG, //used to make basis universal happy
|
|
|
|
FORMAT_DXT5_RA_AS_RG, //used to make basis universal happy
|
2022-09-05 21:11:34 +02:00
|
|
|
FORMAT_ASTC_4x4,
|
|
|
|
FORMAT_ASTC_4x4_HDR,
|
|
|
|
FORMAT_ASTC_8x8,
|
|
|
|
FORMAT_ASTC_8x8_HDR,
|
2014-02-10 02:10:30 +01:00
|
|
|
FORMAT_MAX
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static const char *format_names[FORMAT_MAX];
|
2014-02-10 02:10:30 +01:00
|
|
|
enum Interpolation {
|
|
|
|
INTERPOLATE_NEAREST,
|
|
|
|
INTERPOLATE_BILINEAR,
|
2015-10-01 21:25:36 +02:00
|
|
|
INTERPOLATE_CUBIC,
|
2018-06-01 21:53:35 +02:00
|
|
|
INTERPOLATE_TRILINEAR,
|
2019-05-05 14:03:52 +02:00
|
|
|
INTERPOLATE_LANCZOS,
|
2018-06-01 21:53:35 +02:00
|
|
|
/* INTERPOLATE_TRICUBIC, */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* INTERPOLATE GAUSS */
|
|
|
|
};
|
|
|
|
|
2019-09-27 04:16:44 +02:00
|
|
|
//this is used for compression
|
|
|
|
enum UsedChannels {
|
|
|
|
USED_CHANNELS_L,
|
|
|
|
USED_CHANNELS_LA,
|
|
|
|
USED_CHANNELS_R,
|
|
|
|
USED_CHANNELS_RG,
|
|
|
|
USED_CHANNELS_RGB,
|
|
|
|
USED_CHANNELS_RGBA,
|
2017-06-17 02:47:28 +02:00
|
|
|
};
|
2016-10-03 21:33:42 +02:00
|
|
|
//some functions provided by something else
|
|
|
|
|
2022-09-05 21:11:34 +02:00
|
|
|
enum ASTCFormat {
|
|
|
|
ASTC_FORMAT_4x4,
|
|
|
|
ASTC_FORMAT_8x8,
|
|
|
|
};
|
|
|
|
|
2018-07-14 19:42:37 +02:00
|
|
|
static ImageMemLoadFunc _png_mem_loader_func;
|
2023-09-06 01:44:18 +02:00
|
|
|
static ImageMemLoadFunc _png_mem_unpacker_func;
|
2018-07-14 19:42:37 +02:00
|
|
|
static ImageMemLoadFunc _jpg_mem_loader_func;
|
|
|
|
static ImageMemLoadFunc _webp_mem_loader_func;
|
2020-05-21 13:46:44 +02:00
|
|
|
static ImageMemLoadFunc _tga_mem_loader_func;
|
2020-10-20 23:25:58 +02:00
|
|
|
static ImageMemLoadFunc _bmp_mem_loader_func;
|
2023-06-15 01:27:56 +02:00
|
|
|
static ScalableImageMemLoadFunc _svg_scalable_mem_loader_func;
|
2023-04-28 18:26:01 +02:00
|
|
|
static ImageMemLoadFunc _ktx_mem_loader_func;
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2023-01-25 12:17:11 +01:00
|
|
|
static void (*_image_compress_bc_func)(Image *, UsedChannels p_channels);
|
|
|
|
static void (*_image_compress_bptc_func)(Image *, UsedChannels p_channels);
|
|
|
|
static void (*_image_compress_etc1_func)(Image *);
|
|
|
|
static void (*_image_compress_etc2_func)(Image *, UsedChannels p_channels);
|
|
|
|
static void (*_image_compress_astc_func)(Image *, ASTCFormat p_format);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
static void (*_image_decompress_bc)(Image *);
|
2018-08-22 04:56:04 +02:00
|
|
|
static void (*_image_decompress_bptc)(Image *);
|
2017-04-26 17:49:08 +02:00
|
|
|
static void (*_image_decompress_etc1)(Image *);
|
2016-10-03 21:33:42 +02:00
|
|
|
static void (*_image_decompress_etc2)(Image *);
|
2022-09-05 21:11:34 +02:00
|
|
|
static void (*_image_decompress_astc)(Image *);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-04-12 18:56:50 +02:00
|
|
|
static Vector<uint8_t> (*webp_lossy_packer)(const Ref<Image> &p_image, float p_quality);
|
|
|
|
static Vector<uint8_t> (*webp_lossless_packer)(const Ref<Image> &p_image);
|
|
|
|
static Ref<Image> (*webp_unpacker)(const Vector<uint8_t> &p_buffer);
|
|
|
|
static Vector<uint8_t> (*png_packer)(const Ref<Image> &p_image);
|
|
|
|
static Ref<Image> (*png_unpacker)(const Vector<uint8_t> &p_buffer);
|
2020-02-17 22:06:54 +01:00
|
|
|
static Vector<uint8_t> (*basis_universal_packer)(const Ref<Image> &p_image, UsedChannels p_channels);
|
|
|
|
static Ref<Image> (*basis_universal_unpacker)(const Vector<uint8_t> &p_buffer);
|
2022-03-24 18:18:55 +01:00
|
|
|
static Ref<Image> (*basis_universal_unpacker_ptr)(const uint8_t *p_data, int p_size);
|
2017-05-27 02:49:49 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
_FORCE_INLINE_ Color _get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const;
|
2020-01-27 00:09:40 +01:00
|
|
|
_FORCE_INLINE_ void _set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color);
|
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
private:
|
2020-05-12 17:01:17 +02:00
|
|
|
Format format = FORMAT_L8;
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<uint8_t> data;
|
2020-05-12 17:01:17 +02:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
bool mipmaps = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
void _copy_internals_from(const Image &p_image) {
|
|
|
|
format = p_image.format;
|
|
|
|
width = p_image.width;
|
|
|
|
height = p_image.height;
|
|
|
|
mipmaps = p_image.mipmaps;
|
|
|
|
data = p_image.data;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void _get_mipmap_offset_and_size(int p_mipmap, int &r_offset, int &r_width, int &r_height) const; //get where the mipmap begins in data
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1, int *r_mm_width = nullptr, int *r_mm_height = nullptr);
|
2014-02-10 02:10:30 +01:00
|
|
|
bool _can_modify(Format p_format) const;
|
|
|
|
|
2021-07-05 10:48:25 +02:00
|
|
|
_FORCE_INLINE_ void _get_clipped_src_and_dest_rects(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest, Rect2i &r_clipped_src_rect, Rect2i &r_clipped_dest_rect) const;
|
|
|
|
|
2021-09-08 10:16:11 +02:00
|
|
|
_FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixel_size, uint8_t *p_data, const uint8_t *p_pixel);
|
|
|
|
_FORCE_INLINE_ void _get_pixelb(int p_x, int p_y, uint32_t p_pixel_size, const uint8_t *p_data, uint8_t *p_pixel);
|
|
|
|
|
|
|
|
_FORCE_INLINE_ void _repeat_pixel_over_subsequent_memory(uint8_t *p_pixel, int p_pixel_size, int p_count);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
void _set_data(const Dictionary &p_data);
|
|
|
|
Dictionary _get_data() const;
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Error _load_from_buffer(const Vector<uint8_t> &p_array, ImageMemLoadFunc p_loader);
|
2018-07-14 19:42:37 +02:00
|
|
|
|
2018-08-22 04:56:04 +02:00
|
|
|
static void average_4_uint8(uint8_t &p_out, const uint8_t &p_a, const uint8_t &p_b, const uint8_t &p_c, const uint8_t &p_d);
|
|
|
|
static void average_4_float(float &p_out, const float &p_a, const float &p_b, const float &p_c, const float &p_d);
|
|
|
|
static void average_4_half(uint16_t &p_out, const uint16_t &p_a, const uint16_t &p_b, const uint16_t &p_c, const uint16_t &p_d);
|
|
|
|
static void average_4_rgbe9995(uint32_t &p_out, const uint32_t &p_a, const uint32_t &p_b, const uint32_t &p_c, const uint32_t &p_d);
|
|
|
|
static void renormalize_uint8(uint8_t *p_rgb);
|
|
|
|
static void renormalize_float(float *p_rgb);
|
|
|
|
static void renormalize_half(uint16_t *p_rgb);
|
|
|
|
static void renormalize_rgbe9995(uint32_t *p_rgb);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
|
|
|
int get_width() const; ///< Get image width
|
|
|
|
int get_height() const; ///< Get image height
|
2022-09-01 11:34:15 +02:00
|
|
|
Size2i get_size() const;
|
2016-10-03 21:33:42 +02:00
|
|
|
bool has_mipmaps() const;
|
|
|
|
int get_mipmap_count() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
2016-10-03 21:33:42 +02:00
|
|
|
* Convert the image to another format, conversion only to raw byte format
|
2014-02-10 02:10:30 +01:00
|
|
|
*/
|
2017-03-05 16:44:50 +01:00
|
|
|
void convert(Format p_new_format);
|
2014-10-03 05:10:51 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
|
|
|
* Get the current image format.
|
|
|
|
*/
|
|
|
|
Format get_format() const;
|
|
|
|
|
2020-01-27 00:09:40 +01:00
|
|
|
int get_mipmap_byte_size(int p_mipmap) const; //get where the mipmap begins in data
|
2014-02-10 02:10:30 +01:00
|
|
|
int get_mipmap_offset(int p_mipmap) const; //get where the mipmap begins in data
|
2017-03-05 16:44:50 +01:00
|
|
|
void get_mipmap_offset_and_size(int p_mipmap, int &r_ofs, int &r_size) const; //get where the mipmap begins in data
|
|
|
|
void get_mipmap_offset_size_and_dimensions(int p_mipmap, int &r_ofs, int &r_size, int &w, int &h) const; //get where the mipmap begins in data
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-09-09 17:40:51 +02:00
|
|
|
enum Image3DValidateError {
|
|
|
|
VALIDATE_3D_OK,
|
|
|
|
VALIDATE_3D_ERR_IMAGE_EMPTY,
|
|
|
|
VALIDATE_3D_ERR_MISSING_IMAGES,
|
|
|
|
VALIDATE_3D_ERR_EXTRA_IMAGES,
|
|
|
|
VALIDATE_3D_ERR_IMAGE_SIZE_MISMATCH,
|
|
|
|
VALIDATE_3D_ERR_IMAGE_FORMAT_MISMATCH,
|
|
|
|
VALIDATE_3D_ERR_IMAGE_HAS_MIPMAPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
static Image3DValidateError validate_3d_image(Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_images);
|
|
|
|
static String get_3d_image_validation_error_text(Image3DValidateError p_error);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
2017-03-24 21:45:31 +01:00
|
|
|
* Resize the image, using the preferred interpolation method.
|
2016-03-09 00:00:52 +01:00
|
|
|
*/
|
2020-12-18 15:14:55 +01:00
|
|
|
void resize_to_po2(bool p_square = false, Interpolation p_interpolation = INTERPOLATE_BILINEAR);
|
2017-03-05 16:44:50 +01:00
|
|
|
void resize(int p_width, int p_height, Interpolation p_interpolation = INTERPOLATE_BILINEAR);
|
2016-05-04 17:36:51 +02:00
|
|
|
void shrink_x2();
|
2019-03-07 16:15:10 +01:00
|
|
|
bool is_size_po2() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
|
|
|
* Crop the image to a specific size, if larger, then the image is filled by black
|
|
|
|
*/
|
2017-11-18 04:42:14 +01:00
|
|
|
void crop_from_point(int p_x, int p_y, int p_width, int p_height);
|
2017-03-05 16:44:50 +01:00
|
|
|
void crop(int p_width, int p_height);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-07-14 21:20:12 +02:00
|
|
|
void rotate_90(ClockDirection p_direction);
|
|
|
|
void rotate_180();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void flip_x();
|
|
|
|
void flip_y();
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/**
|
2016-03-09 00:00:52 +01:00
|
|
|
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
|
2014-02-10 02:10:30 +01:00
|
|
|
*/
|
2018-04-30 02:51:37 +02:00
|
|
|
Error generate_mipmaps(bool p_renormalize = false);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-01-27 00:09:40 +01:00
|
|
|
enum RoughnessChannel {
|
|
|
|
ROUGHNESS_CHANNEL_R,
|
|
|
|
ROUGHNESS_CHANNEL_G,
|
|
|
|
ROUGHNESS_CHANNEL_B,
|
|
|
|
ROUGHNESS_CHANNEL_A,
|
|
|
|
ROUGHNESS_CHANNEL_L,
|
|
|
|
};
|
|
|
|
|
|
|
|
Error generate_mipmap_roughness(RoughnessChannel p_roughness_channel, const Ref<Image> &p_normal_map);
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void clear_mipmaps();
|
2018-07-03 15:55:50 +02:00
|
|
|
void normalize(); //for normal maps
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/**
|
2022-07-22 20:06:19 +02:00
|
|
|
* Creates new internal image data of a given size and format. Current image will be lost.
|
2014-02-10 02:10:30 +01:00
|
|
|
*/
|
2022-07-22 20:06:19 +02:00
|
|
|
void initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
|
|
|
|
void initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
|
|
|
|
void initialize_data(const char **p_xpm);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* returns true when the image is empty (0,0) in size
|
|
|
|
*/
|
2020-12-15 13:04:21 +01:00
|
|
|
bool is_empty() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<uint8_t> get_data() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error load(const String &p_path);
|
2022-05-04 01:49:20 +02:00
|
|
|
static Ref<Image> load_from_file(const String &p_path);
|
2017-04-30 03:14:14 +02:00
|
|
|
Error save_png(const String &p_path) const;
|
Implement Running Godot as Movie Writer
* Allows running the game in "movie writer" mode.
* It ensures entirely stable framerate, so your run can be saved stable and with proper sound (which is impossible if your CPU/GPU can't sustain doing this in real-time).
* If disabling vsync, it can save movies faster than the game is run, but if you want to control the interaction it can get difficult.
* Implements a simple, default MJPEG writer.
This new features has two main use cases, which have high demand:
* Saving game videos in high quality and ensuring the frame rate is *completely* stable, always.
* Using Godot as a tool to make movies and animations (which is ideal if you want interaction, or creating them procedurally. No other software is as good for this).
**Note**: This feature **IS NOT** for capturing real-time footage. Use something like OBS, SimpleScreenRecorder or FRAPS to achieve that, as they do a much better job at intercepting the compositor than Godot can probably do using Vulkan or OpenGL natively. If your game runs near real-time when capturing, you can still use this feature but it will play no sound (sound will be saved directly).
Usage:
$ godot --write-movie movie.avi [scene_file.tscn]
Missing:
* Options for configuring video writing via GLOBAL_DEF
* UI Menu for launching with this mode from the editor.
* Add to list of command line options.
* Add a feature tag to override configurations when movie writing (fantastic for saving videos with highest quality settings).
2022-06-17 00:55:19 +02:00
|
|
|
Error save_jpg(const String &p_path, float p_quality = 0.75) const;
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<uint8_t> save_png_to_buffer() const;
|
Implement Running Godot as Movie Writer
* Allows running the game in "movie writer" mode.
* It ensures entirely stable framerate, so your run can be saved stable and with proper sound (which is impossible if your CPU/GPU can't sustain doing this in real-time).
* If disabling vsync, it can save movies faster than the game is run, but if you want to control the interaction it can get difficult.
* Implements a simple, default MJPEG writer.
This new features has two main use cases, which have high demand:
* Saving game videos in high quality and ensuring the frame rate is *completely* stable, always.
* Using Godot as a tool to make movies and animations (which is ideal if you want interaction, or creating them procedurally. No other software is as good for this).
**Note**: This feature **IS NOT** for capturing real-time footage. Use something like OBS, SimpleScreenRecorder or FRAPS to achieve that, as they do a much better job at intercepting the compositor than Godot can probably do using Vulkan or OpenGL natively. If your game runs near real-time when capturing, you can still use this feature but it will play no sound (sound will be saved directly).
Usage:
$ godot --write-movie movie.avi [scene_file.tscn]
Missing:
* Options for configuring video writing via GLOBAL_DEF
* UI Menu for launching with this mode from the editor.
* Add to list of command line options.
* Add a feature tag to override configurations when movie writing (fantastic for saving videos with highest quality settings).
2022-06-17 00:55:19 +02:00
|
|
|
Vector<uint8_t> save_jpg_to_buffer(float p_quality = 0.75) const;
|
2024-01-10 22:53:40 +01:00
|
|
|
Vector<uint8_t> save_exr_to_buffer(bool p_grayscale = false) const;
|
|
|
|
Error save_exr(const String &p_path, bool p_grayscale = false) const;
|
2022-06-04 23:05:55 +02:00
|
|
|
Error save_webp(const String &p_path, const bool p_lossy = false, const float p_quality = 0.75f) const;
|
|
|
|
Vector<uint8_t> save_webp_to_buffer(const bool p_lossy = false, const float p_quality = 0.75f) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-07-22 20:06:19 +02:00
|
|
|
static Ref<Image> create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
|
|
|
|
static Ref<Image> create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
|
|
|
|
void set_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
|
2022-02-13 13:41:29 +01:00
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
/**
|
2014-02-10 02:10:30 +01:00
|
|
|
* create an empty image
|
|
|
|
*/
|
2020-05-12 17:01:17 +02:00
|
|
|
Image() {}
|
2016-03-09 00:00:52 +01:00
|
|
|
/**
|
2014-02-10 02:10:30 +01:00
|
|
|
* create an empty image of a specific size and format
|
|
|
|
*/
|
|
|
|
Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
|
2016-03-09 00:00:52 +01:00
|
|
|
/**
|
2014-02-10 02:10:30 +01:00
|
|
|
* import an image of a specific size and format from a pointer
|
|
|
|
*/
|
2020-02-17 22:06:54 +01:00
|
|
|
Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
~Image() {}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
enum AlphaMode {
|
|
|
|
ALPHA_NONE,
|
|
|
|
ALPHA_BIT,
|
|
|
|
ALPHA_BLEND
|
|
|
|
};
|
|
|
|
|
|
|
|
AlphaMode detect_alpha() const;
|
2015-06-02 00:42:34 +02:00
|
|
|
bool is_invisible() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static int get_format_pixel_size(Format p_format);
|
|
|
|
static int get_format_pixel_rshift(Format p_format);
|
2017-05-27 02:49:49 +02:00
|
|
|
static int get_format_block_size(Format p_format);
|
2017-03-05 16:44:50 +01:00
|
|
|
static void get_format_min_pixel_size(Format p_format, int &r_w, int &r_h);
|
2016-10-03 21:33:42 +02:00
|
|
|
|
2018-08-06 19:56:06 +02:00
|
|
|
static int get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps = false);
|
2014-02-10 02:10:30 +01:00
|
|
|
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
|
2019-07-27 15:23:24 +02:00
|
|
|
static Size2i get_image_mipmap_size(int p_width, int p_height, Format p_format, int p_mipmap);
|
2018-11-16 23:12:00 +01:00
|
|
|
static int get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap);
|
2019-09-27 04:16:44 +02:00
|
|
|
static int get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
enum CompressMode {
|
2016-10-03 21:33:42 +02:00
|
|
|
COMPRESS_S3TC,
|
|
|
|
COMPRESS_ETC,
|
2017-05-27 02:49:49 +02:00
|
|
|
COMPRESS_ETC2,
|
2020-12-10 23:01:00 +01:00
|
|
|
COMPRESS_BPTC,
|
2022-09-05 21:11:34 +02:00
|
|
|
COMPRESS_ASTC,
|
2021-06-25 13:50:22 +02:00
|
|
|
COMPRESS_MAX,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2019-09-27 04:16:44 +02:00
|
|
|
enum CompressSource {
|
|
|
|
COMPRESS_SOURCE_GENERIC,
|
|
|
|
COMPRESS_SOURCE_SRGB,
|
2021-06-25 13:50:22 +02:00
|
|
|
COMPRESS_SOURCE_NORMAL,
|
|
|
|
COMPRESS_SOURCE_MAX,
|
2019-09-27 04:16:44 +02:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-01-25 12:17:11 +01:00
|
|
|
Error compress(CompressMode p_mode, CompressSource p_source = COMPRESS_SOURCE_GENERIC, ASTCFormat p_astc_format = ASTC_FORMAT_4x4);
|
|
|
|
Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, ASTCFormat p_astc_format = ASTC_FORMAT_4x4);
|
2014-06-11 15:41:03 +02:00
|
|
|
Error decompress();
|
2015-05-31 06:59:42 +02:00
|
|
|
bool is_compressed() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void fix_alpha_edges();
|
2014-05-24 06:35:47 +02:00
|
|
|
void premultiply_alpha();
|
2014-06-16 15:22:26 +02:00
|
|
|
void srgb_to_linear();
|
2020-12-23 10:34:26 +01:00
|
|
|
void normal_map_to_xy();
|
2018-05-30 21:14:07 +02:00
|
|
|
Ref<Image> rgbe_to_srgb();
|
2019-09-27 04:16:44 +02:00
|
|
|
Ref<Image> get_image_from_mipmap(int p_mipamp) const;
|
2020-12-23 10:34:26 +01:00
|
|
|
void bump_map_to_normal_map(float bump_scale = 1.0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-09 22:43:34 +02:00
|
|
|
void blit_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest);
|
|
|
|
void blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2i &p_src_rect, const Point2i &p_dest);
|
|
|
|
void blend_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest);
|
|
|
|
void blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2i &p_src_rect, const Point2i &p_dest);
|
2021-09-07 10:27:32 +02:00
|
|
|
void fill(const Color &p_color);
|
2022-07-09 22:43:34 +02:00
|
|
|
void fill_rect(const Rect2i &p_rect, const Color &p_color);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-09 22:43:34 +02:00
|
|
|
Rect2i get_used_rect() const;
|
2022-09-18 02:19:55 +02:00
|
|
|
Ref<Image> get_region(const Rect2i &p_area) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-01-25 12:17:11 +01:00
|
|
|
static void set_compress_bc_func(void (*p_compress_func)(Image *, UsedChannels));
|
|
|
|
static void set_compress_bptc_func(void (*p_compress_func)(Image *, UsedChannels));
|
2015-10-21 14:50:44 +02:00
|
|
|
static String get_format_name(Format p_format);
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Error load_png_from_buffer(const Vector<uint8_t> &p_array);
|
|
|
|
Error load_jpg_from_buffer(const Vector<uint8_t> &p_array);
|
|
|
|
Error load_webp_from_buffer(const Vector<uint8_t> &p_array);
|
2020-05-21 13:46:44 +02:00
|
|
|
Error load_tga_from_buffer(const Vector<uint8_t> &p_array);
|
2020-10-20 23:25:58 +02:00
|
|
|
Error load_bmp_from_buffer(const Vector<uint8_t> &p_array);
|
2023-04-28 18:26:01 +02:00
|
|
|
Error load_ktx_from_buffer(const Vector<uint8_t> &p_array);
|
2017-12-20 21:16:21 +01:00
|
|
|
|
2023-06-15 01:27:56 +02:00
|
|
|
Error load_svg_from_buffer(const Vector<uint8_t> &p_array, float scale = 1.0);
|
|
|
|
Error load_svg_from_string(const String &p_svg_str, float scale = 1.0);
|
|
|
|
|
2019-09-27 04:16:44 +02:00
|
|
|
void convert_rg_to_ra_rgba8();
|
|
|
|
void convert_ra_rgba8_to_rg();
|
2022-12-01 15:34:05 +01:00
|
|
|
void convert_rgba8_to_bgra8();
|
2019-09-27 04:16:44 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
|
2014-02-10 02:10:30 +01:00
|
|
|
Image(const char **p_xpm);
|
2017-05-17 12:36:47 +02:00
|
|
|
|
2020-07-10 12:34:39 +02:00
|
|
|
virtual Ref<Resource> duplicate(bool p_subresources = false) const override;
|
2017-05-17 12:36:47 +02:00
|
|
|
|
2022-03-24 18:18:55 +01:00
|
|
|
UsedChannels detect_used_channels(CompressSource p_source = COMPRESS_SOURCE_GENERIC) const;
|
2018-08-06 19:56:06 +02:00
|
|
|
void optimize_channels();
|
2017-05-27 02:49:49 +02:00
|
|
|
|
2020-11-21 08:42:29 +01:00
|
|
|
Color get_pixelv(const Point2i &p_point) const;
|
2017-06-17 02:28:58 +02:00
|
|
|
Color get_pixel(int p_x, int p_y) const;
|
2020-11-21 08:42:29 +01:00
|
|
|
void set_pixelv(const Point2i &p_point, const Color &p_color);
|
2017-07-07 19:05:45 +02:00
|
|
|
void set_pixel(int p_x, int p_y, const Color &p_color);
|
2017-05-27 02:49:49 +02:00
|
|
|
|
2021-02-12 16:16:37 +01:00
|
|
|
void adjust_bcs(float p_brightness, float p_contrast, float p_saturation);
|
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
void set_as_black();
|
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
void copy_internals_from(const Ref<Image> &p_image) {
|
2024-01-26 20:33:22 +01:00
|
|
|
ERR_FAIL_COND_MSG(p_image.is_null(), "Cannot copy image internals: invalid Image object.");
|
2017-05-17 12:36:47 +02:00
|
|
|
format = p_image->format;
|
|
|
|
width = p_image->width;
|
|
|
|
height = p_image->height;
|
|
|
|
mipmaps = p_image->mipmaps;
|
|
|
|
data = p_image->data;
|
|
|
|
}
|
2022-01-18 13:39:55 +01:00
|
|
|
|
|
|
|
Dictionary compute_image_metrics(const Ref<Image> p_compared_image, bool p_luma_metric = true);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-05-17 12:36:47 +02:00
|
|
|
VARIANT_ENUM_CAST(Image::Format)
|
|
|
|
VARIANT_ENUM_CAST(Image::Interpolation)
|
|
|
|
VARIANT_ENUM_CAST(Image::CompressMode)
|
2017-06-17 02:47:28 +02:00
|
|
|
VARIANT_ENUM_CAST(Image::CompressSource)
|
2019-09-27 04:16:44 +02:00
|
|
|
VARIANT_ENUM_CAST(Image::UsedChannels)
|
2017-05-17 12:36:47 +02:00
|
|
|
VARIANT_ENUM_CAST(Image::AlphaMode)
|
2020-01-27 00:09:40 +01:00
|
|
|
VARIANT_ENUM_CAST(Image::RoughnessChannel)
|
2022-09-05 21:11:34 +02:00
|
|
|
VARIANT_ENUM_CAST(Image::ASTCFormat)
|
2017-05-17 12:36:47 +02:00
|
|
|
|
2020-03-25 11:10:34 +01:00
|
|
|
#endif // IMAGE_H
|