GadgetSeed  0.9.6
com_graphics.c
[詳解]
1 /** @file
2  @brief グラフィック関連のコマンド
3 
4  @date 2008.04.08
5  @date 2007.04.22
6 
7  @author Takashi SHUDO
8 
9  @section graph_command graphコマンド
10 
11  graph コマンドには以下のサブコマンドがあります。
12 
13  | サブコマンド | 機能 | 詳細 |
14  |:------------------|:--------------------------------------|:------------------------------|
15  | drawmode | @copybrief com_graph_drawmode | @ref com_graph_drawmode |
16  | forecolor | @copybrief com_graph_forecolor | @ref com_graph_forecolor |
17  | backcolor | @copybrief com_graph_backcolor | @ref com_graph_backcolor |
18  | cls | @copybrief com_graph_cls | @ref com_graph_cls |
19  | point | @copybrief com_graph_point | @ref com_graph_point |
20  | hline | @copybrief com_graph_hline | @ref com_graph_hline |
21  | vline | @copybrief com_graph_vline | @ref com_graph_vline |
22  | rect | @copybrief com_graph_rect | @ref com_graph_rect |
23  | fillrect | @copybrief com_graph_fillrect | @ref com_graph_fillrect |
24  | roundrect | @copybrief com_graph_roundrect | @ref com_graph_roundrect |
25  | roundfrect | @copybrief com_graph_roundfillrect | @ref com_graph_roundfillrect |
26  | cliprect | @copybrief com_graph_cliprect | @ref com_graph_cliprect |
27  | line | @copybrief com_graph_line | @ref com_graph_line |
28  | setfont | @copybrief com_graph_setfont | @ref com_graph_setfont |
29  | proport | @copybrief com_graph_proportional | @ref com_graph_proportional |
30  | drawchar | @copybrief com_graph_drawchar | @ref com_graph_drawchar |
31  | charcode | @copybrief com_graph_charcode | @ref com_graph_charcode |
32  | drawstr | @copybrief com_graph_drawstr | @ref com_graph_drawstr |
33  | fontpreview | @copybrief com_graph_fontpreview | @ref com_graph_fontpreview |
34  | circle | @copybrief com_graph_circle | @ref com_graph_circle |
35  | fillcircle | @copybrief com_graph_fillcircle | @ref com_graph_fillcircle |
36  | ellipse | @copybrief com_graph_ellipse | @ref com_graph_ellipse |
37  | fillellipse | @copybrief com_graph_fillellipse | @ref com_graph_fillellipse |
38  | scrollv | @copybrief com_graph_scrollv | @ref com_graph_scrollv |
39  | jpeg | @copybrief com_graph_jpeg | @ref com_graph_jpeg |
40  | png | @copybrief com_graph_png | @ref com_graph_png |
41  | vertex4 | @copybrief com_graph_vertex4 | @ref com_graph_vertex4 |
42  | dispframe | @copybrief com_graph_dispframe | @ref com_graph_dispframe |
43  | drawframe | @copybrief com_graph_drawframe | @ref com_graph_drawframe |
44  | sector | @copybrief com_graph_sector | @ref com_graph_sector |
45  | enlbitmap | @copybrief com_graph_enlbitmap | @ref com_graph_enlbitmap |
46 */
47 
48 #include "sysconfig.h"
49 #include "gadgetseed.h"
50 #include "shell.h"
51 #include "str.h"
52 #include "timer.h"
53 #include "font.h"
54 #include "console.h"
55 #include "tprintf.h"
56 #ifdef GSC_COMP_ENABLE_FATFS
57 #include "file.h"
58 #endif
59 #include "memory.h"
60 
61 #include "device/video_ioctl.h"
62 #include "graphics.h"
63 
64 #if 0
65 static short scr_width;
66 static short scr_height;
67 
68 static rect frect;
69 static rect crect;
70 
71 static void init_graph_com(void)
72 {
73  get_screen_info(&scr_width, &scr_height);
74 
75  frect.left = 3;
76  frect.top = 3;
77  frect.right = scr_width-3;
78  frect.bottom = scr_height-3;
79  crect.left = 4;
80  crect.top = 4;
81  crect.right = scr_width-4;
82  crect.bottom = scr_height-4;
83 }
84 #endif
85 
86 static int drawmode(int argc, uchar *argv[]);
87 
88 /**
89  @brief 描画モードを設定する
90 
91  設定可能なモードは以下
92 
93  0:標準\n
94  1:フォアカラーとバックカラーを逆に描画する\n
95  2:フォアカラーのみ描画する
96 */
97 const struct st_shell_command com_graph_drawmode = {
98  .name = "drawmode",
99  .command = drawmode,
100  .usage_str = "<mode(0|1|2)>",
101  .manual_str = "Set draw mode(0:NORMAL,1:REVERSE,2:FOREONLY)"
102 };
103 
104 static int drawmode(int argc, uchar *argv[])
105 {
106  if(argc < 2) {
107  print_command_usage(&com_graph_drawmode);
108  return 0;
109  }
110 
111  set_draw_mode(dstou(argv[1]));
112 
113  return 0;
114 }
115 
116 
117 static int forecolor(int argc, uchar *argv[]);
118 
119 /**
120  @brief フォアカラーを設定する
121 */
122 static const struct st_shell_command com_graph_forecolor = {
123  .name = "forecolor",
124  .command = forecolor,
125  .usage_str = "<r(0-255)> <g(0-255)> <b(0-255)>",
126  .manual_str = "Set fore color"
127 };
128 
129 static int forecolor(int argc, uchar *argv[])
130 {
131  unsigned int color;
132 
133  if(argc < 4) {
134  print_command_usage(&com_graph_forecolor);
135  return 0;
136  }
137 
138  color = RGB(dstoi(argv[1]), dstoi(argv[2]), dstoi(argv[3]));
139 
140  set_forecolor(color);
141 
142  return 0;
143 }
144 
145 
146 static int backcolor(int argc, uchar *argv[]);
147 
148 /**
149  @brief バックカラーを設定する
150 */
151 static const struct st_shell_command com_graph_backcolor = {
152  .name = "backcolor",
153  .command = backcolor,
154  .usage_str = "<r(0-255)> <g(0-255)> <b(0-255)>",
155  .manual_str = "Set back color"
156 };
157 
158 static int backcolor(int argc, uchar *argv[])
159 {
160  unsigned int color;
161 
162  if(argc < 4) {
163  print_command_usage(&com_graph_backcolor);
164  return 0;
165  }
166 
167  color = RGB(dstoi(argv[1]), dstoi(argv[2]), dstoi(argv[3]));
168 
169  set_backcolor(color);
170 
171  return 0;
172 }
173 
174 
175 static int cls(int argc, uchar *argv[])
176 {
177  clear_screen();
178 
179  return 0;
180 }
181 
182 /**
183  @brief 画面を初期化する
184 */
185 static const struct st_shell_command com_graph_cls = {
186  .name = "cls",
187  .command = cls,
188  .manual_str = "Clear screen"
189 };
190 
191 
192 static int point(int argc, uchar *argv[]);
193 
194 /**
195  @brief 点を描画する
196 */
197 static const struct st_shell_command com_graph_point = {
198  .name = "point",
199  .command = point,
200  .usage_str = "<x> <y>",
201  .manual_str = "Draw point"
202 };
203 
204 static int point(int argc, uchar *argv[])
205 {
206  if(argc < 2) {
207  print_command_usage(&com_graph_point);
208  return 0;
209  }
210 
211  draw_point(dstoi(argv[1]), dstoi(argv[2]));
212 
213  return 0;
214 }
215 
216 
217 static int hline(int argc, uchar *argv[]);
218 
219 /**
220  @brief 水平線を描画する
221 */
222 static const struct st_shell_command com_graph_hline = {
223  .name = "hline",
224  .command = hline,
225  .usage_str = "<x> <y> <w>",
226  .manual_str = "Draw horizontal line"
227 };
228 
229 static int hline(int argc, uchar *argv[])
230 {
231  if(argc < 4) {
232  print_command_usage(&com_graph_hline);
233  return 0;
234  }
235 
236  draw_h_line(dstoi(argv[1]), dstoi(argv[2]), dstoi(argv[3]));
237 
238  return 0;
239 }
240 
241 
242 static int vline(int argc, uchar *argv[]);
243 
244 /**
245  @brief 垂直線を描画する
246 */
247 static const struct st_shell_command com_graph_vline = {
248  .name = "vline",
249  .command = vline,
250  .usage_str = "<x> <y> <h>",
251  .manual_str = "Draw virtical line"
252 };
253 
254 static int vline(int argc, uchar *argv[])
255 {
256  if(argc < 4) {
257  print_command_usage(&com_graph_vline);
258  return 0;
259  }
260 
261  draw_v_line(dstoi(argv[1]), dstoi(argv[2]), dstoi(argv[3]));
262 
263  return 0;
264 }
265 
266 
267 static int drawrect(int argc, uchar *argv[]);
268 
269 /**
270  @brief 矩形を描画する
271 */
272 static const struct st_shell_command com_graph_rect = {
273  .name = "rect",
274  .command = drawrect,
275  .usage_str = "<x> <y> <xe> <ye>",
276  .manual_str = "Draw rectangle"
277 };
278 
279 static int drawrect(int argc, uchar *argv[])
280 {
281  struct st_rect rect;
282 
283  if(argc < 5) {
284  print_command_usage(&com_graph_rect);
285  return 0;
286  }
287 
288  rect.left = dstoi(argv[1]);
289  rect.top = dstoi(argv[2]);
290  rect.right = dstoi(argv[3]);
291  rect.bottom = dstoi(argv[4]);
292 
293  draw_rect(&rect);
294 
295  return 0;
296 }
297 
298 
299 
300 static int fillrect(int argc, uchar *argv[]);
301 
302 /**
303  @brief 塗りつぶした矩形を描画する
304 */
305 static const struct st_shell_command com_graph_fillrect = {
306  .name = "fillrect",
307  .command = fillrect,
308  .usage_str = "<x> <y> <xe> <ye>",
309  .manual_str = "Draw fill rectangle"
310 };
311 
312 static int fillrect(int argc, uchar *argv[])
313 {
314  struct st_rect rect;
315 
316  if(argc < 5) {
317  print_command_usage(&com_graph_fillrect);
318  return 0;
319  }
320 
321  rect.left = dstoi(argv[1]);
322  rect.top = dstoi(argv[2]);
323  rect.right = dstoi(argv[3]);
324  rect.bottom = dstoi(argv[4]);
325 
326  draw_fill_rect(&rect);
327 
328  return 0;
329 }
330 
331 
332 static int roundrect(int argc, uchar *argv[]);
333 
334 /**
335  @brief 角の丸い矩形を描画する
336 */
337 static const struct st_shell_command com_graph_roundrect = {
338  .name = "roundrect",
339  .command = roundrect,
340  .usage_str = "<x> <y> <xe> <ye> <r>",
341  .manual_str = "Draw round rectangle"
342 };
343 
344 static int roundrect(int argc, uchar *argv[])
345 {
346  struct st_rect rect;
347  short r;
348 
349  if(argc < 6) {
350  print_command_usage(&com_graph_roundrect);
351  return 0;
352  }
353 
354  rect.left = dstoi(argv[1]);
355  rect.top = dstoi(argv[2]);
356  rect.right = dstoi(argv[3]);
357  rect.bottom = dstoi(argv[4]);
358  r = dstoi(argv[5]);
359 
360  draw_round_rect(&rect, r);
361 
362  return 0;
363 }
364 
365 
366 static int roundfillrect(int argc, uchar *argv[]);
367 
368 /**
369  @brief 角の丸い塗りつぶした矩形を描画する
370 */
371 static const struct st_shell_command com_graph_roundfillrect = {
372  .name = "roundfrect",
373  .command = roundfillrect,
374  .usage_str = "<x> <y> <xe> <ye> <r>",
375  .manual_str = "Draw round fill rectangle"
376 };
377 
378 static int roundfillrect(int argc, uchar *argv[])
379 {
380  struct st_rect rect;
381  short r;
382 
383  if(argc < 6) {
384  print_command_usage(&com_graph_roundfillrect);
385  return 0;
386  }
387 
388  rect.left = dstoi(argv[1]);
389  rect.top = dstoi(argv[2]);
390  rect.right = dstoi(argv[3]);
391  rect.bottom = dstoi(argv[4]);
392  r = dstoi(argv[5]);
393 
394  draw_round_fill_rect(&rect, r);
395 
396  return 0;
397 }
398 
399 
400 static int cliprect(int argc, uchar *argv[]);
401 
402 /**
403  @brief クリッピング領域を設定する
404 */
405 static const struct st_shell_command com_graph_cliprect = {
406  .name = "cliprect",
407  .command = cliprect,
408  .usage_str = "[<x> <y> <xe> <ye>]",
409  .manual_str = "Set clipping area"
410 };
411 
412 static int cliprect(int argc, uchar *argv[])
413 {
414  struct st_rect rect;
415 
416  if(argc < 2) {
417  clear_clip_rect();
418  tprintf("clip clear\n");
419  return 0;
420  } else if(argc < 5) {
421  print_command_usage(&com_graph_cliprect);
422  return 0;
423  }
424 
425  rect.left = dstoi(argv[1]);
426  rect.top = dstoi(argv[2]);
427  rect.right = dstoi(argv[3]);
428  rect.bottom = dstoi(argv[4]);
429 
430  set_clip_rect(&rect);
431 
432  return 0;
433 }
434 
435 
436 static int drawline(int argc, uchar *argv[]);
437 
438 /**
439  @brief 直線を描画する
440 */
441 static const struct st_shell_command com_graph_line = {
442  .name = "line",
443  .command = drawline,
444  .usage_str = "<x> <y> <xe> <ye>",
445  .manual_str = "Set line"
446 };
447 
448 static int drawline(int argc, uchar *argv[])
449 {
450  struct st_rect rect;
451 
452  if(argc < 5) {
453  print_command_usage(&com_graph_line);
454  return 0;
455  }
456 
457  rect.left = dstoi(argv[1]);
458  rect.top = dstoi(argv[2]);
459  rect.right = dstoi(argv[3]);
460  rect.bottom = dstoi(argv[4]);
461 
462  draw_line(rect.left, rect.top, rect.right, rect.bottom);
463 
464  return 0;
465 }
466 
467 
468 #ifdef GSC_COMP_ENABLE_FONTS
469 #include "font.h"
470 
471 static int setfont(int argc, uchar *argv[]);
472 
473 /**
474  @brief 描画するフォントを設定する
475 */
476 static const struct st_shell_command com_graph_setfont = {
477  .name = "setfont",
478  .command = setfont,
479  .usage_str = "<font_name>",
480  .manual_str = "Set font"
481 };
482 
483 static int setfont(int argc, uchar *argv[])
484 {
485  if(argc < 2) {
486  int i;
487  int fc = fontset_count();
488  struct st_fontset *fs = get_fontset();;
489 
490  print_command_usage(&com_graph_setfont);
491 
492  tprintf("Font list\n");
493 
494  for(i=0; i<fc; i++) {
495  tprintf(" %s\n", fontset_name(i));
496  }
497 
498  tprintf("Now font name : %s\n", fs->name);
499  return 0;
500  }
501 
502  if(set_font_by_name((char *)argv[1]) == 0) {
503  tprintf("Font name \"%s\" not found.\n", argv[1]);
504  }
505 
506  return 0;
507 }
508 
509 
510 static int proportional(int argc, uchar *argv[]);
511 
512 /**
513  @brief フォントの描画モード(固定幅/プロポーショナル)を設定する
514 */
515 static const struct st_shell_command com_graph_proportional = {
516  .name = "proport",
517  .command = proportional,
518  .usage_str = "<0:FIXED | 1:PROPORT>",
519  .manual_str = "Set font draw mode"
520 };
521 
522 static int proportional(int argc, uchar *argv[])
523 {
524  if(argc < 2) {
525  print_command_usage(&com_graph_proportional);
526  return 0;
527  }
528 
529  set_font_drawmode(dstoi(argv[1]));
530 
531  return 0;
532 }
533 
534 
535 static int drawchar(int argc, uchar *argv[]);
536 
537 /**
538  @brief 1文字描画する
539 */
540 static const struct st_shell_command com_graph_drawchar = {
541  .name = "drawchar",
542  .command = drawchar,
543  .usage_str = "<x> <y> <char>",
544  .manual_str = "Draw charctor"
545 };
546 
547 static int drawchar(int argc, uchar *argv[])
548 {
549  if(argc < 4) {
550  print_command_usage(&com_graph_drawchar);
551  return 0;
552  }
553 
554  draw_char(dstoi(argv[1]), dstoi(argv[2]), argv[3][0]);
555 
556  return 0;
557 }
558 
559 
560 static int drawcode(int argc, uchar *argv[]);
561 
562 /**
563  @brief 指定文字コードの文字を描画する
564 */
565 static const struct st_shell_command com_graph_charcode = {
566  .name = "charcode",
567  .command = drawcode,
568  .usage_str = "<x> <y> <char_code>",
569  .manual_str = "Draw charctor code charctor"
570 };
571 
572 static int drawcode(int argc, uchar *argv[])
573 {
574  if(argc < 4) {
575  print_command_usage(&com_graph_charcode);
576  return 0;
577  }
578 
579  draw_char(dstoi(argv[1]), dstoi(argv[2]), hstoi(argv[3]));
580 
581  return 0;
582 }
583 
584 
585 static int drawstr(int argc, uchar *argv[]);
586 
587 /**
588  @brief 文字列を描画する
589 */
590 static const struct st_shell_command com_graph_drawstr = {
591  .name = "drawstr",
592  .command = drawstr,
593  .usage_str = "<x> <y> <strings> [width]",
594  .manual_str = "Draw charctor code charctor"
595 };
596 
597 static int drawstr(int argc, uchar *argv[])
598 {
599  if(argc < 4) {
600  print_command_usage(&com_graph_drawstr);
601  return 0;
602  }
603 
604  if(argc > 4) {
605  draw_fixed_width_str(dstoi(argv[1]), dstoi(argv[2]),
606  (unsigned char *)argv[3], dstoi(argv[4]));
607  } else {
608  draw_str(dstoi(argv[1]), dstoi(argv[2]), (unsigned char *)argv[3]);
609  }
610 
611  return 0;
612 }
613 
614 
615 static int fontpreview(int argc, uchar *argv[]);
616 
617 /**
618  @brief 指定フォントの半角文字をプレビュー描画する
619 */
620 static const struct st_shell_command com_graph_fontpreview = {
621  .name = "fontpreview",
622  .command = fontpreview,
623  .usage_str = "[<x> <y>]",
624  .manual_str = "Draw font preview"
625 };
626 
627 static int fontpreview(int argc, uchar *argv[])
628 {
629  short sx = 0, sy = 0;
630  short x = 0, y = 0;
631  short width, height;
632  unsigned short fw;
633  unsigned short fh = font_height();
634  unsigned short ch;
635  unsigned short sc = ' ';
636 
637  if(argc >= 2) {
638  sx = dstoi(argv[1]);
639  x = sx;
640  }
641 
642  if(argc >= 3) {
643  sy = dstoi(argv[2]);
644  y = sy;
645  }
646 
647  if(argc >= 4) {
648  sc = *argv[3];
649  }
650 
651  get_screen_info(&width, &height);
652 
653  for(ch = sc; ch <= '~'; ch ++) {
654  fw = font_width(ch);
655  if(x > (width - fw)) {
656  x = sx;
657  y += fh;
658  }
659  draw_char(x, y, ch);
660  x += fw;
661  }
662 
663  return 0;
664 }
665 
666 
667 #endif // GSC_COMP_ENABLE_FONTS
668 
669 static int circle(int argc, uchar *argv[]);
670 
671 /**
672  @brief 円を描画する
673 */
674 static const struct st_shell_command com_graph_circle = {
675  .name = "circle",
676  .command = circle,
677  .usage_str = "<x> <y> <r>",
678  .manual_str = "Draw circle"
679 };
680 
681 static int circle(int argc, uchar *argv[])
682 {
683  if(argc < 4) {
684  print_command_usage(&com_graph_circle);
685  return 0;
686  }
687 
688  draw_circle(dstoi(argv[1]), dstoi(argv[2]), dstoi(argv[3]));
689 
690  return 0;
691 }
692 
693 
694 static int fcircle(int argc, uchar *argv[]);
695 
696 /**
697  @brief 塗りつぶした円を描画する
698 */
699 static const struct st_shell_command com_graph_fillcircle = {
700  .name = "fillcircle",
701  .command = fcircle,
702  .usage_str = "<x> <y> <r>",
703  .manual_str = "Draw fill circle"
704 };
705 
706 static int fcircle(int argc, uchar *argv[])
707 {
708  if(argc < 4) {
709  print_command_usage(&com_graph_fillcircle);
710  return 0;
711  }
712 
713  draw_fill_circle(dstoi(argv[1]), dstoi(argv[2]), dstoi(argv[3]));
714 
715  return 0;
716 }
717 
718 
719 static int ellipse(int argc, uchar *argv[]);
720 
721 /**
722  @brief 楕円を描画する
723 */
724 static const struct st_shell_command com_graph_ellipse = {
725  .name = "ellipse",
726  .command = ellipse,
727  .usage_str = "<x> <y> <rx> <ry>",
728  .manual_str = "Draw ellipse"
729 };
730 
731 static int ellipse(int argc, uchar *argv[])
732 {
733  if(argc < 5) {
734  print_command_usage(&com_graph_ellipse);
735  return 0;
736  }
737 
738  draw_ellipse(dstoi(argv[1]), dstoi(argv[2]),
739  dstoi(argv[3]), dstoi(argv[4]));
740 
741  return 0;
742 }
743 
744 
745 static int fellipse(int argc, uchar *argv[]);
746 
747 /**
748  @brief 塗りつぶした楕円を描画する
749 */
750 static const struct st_shell_command com_graph_fillellipse = {
751  .name = "fillellipse",
752  .command = fellipse,
753  .usage_str = "<x> <y> <rx> <ry>",
754  .manual_str = "Draw fill ellipse"
755 };
756 
757 static int fellipse(int argc, uchar *argv[])
758 {
759  if(argc < 5) {
760  print_command_usage(&com_graph_fillellipse);
761  return 0;
762  }
763 
764  draw_fill_ellipse(dstoi(argv[1]), dstoi(argv[2]),
765  dstoi(argv[3]), dstoi(argv[4]));
766 
767  return 0;
768 }
769 
770 
771 static int scrollv(int argc, uchar *argv[]);
772 
773 /**
774  @brief 縦方向に矩形領域をスクロースする
775 */
776 static const struct st_shell_command com_graph_scrollv = {
777  .name = "scrollv",
778  .command = scrollv,
779  .usage_str = "<x> <y> <xe> <ye> <v>",
780  .manual_str = "Scroll the area virtically"
781 };
782 
783 static int scrollv(int argc, uchar *argv[])
784 {
785  struct st_rect rect;
786  short v;
787 
788  if(argc < 6) {
789  print_command_usage(&com_graph_scrollv);
790  return 0;
791  }
792 
793  rect.left = dstoi(argv[1]);
794  rect.top = dstoi(argv[2]);
795  rect.right = dstoi(argv[3]);
796  rect.bottom = dstoi(argv[4]);
797  v = dstoi(argv[5]);
798 
799  scroll_rect_v(&rect, v);
800 
801  return 0;
802 }
803 
804 
805 #ifdef GSC_COMP_ENABLE_FATFS
806 
807 #ifdef GSC_LIB_ENABLE_PICOJPEG
808 
809 #include "jpegdec.h"
810 
811 static int jpeg(int argc, uchar *argv[]);
812 
813 /**
814  @brief JPEGファイルを描画する
815 */
816 static const struct st_shell_command com_graph_jpeg = {
817  .name = "jpeg",
818  .command = jpeg,
819  .usage_str = "<file_name> [<x> <y>]",
820  .manual_str = "Draw JPEG file"
821 };
822 
823 static int jpeg(int argc, uchar *argv[])
824 {
825 #define BUFSIZE 256
826  int fd;
827  int fsize;
828  short x = 0, y = 0;
829  int flg_posfix = 0;
830  int denomi = 1;
831  static pjpeg_image_info_t jpeginfo;
832 
833  if(argc < 2) {
834  print_command_usage(&com_graph_jpeg);
835  return 0;
836  }
837 
838  if(argc > 3) {
839  x = dstoi(argv[2]);
840  y = dstoi(argv[3]);
841  flg_posfix = 1;
842  }
843 
844  fd = open_file((unsigned char *)argv[1], FA_READ);
845  if(fd < 0) {
846  tprintf("Cannot open file \"%s\".\n", argv[1]);
847  return 0;
848  }
849  fsize = seek_file(fd, 0, SEEK_END);
850  (void)seek_file(fd, 0, SEEK_SET);
851  tprintf("size %d\n", fsize);
852  tprintf("x = %d, y = %d\n", x, y);
853 
854  get_jpeg_file_info(fd, &jpeginfo, 0);
855  tprintf("Width = %d, Height = %d\n", jpeginfo.m_width, jpeginfo.m_height);
856 
857  if((jpeginfo.m_width > GSC_GRAPHICS_DISPLAY_WIDTH) || (jpeginfo.m_height > GSC_GRAPHICS_DISPLAY_HEIGHT)) {
858  close_file(fd);
859  fd = open_file((unsigned char *)argv[1], FA_READ);
860  get_jpeg_file_info(fd, &jpeginfo, 1);
861  denomi = 8;
862  }
863 
864  if(flg_posfix == 0) {
865  x = (GSC_GRAPHICS_DISPLAY_WIDTH - (jpeginfo.m_width / denomi)) / 2;
866  y = (GSC_GRAPHICS_DISPLAY_HEIGHT - (jpeginfo.m_height / denomi)) / 2;
867  }
868 
869  draw_jpeg(x, y);
870 
871  close_file(fd);
872 
873  return 0;
874 }
875 #endif
876 
877 #ifdef GSC_LIB_ENABLE_LIBPNG
878 
879 #include "pngdec.h"
880 
881 static int png(int argc, uchar *argv[]);
882 
883 /**
884  @brief PNGファイルを描画する
885 */
886 static const struct st_shell_command com_graph_png = {
887  .name = "png",
888  .command = png,
889  .usage_str = "<file_name> [<x> <y>]",
890  .manual_str = "Draw PNG file"
891 };
892 
893 static int png(int argc, uchar *argv[])
894 {
895 #define BUFSIZE 256
896  int fd;
897  int fsize;
898  short x = 0, y = 0;
899  int flg_posfix = 0;
900  short width, height;
901  int rt = 0;
902  void *image;
903 
904  if(argc < 2) {
905  print_command_usage(&com_graph_png);
906  return 0;
907  }
908 
909  if(argc > 3) {
910  x = dstoi(argv[2]);
911  y = dstoi(argv[3]);
912  flg_posfix = 1;
913  }
914 
915  fd = open_file((unsigned char *)argv[1], FA_READ);
916  if(fd < 0) {
917  tprintf("Cannot open file \"%s\".\n", argv[1]);
918  return 0;
919  }
920  fsize = seek_file(fd, 0, SEEK_END);
921  (void)seek_file(fd, 0, SEEK_SET);
922  tprintf("size %d\n", fsize);
923  tprintf("x = %d, y = %d\n", x, y);
924 
925  rt = get_png_file_info(fd, &width, &height);
926  if(rt != 0) {
927  tprintf("PNG decode error(%d)\n", rt);
928  goto error;
929  }
930  tprintf("Width = %d, Height = %d\n", width, height);
931 
932  if(flg_posfix == 0) {
933  x = (GSC_GRAPHICS_DISPLAY_WIDTH - width) / 2;
934  y = (GSC_GRAPHICS_DISPLAY_HEIGHT - height) / 2;
935  }
936 
937  image = alloc_memory(width * height * sizeof(PIXEL_DATA));
938  if(image != 0) {
939  decode_png(image);
940  draw_image(x, y, width, height, image, width);
941  free_memory(image);
942  }
943 
944 error:
945  close_file(fd);
946 
947  return 0;
948 }
949 #endif // GSC_LIB_ENABLE_LIBPNG
950 
951 #endif // GSC_COMP_ENABLE_FATFS
952 
953 
954 static int vertex4_region(int argc, uchar *argv[]);
955 
956 /**
957  @brief 4頂点ポリゴンを描画する
958 */
959 static const struct st_shell_command com_graph_vertex4 = {
960  .name = "vertex4",
961  .command = vertex4_region,
962  .usage_str = "<x0> <y0> <x1> <y1> <x2> <y2> <x3> <y3>",
963  .manual_str = "Draw 4 vertex porigon"
964 };
965 
966 static int vertex4_region(int argc, uchar *argv[])
967 {
968  if(argc < 9) {
969  print_command_usage(&com_graph_vertex4);
970  return 0;
971  }
972 
973  draw_vertex4_region(dstoi(argv[1]), dstoi(argv[2]),
974  dstoi(argv[3]), dstoi(argv[4]),
975  dstoi(argv[5]), dstoi(argv[6]),
976  dstoi(argv[7]), dstoi(argv[8]));
977 
978  return 0;
979 }
980 
981 
982 static int display_frame(int argc, uchar *argv[]);
983 
984 /**
985  @brief 表示フレームを設定する
986 */
987 static const struct st_shell_command com_graph_dispframe = {
988  .name = "dispframe",
989  .command = display_frame,
990  .usage_str = "[frame_num(0|1)]",
991  .manual_str = "Set display frame"
992 };
993 
994 static int display_frame(int argc, uchar *argv[])
995 {
996  if(argc < 2) {
997  tprintf("Display Frame %d\n", get_display_frame());
998  } else {
999  set_display_frame(dstoi(argv[1]));
1000  }
1001 
1002  return 0;
1003 }
1004 
1005 
1006 static int draw_frame(int argc, uchar *argv[]);
1007 
1008 /**
1009  @brief 描画フレームを設定する
1010 */
1011 static const struct st_shell_command com_graph_drawframe = {
1012  .name = "drawframe",
1013  .command = draw_frame,
1014  .usage_str = "[frame_num(0|1)]",
1015  .manual_str = "Set draw frame"
1016 };
1017 
1018 static int draw_frame(int argc, uchar *argv[])
1019 {
1020  if(argc < 2) {
1021  tprintf("Draw Frame %d\n", get_draw_frame());
1022  } else {
1023  set_draw_frame(dstoi(argv[1]));
1024  }
1025 
1026  return 0;
1027 }
1028 
1029 
1030 static int sector(int argc, uchar *argv[]);
1031 
1032 /**
1033  @brief 扇を描画する
1034 */
1035 static const struct st_shell_command com_graph_sector = {
1036  .name = "sector",
1037  .command = sector,
1038  .usage_str = "<x> <y> <er> <ir> <q>",
1039  .manual_str = "Draw sector"
1040 };
1041 
1042 static int sector(int argc, uchar *argv[])
1043 {
1044  if(argc < 6) {
1045  print_command_usage(&com_graph_sector);
1046  return 0;
1047  }
1048 
1049  draw_sector(dstoi(argv[1]), dstoi(argv[2]),
1050  dstoi(argv[3]), dstoi(argv[4]),
1051  dstoi(argv[5]));
1052 
1053  return 0;
1054 }
1055 
1056 
1057 static int enlargedbitmap(int argc, uchar *argv[]);
1058 
1059 /**
1060  @brief 拡大したビットマップテストデータを描画する
1061 */
1062 static const struct st_shell_command com_graph_enlbitmap = {
1063  .name = "enlbitmap",
1064  .command = enlargedbitmap,
1065  .usage_str = "<x> <y> <r>",
1066  .manual_str = "Draw enlarged bitmap sample data"
1067 };
1068 
1069 static int enlargedbitmap(int argc, uchar *argv[])
1070 {
1071  extern struct st_bitmap gs_logo;
1072 
1073  if(argc < 4) {
1074  print_command_usage(&com_graph_enlbitmap);
1075  return 0;
1076  }
1077 
1078 #if 1
1079  draw_enlarged_bitmap(dstoi(argv[1]), dstoi(argv[2]),
1080  &gs_logo,
1081  dstoi(argv[3]));
1082 #else
1083  draw_bitmap(dstoi(argv[1]), dstoi(argv[2]),
1084  &gs_logo);
1085 #endif
1086 
1087  return 0;
1088 }
1089 
1090 
1091 
1092 static const struct st_shell_command * const com_grap_list[] = {
1096  &com_graph_cls,
1097  &com_graph_point,
1098  &com_graph_hline,
1099  &com_graph_vline,
1100  &com_graph_rect,
1105  &com_graph_line,
1106 #ifdef GSC_COMP_ENABLE_FONTS
1113 #endif
1119 #ifdef GSC_COMP_ENABLE_FATFS
1120 #ifdef GSC_LIB_ENABLE_PICOJPEG
1121  &com_graph_jpeg,
1122 #endif
1123 #ifdef GSC_LIB_ENABLE_LIBPNG
1124  &com_graph_png,
1125 #endif
1126 #endif
1132  0
1133 };
1134 
1135 const struct st_shell_command com_graphics = {
1136  .name = "graph",
1137  .manual_str = "Graphics operation commands",
1138  .sublist = com_grap_list
1139 }; ///< グラフィックス描画
void draw_point(short x, short y)
点を描画する
Definition: graphics.c:447
unsigned char uchar
GadgetSeedの文字(列)は unsigned char 型となる
Definition: str.h:13
PNGデコード
JPEGデコード
static const struct st_shell_command com_graph_dispframe
表示フレームを設定する
Definition: com_graphics.c:987
static const struct st_shell_command com_graph_forecolor
フォアカラーを設定する
Definition: com_graphics.c:122
シェルコマンド構造体
Definition: shell.h:33
コマンドシェル
char name[MAX_FONTNAMELEN]
フォントセット名
Definition: fontdata.h:24
メモリ管理
t_ssize seek_file(int fd, t_ssize offset, int whence)
ファイルアクセス位置の設定
Definition: file.c:244
const char * fontset_name(int num)
フォント名を取得する
Definition: font.c:188
void clear_clip_rect(void)
クリッピングエリアを無効にする
Definition: graphics.c:254
unsigned short font_height(void)
カレントフォントセットの文字高さを取得する
Definition: font.c:703
static const struct st_shell_command com_graph_line
直線を描画する
Definition: com_graphics.c:441
static const struct st_shell_command com_graph_sector
扇を描画する
static const struct st_shell_command com_graph_roundrect
角の丸い矩形を描画する
Definition: com_graphics.c:337
void draw_image(short px, short py, short width, short height, void *image, short dw)
イメージデータを描画する
Definition: graphics.c:1840
static const struct st_shell_command com_graph_fillellipse
塗りつぶした楕円を描画する
Definition: com_graphics.c:750
void draw_round_rect(struct st_rect *rect, short r)
角の丸い矩形を描画する
Definition: graphics.c:748
void free_memory(void *ptr)
確保したメモリを開放する
Definition: memory.c:195
画像表示デバイスドライバ ioctl 用マクロ定義
int fontset_count(void)
登録されているフォントセットの数を取得する
Definition: font.c:170
void draw_bitmap(short px, short py, struct st_bitmap *bitmap)
ビットマップデータを描画する
Definition: graphics.c:1146
矩形
Definition: graphics.h:64
void set_backcolor(unsigned int color)
描画の背景色を設定する
Definition: graphics.c:392
文字列処理
void draw_sector(short x, short y, short er, short ir, char q)
扇形を描画する
Definition: graphics.c:1732
short top
左上頂点のY座標
Definition: graphics.h:66
short bottom
右下頂点のY座標
Definition: graphics.h:68
short left
左上頂点のX座標
Definition: graphics.h:65
void draw_str(short x, short y, uchar *str)
文字列を描画する
Definition: font.c:494
フォントセット
Definition: fontdata.h:23
int close_file(int fd)
ファイルを閉じる
Definition: file.c:297
ビットマップグラフィックデータ
Definition: graphics.h:86
unsigned int dstou(uchar *str)
10進数文字列 unsigned int 変換
Definition: str.c:558
ファイル
void set_font_drawmode(int mode)
フォント描画モードを設定する
Definition: font.c:247
static const struct st_shell_command com_graph_fontpreview
指定フォントの半角文字をプレビュー描画する
Definition: com_graphics.c:620
static const struct st_shell_command com_graph_rect
矩形を描画する
Definition: com_graphics.c:272
カーネルタイマ
static const struct st_shell_command com_graph_fillcircle
塗りつぶした円を描画する
Definition: com_graphics.c:699
static const struct st_shell_command com_graph_point
点を描画する
Definition: com_graphics.c:197
void get_screen_info(short *width, short *height)
スクリーンのサイズ情報を取得する
Definition: graphics.c:329
short right
右下頂点のX座標
Definition: graphics.h:67
void draw_line(short x, short y, short xe, short ye)
直線を描画する
Definition: graphics.c:664
void draw_h_line(short x, short y, short width)
水平線を描画する
Definition: graphics.c:477
void draw_rect(struct st_rect *rect)
矩形を描画する
Definition: graphics.c:694
static const struct st_shell_command com_graph_backcolor
バックカラーを設定する
Definition: com_graphics.c:151
void scroll_rect_v(struct st_rect *rect, short pixcel)
矩形範囲を縦方向にスクロールする
Definition: graphics.c:1882
struct st_fontset * set_font_by_name(char *name)
カレントフォントセットをフォント名で設定する
Definition: font.c:226
struct st_fontset * get_fontset(void)
描画に使用されているフォントセット(カレントフォントセット)取得する
Definition: font.c:160
void draw_fill_rect(struct st_rect *rect)
塗りつぶした矩形を描画する
Definition: graphics.c:821
int dstoi(uchar *str)
10進数文字列 int 変換
Definition: str.c:523
int open_file(const uchar *path, int flags)
ファイルを開く
Definition: file.c:144
const struct st_shell_command com_graph_drawmode
描画モードを設定する
Definition: com_graphics.c:97
void * alloc_memory(unsigned int size)
メモリを確保する
Definition: memory.c:138
uchar name[12]
コマンド名文字列
Definition: shell.h:34
int get_draw_frame(void)
描画するフレームバッファ番号を取得する
Definition: graphics.c:246
void set_draw_mode(unsigned char mode)
描画モードを設定する
Definition: graphics.c:414
void set_forecolor(unsigned int color)
描画の色を設定する
Definition: graphics.c:370
int get_display_frame(void)
表示しているフレームバッファ番号を取得する
Definition: graphics.c:214
unsigned short draw_char(short x, short y, ushort ch)
文字を描画する
Definition: font.c:433
GadgetSeed カーネル
void draw_fill_ellipse(short xc, short yc, short rx, short ry)
塗りつぶした楕円を描画する
Definition: graphics.c:1335
static const struct st_shell_command com_graph_circle
円を描画する
Definition: com_graphics.c:674
int tprintf(const char *fmt,...)
簡易printf
Definition: tprintf.c:85
static const struct st_shell_command com_graph_cliprect
クリッピング領域を設定する
Definition: com_graphics.c:405
int set_display_frame(int fnum)
表示するフレームバッファ番号を設定する
Definition: graphics.c:204
#define SEEK_SET
設定
Definition: device.h:21
void set_clip_rect(struct st_rect *rect)
クリッピングエリアを矩形で指定する
Definition: graphics.c:264
static const struct st_shell_command com_graph_scrollv
縦方向に矩形領域をスクロースする
Definition: com_graphics.c:776
static const struct st_shell_command com_graph_drawframe
描画フレームを設定する
static const struct st_shell_command com_graph_fillrect
塗りつぶした矩形を描画する
Definition: com_graphics.c:305
int set_draw_frame(int fnum)
描画するフレームバッファ番号を設定する
Definition: graphics.c:236
void clear_screen(void)
画面を全て0で描画する
Definition: graphics.c:338
static const struct st_shell_command com_graph_setfont
描画するフォントを設定する
Definition: com_graphics.c:476
static const struct st_shell_command com_graph_roundfillrect
角の丸い塗りつぶした矩形を描画する
Definition: com_graphics.c:371
static const struct st_shell_command com_graph_hline
水平線を描画する
Definition: com_graphics.c:222
unsigned short font_width(unsigned short ch)
カレントフォントセットの文字幅を取得する
Definition: font.c:648
static const struct st_shell_command com_graph_drawstr
文字列を描画する
Definition: com_graphics.c:590
コンソールI/O
static const struct st_shell_command com_graph_proportional
フォントの描画モード(固定幅/プロポーショナル)を設定する
Definition: com_graphics.c:515
void draw_vertex4_region(short x0, short y0, short x1, short y1, short x2, short y2, short x3, short y3)
塗りつぶした4頂点の領域を描画する
Definition: graphics.c:1510
int hstoi(uchar *str)
16進数文字列 int 変換
Definition: str.c:145
static const struct st_shell_command com_graph_drawchar
1文字描画する
Definition: com_graphics.c:540
void draw_fill_circle(short x0, short y0, short r)
塗りつぶした円を描画する
Definition: graphics.c:1253
static const struct st_shell_command com_graph_enlbitmap
拡大したビットマップテストデータを描画する
void draw_enlarged_bitmap(short px, short py, struct st_bitmap *bitmap, int rate)
拡大したビットマップデータを描画する
Definition: graphics.c:1160
static const struct st_shell_command com_graph_vertex4
4頂点ポリゴンを描画する
Definition: com_graphics.c:959
void draw_v_line(short x, short y, short height)
垂直線を描画する
Definition: graphics.c:511
#define SEEK_END
ファイルサイズに加算
Definition: device.h:23
void draw_circle(short x0, short y0, short r)
円を描画する
Definition: graphics.c:1173
static const struct st_shell_command com_graph_cls
画面を初期化する
Definition: com_graphics.c:185
void draw_round_fill_rect(struct st_rect *rect, short r)
角の丸い塗りつぶした矩形を描画する
Definition: graphics.c:838
グラフィックライブラリ
フォント
static const struct st_shell_command com_graph_vline
垂直線を描画する
Definition: com_graphics.c:247
unsigned short PIXEL_DATA
$gsc グラフィックデバイスは24ビットカラー
Definition: graphics.h:17
機能限定printf
static const struct st_shell_command com_graph_ellipse
楕円を描画する
Definition: com_graphics.c:724
void draw_fixed_width_str(short x, short y, uchar *str, short width)
固定幅で文字列を描画する
Definition: font.c:520
static const struct st_shell_command com_graph_jpeg
JPEGファイルを描画する
Definition: com_graphics.c:816
void draw_ellipse(short xc, short yc, short rx, short ry)
楕円を描画する
Definition: graphics.c:1283
static const struct st_shell_command com_graph_charcode
指定文字コードの文字を描画する
Definition: com_graphics.c:565