OpenCores
URL https://opencores.org/ocsvn/leros/leros/trunk

Subversion Repositories leros

[/] [leros/] [trunk/] [java/] [target/] [src/] [DrawLine.java] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 martin
import com.muvium.leros.Native;
2
 
3
import com.muvium.MuviumRunnable;
4
 
5 3 martin
/*
6
 * Example program for Leros.
7 6 martin
 * Line drawing benchmark for the JTRES 2011 paper submisssion.
8
 *
9
 * Might in the meantime be broken, as this used a different IO class
10
 */
11
 
12
public class DrawLine extends MuviumRunnable {
13
 
14
    static int Axv ;
15
    static int Ayv ;
16
    static int Bxv ;
17
    static int Byv ;
18
    static int Z ;
19
    static int color ;
20
 
21
    static int  Ax = Axv;
22
    static int  Ay = Ayv;
23
    static int  Bx = Bxv;
24
    static int  By = Byv;
25
 
26
    static int  p ;
27
 
28
    public void run(){
29
        int dx = 0 ;
30
        int dy  = 0;
31
        int Xincr  = 0;
32
        int Yincr  = 0;
33
        int dPr = 0;
34
        int dPru = 0;
35
 
36
       while( true ){
37
 
38
             Axv = Native.rd(0);
39
             Ayv = Native.rd(0);
40
             Bxv = Native.rd(0);
41
             Byv = Native.rd(0);
42
             Z =   Native.rd(0);
43
             color = Native.rd(0);
44
 
45
              Ax = Axv;
46
              Ay = Ayv;
47
              Bx = Bxv;
48
              By = Byv;
49
 
50
           //dx = Math.abs(Ax - Bx);  //';  // store the change in X and Y of the line endpoints
51
           if( Bx > Ax ){
52
               dx = Bx - Ax;
53
           }else{
54
               dx = Ax - Bx;
55
           }
56
 
57
 
58
           //dY = Math.abs(AY - By);  //';  // store the change in X and Y of the line endpoints
59
           if( By > Ay ){
60
               dy = By - Ay;
61
           }else{
62
               dy = Ay - By;
63
           }
64
 
65
           if( dy == 0){
66
               //horizontalLine( Ax, Bx, AY ); //TODO Inline
67
 
68
            }else{
69
               if( dx == 0 ){
70
                  // verticalLine( AY, By, Ax );//TODO Inline
71
 
72
               }else{
73
 
74
              // 'diagonal line
75
 
76
            //'If dX = 0 Then drawHorizontal
77
 
78
       //'//------------------------------------------------------------------------
79
       //'// DETERMINE "DIRECTIONS" TO INCREMENT X AND Y (REGARDLESS OF DECISION)
80
       //'//------------------------------------------------------------------------
81
               if( Ax > Bx ){ // '// which direction in X?
82
                   Xincr = -1;
83
               }else{
84
                   Xincr = 1;
85
               }
86
 
87
               if(  Ay > By) { // '// which direction in Y?
88
                   Yincr = -1;
89
               }else{
90
                   Yincr = 1;
91
               }
92
 
93
 
94
       //'//------------------------------------------------------------------------
95
       //'// DETERMINE INDEPENDENT VARIABLE (ONE THAT ALWAYS INCREMENTS BY 1 (OR -1) )
96
       //'// AND INITIATE APPROPRIATE LINE DRAWING ROUTINE (BASED ON FIRST OCTANT
97
       //'// ALWAYS). THE X AND Y'S MAY BE FLIPPED IF Y IS THE INDEPENDENT VARIABLE.
98
       //'//------------------------------------------------------------------------
99
                       if (dx >= dy) { //              '// if X is the independent variable
100
 
101
                           dPr = dy * 2;             //   '// amount to increment decision if right is chosen (always)
102
                           dPru = dPr - (dx * 2) ;    //  '// amount to increment decision if up is chosen
103
 
104
                           p = dPr - dx ;              // '// decision variable start value
105
 
106
                           for(; dx >= 0; dx-- ){ //For dx = dx To 0 Step -1
107
 
108
                              // setPixel( Ax, AY, color );  
109
 
110
                               Native.wr( Z , 0);
111
                               Native.wr( color, 0);
112
                               Native.wr( Ax, 0);
113
                               Native.wr( Ay, 0);
114
 
115
 
116
                               Ax = Ax + Xincr;        // '// increment independent variable
117
                               if( p > 0 ){
118
                                   Ay = Ay + Yincr;
119
                               }
120
 
121
 
122
                               if( p > 0 ){
123
                                 p = p + dPru ;         //'// increment decision (for up)
124
                               }else{
125
                                   p = p + dPr;
126
                               }
127
 
128
                           }
129
 
130
                       }else{
131
 
132
                           dPr = dx * 2 ;           //    '// amount to increment decision if right is chosen (always)
133
                           dPru = dPr - (dy * 2)    ;//   '// amount to increment decision if up is chosen
134
                           p = dPr - dy             ;//  '// decision variable start value
135
 
136
                           for(; dy >= 0; dy--){ //For dY = dY To 0 Step -1    '// process each point in the line one at a time (just use dY)
137
 
138
                              //  setPixel( Ax, AY, color );  
139
                               Native.wr( Z , 0);
140
                               Native.wr( color, 0);
141
                               Native.wr( Ax, 0);
142
                               Native.wr( Ay, 0);
143
 
144
                               Ay = Ay + Yincr;        //  '// increment independent variable
145
                               if( p > 0 ){
146
                                   Ax = Ax + Xincr;
147
                               }
148
 
149
                               if( p > 0 ){
150
                                 p = p + dPru ;          // '// increment decision (for up)
151
                               }else{
152
                                   p = p + dPr;
153
                               }
154
 
155
                           }
156
                       }
157
 
158
               }
159
            }
160
 
161
            Native.wr(0xFF, 0); //Done
162
        }
163
 
164
    } //Run()
165
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.