OSDN Git Service

Updated the lcdtool to version 0.0.3.
[bluetank/bluetank.git] / soft / utils / lcdtool / main.c
index 9014dc4..946124f 100644 (file)
@@ -5,7 +5,7 @@
 
 /*
  * ===============================================================
- *  BlueTank
+ *  LCD Image Tool
  * ===============================================================
  * Copyright (c) 2012 Shinichiro Nakamura
  *
 
 #include <stdio.h>
 #include <string.h>
-#include <stdlib.h>
-#include "bmpimg.h"
 #include "lcdimg.h"
-#include "canvas.h"
+#include "util.h"
 
-int main(int argc, char **argv);
-
-/**
- * @brief ストリームからデータを読み込む。
- * @details
- * インターフェースでは、何からどのように読み込むかについて一切感知していない。
- * この関数では、何からどのように読み込むかについて解決する。
- *
- * @param buf バッファへのポインタ。
- * @param size 読み込みバイトサイズ。
- * @param extobj ユーザが指定した拡張オブジェクト。
- */
-int func_fread(void *buf, const unsigned int size, void *extobj)
-{
-    FILE *fp = (FILE *)extobj;
-    return fread(buf, size, 1, fp);
-}
+#define VERSION_MAJOR   (0)
+#define VERSION_MINOR   (0)
+#define VERSION_RELEASE (3)
 
-/**
- * @brief ストリームへデータを書き込む。
- * @details
- * インターフェースでは、何にどのように書き込むかについて一切感知していない。
- * この関数では、何にどのように書き込むかについて解決する。
- *
- * @param buf バッファへのポインタ。
- * @param size 書き込みバイトサイズ。
- * @param extobj ユーザが指定した拡張オブジェクト。
- */
-int func_fwrite(const void *buf, const unsigned int size, void *extobj)
-{
-    FILE *fp = (FILE *)extobj;
-    return fwrite(buf, size, 1, fp);
-}
+int main(int argc, char **argv);
 
 int main(int argc, char **argv)
 {
-    const int imgw = 240;
-    const int imgh = 110;
-    canvas_t canvas;
-    bmpimg_t bmpimg;
-    bmpcol_t col;
     LCDIMG *lcdimg;
-    FILE *fp;
-    int i;
-
-    if (argc != 4) {
-        printf("lcdtool [file] [line1] [line2]\n");
-        exit(1);
+    int i, j;
+
+    if (argc < 5) {
+        printf("=================================================\n");
+        printf(" LCD Tool (Version %d.%d.%d)\n", VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE);
+        printf(" Copyright(C) 2012 Shinichiro Nakamura\n");
+        printf("=================================================\n");
+        printf("\n");
+        printf(" lcdtool [LCD Profile] [LCD Fontfile] [BMP File] [Line 1] [Line 2] ...\n");
+        printf("\n");
+        return 0;
     }
 
-    /*
-     * 画像ピクセルを格納する領域を確保する。
-     */
-    canvas.w = imgw;
-    canvas.h = imgh;
-    canvas.buffer = (bmpcol_t *)malloc(sizeof(bmpcol_t) * imgw * imgh);
-
-    /*
-     * 開始処理。
-     *
-     * ピクセル入出力関数を渡して初期化する。
-     * ユーザが指定可能な拡張オブジェクトに、独自に規定したキャンバスを渡しておく。
-     */
-    bmpimg_open(&bmpimg, imgw, imgh, canvas_pixel_writer, &canvas, canvas_pixel_reader, &canvas);
-
-    BMPIMG_SET_COLOR(col, 124, 120, 230);
-    bmpimg_fill_box(&bmpimg, 0, 0, imgw - 1, imgh - 1, &col);
-
-    lcdimg = lcdimg_open(8, 2);
-    for (i = 0; i < strlen(argv[2]); i++) {
-        lcdimg_text(lcdimg, i, 0, argv[2][i]);
+    lcdimg = lcdimg_open(argv[1], argv[2]);
+    if (lcdimg == NULL) {
+        printf("Illegal configuration found.\n");
+            return 1;
     }
-    for (i = 0; i < strlen(argv[3]); i++) {
-        lcdimg_text(lcdimg, i, 1, argv[3][i]);
+    for (i = 0; i <= argc - 5; i++) {
+        char buf[BUFSIZ];
+        int bytes = 0;
+        if (util_format(argv[4 + i], buf, sizeof(buf), &bytes) != 0) {
+            printf("Illegal format string found.\n");
+            return 2;
+        }
+        for (j = 0; j < bytes; j++) {
+            lcdimg_text(lcdimg, j, i, buf[j]);
+        }
     }
-
-    lcdimg_draw(lcdimg, canvas_drawer, &canvas);
-
-    fp = fopen(argv[1], "wb");
-    if (fp != NULL) {
-        bmpimg_bmp_write(&bmpimg, func_fwrite, fp);
-        fclose(fp);
-    }
-
+    lcdimg_write(lcdimg, argv[3]);
     lcdimg_close(lcdimg);
 
-    /*
-     * 終了処理。
-     */
-    bmpimg_close(&bmpimg);
-
-    /*
-     * 画像ピクセルを格納する領域を破棄する。
-     */
-    free(canvas.buffer);
-
     return 0;
 }