From 81c89c388a577e4067ffa4ef2833d58b71a3f04a Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Thu, 28 Mar 2024 13:00:00 +0100 Subject: [PATCH 01/10] Auto-commit for release 3.3.6_pre --- html/header.html | 2 +- html/header_doxygen.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/html/header.html b/html/header.html index fe587252..07466b27 100644 --- a/html/header.html +++ b/html/header.html @@ -23,7 +23,7 @@
Logo

- Latest stable version: 3.3.5        Current pre-release: 3.3.6 (2024/03/17) + Latest stable version: 3.3.5        Current pre-release: 3.3.6 (2024/03/28)


diff --git a/html/header_doxygen.html b/html/header_doxygen.html index 8f194cf7..71e5c6ab 100644 --- a/html/header_doxygen.html +++ b/html/header_doxygen.html @@ -26,7 +26,7 @@
Logo

- Latest stable version: 3.3.5        Current pre-release: 3.3.6 (2024/03/17) + Latest stable version: 3.3.5        Current pre-release: 3.3.6 (2024/03/28)


From c1caf4e5b9eebceb0724784ba141ac455e0723f5 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 13:03:34 +0200 Subject: [PATCH 02/10] CImg<>::draw_line(): Fix when specified coordinates are large and go outside image boundaries. --- CImg.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CImg.h b/CImg.h index be4ee62a..01cd6aa4 100644 --- a/CImg.h +++ b/CImg.h @@ -48653,7 +48653,7 @@ namespace cimg_library { int w1 = width() - 1, h1 = height() - 1, dx01 = x1 - x0, dy01 = y1 - y0; - + const float steep = (float)dx01/dy01; const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1); dx01*=-1; dy01*=-1; } @@ -48669,10 +48669,10 @@ namespace cimg_library { dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { - const int - yy0 = y - y0, - x = x0 + (dx01*yy0 + hdy01)/dy01; - if (x>=0 && x<=w1 && pattern&hatch) { + const int yy0 = y - y0; + const float fx = x0 + yy0*steep; + if (fx>=0 && fx<=w1 && pattern&hatch) { + const int x = (int)(fx + 0.5f); T *const ptrd = is_horizontal?data(y,x):data(x,y); cimg_forC(*this,c) { const T val = color[c]; From a6f2fffba5a78952899d42dcc4eb08253003096d Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 13:05:13 +0200 Subject: [PATCH 03/10] CImg<>::draw_line(): Fix when specified coordinates are large and go outside image boundaries. --- CImg.h | 1 - 1 file changed, 1 deletion(-) diff --git a/CImg.h b/CImg.h index 01cd6aa4..f0062b40 100644 --- a/CImg.h +++ b/CImg.h @@ -48663,7 +48663,6 @@ namespace cimg_library { cimg_init_scanline(opacity); const int step = y0<=y1?1:-1, - hdy01 = dy01*cimg::sign(dx01)/2, cy0 = cimg::cut(y0,0,h1), cy1 = cimg::cut(y1,0,h1) + step; dy01+=dy01?0:1; From bf53c56e821e4939355e6f6828f9af64c4b2c56e Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 13:05:46 +0200 Subject: [PATCH 04/10] CImg<>::draw_line(): Fix when specified coordinates are large and go outside image boundaries. --- CImg.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CImg.h b/CImg.h index f0062b40..59cb124d 100644 --- a/CImg.h +++ b/CImg.h @@ -48668,8 +48668,7 @@ namespace cimg_library { dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { - const int yy0 = y - y0; - const float fx = x0 + yy0*steep; + const float fx = x0 + (y - y0)*steep; if (fx>=0 && fx<=w1 && pattern&hatch) { const int x = (int)(fx + 0.5f); T *const ptrd = is_horizontal?data(y,x):data(x,y); From d9e298c413b81c3df6ca8785c8d32c14bc3f5252 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 13:31:03 +0200 Subject: [PATCH 05/10] CImg<>::draw_line(): Fix when specified coordinates are large and go outside image boundaries. --- CImg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CImg.h b/CImg.h index 59cb124d..24e51a88 100644 --- a/CImg.h +++ b/CImg.h @@ -48653,7 +48653,7 @@ namespace cimg_library { int w1 = width() - 1, h1 = height() - 1, dx01 = x1 - x0, dy01 = y1 - y0; - const float steep = (float)dx01/dy01; + const float steep = dy01?(float)dx01/dy01:0; const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1); dx01*=-1; dy01*=-1; } From 7f256ee0f395dfb0c5acb1f136d37da0b8592e98 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 13:42:25 +0200 Subject: [PATCH 06/10] CImg<>::draw_line(): Fix when specified coordinates are large and go outside image boundaries. --- CImg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CImg.h b/CImg.h index 24e51a88..62009a34 100644 --- a/CImg.h +++ b/CImg.h @@ -48653,10 +48653,10 @@ namespace cimg_library { int w1 = width() - 1, h1 = height() - 1, dx01 = x1 - x0, dy01 = y1 - y0; - const float steep = dy01?(float)dx01/dy01:0; const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1); dx01*=-1; dy01*=-1; } + const float steep = dy01?(float)dx01/dy01:0; static unsigned int hatch = ~0U - (~0U>>1); if (init_hatch) hatch = ~0U - (~0U>>1); From 458ecec4405061fd31d92297943efc95146504b3 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 13:54:30 +0200 Subject: [PATCH 07/10] . --- CImg.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/CImg.h b/CImg.h index 62009a34..fc7b6d9b 100644 --- a/CImg.h +++ b/CImg.h @@ -1062,13 +1062,13 @@ extern "C" { ((_n1##x&3)==2?(img)._height - 1 - ++y:--x))))?0:1) #define cimg_for_lineXY(x,y,x0,y0,x1,y1) \ - for (int x = (int)(x0), y = (int)(y0), _sx = 1, _sy = 1, _steep = 0, \ + for (int x = (int)(x0), y = (int)(y0), _sx = 1, _sy = 1, _slope = 0, \ _dx=(x1)>(x0)?(int)(x1) - (int)(x0):(_sx=-1,(int)(x0) - (int)(x1)), \ _dy=(y1)>(y0)?(int)(y1) - (int)(y0):(_sy=-1,(int)(y0) - (int)(y1)), \ _counter = _dx, \ - _err = _dx>_dy?(_dy>>1):((_steep=1),(_counter=_dy),(_dx>>1)); \ + _err = _dx>_dy?(_dy>>1):((_slope=1),(_counter=_dy),(_dx>>1)); \ _counter>=0; \ - --_counter, x+=_steep? \ + --_counter, x+=_slope? \ (y+=_sy,(_err-=_dx)<0?_err+=_dy,_sx:0): \ (y+=(_err-=_dy)<0?_err+=_dx,_sy:0,_sx)) @@ -48656,7 +48656,7 @@ namespace cimg_library { const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1); dx01*=-1; dy01*=-1; } - const float steep = dy01?(float)dx01/dy01:0; + const float slope = dy01?(float)dx01/dy01:0; static unsigned int hatch = ~0U - (~0U>>1); if (init_hatch) hatch = ~0U - (~0U>>1); @@ -48668,7 +48668,7 @@ namespace cimg_library { dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { - const float fx = x0 + (y - y0)*steep; + const float fx = x0 + (y - y0)*slope; if (fx>=0 && fx<=w1 && pattern&hatch) { const int x = (int)(fx + 0.5f); T *const ptrd = is_horizontal?data(y,x):data(x,y); @@ -48724,10 +48724,7 @@ namespace cimg_library { const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); - if (pattern==~0U && y0>y1) { - cimg::swap(x0,x1,y0,y1,iz0,iz1); - dx01*=-1; dy01*=-1; diz01*=-1; - } + if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1,iz0,iz1); dx01*=-1; dy01*=-1; diz01*=-1; } static unsigned int hatch = ~0U - (~0U>>1); if (init_hatch) hatch = ~0U - (~0U>>1); From adefa706d18ea5e83c0f27167de61b89dd8be3e6 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 14:04:01 +0200 Subject: [PATCH 08/10] . --- CImg.h | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/CImg.h b/CImg.h index fc7b6d9b..c074e8ec 100644 --- a/CImg.h +++ b/CImg.h @@ -48656,7 +48656,7 @@ namespace cimg_library { const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1); dx01*=-1; dy01*=-1; } - const float slope = dy01?(float)dx01/dy01:0; + const float slope_x = dy01?(float)dx01/dy01:0; static unsigned int hatch = ~0U - (~0U>>1); if (init_hatch) hatch = ~0U - (~0U>>1); @@ -48668,7 +48668,8 @@ namespace cimg_library { dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { - const float fx = x0 + (y - y0)*slope; + const int yy0 = y - y0; + const float fx = x0 + yy0*slope_x; if (fx>=0 && fx<=w1 && pattern&hatch) { const int x = (int)(fx + 0.5f); T *const ptrd = is_horizontal?data(y,x):data(x,y); @@ -48725,29 +48726,32 @@ namespace cimg_library { const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1,iz0,iz1); dx01*=-1; dy01*=-1; diz01*=-1; } + const float slope_x = dy01?(float)dx01/dy01:0, slope_z = dy01?(float)diz01/dy01:0; static unsigned int hatch = ~0U - (~0U>>1); if (init_hatch) hatch = ~0U - (~0U>>1); cimg_init_scanline(opacity); const int - step = y0<=y1?1:-1, hdy01 = dy01*cimg::sign(dx01)/2, - cy0 = cimg::cut(y0,0,h1), cy1 = cimg::cut(y1,0,h1) + step; + step = y0<=y1?1:-1, + cy0 = cimg::cut(y0,0,h1), + cy1 = cimg::cut(y1,0,h1) + step; dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { - const int - yy0 = y - y0, - x = x0 + (dx01*yy0 + hdy01)/dy01; - const float iz = iz0 + diz01*yy0/dy01; - tz *const ptrz = is_horizontal?zbuffer.data(y,x):zbuffer.data(x,y); - - if (x>=0 && x<=w1 && pattern&hatch && iz>=*ptrz) { - *ptrz = (tz)iz; - T *const ptrd = is_horizontal?data(y,x):data(x,y); - cimg_forC(*this,c) { - const T val = color[c]; - ptrd[c*_sc_whd] = opacity>=1?val:(T)(val*_sc_nopacity + ptrd[c*_sc_whd]*_sc_copacity); + const int yy0 = y - y0; + const float fx = x0 + yy0*slope_x; + const float iz = iz0 + yy0*slope_z; + if (fx>=0 && fx<=w1 && pattern&hatch) { + const int x = (int)(fx + 0.5f); + tz *const ptrz = is_horizontal?zbuffer.data(y,x):zbuffer.data(x,y); + if (iz>=*ptrz) { + *ptrz = (tz)iz; + T *const ptrd = is_horizontal?data(y,x):data(x,y); + cimg_forC(*this,c) { + const T val = color[c]; + ptrd[c*_sc_whd] = opacity>=1?val:(T)(val*_sc_nopacity + ptrd[c*_sc_whd]*_sc_copacity); + } } } if (!(hatch>>=1)) hatch = ~0U - (~0U>>1); From f9121d81cf10e966d26a8306e16746db994148b9 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 14:25:06 +0200 Subject: [PATCH 09/10] . --- CImg.h | 108 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/CImg.h b/CImg.h index c074e8ec..e7e8a088 100644 --- a/CImg.h +++ b/CImg.h @@ -48648,23 +48648,23 @@ namespace cimg_library { const tc *const color, const float opacity=1, const unsigned int pattern=~0U, const bool init_hatch=true) { if (is_empty() || !opacity || !pattern || - std::min(y0,y1)>=height() || std::max(y0,y1)<0 || - std::min(x0,x1)>=width() || std::max(x0,x1)<0) return *this; + std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) + return *this; int w1 = width() - 1, h1 = height() - 1, dx01 = x1 - x0, dy01 = y1 - y0; const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); - if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1); dx01*=-1; dy01*=-1; } + if (pattern==~0U && y0>y1) { + cimg::swap(x0,x1,y0,y1); + dx01*=-1; dy01*=-1; + } const float slope_x = dy01?(float)dx01/dy01:0; static unsigned int hatch = ~0U - (~0U>>1); if (init_hatch) hatch = ~0U - (~0U>>1); cimg_init_scanline(opacity); - const int - step = y0<=y1?1:-1, - cy0 = cimg::cut(y0,0,h1), - cy1 = cimg::cut(y1,0,h1) + step; + const int step = y0<=y1?1:-1, cy0 = cimg::cut(y0,0,h1), cy1 = cimg::cut(y1,0,h1) + step; dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { @@ -48714,34 +48714,35 @@ namespace cimg_library { "different dimensions.", cimg_instance, zbuffer._width,zbuffer._height,zbuffer._depth,zbuffer._spectrum,zbuffer._data); - - if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) return *this; - - float iz0 = 1/z0, iz1 = 1/z1; + if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) + return *this; int w1 = width() - 1, h1 = height() - 1, dx01 = x1 - x0, dy01 = y1 - y0; - float diz01 = iz1 - iz0; + float iz0 = 1/z0, iz1 = 1/z1, diz01 = iz1 - iz0; const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); - if (pattern==~0U && y0>y1) { cimg::swap(x0,x1,y0,y1,iz0,iz1); dx01*=-1; dy01*=-1; diz01*=-1; } - const float slope_x = dy01?(float)dx01/dy01:0, slope_z = dy01?(float)diz01/dy01:0; + if (pattern==~0U && y0>y1) { + cimg::swap(x0,x1,y0,y1,iz0,iz1); + dx01*=-1; dy01*=-1; diz01*=-1; + } + const float + slope_x = dy01?(float)dx01/dy01:0, + slope_iz = dy01?(float)diz01/dy01:0; static unsigned int hatch = ~0U - (~0U>>1); if (init_hatch) hatch = ~0U - (~0U>>1); cimg_init_scanline(opacity); - const int - step = y0<=y1?1:-1, - cy0 = cimg::cut(y0,0,h1), - cy1 = cimg::cut(y1,0,h1) + step; + const int step = y0<=y1?1:-1, cy0 = cimg::cut(y0,0,h1), cy1 = cimg::cut(y1,0,h1) + step; dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { const int yy0 = y - y0; - const float fx = x0 + yy0*slope_x; - const float iz = iz0 + yy0*slope_z; + const float + fx = x0 + yy0*slope_x, + iz = iz0 + yy0*slope_iz; if (fx>=0 && fx<=w1 && pattern&hatch) { const int x = (int)(fx + 0.5f); tz *const ptrz = is_horizontal?zbuffer.data(y,x):zbuffer.data(x,y); @@ -48798,13 +48799,12 @@ namespace cimg_library { cimg_instance, texture._width,texture._height,texture._depth,texture._spectrum,texture._data); if (is_overlapped(texture)) return draw_line(x0,y0,x1,y1,+texture,tx0,ty0,tx1,ty1,opacity,pattern,init_hatch); - - if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) return *this; - - int w1 = width() - 1, h1 = height() - 1; - longT - dx01 = (longT)x1 - x0, dy01 = (longT)y1 - y0, - dtx01 = (longT)tx1 - tx0, dty01 = (longT)ty1 - ty0; + if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) + return *this; + int + w1 = width() - 1, h1 = height() - 1, + dx01 = x1 - x0, dy01 = y1 - y0, + dtx01 = tx1 - tx0, dty01 = ty1 - ty0; const bool is_horizontal = cimg::abs(dx01)>cimg::abs(dy01); if (is_horizontal) cimg::swap(x0,y0,x1,y1,w1,h1,dx01,dy01); @@ -48812,6 +48812,10 @@ namespace cimg_library { cimg::swap(x0,x1,y0,y1,tx0,tx1,ty0,ty1); dx01*=-1; dy01*=-1; dtx01*=-1; dty01*=-1; } + const float + slope_x = dy01?(float)dx01/dy01:0, + slope_tx = dy01?(float)dtx01/dy01:0, + slope_ty = dy01?(float)dty01/dy01:0; const ulongT twhd = (ulongT)texture._width*texture._height*texture._depth; static unsigned int hatch = ~0U - (~0U>>1); @@ -48819,20 +48823,19 @@ namespace cimg_library { cimg_init_scanline(opacity); const int step = y0<=y1?1:-1, cy0 = cimg::cut(y0,0,h1), cy1 = cimg::cut(y1,0,h1) + step; - const longT - hdy01 = dy01*cimg::sign(dx01)/2, - hdy01tx = dy01*cimg::sign(dtx01)/2, - hdy01ty = dy01*cimg::sign(dty01)/2; - dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { - const longT - yy0 = (longT)y - y0, - x = x0 + (dx01*yy0 + hdy01)/dy01, - tx = tx0 + (dtx01*yy0 + hdy01tx)/dy01, - ty = ty0 + (dty01*yy0 + hdy01ty)/dy01; - if (x>=0 && x<=w1 && pattern&hatch) { + const int yy0 = y - y0; + const float + fx = x0 + yy0*slope_x, + ftx = tx0 + yy0*slope_tx, + fty = ty0 + yy0*slope_ty; + if (fx>=0 && fx<=w1 && pattern&hatch) { + const int + x = (int)(fx + 0.5f), + tx = (int)(ftx + 0.5f), + ty = (int)(fty + 0.5f); T *const ptrd = is_horizontal?data(y,x):data(x,y); const tc *const color = &texture._atXY(tx,ty); cimg_forC(*this,c) { @@ -48882,8 +48885,9 @@ namespace cimg_library { if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) return *this; float iz0 = 1/z0, iz1 = 1/z1; - int w1 = width() - 1, h1 = height() - 1; - longT dx01 = (longT)x1 - x0, dy01 = (longT)y1 - y0; + int + w1 = width() - 1, h1 = height() - 1, + dx01 = x1 - x0, dy01 = y1 - y0; float diz01 = iz1 - iz0, txz0 = tx0*iz0, txz1 = tx1*iz1, @@ -48896,6 +48900,11 @@ namespace cimg_library { cimg::swap(x0,x1,y0,y1,iz0,iz1,txz0,txz1,tyz0,tyz1); dx01*=-1; dy01*=-1; diz01*=-1; dtxz01*=-1; dtyz01*=-1; } + const float + slope_x = dy01?(float)dx01/dy01:0, + slope_iz = dy01?(float)diz01/dy01:0, + slope_txz = dy01?(float)dtxz01/dy01:0, + slope_tyz = dy01?(float)dtyz01/dy01:0; const ulongT twhd = (ulongT)texture._width*texture._height*texture._depth; static unsigned int hatch = ~0U - (~0U>>1); @@ -48903,22 +48912,17 @@ namespace cimg_library { cimg_init_scanline(opacity); const int step = y0<=y1?1:-1, cy0 = cimg::cut(y0,0,h1), cy1 = cimg::cut(y1,0,h1) + step; - const longT hdy01 = dy01*cimg::sign(dx01)/2; - dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { - const longT - yy0 = (longT)y - y0, - x = x0 + (dx01*yy0 + hdy01)/dy01; + const int yy0 = y - y0; const float - iz = iz0 + diz01*yy0/dy01, - txz = txz0 + dtxz01*yy0/dy01, - tyz = tyz0 + dtyz01*yy0/dy01; - if (x>=0 && x<=w1 && pattern&hatch) { - const int - tx = (int)cimg::round(txz/iz), - ty = (int)cimg::round(tyz/iz); + fx = x0 + yy0*slope_x, + fiz = iz0 + yy0*slope_iz, + ftxz = txz0 + yy0*slope_txz, + ftyz = tyz0 + yy0*slope_tyz; + if (fx>=0 && fx<=w1 && pattern&hatch) { + const int x = (int)(fx + 0.5f), tx = (int)(ftxz/fiz + 0.5f), ty = (int)(ftyz/fiz + 0.5f); T *const ptrd = is_horizontal?data(y,x):data(x,y); const tc *const color = &texture._atXY(tx,ty); cimg_forC(*this,c) { From edc58f76675528bf75c4ca3cc17daf1147eccc30 Mon Sep 17 00:00:00 2001 From: David Tschumperle Date: Tue, 9 Apr 2024 14:34:02 +0200 Subject: [PATCH 10/10] . --- CImg.h | 69 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/CImg.h b/CImg.h index e7e8a088..aa38a072 100644 --- a/CImg.h +++ b/CImg.h @@ -48881,14 +48881,13 @@ namespace cimg_library { texture._width,texture._height,texture._depth,texture._spectrum,texture._data); if (is_overlapped(texture)) return draw_line(x0,y0,z0,x1,y1,z1,+texture,tx0,ty0,tx1,ty1,opacity,pattern,init_hatch); - - if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) return *this; - - float iz0 = 1/z0, iz1 = 1/z1; + if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) + return *this; int w1 = width() - 1, h1 = height() - 1, dx01 = x1 - x0, dy01 = y1 - y0; float + iz0 = 1/z0, iz1 = 1/z1, diz01 = iz1 - iz0, txz0 = tx0*iz0, txz1 = tx1*iz1, tyz0 = ty0*iz0, tyz1 = ty1*iz1, @@ -48918,11 +48917,14 @@ namespace cimg_library { const int yy0 = y - y0; const float fx = x0 + yy0*slope_x, - fiz = iz0 + yy0*slope_iz, + iz = iz0 + yy0*slope_iz, ftxz = txz0 + yy0*slope_txz, ftyz = tyz0 + yy0*slope_tyz; if (fx>=0 && fx<=w1 && pattern&hatch) { - const int x = (int)(fx + 0.5f), tx = (int)(ftxz/fiz + 0.5f), ty = (int)(ftyz/fiz + 0.5f); + const int + x = (int)(fx + 0.5f), + tx = (int)(ftxz/iz + 0.5f), + ty = (int)(ftyz/iz + 0.5f); T *const ptrd = is_horizontal?data(y,x):data(x,y); const tc *const color = &texture._atXY(tx,ty); cimg_forC(*this,c) { @@ -48976,13 +48978,14 @@ namespace cimg_library { texture._width,texture._height,texture._depth,texture._spectrum,texture._data); if (is_overlapped(texture)) return draw_line(zbuffer,x0,y0,z0,x1,y1,z1,+texture,tx0,ty0,tx1,ty1,opacity,pattern,init_hatch); + if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) + return *this; - if (std::min(y0,y1)>=height() || std::max(y0,y1)<0 || std::min(x0,x1)>=width() || std::max(x0,x1)<0) return *this; - - float iz0 = 1/z0, iz1 = 1/z1; - int w1 = width() - 1, h1 = height() - 1; - longT dx01 = (longT)x1 - x0, dy01 = (longT)y1 - y0; + int + w1 = width() - 1, h1 = height() - 1, + dx01 = x1 - x0, dy01 = y1 - y0; float + iz0 = 1/z0, iz1 = 1/z1, diz01 = iz1 - iz0, txz0 = tx0*iz0, txz1 = tx1*iz1, tyz0 = ty0*iz0, tyz1 = ty1*iz1, @@ -48994,6 +48997,11 @@ namespace cimg_library { cimg::swap(x0,x1,y0,y1,iz0,iz1,txz0,txz1,tyz0,tyz1); dx01*=-1; dy01*=-1; diz01*=-1; dtxz01*=-1; dtyz01*=-1; } + const float + slope_x = dy01?(float)dx01/dy01:0, + slope_iz = dy01?(float)diz01/dy01:0, + slope_txz = dy01?(float)dtxz01/dy01:0, + slope_tyz = dy01?(float)dtyz01/dy01:0; const ulongT twhd = (ulongT)texture._width*texture._height*texture._depth; static unsigned int hatch = ~0U - (~0U>>1); @@ -49001,30 +49009,29 @@ namespace cimg_library { cimg_init_scanline(opacity); const int step = y0<=y1?1:-1, cy0 = cimg::cut(y0,0,h1), cy1 = cimg::cut(y1,0,h1) + step; - const longT hdy01 = dy01*cimg::sign(dx01)/2; - dy01+=dy01?0:1; for (int y = cy0; y!=cy1; y+=step) { - const longT - yy0 = (longT)y - y0, - x = x0 + (dx01*yy0 + hdy01)/dy01; + const int yy0 = y - y0; const float - iz = iz0 + diz01*yy0/dy01, - txz = txz0 + dtxz01*yy0/dy01, - tyz = tyz0 + dtyz01*yy0/dy01; - tz *const ptrz = is_horizontal?zbuffer.data(y,x):zbuffer.data(x,y); - - if (x>=0 && x<=w1 && pattern&hatch && iz>=*ptrz) { - *ptrz = (tz)iz; - const int - tx = (int)cimg::round(txz/iz), - ty = (int)cimg::round(tyz/iz); - T *const ptrd = is_horizontal?data(y,x):data(x,y); - const tc *const color = &texture._atXY(tx,ty); - cimg_forC(*this,c) { - const T val = color[c*twhd]; - ptrd[c*_sc_whd] = opacity>=1?val:(T)(val*_sc_nopacity + ptrd[c*_sc_whd]*_sc_copacity); + fx = x0 + yy0*slope_x, + iz = iz0 + yy0*slope_iz, + ftxz = txz0 + yy0*slope_txz, + ftyz = tyz0 + yy0*slope_tyz; + if (fx>=0 && fx<=w1 && pattern&hatch) { + const int x = (int)(fx + 0.5f); + tz *const ptrz = is_horizontal?zbuffer.data(y,x):zbuffer.data(x,y); + if (iz>=*ptrz) { + *ptrz = (tz)iz; + const int + tx = (int)(ftxz/iz + 0.5f), + ty = (int)(ftyz/iz + 0.5f); + T *const ptrd = is_horizontal?data(y,x):data(x,y); + const tc *const color = &texture._atXY(tx,ty); + cimg_forC(*this,c) { + const T val = color[c*twhd]; + ptrd[c*_sc_whd] = opacity>=1?val:(T)(val*_sc_nopacity + ptrd[c*_sc_whd]*_sc_copacity); + } } } if (!(hatch>>=1)) hatch = ~0U - (~0U>>1);