delorie.com/archives/browse.cgi   search  
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>&nbsp;&nbsp;&nbsp;&nbsp; My name is Ardy and I have an aready fast
line agrothym that needs to go faster. I need&nbsp; to find a way to posibly
optomize the pixel addressing part.
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Thanks,
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-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>&nbsp;&nbsp;&nbsp; YTbl=new unsigned int [200];</I></B>
<BR><B><I>&nbsp;&nbsp; for(int a=0;a&lt;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>&nbsp;&nbsp; long XDelta,YDelta,a,M,Y,X;</I></B>
<BR><B><I>&nbsp;&nbsp; XDelta=((x2-x1)&lt;&lt;8);YDelta=((y2-y1)&lt;&lt;8);</I></B>
<BR><B><I>&nbsp;&nbsp; if(ABS(XDelta)>=ABS(YDelta)) {</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; M=(YDelta&lt;&lt;8)/XDelta;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Y=(y1&lt;&lt;8);</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(XDelta>=0) {</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(a=x1;a&lt;=x2;a++)
{</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
RamPg[YTbl[(Y>>8)]+a]=color;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Y+=M;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else {</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(a=x1;a>=x2;a--)
{</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
RamPg[YTbl[(Y>>8)]+a]=color;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Y-=M;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;</I></B>
<BR><B><I>&nbsp;&nbsp; } else {</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; M=(XDelta&lt;&lt;8)/YDelta;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; X=(x1&lt;&lt;8);</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(YDelta>=0) {</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(a=y1;a&lt;=y2;a++)
{</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
RamPg[YTbl[a]+(X>>8)]=color;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
X+=M;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else {</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for(a=y1;a>=y2;a--)
{</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
RamPg[YTbl[a]+(X>>8)]=color;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
X-=M;</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</I></B>
<BR><B><I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</I></B>
<BR><B><I>&nbsp;&nbsp; }</I></B>
<BR><B><I>&nbsp;&nbsp; return;</I></B>
<BR><B><I>}</I></B>
<BR>&nbsp;
<BR>&nbsp;

<P>&nbsp;</HTML>

--------------073B5545556899EF7FF1DDB7--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019