/* --- winn-cm ver1.1 */
/* This is a sample program for reading color data in file
/* and make mono color map using average of RGB 2000.09.14 */
/* vdataにカラー画像を読み込んで、モノクロ化してvdata2に入れ表示*/
/* --- modified by M.Shimpo based on winn.c */
/* last modification 2000.11.27 */
/* usage example winn-cm ~/Video_data/amano/Fune9-c.ras */
#include <stdio.h>
#include "vismain.h"
int main(int argc, char
*argv[])/*==============================================
=*/
{
char data_name[100];
unsigned char *vdata, *vdata2, *vdisp, *vdisp2, r, g, b, *colbuf;
double m;
/* unsigned char *vdata, *vdata2, *vdisp, *vdisp2, r, g, b,m, *colbuf; */
unsigned char *vd[MAX_HEIGHT], *vd2[MAX_HEIGHT];
int width, height, depth, points, gray=0, bwrev;
XColor *color; int pixs;
struct rasin *rasin;
static Window win1, win2;
int x, y, i;
XImage *image; XStandardColormap *scmap;
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はrasterfileのカラーマップデータ
*/
points = width * height; /* 画素点の数を横幅と縦幅から計算 */
/* 画像領域vdata2(処理結果用、vdataと同サイズ)の確保 */
vdata2 = (unsigned char *)malloc(points); /* 各点ごとに1バイト使用 */
/* vdata2 = (unsigned char *)malloc(points *rasin->pix_span);*/ /* 各点ごと
に3(4)バイト使用 */
if(vdata2 == NULL) goto err;
/* 2次元配列類似アクセス(f_xyc(data,x,y,c))の準備*/
/* y行目先頭の点のvdata, vdata2中の位置を設定 */
for(y = 0; y < height; y++){
vd [y] = vdata + rasin->pix_span * y * width;
vd2[y] = vdata2 + y * width;
}
/* vdataから読んで(処理の上)vdata2に書く(ラスター走査) */
for(y = 0; y < height; y++){
for(x = 0; x < width; x++){
r = f_xyc(vd, x, y, 'r'); /* vdata各画素rの読み出し、2次元配
列類似アクセスマクロ使用(visio.h参照)*/ /* 注意ras_type3のデータのときf_xycrを
使うこと */
g = f_xyc(vd, x, y, 'g');
b = f_xyc(vd, x, y, 'b');
m = sqrt((double)(r*r + g*g + b*b))/sqrt(3.0);
/* m = (u_char)(sqrt((double)(((r*r) + (g*g) + (b*b))/3.0))); */
f_xy(vd2,x,y)= (unsigned char) m;
}
}
pixs = 256; /* 2000.12.28 */
colbuf = (u_char *)malloc(pixs*3);
for(i=0;i<pixs;i++){
colbuf[i ] = colbuf[pixs + i] = colbuf[2*pixs + i] = i;
/* *(colbuf + i) = (u_char)(i);
*(colbuf + pixs + i) = (u_char)(i);
*(colbuf + 2*pixs + i) = (u_char)(i); */
}
color=mk_nrmcmp(256,colbuf);
/* vdata2からscmapに従って表示用の形式vdispを作る */
/* vdisp = data_to_disp(vdata2, points, scmap, pixs, rasin);*/
cmap = set_cmap(color, pixs, rasin); /* カラーマップの設定 */
win1 = win_set(width, height, "output data", cmap);/*ウインドウの設定*/
printf("Hit Return Key after window set\n");
depth =8;
/* 表示用データvdispをcolorに従ってディスプレイに表示 */
vdisp = vdata2;
image = put_image (vdisp, width, height, depth, win1, color, pixs
, gray);
printf("Hit Return Key to continue\n");
getchar();
XClearWindow(disp,win1);
XFlush(disp);
printf("Hit Return Key to end\n");
getchar();
XFree(image);
free(vdata); free(vdisp);
return SUCCESS;
err: printf("error in main\n");
return FAIL;
}
/* End of main */
戻る