Now Image is enabled and it compiles.

This commit is contained in:
Relintai 2022-02-04 13:37:52 +01:00
parent e60cb3ab42
commit 71947ea292
4 changed files with 308 additions and 769 deletions

View File

@ -14,6 +14,7 @@ env.add_source_files(env.core_sources, "./hash/*.cpp")
env.add_source_files(env.core_sources, "./bry_http/*.cpp") env.add_source_files(env.core_sources, "./bry_http/*.cpp")
env.add_source_files(env.core_sources, "./database/*.cpp") env.add_source_files(env.core_sources, "./database/*.cpp")
env.add_source_files(env.core_sources, "./os/*.cpp") env.add_source_files(env.core_sources, "./os/*.cpp")
env.add_source_files(env.core_sources, "./image/*.cpp")
env.add_source_files(env.core_sources, "./threading/*.cpp") env.add_source_files(env.core_sources, "./threading/*.cpp")
env.add_source_files(env.core_sources, "./settings/*.cpp") env.add_source_files(env.core_sources, "./settings/*.cpp")
env.add_source_files(env.core_sources, "./nodes/*.cpp") env.add_source_files(env.core_sources, "./nodes/*.cpp")

File diff suppressed because it is too large Load Diff

View File

@ -31,35 +31,17 @@
#ifndef IMAGE_H #ifndef IMAGE_H
#define IMAGE_H #define IMAGE_H
#include "core/color.h" #include "core/math/color.h"
#include "core/math/rect2.h" #include "core/math/rect2.h"
#include "core/pool_vector.h" #include "core/containers/vector.h"
#include "core/resource.h" #include "core/resource.h"
#include "core/math/rect2i.h"
/** #include "core/math/vector2i.h"
* @author Juan Linietsky <reduzio@gmail.com>
*
* 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.
*/
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);
class Image : public Resource { class Image : public Resource {
GDCLASS(Image, Resource); RCPP_OBJECT(Image, Resource);
public: public:
static SavePNGFunc save_png_func;
static SaveEXRFunc save_exr_func;
static SavePNGBufferFunc save_png_buffer_func;
enum { enum {
MAX_WIDTH = 16384, // force a limit somehow MAX_WIDTH = 16384, // force a limit somehow
MAX_HEIGHT = 16384 // force a limit somehow MAX_HEIGHT = 16384 // force a limit somehow
@ -127,49 +109,19 @@ public:
COMPRESS_SOURCE_MAX, COMPRESS_SOURCE_MAX,
}; };
//some functions provided by something else bool write_lock;
static ImageMemLoadFunc _png_mem_loader_func;
static ImageMemLoadFunc _jpg_mem_loader_func;
static ImageMemLoadFunc _webp_mem_loader_func;
static ImageMemLoadFunc _tga_mem_loader_func;
static ImageMemLoadFunc _bmp_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_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_decompress_pvrtc)(Image *);
static void (*_image_decompress_bc)(Image *);
static void (*_image_decompress_bptc)(Image *);
static void (*_image_decompress_etc1)(Image *);
static void (*_image_decompress_etc2)(Image *);
static PoolVector<uint8_t> (*webp_lossy_packer)(const Ref<Image> &p_image, float p_quality);
static PoolVector<uint8_t> (*webp_lossless_packer)(const Ref<Image> &p_image);
static Ref<Image> (*webp_unpacker)(const PoolVector<uint8_t> &p_buffer);
static PoolVector<uint8_t> (*png_packer)(const Ref<Image> &p_image);
static Ref<Image> (*png_unpacker)(const PoolVector<uint8_t> &p_buffer);
PoolVector<uint8_t>::Write write_lock;
protected:
static void _bind_methods();
private: private:
void _create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format) { void _create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {
create(p_width, p_height, p_use_mipmaps, p_format); create(p_width, p_height, p_use_mipmaps, p_format);
} }
void _create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const PoolVector<uint8_t> &p_data) { void _create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {
create(p_width, p_height, p_use_mipmaps, p_format, p_data); create(p_width, p_height, p_use_mipmaps, p_format, p_data);
} }
Format format; Format format;
PoolVector<uint8_t> data; Vector<uint8_t> data;
int width, height; int width, height;
bool mipmaps; bool mipmaps;
@ -191,11 +143,6 @@ private:
_FORCE_INLINE_ void _repeat_pixel_over_subsequent_memory(uint8_t *p_pixel, int p_pixel_size, int p_count); _FORCE_INLINE_ void _repeat_pixel_over_subsequent_memory(uint8_t *p_pixel, int p_pixel_size, int p_count);
void _set_data(const Dictionary &p_data);
Dictionary _get_data() const;
Error _load_from_buffer(const PoolVector<uint8_t> &p_array, ImageMemLoadFunc p_loader);
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_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_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_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);
@ -232,7 +179,6 @@ public:
void resize_to_po2(bool p_square = false, Interpolation p_interpolation = INTERPOLATE_BILINEAR); void resize_to_po2(bool p_square = false, Interpolation p_interpolation = INTERPOLATE_BILINEAR);
void resize(int p_width, int p_height, Interpolation p_interpolation = INTERPOLATE_BILINEAR); void resize(int p_width, int p_height, Interpolation p_interpolation = INTERPOLATE_BILINEAR);
void shrink_x2(); void shrink_x2();
void expand_x2_hq2x();
bool is_size_po2() const; bool is_size_po2() const;
/** /**
* Crop the image to a specific size, if larger, then the image is filled by black * Crop the image to a specific size, if larger, then the image is filled by black
@ -246,7 +192,7 @@ public:
/** /**
* Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1) * Generate a mipmap to an image (creates an image 1/4 the size, with averaging of 4->1)
*/ */
Error generate_mipmaps(bool p_renormalize = false); int generate_mipmaps(bool p_renormalize = false);
void clear_mipmaps(); void clear_mipmaps();
void normalize(); //for normal maps void normalize(); //for normal maps
@ -255,7 +201,7 @@ public:
* Create a new image of a given size and format. Current image will be lost * Create a new image of a given size and format. Current image will be lost
*/ */
void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format); void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const PoolVector<uint8_t> &p_data); void create(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
void create(const char **p_xpm); void create(const char **p_xpm);
/** /**
@ -263,25 +209,13 @@ public:
*/ */
bool empty() const; bool empty() const;
PoolVector<uint8_t> get_data() const; Vector<uint8_t> get_data() const;
const uint8_t* datar() const;
uint8_t* dataw();
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;
/**
* create an empty image
*/
Image(); Image();
/**
* create an empty image of a specific size and format
*/
Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format); Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format);
/** Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const Vector<uint8_t> &p_data);
* import an image of a specific size and format from a pointer
*/
Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const PoolVector<uint8_t> &p_data);
enum AlphaMode { enum AlphaMode {
ALPHA_NONE, ALPHA_NONE,
@ -311,8 +245,6 @@ public:
COMPRESS_MAX, COMPRESS_MAX,
}; };
Error compress(CompressMode p_mode = COMPRESS_S3TC, CompressSource p_source = COMPRESS_SOURCE_GENERIC, float p_lossy_quality = 0.7);
Error decompress();
bool is_compressed() const; bool is_compressed() const;
void fix_alpha_edges(); void fix_alpha_edges();
@ -322,10 +254,10 @@ public:
Ref<Image> rgbe_to_srgb(); Ref<Image> rgbe_to_srgb();
void bumpmap_to_normalmap(float bump_scale = 1.0); 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); void blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Vector2 &p_dest);
void blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest); void blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Vector2 &p_dest);
void blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest); void blend_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Vector2 &p_dest);
void blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Point2 &p_dest); void blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2 &p_src_rect, const Vector2 &p_dest);
void fill(const Color &p_color); void fill(const Color &p_color);
void fill_rect(const Rect2 &p_rect, const Color &p_color); void fill_rect(const Rect2 &p_rect, const Color &p_color);
@ -336,13 +268,6 @@ public:
static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource)); static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource));
static String get_format_name(Format p_format); 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);
Error load_tga_from_buffer(const PoolVector<uint8_t> &p_array);
Error load_bmp_from_buffer(const PoolVector<uint8_t> &p_array);
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
Image(const char **p_xpm); Image(const char **p_xpm);
virtual Ref<Resource> duplicate(bool p_subresources = false) const; virtual Ref<Resource> duplicate(bool p_subresources = false) const;
@ -363,13 +288,14 @@ public:
DetectChannels get_detected_channels(); DetectChannels get_detected_channels();
void optimize_channels(); void optimize_channels();
Color get_pixelv(const Point2 &p_src) const; Color get_pixelv(const Vector2 &p_src) const;
Color get_pixel(int p_x, int p_y) const; Color get_pixel(int p_x, int p_y) const;
void set_pixelv(const Point2 &p_dst, const Color &p_color); void set_pixelv(const Vector2 &p_dst, const Color &p_color);
void set_pixel(int p_x, int p_y, const Color &p_color); void set_pixel(int p_x, int p_y, const Color &p_color);
void copy_internals_from(const Ref<Image> &p_image) { void copy_internals_from(const Ref<Image> &p_image) {
ERR_FAIL_COND_MSG(p_image.is_null(), "It's not a reference to a valid Image object."); ERR_FAIL_COND(p_image.is_null());
format = p_image->format; format = p_image->format;
width = p_image->width; width = p_image->width;
height = p_image->height; height = p_image->height;
@ -380,10 +306,4 @@ public:
~Image(); ~Image();
}; };
VARIANT_ENUM_CAST(Image::Format)
VARIANT_ENUM_CAST(Image::Interpolation)
VARIANT_ENUM_CAST(Image::CompressMode)
VARIANT_ENUM_CAST(Image::CompressSource)
VARIANT_ENUM_CAST(Image::AlphaMode)
#endif #endif

View File

@ -7,6 +7,8 @@
#include "core/containers/vector.h" #include "core/containers/vector.h"
//TODO move to wchar_t!
class String { class String {
public: public:
void push_back(const char element); void push_back(const char element);