summaryrefslogtreecommitdiff
path: root/core/image.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/image.h')
-rw-r--r--core/image.h82
1 files changed, 55 insertions, 27 deletions
diff --git a/core/image.h b/core/image.h
index c15cfc9f6f..1cc22420d5 100644
--- a/core/image.h
+++ b/core/image.h
@@ -47,6 +47,7 @@
class Image;
typedef Error (*SavePNGFunc)(const String &p_path, const Ref<Image> &p_img);
+typedef PoolVector<uint8_t> (*SavePNGBufferFunc)(const Ref<Image> &p_img);
typedef Ref<Image> (*ImageMemLoadFunc)(const uint8_t *p_png, int p_size);
typedef Error (*SaveEXRFunc)(const String &p_path, const Ref<Image> &p_img, bool p_grayscale);
@@ -57,10 +58,12 @@ class Image : public Resource {
public:
static SavePNGFunc save_png_func;
static SaveEXRFunc save_exr_func;
+ static SavePNGBufferFunc save_png_buffer_func;
enum {
- MAX_WIDTH = 16384, // force a limit somehow
- MAX_HEIGHT = 16384 // force a limit somehow
+ MAX_WIDTH = (1 << 24), // force a limit somehow
+ MAX_HEIGHT = (1 << 24), // force a limit somehow
+ MAX_PIXELS = 268435456
};
enum Format {
@@ -72,7 +75,7 @@ public:
FORMAT_RGB8,
FORMAT_RGBA8,
FORMAT_RGBA4444,
- FORMAT_RGBA5551,
+ FORMAT_RGB565,
FORMAT_RF, //float
FORMAT_RGF,
FORMAT_RGBF,
@@ -102,6 +105,8 @@ public:
FORMAT_ETC2_RGB8,
FORMAT_ETC2_RGBA8,
FORMAT_ETC2_RGB8A1,
+ FORMAT_ETC2_RA_AS_RG, //used to make basis universal happy
+ FORMAT_DXT5_RA_AS_RG, //used to make basis universal happy
FORMAT_MAX
};
@@ -117,25 +122,27 @@ public:
/* INTERPOLATE GAUSS */
};
- enum CompressSource {
- COMPRESS_SOURCE_GENERIC,
- COMPRESS_SOURCE_SRGB,
- COMPRESS_SOURCE_NORMAL,
- COMPRESS_SOURCE_LAYERED,
+ //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,
};
-
//some functions provided by something else
static ImageMemLoadFunc _png_mem_loader_func;
static ImageMemLoadFunc _jpg_mem_loader_func;
static ImageMemLoadFunc _webp_mem_loader_func;
- static void (*_image_compress_bc_func)(Image *, float, CompressSource p_source);
- static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, CompressSource p_source);
+ static void (*_image_compress_bc_func)(Image *, float, UsedChannels p_channels);
+ static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, UsedChannels p_channels);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
static void (*_image_compress_etc1_func)(Image *, float);
- static void (*_image_compress_etc2_func)(Image *, float, CompressSource p_source);
+ static void (*_image_compress_etc2_func)(Image *, float, UsedChannels p_channels);
static void (*_image_decompress_pvrtc)(Image *);
static void (*_image_decompress_bc)(Image *);
@@ -147,9 +154,14 @@ public:
static Ref<Image> (*lossy_unpacker)(const PoolVector<uint8_t> &p_buffer);
static PoolVector<uint8_t> (*lossless_packer)(const Ref<Image> &p_image);
static Ref<Image> (*lossless_unpacker)(const PoolVector<uint8_t> &p_buffer);
+ static PoolVector<uint8_t> (*basis_universal_packer)(const Ref<Image> &p_image, UsedChannels p_channels);
+ static Ref<Image> (*basis_universal_unpacker)(const PoolVector<uint8_t> &p_buffer);
PoolVector<uint8_t>::Write write_lock;
+ _FORCE_INLINE_ Color _get_color_at_ofs(uint8_t *ptr, uint32_t ofs) const;
+ _FORCE_INLINE_ void _set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color);
+
protected:
static void _bind_methods();
@@ -177,7 +189,7 @@ private:
_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
- static int _get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps = -1);
+ 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 = NULL, int *r_mm_height = NULL);
bool _can_modify(Format p_format) const;
_FORCE_INLINE_ void _put_pixelb(int p_x, int p_y, uint32_t p_pixelsize, uint8_t *p_data, const uint8_t *p_pixel);
@@ -214,6 +226,7 @@ public:
*/
Format get_format() const;
+ int get_mipmap_byte_size(int p_mipmap) const; //get where the mipmap begins in data
int get_mipmap_offset(int p_mipmap) const; //get where the mipmap begins in data
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
@@ -240,6 +253,16 @@ public:
*/
Error generate_mipmaps(bool p_renormalize = false);
+ 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);
+
void clear_mipmaps();
void normalize(); //for normal maps
@@ -259,6 +282,7 @@ public:
Error load(const String &p_path);
Error save_png(const String &p_path) const;
+ PoolVector<uint8_t> save_png_to_buffer() const;
Error save_exr(const String &p_path, bool p_grayscale) const;
/**
@@ -290,7 +314,9 @@ public:
static int get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps = false);
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
+ static Size2i get_image_mipmap_size(int p_width, int p_height, Format p_format, int p_mipmap);
static int get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap);
+ 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);
enum CompressMode {
COMPRESS_S3TC,
@@ -300,8 +326,14 @@ public:
COMPRESS_ETC2,
COMPRESS_BPTC
};
+ enum CompressSource {
+ COMPRESS_SOURCE_GENERIC,
+ COMPRESS_SOURCE_SRGB,
+ COMPRESS_SOURCE_NORMAL
+ };
- Error compress(CompressMode p_mode = COMPRESS_S3TC, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7);
+ Error compress(CompressMode p_mode, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7);
+ Error compress_from_channels(CompressMode p_mode, UsedChannels p_channels, float p_lossy_quality = 0.7);
Error decompress();
bool is_compressed() const;
@@ -310,6 +342,7 @@ public:
void srgb_to_linear();
void normalmap_to_xy();
Ref<Image> rgbe_to_srgb();
+ Ref<Image> get_image_from_mipmap(int p_mipamp) const;
void bumpmap_to_normalmap(float bump_scale = 1.0);
void blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest);
@@ -321,14 +354,17 @@ public:
Rect2 get_used_rect() const;
Ref<Image> get_rect(const Rect2 &p_area) const;
- static void set_compress_bc_func(void (*p_compress_func)(Image *, float, CompressSource));
- static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource));
+ static void set_compress_bc_func(void (*p_compress_func)(Image *, float, UsedChannels));
+ static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, UsedChannels));
static String get_format_name(Format p_format);
Error load_png_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_jpg_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_webp_from_buffer(const PoolVector<uint8_t> &p_array);
+ void convert_rg_to_ra_rgba8();
+ void convert_ra_rgba8_to_rg();
+
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
Image(const char **p_xpm);
@@ -337,17 +373,7 @@ public:
void lock();
void unlock();
- //this is used for compression
- enum DetectChannels {
- DETECTED_L,
- DETECTED_LA,
- DETECTED_R,
- DETECTED_RG,
- DETECTED_RGB,
- DETECTED_RGBA,
- };
-
- DetectChannels get_detected_channels();
+ UsedChannels detect_used_channels(CompressSource p_source = COMPRESS_SOURCE_GENERIC);
void optimize_channels();
Color get_pixelv(const Point2 &p_src) const;
@@ -371,6 +397,8 @@ VARIANT_ENUM_CAST(Image::Format)
VARIANT_ENUM_CAST(Image::Interpolation)
VARIANT_ENUM_CAST(Image::CompressMode)
VARIANT_ENUM_CAST(Image::CompressSource)
+VARIANT_ENUM_CAST(Image::UsedChannels)
VARIANT_ENUM_CAST(Image::AlphaMode)
+VARIANT_ENUM_CAST(Image::RoughnessChannel)
#endif