/* --- wrtds.c ver1.3.1 */
/*  This is a sample program for write image data in sunraster
format */
/* coded by Masaki Oshima */
/*                             1st release(ver1.0)  2000.07.05  */
/*                             last modification    2000.10.11  */

/* usage example winn ~/Video_data/gazou/hirosue.ras */


#include <stdio.h>
#include "vismain.h"

int main(int argc, char *argv[])/*==============================================
=*/
{
        char data_name[100],data_name2[100] = "outputfile.ras";
        unsigned char   *vdata, *vdisp;
        int width, height, depth, gray, bwrev;
        int length, type, maptype, maplength;
        XColor *color; int pixs;
        struct rasin *rasin;
        static Window win1;
        int points;
        XImage *image; XStandardColormap *scmap;
        Colormap cmap; /* 2000.08.30 */

        if( argc<2 ){
            printf("Usage: [Program][data_name]\n");
            return (int)NULL;
        }
        sprintf(data_name,"%s",argv[1]); /*データ名の設定*/

        /*画像ファイルデータの読み込み  rasinはデータ入力のための領域  visio.h参
照*/
        rasin = get_image(data_name, &width, &height, &pixs);
        if(rasin == NULL) goto err;
        vdata = rasin->vdata;           /* vdataは入力画像の入っている領域  */
        color = rasin->color;           /* colorはカラーマップデータ        */
        points = width * height;        /* 画素点の数を横幅と縦幅から計算 */

        if(rasin->dir_col == True){ /* ifが成立するときダイレクトカラー画像 */
/*      if(rasin->color_data == True){ */
           scmap = rasin->scmap; /* scmapはカラー画像のとき用いる標準カラーマッ
プ形式のデータ */
           /* vdataからscmapに従って表示用の形式vdispを作る */
           vdisp = data_to_disp(vdata, points, scmap, pixs, rasin);
        }else{
           vdisp = vdata; /* モノクロ画像のときはvdispはvdataと同じでよい */
        }

        cmap = set_cmap(color, pixs, rasin); /* カラーマップの設定 */
/*      cmap = set_cmap(color, pixs); 2000.08.31 */
        printf("Hit Return Key for window setting\n"); /* ウインドウ設定の\
ための待ち */
        getchar();
        win1  = win_set(width, height, "output data", cmap);      /* ウインドウ
の設定 */
/*      win1  = win_set(width, height, "output data"); 2000.08.30 */
        printf("Hit Return Key for window setting\n");      /* ウインドウ設定の
ための待ち */
        getchar();

/*      bwrev = set_cmap(win1, color, pixs); 2000.08.30 */

        depth =8;
        /* 表示用データvdispをcolorに従ってディスプレイに表示 */
        gray = rasin->gray;
        image = put_image (vdisp, width, height, depth, win1, color, pixs, gray)
;
/*      image = put_image (vdisp, width, height, depth, win1, color, pixs, gray,
 bwrev); 2000.08.30 */
        printf("enter data name\n");      /* 表示を保持するための待ち */
        scanf("%s",data_name2);
        length  = rasin->length;     pixs      = rasin->pixs;
        depth   = rasin->depth;      type      = rasin->type;
        maptype = rasin->maptype;    maplength = rasin->maplength;
        wrt_image(data_name2, vdata, length, color, pixs, width, height, depth,
        type, maptype, maplength);
        XFree(image);                        /* 使用したメモリを解放する */
        free(vdata); free(vdisp);
        return SUCCESS;
        /* エラー時の処理 */
err:    printf("error in main\n");
        return FAIL;
}
/* End of main */


戻る