From a18c4e62c661d2b92a0cb62191dfa4a5c1084955 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sun, 3 Mar 2024 00:27:09 +0000 Subject: [PATCH] Update CImg to v.3.3.4 --- .github/workflows/cimg.yml | 4 +- src/CImg.h | 1809 ++++++++++++++++++++---------------- 2 files changed, 1011 insertions(+), 802 deletions(-) diff --git a/.github/workflows/cimg.yml b/.github/workflows/cimg.yml index 90817df..ec594bd 100644 --- a/.github/workflows/cimg.yml +++ b/.github/workflows/cimg.yml @@ -23,7 +23,7 @@ jobs: name: Update CImg.h runs-on: ubuntu-latest needs: check-version - if: ${{ needs.check-version.outputs.latest-tag != 'v.3.3.3' }} + if: ${{ needs.check-version.outputs.latest-tag != 'v.3.3.4' }} steps: - uses: actions/checkout@v4 name: Checkout this repository @@ -36,7 +36,7 @@ jobs: location: 'src' - name: Commit new CImg version (and update script) run: | - sed -i 's/v.3.3.3/${{ needs.check-version.outputs.latest-tag }}/' .github/workflows/cimg.yml + sed -i 's/v.3.3.4/${{ needs.check-version.outputs.latest-tag }}/' .github/workflows/cimg.yml git config user.name 'GitHub Actions' git config user.email 'actions@github.com' git commit -am "Update CImg to ${{ needs.check-version.outputs.latest-tag }}" diff --git a/src/CImg.h b/src/CImg.h index 63b2126..ca2a4df 100644 --- a/src/CImg.h +++ b/src/CImg.h @@ -54,7 +54,7 @@ // Set version number of the library. #ifndef cimg_version -#define cimg_version 333 +#define cimg_version 334 /*----------------------------------------------------------- # @@ -6095,8 +6095,7 @@ namespace cimg_library { } inline double rand(const double val_min, const double val_max, cimg_uint64 *const p_rng) { - const double val = cimg::_rand(p_rng)/(double)~0U; - return val_min + (val_max - val_min)*val; + return val_min + (val_max - val_min)*cimg::_rand(p_rng)/~0U; } inline double rand(const double val_min, const double val_max) { @@ -6107,8 +6106,7 @@ namespace cimg_library { } inline double rand(const double val_max, cimg_uint64 *const p_rng) { - const double val = cimg::_rand(p_rng)/(double)~0U; - return val_max*val; + return val_max*cimg::_rand(p_rng)/(double)~0U; } inline double rand(const double val_max=1) { @@ -6909,12 +6907,23 @@ namespace cimg_library { return _fibonacci(n); // Not precise, but better than the wrong overflowing calculation } - //! Calculate greatest common divisor. - inline long gcd(long a, long b) { - while (a) { const long c = a; a = b%a; b = c; } + //! Calculate greatest common divisor of two integers. + template + inline T gcd(T a, T b) { + if (a<0) a = -a; + if (b<0) b = -b; + while (a) { const T c = a; a = b%a; b = c; } return b; } + //! Calculate least common multiple of two integers. + template + inline T lcm(T a, T b) { + if (a<0) a = -a; + if (!a && !b) return 0; + return a*(b/gcd(a,b)); + } + //! Convert character to lower case. inline char lowercase(const char x) { return (char)((x<'A'||x>'Z')?x:x - 'A' + 'a'); @@ -16978,25 +16987,19 @@ namespace cimg_library { const char *const calling_function, *s_op, *ss_op; typedef double (*mp_func)(_cimg_math_parser&); -#define _cimg_mp_is_scalar(arg) (memtype[arg]<2) // Is scalar value? -#define _cimg_mp_is_const_scalar(arg) (memtype[arg]==1) // Is const scalar? -#define _cimg_mp_is_vector(arg) (memtype[arg]>1) // Is vector? -#define _cimg_mp_is_comp(arg) (!memtype[arg]) // Is computation value? -#define _cimg_mp_is_reserved(arg) (memtype[arg]==-1) // Is scalar and reserved (e.g. variable)? -#define _cimg_mp_size(arg) (_cimg_mp_is_scalar(arg)?0U:(unsigned int)memtype[arg] - 1) // Size (0=scalar, N>0=vectorN) #define _cimg_mp_calling_function s_calling_function()._data -#define _cimg_mp_op(s) s_op = s; ss_op = ss #define _cimg_mp_check_const_scalar(arg,n_arg,mode) check_const_scalar(arg,n_arg,mode,ss,se,saved_char) #define _cimg_mp_check_const_index(arg) check_const_index(arg,ss,se,saved_char) #define _cimg_mp_check_notnan_index(arg) check_notnan_index(arg,ss,se,saved_char) #define _cimg_mp_check_list() check_list(ss,se,saved_char) #define _cimg_mp_check_matrix_square(arg,n_arg) check_matrix_square(arg,n_arg,ss,se,saved_char) #define _cimg_mp_check_type(arg,n_arg,mode,N) check_type(arg,n_arg,mode,N,ss,se,saved_char) - +#define _cimg_mp_const_scalar(val) _cimg_mp_return(const_scalar((double)(val))) #define _cimg_mp_defunc(mp) (*(mp_func)(*(mp).opcode))(mp) +#define _cimg_mp_op(s) s_op = s; ss_op = ss #define _cimg_mp_return(x) { *se = saved_char; s_op = previous_s_op; ss_op = previous_ss_op; return x; } #define _cimg_mp_return_nan() _cimg_mp_return(_cimg_mp_slot_nan) -#define _cimg_mp_const_scalar(val) _cimg_mp_return(const_scalar((double)(val))) +#define _cimg_mp_same(x) _cimg_mp_return(same(x)); #define _cimg_mp_scalar0(op) _cimg_mp_return(scalar0(op)) #define _cimg_mp_scalar1(op,i1) _cimg_mp_return(scalar1(op,i1)) #define _cimg_mp_scalar2(op,i1,i2) _cimg_mp_return(scalar2(op,i1,i2)) @@ -17005,6 +17008,12 @@ namespace cimg_library { #define _cimg_mp_scalar5(op,i1,i2,i3,i4,i5) _cimg_mp_return(scalar5(op,i1,i2,i3,i4,i5)) #define _cimg_mp_scalar6(op,i1,i2,i3,i4,i5,i6) _cimg_mp_return(scalar6(op,i1,i2,i3,i4,i5,i6)) #define _cimg_mp_scalar7(op,i1,i2,i3,i4,i5,i6,i7) _cimg_mp_return(scalar7(op,i1,i2,i3,i4,i5,i6,i7)) +#define _cimg_mp_strerr \ + *se = saved_char; \ + for (s0 = ss; s0>expr._data && *s0!=';'; --s0) {} \ + if (*s0==';') ++s0; \ + while (cimg::is_blank(*s0)) ++s0; \ + cimg::strellipsize(s0,64) #define _cimg_mp_vector1_v(op,i1) _cimg_mp_return(vector1_v(op,i1)) #define _cimg_mp_vector2_sv(op,i1,i2) _cimg_mp_return(vector2_sv(op,i1,i2)) #define _cimg_mp_vector2_vs(op,i1,i2) _cimg_mp_return(vector2_vs(op,i1,i2)) @@ -17013,12 +17022,6 @@ namespace cimg_library { #define _cimg_mp_vector4_vvss(op,i1,i2,i3,i4) _cimg_mp_return(vector4_vvss(op,i1,i2,i3,i4)) #define _cimg_mp_vector4_vsss(op,i1,i2,i3,i4) _cimg_mp_return(vector4_vsss(op,i1,i2,i3,i4)) #define _cimg_mp_vector4_svss(op,i1,i2,i3,i4) _cimg_mp_return(vector4_svss(op,i1,i2,i3,i4)) -#define _cimg_mp_strerr \ - *se = saved_char; \ - for (s0 = ss; s0>expr._data && *s0!=';'; --s0) {} \ - if (*s0==';') ++s0; \ - while (cimg::is_blank(*s0)) ++s0; \ - cimg::strellipsize(s0,64) // Constructors / Destructors. ~_cimg_math_parser() { @@ -17065,11 +17068,11 @@ namespace cimg_library { #define _cimg_mp_interpolation (reserved_label[31]!=~0U?reserved_label[31]:0) #define _cimg_mp_boundary (reserved_label[32]!=~0U?reserved_label[32]:0) #define _cimg_mp_slot_t 17 -#define _cimg_mp_slot_nan 29 -#define _cimg_mp_slot_x 30 -#define _cimg_mp_slot_y 31 -#define _cimg_mp_slot_z 32 -#define _cimg_mp_slot_c 33 +#define _cimg_mp_slot_nan 30 +#define _cimg_mp_slot_x 31 +#define _cimg_mp_slot_y 32 +#define _cimg_mp_slot_z 33 +#define _cimg_mp_slot_c 34 mem.assign(96); for (unsigned int i = 0; i<=10; ++i) mem[i] = (double)i; // mem[0-10] = 0...10 @@ -17087,6 +17090,7 @@ namespace cimg_library { mem[26] = (double)imglist._width; // l mem[27] = std::exp(1.); // e mem[28] = cimg::PI; // pi + mem[29] = DBL_EPSILON; // eps mem[_cimg_mp_slot_nan] = cimg::type::nan(); // nan // Set value property : @@ -17103,19 +17107,19 @@ namespace cimg_library { // reserved_label[0-32] are used to store the memory index of these variables: // [0] = wh, [1] = whd, [2] = whds, [3] = pi, [4] = im, [5] = iM, [6] = ia, [7] = iv, [8] = id, // [9] = is, [10] = ip, [11] = ic, [12] = in, [13] = xm, [14] = ym, [15] = zm, [16] = cm, [17] = xM, - // [18] = yM, [19] = zM, [20] = cM, [21] = i0...[30] = i9, [31] = interpolation, [32] = boundary + // [18] = yM, [19] = zM, [20] = cM, [21] = i0...[30] = i9, [31] = interpolation, [32] = boundary, [33] = eps // Compile expression into a sequence of opcodes. s_op = ""; ss_op = expr._data; const unsigned int ind_result = compile(expr._data,expr._data + expr._width - 1,0,0,0); - if (!_cimg_mp_is_const_scalar(ind_result)) { - if (_cimg_mp_is_vector(ind_result)) - CImg(&mem[ind_result] + 1,_cimg_mp_size(ind_result),1,1,1,true). + if (!is_const_scalar(ind_result)) { + if (is_vector(ind_result)) + CImg(&mem[ind_result] + 1,size(ind_result),1,1,1,true). fill(cimg::type::nan()); else if (ind_result!=_cimg_mp_slot_t) mem[ind_result] = cimg::type::nan(); } if (mem._width>=256 && mem._width - mempos>=mem._width/2) mem.resize(mempos,1,1,1,-1); - result_dim = _cimg_mp_size(ind_result); + result_dim = size(ind_result); result = mem._data + ind_result; // Free resources used for compiling expression and prepare evaluation. @@ -17268,13 +17272,22 @@ namespace cimg_library { if (!cimg::strcasecmp(s,"inf")) { val = cimg::type::inf(); nb = 1; } else if (!cimg::strcasecmp(s,"nan")) { val = cimg::type::nan(); nb = 1; } if (nb==1 && is_sth) val = -val; - } else if (*s=='0' && (s[1]=='x' || s[1]=='X')) { // Hexadecimal number + } else if (*s=='0' && (s[1]=='x' || s[1]=='X')) { // Hexadecimal litteral is_sth = *ss=='-'; if (cimg_sscanf(s + 2,"%x%c",&arg1,&sep)==1) { nb = 1; val = (double)arg1; if (is_sth) val = -val; } + } else if (*s=='0' && (s[1]=='b' || s[1]=='B')) { // Binary litteral + is_sth = *ss=='-'; + variable_name.assign(65); + if (cimg_sscanf(s + 2,"%64[01]%c",variable_name.data(),&sep)==1) { + nb = 1; + val = (double)std::strtol(variable_name,0,2); + } + if (is_sth) val = -val; + variable_name.assign(); } if (!nb) nb = cimg_sscanf(ss,"%lf%c%c",&val,&(sep=0),&(end=0)); if (nb==1) _cimg_mp_const_scalar(val); @@ -17307,13 +17320,10 @@ namespace cimg_library { case 'z' : _cimg_mp_return(reserved_label[(int)'z']!=~0U?reserved_label[(int)'z']:_cimg_mp_slot_z); case 'u' : if (reserved_label[(int)'u']!=~0U) _cimg_mp_return(reserved_label[(int)'u']); - _cimg_mp_scalar2(mp_u,0,1); - case 'v' : - if (reserved_label[(int)'v']!=~0U) _cimg_mp_return(reserved_label[(int)'v']); - _cimg_mp_scalar2(mp_u,11,1); + _cimg_mp_scalar0(mp_rand_double_0_1); case 'g' : if (reserved_label[(int)'g']!=~0U) _cimg_mp_return(reserved_label[(int)'g']); - _cimg_mp_scalar0(mp_g); + _cimg_mp_scalar0(mp_rand_double_gaussian); case 'i' : if (reserved_label[(int)'i']!=~0U) _cimg_mp_return(reserved_label[(int)'i']); _cimg_mp_scalar0(mp_i); @@ -17401,6 +17411,8 @@ namespace cimg_library { } else if (ss3==se) { // Three-chars reserved variable if (*ss=='w' && *ss1=='h' && *ss2=='d') // whd _cimg_mp_return(reserved_label[1]!=~0U?reserved_label[1]:24); + if (*ss=='e' && *ss1=='p' && *ss2=='s') // eps + _cimg_mp_return(reserved_label[33]!=~0U?reserved_label[33]:29); } else if (ss4==se) { // Four-chars reserved variable if (*ss=='w' && *ss1=='h' && *ss2=='d' && *ss3=='s') // whds _cimg_mp_return(reserved_label[2]!=~0U?reserved_label[2]:25); @@ -17439,7 +17451,7 @@ namespace cimg_library { // Assign image value (direct). if (l_variable_name>2 && (*ss=='i' || *ss=='j' || *ss=='I' || *ss=='J') && (*ss1=='(' || *ss1=='[') && - (reserved_label[(int)*ss]==~0U || *ss1=='(' || !_cimg_mp_is_vector(reserved_label[(int)*ss]))) { + (reserved_label[(int)*ss]==~0U || *ss1=='(' || !is_vector(reserved_label[(int)*ss]))) { is_relative = *ss=='j' || *ss=='J'; if (*ss1=='[' && *ve1==']') { // i/j/I/J[_#ind,offset] = value @@ -17454,7 +17466,7 @@ namespace cimg_library { _cimg_mp_check_type(arg1,0,1,0); arg2 = compile(s + 1,se,depth1,0,block_flags); // Value to assign _cimg_mp_check_type(arg2,2,*ss>='i'?1:3,0); - if (_cimg_mp_is_vector(arg2)) { + if (is_vector(arg2)) { if (p1!=~0U) { _cimg_mp_check_const_index(p1); p3 = (unsigned int)cimg::mod((int)mem[p1],imglist.width()); @@ -17469,10 +17481,10 @@ namespace cimg_library { p_ref[1] = p1; p_ref[2] = (unsigned int)is_relative; p_ref[3] = arg1; - if (_cimg_mp_is_vector(arg2)) + if (is_vector(arg2)) set_reserved_vector(arg2); // Prevent from being used in further optimization - else if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -1; - if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -1; + else if (is_comp_scalar(arg2)) memtype[arg2] = -1; + if (is_comp_scalar(arg1)) memtype[arg1] = -1; } if (p1!=~0U) { @@ -17480,23 +17492,23 @@ namespace cimg_library { if (*ss>='i') CImg::vector((ulongT)(is_relative?mp_list_set_joff:mp_list_set_ioff), arg2,p1,arg1).move_to(code); - else if (_cimg_mp_is_scalar(arg2)) + else if (is_scalar(arg2)) CImg::vector((ulongT)(is_relative?mp_list_set_Joff_s:mp_list_set_Ioff_s), arg2,p1,arg1).move_to(code); else CImg::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v), - arg2,p1,arg1,_cimg_mp_size(arg2)).move_to(code); + arg2,p1,arg1,size(arg2)).move_to(code); } else { if (!imgout) _cimg_mp_return(arg2); if (*ss>='i') CImg::vector((ulongT)(is_relative?mp_set_joff:mp_set_ioff), arg2,arg1).move_to(code); - else if (_cimg_mp_is_scalar(arg2)) + else if (is_scalar(arg2)) CImg::vector((ulongT)(is_relative?mp_set_Joff_s:mp_set_Ioff_s), arg2,arg1).move_to(code); else CImg::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v), - arg2,arg1,_cimg_mp_size(arg2)).move_to(code); + arg2,arg1,size(arg2)).move_to(code); } _cimg_mp_return(arg2); } @@ -17518,8 +17530,8 @@ namespace cimg_library { if (s01) { arg2 = arg1 + 1; @@ -17539,7 +17551,7 @@ namespace cimg_library { } } - if (_cimg_mp_is_vector(arg5)) { + if (is_vector(arg5)) { if (p1!=~0U) { _cimg_mp_check_const_index(p1); p3 = (unsigned int)cimg::mod((int)mem[p1],imglist.width()); @@ -17558,37 +17570,37 @@ namespace cimg_library { p_ref[4] = arg2; p_ref[5] = arg3; p_ref[6] = arg4; - if (_cimg_mp_is_vector(arg5)) + if (is_vector(arg5)) set_reserved_vector(arg5); // Prevent from being used in further optimization - else if (_cimg_mp_is_comp(arg5)) memtype[arg5] = -1; - if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -1; - if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -1; - if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -1; - if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -1; - if (_cimg_mp_is_comp(arg4)) memtype[arg4] = -1; + else if (is_comp_scalar(arg5)) memtype[arg5] = -1; + if (p1!=~0U && is_comp_scalar(p1)) memtype[p1] = -1; + if (is_comp_scalar(arg1)) memtype[arg1] = -1; + if (is_comp_scalar(arg2)) memtype[arg2] = -1; + if (is_comp_scalar(arg3)) memtype[arg3] = -1; + if (is_comp_scalar(arg4)) memtype[arg4] = -1; } if (p1!=~0U) { if (!imglist) _cimg_mp_return(arg5); if (*ss>='i') CImg::vector((ulongT)(is_relative?mp_list_set_jxyzc:mp_list_set_ixyzc), arg5,p1,arg1,arg2,arg3,arg4).move_to(code); - else if (_cimg_mp_is_scalar(arg5)) + else if (is_scalar(arg5)) CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_s:mp_list_set_Ixyz_s), arg5,p1,arg1,arg2,arg3).move_to(code); else CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v), - arg5,p1,arg1,arg2,arg3,_cimg_mp_size(arg5)).move_to(code); + arg5,p1,arg1,arg2,arg3,size(arg5)).move_to(code); } else { if (!imgout) _cimg_mp_return(arg5); if (*ss>='i') CImg::vector((ulongT)(is_relative?mp_set_jxyzc:mp_set_ixyzc), arg5,arg1,arg2,arg3,arg4).move_to(code); - else if (_cimg_mp_is_scalar(arg5)) + else if (is_scalar(arg5)) CImg::vector((ulongT)(is_relative?mp_set_Jxyz_s:mp_set_Ixyz_s), arg5,arg1,arg2,arg3).move_to(code); else CImg::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v), - arg5,arg1,arg2,arg3,_cimg_mp_size(arg5)).move_to(code); + arg5,arg1,arg2,arg3,size(arg5)).move_to(code); } _cimg_mp_return(arg5); } @@ -17601,16 +17613,16 @@ namespace cimg_library { variable_name[s0 - ss] = 0; // Remove brackets in variable name get_variable_pos(variable_name,arg1,arg2); arg1 = arg2!=~0U?reserved_label[arg2]:arg1!=~0U?variable_pos[arg1]:~0U; // Vector slot - if (arg1==~0U || _cimg_mp_is_scalar(arg1)) + if (arg1==~0U || is_scalar(arg1)) compile(ss,s0,depth1,0,block_flags); // Variable does not exist or is not a vector -> error arg2 = compile(++s0,ve1,depth1,0,block_flags); // Index arg3 = compile(s + 1,se,depth1,0,block_flags); // Value to assign _cimg_mp_check_type(arg3,2,1,0); - if (_cimg_mp_is_const_scalar(arg2)) { // Constant index -> return corresponding variable slot directly + if (is_const_scalar(arg2)) { // Constant index -> return corresponding variable slot directly nb = (int)mem[arg2]; - if (nb>=0 && nb<(int)_cimg_mp_size(arg1)) { + if (nb>=0 && nb<(int)size(arg1)) { arg1+=nb + 1; CImg::vector((ulongT)mp_copy,arg1,arg3).move_to(code); _cimg_mp_return(arg1); @@ -17623,10 +17635,10 @@ namespace cimg_library { *p_ref = 1; p_ref[1] = arg1; p_ref[2] = arg2; - if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -1; // Prevent from being used in further optimization - if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -1; + if (is_comp_scalar(arg3)) memtype[arg3] = -1; // Prevent from being used in further optimization + if (is_comp_scalar(arg2)) memtype[arg2] = -1; } - CImg::vector((ulongT)mp_vector_set_off,arg3,arg1,(ulongT)_cimg_mp_size(arg1),arg2). + CImg::vector((ulongT)mp_vector_set_off,arg3,arg1,(ulongT)size(arg1),arg2). move_to(code); _cimg_mp_return(arg3); } @@ -17750,13 +17762,13 @@ namespace cimg_library { arg1 = arg2!=~0U?reserved_label[arg2]:arg1!=~0U?variable_pos[arg1]:~0U; if (arg1==~0U) { // Create new variable - if (_cimg_mp_is_vector(arg3)) { // Vector variable - arg1 = is_sth || is_comp_vector(arg3)?arg3:vector_copy(arg3); + if (is_vector(arg3)) { // Vector variable + arg1 = is_sth || is_comp_vector(arg3)?arg3:copy(arg3); set_reserved_vector(arg1); // Prevent from being used in further optimization } else { // Scalar variable if (is_const) arg1 = arg3; else { - arg1 = is_sth || _cimg_mp_is_comp(arg3)?arg3:scalar1(mp_copy,arg3); + arg1 = is_sth || is_comp_scalar(arg3)?arg3:scalar1(mp_copy,arg3); memtype[arg1] = -1; } } @@ -17769,25 +17781,25 @@ namespace cimg_library { } } else { // Variable already exists -> assign a new value - if (is_const || _cimg_mp_is_const_scalar(arg1)) { + if (is_const || is_const_scalar(arg1)) { _cimg_mp_strerr; cimg::strellipsize(variable_name,64); throw CImgArgumentException("[" cimg_appname "_math_parser] " "CImg<%s>::%s: %s: Invalid assignment of %sconst variable '%s'%s, " "in expression '%s'.", pixel_type(),_cimg_mp_calling_function,s_op, - _cimg_mp_is_const_scalar(arg1)?"":"non-", + is_const_scalar(arg1)?"":"non-", variable_name._data, - !_cimg_mp_is_const_scalar(arg1) && is_const?" as a const variable":"", + !is_const_scalar(arg1) && is_const?" as a const variable":"", s0); } - _cimg_mp_check_type(arg3,2,_cimg_mp_is_vector(arg1)?3:1,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1)) { // Vector - if (_cimg_mp_is_vector(arg3)) // From vector - CImg::vector((ulongT)mp_vector_copy,arg1,arg3,(ulongT)_cimg_mp_size(arg1)). + _cimg_mp_check_type(arg3,2,is_vector(arg1)?3:1,size(arg1)); + if (is_vector(arg1)) { // Vector + if (is_vector(arg3)) // From vector + CImg::vector((ulongT)mp_vector_copy,arg1,arg3,(ulongT)size(arg1)). move_to(code); else // From scalar - CImg::vector((ulongT)mp_vector_init,arg1,1,(ulongT)_cimg_mp_size(arg1),arg3). + CImg::vector((ulongT)mp_vector_init,arg1,1,(ulongT)size(arg1),arg3). move_to(code); } else // Scalar CImg::vector((ulongT)mp_copy,arg1,arg3).move_to(code); @@ -17811,7 +17823,7 @@ namespace cimg_library { arg3 = ref[1]; // Vector slot arg4 = ref[2]; // Index if (p_ref) std::memcpy(p_ref,ref,siz_ref); - CImg::vector((ulongT)mp_vector_set_off,arg2,arg3,(ulongT)_cimg_mp_size(arg3),arg4). + CImg::vector((ulongT)mp_vector_set_off,arg2,arg3,(ulongT)size(arg3),arg4). move_to(code); _cimg_mp_return(arg2); } @@ -17859,37 +17871,37 @@ namespace cimg_library { if (*ref==4) { // Image value (vector): I/J[_#ind,off] = value if (!is_inside_critical) is_parallelizable = false; - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); + _cimg_mp_check_type(arg2,2,3,size(arg1)); p1 = ref[1]; // Index is_relative = (bool)ref[2]; arg3 = ref[3]; // Offset if (p_ref) std::memcpy(p_ref,ref,siz_ref); if (p1!=~0U) { if (!imglist) _cimg_mp_return(arg2); - if (_cimg_mp_is_scalar(arg2)) + if (is_scalar(arg2)) CImg::vector((ulongT)(is_relative?mp_list_set_Joff_s:mp_list_set_Ioff_s), arg2,p1,arg3).move_to(code); else { _cimg_mp_check_const_index(p1); CImg::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v), - arg2,p1,arg3,_cimg_mp_size(arg2)).move_to(code); + arg2,p1,arg3,size(arg2)).move_to(code); } } else { if (!imgout) _cimg_mp_return(arg2); - if (_cimg_mp_is_scalar(arg2)) + if (is_scalar(arg2)) CImg::vector((ulongT)(is_relative?mp_set_Joff_s:mp_set_Ioff_s), arg2,arg3).move_to(code); else CImg::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v), - arg2,arg3,_cimg_mp_size(arg2)).move_to(code); + arg2,arg3,size(arg2)).move_to(code); } _cimg_mp_return(arg2); } if (*ref==5) { // Image value (vector): I/J(_#ind,_x,_y,_z,_c) = value if (!is_inside_critical) is_parallelizable = false; - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); + _cimg_mp_check_type(arg2,2,3,size(arg1)); p1 = ref[1]; // Index is_relative = (bool)ref[2]; arg3 = ref[3]; // X @@ -17898,39 +17910,39 @@ namespace cimg_library { if (p_ref) std::memcpy(p_ref,ref,siz_ref); if (p1!=~0U) { if (!imglist) _cimg_mp_return(arg2); - if (_cimg_mp_is_scalar(arg2)) + if (is_scalar(arg2)) CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_s:mp_list_set_Ixyz_s), arg2,p1,arg3,arg4,arg5).move_to(code); else { _cimg_mp_check_const_index(p1); CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v), - arg2,p1,arg3,arg4,arg5,_cimg_mp_size(arg2)).move_to(code); + arg2,p1,arg3,arg4,arg5,size(arg2)).move_to(code); } } else { if (!imgout) _cimg_mp_return(arg2); - if (_cimg_mp_is_scalar(arg2)) + if (is_scalar(arg2)) CImg::vector((ulongT)(is_relative?mp_set_Jxyz_s:mp_set_Ixyz_s), arg2,arg3,arg4,arg5).move_to(code); else CImg::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v), - arg2,arg3,arg4,arg5,_cimg_mp_size(arg2)).move_to(code); + arg2,arg3,arg4,arg5,size(arg2)).move_to(code); } _cimg_mp_return(arg2); } - if (_cimg_mp_is_vector(arg1)) { // Vector variable: V = value - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg2)) // From vector - CImg::vector((ulongT)mp_vector_copy,arg1,arg2,(ulongT)_cimg_mp_size(arg1)). + if (is_vector(arg1)) { // Vector variable: V = value + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg2)) // From vector + CImg::vector((ulongT)mp_vector_copy,arg1,arg2,(ulongT)size(arg1)). move_to(code); else // From scalar - CImg::vector((ulongT)mp_vector_init,arg1,1,(ulongT)_cimg_mp_size(arg1),arg2). + CImg::vector((ulongT)mp_vector_init,arg1,1,(ulongT)size(arg1),arg2). move_to(code); _cimg_mp_return(arg1); } - if (_cimg_mp_is_reserved(arg1)) { // Scalar variable: s = scalar + if (is_reserved(arg1)) { // Scalar variable: s = scalar _cimg_mp_check_type(arg2,2,1,0); CImg::vector((ulongT)mp_copy,arg1,arg2).move_to(code); _cimg_mp_return(arg1); @@ -17944,7 +17956,7 @@ namespace cimg_library { "CImg<%s>::%s: %s: Invalid %slvalue '%s', " "in expression '%s'.", pixel_type(),_cimg_mp_calling_function,s_op, - arg1!=~0U && _cimg_mp_is_const_scalar(arg1)?"const ":"", + arg1!=~0U && is_const_scalar(arg1)?"const ":"", variable_name._data,s0); } @@ -17959,7 +17971,7 @@ namespace cimg_library { arg2 = compile(s + 1,se,depth1,0,block_flags); // Right operand _cimg_mp_check_type(arg1,1,2,2); _cimg_mp_check_type(arg2,2,3,2); - if (_cimg_mp_is_vector(arg2)) { // Complex **= complex + if (is_vector(arg2)) { // Complex **= complex if (*ps=='*') CImg::vector((ulongT)mp_complex_mul,arg1,arg1,arg2).move_to(code); else if (*ps=='/') @@ -17967,16 +17979,11 @@ namespace cimg_library { else CImg::vector((ulongT)mp_complex_pow_vv,arg1,arg1,arg2).move_to(code); } else { // Complex **= scalar - if (*ps=='*') { - if (arg2==1) _cimg_mp_return(arg1); - self_vector_s(arg1,mp_self_mul,arg2); - } else if (*ps=='/') { - if (arg2==1) _cimg_mp_return(arg1); - self_vector_s(arg1,mp_self_div,arg2); - } else { - if (arg2==1) _cimg_mp_return(arg1); - CImg::vector((ulongT)mp_complex_pow_vs,arg1,arg1,arg2).move_to(code); - } + if (arg2==1) _cimg_mp_return(arg1); + if (*ps=='*') self_vector_s(arg1,mp_self_mul,arg2); + else if (*ps=='/') self_vector_s(arg1,mp_self_div,arg2); + else if (arg2==2) CImg::vector((ulongT)mp_complex_sqr,arg1,arg1 + 1,arg1 + 2).move_to(code); + else CImg::vector((ulongT)mp_complex_pow_vs,arg1,arg1,arg2).move_to(code); } if (*ref==4) { // Image value (vector): I/J[_#ind,off] **= value @@ -17989,11 +17996,11 @@ namespace cimg_library { if (!imglist) _cimg_mp_return(arg1); _cimg_mp_check_const_index(p1); CImg::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v), - arg1,p1,arg3,_cimg_mp_size(arg1)).move_to(code); + arg1,p1,arg3,size(arg1)).move_to(code); } else { if (!imgout) _cimg_mp_return(arg1); CImg::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v), - arg1,arg3,_cimg_mp_size(arg1)).move_to(code); + arg1,arg3,size(arg1)).move_to(code); } } else if (*ref==5) { // Image value (vector): I/J(_#ind,_x,_y,_z,_c) **= value @@ -18008,11 +18015,11 @@ namespace cimg_library { if (!imglist) _cimg_mp_return(arg1); _cimg_mp_check_const_index(p1); CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v), - arg1,p1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code); + arg1,p1,arg3,arg4,arg5,size(arg1)).move_to(code); } else { if (!imgout) _cimg_mp_return(arg1); CImg::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v), - arg1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code); + arg1,arg3,arg4,arg5,size(arg1)).move_to(code); } } @@ -18044,13 +18051,16 @@ namespace cimg_library { // Check for particular case to be simplified. if ((op==mp_self_add || op==mp_self_sub) && !arg2) _cimg_mp_return(arg1); - if ((op==mp_self_mul || op==mp_self_div) && arg2==1) _cimg_mp_return(arg1); + if ((op==mp_self_mul || op==mp_self_div || op==mp_self_pow) && arg2==1) _cimg_mp_return(arg1); + if (op==mp_self_pow && (arg2==0 || arg2==2)) { + if (!arg2) CImg::vector((ulongT)mp_copy,arg1,1).move_to(code); + else CImg::vector((ulongT)mp_sqr,arg1,arg1).move_to(code); + _cimg_mp_return(arg1); + } // Apply operator on a copy to prevent modifying a constant or a variable. - if (*ref && (_cimg_mp_is_const_scalar(arg1) || _cimg_mp_is_vector(arg1) || _cimg_mp_is_reserved(arg1))) { - if (_cimg_mp_is_vector(arg1)) arg1 = vector_copy(arg1); - else arg1 = scalar1(mp_copy,arg1); - } + if (*ref && (is_const_scalar(arg1) || is_vector(arg1) || is_reserved(arg1))) + arg1 = copy(arg1); if (*ref==1) { // Vector value (scalar): V[k] += scalar _cimg_mp_check_type(arg2,2,1,0); @@ -18058,7 +18068,7 @@ namespace cimg_library { arg4 = ref[2]; // Index if (p_ref) std::memcpy(p_ref,ref,siz_ref); CImg::vector((ulongT)op,arg1,arg2).move_to(code); - CImg::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)_cimg_mp_size(arg3),arg4). + CImg::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)size(arg3),arg4). move_to(code); _cimg_mp_return(arg1); } @@ -18108,54 +18118,54 @@ namespace cimg_library { if (*ref==4) { // Image value (vector): I/J[_#ind,off] += value if (!is_inside_critical) is_parallelizable = false; - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); + _cimg_mp_check_type(arg2,2,3,size(arg1)); p1 = ref[1]; // Index is_relative = (bool)ref[2]; arg3 = ref[3]; // Offset if (p_ref) std::memcpy(p_ref,ref,siz_ref); - if (_cimg_mp_is_scalar(arg2)) self_vector_s(arg1,op,arg2); else self_vector_v(arg1,op,arg2); + if (is_scalar(arg2)) self_vector_s(arg1,op,arg2); else self_vector_v(arg1,op,arg2); if (p1!=~0U) { if (!imglist) _cimg_mp_return(arg1); CImg::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v), - arg1,p1,arg3,_cimg_mp_size(arg1)).move_to(code); + arg1,p1,arg3,size(arg1)).move_to(code); } else { if (!imgout) _cimg_mp_return(arg1); CImg::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v), - arg1,arg3,_cimg_mp_size(arg1)).move_to(code); + arg1,arg3,size(arg1)).move_to(code); } _cimg_mp_return(arg1); } if (*ref==5) { // Image value (vector): I/J(_#ind,_x,_y,_z,_c) += value if (!is_inside_critical) is_parallelizable = false; - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); + _cimg_mp_check_type(arg2,2,3,size(arg1)); p1 = ref[1]; // Index is_relative = (bool)ref[2]; arg3 = ref[3]; // X arg4 = ref[4]; // Y arg5 = ref[5]; // Z if (p_ref) std::memcpy(p_ref,ref,siz_ref); - if (_cimg_mp_is_scalar(arg2)) self_vector_s(arg1,op,arg2); else self_vector_v(arg1,op,arg2); + if (is_scalar(arg2)) self_vector_s(arg1,op,arg2); else self_vector_v(arg1,op,arg2); if (p1!=~0U) { if (!imglist) _cimg_mp_return(arg1); CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v), - arg1,p1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code); + arg1,p1,arg3,arg4,arg5,size(arg1)).move_to(code); } else { if (!imgout) _cimg_mp_return(arg1); CImg::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v), - arg1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code); + arg1,arg3,arg4,arg5,size(arg1)).move_to(code); } _cimg_mp_return(arg1); } - if (_cimg_mp_is_vector(arg1)) { // Vector variable: V += value - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg2)) self_vector_v(arg1,op,arg2); // Vector += vector + if (is_vector(arg1)) { // Vector variable: V += value + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg2)) self_vector_v(arg1,op,arg2); // Vector += vector else self_vector_s(arg1,op,arg2); // Vector += scalar _cimg_mp_return(arg1); } - if (_cimg_mp_is_reserved(arg1)) { // Scalar variable: s += scalar + if (is_reserved(arg1)) { // Scalar variable: s += scalar _cimg_mp_check_type(arg2,2,1,0); CImg::vector((ulongT)op,arg1,arg2).move_to(code); _cimg_mp_return(arg1); @@ -18169,7 +18179,7 @@ namespace cimg_library { "CImg<%s>::%s: %s: Invalid %slvalue '%s', " "in expression '%s'.", pixel_type(),_cimg_mp_calling_function,s_op, - _cimg_mp_is_const_scalar(arg1)?"const ":"", + is_const_scalar(arg1)?"const ":"", variable_name._data,s0); } @@ -18179,7 +18189,7 @@ namespace cimg_library { s1 = s + 1; while (s1::vector((ulongT)mp_if,pos,arg1,arg2,arg3, p3 - p2,code._width - p3,arg4).move_to(code,p2); @@ -18202,16 +18212,15 @@ namespace cimg_library { _cimg_mp_op("Operator '||'"); arg1 = compile(ss,s,depth1,0,block_flags); _cimg_mp_check_type(arg1,1,1,0); - if (arg1>0 && arg1<=16) _cimg_mp_return(1); + if (is_const_scalar(arg1) && mem[arg1]) _cimg_mp_return(1); p2 = code._width; arg2 = compile(s + 2,se,depth1,0,block_flags); _cimg_mp_check_type(arg2,2,1,0); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1] || mem[arg2]); - if (!arg1) _cimg_mp_return(arg2); + if (!arg1) _cimg_mp_scalar1(mp_bool,arg2); pos = scalar(); - CImg::vector((ulongT)mp_logical_or,pos,arg1,arg2,code._width - p2). - move_to(code,p2); + CImg::vector((ulongT)mp_logical_or,pos,arg1,arg2,code._width - p2).move_to(code,p2); return_new_comp = true; _cimg_mp_return(pos); } @@ -18225,9 +18234,9 @@ namespace cimg_library { p2 = code._width; arg2 = compile(s + 2,se,depth1,0,block_flags); _cimg_mp_check_type(arg2,2,1,0); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1] && mem[arg2]); - if (arg1>0 && arg1<=16) _cimg_mp_return(arg2); + if (is_const_scalar(arg1) && mem[arg1]) _cimg_mp_scalar1(mp_bool,arg2); pos = scalar(); CImg::vector((ulongT)mp_logical_and,pos,arg1,arg2,code._width - p2). move_to(code,p2); @@ -18240,20 +18249,20 @@ namespace cimg_library { _cimg_mp_op("Operator '|'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_or,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) { - if (!arg2) _cimg_mp_return(arg1); + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_or,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) { + if (!arg2) _cimg_mp_same(arg1); _cimg_mp_vector2_vs(mp_bitwise_or,arg1,arg2); } - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) { - if (!arg1) _cimg_mp_return(arg2); + if (is_scalar(arg1) && is_vector(arg2)) { + if (!arg1) _cimg_mp_same(arg2); _cimg_mp_vector2_sv(mp_bitwise_or,arg1,arg2); } - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar((longT)mem[arg1] | (longT)mem[arg2]); - if (!arg2) _cimg_mp_return(arg1); - if (!arg1) _cimg_mp_return(arg2); + if (!arg2) _cimg_mp_same(arg1); + if (!arg1) _cimg_mp_same(arg2); _cimg_mp_scalar2(mp_bitwise_or,arg1,arg2); } @@ -18262,11 +18271,11 @@ namespace cimg_library { _cimg_mp_op("Operator '&'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_and,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_bitwise_and,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_bitwise_and,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_and,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_bitwise_and,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_bitwise_and,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar((longT)mem[arg1] & (longT)mem[arg2]); if (!arg1 || !arg2) _cimg_mp_return(0); _cimg_mp_scalar2(mp_bitwise_and,arg1,arg2); @@ -18278,8 +18287,8 @@ namespace cimg_library { arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 2,se,depth1,0,block_flags); if (arg1==arg2) _cimg_mp_return(0); - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg2); + p1 = size(arg1); + p2 = size(arg2); if (p1 || p2) { if (p1 && p2 && p1!=p2) _cimg_mp_return(1); pos = scalar(); @@ -18287,7 +18296,7 @@ namespace cimg_library { return_new_comp = true; _cimg_mp_return(pos); } - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]!=mem[arg2]); _cimg_mp_scalar2(mp_neq,arg1,arg2); } @@ -18298,8 +18307,8 @@ namespace cimg_library { arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 2,se,depth1,0,block_flags); if (arg1==arg2) _cimg_mp_return(1); - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg2); + p1 = size(arg1); + p2 = size(arg2); if (p1 || p2) { if (p1 && p2 && p1!=p2) _cimg_mp_return(0); pos = scalar(); @@ -18307,7 +18316,7 @@ namespace cimg_library { return_new_comp = true; _cimg_mp_return(pos); } - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]==mem[arg2]); _cimg_mp_scalar2(mp_eq,arg1,arg2); } @@ -18317,11 +18326,11 @@ namespace cimg_library { _cimg_mp_op("Operator '<='"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 2,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_lte,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_lte,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_lte,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_lte,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_lte,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_lte,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]<=mem[arg2]); if (arg1==arg2) _cimg_mp_return(1); _cimg_mp_scalar2(mp_lte,arg1,arg2); @@ -18332,11 +18341,11 @@ namespace cimg_library { _cimg_mp_op("Operator '>='"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 2,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_gte,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_gte,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_gte,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_gte,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_gte,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_gte,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]>=mem[arg2]); if (arg1==arg2) _cimg_mp_return(1); _cimg_mp_scalar2(mp_gte,arg1,arg2); @@ -18347,11 +18356,11 @@ namespace cimg_library { _cimg_mp_op("Operator '<'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_lt,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_lt,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_lt,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_lt,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_lt,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_lt,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_gt,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_gt,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_gt,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_gt,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_gt,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_gt,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]>mem[arg2]); if (arg1==arg2) _cimg_mp_return(0); _cimg_mp_scalar2(mp_gt,arg1,arg2); @@ -18377,19 +18386,19 @@ namespace cimg_library { _cimg_mp_op("Operator '<<'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 2,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_left_shift,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) { - if (!arg2) _cimg_mp_return(arg1); + if (is_vector(arg1) && is_scalar(arg2)) { + if (!arg2) _cimg_mp_same(arg1); _cimg_mp_vector2_vs(mp_bitwise_left_shift,arg1,arg2); } - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_bitwise_left_shift,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar((longT)mem[arg1]<<(unsigned int)mem[arg2]); if (!arg1) _cimg_mp_return(0); - if (!arg2) _cimg_mp_return(arg1); + if (!arg2) _cimg_mp_same(arg1); _cimg_mp_scalar2(mp_bitwise_left_shift,arg1,arg2); } @@ -18398,19 +18407,19 @@ namespace cimg_library { _cimg_mp_op("Operator '>>'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 2,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_bitwise_right_shift,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) { - if (!arg2) _cimg_mp_return(arg1); + if (is_vector(arg1) && is_scalar(arg2)) { + if (!arg2) _cimg_mp_same(arg1); _cimg_mp_vector2_vs(mp_bitwise_right_shift,arg1,arg2); } - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_bitwise_right_shift,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar((longT)mem[arg1]>>(unsigned int)mem[arg2]); if (!arg1) _cimg_mp_return(0); - if (!arg2) _cimg_mp_return(arg1); + if (!arg2) _cimg_mp_same(arg1); _cimg_mp_scalar2(mp_bitwise_right_shift,arg1,arg2); } @@ -18423,17 +18432,17 @@ namespace cimg_library { _cimg_mp_op("Operator '+'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (!arg2) _cimg_mp_return(arg1); - if (!arg1) _cimg_mp_return(arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_add,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_add,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_add,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (!arg2) _cimg_mp_same(arg1); + if (!arg1) _cimg_mp_same(arg2); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_add,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_add,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_add,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1] + mem[arg2]); if (code) { // Try to spot linear case 'a*b + c' CImg &pop = code.back(); - if (pop[0]==(ulongT)mp_mul && _cimg_mp_is_comp(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) { + if (pop[0]==(ulongT)mp_mul && is_comp_scalar(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) { arg3 = (unsigned int)pop[1]; arg4 = (unsigned int)pop[2]; arg5 = (unsigned int)pop[3]; @@ -18456,20 +18465,20 @@ namespace cimg_library { _cimg_mp_op("Operator '-'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (!arg2) _cimg_mp_return(arg1); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_sub,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_sub,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) { + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (!arg2) _cimg_mp_same(arg1); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_sub,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_sub,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) { if (!arg1) _cimg_mp_vector1_v(mp_minus,arg2); _cimg_mp_vector2_sv(mp_sub,arg1,arg2); } - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1] - mem[arg2]); if (!arg1) _cimg_mp_scalar1(mp_minus,arg2); if (code) { // Try to spot linear cases 'a*b - c' and 'c - a*b' CImg &pop = code.back(); - if (pop[0]==(ulongT)mp_mul && _cimg_mp_is_comp(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) { + if (pop[0]==(ulongT)mp_mul && is_comp_scalar(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) { arg3 = (unsigned int)pop[1]; arg4 = (unsigned int)pop[2]; arg5 = (unsigned int)pop[3]; @@ -18490,17 +18499,17 @@ namespace cimg_library { arg2 = compile(s + 2,se,depth1,0,block_flags); _cimg_mp_check_type(arg1,1,3,2); _cimg_mp_check_type(arg2,2,3,2); - if (arg2==1) _cimg_mp_return(arg1); - if (arg1==1) _cimg_mp_return(arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) { + if (arg2==1) _cimg_mp_same(arg1); + if (arg1==1) _cimg_mp_same(arg2); + if (is_vector(arg1) && is_vector(arg2)) { pos = vector(2); CImg::vector((ulongT)mp_complex_mul,pos,arg1,arg2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_mul,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_mul,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_mul,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_mul,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]*mem[arg2]); if (!arg1 || !arg2) _cimg_mp_return(0); _cimg_mp_scalar2(mp_mul,arg1,arg2); @@ -18513,21 +18522,21 @@ namespace cimg_library { arg2 = compile(s + 2,se,depth1,0,block_flags); _cimg_mp_check_type(arg1,1,3,2); _cimg_mp_check_type(arg2,2,3,2); - if (arg2==1) _cimg_mp_return(arg1); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) { + if (arg2==1) _cimg_mp_same(arg1); + if (is_vector(arg1) && is_vector(arg2)) { pos = vector(2); CImg::vector((ulongT)mp_complex_div_vv,pos,arg1,arg2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_div,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) { + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_div,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) { pos = vector(2); CImg::vector((ulongT)mp_complex_div_sv,pos,arg1,arg2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]/mem[arg2]); if (!arg1) _cimg_mp_return(0); _cimg_mp_scalar2(mp_div,arg1,arg2); @@ -18537,25 +18546,25 @@ namespace cimg_library { _cimg_mp_op("Operator '*'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - p2 = _cimg_mp_size(arg2); - if (p2>0 && (ulongT)_cimg_mp_size(arg1)==(ulongT)p2*p2) { // Particular case of matrix multiplication + p2 = size(arg2); + if (p2>0 && (ulongT)size(arg1)==(ulongT)p2*p2) { // Particular case of matrix multiplication pos = vector(p2); CImg::vector((ulongT)mp_matrix_mul,pos,arg1,arg2,p2,p2,1).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (arg2==1) _cimg_mp_return(arg1); - if (arg1==1) _cimg_mp_return(arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_mul,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_mul,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_mul,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (arg2==1) _cimg_mp_same(arg1); + if (arg1==1) _cimg_mp_same(arg2); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_mul,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_mul,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_mul,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]*mem[arg2]); if (code) { // Try to spot double multiplication 'a*b*c' CImg &pop = code.back(); - if (pop[0]==(ulongT)mp_mul && _cimg_mp_is_comp(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) { + if (pop[0]==(ulongT)mp_mul && is_comp_scalar(pop[1]) && (pop[1]==arg1 || pop[1]==arg2)) { arg3 = (unsigned int)pop[1]; arg4 = (unsigned int)pop[2]; arg5 = (unsigned int)pop[3]; @@ -18572,12 +18581,12 @@ namespace cimg_library { _cimg_mp_op("Operator '/'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (arg2==1) _cimg_mp_return(arg1); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_div,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_div,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_div,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (arg2==1) _cimg_mp_same(arg1); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_div,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_div,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_div,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(mem[arg1]/mem[arg2]); if (!arg1) _cimg_mp_return(0); _cimg_mp_scalar2(mp_div,arg1,arg2); @@ -18588,11 +18597,11 @@ namespace cimg_library { _cimg_mp_op("Operator '%'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_modulo,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_modulo,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_modulo,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_modulo,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_modulo,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_modulo,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(cimg::mod(mem[arg1],mem[arg2])); _cimg_mp_scalar2(mp_modulo,arg1,arg2); } @@ -18606,8 +18615,8 @@ namespace cimg_library { if (*ss=='-' && (*ss1!='-' || (ss2='0' && *ss2<='9'))) { // Unary minus ('-') _cimg_mp_op("Operator '-'"); arg1 = compile(ss1,se,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_minus,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(-mem[arg1]); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_minus,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(-mem[arg1]); _cimg_mp_scalar1(mp_minus,arg1); } @@ -18615,21 +18624,21 @@ namespace cimg_library { _cimg_mp_op("Operator '!'"); if (*ss1=='!') { // '!!expr' optimized as 'bool(expr)' arg1 = compile(ss2,se,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_bool,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar((bool)mem[arg1]); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_bool,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar((bool)mem[arg1]); _cimg_mp_scalar1(mp_bool,arg1); } arg1 = compile(ss1,se,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_logical_not,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(!mem[arg1]); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_logical_not,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(!mem[arg1]); _cimg_mp_scalar1(mp_logical_not,arg1); } if (*ss=='~') { // Bitwise not ('~') _cimg_mp_op("Operator '~'"); arg1 = compile(ss1,se,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_bitwise_not,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(~(unsigned int)mem[arg1]); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_bitwise_not,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(~(unsigned int)mem[arg1]); _cimg_mp_scalar1(mp_bitwise_not,arg1); } } @@ -18641,16 +18650,22 @@ namespace cimg_library { arg2 = compile(s + 2,se,depth1,0,block_flags); _cimg_mp_check_type(arg1,1,3,2); _cimg_mp_check_type(arg2,2,3,2); - if (arg2==1) _cimg_mp_return(arg1); + if (arg2==1) _cimg_mp_same(arg1); pos = vector(2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) - CImg::vector((ulongT)mp_complex_pow_vv,pos,arg1,arg2).move_to(code); - else if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) - CImg::vector((ulongT)mp_complex_pow_vs,pos,arg1,arg2).move_to(code); - else if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) - CImg::vector((ulongT)mp_complex_pow_sv,pos,arg1,arg2).move_to(code); - else - CImg::vector((ulongT)mp_complex_pow_ss,pos,arg1,arg2).move_to(code); + if (!arg2) CImg::vector((ulongT)mp_complex_one,pos).move_to(code); + else if (arg2==2) { + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_sqr,pos,arg1,0).move_to(code); + else CImg::vector((ulongT)mp_complex_sqr,pos,arg1 + 1,arg1 + 2).move_to(code); + } else { + if (is_vector(arg1) && is_vector(arg2)) + CImg::vector((ulongT)mp_complex_pow_vv,pos,arg1,arg2).move_to(code); + else if (is_vector(arg1) && is_scalar(arg2)) + CImg::vector((ulongT)mp_complex_pow_vs,pos,arg1,arg2).move_to(code); + else if (is_scalar(arg1) && is_vector(arg2)) + CImg::vector((ulongT)mp_complex_pow_sv,pos,arg1,arg2).move_to(code); + else + CImg::vector((ulongT)mp_complex_pow_ss,pos,arg1,arg2).move_to(code); + } return_new_comp = true; _cimg_mp_return(pos); } @@ -18660,12 +18675,12 @@ namespace cimg_library { _cimg_mp_op("Operator '^'"); arg1 = compile(ss,s,depth1,0,block_flags); arg2 = compile(s + 1,se,depth1,0,block_flags); - _cimg_mp_check_type(arg2,2,3,_cimg_mp_size(arg1)); - if (arg2==1) _cimg_mp_return(arg1); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_vv(mp_pow,arg1,arg2); - if (_cimg_mp_is_vector(arg1) && _cimg_mp_is_scalar(arg2)) _cimg_mp_vector2_vs(mp_pow,arg1,arg2); - if (_cimg_mp_is_scalar(arg1) && _cimg_mp_is_vector(arg2)) _cimg_mp_vector2_sv(mp_pow,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) + _cimg_mp_check_type(arg2,2,3,size(arg1)); + if (arg2==1) _cimg_mp_same(arg1); + if (is_vector(arg1) && is_vector(arg2)) _cimg_mp_vector2_vv(mp_pow,arg1,arg2); + if (is_vector(arg1) && is_scalar(arg2)) _cimg_mp_vector2_vs(mp_pow,arg1,arg2); + if (is_scalar(arg1) && is_vector(arg2)) _cimg_mp_vector2_sv(mp_pow,arg1,arg2); + if (is_const_scalar(arg1) && is_const_scalar(arg2)) _cimg_mp_const_scalar(std::pow(mem[arg1],mem[arg2])); switch (arg2) { case 0 : _cimg_mp_return(1); @@ -18673,7 +18688,7 @@ namespace cimg_library { case 3 : _cimg_mp_scalar1(mp_pow3,arg1); case 4 : _cimg_mp_scalar1(mp_pow4,arg1); default : - if (_cimg_mp_is_const_scalar(arg2)) { + if (is_const_scalar(arg2)) { if (mem[arg2]==0.5) { _cimg_mp_scalar1(mp_sqrt,arg1); } else if (mem[arg2]==0.25) { _cimg_mp_scalar1(mp_pow0_25,arg1); } } @@ -18684,17 +18699,17 @@ namespace cimg_library { // Percentage computation. if (*se1=='%') { arg1 = compile(ss,se1,depth1,0,block_flags); - arg2 = _cimg_mp_is_const_scalar(arg1)?0:const_scalar(100); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector2_vs(mp_div,arg1,arg2); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(mem[arg1]/100); + arg2 = is_const_scalar(arg1)?0:const_scalar(100); + if (is_vector(arg1)) _cimg_mp_vector2_vs(mp_div,arg1,arg2); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(mem[arg1]/100); _cimg_mp_scalar2(mp_div,arg1,arg2); } // Degree to radian postfix operator ('°' in UTF-8). if (se2>ss && (unsigned char)*se2==0xC2 && (unsigned char)*se1==0xB0) { arg1 = compile(ss,se2,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_deg2rad,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(mem[arg1]*cimg::PI/180); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_deg2rad,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(mem[arg1]*cimg::PI/180); _cimg_mp_scalar1(mp_deg2rad,arg1); } @@ -18713,23 +18728,17 @@ namespace cimg_library { compile(ss,se2,depth1,ref,block_flags); // Variable slot // Apply operator on a copy to prevent modifying a constant or a variable. - if (*ref && (_cimg_mp_is_const_scalar(arg1) || _cimg_mp_is_vector(arg1) || _cimg_mp_is_reserved(arg1))) { - if (_cimg_mp_is_vector(arg1)) arg1 = vector_copy(arg1); - else arg1 = scalar1(mp_copy,arg1); - } + if (*ref && (is_const_scalar(arg1) || is_vector(arg1) || is_reserved(arg1))) + arg1 = copy(arg1); - if (is_sth) pos = arg1; // Determine return index, depending on pre/post action - else { - if (_cimg_mp_is_vector(arg1)) pos = vector_copy(arg1); - else pos = scalar1(mp_copy,arg1); - } + pos = is_sth?arg1:copy(arg1); // Determine return index, depending on pre/post action if (*ref==1) { // Vector value (scalar): V[k]++ arg3 = ref[1]; // Vector slot arg4 = ref[2]; // Index if (is_sth && p_ref) std::memcpy(p_ref,ref,ref._width*sizeof(unsigned int)); CImg::vector((ulongT)op,arg1,1).move_to(code); - CImg::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)_cimg_mp_size(arg3),arg4). + CImg::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)size(arg3),arg4). move_to(code); _cimg_mp_return(pos); } @@ -18785,11 +18794,11 @@ namespace cimg_library { if (p1!=~0U) { if (!imglist) _cimg_mp_return(pos); CImg::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v), - arg1,p1,arg3,_cimg_mp_size(arg1)).move_to(code); + arg1,p1,arg3,size(arg1)).move_to(code); } else { if (!imgout) _cimg_mp_return(pos); CImg::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v), - arg1,arg3,_cimg_mp_size(arg1)).move_to(code); + arg1,arg3,size(arg1)).move_to(code); } _cimg_mp_return(pos); } @@ -18806,21 +18815,21 @@ namespace cimg_library { if (p1!=~0U) { if (!imglist) _cimg_mp_return(pos); CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v), - arg1,p1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code); + arg1,p1,arg3,arg4,arg5,size(arg1)).move_to(code); } else { if (!imgout) _cimg_mp_return(pos); CImg::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v), - arg1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code); + arg1,arg3,arg4,arg5,size(arg1)).move_to(code); } _cimg_mp_return(pos); } - if (_cimg_mp_is_vector(arg1)) { // Vector variable: V++ + if (is_vector(arg1)) { // Vector variable: V++ self_vector_s(arg1,op==mp_self_increment?mp_self_add:mp_self_sub,1); _cimg_mp_return(pos); } - if (_cimg_mp_is_reserved(arg1)) { // Scalar variable: s++ + if (is_reserved(arg1)) { // Scalar variable: s++ CImg::vector((ulongT)op,arg1).move_to(code); _cimg_mp_return(pos); } @@ -18835,7 +18844,7 @@ namespace cimg_library { "CImg<%s>::%s: %s: Invalid %slvalue '%s', " "in expression '%s'.", pixel_type(),_cimg_mp_calling_function,s_op, - _cimg_mp_is_const_scalar(arg1)?"const ":"", + is_const_scalar(arg1)?"const ":"", variable_name._data,s0); } @@ -18851,7 +18860,7 @@ namespace cimg_library { if (!is_sth && (*ss=='I' || *ss=='J') && *ss1=='[' && (reserved_label[(int)*ss]==~0U || - !_cimg_mp_is_vector(reserved_label[(int)*ss]))) { // Image value as a vector + !is_vector(reserved_label[(int)*ss]))) { // Image value as a vector if (*ss2=='#') { // Index specified s0 = ss3; while (s0ss && (*s0!='[' || level[s0 - expr._data]!=clevel)) --s0; if (s0>ss) { // Vector element arg1 = compile(ss,s0,depth1,0,block_flags); - if (_cimg_mp_is_scalar(arg1)) { + if (is_scalar(arg1)) { variable_name.assign(ss,(unsigned int)(s0 - ss + 1)).back() = 0; _cimg_mp_strerr; cimg::strellipsize(variable_name,64); @@ -18942,7 +18951,7 @@ namespace cimg_library { s1 = s0 + 1; while (s1 sub-vector extraction - p1 = _cimg_mp_size(arg1); + p1 = size(arg1); arg2 = compile(++s0,s1,depth1,0,block_flags); // Starting index s0 = ++s1; while (s0 vector value reference arg2 = compile(++s0,se1,depth1,0,block_flags); - if (_cimg_mp_is_const_scalar(arg2)) { // Constant index + if (is_const_scalar(arg2)) { // Constant index nb = (int)mem[arg2]; - if (nb>=0 && nb<(int)_cimg_mp_size(arg1)) _cimg_mp_return(arg1 + 1 + nb); + if (nb>=0 && nb<(int)size(arg1)) _cimg_mp_return(arg1 + 1 + nb); variable_name.assign(ss,(unsigned int)(s0 - ss)).back() = 0; _cimg_mp_strerr; cimg::strellipsize(variable_name,64); @@ -18969,15 +18978,15 @@ namespace cimg_library { "in expression '%s'.", pixel_type(),_cimg_mp_calling_function, variable_name._data,nb, - variable_name._data,_cimg_mp_size(arg1),s0); + variable_name._data,size(arg1),s0); } if (p_ref) { *p_ref = 1; p_ref[1] = arg1; p_ref[2] = arg2; - if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -1; // Prevent from being used in further optimization + if (is_comp_scalar(arg2)) memtype[arg2] = -1; // Prevent from being used in further optimization } - pos = scalar3(mp_vector_off,arg1,_cimg_mp_size(arg1),arg2); + pos = scalar3(mp_vector_off,arg1,size(arg1),arg2); memtype[pos] = -1; // Prevent from being used in further optimization _cimg_mp_return(pos); } @@ -19006,8 +19015,8 @@ namespace cimg_library { if (s01) { arg2 = arg1 + 1; @@ -19039,14 +19048,14 @@ namespace cimg_library { p_ref[3] = arg1; p_ref[4] = arg2; p_ref[5] = arg3; - if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -1; // Prevent from being used in further optimization - if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -1; - if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -1; - if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -1; + if (p1!=~0U && is_comp_scalar(p1)) memtype[p1] = -1; // Prevent from being used in further optimization + if (is_comp_scalar(arg1)) memtype[arg1] = -1; + if (is_comp_scalar(arg2)) memtype[arg2] = -1; + if (is_comp_scalar(arg3)) memtype[arg3] = -1; } p2 = ~0U; // 'p2' must be the dimension of the vector-valued operand if any if (p1==~0U) p2 = imgin._spectrum; - else if (_cimg_mp_is_const_scalar(p1)) { + else if (is_const_scalar(p1)) { p3 = (unsigned int)cimg::mod((int)mem[p1],imglist.width()); p2 = imglist[p3]._spectrum; } @@ -19083,8 +19092,8 @@ namespace cimg_library { if (s01) { arg2 = arg1 + 1; @@ -19124,11 +19133,11 @@ namespace cimg_library { p_ref[4] = arg2; p_ref[5] = arg3; p_ref[6] = arg4; - if (p1!=~0U && _cimg_mp_is_comp(p1)) memtype[p1] = -1; // Prevent from being used in further optimization - if (_cimg_mp_is_comp(arg1)) memtype[arg1] = -1; - if (_cimg_mp_is_comp(arg2)) memtype[arg2] = -1; - if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -1; - if (_cimg_mp_is_comp(arg4)) memtype[arg4] = -1; + if (p1!=~0U && is_comp_scalar(p1)) memtype[p1] = -1; // Prevent from being used in further optimization + if (is_comp_scalar(arg1)) memtype[arg1] = -1; + if (is_comp_scalar(arg2)) memtype[arg2] = -1; + if (is_comp_scalar(arg3)) memtype[arg3] = -1; + if (is_comp_scalar(arg4)) memtype[arg4] = -1; } if (p1!=~0U) { @@ -19167,8 +19176,8 @@ namespace cimg_library { if (!std::strncmp(ss,"abs(",4)) { // Absolute value _cimg_mp_op("Function 'abs()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_abs,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::abs(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_abs,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::abs(mem[arg1])); _cimg_mp_scalar1(mp_abs,arg1); } @@ -19181,32 +19190,32 @@ namespace cimg_library { if (!std::strncmp(ss,"acos(",5)) { // Arccos _cimg_mp_op("Function 'acos()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_acos,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::acos(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_acos,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::acos(mem[arg1])); _cimg_mp_scalar1(mp_acos,arg1); } if (!std::strncmp(ss,"acosh(",6)) { // Hyperbolic arccosine _cimg_mp_op("Function 'acosh()'"); arg1 = compile(ss6,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_acosh,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::acosh(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_acosh,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::acosh(mem[arg1])); _cimg_mp_scalar1(mp_acosh,arg1); } if (!std::strncmp(ss,"asinh(",6)) { // Hyperbolic arcsine _cimg_mp_op("Function 'asinh()'"); arg1 = compile(ss6,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_asinh,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::asinh(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_asinh,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::asinh(mem[arg1])); _cimg_mp_scalar1(mp_asinh,arg1); } if (!std::strncmp(ss,"atanh(",6)) { // Hyperbolic arctangent _cimg_mp_op("Function 'atanh()'"); arg1 = compile(ss6,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_atanh,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::atanh(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_atanh,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::atanh(mem[arg1])); _cimg_mp_scalar1(mp_atanh,arg1); } @@ -19220,7 +19229,7 @@ namespace cimg_library { _cimg_mp_check_type(arg1,1,1,0); s2 = ++s1; while (s2::vector((ulongT)(*ss3=='0'?mp_arg0:mp_arg),0,0,p2,arg1,arg2).move_to(l_opcode); for (s = ++s2; s'y').move_to(opcode); opcode[2] = opcode._height; - if (_cimg_mp_is_const_scalar(arg1)) { + if (is_const_scalar(arg1)) { p3-=1; // Number of args if (*ss3=='0') arg1 = (unsigned int)(mem[arg1]<0?mem[arg1] + p3:mem[arg1] + 1); else arg1 = (unsigned int)(mem[arg1]<0?mem[arg1] + p3:mem[arg1]); @@ -19255,16 +19264,16 @@ namespace cimg_library { if (!std::strncmp(ss,"asin(",5)) { // Arcsin _cimg_mp_op("Function 'asin()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_asin,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::asin(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_asin,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::asin(mem[arg1])); _cimg_mp_scalar1(mp_asin,arg1); } if (!std::strncmp(ss,"atan(",5)) { // Arctan _cimg_mp_op("Function 'atan()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_atan,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::atan(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_atan,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::atan(mem[arg1])); _cimg_mp_scalar1(mp_atan,arg1); } @@ -19273,11 +19282,11 @@ namespace cimg_library { s1 = ss6; while (s1 Error too much arguments if (p2>4) { @@ -19374,7 +19383,7 @@ namespace cimg_library { _cimg_mp_op("Function 'cabs()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); - if (_cimg_mp_is_scalar(arg1)) _cimg_mp_scalar2(mp_complex_abs,arg1,0); + if (is_scalar(arg1)) _cimg_mp_scalar2(mp_complex_abs,arg1,0); _cimg_mp_scalar2(mp_complex_abs,arg1 + 1,arg1 + 2); } @@ -19382,15 +19391,15 @@ namespace cimg_library { _cimg_mp_op("Function 'carg()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); - if (_cimg_mp_is_scalar(arg1)) _cimg_mp_scalar2(mp_atan2,0,arg1); + if (is_scalar(arg1)) _cimg_mp_scalar2(mp_atan2,0,arg1); _cimg_mp_scalar2(mp_atan2,arg1 + 2,arg1 + 1); } if (!std::strncmp(ss,"cbrt(",5)) { // Cubic root _cimg_mp_op("Function 'cbrt()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_cbrt,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::cbrt(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_cbrt,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::cbrt(mem[arg1])); _cimg_mp_scalar1(mp_cbrt,arg1); } @@ -19399,7 +19408,7 @@ namespace cimg_library { arg1 = compile(ss6,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_conj,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_conj,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_conj,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19408,8 +19417,8 @@ namespace cimg_library { if (!std::strncmp(ss,"ceil(",5)) { // Ceil _cimg_mp_op("Function 'ceil()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_ceil,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::ceil(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_ceil,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::ceil(mem[arg1])); _cimg_mp_scalar1(mp_ceil,arg1); } @@ -19418,7 +19427,7 @@ namespace cimg_library { arg1 = compile(ss5,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_exp,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_exp,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_exp,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19429,7 +19438,7 @@ namespace cimg_library { arg1 = compile(ss5,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_log,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_log,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_log,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19440,7 +19449,7 @@ namespace cimg_library { arg1 = compile(ss5,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_cos,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_cos,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_cos,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19451,18 +19460,29 @@ namespace cimg_library { arg1 = compile(ss5,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_sin,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_sin,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_sin,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } + if (!std::strncmp(ss,"csqr(",5)) { // Complex square + _cimg_mp_op("Function 'csqr()'"); + arg1 = compile(ss5,se1,depth1,0,block_flags); + _cimg_mp_check_type(arg1,0,3,2); + pos = vector(2); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_sqr,pos,arg1,0).move_to(code); + else CImg::vector((ulongT)mp_complex_sqr,pos,arg1 + 1,arg1 + 2).move_to(code); + return_new_comp = true; + _cimg_mp_return(pos); + } + if (!std::strncmp(ss,"csqrt(",6)) { // Complex square root _cimg_mp_op("Function 'csqrt()'"); arg1 = compile(ss6,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_sqrt,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_sqrt,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_sqrt,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19473,7 +19493,7 @@ namespace cimg_library { arg1 = compile(ss5,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_tan,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_tan,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_tan,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19484,7 +19504,7 @@ namespace cimg_library { arg1 = compile(ss6,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_cosh,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_cosh,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_cosh,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19495,7 +19515,7 @@ namespace cimg_library { arg1 = compile(ss6,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_sinh,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_sinh,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_sinh,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19506,7 +19526,7 @@ namespace cimg_library { arg1 = compile(ss6,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,0,3,2); pos = vector(2); - if (_cimg_mp_is_scalar(arg1)) CImg::vector((ulongT)mp_complex_tanh,pos,arg1,0).move_to(code); + if (is_scalar(arg1)) CImg::vector((ulongT)mp_complex_tanh,pos,arg1,0).move_to(code); else CImg::vector((ulongT)mp_complex_tanh,pos,arg1 + 1,arg1 + 2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); @@ -19540,12 +19560,12 @@ namespace cimg_library { } } } - if (_cimg_mp_is_vector(arg1)) { + if (is_vector(arg1)) { if (!ref[0]) ++arg1; else if (ref[0]>=4 && arg4==~0U) arg4 = scalar1(mp_image_whd,ref[1]); } - if (_cimg_mp_is_vector(arg2)) { - if (arg3==~0U) arg3 = const_scalar(_cimg_mp_size(arg2)); + if (is_vector(arg2)) { + if (arg3==~0U) arg3 = const_scalar(size(arg2)); if (!ref[7]) ++arg2; if (ref[7]>=4 && arg5==~0U) arg5 = scalar1(mp_image_whd,ref[8]); } @@ -19565,16 +19585,16 @@ namespace cimg_library { if (!std::strncmp(ss,"cos(",4)) { // Cosine _cimg_mp_op("Function 'cos()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_cos,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::cos(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_cos,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::cos(mem[arg1])); _cimg_mp_scalar1(mp_cos,arg1); } if (!std::strncmp(ss,"cosh(",5)) { // Hyperbolic cosine _cimg_mp_op("Function 'cosh()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_cosh,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::cosh(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_cosh,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::cosh(mem[arg1])); _cimg_mp_scalar1(mp_cosh,arg1); } @@ -19590,11 +19610,11 @@ namespace cimg_library { arg3 = compile(s2,s1,depth1,0,block_flags); arg4 = s11) _cimg_mp_check_type(arg1,pos,1,0); CImg::vector(arg1).move_to(l_opcode); s = ns; @@ -19774,7 +19794,7 @@ namespace cimg_library { opcode[3] = (ulongT)mem[opcode[3]]; _cimg_mp_check_const_scalar((unsigned int)opcode[4],5,3); // s opcode[4] = (ulongT)mem[opcode[4]]; - p1 = _cimg_mp_size((unsigned int)opcode[0]); + p1 = size((unsigned int)opcode[0]); arg2 = (unsigned int)opcode[1]; arg3 = (unsigned int)opcode[2]; arg4 = (unsigned int)opcode[3]; @@ -19838,8 +19858,8 @@ namespace cimg_library { arg3 = compile(++s2,se1,depth1,0,block_flags); _cimg_mp_check_type(arg2,2,1,0); _cimg_mp_check_type(arg3,3,1,0); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector3_vss(mp_cut,arg1,arg2,arg3); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2) && _cimg_mp_is_const_scalar(arg3)) { + if (is_vector(arg1)) _cimg_mp_vector3_vss(mp_cut,arg1,arg2,arg3); + if (is_const_scalar(arg1) && is_const_scalar(arg2) && is_const_scalar(arg3)) { val = mem[arg1]; val1 = mem[arg2]; val2 = mem[arg3]; @@ -19854,7 +19874,7 @@ namespace cimg_library { s1 = s0; while (s1::vector((ulongT)mp_date,pos,_cimg_mp_size(pos), - arg1,arg1==~0U?~0U:_cimg_mp_size(arg1), - arg2,arg2==~0U?~0U:_cimg_mp_size(arg2)).move_to(code); + pos = arg1==~0U || is_vector(arg1)?vector(arg1==~0U?7:size(arg1)):scalar(); + CImg::vector((ulongT)mp_date,pos,size(pos), + arg1,arg1==~0U?~0U:size(arg1), + arg2,arg2==~0U?~0U:size(arg2)).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } @@ -20183,8 +20203,8 @@ namespace cimg_library { if (!std::strncmp(ss,"deg2rad(",8)) { // Degrees to radians _cimg_mp_op("Function 'deg2rad()'"); arg1 = compile(ss8,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_deg2rad,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(mem[arg1]*cimg::PI/180); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_deg2rad,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(mem[arg1]*cimg::PI/180); _cimg_mp_scalar1(mp_deg2rad,arg1); } @@ -20219,8 +20239,8 @@ namespace cimg_library { c1 = *s1; *s1 = 0; variable_name.assign(CImg::string(ss8,true,true).unroll('y'),true); cimg::strpare(variable_name,false,true); - if (_cimg_mp_is_vector(arg1)) - ((CImg::vector((ulongT)mp_vector_print,arg1,0,(ulongT)_cimg_mp_size(arg1),0), + if (is_vector(arg1)) + ((CImg::vector((ulongT)mp_vector_print,arg1,0,(ulongT)size(arg1),0), variable_name)>'y').move_to(opcode); else ((CImg::vector((ulongT)mp_print,arg1,0,0), @@ -20228,7 +20248,7 @@ namespace cimg_library { opcode[2] = opcode._height; opcode.move_to(code); - ((CImg::vector((ulongT)mp_display,arg1,0,(ulongT)_cimg_mp_size(arg1), + ((CImg::vector((ulongT)mp_display,arg1,0,(ulongT)size(arg1), arg2,arg3,arg4,arg5), variable_name)>'y').move_to(opcode); opcode[2] = opcode._height; @@ -20248,7 +20268,7 @@ namespace cimg_library { _cimg_mp_op("Function 'det()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); _cimg_mp_check_matrix_square(arg1,1); - p1 = (unsigned int)cimg::round(std::sqrt((float)_cimg_mp_size(arg1))); + p1 = (unsigned int)cimg::round(std::sqrt((float)size(arg1))); _cimg_mp_scalar2(mp_det,arg1,p1); } @@ -20259,9 +20279,9 @@ namespace cimg_library { ns = s; while (ns::sequence(_cimg_mp_size(arg2),arg2 + 1, - arg2 + (ulongT)_cimg_mp_size(arg2)). + if (is_vector(arg2)) + CImg::sequence(size(arg2),arg2 + 1, + arg2 + (ulongT)size(arg2)). move_to(l_opcode); else CImg::vector(arg2).move_to(l_opcode); s = ns; @@ -20281,9 +20301,9 @@ namespace cimg_library { s1 = ss4; while (s1::vector((ulongT)mp_do,p1,p2,arg2 - arg1,code._width - arg2,_cimg_mp_size(p1), - p1>=arg6 && !_cimg_mp_is_const_scalar(p1), - p2>=arg6 && !_cimg_mp_is_const_scalar(p2)).move_to(code,arg1); + CImg::vector((ulongT)mp_do,p1,p2,arg2 - arg1,code._width - arg2,size(p1), + p1>=arg6 && !is_const_scalar(p1), + p2>=arg6 && !is_const_scalar(p2)).move_to(code,arg1); _cimg_mp_return(p1); } @@ -20323,7 +20343,7 @@ namespace cimg_library { } (l_opcode>'y').move_to(opcode); - is_sth = p1==~0U && opcode._height>5 && _cimg_mp_is_vector((unsigned int)opcode[5]); // Is vector drawing? + is_sth = p1==~0U && opcode._height>5 && is_vector((unsigned int)opcode[5]); // Is vector drawing? if ((is_sth && (opcode._height<6 || opcode._height>17)) || (!is_sth && (opcode._height<1 || opcode._height>12))) { _cimg_mp_strerr; @@ -20341,37 +20361,37 @@ namespace cimg_library { _cimg_mp_check_type((unsigned int)opcode[3],4,1,0); // d _cimg_mp_check_type((unsigned int)opcode[4],5,1,0); // s - if (opcode._height<8 || (opcode._height<10 && _cimg_mp_is_vector((unsigned int)opcode[7]))) { + if (opcode._height<8 || (opcode._height<10 && is_vector((unsigned int)opcode[7]))) { // D,w,h,d,s,S[,opac,M,maxM] if (opcode._height>6) _cimg_mp_check_type((unsigned int)opcode[6],7,1,0); // opac if (opcode._height>8) _cimg_mp_check_type((unsigned int)opcode[8],9,1,0); // maxM CImg::vector((ulongT)mp_vector_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode), // 1-2: D,sizD + *opcode,size((unsigned int)*opcode), // 1-2: D,sizD opcode[1],opcode[2],opcode[3],opcode[4], // 3-6: w,h,d,s - opcode[5],_cimg_mp_size((unsigned int)opcode[5]), // 7-8: S,sizS + opcode[5],size((unsigned int)opcode[5]), // 7-8: S,sizS 0,0,0,0, // 9-12: x,y,z,c ~0U,~0U,~0U,~0U, // 13-16: dx,dy,dz,dc opcode._height<7?1:opcode[6], // 17: opac opcode._height<8?~0U:opcode[7], // 18: M - opcode._height<8?0:_cimg_mp_size((unsigned int)opcode[7]), // 19: sizM + opcode._height<8?0:size((unsigned int)opcode[7]), // 19: sizM opcode._height<9?1:opcode[8]).move_to(code); // 20: maxM - } else if (opcode._height<10 || (opcode._height<12 && _cimg_mp_is_vector((unsigned int)opcode[9]))) { + } else if (opcode._height<10 || (opcode._height<12 && is_vector((unsigned int)opcode[9]))) { // D,w,h,d,s,S,x,dx[,opac,M,maxM] _cimg_mp_check_type((unsigned int)opcode[6],7,1,0); // x _cimg_mp_check_type((unsigned int)opcode[7],8,1,0); // dx if (opcode._height>8) _cimg_mp_check_type((unsigned int)opcode[8],9,1,0); // opac if (opcode._height>10) _cimg_mp_check_type((unsigned int)opcode[10],11,1,0); // maxM CImg::vector((ulongT)mp_vector_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode), // 1-2: D,sizD + *opcode,size((unsigned int)*opcode), // 1-2: D,sizD opcode[1],opcode[2],opcode[3],opcode[4], // 3-6: w,h,d,s - opcode[5],_cimg_mp_size((unsigned int)opcode[5]), // 7-8: S,sizS + opcode[5],size((unsigned int)opcode[5]), // 7-8: S,sizS opcode[6],0,0,0, // 9-12: x,y,z,c opcode[7],~0U,~0U,~0U, // 13-16: dx,dy,dz,dc opcode._height<9?1:opcode[8], // 17: opac opcode._height<10?~0U:opcode[9], // 18: M - opcode._height<10?0:_cimg_mp_size((unsigned int)opcode[9]), // 19: sizM + opcode._height<10?0:size((unsigned int)opcode[9]), // 19: sizM opcode._height<11?1:opcode[10]).move_to(code); // 20: maxM - } else if (opcode._height<12 || (opcode._height<14 && _cimg_mp_is_vector((unsigned int)opcode[11]))) { + } else if (opcode._height<12 || (opcode._height<14 && is_vector((unsigned int)opcode[11]))) { // D,w,h,d,s,S,x,y,dx,dy[,opac,M,maxM] _cimg_mp_check_type((unsigned int)opcode[6],7,1,0); // x _cimg_mp_check_type((unsigned int)opcode[7],8,1,0); // y @@ -20380,16 +20400,16 @@ namespace cimg_library { if (opcode._height>10) _cimg_mp_check_type((unsigned int)opcode[10],11,1,0); // opac if (opcode._height>12) _cimg_mp_check_type((unsigned int)opcode[12],13,1,0); // maxM CImg::vector((ulongT)mp_vector_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode), // 1-2: D,sizD + *opcode,size((unsigned int)*opcode), // 1-2: D,sizD opcode[1],opcode[2],opcode[3],opcode[4], // 3-6: w,h,d,s - opcode[5],_cimg_mp_size((unsigned int)opcode[5]), // 7-8: S,sizS + opcode[5],size((unsigned int)opcode[5]), // 7-8: S,sizS opcode[6],opcode[7],0,0, // 9-12: x,y,z,c opcode[8],opcode[9],~0U,~0U, // 13-16: dx,dy,dz,dc opcode._height<11?1:opcode[10], // 17: opac opcode._height<12?~0U:opcode[11], // 18: M - opcode._height<12?0:_cimg_mp_size((unsigned int)opcode[11]), // 19: sizM + opcode._height<12?0:size((unsigned int)opcode[11]), // 19: sizM opcode._height<13?1:opcode[12]).move_to(code); // 20: maxM - } else if (opcode._height<14 || (opcode._height<16 && _cimg_mp_is_vector((unsigned int)opcode[13]))) { + } else if (opcode._height<14 || (opcode._height<16 && is_vector((unsigned int)opcode[13]))) { // D,w,h,d,s,S,x,y,z,dx,dy,dz[,opac,M,maxM] _cimg_mp_check_type((unsigned int)opcode[6],7,1,0); // x _cimg_mp_check_type((unsigned int)opcode[7],8,1,0); // y @@ -20400,16 +20420,16 @@ namespace cimg_library { if (opcode._height>12) _cimg_mp_check_type((unsigned int)opcode[12],13,1,0); // opac if (opcode._height>14) _cimg_mp_check_type((unsigned int)opcode[14],15,1,0); // maxM CImg::vector((ulongT)mp_vector_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode), // 1-2: D,sizD + *opcode,size((unsigned int)*opcode), // 1-2: D,sizD opcode[1],opcode[2],opcode[3],opcode[4], // 3-6: w,h,d,s - opcode[5],_cimg_mp_size((unsigned int)opcode[5]), // 7-8: S,sizS + opcode[5],size((unsigned int)opcode[5]), // 7-8: S,sizS opcode[6],opcode[7],opcode[8],0, // 9-12: x,y,z,c opcode[9],opcode[10],opcode[11],~0U, // 13-16: dx,dy,dz,dc opcode._height<13?1:opcode[12], // 17: opac opcode._height<14?~0U:opcode[13], // 18: M - opcode._height<14?0:_cimg_mp_size((unsigned int)opcode[13]), // 19: sizM + opcode._height<14?0:size((unsigned int)opcode[13]), // 19: sizM opcode._height<15?1:opcode[14]).move_to(code); // 20: maxM - } else if (opcode._height<16 || (opcode._height<18 && _cimg_mp_is_vector((unsigned int)opcode[15]))) { + } else if (opcode._height<16 || (opcode._height<18 && is_vector((unsigned int)opcode[15]))) { // D,w,h,d,s,S,x,y,z,c,dx,dy,dz,dc[,opac,M,maxM] _cimg_mp_check_type((unsigned int)opcode[6],7,1,0); // x _cimg_mp_check_type((unsigned int)opcode[7],8,1,0); // y @@ -20422,14 +20442,14 @@ namespace cimg_library { if (opcode._height>14) _cimg_mp_check_type((unsigned int)opcode[14],15,1,0); // opac if (opcode._height>16) _cimg_mp_check_type((unsigned int)opcode[16],17,1,0); // maxM CImg::vector((ulongT)mp_vector_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode), // 1-2: D,sizD + *opcode,size((unsigned int)*opcode), // 1-2: D,sizD opcode[1],opcode[2],opcode[3],opcode[4], // 3-6: w,h,d,s - opcode[5],_cimg_mp_size((unsigned int)opcode[5]), // 7-8: S,sizS + opcode[5],size((unsigned int)opcode[5]), // 7-8: S,sizS opcode[6],opcode[7],opcode[8],opcode[9], // 9-12: x,y,z,c opcode[10],opcode[11],opcode[12],opcode[13], // 13-16: dx,dy,dz,dc opcode._height<15?1:opcode[14], // 17: opac opcode._height<16?~0U:opcode[15], // 18: M - opcode._height<16?0:_cimg_mp_size((unsigned int)opcode[15]), // 19: sizM + opcode._height<16?0:size((unsigned int)opcode[15]), // 19: sizM opcode._height<17?1:opcode[16]).move_to(code); // 20: maxM } else { _cimg_mp_strerr; @@ -20443,33 +20463,33 @@ namespace cimg_library { if (!is_inside_critical) is_parallelizable = false; arg1 = p1!=~0U; _cimg_mp_check_type((unsigned int)*opcode,1 + arg1,2,0); // S - if (opcode._height<3 || (opcode._height<5 && _cimg_mp_is_vector((unsigned int)opcode[2]))) { + if (opcode._height<3 || (opcode._height<5 && is_vector((unsigned int)opcode[2]))) { // S[,opac,M,maxM] if (opcode._height>1) _cimg_mp_check_type((unsigned int)opcode[1],2 + arg1,1,0); // opac if (opcode._height>3) _cimg_mp_check_type((unsigned int)opcode[3],4 + arg1,1,0); // maxM CImg::vector((ulongT)mp_image_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind + *opcode,size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind 0,0,0,0, // 4-7: x,y,z,c ~0U,~0U,~0U,~0U, // 8-11: dx,dy,dz,dc opcode._height<2?1:opcode[1], // 12: opac opcode._height<3?~0U:opcode[2], // 13: M - opcode._height<3?0:_cimg_mp_size((unsigned int)opcode[2]), // 14: sizM + opcode._height<3?0:size((unsigned int)opcode[2]), // 14: sizM opcode._height<4?1:opcode[3]).move_to(code); // 15: maxM - } else if (opcode._height<5 || (opcode._height<7 && _cimg_mp_is_vector((unsigned int)opcode[4]))) { + } else if (opcode._height<5 || (opcode._height<7 && is_vector((unsigned int)opcode[4]))) { // x,dx,S[,opac,M,maxM] _cimg_mp_check_type((unsigned int)opcode[1],2 + arg1,1,0); // x _cimg_mp_check_type((unsigned int)opcode[2],3 + arg1,1,0); // dx if (opcode._height>3) _cimg_mp_check_type((unsigned int)opcode[3],4 + arg1,1,0); // opac if (opcode._height>5) _cimg_mp_check_type((unsigned int)opcode[5],6 + arg1,1,0); // maxM CImg::vector((ulongT)mp_image_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind + *opcode,size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind opcode[1],0,0,0, // 4-7: x,y,z,c opcode[2],~0U,~0U,~0U, // 8-11: dx,dy,dz,dc opcode._height<4?1:opcode[3], // 12: opac opcode._height<5?~0U:opcode[4], // 13: M - opcode._height<5?0:_cimg_mp_size((unsigned int)opcode[4]), // 14: sizM + opcode._height<5?0:size((unsigned int)opcode[4]), // 14: sizM opcode._height<6?1:opcode[5]).move_to(code); // 15: maxM - } else if (opcode._height<7 || (opcode._height<9 && _cimg_mp_is_vector((unsigned int)opcode[6]))) { + } else if (opcode._height<7 || (opcode._height<9 && is_vector((unsigned int)opcode[6]))) { // x,y,dx,dy,S[,opac,M,maxM] _cimg_mp_check_type((unsigned int)opcode[1],2 + arg1,1,0); // x _cimg_mp_check_type((unsigned int)opcode[2],3 + arg1,1,0); // y @@ -20478,14 +20498,14 @@ namespace cimg_library { if (opcode._height>5) _cimg_mp_check_type((unsigned int)opcode[5],6 + arg1,1,0); // opac if (opcode._height>7) _cimg_mp_check_type((unsigned int)opcode[7],8 + arg1,1,0); // maxM CImg::vector((ulongT)mp_image_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind + *opcode,size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind opcode[1],opcode[2],0,0, // 4-7: x,y,z,c opcode[3],opcode[4],~0U,~0U, // 8-11: dx,dy,dz,dc opcode._height<6?1:opcode[5], // 12: opac opcode._height<7?~0U:opcode[6], // 13: M - opcode._height<7?0:_cimg_mp_size((unsigned int)opcode[6]), // 14: sizM + opcode._height<7?0:size((unsigned int)opcode[6]), // 14: sizM opcode._height<8?1:opcode[7]).move_to(code); // 15: maxM - } else if (opcode._height<9 || (opcode._height<11 && _cimg_mp_is_vector((unsigned int)opcode[8]))) { + } else if (opcode._height<9 || (opcode._height<11 && is_vector((unsigned int)opcode[8]))) { // x,y,z,dx,dy,dz,S[,opac,M,maxM] _cimg_mp_check_type((unsigned int)opcode[1],2 + arg1,1,0); // x _cimg_mp_check_type((unsigned int)opcode[2],3 + arg1,1,0); // y @@ -20496,14 +20516,14 @@ namespace cimg_library { if (opcode._height>7) _cimg_mp_check_type((unsigned int)opcode[7],8 + arg1,1,0); // opac if (opcode._height>9) _cimg_mp_check_type((unsigned int)opcode[9],10 + arg1,1,0); // maxM CImg::vector((ulongT)mp_image_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind + *opcode,size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind opcode[1],opcode[2],opcode[3],0, // 4-7: x,y,z,c opcode[4],opcode[5],opcode[6],~0U, // 8-11: dx,dy,dz,dc opcode._height<8?1:opcode[7], // 12: opac opcode._height<9?~0U:opcode[8], // 13: M - opcode._height<9?0:_cimg_mp_size((unsigned int)opcode[8]), // 14: sizM + opcode._height<9?0:size((unsigned int)opcode[8]), // 14: sizM opcode._height<10?1:opcode[9]).move_to(code); // 15: maxM - } else if (opcode._height<11 || (opcode._height<13 && _cimg_mp_is_vector((unsigned int)opcode[10]))) { + } else if (opcode._height<11 || (opcode._height<13 && is_vector((unsigned int)opcode[10]))) { // x,y,z,c,dx,dy,dz,dc,S[,opac,M,maxM] _cimg_mp_check_type((unsigned int)opcode[1],2 + arg1,1,0); // x _cimg_mp_check_type((unsigned int)opcode[2],3 + arg1,1,0); // y @@ -20516,12 +20536,12 @@ namespace cimg_library { if (opcode._height>9) _cimg_mp_check_type((unsigned int)opcode[9],10 + arg1,1,0); // opac if (opcode._height>11) _cimg_mp_check_type((unsigned int)opcode[11],12 + arg1,1,0); // maxM CImg::vector((ulongT)mp_image_draw, - *opcode,_cimg_mp_size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind + *opcode,size((unsigned int)*opcode),p1, // 1-3: S,sizS,#ind opcode[1],opcode[2],opcode[3],opcode[4], // 4-7: x,y,z,c opcode[5],opcode[6],opcode[7],opcode[8], // 8-11: dx,dy,dz,dc opcode._height<10?1:opcode[9], // 12: opac opcode._height<11?~0U:opcode[10], // 13: M - opcode._height<11?0:_cimg_mp_size((unsigned int)opcode[10]), // 14: sizM + opcode._height<11?0:size((unsigned int)opcode[10]), // 14: sizM opcode._height<12?1:opcode[11]).move_to(code); // 15: maxM } else { _cimg_mp_strerr; @@ -20543,7 +20563,7 @@ namespace cimg_library { ns = s; while (ns::vector(arg1,_cimg_mp_size(arg1)).move_to(l_opcode); + CImg::vector(arg1,size(arg1)).move_to(l_opcode); s = ns; } (l_opcode>'y').move_to(opcode); @@ -20556,7 +20576,7 @@ namespace cimg_library { _cimg_mp_op("Function 'eig()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); _cimg_mp_check_matrix_square(arg1,1); - p1 = (unsigned int)cimg::round(std::sqrt((float)_cimg_mp_size(arg1))); + p1 = (unsigned int)cimg::round(std::sqrt((float)size(arg1))); pos = vector((p1 + 1)*p1); CImg::vector((ulongT)mp_matrix_eig,pos,arg1,p1).move_to(code); return_new_comp = true; @@ -20578,9 +20598,9 @@ namespace cimg_library { ns = s; while (ns::sequence(_cimg_mp_size(arg2),arg2 + 1, - arg2 + (ulongT)_cimg_mp_size(arg2)). + if (is_vector(arg2)) // Vector argument allowed to specify cordinates and color + CImg::sequence(size(arg2),arg2 + 1, + arg2 + (ulongT)size(arg2)). move_to(l_opcode); else CImg::vector(arg2).move_to(l_opcode); @@ -20609,7 +20629,7 @@ namespace cimg_library { _cimg_mp_check_const_scalar(arg2,2,3); if (arg3!=~0U) _cimg_mp_check_type(arg3,3,1,0); if (arg4!=~0U) _cimg_mp_check_type(arg4,3,1,0); - p1 = _cimg_mp_size(arg1); + p1 = size(arg1); arg2 = (unsigned int)mem[arg2]; pos = vector(p1); CImg::vector((ulongT)mp_vector_equalize,pos,arg1,p1,arg2,arg3,arg4).move_to(code); @@ -20621,8 +20641,8 @@ namespace cimg_library { if (!std::strncmp(ss,"erf(",4)) { // Error function _cimg_mp_op("Function 'erf()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_erf,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::erf(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_erf,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::erf(mem[arg1])); _cimg_mp_scalar1(mp_erf,arg1); } #endif @@ -20630,16 +20650,16 @@ namespace cimg_library { if (!std::strncmp(ss,"erfinv(",7)) { // Inverse of error function _cimg_mp_op("Function 'erfinv()'"); arg1 = compile(ss7,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_erfinv,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::erfinv(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_erfinv,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::erfinv(mem[arg1])); _cimg_mp_scalar1(mp_erfinv,arg1); } if (!std::strncmp(ss,"exp(",4)) { // Exponential _cimg_mp_op("Function 'exp()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_exp,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::exp(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_exp,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::exp(mem[arg1])); _cimg_mp_scalar1(mp_exp,arg1); } @@ -20648,7 +20668,7 @@ namespace cimg_library { s1 = ss5; while (s1uint conversion _cimg_mp_op("Function 'f2ui()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_f2ui,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar((double)cimg::float2uint((float)mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_f2ui,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar((double)cimg::float2uint((float)mem[arg1])); _cimg_mp_scalar1(mp_f2ui,arg1); } if (!std::strncmp(ss,"fact(",5)) { // Factorial _cimg_mp_op("Function 'fact()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_factorial,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::factorial((int)mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_factorial,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::factorial((int)mem[arg1])); _cimg_mp_scalar1(mp_factorial,arg1); } if (!std::strncmp(ss,"fibo(",5)) { // Fibonacci _cimg_mp_op("Function 'fibo()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_fibonacci,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::fibonacci((int)mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_fibonacci,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::fibonacci((int)mem[arg1])); _cimg_mp_scalar1(mp_fibonacci,arg1); } @@ -20746,7 +20766,7 @@ namespace cimg_library { _cimg_mp_op("Function 'fill()'"); s0 = ss5; while (s0::%s: %s: Target scalar is constant, " "in expression '%s'.", @@ -20767,8 +20787,8 @@ namespace cimg_library { } get_variable_pos(variable_name,arg2,arg3); arg2 = arg3!=~0U?reserved_label[arg3]:arg2!=~0U?variable_pos[arg2]:~0U; // Variable slot - if (arg2!=~0U && (!_cimg_mp_is_scalar(arg2) || - _cimg_mp_is_const_scalar(arg2))) { // Variable is not a vector or is a constant->error + if (arg2!=~0U && (!is_scalar(arg2) || + is_const_scalar(arg2))) { // Variable is not a vector or is a constant->error cimg::strellipsize(variable_name,64); throw CImgArgumentException("[" cimg_appname "_math_parser] " "CImg<%s>::%s: %s: Invalid type '%s' for variable '%s' " @@ -20793,7 +20813,7 @@ namespace cimg_library { } // arg2 = variable slot, arg3 = fill expression. _cimg_mp_check_type(arg3,3,1,0); - CImg::vector((ulongT)mp_fill,arg1,_cimg_mp_size(arg1),arg2,arg3,code._width - p1). + CImg::vector((ulongT)mp_fill,arg1,size(arg1),arg2,arg3,code._width - p1). move_to(code,p1); _cimg_mp_return_nan(); } @@ -20830,13 +20850,13 @@ namespace cimg_library { } } if (p1!=~0U) { - if (_cimg_mp_size(arg2)>1) - _cimg_mp_scalar5(mp_list_find_seq,p1,arg2,_cimg_mp_size(arg2),arg3,arg4); - _cimg_mp_scalar4(mp_list_find,p1,arg2 + (_cimg_mp_size(arg2)?1:0),arg3,arg4); + if (size(arg2)>1) + _cimg_mp_scalar5(mp_list_find_seq,p1,arg2,size(arg2),arg3,arg4); + _cimg_mp_scalar4(mp_list_find,p1,arg2 + (size(arg2)?1:0),arg3,arg4); } - if (_cimg_mp_size(arg2)>1) - _cimg_mp_scalar6(mp_find_seq,arg1,_cimg_mp_size(arg1),arg2,_cimg_mp_size(arg2),arg3,arg4); - _cimg_mp_scalar5(mp_find,arg1,_cimg_mp_size(arg1),arg2 + (_cimg_mp_size(arg2)?1:0),arg3,arg4); + if (size(arg2)>1) + _cimg_mp_scalar6(mp_find_seq,arg1,size(arg1),arg2,size(arg2),arg3,arg4); + _cimg_mp_scalar5(mp_find,arg1,size(arg1),arg2 + (size(arg2)?1:0),arg3,arg4); } if (*ss1=='o' && *ss2=='r' && *ss3=='(') { // For loop @@ -20859,19 +20879,19 @@ namespace cimg_library { arg4 = pos = code._width; } _cimg_mp_check_type(p2,2,1,0); - arg5 = _cimg_mp_size(pos); - CImg::vector((ulongT)mp_for,p3,(ulongT)_cimg_mp_size(p3),p2,arg2 - arg1,arg3 - arg2, + arg5 = size(pos); + CImg::vector((ulongT)mp_for,p3,(ulongT)size(p3),p2,arg2 - arg1,arg3 - arg2, arg4 - arg3,code._width - arg4, - p3>=arg6 && !_cimg_mp_is_const_scalar(p3), - p2>=arg6 && !_cimg_mp_is_const_scalar(p2)).move_to(code,arg1); + p3>=arg6 && !is_const_scalar(p3), + p2>=arg6 && !is_const_scalar(p2)).move_to(code,arg1); _cimg_mp_return(p3); } if (!std::strncmp(ss,"floor(",6)) { // Floor _cimg_mp_op("Function 'floor()'"); arg1 = compile(ss6,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_floor,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::floor(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_floor,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::floor(mem[arg1])); _cimg_mp_scalar1(mp_floor,arg1); } @@ -20880,7 +20900,7 @@ namespace cimg_library { arg1 = compile(ss6,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,1,2,0); pos = scalar(); - CImg::vector((ulongT)mp_fsize,pos,arg1,(ulongT)_cimg_mp_size(arg1)).move_to(code); + CImg::vector((ulongT)mp_fsize,pos,arg1,(ulongT)size(arg1)).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } @@ -20891,8 +20911,8 @@ namespace cimg_library { if (!std::strncmp(ss,"gamma(",6)) { // Gamma _cimg_mp_op("Function 'gamma()'"); arg1 = compile(ss6,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_gamma,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::tgamma(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_gamma,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::tgamma(mem[arg1])); _cimg_mp_scalar1(mp_gamma,arg1); } #endif @@ -20909,8 +20929,8 @@ namespace cimg_library { } _cimg_mp_check_type(arg2,2,1,0); _cimg_mp_check_type(arg3,3,1,0); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector3_vss(mp_gauss,arg1,arg2,arg3); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2) && _cimg_mp_is_const_scalar(arg3)) { + if (is_vector(arg1)) _cimg_mp_vector3_vss(mp_gauss,arg1,arg2,arg3); + if (is_const_scalar(arg1) && is_const_scalar(arg2) && is_const_scalar(arg3)) { val1 = mem[arg1]; val2 = mem[arg2]; _cimg_mp_const_scalar(std::exp(-val1*val1/(2*val2*val2))/(mem[arg3]?std::sqrt(2*val2*val2*cimg::PI):1)); @@ -20918,20 +20938,8 @@ namespace cimg_library { _cimg_mp_scalar3(mp_gauss,arg1,arg2,arg3); } - if (!std::strncmp(ss,"gcd(",4)) { // Gcd - _cimg_mp_op("Function 'gcd()'"); - s1 = ss4; while (s1::max(); if (mem[arg2]>=siz_max) { @@ -20991,7 +20999,7 @@ namespace cimg_library { _cimg_mp_check_const_scalar(arg2,2,3); if (arg3!=~0U) _cimg_mp_check_type(arg3,3,1,0); if (arg4!=~0U) _cimg_mp_check_type(arg4,3,1,0); - p1 = _cimg_mp_size(arg1); + p1 = size(arg1); arg2 = (unsigned int)mem[arg2]; pos = vector(arg2); CImg::vector((ulongT)mp_vector_histogram,pos,arg1,p1,arg2,arg3,arg4).move_to(code); @@ -21033,7 +21041,7 @@ namespace cimg_library { s2 = s1 + 1; while (s2::vector((ulongT)mp_if,pos,arg1,arg2,arg3, p3 - p2,code._width - p3,arg4).move_to(code,p2); @@ -21070,8 +21078,8 @@ namespace cimg_library { _cimg_mp_check_const_scalar(arg3,3,3); _cimg_mp_check_type(arg4,4,1,0); _cimg_mp_check_const_scalar(arg5,5,2); - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg2); + p1 = size(arg1); + p2 = size(arg2); arg3 = (unsigned int)mem[arg3]; arg5 = (unsigned int)mem[arg5]; p3 = p2/arg3; // Number of color entries @@ -21109,9 +21117,9 @@ namespace cimg_library { _cimg_mp_check_type(arg4,4,1,0); _cimg_mp_check_type(arg5,5,1,0); } - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2) && - _cimg_mp_is_const_scalar(arg3) && _cimg_mp_is_const_scalar(arg4) && - _cimg_mp_is_const_scalar(arg5)) { // Optimize constant case + if (is_const_scalar(arg1) && is_const_scalar(arg2) && + is_const_scalar(arg3) && is_const_scalar(arg4) && + is_const_scalar(arg5)) { // Optimize constant case val = mem[arg1]; val1 = mem[arg2]; val2 = mem[arg3]; if (val2>=val1) is_sth = (mem[arg4]?(val>=val1):(val>val1)) && (mem[arg5]?(val<=val2):(val=val2):(val>val2)) && (mem[arg4]?(val<=val1):(val::vector((ulongT)mp_isdir,pos,arg1,(ulongT)_cimg_mp_size(arg1)).move_to(code); + CImg::vector((ulongT)mp_isdir,pos,arg1,(ulongT)size(arg1)).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } @@ -21229,7 +21237,7 @@ namespace cimg_library { _cimg_mp_op("Function 'isfile()'"); arg1 = compile(ss7,se1,depth1,0,block_flags); pos = scalar(); - CImg::vector((ulongT)mp_isfile,pos,arg1,(ulongT)_cimg_mp_size(arg1)).move_to(code); + CImg::vector((ulongT)mp_isfile,pos,arg1,(ulongT)size(arg1)).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } @@ -21243,7 +21251,7 @@ namespace cimg_library { ns = s; while (ns::vector(arg1,_cimg_mp_size(arg1)).move_to(l_opcode); + CImg::vector(arg1,size(arg1)).move_to(l_opcode); s = ns; } (l_opcode>'y').move_to(opcode); @@ -21257,8 +21265,8 @@ namespace cimg_library { _cimg_mp_op("Function 'isinf()'"); if (ss6==se1) _cimg_mp_return(0); arg1 = compile(ss6,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_isinf,arg1); - if (_cimg_mp_is_const_scalar(arg1)) + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_isinf,arg1); + if (is_const_scalar(arg1)) _cimg_mp_return((unsigned int)cimg::type::is_inf(mem[arg1])); _cimg_mp_scalar1(mp_isinf,arg1); } @@ -21268,8 +21276,8 @@ namespace cimg_library { if (ss6==se1) _cimg_mp_return(0); try { arg1 = compile(ss6,se1,depth1,0,block_flags); } catch(CImgException&) { _cimg_mp_return(0); } - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_isint,arg1); - if (_cimg_mp_is_const_scalar(arg1)) + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_isint,arg1); + if (is_const_scalar(arg1)) _cimg_mp_return((unsigned int)((double)(longT)mem[arg1]==mem[arg1])); _cimg_mp_scalar1(mp_isint,arg1); } @@ -21278,8 +21286,8 @@ namespace cimg_library { _cimg_mp_op("Function 'isnan()'"); if (ss6==se1) _cimg_mp_return(0); arg1 = compile(ss6,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_isnan,arg1); - if (_cimg_mp_is_const_scalar(arg1)) + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_isnan,arg1); + if (is_const_scalar(arg1)) _cimg_mp_return((unsigned int)cimg::type::is_nan(mem[arg1])); _cimg_mp_scalar1(mp_isnan,arg1); } @@ -21308,7 +21316,7 @@ namespace cimg_library { _cimg_mp_op("Function 'isvarname()'"); arg1 = compile(ss + 10,se1,depth1,0,block_flags); pos = scalar(); - CImg::vector((ulongT)mp_isvarname,pos,arg1,(ulongT)_cimg_mp_size(arg1)).move_to(code); + CImg::vector((ulongT)mp_isvarname,pos,arg1,(ulongT)size(arg1)).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } @@ -21330,19 +21338,19 @@ namespace cimg_library { arg2 = compile(s1,s2,depth1,0,block_flags); arg3 = s2::vector((ulongT)mp_vector_lerp,pos,p1,arg1,arg2,arg3).move_to(code); @@ -21353,32 +21361,32 @@ namespace cimg_library { if (!std::strncmp(ss,"log(",4)) { // Natural logarithm _cimg_mp_op("Function 'log()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_log,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::log(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_log,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::log(mem[arg1])); _cimg_mp_scalar1(mp_log,arg1); } if (!std::strncmp(ss,"log2(",5)) { // Base-2 logarithm _cimg_mp_op("Function 'log2()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_log2,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::log2(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_log2,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::log2(mem[arg1])); _cimg_mp_scalar1(mp_log2,arg1); } if (!std::strncmp(ss,"log10(",6)) { // Base-10 logarithm _cimg_mp_op("Function 'log10()'"); arg1 = compile(ss6,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_log10,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::log10(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_log10,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::log10(mem[arg1])); _cimg_mp_scalar1(mp_log10,arg1); } if (!std::strncmp(ss,"lowercase(",10)) { // Lower case _cimg_mp_op("Function 'lowercase()'"); arg1 = compile(ss + 10,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_lowercase,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::lowercase(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_lowercase,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::lowercase(mem[arg1])); _cimg_mp_scalar1(mp_lowercase,arg1); } break; @@ -21405,8 +21413,8 @@ namespace cimg_library { _cimg_mp_check_const_scalar(arg3,3,3); _cimg_mp_check_const_scalar(arg4,4,3); _cimg_mp_check_type(arg5,5,1,0); - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg2); + p1 = size(arg1); + p2 = size(arg2); arg3 = (unsigned int)mem[arg3]; arg4 = (unsigned int)mem[arg4]; if (p1%arg3) { @@ -21443,8 +21451,8 @@ namespace cimg_library { _cimg_mp_check_type(arg1,1,2,0); _cimg_mp_check_type(arg2,2,2,0); _cimg_mp_check_const_scalar(arg3,3,3); - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg2); + p1 = size(arg1); + p2 = size(arg2); p3 = (unsigned int)mem[arg3]; arg5 = p2/p3; arg4 = p1/arg5; @@ -21481,8 +21489,8 @@ namespace cimg_library { _cimg_mp_check_const_scalar(arg3,3,3); _cimg_mp_check_const_scalar(arg4,4,3); _cimg_mp_check_const_scalar(arg5,5,3); - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg6); + p1 = size(arg1); + p2 = size(arg6); arg2 = (unsigned int)mem[arg2]; arg3 = (unsigned int)mem[arg3]; arg4 = (unsigned int)mem[arg4]; @@ -21526,8 +21534,8 @@ namespace cimg_library { _cimg_mp_check_type(arg5,5,1,0); _cimg_mp_check_type(arg6,6,1,0); _cimg_mp_check_type(p3,7,1,0); - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg3); + p1 = size(arg1); + p2 = size(arg3); const unsigned int wS = (unsigned int)mem[arg2], wD = (unsigned int)mem[arg4], @@ -21572,8 +21580,8 @@ namespace cimg_library { s1 = ss4; while (s1::vector((ulongT)mp_vector_noise,pos,arg1,p1,arg2,arg3).move_to(code); return_new_comp = true; @@ -21708,8 +21716,8 @@ namespace cimg_library { _cimg_mp_check_type(arg2,2,1,0); _cimg_mp_check_type(arg3,3,1,0); _cimg_mp_check_type(arg4,4,1,0); - if (_cimg_mp_is_scalar(arg1)) _cimg_mp_scalar3(mp_lerp,arg2,arg3,arg4); - p1 = _cimg_mp_size(arg1); + if (is_scalar(arg1)) _cimg_mp_scalar3(mp_lerp,arg2,arg3,arg4); + p1 = size(arg1); pos = vector(p1); CImg::vector((ulongT)mp_vector_normalize,pos,arg1,p1,arg2,arg3,arg4).move_to(code); return_new_comp = true; @@ -21722,7 +21730,7 @@ namespace cimg_library { arg1 = compile(ss6,s1,depth1,0,block_flags); arg2 = s11 && _cimg_mp_is_vector(arg2)) // Vector argument allowed to specify coordinates and color - CImg::sequence(_cimg_mp_size(arg2),arg2 + 1, - arg2 + (ulongT)_cimg_mp_size(arg2)). + if (pos>1 && is_vector(arg2)) // Vector argument allowed to specify coordinates and color + CImg::sequence(size(arg2),arg2 + 1, + arg2 + (ulongT)size(arg2)). move_to(l_opcode); else { _cimg_mp_check_type(arg2,pos,1,0); @@ -21852,7 +21860,7 @@ namespace cimg_library { c1 = *ns; *ns = 0; variable_name.assign(CImg::string(s,true,true).unroll('y'),true); cimg::strpare(variable_name,false,true); - if (_cimg_mp_is_const_scalar(pos)) // Const scalar + if (is_const_scalar(pos)) // Const scalar std::fprintf(cimg::output(),"\n[" cimg_appname "_math_parser] %s = %.17g " "(mem[%u]: %s%s)", variable_name._data,mem[pos],pos,s_type(pos)._data,s_ref(ref)._data); @@ -21863,8 +21871,8 @@ namespace cimg_library { if (p_ref) std::memcpy(p_ref,ref,siz_ref); - if (_cimg_mp_is_vector(pos)) // Vector - ((CImg::vector((ulongT)mp_vector_print,pos,0,(ulongT)_cimg_mp_size(pos),is_sth?1:0), + if (is_vector(pos)) // Vector + ((CImg::vector((ulongT)mp_vector_print,pos,0,(ulongT)size(pos),is_sth?1:0), variable_name)>'y').move_to(opcode); else // Scalar ((CImg::vector((ulongT)mp_print,pos,0,is_sth?1:0), @@ -21882,8 +21890,8 @@ namespace cimg_library { if (!std::strncmp(ss,"rad2deg(",8)) { // Degrees to radians _cimg_mp_op("Function 'rad2deg()'"); arg1 = compile(ss8,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_rad2deg,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(mem[arg1]*180/cimg::PI); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_rad2deg,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(mem[arg1]*180/cimg::PI); _cimg_mp_scalar1(mp_rad2deg,arg1); } @@ -21919,7 +21927,7 @@ namespace cimg_library { s1 = ++s2; while (s1::string(s1).move_to(variable_def); } - if (_cimg_mp_is_vector(arg3)) + if (is_vector(arg3)) set_reserved_vector(arg3); // Prevent from being used in further optimization - else if (_cimg_mp_is_comp(arg3)) memtype[arg3] = -1; + else if (is_comp_scalar(arg3)) memtype[arg3] = -1; *se1 = ')'; _cimg_mp_return(arg3); } @@ -21987,8 +21995,8 @@ namespace cimg_library { } get_variable_pos(variable_name,arg2,arg3); arg2 = arg3!=~0U?reserved_label[arg3]:arg2!=~0U?variable_pos[arg2]:~0U; // Variable slot - if (arg2!=~0U && (!_cimg_mp_is_scalar(arg2) || - _cimg_mp_is_const_scalar(arg2))) { // Variable is not a vector or is a constant->error + if (arg2!=~0U && (!is_scalar(arg2) || + is_const_scalar(arg2))) { // Variable is not a vector or is a constant->error cimg::strellipsize(variable_name,64); throw CImgArgumentException("[" cimg_appname "_math_parser] " "CImg<%s>::%s: %s: Invalid type '%s' for variable '%s' " @@ -22030,7 +22038,7 @@ namespace cimg_library { (l_opcode>'y').move_to(opcode); if (opcode.height()<2) compile(s,se1,depth1,0,block_flags); // Not enough arguments -> throw exception arg1 = (unsigned int)opcode[0]; // Vector to resize - p1 = _cimg_mp_size(arg1); + p1 = size(arg1); if (opcode.height()<=4) { // Simple vector resize arg2 = (unsigned int)opcode[1]; @@ -22118,8 +22126,8 @@ namespace cimg_library { if (!std::strncmp(ss,"reverse(",8)) { // Vector reverse _cimg_mp_op("Function 'reverse()'"); arg1 = compile(ss8,se1,depth1,0,block_flags); - if (!_cimg_mp_is_vector(arg1)) _cimg_mp_return(arg1); - p1 = _cimg_mp_size(arg1); + if (!is_vector(arg1)) _cimg_mp_same(arg1); + p1 = size(arg1); pos = vector(p1); CImg::vector((ulongT)mp_vector_reverse,pos,arg1,p1).move_to(code); return_new_comp = true; @@ -22132,8 +22140,8 @@ namespace cimg_library { arg1 = compile(ss4,s1,depth1,0,block_flags); arg2 = s11) { @@ -22190,8 +22198,8 @@ namespace cimg_library { } _cimg_mp_check_type(arg2,2,1,0); _cimg_mp_check_type(arg3,3,1,0); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector3_vss(mp_round,arg1,arg2,arg3); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2) && _cimg_mp_is_const_scalar(arg3)) + if (is_vector(arg1)) _cimg_mp_vector3_vss(mp_round,arg1,arg2,arg3); + if (is_const_scalar(arg1) && is_const_scalar(arg2) && is_const_scalar(arg3)) _cimg_mp_const_scalar(cimg::round(mem[arg1],mem[arg2],(int)mem[arg3])); _cimg_mp_scalar3(mp_round,arg1,arg2,arg3); } @@ -22206,7 +22214,7 @@ namespace cimg_library { ns = s; while (ns::vector(arg1,_cimg_mp_size(arg1)).move_to(l_opcode); + CImg::vector(arg1,size(arg1)).move_to(l_opcode); s = ns; } (l_opcode>'y').move_to(opcode); @@ -22245,20 +22253,20 @@ namespace cimg_library { _cimg_mp_check_type(arg3,3,1,0); arg4 = s3::vector((ulongT)mp_set,arg2,p2,arg1,p1).move_to(code); _cimg_mp_return_nan(); } @@ -22277,7 +22285,7 @@ namespace cimg_library { _cimg_mp_check_type(arg1,1,2,0); _cimg_mp_check_type(arg2,2,1,0); _cimg_mp_check_type(arg3,3,1,0); - p1 = _cimg_mp_size(arg1); + p1 = size(arg1); pos = vector(p1); CImg::vector((ulongT)mp_shift,pos,arg1,p1,arg2,arg3).move_to(code); return_new_comp = true; @@ -22287,39 +22295,39 @@ namespace cimg_library { if (!std::strncmp(ss,"sign(",5)) { // Sign _cimg_mp_op("Function 'sign()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sign,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::sign(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_sign,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::sign(mem[arg1])); _cimg_mp_scalar1(mp_sign,arg1); } if (!std::strncmp(ss,"sin(",4)) { // Sine _cimg_mp_op("Function 'sin()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sin,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::sin(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_sin,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::sin(mem[arg1])); _cimg_mp_scalar1(mp_sin,arg1); } if (!std::strncmp(ss,"sinc(",5)) { // Sine cardinal _cimg_mp_op("Function 'sinc()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sinc,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::sinc(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_sinc,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::sinc(mem[arg1])); _cimg_mp_scalar1(mp_sinc,arg1); } if (!std::strncmp(ss,"sinh(",5)) { // Hyperbolic sine _cimg_mp_op("Function 'sinh()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sinh,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::sinh(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_sinh,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::sinh(mem[arg1])); _cimg_mp_scalar1(mp_sinh,arg1); } if (!std::strncmp(ss,"size(",5)) { // Vector size _cimg_mp_op("Function 'size()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - _cimg_mp_const_scalar(_cimg_mp_is_scalar(arg1)?0:_cimg_mp_size(arg1)); + _cimg_mp_const_scalar(is_scalar(arg1)?0:size(arg1)); } if (!std::strncmp(ss,"solve(",6)) { // Solve square linear system @@ -22340,8 +22348,8 @@ namespace cimg_library { _cimg_mp_check_const_scalar(arg3,3,3); _cimg_mp_check_type(arg4,4,1,0); - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg2); + p1 = size(arg1); + p2 = size(arg2); p3 = (unsigned int)mem[arg3]; arg5 = p2/p3; arg6 = p1/arg5; @@ -22378,7 +22386,7 @@ namespace cimg_library { _cimg_mp_check_type(arg2,2,1,0); if (arg3!=~0U) _cimg_mp_check_type(arg3,3,1,0); _cimg_mp_check_type(arg4,4,1,0); - p1 = _cimg_mp_size(arg1); + p1 = size(arg1); pos = vector(p1); CImg::vector((ulongT)mp_sort,pos,arg1,p1,arg2,arg3,arg4).move_to(code); return_new_comp = true; @@ -22388,16 +22396,16 @@ namespace cimg_library { if (!std::strncmp(ss,"sqr(",4)) { // Square _cimg_mp_op("Function 'sqr()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sqr,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::sqr(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_sqr,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::sqr(mem[arg1])); _cimg_mp_scalar1(mp_sqr,arg1); } if (!std::strncmp(ss,"sqrt(",5)) { // Square root _cimg_mp_op("Function 'sqrt()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_sqrt,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::sqrt(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_sqrt,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::sqrt(mem[arg1])); _cimg_mp_scalar1(mp_sqrt,arg1); } @@ -22427,10 +22435,10 @@ namespace cimg_library { s1 = ss6; while (s1::vector((ulongT)mp_s2v,pos,arg1,p1,arg2,arg3).move_to(code); return_new_comp = true; @@ -22500,10 +22508,10 @@ namespace cimg_library { ns = s; while (ns::vector(arg2,p2).move_to(l_opcode); @@ -22527,7 +22535,7 @@ namespace cimg_library { arg2 = s1::%s: %s: %s argument cannot be a constant, " "in expression '%s'.", pixel_type(),_cimg_mp_calling_function,s_op, - _cimg_mp_is_const_scalar(arg1)?"First":"Second",s0); + is_const_scalar(arg1)?"First":"Second",s0); } CImg::vector((ulongT)mp_swap,arg1,arg2,p1).move_to(code); @@ -22571,7 +22579,7 @@ namespace cimg_library { case 1 : // arg1: V[k] arg3 = _ref[1]; // Vector slot arg4 = _ref[2]; // Index - CImg::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)_cimg_mp_size(arg3),arg4). + CImg::vector((ulongT)mp_vector_set_off,arg1,arg3,(ulongT)size(arg3),arg4). move_to(code); break; case 2 : // arg1: i/j[_#ind,off] @@ -22614,23 +22622,23 @@ namespace cimg_library { arg3 = _ref[3]; // Offset if (p1!=~0U) { if (imglist) { - if (_cimg_mp_is_scalar(arg1)) + if (is_scalar(arg1)) CImg::vector((ulongT)(is_relative?mp_list_set_Joff_s:mp_list_set_Ioff_s), arg1,p1,arg3).move_to(code); else { _cimg_mp_check_const_index(p1); CImg::vector((ulongT)(is_relative?mp_list_set_Joff_v:mp_list_set_Ioff_v), - arg1,p1,arg3,_cimg_mp_size(arg1)).move_to(code); + arg1,p1,arg3,size(arg1)).move_to(code); } } } else { if (imgout) { - if (_cimg_mp_is_scalar(arg1)) + if (is_scalar(arg1)) CImg::vector((ulongT)(is_relative?mp_set_Joff_s:mp_set_Ioff_s), arg1,arg3).move_to(code); else CImg::vector((ulongT)(is_relative?mp_set_Joff_v:mp_set_Ioff_v), - arg1,arg3,_cimg_mp_size(arg1)).move_to(code); + arg1,arg3,size(arg1)).move_to(code); } } break; @@ -22643,23 +22651,23 @@ namespace cimg_library { arg5 = _ref[5]; // Z if (p1!=~0U) { if (imglist) { - if (_cimg_mp_is_scalar(arg1)) + if (is_scalar(arg1)) CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_s:mp_list_set_Ixyz_s), arg1,p1,arg3,arg4,arg5).move_to(code); else { _cimg_mp_check_const_index(p1); CImg::vector((ulongT)(is_relative?mp_list_set_Jxyz_v:mp_list_set_Ixyz_v), - arg1,p1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code); + arg1,p1,arg3,arg4,arg5,size(arg1)).move_to(code); } } } else { if (imgout) { - if (_cimg_mp_is_scalar(arg1)) + if (is_scalar(arg1)) CImg::vector((ulongT)(is_relative?mp_set_Jxyz_s:mp_set_Ixyz_s), arg1,arg3,arg4,arg5).move_to(code); else CImg::vector((ulongT)(is_relative?mp_set_Jxyz_v:mp_set_Ixyz_v), - arg1,arg3,arg4,arg5,_cimg_mp_size(arg1)).move_to(code); + arg1,arg3,arg4,arg5,size(arg1)).move_to(code); } } break; @@ -22679,16 +22687,16 @@ namespace cimg_library { if (!std::strncmp(ss,"tan(",4)) { // Tangent _cimg_mp_op("Function 'tan()'"); arg1 = compile(ss4,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_tan,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::tan(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_tan,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::tan(mem[arg1])); _cimg_mp_scalar1(mp_tan,arg1); } if (!std::strncmp(ss,"tanh(",5)) { // Hyperbolic tangent _cimg_mp_op("Function 'tanh()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_tanh,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(std::tanh(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_tanh,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(std::tanh(mem[arg1])); _cimg_mp_scalar1(mp_tanh,arg1); } @@ -22696,7 +22704,7 @@ namespace cimg_library { _cimg_mp_op("Function 'trace()'"); arg1 = compile(ss6,se1,depth1,0,block_flags); _cimg_mp_check_matrix_square(arg1,1); - p1 = (unsigned int)cimg::round(std::sqrt((float)_cimg_mp_size(arg1))); + p1 = (unsigned int)cimg::round(std::sqrt((float)size(arg1))); _cimg_mp_scalar2(mp_trace,arg1,p1); } @@ -22707,7 +22715,7 @@ namespace cimg_library { arg2 = compile(++s1,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,1,2,0); _cimg_mp_check_const_scalar(arg2,2,3); - p1 = _cimg_mp_size(arg1); + p1 = size(arg1); p2 = (unsigned int)mem[arg2]; p3 = p1/p2; if (p2*p3!=p1) { @@ -22726,48 +22734,11 @@ namespace cimg_library { break; case 'u' : - if (*ss1=='(') { // Random value with uniform distribution in specified range - _cimg_mp_op("Function 'u()'"); - if (*ss2==')') _cimg_mp_scalar2(mp_u,0,1); - s1 = ss2; while (s1float conversion _cimg_mp_op("Function 'ui2f()'"); arg1 = compile(ss5,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_ui2f,arg1); - if (_cimg_mp_is_const_scalar(arg1)) + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_ui2f,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar((double)cimg::uint2float((unsigned int)mem[arg1])); _cimg_mp_scalar1(mp_ui2f,arg1); } @@ -22779,11 +22750,11 @@ namespace cimg_library { arg1 = compile(s0,s1,depth1,0,block_flags); arg2 = s10) pos = is_comp_vector(arg1)?arg1:((return_new_comp = true), vector(p1)); else { pos = scalar(); - if (_cimg_mp_is_const_scalar(arg1) && _cimg_mp_is_const_scalar(arg2)) { + if (is_const_scalar(arg1) && is_const_scalar(arg2)) { val = mem[arg1]; _cimg_mp_const_scalar(val?(mem[arg2]?1:val):0); } @@ -22819,8 +22790,8 @@ namespace cimg_library { if (!std::strncmp(ss,"uppercase(",10)) { // Upper case _cimg_mp_op("Function 'uppercase()'"); arg1 = compile(ss + 10,se1,depth1,0,block_flags); - if (_cimg_mp_is_vector(arg1)) _cimg_mp_vector1_v(mp_uppercase,arg1); - if (_cimg_mp_is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::uppercase(mem[arg1])); + if (is_vector(arg1)) _cimg_mp_vector1_v(mp_uppercase,arg1); + if (is_const_scalar(arg1)) _cimg_mp_const_scalar(cimg::uppercase(mem[arg1])); _cimg_mp_scalar1(mp_uppercase,arg1); } break; @@ -22849,8 +22820,8 @@ namespace cimg_library { ns = s; while (ns::sequence(arg4,arg3 + 1,arg3 + arg4).move_to(l_opcode); arg2+=arg4; } else { CImg::vector(arg3).move_to(l_opcode); ++arg2; } @@ -22910,8 +22881,8 @@ namespace cimg_library { ns = s; while (ns::vector(arg2,p2).move_to(l_opcode); s = ns; @@ -22939,14 +22910,14 @@ namespace cimg_library { } _cimg_mp_check_type(arg2,2,1,0); if (arg3==~0U) { // Auto-guess best output vector size - p1 = _cimg_mp_size(arg1); + p1 = size(arg1); p1 = p1?25*p1 - 1:24; } else { _cimg_mp_check_const_scalar(arg3,3,3); p1 = (unsigned int)mem[arg3]; } pos = vector(p1); - CImg::vector((ulongT)mp_v2s,pos,p1,arg1,_cimg_mp_size(arg1),arg2).move_to(code); + CImg::vector((ulongT)mp_v2s,pos,p1,arg1,size(arg1),arg2).move_to(code); return_new_comp = true; _cimg_mp_return(pos); } @@ -23013,8 +22984,8 @@ namespace cimg_library { if (opcode.height()<10) compile(s,se1,depth1,0,block_flags); // Not enough arguments -> throw exception arg1 = (unsigned int)opcode[0]; // Image to warp arg2 = (unsigned int)opcode[5]; // Warp map - p1 = _cimg_mp_size(arg1); - p2 = _cimg_mp_size(arg2); + p1 = size(arg1); + p2 = size(arg2); p3 = opcode.height(); opcode.resize(1,13,1,1,0); if (p3<11) opcode[10] = 0; @@ -23059,10 +23030,10 @@ namespace cimg_library { arg6 = mempos; pos = compile(++s1,se1,depth1,0,block_flags); _cimg_mp_check_type(arg1,1,1,0); - arg2 = _cimg_mp_size(pos); + arg2 = size(pos); CImg::vector((ulongT)mp_while,pos,arg1,p2 - p1,code._width - p2,arg2, - pos>=arg6 && !_cimg_mp_is_const_scalar(pos), - arg1>=arg6 && !_cimg_mp_is_const_scalar(arg1)).move_to(code,p1); + pos>=arg6 && !is_const_scalar(pos), + arg1>=arg6 && !is_const_scalar(arg1)).move_to(code,p1); _cimg_mp_return(pos); } break; @@ -23073,11 +23044,11 @@ namespace cimg_library { s1 = ss4; while (s1::sequence(_cimg_mp_size(arg2),arg2 + 1,arg2 + (ulongT)_cimg_mp_size(arg2)). + if (is_vector(arg2)) + CImg::sequence(size(arg2),arg2 + 1,arg2 + (ulongT)size(arg2)). move_to(l_opcode); else CImg::vector(arg2).move_to(l_opcode); - is_sth&=_cimg_mp_is_const_scalar(arg2); + is_sth&=is_const_scalar(arg2); s = ns; } (l_opcode>'y').move_to(opcode); @@ -23121,42 +23092,87 @@ namespace cimg_library { _cimg_mp_return(pos); } - if (!std::strncmp(ss,"max(",4) || !std::strncmp(ss,"min(",4) || - !std::strncmp(ss,"maxabs(",7) || !std::strncmp(ss,"minabs(",7) || - !std::strncmp(ss,"med(",4) || !std::strncmp(ss,"kth(",4) || - !std::strncmp(ss,"sum(",4) || !std::strncmp(ss,"avg(",4) || - !std::strncmp(ss,"std(",4) || !std::strncmp(ss,"var(",4) || - !std::strncmp(ss,"prod(",5) || - !std::strncmp(ss,"argmin(",7) || !std::strncmp(ss,"argmax(",7) || - !std::strncmp(ss,"argminabs(",10) || !std::strncmp(ss,"argmaxabs(",10) || - !std::strncmp(ss,"argkth(",7)) { // Multi-argument functions - _cimg_mp_op(*ss=='a'?(ss[1]=='v'?"Function 'avg()'": - ss[3]=='k'?"Function 'argkth()'": - ss[4]=='i' && ss[6]=='('?"Function 'argmin()'": - ss[4]=='i'?"Function argminabs()'": - ss[6]=='('?"Function 'argmax()'": - "Function 'argmaxabs()'"): - *ss=='s'?(ss[1]=='u'?"Function 'sum()'":"Function 'std()'"): + if ((*ss=='u' || *ss=='v') && *ss1=='(') { // Random value with uniform distribution in specified range + is_sth = *ss=='v'; // is integer generator? + _cimg_mp_op(is_sth?"Function 'v()'":"Function 'u()'"); + if (*ss2==')') _cimg_mp_scalar0(is_sth?mp_rand_int_0_1:mp_rand_double_0_1); + s1 = ss2; while (s1::vector((ulongT)op,pos,0).move_to(l_opcode); @@ -23164,9 +23180,9 @@ namespace cimg_library { ns = s; while (ns::vector(arg2 + 1,_cimg_mp_size(arg2)).move_to(l_opcode); + if (is_vector(arg2)) CImg::vector(arg2 + 1,size(arg2)).move_to(l_opcode); else CImg::vector(arg2,1).move_to(l_opcode); - is_sth&=_cimg_mp_is_const_scalar(arg2); + is_sth&=is_const_scalar(arg2); s = ns; } (l_opcode>'y').move_to(opcode); @@ -23337,8 +23353,8 @@ namespace cimg_library { ns = s; while (ns::sequence(arg3,arg2 + 1,arg2 + arg3).move_to(l_opcode); arg1+=arg3; } else { CImg::vector(arg2).move_to(l_opcode); ++arg1; } @@ -23359,7 +23375,7 @@ namespace cimg_library { if (*ss1=='#' && ss2::vector(imglist[p1].median()).move_to(list_median[p1]); _cimg_mp_const_scalar(*list_median[p1]); @@ -23443,7 +23459,7 @@ namespace cimg_library { if (*ss1=='d') { // id#ind if (!imglist) _cimg_mp_return(0); - if (_cimg_mp_is_const_scalar(arg1)) { + if (is_const_scalar(arg1)) { if (!list_stats) list_stats.assign(imglist._width); if (!list_stats[p1]) list_stats[p1].assign(1,14,1,1,0).fill(imglist[p1].get_stats(),false); _cimg_mp_const_scalar(std::sqrt(list_stats(p1,3))); @@ -23453,7 +23469,7 @@ namespace cimg_library { if (*ss1=='n') { // in#ind if (!imglist) _cimg_mp_return(0); - if (_cimg_mp_is_const_scalar(arg1)) { + if (is_const_scalar(arg1)) { if (!list_norm) list_norm.assign(imglist._width); if (!list_norm[p1]) CImg::vector(imglist[p1].magnitude(2)).move_to(list_norm[p1]); _cimg_mp_const_scalar(*list_norm[p1]); @@ -23482,7 +23498,7 @@ namespace cimg_library { } if (arg2!=~0U) { if (!imglist) _cimg_mp_return(0); - if (_cimg_mp_is_const_scalar(arg1)) { + if (is_const_scalar(arg1)) { if (!list_stats) list_stats.assign(imglist._width); if (!list_stats[p1]) list_stats[p1].assign(1,14,1,1,0).fill(imglist[p1].get_stats(),false); _cimg_mp_const_scalar(list_stats(p1,arg2)); @@ -23495,7 +23511,7 @@ namespace cimg_library { arg1 = compile(ss4,se,depth1,0,block_flags); _cimg_mp_check_notnan_index(arg1); if (!imglist) _cimg_mp_return(0); - p1 = (unsigned int)(_cimg_mp_is_const_scalar(arg1)?cimg::mod((int)mem[arg1],imglist.width()):~0U); + p1 = (unsigned int)(is_const_scalar(arg1)?cimg::mod((int)mem[arg1],imglist.width()):~0U); if (p1!=~0U) _cimg_mp_const_scalar(imglist[p1]._width*imglist[p1]._height*imglist[p1]._depth); _cimg_mp_scalar1(mp_list_whd,arg1); } @@ -23503,7 +23519,7 @@ namespace cimg_library { arg1 = compile(ss5,se,depth1,0,block_flags); _cimg_mp_check_notnan_index(arg1); if (!imglist) _cimg_mp_return(0); - p1 = (unsigned int)(_cimg_mp_is_const_scalar(arg1)?cimg::mod((int)mem[arg1],imglist.width()):~0U); + p1 = (unsigned int)(is_const_scalar(arg1)?cimg::mod((int)mem[arg1],imglist.width()):~0U); if (p1!=~0U) _cimg_mp_const_scalar(imglist[p1]._width*imglist[p1]._height*imglist[p1]._depth*imglist[p1]._spectrum); _cimg_mp_scalar1(mp_list_whds,arg1); @@ -23714,10 +23730,10 @@ namespace cimg_library { // Return type of a memory slot as a string. CImg s_type(const unsigned int arg) const { CImg res; - if (_cimg_mp_is_vector(arg)) { // Vector + if (is_vector(arg)) { // Vector CImg::string("vectorXXXXXXXXXXXXXXXX").move_to(res); - cimg_snprintf(res._data + 6,res._width - 6,"%u",_cimg_mp_size(arg)); - } else if (_cimg_mp_is_const_scalar(arg)) CImg::string("const scalar").move_to(res); // Const scalar + cimg_snprintf(res._data + 6,res._width - 6,"%u",size(arg)); + } else if (is_const_scalar(arg)) CImg::string("const scalar").move_to(res); // Const scalar else CImg::string("scalar").move_to(res); // Scalar return res; } @@ -23861,6 +23877,7 @@ namespace cimg_library { c2 = variable_name[1]; c3 = variable_name[2]; if (c1=='w' && c2=='h' && c3=='d') rp = 1; // whd + else if (c1=='e' && c2=='p' && c3=='s') rp = 33; // eps } else if (variable_name[1] && variable_name[2] && variable_name[3] && !variable_name[4]) { // Four-chars variable c1 = variable_name[0]; @@ -23878,9 +23895,9 @@ namespace cimg_library { if (!std::strcmp(variable_name,variable_def[i])) { pos = i; break; } } - // Return true if all values of a vector are computation values. + // Return true if all values of a vector are (temporary) computational values. bool is_comp_vector(const unsigned int arg) const { - unsigned int siz = _cimg_mp_size(arg); + unsigned int siz = size(arg); if (siz>128) return false; const int *ptr = memtype.data(arg + 1); bool is_tmp = true; @@ -23888,6 +23905,36 @@ namespace cimg_library { return is_tmp; } + // Return true if specified scalar value is a (temporary) computational value. + bool is_comp_scalar(const unsigned int arg) const { + return !memtype[arg]; + } + + // Return true if specified value is a constant scalar. + bool is_const_scalar(const unsigned int arg) const { + return memtype[arg]==1; + } + + // Return true if specified value is a scalar reserved value (e.g. variable). + bool is_reserved(const unsigned int arg) const { + return memtype[arg]==-1; + } + + // Return true if specified value is a scalar. + bool is_scalar(const unsigned int arg) const { + return memtype[arg]<2; + } + + // Return true if specified value is a vector. + bool is_vector(const unsigned int arg) const { + return memtype[arg]>1; + } + + // Return size of specified value (0: scalar, N>0: vectorN). + unsigned int size(const unsigned int arg) const { + return is_scalar(arg)?0U:memtype[arg] - 1U; + } + // Check if a memory slot is a positive integer constant scalar value. // 'mode' can be: // { 0=constant | 1=integer constant | 2=positive integer constant | 3=strictly-positive integer constant } @@ -23895,7 +23942,7 @@ namespace cimg_library { const unsigned int mode, char *const ss, char *const se, const char saved_char) { _cimg_mp_check_type(arg,n_arg,1,0); - if (!_cimg_mp_is_const_scalar(arg)) { + if (!is_const_scalar(arg)) { const char *const s_arg = s_argth(n_arg); char *s0; _cimg_mp_strerr; throw CImgArgumentException("[" cimg_appname "_math_parser] " @@ -23923,7 +23970,7 @@ namespace cimg_library { // Check if an image index is a constant value. void check_const_index(const unsigned int arg, char *const ss, char *const se, const char saved_char) { - if (arg!=~0U && !_cimg_mp_is_const_scalar(arg)) { + if (arg!=~0U && !is_const_scalar(arg)) { char *s0; _cimg_mp_strerr; throw CImgArgumentException("[" cimg_appname "_math_parser] " "CImg<%s>::%s: %s%s Specified image index is not a constant, " @@ -23936,7 +23983,7 @@ namespace cimg_library { void check_notnan_index(const unsigned int arg, char *const ss, char *const se, const char saved_char) { if (arg!=~0U && - (arg==_cimg_mp_slot_nan || (_cimg_mp_is_const_scalar(arg) && cimg::type::is_nan(mem[arg])))) { + (arg==_cimg_mp_slot_nan || (is_const_scalar(arg) && cimg::type::is_nan(mem[arg])))) { char *s0; _cimg_mp_strerr; throw CImgArgumentException("[" cimg_appname "_math_parser] " "CImg<%s>::%s: %s%s Specified index is NaN.", @@ -23949,7 +23996,7 @@ namespace cimg_library { char *const ss, char *const se, const char saved_char) { _cimg_mp_check_type(arg,n_arg,2,0); const unsigned int - siz = _cimg_mp_size(arg), + siz = size(arg), n = (unsigned int)cimg::round(std::sqrt((float)siz)); if (n*n!=siz) { const char *s_arg; @@ -23973,11 +24020,11 @@ namespace cimg_library { const unsigned int mode, const unsigned int N, char *const ss, char *const se, const char saved_char) { const bool - is_scalar = _cimg_mp_is_scalar(arg), - is_vector = _cimg_mp_is_vector(arg) && (!N || _cimg_mp_size(arg)==N); + _is_scalar = is_scalar(arg), + _is_vector = is_vector(arg) && (!N || size(arg)==N); bool cond = false; - if (mode&1) cond|=is_scalar; - if (mode&2) cond|=is_vector; + if (mode&1) cond|=_is_scalar; + if (mode&2) cond|=_is_vector; if (!cond) { const char *s_arg; if (*s_op!='F') s_arg = !n_arg?"":n_arg==1?"Left-hand":"Right-hand"; @@ -24108,18 +24155,38 @@ namespace cimg_library { return pos; } - // Insert new copy of specified vector in memory. - unsigned int vector_copy(const unsigned int arg) { - const unsigned int - siz = _cimg_mp_size(arg), - pos = vector(siz); - CImg::vector((ulongT)mp_vector_copy,pos,arg,siz).move_to(code); - return pos; + // Return a copy of the specified value. + // (this forces a copy to be made. Use 'same()' for cases where you may want to return 'arg'). + unsigned int copy(const unsigned int arg) { + const unsigned int siz = size(arg); + return_new_comp = true; + if (siz) { // Vector + const unsigned int pos = vector(siz); + CImg::vector((ulongT)mp_vector_copy,pos,arg,siz).move_to(code); + return pos; + } + return scalar1(mp_copy,arg); // Scalar + } + + // Return same value as specified. + // (this avoids a copy to be made when possible. Use 'copy()' to force the copy of a value). + unsigned int same(const unsigned int arg) { + if (is_const_scalar(arg)) return arg; + if (is_comp_scalar(arg)) { return_new_comp = true; return arg; } + const unsigned int siz = size(arg); + if (siz) { // Vector + if (is_comp_vector(arg)) { return_new_comp = true; return arg; } + const unsigned int pos = vector(siz); + CImg::vector((ulongT)mp_vector_copy,pos,arg,siz).move_to(code); + return pos; + } + return_new_comp = true; + return scalar1(mp_copy,arg); // Scalar } // Set reserved status to all values of a vector. void set_reserved_vector(const unsigned int arg) { - unsigned int siz = _cimg_mp_size(arg); + unsigned int siz = size(arg); int *ptr = memtype.data(arg + 1); while (siz-->0) *(ptr++) = -1; } @@ -24133,7 +24200,7 @@ namespace cimg_library { unsigned int scalar1(const mp_func op, const unsigned int arg1) { const unsigned int pos = - arg1!=~0U && arg1>_cimg_mp_slot_c && _cimg_mp_is_comp(arg1) && op!=mp_copy?arg1: + arg1!=~0U && arg1>_cimg_mp_slot_c && is_comp_scalar(arg1) && op!=mp_copy?arg1: ((return_new_comp = true), scalar()); CImg::vector((ulongT)op,pos,arg1).move_to(code); return pos; @@ -24141,8 +24208,8 @@ namespace cimg_library { unsigned int scalar2(const mp_func op, const unsigned int arg1, const unsigned int arg2) { const unsigned int pos = - arg1!=~0U && arg1>_cimg_mp_slot_c && _cimg_mp_is_comp(arg1)?arg1: - arg2!=~0U && arg2>_cimg_mp_slot_c && _cimg_mp_is_comp(arg2)?arg2: + arg1!=~0U && arg1>_cimg_mp_slot_c && is_comp_scalar(arg1)?arg1: + arg2!=~0U && arg2>_cimg_mp_slot_c && is_comp_scalar(arg2)?arg2: ((return_new_comp = true), scalar()); CImg::vector((ulongT)op,pos,arg1,arg2).move_to(code); return pos; @@ -24151,9 +24218,9 @@ namespace cimg_library { unsigned int scalar3(const mp_func op, const unsigned int arg1, const unsigned int arg2, const unsigned int arg3) { const unsigned int pos = - arg1!=~0U && arg1>_cimg_mp_slot_c && _cimg_mp_is_comp(arg1)?arg1: - arg2!=~0U && arg2>_cimg_mp_slot_c && _cimg_mp_is_comp(arg2)?arg2: - arg3!=~0U && arg3>_cimg_mp_slot_c && _cimg_mp_is_comp(arg3)?arg3: + arg1!=~0U && arg1>_cimg_mp_slot_c && is_comp_scalar(arg1)?arg1: + arg2!=~0U && arg2>_cimg_mp_slot_c && is_comp_scalar(arg2)?arg2: + arg3!=~0U && arg3>_cimg_mp_slot_c && is_comp_scalar(arg3)?arg3: ((return_new_comp = true), scalar()); CImg::vector((ulongT)op,pos,arg1,arg2,arg3).move_to(code); return pos; @@ -24163,10 +24230,10 @@ namespace cimg_library { const unsigned int arg1, const unsigned int arg2, const unsigned int arg3, const unsigned int arg4) { const unsigned int pos = - arg1!=~0U && arg1>_cimg_mp_slot_c && _cimg_mp_is_comp(arg1)?arg1: - arg2!=~0U && arg2>_cimg_mp_slot_c && _cimg_mp_is_comp(arg2)?arg2: - arg3!=~0U && arg3>_cimg_mp_slot_c && _cimg_mp_is_comp(arg3)?arg3: - arg4!=~0U && arg4>_cimg_mp_slot_c && _cimg_mp_is_comp(arg4)?arg4: + arg1!=~0U && arg1>_cimg_mp_slot_c && is_comp_scalar(arg1)?arg1: + arg2!=~0U && arg2>_cimg_mp_slot_c && is_comp_scalar(arg2)?arg2: + arg3!=~0U && arg3>_cimg_mp_slot_c && is_comp_scalar(arg3)?arg3: + arg4!=~0U && arg4>_cimg_mp_slot_c && is_comp_scalar(arg4)?arg4: ((return_new_comp = true), scalar()); CImg::vector((ulongT)op,pos,arg1,arg2,arg3,arg4).move_to(code); return pos; @@ -24176,11 +24243,11 @@ namespace cimg_library { const unsigned int arg1, const unsigned int arg2, const unsigned int arg3, const unsigned int arg4, const unsigned int arg5) { const unsigned int pos = - arg1!=~0U && arg1>_cimg_mp_slot_c && _cimg_mp_is_comp(arg1)?arg1: - arg2!=~0U && arg2>_cimg_mp_slot_c && _cimg_mp_is_comp(arg2)?arg2: - arg3!=~0U && arg3>_cimg_mp_slot_c && _cimg_mp_is_comp(arg3)?arg3: - arg4!=~0U && arg4>_cimg_mp_slot_c && _cimg_mp_is_comp(arg4)?arg4: - arg5!=~0U && arg5>_cimg_mp_slot_c && _cimg_mp_is_comp(arg5)?arg5: + arg1!=~0U && arg1>_cimg_mp_slot_c && is_comp_scalar(arg1)?arg1: + arg2!=~0U && arg2>_cimg_mp_slot_c && is_comp_scalar(arg2)?arg2: + arg3!=~0U && arg3>_cimg_mp_slot_c && is_comp_scalar(arg3)?arg3: + arg4!=~0U && arg4>_cimg_mp_slot_c && is_comp_scalar(arg4)?arg4: + arg5!=~0U && arg5>_cimg_mp_slot_c && is_comp_scalar(arg5)?arg5: ((return_new_comp = true), scalar()); CImg::vector((ulongT)op,pos,arg1,arg2,arg3,arg4,arg5).move_to(code); return pos; @@ -24190,12 +24257,12 @@ namespace cimg_library { const unsigned int arg1, const unsigned int arg2, const unsigned int arg3, const unsigned int arg4, const unsigned int arg5, const unsigned int arg6) { const unsigned int pos = - arg1!=~0U && arg1>_cimg_mp_slot_c && _cimg_mp_is_comp(arg1)?arg1: - arg2!=~0U && arg2>_cimg_mp_slot_c && _cimg_mp_is_comp(arg2)?arg2: - arg3!=~0U && arg3>_cimg_mp_slot_c && _cimg_mp_is_comp(arg3)?arg3: - arg4!=~0U && arg4>_cimg_mp_slot_c && _cimg_mp_is_comp(arg4)?arg4: - arg5!=~0U && arg5>_cimg_mp_slot_c && _cimg_mp_is_comp(arg5)?arg5: - arg6!=~0U && arg6>_cimg_mp_slot_c && _cimg_mp_is_comp(arg6)?arg6: + arg1!=~0U && arg1>_cimg_mp_slot_c && is_comp_scalar(arg1)?arg1: + arg2!=~0U && arg2>_cimg_mp_slot_c && is_comp_scalar(arg2)?arg2: + arg3!=~0U && arg3>_cimg_mp_slot_c && is_comp_scalar(arg3)?arg3: + arg4!=~0U && arg4>_cimg_mp_slot_c && is_comp_scalar(arg4)?arg4: + arg5!=~0U && arg5>_cimg_mp_slot_c && is_comp_scalar(arg5)?arg5: + arg6!=~0U && arg6>_cimg_mp_slot_c && is_comp_scalar(arg6)?arg6: ((return_new_comp = true), scalar()); CImg::vector((ulongT)op,pos,arg1,arg2,arg3,arg4,arg5,arg6).move_to(code); return pos; @@ -24206,20 +24273,20 @@ namespace cimg_library { const unsigned int arg4, const unsigned int arg5, const unsigned int arg6, const unsigned int arg7) { const unsigned int pos = - arg1!=~0U && arg1>_cimg_mp_slot_c && _cimg_mp_is_comp(arg1)?arg1: - arg2!=~0U && arg2>_cimg_mp_slot_c && _cimg_mp_is_comp(arg2)?arg2: - arg3!=~0U && arg3>_cimg_mp_slot_c && _cimg_mp_is_comp(arg3)?arg3: - arg4!=~0U && arg4>_cimg_mp_slot_c && _cimg_mp_is_comp(arg4)?arg4: - arg5!=~0U && arg5>_cimg_mp_slot_c && _cimg_mp_is_comp(arg5)?arg5: - arg6!=~0U && arg6>_cimg_mp_slot_c && _cimg_mp_is_comp(arg6)?arg6: - arg7!=~0U && arg7>_cimg_mp_slot_c && _cimg_mp_is_comp(arg7)?arg7: + arg1!=~0U && arg1>_cimg_mp_slot_c && is_comp_scalar(arg1)?arg1: + arg2!=~0U && arg2>_cimg_mp_slot_c && is_comp_scalar(arg2)?arg2: + arg3!=~0U && arg3>_cimg_mp_slot_c && is_comp_scalar(arg3)?arg3: + arg4!=~0U && arg4>_cimg_mp_slot_c && is_comp_scalar(arg4)?arg4: + arg5!=~0U && arg5>_cimg_mp_slot_c && is_comp_scalar(arg5)?arg5: + arg6!=~0U && arg6>_cimg_mp_slot_c && is_comp_scalar(arg6)?arg6: + arg7!=~0U && arg7>_cimg_mp_slot_c && is_comp_scalar(arg7)?arg7: ((return_new_comp = true), scalar()); CImg::vector((ulongT)op,pos,arg1,arg2,arg3,arg4,arg5,arg6,arg7).move_to(code); return pos; } void self_vector_s(const unsigned int pos, const mp_func op, const unsigned int arg1) { - const unsigned int siz = _cimg_mp_size(pos); + const unsigned int siz = size(pos); if (siz>24) CImg::vector((ulongT)mp_self_map_vector_s,pos,siz,(ulongT)op,arg1).move_to(code); else { code.insert(siz); @@ -24229,7 +24296,7 @@ namespace cimg_library { } void self_vector_v(const unsigned int pos, const mp_func op, const unsigned int arg1) { - const unsigned int siz = _cimg_mp_size(pos); + const unsigned int siz = size(pos); if (siz>24) CImg::vector((ulongT)mp_self_map_vector_v,pos,siz,(ulongT)op,arg1).move_to(code); else { code.insert(siz); @@ -24240,7 +24307,7 @@ namespace cimg_library { unsigned int vector1_v(const mp_func op, const unsigned int arg1) { const unsigned int - siz = _cimg_mp_size(arg1), + siz = size(arg1), pos = is_comp_vector(arg1)?arg1: ((return_new_comp = true), vector(siz)); if (siz>24) CImg::vector((ulongT)mp_vector_map_v,pos,1,siz,(ulongT)op,arg1).move_to(code); @@ -24254,7 +24321,7 @@ namespace cimg_library { unsigned int vector2_vv(const mp_func op, const unsigned int arg1, const unsigned int arg2) { const unsigned int - siz = _cimg_mp_size(arg1), + siz = size(arg1), pos = is_comp_vector(arg1)?arg1:is_comp_vector(arg2)?arg2: ((return_new_comp = true), vector(siz)); if (siz>24) CImg::vector((ulongT)mp_vector_map_vv,pos,2,siz,(ulongT)op,arg1,arg2).move_to(code); @@ -24268,7 +24335,7 @@ namespace cimg_library { unsigned int vector2_vs(const mp_func op, const unsigned int arg1, const unsigned int arg2) { const unsigned int - siz = _cimg_mp_size(arg1), + siz = size(arg1), pos = is_comp_vector(arg1)?arg1: ((return_new_comp = true), vector(siz)); if (siz>24) CImg::vector((ulongT)mp_vector_map_v,pos,2,siz,(ulongT)op,arg1,arg2).move_to(code); @@ -24282,7 +24349,7 @@ namespace cimg_library { unsigned int vector2_sv(const mp_func op, const unsigned int arg1, const unsigned int arg2) { const unsigned int - siz = _cimg_mp_size(arg2), + siz = size(arg2), pos = is_comp_vector(arg2)?arg2: ((return_new_comp = true), vector(siz)); if (siz>24) CImg::vector((ulongT)mp_vector_map_sv,pos,2,siz,(ulongT)op,arg1,arg2).move_to(code); @@ -24297,7 +24364,7 @@ namespace cimg_library { unsigned int vector3_vss(const mp_func op, const unsigned int arg1, const unsigned int arg2, const unsigned int arg3) { const unsigned int - siz = _cimg_mp_size(arg1), + siz = size(arg1), pos = is_comp_vector(arg1)?arg1: ((return_new_comp = true), vector(siz)); if (siz>24) CImg::vector((ulongT)mp_vector_map_v,pos,3,siz,(ulongT)op,arg1,arg2,arg3).move_to(code); @@ -24312,7 +24379,7 @@ namespace cimg_library { unsigned int vector4_vvss(const mp_func op, const unsigned int arg1, const unsigned int arg2, const unsigned int arg3, const unsigned int arg4) { const unsigned int - siz = _cimg_mp_size(arg1), + siz = size(arg1), pos = is_comp_vector(arg1)?arg1:is_comp_vector(arg2)?arg2: ((return_new_comp = true), vector(siz)); if (siz>24) @@ -24329,7 +24396,7 @@ namespace cimg_library { unsigned int vector4_vsss(const mp_func op, const unsigned int arg1, const unsigned int arg2, const unsigned int arg3, const unsigned int arg4) { const unsigned int - siz = _cimg_mp_size(arg1), + siz = size(arg1), pos = is_comp_vector(arg1)?arg1: ((return_new_comp = true), vector(siz)); if (siz>24) @@ -24346,7 +24413,7 @@ namespace cimg_library { unsigned int vector4_svss(const mp_func op, const unsigned int arg1, const unsigned int arg2, const unsigned int arg3, const unsigned int arg4) { const unsigned int - siz = _cimg_mp_size(arg2), + siz = size(arg2), pos = is_comp_vector(arg2)?arg2: ((return_new_comp = true), vector(siz)); if (siz>24) @@ -24688,6 +24755,13 @@ namespace cimg_library { return cimg::type::nan(); } + static double mp_complex_one(_cimg_math_parser& mp) { + double *ptrd = &_mp_arg(1) + 1; + ptrd[0] = 1; + ptrd[1] = 0; + return cimg::type::nan(); + } + static void _mp_complex_pow(const double r1, const double i1, const double r2, const double i2, double *ptrd) { @@ -24763,6 +24837,14 @@ namespace cimg_library { return cimg::type::nan(); } + static double mp_complex_sqr(_cimg_math_parser& mp) { + const double real = _mp_arg(2), imag = _mp_arg(3); + double *ptrd = &_mp_arg(1) + 1; + ptrd[0] = cimg::sqr(real) - cimg::sqr(imag); + ptrd[1] = 2*real*imag; + return cimg::type::nan(); + } + static double mp_complex_sqrt(_cimg_math_parser& mp) { const double real = _mp_arg(2), imag = _mp_arg(3), @@ -25656,11 +25738,6 @@ namespace cimg_library { return (double)cimg::fsize(ss); } - static double mp_g(_cimg_math_parser& mp) { - cimg::unused(mp); - return cimg::grand(&mp.rng); - } - #if cimg_use_cpp11==1 static double mp_gamma(_cimg_math_parser& mp) { return std::tgamma(_mp_arg(2)); @@ -25690,7 +25767,26 @@ namespace cimg_library { #endif static double mp_gcd(_cimg_math_parser& mp) { - return cimg::gcd((long)_mp_arg(2),(long)_mp_arg(3)); + const unsigned int i_end = (unsigned int)mp.opcode[2]; + CImg values; + if (i_end==5) { // Only a single argument + if ((unsigned)mp.opcode[4]==1) return _mp_arg(3); // Real value + else values.assign(&_mp_arg(3),(unsigned int)mp.opcode[4]); // Vector value + } else if (i_end==7 && (unsigned int)mp.opcode[4]==1 && (unsigned int)mp.opcode[6]==1) // Two real arguments + return (double)cimg::gcd((cimg_int64)_mp_arg(3),(cimg_int64)_mp_arg(5)); + else { + unsigned int siz = 0; + for (unsigned int i = 4; i1) for (unsigned int k = 0; k values; + if (i_end==5) { // Only a single argument + if ((unsigned)mp.opcode[4]==1) return _mp_arg(3); // Real value + else values.assign(&_mp_arg(3),(unsigned int)mp.opcode[4]); // Vector value + } else if (i_end==7 && (unsigned int)mp.opcode[4]==1 && (unsigned int)mp.opcode[6]==1) // Two real arguments + return (double)cimg::lcm((cimg_int64)_mp_arg(3),(cimg_int64)_mp_arg(5)); + else { + unsigned int siz = 0; + for (unsigned int i = 4; i1) for (unsigned int k = 0; k::nan(); } - static double mp_u(_cimg_math_parser& mp) { + static double mp_rand_double(_cimg_math_parser& mp) { return cimg::rand(_mp_arg(2),_mp_arg(3),&mp.rng); } - static double mp_u_ext(_cimg_math_parser& mp) { // Extended version with extremum control + static double mp_rand_double_0_1(_cimg_math_parser& mp) { + return (double)cimg::_rand(&mp.rng)/~0U; + } + + static double mp_rand_double_0_N(_cimg_math_parser& mp) { + return _mp_arg(2)*mp_rand_double_0_1(mp); + } + + static double mp_rand_double_m1_1(_cimg_math_parser& mp) { + return 2*mp_rand_double_0_1(mp) - 1; + } + + static double mp_rand_double_gaussian(_cimg_math_parser& mp) { + return cimg::grand(&mp.rng); + } + + static double mp_rand_double_ext(_cimg_math_parser& mp) { const double eps = 1e-5; const bool include_min = (bool)_mp_arg(4), @@ -28310,6 +28445,62 @@ namespace cimg_library { return cimg::rand(m,M,&mp.rng); } + static double mp_rand_int(_cimg_math_parser& mp) { + double + _m = _mp_arg(2), + _M = _mp_arg(3); + if (_m>_M) cimg::swap(_m,_M); + const int + m = (int)std::ceil(_m), + M = (int)std::floor(_M); + if (m>M) return cimg::type::nan(); + if (M==m) return m; + int val = 0; + do { val = (int)std::floor(cimg::rand(m,M + 1,&mp.rng)); } while (val>M); + return val; + } + + static double mp_rand_int_0_1(_cimg_math_parser& mp) { + return cimg::_rand(&mp.rng)<(~0U>>1); + } + + static double mp_rand_int_0_N(_cimg_math_parser& mp) { + const double _M = _mp_arg(2); + const bool sgn = _M>=0; + const int M = (int)std::floor(sgn?_M:-_M); + if (!M) return 0; + int val = 0; + do { val = (int)std::floor(cimg::rand(M + 1,&mp.rng)); } while (val>M); + return (sgn?1:-1)*val; + } + + static double mp_rand_int_m1_1(_cimg_math_parser& mp) { + const unsigned int + th = ~0U/3, + val = cimg::_rand(&mp.rng); + return val_M) cimg::swap(_m,_M); + int + m = (int)std::ceil(_m), + M = (int)std::floor(_M), + val = 0; + if (!include_min) ++m; + if (!include_max) --M; + if (m>M) return cimg::type::nan(); + if (M==m) return m; + do { val = (int)std::floor(cimg::rand(m,M + 1,&mp.rng)); } while (val>M); + return val; + } + static double mp_ui2f(_cimg_math_parser& mp) { return (double)cimg::uint2float((unsigned int)_mp_arg(2)); } @@ -30374,6 +30565,24 @@ namespace cimg_library { return (s%2)?res:(T)((res + kth_smallest((s>>1) - 1))/2); } + //! Return greatest common diviser of all image values. + T gcd() const { + if (is_empty()) return 0; + const ulongT siz = size(); + longT res = (longT)*_data; + for (ulongT k = 1; k _get_invert_svd(const float lambda) const { CImg U, S, V; SVD(U,S,V,false); - const Tfloat epsilon = (sizeof(Tfloat)<=4?5.96e-8f:1.11e-16f)*std::max(_width,_height)*S.max(); + const Tfloat eps = (sizeof(Tfloat)<=4?5.96e-8f:1.11e-16f)*std::max(_width,_height)*S.max(); cimg_forX(V,x) { - const Tfloat s = S(x), invs = lambda?1/(lambda + s):s>epsilon?1/s:0; + const Tfloat s = S(x), invs = lambda?1/(lambda + s):s>eps?1/s:0; cimg_forY(V,y) V(x,y)*=invs; } return V*U.transpose(); @@ -31475,15 +31684,15 @@ namespace cimg_library { cimg_instance, A._width,A._height,A._depth,A._spectrum,A._data); typedef _cimg_Ttfloat Ttfloat; - const Ttfloat epsilon = 1e-4f; + const Ttfloat eps = 1e-4f; CImg B = A.get_column(1), V(*this,false); for (int i = 1; i<(int)siz; ++i) { - const Ttfloat m = A(0,i)/(B[i - 1]?B[i - 1]:epsilon); + const Ttfloat m = A(0,i)/(B[i - 1]?B[i - 1]:eps); B[i] -= m*A(2,i - 1); V[i] -= m*V[i - 1]; } - (*this)[siz - 1] = (T)(V[siz - 1]/(B[siz - 1]?B[siz - 1]:epsilon)); - for (int i = (int)siz - 2; i>=0; --i) (*this)[i] = (T)((V[i] - A(2,i)*(*this)[i + 1])/(B[i]?B[i]:epsilon)); + (*this)[siz - 1] = (T)(V[siz - 1]/(B[siz - 1]?B[siz - 1]:eps)); + for (int i = (int)siz - 2; i>=0; --i) (*this)[i] = (T)((V[i] - A(2,i)*(*this)[i + 1])/(B[i]?B[i]:eps)); return *this; } @@ -31799,7 +32008,7 @@ namespace cimg_library { const CImg& SVD(CImg& U, CImg& S, CImg& V, const bool sorting=true, const unsigned int max_iteration=40, const float lambda=0) const { typedef _cimg_Ttfloat Ttfloat; - const Ttfloat epsilon = (Ttfloat)1e-25; + const Ttfloat eps = (Ttfloat)1e-25; if (is_empty()) { U.assign(); S.assign(); V.assign(); } else if (_depth!=1 || _spectrum!=1) @@ -31938,9 +32147,9 @@ namespace cimg_library { t x = S[l], y = S[nm]; g = rv1[nm]; h = rv1[k]; - f = ((y - z)*(y + z) + (g - h)*(g + h))/std::max(epsilon,(Ttfloat)2*h*y); + f = ((y - z)*(y + z) + (g - h)*(g + h))/std::max(eps,(Ttfloat)2*h*y); g = cimg::hypot(f,(Ttfloat)1); - f = ((x - z)*(x + z) + h*((y/(f + (f>=0?g:-g))) - h))/std::max(epsilon,(Ttfloat)x); + f = ((x - z)*(x + z) + h*((y/(f + (f>=0?g:-g))) - h))/std::max(eps,(Ttfloat)x); c = s = 1; for (int j = l; j<=nm; ++j) { const int i = j + 1; @@ -31949,8 +32158,8 @@ namespace cimg_library { g = c*g; t y1 = S[i], z1 = cimg::hypot(f,h); rv1[j] = z1; - c = f/std::max(epsilon,(Ttfloat)z1); - s = h/std::max(epsilon,(Ttfloat)z1); + c = f/std::max(eps,(Ttfloat)z1); + s = h/std::max(eps,(Ttfloat)z1); f = x*c + g*s; g = g*c - x*s; h = y1*s; @@ -31963,7 +32172,7 @@ namespace cimg_library { z1 = cimg::hypot(f,h); S[j] = z1; if (z1) { - z1 = 1/std::max(epsilon,(Ttfloat)z1); + z1 = 1/std::max(eps,(Ttfloat)z1); c = f*z1; s = h*z1; }