Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
dtschump committed Apr 9, 2024
1 parent adefa70 commit f9121d8
Showing 1 changed file with 56 additions and 52 deletions.
108 changes: 56 additions & 52 deletions CImg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -48798,41 +48799,43 @@ 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);
if (pattern==~0U && y0>y1) {
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);
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 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) {
Expand Down Expand Up @@ -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,
Expand All @@ -48896,29 +48900,29 @@ 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);
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 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) {
Expand Down

0 comments on commit f9121d8

Please sign in to comment.