godot/core/io/image.cpp

/**************************************************************************/
/*  image.cpp                                                             */
/**************************************************************************/
/*                         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.                 */
/**************************************************************************/

#include "image.h"

#include "core/config/project_settings.h"
#include "core/error/error_list.h"
#include "core/error/error_macros.h"
#include "core/io/image_loader.h"
#include "core/io/resource_loader.h"
#include "core/math/math_funcs.h"
#include "core/string/print_string.h"
#include "core/templates/hash_map.h"
#include "core/variant/dictionary.h"

#include <stdio.h>
#include <cmath>

const char *Image::format_names[Image::FORMAT_MAX] =;

SavePNGFunc Image::save_png_func =;
SaveJPGFunc Image::save_jpg_func =;
SaveEXRFunc Image::save_exr_func =;

SavePNGBufferFunc Image::save_png_buffer_func =;
SaveEXRBufferFunc Image::save_exr_buffer_func =;
SaveJPGBufferFunc Image::save_jpg_buffer_func =;

SaveWebPFunc Image::save_webp_func =;
SaveWebPBufferFunc Image::save_webp_buffer_func =;

void Image::_put_pixelb(int p_x, int p_y, uint32_t p_pixel_size, uint8_t *p_data, const uint8_t *p_pixel) {}

void Image::_get_pixelb(int p_x, int p_y, uint32_t p_pixel_size, const uint8_t *p_data, uint8_t *p_pixel) {}

int Image::get_format_pixel_size(Format p_format) {}

void Image::get_format_min_pixel_size(Format p_format, int &r_w, int &r_h) {}

int Image::get_format_pixel_rshift(Format p_format) {}

int Image::get_format_block_size(Format p_format) {}

void Image::_get_mipmap_offset_and_size(int p_mipmap, int64_t &r_offset, int &r_width, int &r_height) const {}

int64_t Image::get_mipmap_offset(int p_mipmap) const {}

void Image::get_mipmap_offset_and_size(int p_mipmap, int64_t &r_ofs, int64_t &r_size) const {}

void Image::get_mipmap_offset_size_and_dimensions(int p_mipmap, int64_t &r_ofs, int64_t &r_size, int &w, int &h) const {}

Image::Image3DValidateError Image::validate_3d_image(Image::Format p_format, int p_width, int p_height, int p_depth, bool p_mipmaps, const Vector<Ref<Image>> &p_images) {}

String Image::get_3d_image_validation_error_text(Image3DValidateError p_error) {}

int Image::get_width() const {}

int Image::get_height() const {}

Size2i Image::get_size() const {}

bool Image::has_mipmaps() const {}

int Image::get_mipmap_count() const {}

//using template generates perfectly optimized code due to constant expression reduction and unused variable removal present in all compilers
template <uint32_t read_bytes, bool read_alpha, uint32_t write_bytes, bool write_alpha, bool read_gray, bool write_gray>
static void _convert(int p_width, int p_height, const uint8_t *p_src, uint8_t *p_dst) {}

template <typename T, uint32_t read_channels, uint32_t write_channels, T def_zero, T def_one>
static void _convert_fast(int p_width, int p_height, const T *p_src, T *p_dst) {}

static bool _are_formats_compatible(Image::Format p_format0, Image::Format p_format1) {}

void Image::convert(Format p_new_format) {}

Image::Format Image::get_format() const {}

static double _bicubic_interp_kernel(double x) {}

template <int CC, typename T>
static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {}

template <int CC, typename T>
static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {}

template <int CC, typename T>
static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {}

#define LANCZOS_TYPE

static float _lanczos(float p_x) {}

template <int CC, typename T>
static void _scale_lanczos(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {}

static void _overlay(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, float p_alpha, uint32_t p_width, uint32_t p_height, uint32_t p_pixel_size) {}

bool Image::is_size_po2() const {}

void Image::resize_to_po2(bool p_square, Interpolation p_interpolation) {}

void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {}

void Image::crop_from_point(int p_x, int p_y, int p_width, int p_height) {}

void Image::crop(int p_width, int p_height) {}

void Image::rotate_90(ClockDirection p_direction) {}

void Image::rotate_180() {}

void Image::flip_y() {}

void Image::flip_x() {}

/// Get mipmap size and offset.
int64_t Image::_get_dst_image_size(int p_width, int p_height, Format p_format, int &r_mipmaps, int p_mipmaps, int *r_mm_width, int *r_mm_height) {}

bool Image::_can_modify(Format p_format) const {}

template <typename Component, int CC, bool renormalize,
		void (*average_func)(Component &, const Component &, const Component &, const Component &, const Component &),
		void (*renormalize_func)(Component *)>
static void _generate_po2_mipmap(const Component *p_src, Component *p_dst, uint32_t p_width, uint32_t p_height) {}

void Image::shrink_x2() {}

void Image::normalize() {}

Error Image::generate_mipmaps(bool p_renormalize) {}

Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, const Ref<Image> &p_normal_map) {}

void Image::clear_mipmaps() {}

bool Image::is_empty() const {}

Vector<uint8_t> Image::get_data() const {}

Ref<Image> Image::create_empty(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {}

Ref<Image> Image::create_from_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {}

void Image::set_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {}

void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {}

void Image::initialize_data(int p_width, int p_height, bool p_use_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {}

void Image::initialize_data(const char **p_xpm) {}
#define DETECT_ALPHA_MAX_THRESHOLD
#define DETECT_ALPHA_MIN_THRESHOLD

#define DETECT_ALPHA(m_value)

#define DETECT_NON_ALPHA(m_value)

bool Image::is_invisible() const {}

Image::AlphaMode Image::detect_alpha() const {}

Error Image::load(const String &p_path) {}

Ref<Image> Image::load_from_file(const String &p_path) {}

Error Image::save_png(const String &p_path) const {}

Error Image::save_jpg(const String &p_path, float p_quality) const {}

Vector<uint8_t> Image::save_png_to_buffer() const {}

Vector<uint8_t> Image::save_jpg_to_buffer(float p_quality) const {}

Error Image::save_exr(const String &p_path, bool p_grayscale) const {}

Vector<uint8_t> Image::save_exr_to_buffer(bool p_grayscale) const {}

Error Image::save_webp(const String &p_path, const bool p_lossy, const float p_quality) const {}

Vector<uint8_t> Image::save_webp_to_buffer(const bool p_lossy, const float p_quality) const {}

int64_t Image::get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps) {}

int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format) {}

Size2i Image::get_image_mipmap_size(int p_width, int p_height, Format p_format, int p_mipmap) {}

int64_t Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap) {}

int64_t Image::get_image_mipmap_offset_and_dimensions(int p_width, int p_height, Format p_format, int p_mipmap, int &r_w, int &r_h) {}

bool Image::is_compressed() const {}

bool Image::is_format_compressed(Format p_format) {}

Error Image::decompress() {}

Error Image::compress(CompressMode p_mode, CompressSource p_source, ASTCFormat p_astc_format) {}

Error Image::compress_from_channels(CompressMode p_mode, UsedChannels p_channels, ASTCFormat p_astc_format) {}

Image::Image(const char **p_xpm) {}

Image::Image(int p_width, int p_height, bool p_use_mipmaps, Format p_format) {}

Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const Vector<uint8_t> &p_data) {}

Rect2i Image::get_used_rect() const {}

Ref<Image> Image::get_region(const Rect2i &p_region) const {}

void Image::_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 {}

void Image::blit_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest) {}

void Image::blit_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2i &p_src_rect, const Point2i &p_dest) {}

void Image::blend_rect(const Ref<Image> &p_src, const Rect2i &p_src_rect, const Point2i &p_dest) {}

void Image::blend_rect_mask(const Ref<Image> &p_src, const Ref<Image> &p_mask, const Rect2i &p_src_rect, const Point2i &p_dest) {}

// Repeats `p_pixel` `p_count` times in consecutive memory.
// Results in the original pixel and `p_count - 1` subsequent copies of it.
void Image::_repeat_pixel_over_subsequent_memory(uint8_t *p_pixel, int p_pixel_size, int p_count) {}

void Image::fill(const Color &p_color) {}

void Image::fill_rect(const Rect2i &p_rect, const Color &p_color) {}

ImageMemLoadFunc Image::_png_mem_loader_func =;
ImageMemLoadFunc Image::_png_mem_unpacker_func =;
ImageMemLoadFunc Image::_jpg_mem_loader_func =;
ImageMemLoadFunc Image::_webp_mem_loader_func =;
ImageMemLoadFunc Image::_tga_mem_loader_func =;
ImageMemLoadFunc Image::_bmp_mem_loader_func =;
ScalableImageMemLoadFunc Image::_svg_scalable_mem_loader_func =;
ImageMemLoadFunc Image::_ktx_mem_loader_func =;

void (*Image::_image_compress_bc_func)(Image *, Image::UsedChannels) =;
void (*Image::_image_compress_bptc_func)(Image *, Image::UsedChannels) =;
void (*Image::_image_compress_etc1_func)(Image *) =;
void (*Image::_image_compress_etc2_func)(Image *, Image::UsedChannels) =;
void (*Image::_image_compress_astc_func)(Image *, Image::ASTCFormat) =;
Error (*Image::_image_compress_bptc_rd_func)(Image *, Image::UsedChannels) =;
void (*Image::_image_decompress_bc)(Image *) =;
void (*Image::_image_decompress_bptc)(Image *) =;
void (*Image::_image_decompress_etc1)(Image *) =;
void (*Image::_image_decompress_etc2)(Image *) =;
void (*Image::_image_decompress_astc)(Image *) =;

Vector<uint8_t> (*Image::webp_lossy_packer)(const Ref<Image> &, float) =;
Vector<uint8_t> (*Image::webp_lossless_packer)(const Ref<Image> &) =;
Ref<Image> (*Image::webp_unpacker)(const Vector<uint8_t> &) =;
Vector<uint8_t> (*Image::png_packer)(const Ref<Image> &) =;
Ref<Image> (*Image::png_unpacker)(const Vector<uint8_t> &) =;
Vector<uint8_t> (*Image::basis_universal_packer)(const Ref<Image> &, Image::UsedChannels) =;
Ref<Image> (*Image::basis_universal_unpacker)(const Vector<uint8_t> &) =;
Ref<Image> (*Image::basis_universal_unpacker_ptr)(const uint8_t *, int) =;

void Image::_set_data(const Dictionary &p_data) {}

Dictionary Image::_get_data() const {}

Color Image::get_pixelv(const Point2i &p_point) const {}

Color Image::_get_color_at_ofs(const uint8_t *ptr, uint32_t ofs) const {}

void Image::_set_color_at_ofs(uint8_t *ptr, uint32_t ofs, const Color &p_color) {}

Color Image::get_pixel(int p_x, int p_y) const {}

void Image::set_pixelv(const Point2i &p_point, const Color &p_color) {}

void Image::set_pixel(int p_x, int p_y, const Color &p_color) {}

const uint8_t *Image::ptr() const {}

uint8_t *Image::ptrw() {}

int64_t Image::get_data_size() const {}

void Image::adjust_bcs(float p_brightness, float p_contrast, float p_saturation) {}

Image::UsedChannels Image::detect_used_channels(CompressSource p_source) const {}

void Image::optimize_channels() {}

void Image::_bind_methods() {}

void Image::set_compress_bc_func(void (*p_compress_func)(Image *, UsedChannels)) {}

void Image::set_compress_bptc_func(void (*p_compress_func)(Image *, UsedChannels)) {}

void Image::normal_map_to_xy() {}

Ref<Image> Image::rgbe_to_srgb() {}

Ref<Image> Image::get_image_from_mipmap(int p_mipmap) const {}

void Image::bump_map_to_normal_map(float bump_scale) {}

bool Image::detect_signed(bool p_include_mips) const {}

void Image::srgb_to_linear() {}

void Image::linear_to_srgb() {}

void Image::premultiply_alpha() {}

void Image::fix_alpha_edges() {}

String Image::get_format_name(Format p_format) {}

Error Image::load_png_from_buffer(const Vector<uint8_t> &p_array) {}

Error Image::load_jpg_from_buffer(const Vector<uint8_t> &p_array) {}

Error Image::load_webp_from_buffer(const Vector<uint8_t> &p_array) {}

Error Image::load_tga_from_buffer(const Vector<uint8_t> &p_array) {}

Error Image::load_bmp_from_buffer(const Vector<uint8_t> &p_array) {}

Error Image::load_svg_from_buffer(const Vector<uint8_t> &p_array, float scale) {}

Error Image::load_svg_from_string(const String &p_svg_str, float scale) {}

Error Image::load_ktx_from_buffer(const Vector<uint8_t> &p_array) {}

void Image::convert_rg_to_ra_rgba8() {}

void Image::convert_ra_rgba8_to_rg() {}

void Image::convert_rgba8_to_bgra8() {}

Error Image::_load_from_buffer(const Vector<uint8_t> &p_array, ImageMemLoadFunc p_loader) {}

void Image::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) {}

void Image::average_4_float(float &p_out, const float &p_a, const float &p_b, const float &p_c, const float &p_d) {}

void Image::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) {}

void Image::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) {}

void Image::renormalize_uint8(uint8_t *p_rgb) {}

void Image::renormalize_float(float *p_rgb) {}

void Image::renormalize_half(uint16_t *p_rgb) {}

void Image::renormalize_rgbe9995(uint32_t *p_rgb) {}

Image::Image(const uint8_t *p_mem_png_jpg, int p_len) {}

Ref<Resource> Image::duplicate(bool p_subresources) const {}

void Image::set_as_black() {}

Dictionary Image::compute_image_metrics(const Ref<Image> p_compared_image, bool p_luma_metric) {}