// ==================================================== // BOX(x1,y1) - (x2,y2),c // ==================================================== void box_sub(int x1,int y1,int x2,int y2,int c1,int c2,int c3,int c4) { gr_hline(x1,y1,x2,y1,c1); gr_hline(x1,y2,x2,y2,c3); gr_vline(x1,y1,x1,y2,c2); gr_vline(x2,y1,x2,y2,c4); }
// ==================================================== // BOX(x1,y1) - (x2,y2),c // ==================================================== void gr_box(int x1,int y1,int x2,int y2,int c) { gr_hline(x1,y1,x2,y1,c); gr_hline(x1,y2,x2,y2,c); gr_vline(x1,y1,x1,y2,c); gr_vline(x2,y1,x2,y2,c); }
void vline2(int x0,int y0,int x1,int y1,int col) { int yc; /* int ytmp; if(y0>y1) { ytmp=y0;y0=y1;y1=ytmp; } */ yc = (y0+y1)/2; gr_vline(x0,y0 ,x0,yc,col); // (差分)縦の線1. gr_vline(x1,yc+1,x1,y1,col); // (差分)縦の線2. }
/********************************************************************* * 1サンプルの1ビット分を描画 ********************************************************************* * v : 0 か 非0 信号レベル. * diff : 0 か 非0 信号反転が起きた. */ static void plot_signals(int x,int y,int val,int old) { int col0,col1,col2,i,d; col0 = 0; col1 = BACK_COLOR ; col2 = SIG_COLOR2 ; if((x % 40)==0) col0=blue; if(x==0) return; x += 8; gr_vline(x+1,y,x+1,y-AIN_GRAPH_H,col2); //縦の線(先行線). gr_vline(x,y,x,y-AIN_GRAPH_H,col0); //縦の線(現在線). for(i=1;i<5;i++) { d = AIN_GRAPH_H * i / 5; gr_pset(x,y-d , blue); // ベースライン赤. } gr_line(x-1,y-old,x,y-val,SIG_COLOR); }
/********************************************************************* * 1サンプルの1ビット分を描画 ********************************************************************* * v : 0 か 非0 信号レベル. * diff : 0 か 非0 信号反転が起きた. */ void plot_signal(int x,int y,int v,int diff) { int col0,col1,col2; if(v) { col0 = FRAME_COLOR; col1 = SIG_COLOR ; } else { col0 = SIG_COLOR; col1 = BACK_COLOR ; } if(diff) { col2 = SIG_COLOR2;} else { col2 = BACK_COLOR;} if(diff) gr_vline(x,y-1,x,y- H_HEIGHT,col2); //縦の線. if(v) { gr_pset(x,y - H_HEIGHT,col1); // Hレベルの色. }else{ gr_pset(x,y - 2 ,col0); // Lの色. gr_pset(x,y - 1 ,col0); // Lの色. } gr_pset(x,y ,FRAME_COLOR); // ベースライン赤. gr_pset(x,y- H_HEIGHT-1,FRAME_COLOR2); // Hレベルライン赤. }
/********************************************************************* * 1サンプルの1ビット分を描画 ********************************************************************* */ void plot_analog(int x,int y,int val,int old_val) { int diff = old_val - val; int yc = 128+ANALOG_BASE; int y0 = 256+ANALOG_BASE - old_val; int y1 = 256+ANALOG_BASE - val; if(x==SCREEN_X0) { //左端. gr_vline(x-1,ANALOG_BASE,x-1,256+ANALOG_BASE,0); } gr_pset(x,yc ,FRAME_COLOR); // ベースライン赤. gr_pset(x,yc-129,FRAME_COLOR2); // Hレベルライン赤. gr_pset(x,yc+129,FRAME_COLOR2); // Lレベルライン赤. if(diff) vline2(x-1,y0,x,y1,SIG_COLOR1); // (差分)縦の線. else gr_pset(x,y1,SIG_COLOR1); // 信号の色. }
void gr_universal_uline(int a1, int b1, int a2, int b2) { int dx, dy, incr1, incr2, D, x, y, xend, c, pixels_left; int x1, y1; int sign_x = 1, sign_y = 1, step, reverse, i; if (a1==a2) { gr_vline(b1,b2,a1); return; } if (b1==b2) { gr_hline(a1,a2,b1); return; } dx = a2 - a1; dy = b2 - b1; if (dx < 0) { sign_x = -1; dx *= -1; } if (dy < 0) { sign_y = -1; dy *= -1; } /* decide increment sign by the slope sign */ if (sign_x == sign_y) step = 1; else step = -1; if (dy > dx) { /* chooses axis of greatest movement (make * dx) */ EXCHG(a1, b1); EXCHG(a2, b2); EXCHG(dx, dy); reverse = 1; } else reverse = 0; /* note error check for dx==0 should be included here */ if (a1 > a2) { /* start from the smaller coordinate */ x = a2; y = b2; x1 = a1; y1 = b1; } else { x = a1; y = b1; x1 = a2; y1 = b2; } /* Note dx=n implies 0 - n or (dx+1) pixels to be set */ /* Go round loop dx/4 times then plot last 0,1,2 or 3 pixels */ /* In fact (dx-1)/4 as 2 pixels are already plottted */ xend = (dx - 1) / 4; pixels_left = (dx - 1) % 4; /* number of pixels left over at the * end */ plot(x, y, reverse); plot(x1, y1, reverse); /* plot first two points */ incr2 = 4 * dy - 2 * dx; if (incr2 < 0) { /* slope less than 1/2 */ c = 2 * dy; incr1 = 2 * c; D = incr1 - dx; for (i = 0; i < xend; i++) { /* plotting loop */ ++x; --x1; if (D < 0) { /* pattern 1 forwards */ plot(x, y, reverse); plot(++x, y, reverse); /* pattern 1 backwards */ plot(x1, y1, reverse); plot(--x1, y1, reverse); D += incr1; } else { if (D < c) { /* pattern 2 forwards */ plot(x, y, reverse); plot(++x, y += step, reverse); /* pattern 2 backwards */ plot(x1, y1, reverse); plot(--x1, y1 -= step, reverse); } else { /* pattern 3 forwards */ plot(x, y += step, reverse); plot(++x, y, reverse); /* pattern 3 backwards */ plot(x1, y1 -= step, reverse); plot(--x1, y1, reverse); } D += incr2; } } /* end for */ /* plot last pattern */ if (pixels_left) { if (D < 0) { plot(++x, y, reverse); /* pattern 1 */ if (pixels_left > 1) plot(++x, y, reverse); if (pixels_left > 2) plot(--x1, y1, reverse); } else { if (D < c) { plot(++x, y, reverse); /* pattern 2 */ if (pixels_left > 1) plot(++x, y += step, reverse); if (pixels_left > 2) plot(--x1, y1, reverse); } else { /* pattern 3 */ plot(++x, y += step, reverse); if (pixels_left > 1) plot(++x, y, reverse); if (pixels_left > 2) plot(--x1, y1 -= step, reverse); } } } /* end if pixels_left */ } /* end slope < 1/2 */ else { /* slope greater than 1/2 */ c = 2 * (dy - dx); incr1 = 2 * c; D = incr1 + dx; for (i = 0; i < xend; i++) { ++x; --x1; if (D > 0) { /* pattern 4 forwards */ plot(x, y += step, reverse); plot(++x, y += step, reverse); /* pattern 4 backwards */ plot(x1, y1 -= step, reverse); plot(--x1, y1 -= step, reverse); D += incr1; } else { if (D < c) { /* pattern 2 forwards */ plot(x, y, reverse); plot(++x, y += step, reverse); /* pattern 2 backwards */ plot(x1, y1, reverse); plot(--x1, y1 -= step, reverse); } else { /* pattern 3 forwards */ plot(x, y += step, reverse); plot(++x, y, reverse); /* pattern 3 backwards */ plot(x1, y1 -= step, reverse); plot(--x1, y1, reverse); } D += incr2; } } /* end for */ /* plot last pattern */ if (pixels_left) { if (D > 0) { plot(++x, y += step, reverse); /* pattern 4 */ if (pixels_left > 1) plot(++x, y += step, reverse); if (pixels_left > 2) plot(--x1, y1 -= step, reverse); } else { if (D < c) { plot(++x, y, reverse); /* pattern 2 */ if (pixels_left > 1) plot(++x, y += step, reverse); if (pixels_left > 2) plot(--x1, y1, reverse); } else { /* pattern 3 */ plot(++x, y += step, reverse); if (pixels_left > 1) plot(++x, y, reverse); if (pixels_left > 2) { if (D > c) /* step 3 */ plot(--x1, y1 -= step, reverse); else /* step 2 */ plot(--x1, y1, reverse); } } } } } }