void RenderGraphThread
::testFctFastLineDrawingAlgorithm(QImage &r_image, int32_t x1, int32_t y1, int32_t x2, int32_t y2
) {
int x,y,dx,dy,dx1,dy1,px,py,xe,ye,i;
dx=x2-x1;
dy=y2-y1;
dx1=std::abs(dx);
dy1=std::abs(dy);
px=2*dy1-dx1;
py=2*dx1-dy1;
if(dy1<=dx1)
{
if(dx>=0)
{
x=x1;
y=y1;
xe=x2;
}
else
{
x=x2;
y=y2;
xe=x1;
}
testFctPutPixelOnImage(r_image,x,y, 0xFF0B9F8A); // green
for(i=0;x<xe;i++)
{
x=x+1;
if(px<0)
{
px=px+2*dy1;
}
else
{
if((dx<0 && dy<0) || (dx>0 && dy>0))
{
y=y+1;
}
else
{
y=y-1;
}
px=px+2*(dy1-dx1);
}
testFctPutPixelOnImage(r_image,x,y, 0xFF0B9F8A); // green
}
}
else
{
if(dy>=0)
{
x=x1;
y=y1;
ye=y2;
}
else
{
x=x2;
y=y2;
ye=y1;
}
testFctPutPixelOnImage(r_image,x,y, 0xFF0B9F8A); // green
for(i=0;y<ye;i++)
{
y=y+1;
if(py<=0)
{
py=py+2*dx1;
}
else
{
if ((dx<0 && dy<0) || (dx>0 && dy>0))
{
x=x+1;
}
else
{
x=x-1;
}
py=py+2*(dx1-dy1);
}
testFctPutPixelOnImage(r_image,x,y, 0xFF0B9F8A); // green
}
}
}
// TEST CODE FOR FAST DRAWING LINES
void RenderGraphThread
::testFctPutPixelOnImage(QImage &r_image,
const int32_t x,
const int32_t y,
const uint32_t _color
) {
if (y<r_image.height() && x<r_image.width() && x>=0 && y>=0)
{
uchar *pFirstLine = r_image.bits();
int32_t depth = 4;
QRgb* rgbpixel = reinterpret_cast<QRgb*>(pFirstLine + r_image.width()*depth*y + x*depth);
*rgbpixel = _color;
}
}
void RenderGraphThread::testFctFastLineDrawingAlgorithm(QImage &r_image, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
{
int x,y,dx,dy,dx1,dy1,px,py,xe,ye,i;
dx=x2-x1;
dy=y2-y1;
dx1=std::abs(dx);
dy1=std::abs(dy);
px=2*dy1-dx1;
py=2*dx1-dy1;
if(dy1<=dx1)
{
if(dx>=0)
{
x=x1;
y=y1;
xe=x2;
}
else
{
x=x2;
y=y2;
xe=x1;
}
testFctPutPixelOnImage(r_image,x,y, 0xFF0B9F8A); // green
for(i=0;x<xe;i++)
{
x=x+1;
if(px<0)
{
px=px+2*dy1;
}
else
{
if((dx<0 && dy<0) || (dx>0 && dy>0))
{
y=y+1;
}
else
{
y=y-1;
}
px=px+2*(dy1-dx1);
}
testFctPutPixelOnImage(r_image,x,y, 0xFF0B9F8A); // green
}
}
else
{
if(dy>=0)
{
x=x1;
y=y1;
ye=y2;
}
else
{
x=x2;
y=y2;
ye=y1;
}
testFctPutPixelOnImage(r_image,x,y, 0xFF0B9F8A); // green
for(i=0;y<ye;i++)
{
y=y+1;
if(py<=0)
{
py=py+2*dx1;
}
else
{
if ((dx<0 && dy<0) || (dx>0 && dy>0))
{
x=x+1;
}
else
{
x=x-1;
}
py=py+2*(dx1-dy1);
}
testFctPutPixelOnImage(r_image,x,y, 0xFF0B9F8A); // green
}
}
}
// TEST CODE FOR FAST DRAWING LINES
void RenderGraphThread::testFctPutPixelOnImage(QImage &r_image, const int32_t x, const int32_t y, const uint32_t _color)
{
if (y<r_image.height() && x<r_image.width() && x>=0 && y>=0)
{
uchar *pFirstLine = r_image.bits();
int32_t depth = 4;
QRgb* rgbpixel = reinterpret_cast<QRgb*>(pFirstLine + r_image.width()*depth*y + x*depth);
*rgbpixel = _color;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks