/* --- winn-ac.c ver1.3.1 */
/*   This is a sample program for reading 24bit color data in file
              to do something on it and disply it.*/
/* --- coded by Masaki Oshima                                   */
/*                             1st release(ver1.0)  1999.10.01  */
/*                             ver1.1 released      1999.10.13  */
/*                             ver1.2 released      1999.11.12  */
/*                             last modification    2000.10.11  */


/* usage example winn-ac ~/Video_data/amano/Fune9-c.ras */

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


/*                             last modification     2000.08.31  */
int main(int argc, char *argv[])/*==============================================
=*/
{
   char data_name[100], buf[100];
   unsigned char *vdata, *vdata2, *vdisp, *vdisp2, *vdisph, r, g, b;
   unsigned char *vdp[MAX_HEIGHT], *vdp2[MAX_HEIGHT], levav[20][3]
   , ctable[256][3];
   int width, height, depth, points, gray=0;
   XColor *color, *colorh; int pixs, pixsh;
   struct rasin *rasin;
   static Window win1, win2, winh;
   int x, y;
   XImage *image; XStandardColormap *scmap, scmaps, *scmaph;
   Atom prop;
   struct Display_color *dspcol;
   Colormap cmap; /* 2000.08.10 */



   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はXColor形式のカラーデータ */
   points = width * height;        /* 画素点の数を横幅と縦幅から計算 */

        /* 画像領域vdata2(処理結果用、vdataと同サイズ)の確保 */
   vdata2 = (unsigned char *)malloc(points *rasin->pix_span); /* 各点ごとに3バイ
ト使用 */
/*   vdata2 = (unsigned char *)malloc(points *3);*/
   if(vdata2 == NULL) goto err;
   /* 2次元配列類似アクセス(f_xyc(data,x,y,c))の準備*/
   /* y行目先頭の点のvdata, vdata2中の位置を設定 */
   for(y = 0; y < height; y++){ /* 2000.08.29 */
     vdp[y]  = vdata  + rasin->pix_span*y*width;
     vdp2[y] = vdata2 + rasin->pix_span*y*width;
}
/*      {vdp[y] = vdata + 3*y*width; vdp2[y] = vdata2 + 3*y*width;}*/

   /* vdataから読んで(処理の上)vdata2に書く(ラスター走査) */
   for(y = 0; y < height; y++){
      for(x = 0; x < width; x++){
         r = f_xyc(vdp, x, y, 'r'); /* vdata各画素rの読み出し、2次元配列類似アク
セスマクロ使用(visio.h参照)*/
         g = f_xyc(vdp, x, y, 'g');
         b = f_xyc(vdp, x, y, 'b');
       if( y > x && y < x+30) b = 2*b/3; /* 各画素の処理(テスト用) */
         f_xyc(vdp2, x, y, 'r') = r;    /* 各画素のrをvdata2に書く  */
         f_xyc(vdp2, x, y, 'g') = g;
         f_xyc(vdp2, x, y, 'b') = b;
/*       r = *(vdata + (y*width + x)*3 + 2 );*/  /*  この形式で読み書きしてもよ
い、ただしマクロの方が速い */
/*       g = *(vdata + (y*width + x)*3 + 1 );
         b = *(vdata + (y*width + x)*3     );
         if( y > height/2) b = b/2;
         *(vdata2 + (y*width + x)*3 + 2 ) = (unsigned char) r;
         *(vdata2 + (y*width + x)*3 + 1 ) = (unsigned char) g;
         *(vdata2 + (y*width + x)*3     ) = (unsigned char) b;*/
      }
   }

/* sub( vdp2);                  関数に処理結果を渡したいときの呼び出し例 */
/* sub( unisigned char *vdp2[]) 呼び出される側。上記のfor文と同様にアクセス可能
*/

   depth = 8;
/*   goto homo_h;*/
/* ---------- ディスプレイへの表示(手抜き版)---------- */
        if(rasin->dir_col == True){ /* ifが成立するときダイレクトカラー画像 */
           scmap = rasin->scmap; /* scmapはカラー画像のとき用いる標準カラー
                                    マップ形式のデータ */
           /* vdataからscmapに従って表示用の形式vdispを作る */
           vdisp = data_to_disp(vdata, points, scmap, pixs, rasin);
         }else{
           vdisp = vdata; /* カラーマップのあるデータ(非ダイレクトカラー)
                             のときはvdispはvdataと同じでよい */
         }
   printf("Hit Return Key to set window for put_image\n");
   gets(buf);
   cmap = set_cmap(color, pixs, rasin);           /* カラーマップの設定 */
/*   cmap = set_cmap(color, pixs);          2000.08.31 */
/*   bwrev = set_cmap(win1, color, pixs);*/
   win1  = win_set(width, height, "output data", cmap); /*ウインドウの設定*/
/*   win1  = win_set(width, height, "output data");*/
   printf("Hit Return Key to continue\n");
   gets(buf);

   /* 表示用データvdispをcolorに従ってディスプレイに表示 */
   image = put_image (vdisp, width, height, depth, win1, color, pixs
   , gray);
/*   , gray, bwrev);*/
   XFlush(disp);

/* ---------- ディスプレイへの表示(ディザ法)---------- */
   printf("Hit Return Key to set window for dith_data\n");
   gets(buf);
   win2 = win_set(width, height, "output by dither", cmap);   /*ウインドウの設定
*/
/*   win2 = win_set(width, height, "output by dither");*/
   printf("Hit Return Key to continue\n");
   gets(buf);

   if(rasin->dir_col != True){
     printf("no support for non-direct color data here after\n");
     return NULL;
   }
   /* ディザ方式でディスプレイするためのデータ生成 */
   vdisp2 = dith_data(vdata2, vdp2, width, height, scmap, rasin);
/*   vdisp2 = dith_data(vdata2, vdp2, width, height, scmap); 2000.08.29 */
   image = put_image (vdisp2, width, height, depth, win2, color, pixs
   , gray);
/*   , gray, bwrev);*/
   XFlush(disp);

homo_h:
/*-- ディスプレイへの表示(カラーヒストグラム平坦化によるカラーマップ使用)--*/
   dspcol = (struct Display_color *)malloc(sizeof(struct Display_color));
   if(dspcol == NULL) goto err;
   dspcol->vdata = vdata2; dspcol->width = width; dspcol->height = height;
   dspcol->points = points;
   dspcol->levav  = levav ; dspcol->ctable = ctable;
   scmaph = homo_hist(vdp2, width, height, &pixsh, dspcol, levav, ctable, rasin)
;
/*   scmaph = homo_hist(vdp2, width, height, &pixsh, dspcol, levav, ctable); 200
0.08.30*/
   colorh = dspcol->color;
   cmap  = set_cmap(colorh, pixsh, rasin);          /* カラーマップの設定 */
/*   cmap  = set_cmap(colorh, pixsh);   2000.08.31 */
/*   bwrev  = set_cmap(winh, colorh, pixsh);*/
   printf("Hit Return Key to set window for homo_hist\n");
   gets(buf);
   winh = win_set(width, height, "output by homo_hist", cmap); /*ウインドウの設
定*/
/*   winh = win_set(width, height, "output by homo_hist");*/

   vdisph = data_to_dsph(vdata2, points, scmaph, pixsh, levav, ctable, rasin);
/*   vdisph = data_to_dsph(vdata2, points, scmaph, pixsh, levav, ctable); 2000.0
8.30 */
   dspcol->vdisp = vdisph;

   image = put_image (vdisph, width, height, depth, winh, color, pixs
   , gray);
/*   , gray, bwrev);*/
   XFlush(disp);

   printf("Hit Return Key to end\n");
   gets(buf);
   XFree(image);
   free(vdata); free(vdisp);
   return SUCCESS;
err:    printf("error in main\n");
        return FAIL;
}
/* End of main */


戻る