Mail Archives: djgpp/1997/11/19/18:20:41
From: | "STEVEN S. FALLS" <ELN/broadview AT earthlink DOT net>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Help, Can anyone help optomize this already fast line routine
|
Date: | Sun, 16 Nov 1997 00:42:17 -0800
|
Organization: | EarthLink Network, Inc.
|
Lines: | 132
|
Message-ID: | <346EB1E8.504A7CBF@earthlink.net>
|
Reply-To: | ELN/broadview AT earthlink DOT net
|
NNTP-Posting-Host: | 153.37.31.22
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
--------------073B5545556899EF7FF1DDB7
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
My name is Ardy and I have an aready fast line agrothym that needs
to go faster. I need to find a way to posibly optomize the pixel
addressing part.
Thanks,
-Ardy
#define ABS(x)(((x) >= 0) ? (x) : (-(x)))
unsigned int *YTbl;
void Set YTbl(void) {
YTbl=new unsigned int [200];
for(int a=0;a<200;a++) YTbl[a]=a*320;
}
void Line(int x1,int y1,int x2,int y2,unsigned char color){
long XDelta,YDelta,a,M,Y,X;
XDelta=((x2-x1)<<8);YDelta=((y2-y1)<<8);
if(ABS(XDelta)>=ABS(YDelta)) {
M=(YDelta<<8)/XDelta;
Y=(y1<<8);
if(XDelta>=0) {
for(a=x1;a<=x2;a++) {
RamPg[YTbl[(Y>>8)]+a]=color;
Y+=M;
}
}else {
for(a=x1;a>=x2;a--) {
RamPg[YTbl[(Y>>8)]+a]=color;
Y-=M;
}
}
return;
} else {
M=(XDelta<<8)/YDelta;
X=(x1<<8);
if(YDelta>=0) {
for(a=y1;a<=y2;a++) {
RamPg[YTbl[a]+(X>>8)]=color;
X+=M;
}
}else {
for(a=y1;a>=y2;a--) {
RamPg[YTbl[a]+(X>>8)]=color;
X-=M;
}
}
}
return;
}
--------------073B5545556899EF7FF1DDB7
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<HTML>
Hi,
<BR> My name is Ardy and I have an aready fast
line agrothym that needs to go faster. I need to find a way to posibly
optomize the pixel addressing part.
<BR>
Thanks,
<BR>
-Ardy
<P><B><I>#define ABS(x)(((x) >= 0) ? (x) : (-(x)))</I></B>
<BR><B><I>unsigned int *YTbl;</I></B>
<BR><B><I>void Set YTbl(void) {</I></B>
<BR><B><I> YTbl=new unsigned int [200];</I></B>
<BR><B><I> for(int a=0;a<200;a++) YTbl[a]=a*320;</I></B>
<BR><B><I>}</I></B>
<BR><B><I>void Line(int x1,int y1,int x2,int y2,unsigned char color){</I></B>
<BR><B><I> long XDelta,YDelta,a,M,Y,X;</I></B>
<BR><B><I> XDelta=((x2-x1)<<8);YDelta=((y2-y1)<<8);</I></B>
<BR><B><I> if(ABS(XDelta)>=ABS(YDelta)) {</I></B>
<BR><B><I> M=(YDelta<<8)/XDelta;</I></B>
<BR><B><I> Y=(y1<<8);</I></B>
<BR><B><I> if(XDelta>=0) {</I></B>
<BR><B><I> for(a=x1;a<=x2;a++)
{</I></B>
<BR><B><I>
RamPg[YTbl[(Y>>8)]+a]=color;</I></B>
<BR><B><I>
Y+=M;</I></B>
<BR><B><I> }</I></B>
<BR><B><I> }else {</I></B>
<BR><B><I> for(a=x1;a>=x2;a--)
{</I></B>
<BR><B><I>
RamPg[YTbl[(Y>>8)]+a]=color;</I></B>
<BR><B><I>
Y-=M;</I></B>
<BR><B><I> }</I></B>
<BR><B><I> }</I></B>
<BR><B><I> return;</I></B>
<BR><B><I> } else {</I></B>
<BR><B><I> M=(XDelta<<8)/YDelta;</I></B>
<BR><B><I> X=(x1<<8);</I></B>
<BR><B><I> if(YDelta>=0) {</I></B>
<BR><B><I> for(a=y1;a<=y2;a++)
{</I></B>
<BR><B><I>
RamPg[YTbl[a]+(X>>8)]=color;</I></B>
<BR><B><I>
X+=M;</I></B>
<BR><B><I> }</I></B>
<BR><B><I> }else {</I></B>
<BR><B><I> for(a=y1;a>=y2;a--)
{</I></B>
<BR><B><I>
RamPg[YTbl[a]+(X>>8)]=color;</I></B>
<BR><B><I>
X-=M;</I></B>
<BR><B><I> }</I></B>
<BR><B><I> }</I></B>
<BR><B><I> }</I></B>
<BR><B><I> return;</I></B>
<BR><B><I>}</I></B>
<BR>
<BR>
<P> </HTML>
--------------073B5545556899EF7FF1DDB7--
- Raw text -