diff --git a/CImg.h b/CImg.h index 7bebd95a..4b82e8ea 100644 --- a/CImg.h +++ b/CImg.h @@ -19917,7 +19917,7 @@ namespace cimg_library { pixel_type(),_cimg_mp_calling_function,s_op, std::max(p1,1U),arg2,arg3,arg4,arg5,(ulongT)arg2*arg3*arg4*arg5); pos = vector(arg2*arg3*arg4*arg5); - CImg::vector((ulongT)mp_vector_cumulate,pos,arg1,arg2,arg3,arg4,arg5,arg6,p2).move_to(code); + CImg::vector((ulongT)mp_cumulate,pos,arg1,arg2,arg3,arg4,arg5,arg6,p2).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -20640,7 +20640,7 @@ namespace cimg_library { 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); + CImg::vector((ulongT)mp_equalize,pos,arg1,p1,arg2,arg3,arg4).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -21036,7 +21036,7 @@ namespace cimg_library { 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); + CImg::vector((ulongT)mp_histogram,pos,arg1,p1,arg2,arg3,arg4).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -21130,7 +21130,7 @@ namespace cimg_library { pixel_type(),_cimg_mp_calling_function,s_op, std::max(p1,1U),arg3); pos = vector(arg5?p1:p1/arg3); - CImg::vector((ulongT)mp_vector_index,pos,arg1,p1,arg2,p2,arg3,arg4,arg5).move_to(code); + CImg::vector((ulongT)mp_index,pos,arg1,p1,arg2,p2,arg3,arg4,arg5).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -21551,7 +21551,7 @@ namespace cimg_library { pixel_type(),_cimg_mp_calling_function,s_op, std::max(p1,1U),arg2,arg3,arg4,arg5,(ulongT)arg2*arg3*arg4*arg5); pos = vector(arg2*arg3*arg4*arg5); - CImg::vector((ulongT)mp_vector_mirror,pos,arg1,arg2,arg3,arg4,arg5,arg6,p2).move_to(code); + CImg::vector((ulongT)mp_mirror,pos,arg1,arg2,arg3,arg4,arg5,arg6,p2).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -21740,7 +21740,7 @@ namespace cimg_library { _cimg_mp_check_type(arg3,3,1,0); p1 = size(arg1); pos = vector(p1); - CImg::vector((ulongT)mp_vector_noise,pos,arg1,p1,arg2,arg3).move_to(code); + CImg::vector((ulongT)mp_noise,pos,arg1,p1,arg2,arg3).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -21768,7 +21768,7 @@ namespace cimg_library { 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); + CImg::vector((ulongT)mp_normalize,pos,arg1,p1,arg2,arg3,arg4).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -21780,7 +21780,7 @@ namespace cimg_library { arg2 = s1::vector((ulongT)mp_vector_permute,pos,arg1,arg2,arg3,arg4,arg5,arg6,p2).move_to(code); + CImg::vector((ulongT)mp_permute,pos,arg1,arg2,arg3,arg4,arg5,arg6,p2).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -22178,7 +22178,7 @@ namespace cimg_library { 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); + CImg::vector((ulongT)mp_reverse,pos,arg1,p1).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -22388,7 +22388,7 @@ namespace cimg_library { p1 = size(arg1); if (p1>0) pos = is_comp_vector(arg1)?arg1:((return_comp = true), vector(p1)); else _cimg_mp_return(1); - CImg::vector((ulongT)mp_vector_softmax,pos,arg1,p1,arg2).move_to(code); + CImg::vector((ulongT)mp_softmax,pos,arg1,p1,arg2).move_to(code); _cimg_mp_return(pos); } @@ -22434,23 +22434,28 @@ namespace cimg_library { _cimg_mp_op("Function 'sort()'"); s1 = ss5; while (s1::vector((ulongT)mp_sort,pos,arg1,p1,arg2,arg3,arg4).move_to(code); + CImg::vector((ulongT)mp_sort,pos,arg1,p1,arg2,arg3,arg4,arg5).move_to(code); return_comp = true; _cimg_mp_return(pos); } @@ -22821,7 +22826,7 @@ namespace cimg_library { _cimg_mp_const_scalar(val?(mem[arg2]?1:val):0); } } - CImg::vector((ulongT)mp_vector_unitnorm,pos,arg1,p1,arg2).move_to(code); + CImg::vector((ulongT)mp_unitnorm,pos,arg1,p1,arg2).move_to(code); _cimg_mp_return(pos); } @@ -23091,7 +23096,7 @@ namespace cimg_library { std::max(p2,1U),arg3,arg4,arg5,arg6,(ulongT)arg3*arg4*arg5*arg6); pos = vector(arg3*arg4*arg5*(unsigned int)opcode[4]); opcode.resize(1,15,1,1,0,0,0,1); - opcode[0] = (ulongT)mp_vector_warp; + opcode[0] = (ulongT)mp_warp; opcode[1] = (ulongT)pos; opcode.move_to(code); return_comp = true; @@ -23156,7 +23161,7 @@ namespace cimg_library { (l_opcode>'y').move_to(opcode); op = val==2?(is_hypot && opcode._height<8?_mp_vector_hypot:_mp_vector_norm2): val==1?_mp_vector_norm1:!val?_mp_vector_norm0: - cimg::type::is_inf(val)?_mp_vector_norminf:_mp_vector_normp; + cimg::type::is_inf(val)?_mp_vector_norminf:_mp_normp; opcode[0] = (ulongT)op; opcode[2] = opcode._height; if (is_sth) _cimg_mp_const_scalar(op(*this)); @@ -25100,26 +25105,6 @@ namespace cimg_library { return mp.mem[g_target]; } - static double mp_image_crop(_cimg_math_parser& mp) { - double *ptrd = &_mp_arg(1) + 1; - const int x = (int)_mp_arg(3), y = (int)_mp_arg(4), z = (int)_mp_arg(5), c = (int)_mp_arg(6); - const unsigned int - dx = (unsigned int)mp.opcode[7], - dy = (unsigned int)mp.opcode[8], - dz = (unsigned int)mp.opcode[9], - dc = (unsigned int)mp.opcode[10]; - const unsigned int boundary_conditions = (unsigned int)_mp_arg(11); - unsigned int ind = (unsigned int)mp.opcode[2]; - if (ind!=~0U) ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width()); - const CImg &img = ind==~0U?mp.imgin:mp.imglist[ind]; - if (!img) std::memset(ptrd,0,dx*dy*dz*dc*sizeof(double)); - else CImg(ptrd,dx,dy,dz,dc,true) = img.get_crop(x,y,z,c, - x + dx - 1,y + dy - 1, - z + dz - 1,c + dc - 1, - boundary_conditions); - return cimg::type::nan(); - } - static double mp_cross(_cimg_math_parser& mp) { CImg vout(&_mp_arg(1) + 1,1,3,1,1,true), @@ -25129,6 +25114,29 @@ namespace cimg_library { return cimg::type::nan(); } + static double mp_cumulate(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int + wA = (unsigned int)mp.opcode[3], + hA = (unsigned int)mp.opcode[4], + dA = (unsigned int)mp.opcode[5], + sA = (unsigned int)mp.opcode[6], + sizp = (unsigned int)mp.opcode[8]; + const double + *const ptrs = &_mp_arg(2) + 1, + *const ptrp = sizp!=~0U?&_mp_arg(7) + 1:0; + CImg str; + if (ptrp) { + str.assign(std::max(1U,sizp) + 1); + if (!sizp) str[0] = _mp_arg(7); + else for (unsigned int p = 0; p(ptrd,wA,hA,dA,sA,true) = CImg(ptrs,wA,hA,dA,sA,true). + get_cumulate(str); + return cimg::type::nan(); + } + static double mp_cut(_cimg_math_parser& mp) { double val = _mp_arg(2), cmin = _mp_arg(3), cmax = _mp_arg(4); return valcmax?cmax:val; @@ -25609,6 +25617,22 @@ namespace cimg_library { return (double)(_mp_arg(2)==_mp_arg(3)); } + static double mp_equalize(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int + siz = (unsigned int)mp.opcode[3], + nb_levels = (unsigned int)mp.opcode[4]; + const double *const ptrs = &_mp_arg(2) + 1; + CImg img(ptrs,siz,1,1,1,true); + double min_value = 0, max_value = 0; + if ((unsigned int)mp.opcode[5]==~0U || (unsigned int)mp.opcode[6]==~0U) + min_value = img.min_max(max_value); + if ((unsigned int)mp.opcode[5]!=~0U) min_value = _mp_arg(5); + if ((unsigned int)mp.opcode[6]!=~0U) max_value = _mp_arg(6); + CImg(ptrd,siz,1,1,1,true) = img.get_equalize(nb_levels,min_value,max_value); + return cimg::type::nan(); + } + #if cimg_use_cpp11==1 static double mp_erf(_cimg_math_parser& mp) { return std::erf(_mp_arg(2)); @@ -25926,20 +25950,6 @@ namespace cimg_library { return values.gcd(); } -#ifdef cimg_mp_func_name - static double mp_name(_cimg_math_parser& mp) { - double *const ptr = &_mp_arg(1) + 1; - const unsigned int siz = (unsigned int)mp.opcode[3]; - unsigned int ind = (unsigned int)mp.opcode[2]; - if (ind==~0U) std::memset(ptr,0,siz*sizeof(double)); - else { - ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width()); - cimg_mp_func_name(ind,ptr,siz); - } - return cimg::type::nan(); - } -#endif - static double mp_gt(_cimg_math_parser& mp) { return (double)(_mp_arg(2)>_mp_arg(3)); } @@ -25948,6 +25958,22 @@ namespace cimg_library { return (double)(_mp_arg(2)>=_mp_arg(3)); } + static double mp_histogram(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int + siz = (unsigned int)mp.opcode[3], + nb_levels = (unsigned int)mp.opcode[4]; + const double *const ptrs = &_mp_arg(2) + 1; + CImg img(ptrs,siz,1,1,1,true); + double min_value = 0, max_value = 0; + if ((unsigned int)mp.opcode[5]==~0U || (unsigned int)mp.opcode[6]==~0U) + min_value = img.min_max(max_value); + if ((unsigned int)mp.opcode[5]!=~0U) min_value = _mp_arg(5); + if ((unsigned int)mp.opcode[6]!=~0U) max_value = _mp_arg(6); + CImg(ptrd,nb_levels,1,1,1,true) = img.get_histogram(nb_levels,min_value,max_value); + return cimg::type::nan(); + } + static double mp_i(_cimg_math_parser& mp) { if (mp.imgin) return (double)mp.imgin((int)mp.mem[_cimg_mp_slot_x],(int)mp.mem[_cimg_mp_slot_y], @@ -25980,6 +26006,26 @@ namespace cimg_library { return mp.mem[is_cond?mem_left:mem_right]; } + static double mp_image_crop(_cimg_math_parser& mp) { + double *ptrd = &_mp_arg(1) + 1; + const int x = (int)_mp_arg(3), y = (int)_mp_arg(4), z = (int)_mp_arg(5), c = (int)_mp_arg(6); + const unsigned int + dx = (unsigned int)mp.opcode[7], + dy = (unsigned int)mp.opcode[8], + dz = (unsigned int)mp.opcode[9], + dc = (unsigned int)mp.opcode[10]; + const unsigned int boundary_conditions = (unsigned int)_mp_arg(11); + unsigned int ind = (unsigned int)mp.opcode[2]; + if (ind!=~0U) ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width()); + const CImg &img = ind==~0U?mp.imgin:mp.imglist[ind]; + if (!img) std::memset(ptrd,0,dx*dy*dz*dc*sizeof(double)); + else CImg(ptrd,dx,dy,dz,dc,true) = img.get_crop(x,y,z,c, + x + dx - 1,y + dy - 1, + z + dz - 1,c + dc - 1, + boundary_conditions); + return cimg::type::nan(); + } + static double mp_image_d(_cimg_math_parser& mp) { unsigned int ind = (unsigned int)mp.opcode[2]; if (ind!=~0U) { @@ -26207,6 +26253,25 @@ namespace cimg_library { return _mp_arg(2) + 1; } + static double mp_index(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int + sizA = (unsigned int)mp.opcode[3], + sizP = (unsigned int)mp.opcode[5], + dim_colors = (unsigned int)mp.opcode[6], + nb_colors = sizP/dim_colors, + wA = sizA/dim_colors; + const double dithering = _mp_arg(7); + const bool map_colors = (bool)mp.opcode[8]; + const double + *const ptrs = &_mp_arg(2) + 1, + *const ptrp = &_mp_arg(4) + 1; + CImg colormap(ptrp,nb_colors,1,1,dim_colors,true); + CImg(ptrd,wA,1,1,map_colors?dim_colors:1,true) = CImg(ptrs,wA,1,1,dim_colors,true). + get_index(colormap,dithering,map_colors); + return cimg::type::nan(); + } + static double mp_inrange(_cimg_math_parser& mp) { const unsigned int sizd = (unsigned int)mp.opcode[2]; const bool @@ -27726,6 +27791,26 @@ namespace cimg_library { return -_mp_arg(2); } + static double mp_mirror(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int + wA = (unsigned int)mp.opcode[3], + hA = (unsigned int)mp.opcode[4], + dA = (unsigned int)mp.opcode[5], + sA = (unsigned int)mp.opcode[6], + sizp = (unsigned int)mp.opcode[8]; + const double + *const ptrs = &_mp_arg(2) + 1, + *const ptrp = &_mp_arg(7) + 1; + CImg str(std::max(1U,sizp) + 1); + if (!sizp) str[0] = _mp_arg(7); + else for (unsigned int p = 0; p(ptrd,wA,hA,dA,sA,true) = CImg(ptrs,wA,hA,dA,sA,true). + get_mirror(str); + return cimg::type::nan(); + } + static double mp_med(_cimg_math_parser& mp) { const unsigned int i_end = (unsigned int)mp.opcode[2]; CImg values; @@ -27788,10 +27873,87 @@ namespace cimg_library { return _mp_arg(2)*_mp_arg(3)*_mp_arg(4); } +#ifdef cimg_mp_func_name + static double mp_name(_cimg_math_parser& mp) { + double *const ptr = &_mp_arg(1) + 1; + const unsigned int siz = (unsigned int)mp.opcode[3]; + unsigned int ind = (unsigned int)mp.opcode[2]; + if (ind==~0U) std::memset(ptr,0,siz*sizeof(double)); + else { + ind = (unsigned int)cimg::mod((int)_mp_arg(2),mp.imglist.width()); + cimg_mp_func_name(ind,ptr,siz); + } + return cimg::type::nan(); + } +#endif + static double mp_neq(_cimg_math_parser& mp) { return (double)(_mp_arg(2)!=_mp_arg(3)); } + static double mp_noise(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int + siz = (unsigned int)mp.opcode[3], + noise_type = (unsigned int)_mp_arg(5); + const double + *const ptrs = &_mp_arg(2) + 1, + amplitude = _mp_arg(4); + CImg(ptrd,siz,1,1,1,true) = CImg(ptrs,siz,1,1,1,true).get_noise(amplitude,noise_type); + return cimg::type::nan(); + } + + static double mp_normalize(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int siz = (unsigned int)mp.opcode[3]; + const double + *const ptrs = &_mp_arg(2) + 1, + min_value = _mp_arg(4), + max_value = _mp_arg(5), + constant_case_ratio = _mp_arg(6); + CImg(ptrd,siz,1,1,1,true) = CImg(ptrs,siz,1,1,1,true). + get_normalize(min_value,max_value,constant_case_ratio); + return cimg::type::nan(); + } + + static double _mp_normp(_cimg_math_parser& mp) { + const unsigned int siz = (unsigned int)mp.opcode[2]; + const double p = _mp_arg(3); + double res = 0; + for (unsigned int i = siz - 1; i>3; --i) res+=(double)std::pow(cimg::abs(_mp_arg(i)),p); + res = (double)std::pow(res,1.0/p); + return res; + } + + static double mp_normp(_cimg_math_parser& mp) { + const unsigned int siz = (unsigned int)mp.opcode[3]; + const double p = _mp_arg(4); + if (siz>0) { // Vector-valued argument + const double *ptrs = &_mp_arg(2) + 1; + double res = 0; + if (p==2) { // L2 + for (unsigned int i = 0; i::is_inf(p)) { // L-inf + for (unsigned int i = 0; ires) res = val; + } + } else { // L-p + for (unsigned int i = 0; i0?res:0; + } + // Scalar-valued argument. + const double val = _mp_arg(2); + return p?cimg::abs(val):(val!=0); + } + static double mp_o2c(_cimg_math_parser& mp) { unsigned int ind = (unsigned int)mp.opcode[2]; if (ind!=~0U) { @@ -27819,6 +27981,25 @@ namespace cimg_library { return cimg::permutations((int)_mp_arg(2),(int)_mp_arg(3),(bool)_mp_arg(4)); } + static double mp_permute(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int + wA = (unsigned int)mp.opcode[3], + hA = (unsigned int)mp.opcode[4], + dA = (unsigned int)mp.opcode[5], + sA = (unsigned int)mp.opcode[6], + sizp = (unsigned int)mp.opcode[8]; + const double + *const ptrs = &_mp_arg(2) + 1, + *const ptrp = &_mp_arg(7) + 1; + CImg str(sizp + 1); + for (unsigned int p = 0; p(ptrd,wA,hA,dA,sA,true) = CImg(ptrs,wA,hA,dA,sA,true). + get_permute_axes(str); + return cimg::type::nan(); + } + static double mp_polygon(_cimg_math_parser& mp) { const unsigned int i_end = (unsigned int)mp.opcode[2]; unsigned int ind = (unsigned int)mp.opcode[3]; @@ -27971,6 +28152,14 @@ namespace cimg_library { return *ptrs; } + static double mp_reverse(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const double *const ptrs = &_mp_arg(2) + 1; + const unsigned int siz = (unsigned int)mp.opcode[3]; + CImg(ptrd,siz,1,1,1,true) = CImg(ptrs,siz,1,1,1,true).get_mirror('x'); + return cimg::type::nan(); + } + static double mp_rol(_cimg_math_parser& mp) { return cimg::rol(_mp_arg(2),(unsigned int)_mp_arg(3)); } @@ -28337,6 +28526,19 @@ namespace cimg_library { return std::sinh(_mp_arg(2)); } + static double mp_softmax(_cimg_math_parser& mp) { + const unsigned int siz = (unsigned int)mp.opcode[3]; + const double temperature = _mp_arg(4); + if (siz>0) { // Vector-valued argument + double *const ptrd = &_mp_arg(1) + 1; + const double *const ptrs = &_mp_arg(2) + 1; + CImg(ptrd,siz,1,1,1,true) = CImg(ptrs,siz,1,1,1,true).get_softmax(temperature); + return cimg::type::nan(); + } + // Scalar-valued argument. + return 1; + } + static double mp_solve(_cimg_math_parser& mp) { double *ptrd = &_mp_arg(1) + 1; const double @@ -28359,7 +28561,8 @@ namespace cimg_library { const unsigned int siz = (unsigned int)mp.opcode[3], nb_elts = mp.opcode[5]==~0U?siz:(unsigned int)_mp_arg(5), - siz_elt = (unsigned int)_mp_arg(6); + siz_elt = (unsigned int)_mp_arg(6), + sort_index = std::min((unsigned int)_mp_arg(7),siz_elt - 1); const ulongT sn = siz_elt*nb_elts; if (sn>siz || siz_elt<1) throw CImgArgumentException("[" cimg_appname "_math_parser] CImg<%s>: Function 'sort()': " @@ -28367,7 +28570,7 @@ namespace cimg_library { "for sorting a vector of size %u.", mp.imgin.pixel_type(),_mp_arg(5),_mp_arg(6),siz); CImg(ptrd,siz_elt,nb_elts,1,1,true) = CImg(ptrs,siz_elt,nb_elts,1,1,true). - get_sort(is_increasing,siz_elt>1?'y':0); + shift(-(int)sort_index,0,0,0,2).get_sort(is_increasing,siz_elt>1?'y':0).shift((int)sort_index,0,0,0,2); if (sn(ptrd + sn,siz - sn,1,1,1,true) = CImg(ptrs + sn,siz - sn,1,1,1,true); return cimg::type::nan(); } @@ -28648,6 +28851,23 @@ namespace cimg_library { return (double)cimg::uint2float((unsigned int)_mp_arg(2)); } + static double mp_unitnorm(_cimg_math_parser& mp) { + const unsigned int siz = (unsigned int)mp.opcode[3]; + const double p = _mp_arg(4); + if (siz>0) { // Vector-valued argument + double *const ptrd = &_mp_arg(1) + 1; + const double *const ptrs = &_mp_arg(2) + 1; + if (ptrd!=ptrs) std::memcpy(ptrd,ptrs,siz*sizeof(double)); + CImg vec(ptrd,siz,1,1,1,true); + const double mag = vec.magnitude(p); + if (mag>0) vec/=mag; + return cimg::type::nan(); + } + // Scalar-valued argument. + const double val = _mp_arg(2); + return val?(_mp_arg(2)?1:val):0; + } + static double mp_uppercase(_cimg_math_parser& mp) { return cimg::uppercase(_mp_arg(2)); } @@ -28710,29 +28930,6 @@ namespace cimg_library { return cimg::type::nan(); } - static double mp_vector_cumulate(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int - wA = (unsigned int)mp.opcode[3], - hA = (unsigned int)mp.opcode[4], - dA = (unsigned int)mp.opcode[5], - sA = (unsigned int)mp.opcode[6], - sizp = (unsigned int)mp.opcode[8]; - const double - *const ptrs = &_mp_arg(2) + 1, - *const ptrp = sizp!=~0U?&_mp_arg(7) + 1:0; - CImg str; - if (ptrp) { - str.assign(std::max(1U,sizp) + 1); - if (!sizp) str[0] = _mp_arg(7); - else for (unsigned int p = 0; p(ptrd,wA,hA,dA,sA,true) = CImg(ptrs,wA,hA,dA,sA,true). - get_cumulate(str); - return cimg::type::nan(); - } - static double mp_vector_draw(_cimg_math_parser& mp) { double *const ptrd = &_mp_arg(1) + 1; const double *const ptrs = &_mp_arg(7) + 1; @@ -28785,38 +28982,6 @@ namespace cimg_library { return cimg::type::nan(); } - static double mp_vector_equalize(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int - siz = (unsigned int)mp.opcode[3], - nb_levels = (unsigned int)mp.opcode[4]; - const double *const ptrs = &_mp_arg(2) + 1; - CImg img(ptrs,siz,1,1,1,true); - double min_value = 0, max_value = 0; - if ((unsigned int)mp.opcode[5]==~0U || (unsigned int)mp.opcode[6]==~0U) - min_value = img.min_max(max_value); - if ((unsigned int)mp.opcode[5]!=~0U) min_value = _mp_arg(5); - if ((unsigned int)mp.opcode[6]!=~0U) max_value = _mp_arg(6); - CImg(ptrd,siz,1,1,1,true) = img.get_equalize(nb_levels,min_value,max_value); - return cimg::type::nan(); - } - - static double mp_vector_histogram(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int - siz = (unsigned int)mp.opcode[3], - nb_levels = (unsigned int)mp.opcode[4]; - const double *const ptrs = &_mp_arg(2) + 1; - CImg img(ptrs,siz,1,1,1,true); - double min_value = 0, max_value = 0; - if ((unsigned int)mp.opcode[5]==~0U || (unsigned int)mp.opcode[6]==~0U) - min_value = img.min_max(max_value); - if ((unsigned int)mp.opcode[5]!=~0U) min_value = _mp_arg(5); - if ((unsigned int)mp.opcode[6]!=~0U) max_value = _mp_arg(6); - CImg(ptrd,nb_levels,1,1,1,true) = img.get_histogram(nb_levels,min_value,max_value); - return cimg::type::nan(); - } - static double _mp_vector_hypot(_cimg_math_parser& mp) { switch ((unsigned int)mp.opcode[2]) { case 5 : return cimg::abs(_mp_arg(4)); @@ -28826,25 +28991,6 @@ namespace cimg_library { return _mp_vector_norm2(mp); } - static double mp_vector_index(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int - sizA = (unsigned int)mp.opcode[3], - sizP = (unsigned int)mp.opcode[5], - dim_colors = (unsigned int)mp.opcode[6], - nb_colors = sizP/dim_colors, - wA = sizA/dim_colors; - const double dithering = _mp_arg(7); - const bool map_colors = (bool)mp.opcode[8]; - const double - *const ptrs = &_mp_arg(2) + 1, - *const ptrp = &_mp_arg(4) + 1; - CImg colormap(ptrp,nb_colors,1,1,dim_colors,true); - CImg(ptrd,wA,1,1,map_colors?dim_colors:1,true) = CImg(ptrs,wA,1,1,dim_colors,true). - get_index(colormap,dithering,map_colors); - return cimg::type::nan(); - } - static double mp_vector_init(_cimg_math_parser& mp) { unsigned int ptrs = 4U, @@ -28988,56 +29134,10 @@ namespace cimg_library { return cimg::type::nan(); } - static double mp_vector_mirror(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int - wA = (unsigned int)mp.opcode[3], - hA = (unsigned int)mp.opcode[4], - dA = (unsigned int)mp.opcode[5], - sA = (unsigned int)mp.opcode[6], - sizp = (unsigned int)mp.opcode[8]; - const double - *const ptrs = &_mp_arg(2) + 1, - *const ptrp = &_mp_arg(7) + 1; - CImg str(std::max(1U,sizp) + 1); - if (!sizp) str[0] = _mp_arg(7); - else for (unsigned int p = 0; p(ptrd,wA,hA,dA,sA,true) = CImg(ptrs,wA,hA,dA,sA,true). - get_mirror(str); - return cimg::type::nan(); - } - static double mp_vector_neq(_cimg_math_parser& mp) { return !mp_vector_eq(mp); } - static double mp_vector_noise(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int - siz = (unsigned int)mp.opcode[3], - noise_type = (unsigned int)_mp_arg(5); - const double - *const ptrs = &_mp_arg(2) + 1, - amplitude = _mp_arg(4); - CImg(ptrd,siz,1,1,1,true) = CImg(ptrs,siz,1,1,1,true).get_noise(amplitude,noise_type); - return cimg::type::nan(); - } - - - static double mp_vector_normalize(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int siz = (unsigned int)mp.opcode[3]; - const double - *const ptrs = &_mp_arg(2) + 1, - min_value = _mp_arg(4), - max_value = _mp_arg(5), - constant_case_ratio = _mp_arg(6); - CImg(ptrd,siz,1,1,1,true) = CImg(ptrs,siz,1,1,1,true). - get_normalize(min_value,max_value,constant_case_ratio); - return cimg::type::nan(); - } - static double _mp_vector_norm0(_cimg_math_parser& mp) { const unsigned int siz = (unsigned int)mp.opcode[2]; double res = 0; @@ -29069,63 +29169,6 @@ namespace cimg_library { return res; } - static double _mp_vector_normp(_cimg_math_parser& mp) { - const unsigned int siz = (unsigned int)mp.opcode[2]; - const double p = _mp_arg(3); - double res = 0; - for (unsigned int i = siz - 1; i>3; --i) res+=(double)std::pow(cimg::abs(_mp_arg(i)),p); - res = (double)std::pow(res,1.0/p); - return res; - } - - static double mp_vector_normp(_cimg_math_parser& mp) { - const unsigned int siz = (unsigned int)mp.opcode[3]; - const double p = _mp_arg(4); - if (siz>0) { // Vector-valued argument - const double *ptrs = &_mp_arg(2) + 1; - double res = 0; - if (p==2) { // L2 - for (unsigned int i = 0; i::is_inf(p)) { // L-inf - for (unsigned int i = 0; ires) res = val; - } - } else { // L-p - for (unsigned int i = 0; i0?res:0; - } - // Scalar-valued argument. - const double val = _mp_arg(2); - return p?cimg::abs(val):(val!=0); - } - - static double mp_vector_permute(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int - wA = (unsigned int)mp.opcode[3], - hA = (unsigned int)mp.opcode[4], - dA = (unsigned int)mp.opcode[5], - sA = (unsigned int)mp.opcode[6], - sizp = (unsigned int)mp.opcode[8]; - const double - *const ptrs = &_mp_arg(2) + 1, - *const ptrp = &_mp_arg(7) + 1; - CImg str(sizp + 1); - for (unsigned int p = 0; p(ptrd,wA,hA,dA,sA,true) = CImg(ptrs,wA,hA,dA,sA,true). - get_permute_axes(str); - return cimg::type::nan(); - } - static double mp_vector_print(_cimg_math_parser& mp) { const bool print_string = (bool)mp.opcode[4]; cimg_pragma_openmp(critical(mp_vector_print)) @@ -29232,14 +29275,6 @@ namespace cimg_library { return cimg::type::nan(); } - static double mp_vector_reverse(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const double *const ptrs = &_mp_arg(2) + 1; - const unsigned int siz = (unsigned int)mp.opcode[3]; - CImg(ptrd,siz,1,1,1,true) = CImg(ptrs,siz,1,1,1,true).get_mirror('x'); - return cimg::type::nan(); - } - static double mp_vector_set_off(_cimg_math_parser& mp) { const unsigned int ptr = (unsigned int)mp.opcode[2] + 1, @@ -29249,59 +29284,6 @@ namespace cimg_library { return _mp_arg(1); } - static double mp_vector_softmax(_cimg_math_parser& mp) { - const unsigned int siz = (unsigned int)mp.opcode[3]; - const double temperature = _mp_arg(4); - if (siz>0) { // Vector-valued argument - double *const ptrd = &_mp_arg(1) + 1; - const double *const ptrs = &_mp_arg(2) + 1; - CImg(ptrd,siz,1,1,1,true) = CImg(ptrs,siz,1,1,1,true).get_softmax(temperature); - return cimg::type::nan(); - } - // Scalar-valued argument. - return 1; - } - - static double mp_vector_unitnorm(_cimg_math_parser& mp) { - const unsigned int siz = (unsigned int)mp.opcode[3]; - const double p = _mp_arg(4); - if (siz>0) { // Vector-valued argument - double *const ptrd = &_mp_arg(1) + 1; - const double *const ptrs = &_mp_arg(2) + 1; - if (ptrd!=ptrs) std::memcpy(ptrd,ptrs,siz*sizeof(double)); - CImg vec(ptrd,siz,1,1,1,true); - const double mag = vec.magnitude(p); - if (mag>0) vec/=mag; - return cimg::type::nan(); - } - // Scalar-valued argument. - const double val = _mp_arg(2); - return val?(_mp_arg(2)?1:val):0; - } - - static double mp_vector_warp(_cimg_math_parser& mp) { - double *const ptrd = &_mp_arg(1) + 1; - const unsigned int - wA = (unsigned int)mp.opcode[3], - hA = (unsigned int)mp.opcode[4], - dA = (unsigned int)mp.opcode[5], - sA = (unsigned int)mp.opcode[6], - wB = (unsigned int)mp.opcode[8], - hB = (unsigned int)mp.opcode[9], - dB = (unsigned int)mp.opcode[10], - sB = (unsigned int)mp.opcode[11]; - const int - mode = (int)_mp_arg(12), - interpolation = (int)_mp_arg(13), - boundary_conditions = (int)_mp_arg(14); - const double - *const ptrs = &_mp_arg(2) + 1, - *const ptrw = &_mp_arg(7) + 1; - CImg(ptrd,wB,hB,dB,sA,true) = CImg(ptrs,wA,hA,dA,sA,true). - get_warp(CImg(ptrw,wB,hB,dB,sB,true),mode,interpolation,boundary_conditions); - return cimg::type::nan(); - } - #define _cimg_mp_vfunc(func) \ const longT sizd = (longT)mp.opcode[2];\ const unsigned int nbargs = (unsigned int)(mp.opcode[3] - 4)/2; \ @@ -29414,7 +29396,30 @@ namespace cimg_library { const unsigned int l = std::min(sizd,(unsigned int)std::strlen(str) + 1); CImg(ptrd,l,1,1,1,true) = str.get_shared_points(0,l - 1); return cimg::type::nan(); - } + } + + static double mp_warp(_cimg_math_parser& mp) { + double *const ptrd = &_mp_arg(1) + 1; + const unsigned int + wA = (unsigned int)mp.opcode[3], + hA = (unsigned int)mp.opcode[4], + dA = (unsigned int)mp.opcode[5], + sA = (unsigned int)mp.opcode[6], + wB = (unsigned int)mp.opcode[8], + hB = (unsigned int)mp.opcode[9], + dB = (unsigned int)mp.opcode[10], + sB = (unsigned int)mp.opcode[11]; + const int + mode = (int)_mp_arg(12), + interpolation = (int)_mp_arg(13), + boundary_conditions = (int)_mp_arg(14); + const double + *const ptrs = &_mp_arg(2) + 1, + *const ptrw = &_mp_arg(7) + 1; + CImg(ptrd,wB,hB,dB,sA,true) = CImg(ptrs,wA,hA,dA,sA,true). + get_warp(CImg(ptrw,wB,hB,dB,sB,true),mode,interpolation,boundary_conditions); + return cimg::type::nan(); + } static double mp_while(_cimg_math_parser& mp) { const ulongT diff --git a/html/header.html b/html/header.html index 266a764e..311d37ff 100644 --- a/html/header.html +++ b/html/header.html @@ -23,7 +23,7 @@
Logo

- Latest stable version: 3.4.2        Current pre-release: 3.4.3 (2024/09/12) + Latest stable version: 3.4.2        Current pre-release: 3.4.3 (2024/09/13)


diff --git a/html/header_doxygen.html b/html/header_doxygen.html index ef8dd74e..c9c783f4 100644 --- a/html/header_doxygen.html +++ b/html/header_doxygen.html @@ -26,7 +26,7 @@
Logo

- Latest stable version: 3.4.2        Current pre-release: 3.4.3 (2024/09/12) + Latest stable version: 3.4.2        Current pre-release: 3.4.3 (2024/09/13)