@ -28,15 +28,14 @@
/*************************************************************************/
# include "image.h"
# include "hash_map.h"
# include "core/io/image_loader.h"
# include "core/os/copymem.h"
# include "hash_map.h"
# include "hq2x.h"
# include "print_string.h"
# include <stdio.h>
const char * Image : : format_names [ Image : : FORMAT_MAX ] = {
" Lum8 " , //luminance
" LumAlpha8 " , //luminance-alpha
@ -80,10 +79,8 @@ const char* Image::format_names[Image::FORMAT_MAX]={
SavePNGFunc Image : : save_png_func = NULL ;
void Image : : _put_pixelb ( int p_x , int p_y , uint32_t p_pixelsize , uint8_t * p_dst , const uint8_t * p_src ) {
uint32_t ofs = ( p_y * width + p_x ) * p_pixelsize ;
for ( uint32_t i = 0 ; i < p_pixelsize ; i + + ) {
@ -98,60 +95,73 @@ void Image::_get_pixelb(int p_x,int p_y, uint32_t p_pixelsize,const uint8_t *p_
for ( uint32_t i = 0 ; i < p_pixelsize ; i + + ) {
p_dst [ ofs ] = p_src [ ofs + i ] ;
}
}
int Image : : get_format_pixel_size ( Format p_format ) {
switch ( p_format ) {
case FORMAT_L8 : return 1 ; //luminance
case FORMAT_LA8 : return 2 ; //luminance-alpha
case FORMAT_L8 :
return 1 ; //luminance
case FORMAT_LA8 :
return 2 ; //luminance-alpha
case FORMAT_R8 : return 1 ;
case FORMAT_RG8 : return 2 ;
case FORMAT_RGB8 : return 3 ;
case FORMAT_RGBA8 : return 4 ;
case FORMAT_RGB565 : return 2 ; //16 bit
case FORMAT_RGB565 :
return 2 ; //16 bit
case FORMAT_RGBA4444 : return 2 ;
case FORMAT_RGBA5551 : return 2 ;
case FORMAT_RF : return 4 ; //float
case FORMAT_RF :
return 4 ; //float
case FORMAT_RGF : return 8 ;
case FORMAT_RGBF : return 12 ;
case FORMAT_RGBAF : return 16 ;
case FORMAT_RH : return 2 ; //half float
case FORMAT_RH :
return 2 ; //half float
case FORMAT_RGH : return 4 ;
case FORMAT_RGBH : return 8 ;
case FORMAT_RGBAH : return 12 ;
case FORMAT_DXT1 : return 1 ; //s3tc bc1
case FORMAT_DXT3 : return 1 ; //bc2
case FORMAT_DXT5 : return 1 ; //bc3
case FORMAT_ATI1 : return 1 ; //bc4
case FORMAT_ATI2 : return 1 ; //bc5
case FORMAT_BPTC_RGBA : return 1 ; //btpc bc6h
case FORMAT_BPTC_RGBF : return 1 ; //float /
case FORMAT_BPTC_RGBFU : return 1 ; //unsigned float
case FORMAT_PVRTC2 : return 1 ; //pvrtc
case FORMAT_DXT1 :
return 1 ; //s3tc bc1
case FORMAT_DXT3 :
return 1 ; //bc2
case FORMAT_DXT5 :
return 1 ; //bc3
case FORMAT_ATI1 :
return 1 ; //bc4
case FORMAT_ATI2 :
return 1 ; //bc5
case FORMAT_BPTC_RGBA :
return 1 ; //btpc bc6h
case FORMAT_BPTC_RGBF :
return 1 ; //float /
case FORMAT_BPTC_RGBFU :
return 1 ; //unsigned float
case FORMAT_PVRTC2 :
return 1 ; //pvrtc
case FORMAT_PVRTC2A : return 1 ;
case FORMAT_PVRTC4 : return 1 ;
case FORMAT_PVRTC4A : return 1 ;
case FORMAT_ETC : return 1 ; //etc1
case FORMAT_ETC2_R11 : return 1 ; //etc2
case FORMAT_ETC2_R11S : return 1 ; //signed: return 1; NOT srgb.
case FORMAT_ETC :
return 1 ; //etc1
case FORMAT_ETC2_R11 :
return 1 ; //etc2
case FORMAT_ETC2_R11S :
return 1 ; //signed: return 1; NOT srgb.
case FORMAT_ETC2_RG11 : return 1 ;
case FORMAT_ETC2_RG11S : return 1 ;
case FORMAT_ETC2_RGB8 : return 1 ;
case FORMAT_ETC2_RGBA8 : return 1 ;
case FORMAT_ETC2_RGB8A1 : return 1 ;
case FORMAT_MAX : { }
case FORMAT_MAX : {
}
}
return 0 ;
}
void Image : : get_format_min_pixel_size ( Format p_format , int & r_w , int & r_h ) {
switch ( p_format ) {
case FORMAT_DXT1 : //s3tc bc1
case FORMAT_DXT3 : //bc2
@ -204,10 +214,8 @@ void Image::get_format_min_pixel_size(Format p_format,int &r_w, int &r_h) {
r_h = 1 ;
} break ;
}
}
int Image : : get_format_pixel_rshift ( Format p_format ) {
if ( p_format = = FORMAT_DXT1 | | p_format = = FORMAT_ATI1 | | p_format = = FORMAT_PVRTC4 | | p_format = = FORMAT_PVRTC4A | | p_format = = FORMAT_ETC | | p_format = = FORMAT_ETC2_R11 | | p_format = = FORMAT_ETC2_R11S | | p_format = = FORMAT_ETC2_RGB8 | | p_format = = FORMAT_ETC2_RGB8A1 )
@ -218,7 +226,6 @@ int Image::get_format_pixel_rshift(Format p_format) {
return 0 ;
}
void Image : : _get_mipmap_offset_and_size ( int p_mipmap , int & r_offset , int & r_width , int & r_height ) const {
int w = width ;
@ -260,19 +267,16 @@ void Image::get_mipmap_offset_and_size(int p_mipmap,int &r_ofs, int &r_size) con
_get_mipmap_offset_and_size ( p_mipmap + 1 , ofs2 , w , h ) ;
r_ofs = ofs ;
r_size = ofs2 - ofs ;
}
void Image : : get_mipmap_offset_size_and_dimensions ( int p_mipmap , int & r_ofs , int & r_size , int & w , int & h ) const {
int ofs ;
_get_mipmap_offset_and_size ( p_mipmap , ofs , w , h ) ;
int ofs2 , w2 , h2 ;
_get_mipmap_offset_and_size ( p_mipmap + 1 , ofs2 , w2 , h2 ) ;
r_ofs = ofs ;
r_size = ofs2 - ofs ;
}
int Image : : get_width ( ) const {
@ -298,13 +302,10 @@ int Image::get_mipmap_count() const {
return 0 ;
}
//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 ) {
for ( int y = 0 ; y < p_height ; y + + ) {
for ( int x = 0 ; x < p_width ; x + + ) {
@ -341,10 +342,8 @@ static void _convert( int p_width,int p_height,const uint8_t* p_src,uint8_t* p_d
if ( write_alpha ) {
wofs [ write_bytes ] = rgba [ 3 ] ;
}
}
}
}
void Image : : convert ( Format p_new_format ) {
@ -355,14 +354,12 @@ void Image::convert( Format p_new_format ){
if ( p_new_format = = format )
return ;
if ( format > = FORMAT_RGB565 | | p_new_format > = FORMAT_RGB565 ) {
ERR_EXPLAIN ( " Cannot convert to <-> from non byte formats. " ) ;
ERR_FAIL ( ) ;
}
Image new_img ( width , height , 0 , p_new_format ) ;
//int len=data.size();
@ -407,10 +404,8 @@ void Image::convert( Format p_new_format ){
case FORMAT_RGBA8 | ( FORMAT_R8 < < 8 ) : _convert < 3 , true , 1 , false , false , false > ( width , height , rptr , wptr ) ; break ;
case FORMAT_RGBA8 | ( FORMAT_RG8 < < 8 ) : _convert < 3 , true , 2 , false , false , false > ( width , height , rptr , wptr ) ; break ;
case FORMAT_RGBA8 | ( FORMAT_RGB8 < < 8 ) : _convert < 3 , true , 3 , false , false , false > ( width , height , rptr , wptr ) ; break ;
}
r = PoolVector < uint8_t > : : Read ( ) ;
w = PoolVector < uint8_t > : : Write ( ) ;
@ -422,7 +417,6 @@ void Image::convert( Format p_new_format ){
if ( gen_mipmaps )
generate_mipmaps ( ) ;
}
Image : : Format Image : : get_format ( ) const {
@ -441,14 +435,12 @@ static double _bicubic_interp_kernel( double x ) {
else if ( x < 2 )
bc = ( ( - 0.5 * x + 2.5 ) * x - 4 ) * x + 2 ;
return bc ;
}
template < int CC >
static void _scale_cubic ( const uint8_t * p_src , uint8_t * p_dst , uint32_t p_src_width , uint32_t p_src_height , uint32_t p_dst_width , uint32_t p_dst_height ) {
// get source image size
int width = p_src_width ;
int height = p_src_height ;
@ -484,8 +476,6 @@ static void _scale_cubic(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_wi
color [ i ] = 0 ;
}
for ( int n = - 1 ; n < 3 ; n + + ) {
// get Y cooefficient
k1 = _bicubic_interp_kernel ( dy - ( double ) n ) ;
@ -523,9 +513,6 @@ static void _scale_cubic(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_wi
}
}
template < int CC >
static void _scale_bilinear ( const uint8_t * p_src , uint8_t * p_dst , uint32_t p_src_width , uint32_t p_src_height , uint32_t p_dst_width , uint32_t p_dst_height ) {
@ -542,7 +529,6 @@ static void _scale_bilinear(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src
uint32_t src_yofs_frac = src_yofs_up_fp & FRAC_MASK ;
uint32_t src_yofs_up = src_yofs_up_fp > > FRAC_BITS ;
uint32_t src_yofs_down = ( i + 1 ) * p_src_height / p_dst_height ;
if ( src_yofs_down > = p_src_height )
src_yofs_down = p_src_height - 1 ;
@ -582,11 +568,9 @@ static void _scale_bilinear(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src
}
}
template < int CC >
static void _scale_nearest ( const uint8_t * p_src , uint8_t * p_dst , uint32_t p_src_width , uint32_t p_src_height , uint32_t p_dst_width , uint32_t p_dst_height ) {
for ( uint32_t i = 0 ; i < p_dst_height ; i + + ) {
uint32_t src_yofs = i * p_src_height / p_dst_height ;
@ -606,7 +590,6 @@ static void _scale_nearest(const uint8_t* p_src, uint8_t* p_dst, uint32_t p_src_
}
}
void Image : : resize_to_po2 ( bool p_square ) {
if ( ! _can_modify ( format ) ) {
@ -634,7 +617,6 @@ Image Image::resized( int p_width, int p_height, int p_interpolation ) {
return ret ;
} ;
void Image : : resize ( int p_width , int p_height , Interpolation p_interpolation ) {
if ( ! _can_modify ( format ) ) {
@ -647,7 +629,6 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
ERR_FAIL_COND ( p_width > MAX_WIDTH ) ;
ERR_FAIL_COND ( p_height > MAX_HEIGHT ) ;
if ( p_width = = width & & p_height = = height )
return ;
@ -659,7 +640,6 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
PoolVector < uint8_t > : : Write w = dst . data . write ( ) ;
unsigned char * w_ptr = w . ptr ( ) ;
switch ( p_interpolation ) {
case INTERPOLATE_NEAREST : {
@ -691,8 +671,6 @@ void Image::resize( int p_width, int p_height, Interpolation p_interpolation ) {
}
} break ;
}
r = PoolVector < uint8_t > : : Read ( ) ;
@ -741,17 +719,14 @@ void Image::crop( int p_width, int p_height ) {
_get_pixelb ( x , y , pixel_size , r . ptr ( ) , pdata ) ;
}
dst . _put_pixelb ( x , y , pixel_size , w . ptr ( ) , pdata ) ;
}
}
}
if ( mipmaps > 0 )
dst . generate_mipmaps ( ) ;
* this = dst ;
}
void Image : : flip_y ( ) {
@ -766,8 +741,6 @@ void Image::flip_y() {
if ( gm )
clear_mipmaps ( ) ;
{
PoolVector < uint8_t > : : Write w = data . write ( ) ;
uint8_t up [ 16 ] ;
@ -778,21 +751,17 @@ void Image::flip_y() {
for ( int x = 0 ; x < width ; x + + ) {
_get_pixelb ( x , y , pixel_size , w . ptr ( ) , up ) ;
_get_pixelb ( x , height - y - 1 , pixel_size , w . ptr ( ) , down ) ;
_put_pixelb ( x , height - y - 1 , pixel_size , w . ptr ( ) , up ) ;
_put_pixelb ( x , y , pixel_size , w . ptr ( ) , down ) ;
}
}
}
if ( gm )
generate_mipmaps ( ) ;
}
void Image : : flip_x ( ) {
@ -806,7 +775,6 @@ void Image::flip_x() {
if ( gm )
clear_mipmaps ( ) ;
{
PoolVector < uint8_t > : : Write w = data . write ( ) ;
uint8_t up [ 16 ] ;
@ -817,20 +785,17 @@ void Image::flip_x() {
for ( int x = 0 ; x < width ; x + + ) {
_get_pixelb ( x , y , pixel_size , w . ptr ( ) , up ) ;
_get_pixelb ( width - x - 1 , y , pixel_size , w . ptr ( ) , down ) ;
_put_pixelb ( width - x - 1 , y , pixel_size , w . ptr ( ) , up ) ;
_put_pixelb ( x , y , pixel_size , w . ptr ( ) , down ) ;
}
}
}
if ( gm )
generate_mipmaps ( ) ;
}
int Image : : _get_dst_image_size ( int p_width , int p_height , Format p_format , int & r_mipmaps , int p_mipmaps ) {
@ -892,7 +857,6 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
uint8_t * dst_ptr = & p_dst [ i * dst_w * CC ] ;
uint32_t count = dst_w ;
while ( count - - ) {
for ( int j = 0 ; j < CC ; j + + ) {
@ -903,7 +867,6 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
val + = rdown_ptr [ j ] ;
val + = rdown_ptr [ j + CC ] ;
dst_ptr [ j ] = val > > 2 ;
}
dst_ptr + = CC ;
@ -913,7 +876,6 @@ static void _generate_po2_mipmap(const uint8_t* p_src, uint8_t* p_dst, uint32_t
}
}
void Image : : expand_x2_hq2x ( ) {
ERR_FAIL_COND ( ! _can_modify ( format ) ) ;
@ -935,29 +897,24 @@ void Image::expand_x2_hq2x() {
PoolVector < uint8_t > : : Write w = dest . write ( ) ;
hq2x_resize ( ( const uint32_t * ) r . ptr ( ) , width , height , ( uint32_t * ) w . ptr ( ) ) ;
}
width * = 2 ;
height * = 2 ;
data = dest ;
if ( current ! = FORMAT_RGBA8 )
convert ( current ) ;
if ( mipmaps ) {
generate_mipmaps ( ) ;
}
}
void Image : : shrink_x2 ( ) {
ERR_FAIL_COND ( data . size ( ) = = 0 ) ;
if ( mipmaps ) {
//just use the lower mipmap as base and copy all
@ -968,7 +925,6 @@ void Image::shrink_x2() {
int new_size = data . size ( ) - ofs ;
new_img . resize ( new_size ) ;
{
PoolVector < uint8_t > : : Write w = new_img . write ( ) ;
PoolVector < uint8_t > : : Read r = data . read ( ) ;
@ -1007,7 +963,6 @@ void Image::shrink_x2() {
width / = 2 ;
height / = 2 ;
data = new_img ;
}
}
@ -1016,7 +971,6 @@ Error Image::generate_mipmaps() {
if ( ! _can_modify ( format ) ) {
ERR_EXPLAIN ( " Cannot generate mipmaps in indexed, compressed or custom image formats. " ) ;
ERR_FAIL_V ( ERR_UNAVAILABLE ) ;
}
ERR_FAIL_COND_V ( width = = 0 | | height = = 0 , ERR_UNCONFIGURED ) ;
@ -1038,11 +992,9 @@ Error Image::generate_mipmaps() {
for ( int i = 1 ; i < mmcount ; i + + ) {
int ofs , w , h ;
_get_mipmap_offset_and_size ( i , ofs , w , h ) ;
switch ( format ) {
case FORMAT_L8 :
@ -1059,7 +1011,6 @@ Error Image::generate_mipmaps() {
prev_h = h ;
}
} else {
//use slow code..
@ -1070,7 +1021,6 @@ Error Image::generate_mipmaps() {
for ( int i = 1 ; i < mmcount ; i + + ) {
int ofs , w , h ;
_get_mipmap_offset_and_size ( i , ofs , w , h ) ;
@ -1089,9 +1039,6 @@ Error Image::generate_mipmaps() {
prev_w = w ;
prev_h = h ;
}
}
mipmaps = true ;
@ -1112,10 +1059,8 @@ void Image::clear_mipmaps() {
data . resize ( ofs ) ;
mipmaps = false ;
}
bool Image : : empty ( ) const {
return ( data . size ( ) = = 0 ) ;
@ -1128,7 +1073,6 @@ PoolVector<uint8_t> Image::get_data() const {
void Image : : create ( int p_width , int p_height , bool p_use_mipmaps , Format p_format ) {
int mm = 0 ;
int size = _get_dst_image_size ( p_width , p_height , p_format , mm , p_use_mipmaps ? - 1 : 0 ) ;
data . resize ( size ) ;
@ -1141,8 +1085,6 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps,Format p_format
height = p_height ;
mipmaps = p_use_mipmaps ;
format = p_format ;
}
void Image : : create ( int p_width , int p_height , bool p_use_mipmaps , Format p_format , const PoolVector < uint8_t > & p_data ) {
@ -1165,10 +1107,8 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma
mipmaps = p_use_mipmaps ;
}
void Image : : create ( const char * * p_xpm ) {
int size_width , size_height ;
int pixelchars = 0 ;
mipmaps = false ;
@ -1193,7 +1133,6 @@ void Image::create( const char ** p_xpm ) {
const char * line_ptr = p_xpm [ line ] ;
switch ( status ) {
case READING_HEADER : {
@ -1262,7 +1201,6 @@ void Image::create( const char ** p_xpm ) {
case 4 : col_b = v < < 4 ; break ;
case 5 : col_b | = v ; break ;
} ;
}
// magenta mask
@ -1274,7 +1212,6 @@ void Image::create( const char ** p_xpm ) {
colormap [ colorstring ] = Color ( col_r / 255.0 , col_g / 255.0 , col_b / 255.0 , 1.0 ) ;
}
}
}
if ( line = = colormap_size ) {
@ -1301,7 +1238,6 @@ void Image::create( const char ** p_xpm ) {
pixel [ i ] = CLAMP ( ( * colorptr ) [ i ] * 255 , 0 , 255 ) ;
}
_put_pixelb ( x , y , pixel_size , w . ptr ( ) , pixel ) ;
}
if ( y = = ( size_height - 1 ) )
@ -1338,7 +1274,6 @@ void Image::create( const char ** p_xpm ) {
} \
}
bool Image : : is_invisible ( ) const {
if ( format = = FORMAT_L8 | |
@ -1350,7 +1285,6 @@ bool Image::is_invisible() const {
if ( len = = 0 )
return true ;
int w , h ;
_get_mipmap_offset_and_size ( 1 , len , w , h ) ;
@ -1363,7 +1297,6 @@ bool Image::is_invisible() const {
case FORMAT_LA8 : {
for ( int i = 0 ; i < ( len > > 1 ) ; i + + ) {
DETECT_NON_ALPHA ( data_ptr [ ( i < < 1 ) + 1 ] ) ;
}
@ -1391,7 +1324,6 @@ bool Image::is_invisible() const {
Image : : AlphaMode Image : : detect_alpha ( ) const {
int len = data . size ( ) ;
if ( len = = 0 )
@ -1410,7 +1342,6 @@ Image::AlphaMode Image::detect_alpha() const {
case FORMAT_LA8 : {
for ( int i = 0 ; i < ( len > > 1 ) ; i + + ) {
DETECT_ALPHA ( data_ptr [ ( i < < 1 ) + 1 ] ) ;
}
@ -1438,7 +1369,6 @@ Image::AlphaMode Image::detect_alpha() const {
return ALPHA_BIT ;
else
return ALPHA_NONE ;
}
Error Image : : load ( const String & p_path ) {
@ -1464,14 +1394,10 @@ bool Image::operator==(const Image& p_image) const {
return r . ptr ( ) = = pr . ptr ( ) ;
}
int Image : : get_image_data_size ( int p_width , int p_height , Format p_format , int p_mipmaps ) {
int mm ;
return _get_dst_image_size ( p_width , p_height , p_format , mm , p_mipmaps ) ;
}
int Image : : get_image_required_mipmaps ( int p_width , int p_height , Format p_format ) {
@ -1479,16 +1405,10 @@ int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format
int mm ;
_get_dst_image_size ( p_width , p_height , p_format , mm , - 1 ) ;
return mm ;
}
Error Image : : _decompress_bc ( ) {
int wd = width , ht = height ;
if ( wd % 4 ! = 0 ) {
wd + = 4 - ( wd % 4 ) ;
@ -1497,7 +1417,6 @@ Error Image::_decompress_bc() {
ht + = 4 - ( ht % 4 ) ;
}
int mm ;
int size = _get_dst_image_size ( wd , ht , FORMAT_RGBA8 , mm ) ;
@ -1530,7 +1449,6 @@ Error Image::_decompress_bc() {
}
}
for ( int j = 0 ; j < len ; j + + ) {
const uint8_t * src = & r [ rofs + j * 8 ] ;
@ -1584,13 +1502,11 @@ Error Image::_decompress_bc() {
dst [ idx + 3 ] = table [ block & 0x3 ] [ 3 ] ;
block > > = 2 ;
}
}
rofs + = len * 8 ;
wofs + = wd * ht * 4 ;
wd / = 2 ;
ht / = 2 ;
@ -1609,7 +1525,6 @@ Error Image::_decompress_bc() {
}
}
for ( int j = 0 ; j < len ; j + + ) {
const uint8_t * src = & r [ rofs + j * 16 ] ;
@ -1630,7 +1545,6 @@ Error Image::_decompress_bc() {
ablock < < = 8 ;
ablock | = src [ 6 ] ;
uint16_t col_a = src [ 8 + 1 ] ;
col_a < < = 8 ;
col_a | = src [ 8 + 0 ] ;
@ -1677,13 +1591,11 @@ Error Image::_decompress_bc() {
block > > = 2 ;
ablock > > = 4 ;
}
}
rofs + = len * 16 ;
wofs + = wd * ht * 4 ;
wd / = 2 ;
ht / = 2 ;
@ -1702,8 +1614,6 @@ Error Image::_decompress_bc() {
}
}
for ( int j = 0 ; j < len ; j + + ) {
const uint8_t * src = & r [ rofs + j * 16 ] ;
@ -1745,10 +1655,8 @@ Error Image::_decompress_bc() {
atable [ 5 ] = ( int ( a_start ) * 0 + int ( a_end ) * 5 ) / 5 ;
atable [ 6 ] = 0 ;
atable [ 7 ] = 255 ;
}
uint16_t col_a = src [ 8 + 1 ] ;
col_a < < = 8 ;
col_a | = src [ 8 + 0 ] ;
@ -1772,7 +1680,6 @@ Error Image::_decompress_bc() {
table [ 3 ] [ 1 ] = ( int ( table [ 0 ] [ 1 ] ) + int ( table [ 1 ] [ 1 ] ) * 2 ) / 3 ;
table [ 3 ] [ 2 ] = ( int ( table [ 0 ] [ 2 ] ) + int ( table [ 1 ] [ 2 ] ) * 2 ) / 3 ;
uint32_t block = src [ 4 + 8 ] ;
block < < = 8 ;
block | = src [ 5 + 8 ] ;
@ -1785,8 +1692,6 @@ Error Image::_decompress_bc() {
int x = ( j % ( wd / 4 ) ) * 4 ;
int pixofs = ( y * wd + x ) * 4 ;
for ( int k = 0 ; k < 16 ; k + + ) {
uint8_t alpha = ablock & 0x7 ;
int idx = pixofs + ofs_table [ k ] ;
@ -1797,20 +1702,17 @@ Error Image::_decompress_bc() {
block > > = 2 ;
ablock > > = 3 ;
}
}
rofs + = len * 16 ;
wofs + = wd * ht * 4 ;
wd / = 2 ;
ht / = 2 ;
} break ;
default : { }
}
}
w = PoolVector < uint8_t > : : Write ( ) ;
@ -1832,7 +1734,6 @@ bool Image::is_compressed() const {
return format > = FORMAT_RGB565 ;
}
Image Image : : decompressed ( ) const {
Image img = * this ;
@ -1855,7 +1756,6 @@ Error Image::decompress() {
return OK ;
}
Error Image : : compress ( CompressMode p_mode ) {
switch ( p_mode ) {
@ -1892,7 +1792,6 @@ Error Image::compress(CompressMode p_mode) {
} break ;
}
return OK ;
}
@ -1914,7 +1813,6 @@ Image::Image(const char **p_xpm) {
create ( p_xpm ) ;
}
Image : : Image ( int p_width , int p_height , bool p_use_mipmaps , Format p_format ) {
width = 0 ;
@ -1923,7 +1821,6 @@ Image::Image(int p_width, int p_height,bool p_use_mipmaps, Format p_format) {
format = FORMAT_L8 ;
create ( p_width , p_height , p_use_mipmaps , p_format ) ;
}
Image : : Image ( int p_width , int p_height , bool p_mipmaps , Format p_format , const PoolVector < uint8_t > & p_data ) {
@ -1934,10 +1831,8 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const P
format = FORMAT_L8 ;
create ( p_width , p_height , p_mipmaps , p_format , p_data ) ;
}
Rect2 Image : : get_used_rect ( ) const {
if ( format ! = FORMAT_LA8 & & format ! = FORMAT_RGBA8 )
@ -1958,7 +1853,6 @@ Rect2 Image::get_used_rect() const {
for ( int j = 0 ; j < height ; j + + ) {
for ( int i = 0 ; i < width ; i + + ) {
bool opaque = rptr [ ( j * width + i ) * ps + ( ps - 1 ) ] > 2 ;
if ( ! opaque )
continue ;
@ -1977,10 +1871,8 @@ Rect2 Image::get_used_rect() const {
return Rect2 ( ) ;
else
return Rect2 ( minx , miny , maxx - minx + 1 , maxy - miny + 1 ) ;
}
Image Image : : get_rect ( const Rect2 & p_area ) const {
Image img ( p_area . size . x , p_area . size . y , mipmaps , format ) ;
@ -1997,7 +1889,6 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2&
ERR_FAIL_COND ( srcdsize = = 0 ) ;
ERR_FAIL_COND ( format ! = p_src . format ) ;
Rect2i local_src_rect = Rect2i ( 0 , 0 , width , height ) . clip ( Rect2i ( p_dest + p_src_rect . pos , p_src_rect . size ) ) ;
if ( local_src_rect . size . x < = 0 | | local_src_rect . size . y < = 0 )
@ -2014,7 +1905,6 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2&
for ( int i = 0 ; i < src_rect . size . y ; i + + ) {
for ( int j = 0 ; j < src_rect . size . x ; j + + ) {
int src_x = src_rect . pos . x + j ;
@ -2031,10 +1921,8 @@ void Image::blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2&
}
}
}
}
Image ( * Image : : _png_mem_loader_func ) ( const uint8_t * , int ) = NULL ;
Image ( * Image : : _jpg_mem_loader_func ) ( const uint8_t * , int ) = NULL ;
@ -2058,8 +1946,6 @@ void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
_image_compress_bc_func = p_compress_func ;
}
void Image : : normalmap_to_xy ( ) {
convert ( Image : : FORMAT_RGBA8 ) ;
@ -2087,7 +1973,6 @@ void Image::srgb_to_linear() {
static const uint8_t srgb2lin [ 256 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 , 2 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 4 , 4 , 4 , 4 , 4 , 5 , 5 , 5 , 5 , 6 , 6 , 6 , 6 , 7 , 7 , 7 , 8 , 8 , 8 , 9 , 9 , 9 , 10 , 10 , 10 , 11 , 11 , 11 , 12 , 12 , 13 , 13 , 13 , 14 , 14 , 15 , 15 , 16 , 16 , 16 , 17 , 17 , 18 , 18 , 19 , 19 , 20 , 20 , 21 , 22 , 22 , 23 , 23 , 24 , 24 , 25 , 26 , 26 , 27 , 27 , 28 , 29 , 29 , 30 , 31 , 31 , 32 , 33 , 33 , 34 , 35 , 36 , 36 , 37 , 38 , 38 , 39 , 40 , 41 , 42 , 42 , 43 , 44 , 45 , 46 , 47 , 47 , 48 , 49 , 50 , 51 , 52 , 53 , 54 , 55 , 55 , 56 , 57 , 58 , 59 , 60 , 61 , 62 , 63 , 64 , 65 , 66 , 67 , 68 , 70 , 71 , 72 , 73 , 74 , 75 , 76 , 77 , 78 , 80 , 81 , 82 , 83 , 84 , 85 , 87 , 88 , 89 , 90 , 92 , 93 , 94 , 95 , 97 , 98 , 99 , 101 , 102 , 103 , 105 , 106 , 107 , 109 , 110 , 112 , 113 , 114 , 116 , 117 , 119 , 120 , 122 , 123 , 125 , 126 , 128 , 129 , 131 , 132 , 134 , 135 , 137 , 139 , 140 , 142 , 144 , 145 , 147 , 148 , 150 , 152 , 153 , 155 , 157 , 159 , 160 , 162 , 164 , 166 , 167 , 169 , 171 , 173 , 175 , 176 , 178 , 180 , 182 , 184 , 186 , 188 , 190 , 192 , 193 , 195 , 197 , 199 , 201 , 203 , 205 , 207 , 209 , 211 , 213 , 215 , 218 , 220 , 222 , 224 , 226 , 228 , 230 , 232 , 235 , 237 , 239 , 241 , 243 , 245 , 248 , 250 , 252 } ;
ERR_FAIL_COND ( format ! = FORMAT_RGB8 & & format ! = FORMAT_RGBA8 ) ;
if ( format = = FORMAT_RGBA8 ) {
@ -2116,7 +2001,6 @@ void Image::srgb_to_linear() {
data_ptr [ ( i * 3 ) + 2 ] = srgb2lin [ data_ptr [ ( i * 3 ) + 2 ] ] ;
}
}
}
void Image : : premultiply_alpha ( ) {
@ -2130,7 +2014,6 @@ void Image::premultiply_alpha() {
PoolVector < uint8_t > : : Write wp = data . write ( ) ;
unsigned char * data_ptr = wp . ptr ( ) ;
for ( int i = 0 ; i < height ; i + + ) {
for ( int j = 0 ; j < width ; j + + ) {
@ -2174,7 +2057,6 @@ void Image::fix_alpha_edges() {
int closest_dist = max_dist ;
uint8_t closest_color [ 3 ] ;
int from_x = MAX ( 0 , j - max_radius ) ;
int to_x = MIN ( width - 1 , j + max_radius ) ;
int from_y = MAX ( 0 , i - max_radius ) ;
@ -2197,21 +2079,17 @@ void Image::fix_alpha_edges() {
closest_color [ 0 ] = rp [ 0 ] ;
closest_color [ 1 ] = rp [ 1 ] ;
closest_color [ 2 ] = rp [ 2 ] ;
}
}
if ( closest_dist ! = max_dist ) {
wptr [ 0 ] = closest_color [ 0 ] ;
wptr [ 1 ] = closest_color [ 1 ] ;
wptr [ 2 ] = closest_color [ 2 ] ;
}
}
}
}
String Image : : get_format_name ( Format p_format ) {
@ -2234,7 +2112,6 @@ Image::Image(const uint8_t* p_mem_png_jpg, int p_len) {
if ( empty ( ) & & _jpg_mem_loader_func ) {
* this = _jpg_mem_loader_func ( p_mem_png_jpg , p_len ) ;
}
}
Image : : Image ( ) {
@ -2246,7 +2123,4 @@ Image::Image() {
}
Image : : ~ Image ( ) {
}