void draw(void *_prms) { param_set *p = (param_set *) _prms; int i; double psc = 2 * R / Hmax, vdistmax; gclr(*p->win); copylayer(*p->win, 2, 1); for (i = 0; i < DN; i++) { putimg24m(*p->win, x[i] - 4, y[i] - 4, 8, 8, Xpm_image_stone4); } copylayer(*p->win, 1, 0); gclr(*p->win2); vdistmax = vdist[0]; for (i = 0; i < Hmax; i++) { if (vdistmax < vdist[i]) vdistmax = vdist[i]; } newcolor(*p->win2, "steelblue4"); for (i = 0; i < Hmax; i++) { fillrect(*p->win2, psc * i, 0, psc, vdist[i] / vdistmax * R); } newcolor(*p->win2, "steelblue"); for (i = 0; i < Hmax; i++) { drawrect(*p->win2, psc * i, 0, psc, vdist[i] / vdistmax * R); } copylayer(*p->win2, 1, 0); }
static void remake_tree(int win, double order, double rt, double ra, double rnd, int bgcolor_r, int bgcolor_g, int bgcolor_b) { Cdbl z2 = 0 + 0.9 * L / (1 - pow(rt, order + 1)) * I; Cdbl z1 = 0; int i; /* 背景色専用レイヤ */ layer(win, 0, 2); for (i = 0; i < L; i++) { newrgbcolor(win, bgcolor_r + 128.0 * i / L, bgcolor_g + 128.0 * i / L, bgcolor_b + 128.0 * i / L); drawline(win, -L / 2, i, L / 2 - 1, i); } /* treeのマスク専用レイヤ */ layer(win, 0, 4); gsetbgcolor(win, "#ffffff"); gclr(win); newcolor(win, "#000000"); btree(win, z1, z2, order, rt, ra, rnd); /* treeの専用レイヤ */ layer(win, 0, 3); gsetbgcolor(win, "#003300"); gclr(win); newgcfunction(win, GXandInverted); gputarea(win, -L / 2, 0, win, 4, -L / 2, 0, L / 2 - 1, L - 1); newgcfunction(win, GXcopy); newcolor(win, "white"); drawstr(win, L / 2 - 180, 4, 14, 0, "Background Color: " "#%02x%02x%02x", bgcolor_r, bgcolor_g, bgcolor_b); }
void dessinArbre2(int lg, int x, int y, int angle){ int nx, ny, feuille=10; if(lg<feuille*2) fruits_rouges(x,y); lg+= (int) 0.1*aleat(lg); avance(lg,x,y,angle,&nx,&ny); lg=2*lg/3; if(lg>feuille+4){ int n=3+aleat(3); int i; for(i=1;i<=n;i++){ dessinArbre2(lg,nx,ny,angle-70+i*25); } } else if(lg>feuille-4){ setcolor(newcolor(0,1,0)); int n=3+aleat(3); int i; for(i=1;i<=n;i++){ dessinArbre2(lg,nx,ny,angle-70+i*25); } setcolor(newcolor(0.5,0.3,0.08)); } }
void fruits_rouges(int x,int y){ int chance_fruit=6; if (aleat(100)<chance_fruit){ setcolor(newcolor(0.8,0.07,0.05)); disque(x,y,3); setcolor(newcolor(0.5,0.3,0.08)); } }
int main() { int win, win2, win3; double t = 0, h = 2 * M_PI / 100, quit = 0, run = 1; double clr2 = 0, clr3 = 0; double r[6] = { 0 }; param_set prms = { &win, &win2, &win3, &F, &D, &B, &t, &h, &clr2, &clr3, &run, r }; e_ctrl ctrls[] = { {"Force", &F, 0.1, &init, &prms}, {"Dumping", &D, 0.01, &init, &prms}, {"Nonlinear", &B, 0.1, &init, &prms}, {"_Clear Phase", &clr2, 0, NULL, NULL}, {"_Clear Poincare", &clr3, 0, NULL, NULL}, {"_Run", &run, 0, NULL, NULL}, {"_Quit", &quit, 0, NULL, NULL}, }; int cwin; cwin = init_ctrls(ctrls, 7); win = gopen(2 * WD + 2 * MG, HT); win2 = gopen(WD + MG, HT); win3 = gopen(WD + MG, HT); window(win, 0, -HT / 2, 2 * WD + 2 * MG, HT / 2 - 1); window(win2, -(MG + WD) / 2, -HT / 2, (WD + MG) / 2 - 1, HT / 2 - 1); window(win3, -(MG + WD) / 2, -HT / 2, (WD + MG) / 2 - 1, HT / 2 - 1); winname(win2, "Phase chart"); winname(win3, "Poincare chart"); layer(win, 0, 1); layer(win2, 0, 1); layer(win3, 0, 1); gsetbgcolor(win, ECTRL_BGCOLOR); gsetbgcolor(win2, ECTRL_FGCOLOR); gsetbgcolor(win3, ECTRL_FGCOLOR); newcolor(win, ECTRL_FGCOLOR); newcolor(win2, ECTRL_BGCOLOR); newcolor(win3, "red3"); gclr(win2); gclr(win3); gsetnonblock(ENABLE); while (!quit) { int iscwin, type, button; double wx, wy; iscwin = ggetxpress(&type, &button, &wx, &wy); display_ctrls(cwin, ctrls, 7, wx, wy, iscwin, type, button); if (run) { rk4fixv6(duffing, t, r, h); t += h; draw(&prms); } msleep(5); } gcloseall(); return 0; }
void init(void *_prms) { param_set *p = (param_set *) _prms; int i, j; *p->mid = (L + 1) / 2; /* screen mid */ for (i = 0; i < L + 2; i++) for (j = 0; j < L + 2; j++) grid[i][j] = 0; grid[(int) *p->mid][(int) *p->mid] = 1; if (*p->R >= L) { while (*p->R >= L - 1) { *p->R -= dR; } } *p->src_r = 0; *p->new_r = 1; *p->rem_r = 0; *p->reset = 0; layer(*p->win, 0, 2); gsetbgcolor(*p->win, ECTRL_BGCOLOR); newcolor(*p->win, "#303030"); gclr(*p->win); fillarc(*p->win, *p->mid, *p->mid, *p->R / 2, *p->R / 2, 0, 360, 0); layer(*p->win, 0, 1); copylayer(*p->win, 2, 1); copylayer(*p->win, 1, 0); }
void init(void *_prms) { param_set *p = (param_set *) _prms; int i, j; double th; layer(*p->win, 0, 4); /* mask */ gsetbgcolor(*p->win, "black"); gclr(*p->win); newcolor(*p->win, "white"); fillcirc(*p->win, 0, 0, R, R); newcolor(*p->win, "black"); fillcirc(*p->win, *p->x0, 0, *p->IR, *p->IR); layer(*p->win, 0, 3); /* image-mapped wall and colored vacuum */ gsetbgcolor(*p->win, ECTRL_BGCOLOR); gclr(*p->win); for (i = 0; i < 2; i++) for (j = 0; j < 2; j++) putimg24(*p->win, (i - 1) * 200, (j - 1) * 200, 200, 200, Xpm_image_slope); newgcfunction(*p->win, GXandInverted); gputarea(*p->win, -R, -R, *p->win, 4, -R, -R, R, R); layer(*p->win, 0, 2); /* compose background image */ gclr(*p->win); newgcfunction(*p->win, GXand); gputarea(*p->win, -R, -R, *p->win, 4, -R, -R, R, R); newgcfunction(*p->win, GXor); gputarea(*p->win, -R, -R, *p->win, 3, -R, -R, R, R); newgcfunction(*p->win, GXcopy); layer(*p->win, 0, 1); copylayer(*p->win, 2, 1); /* copy background image */ for (i = 0; i < N; i++) { th = drand48() * 2 * M_PI; x[i] = 0.95 * R * cos(th); y[i] = 0.95 * R * sin(th); vx[i] = (drand48() - 0.5) * Hmax; vy[i] = drand48() * Hmax * sin(drand48() * 2 * M_PI); } *p->run = 0; getstatis(); draw(p); }
void draw(void *_prms) { param_set *p = (param_set *) _prms; static double y[2 * WD], v[2 * WD]; int i; static int poincare = 0; for (i = 0; i < 2 * WD - 1; i++) { y[i] = y[i + 1]; v[i] = v[i + 1]; } y[2 * WD - 1] = p->r[0]; v[2 * WD - 1] = p->r[1]; /* y-t chart */ gclr(*p->win); newcolor(*p->win, "gold"); drawline(*p->win, MG, 0, 2 * WD + MG, 0); newcolor(*p->win, ECTRL_FGCOLOR); for (i = 0; i < 2 * WD; i++) { pset(*p->win, MG + i, y[i] * HT * SCY); } copylayer(*p->win, 1, 0); /* phase chart */ if (*p->clr2 == 1) { gclr(*p->win2); *p->clr2 = 0; } for (i = 0; i < 2 * WD; i++) { pset(*p->win2, y[i] * HT * SCY, v[i] * SCV); } copylayer(*p->win2, 1, 0); /* poincare chart */ if (*p->clr3 == 1) { gclr(*p->win3); *p->clr3 = 0; } if (poincare % 50 == 0) { pset(*p->win3, y[2 * WD - 1] * HT * SCY, v[2 * WD - 1] * SCV); copylayer(*p->win3, 1, 0); } poincare++; }
PaintView::PaintView(QWidget *parent, int width, int height) : QWidget(parent), m_painting(width, height), m_painting_backup(m_painting.size()), m_cursor(), m_color(), m_image(NULL) { resize(m_painting.size()); m_painting.fill(Qt::transparent); m_painting_backup = m_painting; m_cursor[0] = QPoint(-50, -50); m_cursor[1] = QPoint(-50, -50); newcolor(0, 255, 255, 255); newcolor(1, 0, 0, 0); }
void draw(void *_prms) { param_set *p = (param_set *) _prms; double maskx[4], masky[4]; double rad; rad = *p->angle * M_PI / 180; maskx[0] = maskx[1] = *p->sx; maskx[2] = maskx[3] = *p->sx + 200; masky[0] = 0; masky[1] = masky[2] = 200; masky[3] = 200 * tan(*p->angle * M_PI / 180); gclr(*p->win); putimg24(*p->win, *p->sx, 0, 200, 200, Xpm_image_slope); newcolor(*p->win, ECTRL_BGCOLOR); fillpoly(*p->win, maskx, masky, 4, 0); putimg24m(*p->win, *p->bx - 10 * (sin(rad) + 1), *p->by + 10 * (cos(rad) - 1), 20, 20, Xpm_image_stone10); newcolor(*p->win, ECTRL_FGCOLOR); drawline(*p->win, X0 + L, 0, X0 + L, 220); copylayer(*p->win, 1, 0); }
int main() { int win; double angle = 30, ratio = 5, run = 0, reset = 0, quit = 0; double t = 0, h = 0.1; double sx, sy, bx, by; param_set prms = { &win, &angle, &ratio, &t, &h, &run, &reset, &sx, &sy, &bx, &by }; e_ctrl ctrls[] = { {"Angle", &angle, 1, &init, &prms}, {"Ratio M/m", &ratio, 1, &init, &prms}, {"Step", &h, 0.01, &init, &prms}, {"_Run", &run, 0, NULL, NULL}, {"_Reset", &reset, 0, &init, &prms}, {"_Quit", &quit, 0, NULL, NULL} }; int cwin; cwin = init_ctrls(ctrls, 6); win = gopen(WD, HT); layer(win, 0, 1); gsetbgcolor(win, ECTRL_BGCOLOR); newcolor(win, ECTRL_BGCOLOR); init(&prms); gsetnonblock(ENABLE); while (!quit) { int iscwin, type, button; double wx, wy; iscwin = ggetxpress(&type, &button, &wx, &wy); display_ctrls(cwin, ctrls, 6, wx, wy, iscwin, type, button); if (run) { t += h; step(&prms); draw(&prms); if (by < 0) run = 0; } msleep(40); } gcloseall(); return 0; }
void print_density(void *_prms) { param_set *p = (param_set *) _prms; int i, j, numt = 0, numa = 0; for (i = 0; i < L; i++) { for (j = 0; j < L; j++) { if (hypot(i - *p->mid, j - *p->mid) <= *p->src_r) numt++; numa += grid[i][j]; } } newcolor(*p->win, "cornsilk"); drawstr(*p->win, 100, 10, 14, 0, "Density = %.4f", numa / (double) numt); copylayer(*p->win, 1, 0); }
int main(int argc, char **argv) { int win, win2; double quit = 0, run = 1, t = 0, h = 0.05; double x0 = -40, IR = R / 3; param_set prms = { &win, &win2, &x0, &IR, &h, &run, &quit }; e_ctrl ctrls[] = { {"Step", &h, 0.01, NULL, NULL}, {"X0", &x0, 1, &init, &prms}, {"Inner radius", &IR, 1, &init, &prms}, {"_Run", &run, 0, NULL, NULL}, {"_Quit", &quit, 0, NULL, NULL} }; int cwin; cwin = init_ctrls(ctrls, 5); srand48(time(NULL)); win = gopen(2 * R, 2 * R); win2 = gopen(2 * R, R); window(win, -R, -R, R - 1, R - 1); gsetbgcolor(win, WCOLOR); gsetbgcolor(win2, ECTRL_FGCOLOR); newcolor(win, ECTRL_FGCOLOR); layer(win, 0, 1); layer(win2, 0, 1); gsetnonblock(ENABLE); init(&prms); run = 1; while (!quit) { int iscwin, type, button; double wx, wy; iscwin = ggetxpress(&type, &button, &wx, &wy); display_ctrls(cwin, ctrls, 5, wx, wy, iscwin, type, button); if (run) { step(&prms); draw(&prms); t += h; } msleep(40); } gcloseall(); return 0; }
void ImageSefmentByMeanshift(cv::Mat& src,cv::Mat& dst){ //#ifndef SPATIAL_RAD // #define SPATIAL_RAD 10 //#endif //#ifndef COLOR_RAD // #define COLOR_RAD 10 //#endif //#ifndef MAX_PRY_LEVEL // #define MAX_PRY_LEVEL 3 //#endif int spatialRad = 10; int colorRad = 10; int maxPryLevel = 1; //调用meanshift图像金字塔进行分割 pyrMeanShiftFiltering(src,dst,spatialRad,colorRad,maxPryLevel); RNG rng=theRNG(); Mat mask(dst.rows+2,dst.cols+2,CV_8UC1,Scalar::all(0)); for(int i=0;i<dst.rows;i++) //opencv图像等矩阵也是基于0索引的 for(int j=0;j<dst.cols;j++) if(mask.at<uchar>(i+1,j+1)==0) { Scalar newcolor(rng(256),rng(256),rng(256)); floodFill(dst,mask,Point(j,i),newcolor,0,Scalar::all(1),Scalar::all(1)); // floodFill(dst,mask,Point(i,j),newcolor,0,colorDiff,colorDiff); } imshow("src",src); imshow("dst",dst);waitKey(0); /*createTrackbar("spatialRad","dst",&spatialRad,80,meanshift_seg); createTrackbar("colorRad","dst",&colorRad,60,meanshift_seg); createTrackbar("maxPryLevel","dst",&maxPryLevel,5,meanshift_seg); imshow("src",src_S); imshow("dst",dst_S); waitKey();*/ }
void draw(void *_prms) { param_set *p = (param_set *) _prms; int id, aggr = 0, this_r; int x, y, xnt, ynt, tk, key = 0; float tx[50000], ty[50000], th; for (;;) { if (*p->new_r) { *p->new_r = 0; *p->src_r += *p->r_inc; *p->rem_r = *p->src_r + *p->r_inc; if (*p->src_r >= (*p->R / 2)) { *p->run = 0; print_density(p); break; } } th = drand48() * 2.0 * M_PI; x = *p->src_r * cos(th) + *p->mid; y = *p->src_r * sin(th) + *p->mid; tk = 0; while (*p->run) { id = floor(drand48() * 4.0); xnt = (id == 0) ? x - 1 : (id == 1) ? x + 1 : x; ynt = (id <= 1) ? y : (id == 2) ? y - 1 : y + 1; tx[tk] = xnt; ty[tk] = ynt; this_r = hypot(xnt - *p->mid, ynt - *p->mid); if ((xnt < *p->mid - *p->R) || (xnt >= *p->mid + *p->R) || (ynt < *p->mid - *p->R) || (ynt >= *p->mid + *p->R) || (this_r > *p->rem_r)) { newcolor(*p->win, "red4"); break; } /* seems to escape */ if (grid[xnt - 1][ynt] == 1 || grid[xnt][ynt - 1] == 1 || grid[xnt][ynt + 1] == 1 || grid[xnt + 1][ynt] == 1) { aggr = 1; if (drand48() <= *p->agg_prob) { grid[xnt][ynt] = 1; if (this_r >= *p->src_r) *p->new_r = 1; layer(*p->win, 0, 2); newcolor(*p->win, ECTRL_FGCOLOR); pset(*p->win, xnt, ynt); layer(*p->win, 0, 1); newcolor(*p->win, "green3"); } break; } /* aggregate */ if (aggr == 0) { x = xnt; y = ynt; } aggr = 0; tk++; } gclr(*p->win); copylayer(*p->win, 2, 1); newlinestyle(*p->win, LineSolid); drawpts(*p->win, tx, ty, tk - 1); newcolor(*p->win, "gray50"); newlinestyle(*p->win, LineOnOffDash); drawarc(*p->win, *p->mid, *p->mid, *p->src_r, *p->src_r, 0, 360, 0); copylayer(*p->win, 1, 0); msleep(5); key = ggetch(); if (key == 'q') { *p->run = 0; goto RET; } } RET: ; /* do nothing just return */ }
void dessinArbre(int lg, int x, int y, int angle){ srand(time(NULL)); setcolor(newcolor(0.5,0.3,0.08)); dessinArbre2(lg,x,y,angle); }
void main(void) { int vgamode, color, leftpressed; int x, y; vga_init(); vgamode = vga_getdefaultmode(); if ((vgamode == -1) || (vga_getmodeinfo(vgamode)->bytesperpixel != 1)) vgamode = G320x200x256; if (!vga_hasmode(vgamode)) { printf("Mode not available.\n"); exit(1); } printf("\nWARNING: This program will set the keyboard to RAW mode.\n" "The keyboard routines in svgalib have not been tested\n" "very much. There may be no recovery if something goes\n" "wrong.\n\n" "Press ctrl-c now to bail out, enter to continue.\n" "In the test itself, use 'q' or Escape to quit.\n" "It will also terminate after 60 seconds.\n" "Use any cursor keys to move, keypad 0 or enter to change color.\n"); getchar(); vga_setmode(vgamode); gl_setcontextvga(vgamode); gl_enableclipping(); signal(SIGALRM, timeout); /* This installs the default handler, which is good enough for most */ /* purposes. */ if (keyboard_init()) { printf("Could not initialize keyboard.\n"); exit(1); } /* Translate to 4 keypad cursor keys, and unify enter key. */ keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_KEYPADENTER | TRANSLATE_DIAGONAL); /* (TRANSLATE_DIAGONAL seems to give problems.) Michael: No doesn't... but might not do what you expect.. */ alarm(60); /* Terminate after 60 seconds for safety. */ x = WIDTH / 2; y = HEIGHT / 2; color = newcolor(); leftpressed = 0; for (;;) { /* Draw moving box. */ gl_fillbox(x, y, 5, 5, color); /* Draw key status bar at top of screen. */ gl_putbox(0, 0, 128, 1, keyboard_getstate()); /* Wait about 1/100th of a second. */ /* Note that use of this function makes things less */ /* smooth because of timer latency. */ usleep(10000); keyboard_update(); /* Move. */ if (keyboard_keypressed(SCANCODE_CURSORLEFT)) x--; if (keyboard_keypressed(SCANCODE_CURSORRIGHT)) x++; if (keyboard_keypressed(SCANCODE_CURSORUP)) y--; if (keyboard_keypressed(SCANCODE_CURSORDOWN)) y++; /* Boundary checks. */ if (x < 0) x = 0; if (x >= WIDTH) x = WIDTH - 1; if (y < 1) y = 1; if (y >= HEIGHT) y = HEIGHT - 1; /* Check for color change. */ if (keyboard_keypressed(SCANCODE_KEYPAD0) || keyboard_keypressed(SCANCODE_ENTER)) { if (!leftpressed) { color = newcolor(); leftpressed = 1; } } else leftpressed = 0; if (keyboard_keypressed(SCANCODE_Q) || keyboard_keypressed(SCANCODE_ESCAPE)) break; } keyboard_close(); /* Don't forget this! */ vga_setmode(TEXT); exit(0); }
int main() { int win, i, j, k, m, key = 0; int arp[5] = { 0, 3, 1, 4, 2 }, ars[7] = { 0, 5, 3, 1, 6, 4, 2}; double pentagon[3][5], septagon[3][7], parab[3][144], y; win = gopen(L, L); window(win, -L / 2, -L / 2, L / 2, L / 2); gsetbgcolor(win, ECTRL_BGCOLOR); newcolor(win, ECTRL_FGCOLOR); winname(win, "e_3d demo"); layer(win, 0, 1); gsetnonblock(ENABLE); i = j = m = 0; for (i = 0; i < 144; i++) { y = L/(2*144.0)*i; parab[0][i] = 0; parab[1][i] = -y; parab[2][i] = 0.02*y*(L/2 - y); } while (key != 'q') { g3dsetangle(torad(40 * (1.5 + sin(j * 2 * M_PI / 30))), i * 2 * M_PI / 144); gclr(win); for (k = 0; k < 5; k++) { pentagon[0][k] = L / 6 * cos(arp[k] * 2 * M_PI / 5 + m * 2 * M_PI / 50) + L / 5; pentagon[1][k] = L / 6 * sin(arp[k] * 2 * M_PI / 5 + m * 2 * M_PI / 50) + L / 5; pentagon[2][k] = 0; } for (k = 0; k < 7; k++) { septagon[0][k] = L / 6 * cos(ars[k] * 2 * M_PI / 7 + 2 * m * 2 * M_PI / 50) - L / 5; septagon[1][k] = 0; septagon[2][k] = L / 6 * sin(ars[k] * 2 * M_PI / 7 + 2 * m * 2 * M_PI / 50) + L / 5; } newcolor(win, "lightsteelblue"); newlinestyle(win, LineOnOffDash); for(k = 0; k < 6; k++) { drawline3d(win, -L/10*k, 0, 0, -L/10*k, -L/2, 0); drawline3d(win, 0, -L/10*k, 0, -L/2, -L/10*k, 0); } newlinestyle(win, LineSolid); newcolor(win, "red4"); fillpoly3d(win, pentagon[0], pentagon[1], pentagon[2], 5, 0); newcolor(win, "green4"); fillpoly3d(win, septagon[0], septagon[1], septagon[2], 7, 0); newcolor(win, ECTRL_FGCOLOR); drawarrow3d(win, 0, 0, 0, 0, 0, L / 3, 10, 6, 12); drawarrow3d(win, 0, 0, 0, 0, L / 3, 0, 10, 6, 12); drawarrow3d(win, 0, 0, 0, L / 3, 0, 0, 10, 6, 12); newcolor(win, "gold3"); drawstr3d(win, 0, 0, L/3+10, FONTSET, 0, "z¼´"); drawlines3d(win, parab[0], parab[1], parab[2], 144); y = L/(2*36.0)*(i%36); putimg24m3d(win, 0 - 6 *(-sin(_phi) - cos(_th)*cos(_phi)), -y - 6*(cos(_phi) - cos(_th)*sin(_phi)), 0.02*y*(L/2 - y) -6*sin(_th), 12, 12, Xpm_image_stone6); copylayer(win, 1, 0); i++; i %= 144; j++; j %= 30; m++; m %= 50; msleep(40); key = ggetch(); } gcloseall(); return 0; }
void main(void) { struct timeval timeout; fd_set inputs; char bitmap[16 * 16 * 4]; /* big enough for 10x10 bitmap in any mode */ int vgamode, color, pipefd[2], x, y, button, event, cursorsize = 5; char loop = 1, drawcursor = 1; #ifdef USE_RAWKEYBOARD char space_pressed = 0; #endif puts("This is a demo showing the abilities of the new vga_waitevent() function\n" "If something goes wrong it might hang your machine. Thus hit <ctrl>-C now\n" "to bailout if in doubt.\n" "Use mouse to move cursor. 1-9,0 to set the cursor size. Space to change the\n" "cursor color. Left button to draw. Right button or 'Q' to bailout.\n" "The cursor goes on/off every half second by usage of a timeout passed to\n" "vga_waitevent. Every 5 secs a string from a child process (the time) arrives\n" "asynchronously and is displayed by the frontend."); #ifdef USE_RAWKEYBOARD puts("\nBEWARE! This has been compiled to use the raw keyboard. A crash might\n" "render the console unusable. (but shouldn't)."); #endif fputs("\nHit <Enter> if brave enough, else ^C to bailout: ", stdout); fflush(stdout); getchar(); fflush(stdin); /* clear I/O buffer */ pipe(pipefd); if (fork() == 0) { /* fork off b4 touching graphix to avoid side effects */ close(pipefd[0]); /* Important: close reading side, else it remains */ /* opened by child when parent exits and we don't get */ /* a SIGPIPE! */ child(pipefd[1]); } vga_init(); vgamode = vga_getdefaultmode(); if (vgamode == -1) vgamode = G320x200x256; if (!vga_hasmode(vgamode)) { printf("Mode not available.\n"); exit(-1); } /* Enable automatic mouse setup at mode set. */ vga_setmousesupport(1); vga_setmode(vgamode); /* Disable wrapping (default). */ /* mouse_setwrap(MOUSE_NOWRAP); */ gl_setcontextvga(vgamode); gl_enableclipping(); /* There might be some scrap data in the serial buffer from the mouse. It will make vga_waitevent block because it thinks the mouse wants to send data but then no mouse packet arrives. */ color = newcolor(); x = 0; y = 0; gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED); gl_setfont(8, 8, gl_font8x8); gl_setfontcolors(0, newcolor()); #ifdef USE_RAWKEYBOARD if (keyboard_init()) { printf("Could not initialize keyboard.\n"); exit(1); } #endif while (loop) { gl_getbox(x, y, 10, 10, bitmap); if (drawcursor) { gl_hline(x, y, x + cursorsize, color); gl_hline(x, y + cursorsize, x + cursorsize, color); gl_line(x, y, x, y + cursorsize, color); gl_line(x + cursorsize, y, x + cursorsize, y + cursorsize, color); } FD_ZERO(&inputs); FD_SET(pipefd[0], &inputs); timeout.tv_sec = 0; timeout.tv_usec = 500000; /* 0.5 second time out */ event = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT, &inputs, NULL, NULL, &timeout); gl_putbox(x, y, 10, 10, bitmap); if (timeout.tv_sec || timeout.tv_usec) { /* No timeout. An actual event occured. Reset to visible cursor. Note: This is actually a bug as the cursor will get visible on time updates. However, it's better this way for demo/test purposes. */ drawcursor = 1; } else { drawcursor ^= 1; } if (FD_ISSET(pipefd[0], &inputs)) process_input(pipefd[0]); if (event & VGA_MOUSEEVENT) { x = mouse_getx(); y = mouse_gety(); button = mouse_getbutton(); if (button & MOUSE_LEFTBUTTON) gl_fillbox(x, y, cursorsize + 1, cursorsize + 1, color); if (button & MOUSE_RIGHTBUTTON) loop = 0; } if (event & VGA_KEYEVENT) { #ifdef USE_RAWKEYBOARD if (keyboard_keypressed(SCANCODE_1)) cursorsize = 0; if (keyboard_keypressed(SCANCODE_2)) cursorsize = 1; if (keyboard_keypressed(SCANCODE_3)) cursorsize = 2; if (keyboard_keypressed(SCANCODE_4)) cursorsize = 3; if (keyboard_keypressed(SCANCODE_5)) cursorsize = 4; if (keyboard_keypressed(SCANCODE_6)) cursorsize = 5; if (keyboard_keypressed(SCANCODE_7)) cursorsize = 6; if (keyboard_keypressed(SCANCODE_8)) cursorsize = 7; if (keyboard_keypressed(SCANCODE_9)) cursorsize = 8; if (keyboard_keypressed(SCANCODE_0)) cursorsize = 9; if (keyboard_keypressed(SCANCODE_Q)) loop = 0; if (keyboard_keypressed(SCANCODE_SPACE)) { if (!space_pressed) { color = newcolor(); space_pressed = 1; } } else { space_pressed = 0; } #else switch (vga_getch()) { case '1': cursorsize = 0; break; case '2': cursorsize = 1; break; case '3': cursorsize = 2; break; case '4': cursorsize = 3; break; case '5': cursorsize = 4; break; case '6': cursorsize = 5; break; case '7': cursorsize = 6; break; case '8': cursorsize = 7; break; case '9': cursorsize = 8; break; case '0': cursorsize = 9; break; case ' ': color = newcolor(); break; case 'q': case 'Q': loop = 0; break; default: ping(); break; } #endif } } #ifdef USE_RAWKEYBOARD keyboard_close(); /* Don't forget this! */ #endif vga_setmode(TEXT); exit(0); }
int main( int argc, char *argv[] ) { int ret = 1; int win_main, win_zoom, zoom_factor = 2; double p_x = -1, p_y = -1; unsigned char *zoom_buf = NULL; unsigned char *img_buf = NULL; int img_width, img_height, img_msk; int crosshairs = 1; if ( argc < 2 ) { fprintf(stderr,"[USAGE]\n"); fprintf(stderr,"%s filename.png\n",argv[0]); return 1; } /* zoom ウィンドゥ用の画像バッファ */ zoom_buf = (unsigned char *)malloc(ZOOMWN_WIDTH * ZOOMWN_HEIGHT * 4); if ( zoom_buf == NULL ) goto quit; //img_buf = readimage(NULL,argv[1],&img_width,&img_height,&img_msk); //img_buf = readimage("xbmtopbm",argv[1],&img_width,&img_height,&img_msk); #ifdef USE_IMAGEMAGICK img_buf = readimage("convert",argv[1],&img_width,&img_height,&img_msk); #else img_buf = readimage("pngtopnm",argv[1],&img_width,&img_height,&img_msk); #endif if ( img_buf == NULL ) { fprintf(stderr,"ERROR: cannot read file\n"); goto quit; } printf("mask value = %d\n",img_msk); /* 属性設定(左上を原点にする) */ gsetinitialattributes(DISABLE, BOTTOM_LEFT_ORIGIN); /* ウィンドゥのオープン */ win_zoom = gopen(ZOOMWN_WIDTH*2, ZOOMWN_HEIGHT); win_main = gopen(img_width, img_height); layer(win_zoom,0,1); /* メインウィンドゥへの画像の転送 */ gclr(win_main); gputimage(win_main, 0,0, img_buf, img_width, img_height, img_msk); /* カーソル描画のために,XOR での描画functionに設定 */ newgcfunction(win_main, GXxor); newcolor(win_main, "red"); #if 0 /* 保存のテスト */ //writeimage(img_buf,img_width,img_height,img_msk,"pnmtopng",256,"hoge.png"); //writeimage(img_buf,img_width,img_height,img_msk,NULL,256,"hoge.pam"); gsaveimage( win_main,0,0,0,1999,1999,"pnmtopng",256,"capt0.png"); { int im_w, im_h; unsigned char *im = ggetimage(win_main,0,0,0,1999,1999,&im_w,&im_h); writeimage(im_w,im_h,im,0,"pnmtopng",256,"capt.png"); if ( im != NULL ) free(im); } #endif /* メインループ */ while ( 1 ) { int win_ev, type, b; int needs_redraw = 0; double x, y; win_ev = ggetevent(&type,&b,&x,&y) ; if ( type == EnterNotify ) { fprintf(stderr,"event type = EnterNotify wid=%d\n",win_ev); } else if ( type == LeaveNotify ) { fprintf(stderr,"event type = LeaveNotify wid=%d\n",win_ev); } else { fprintf(stderr,"event type = %d wid=%d\n",type,win_ev); } if ( win_ev == win_main ) { if ( type == MotionNotify || type == EnterNotify || type == LeaveNotify ) { if ( type == LeaveNotify ) { x = -32000; y = -32000; } if ( crosshairs ) { /* crosshairs カーソルを消す */ drawline(win_main, 0,p_y, img_width,p_y); drawline(win_main, p_x,0, p_x,img_height); /* crosshairs カーソルを表示する */ drawline(win_main, 0,y, img_width,y); drawline(win_main, x,0, x,img_height); } needs_redraw = 1; p_x = x; p_y = y; } else if ( type == ButtonPress ) { if ( b == 1 ) zoom_factor++; else if ( b == 3 ) zoom_factor--; needs_redraw = 1; } } if ( type == KeyPress ) { if ( b == 'q' ) goto quit; else if ( b == '>' || b == '+' ) zoom_factor++; else if ( b == '<' || b == '-' ) zoom_factor--; else if ( b == ' ' ) { if ( crosshairs ) { /* crosshairs カーソルを消す */ drawline(win_main, 0,p_y, img_width,p_y); drawline(win_main, p_x,0, p_x,img_height); crosshairs = 0; } else { /* crosshairs カーソルを表示する */ drawline(win_main, 0,p_y, img_width,p_y); drawline(win_main, p_x,0, p_x,img_height); crosshairs = 1; } } needs_redraw = 1; } if ( needs_redraw ) { if ( zoom_factor < 2 ) zoom_factor = 2; else if ( 32 < zoom_factor ) zoom_factor = 32; get_zoom_image(img_width, img_height, img_buf, p_x, p_y, zoom_factor, ZOOMWN_WIDTH, ZOOMWN_HEIGHT, zoom_buf); gclr(win_zoom); /* 普通のコピー */ newgcfunction(win_zoom, GXcopy); gputimage(win_zoom, 0, 0, zoom_buf, ZOOMWN_WIDTH, ZOOMWN_HEIGHT, img_msk); /* 反転コピー */ newgcfunction(win_zoom, GXcopyInverted); gputarea(win_zoom, ZOOMWN_WIDTH, 0, win_zoom,1, 0,0,ZOOMWN_WIDTH-1, ZOOMWN_HEIGHT-1); /* ズームウィンドゥで,文字列を反転描画する */ newgcfunction(win_zoom, GXinvert); drawstr(win_zoom,2,14,14,0, "%dx zoom pos=(%g,%g)\n",zoom_factor,p_x,p_y); copylayer(win_zoom,1,0); } } ret = 0; quit: gcloseall(); if ( img_buf != NULL ) free(img_buf); if ( zoom_buf != NULL ) free(zoom_buf); return ret; }