/* --- visio.h ver1.4 */
/* --- coded by Masaki Oshima 1st release(ver1.0) 1999.10.01 */
/* ver1.1 released 1999.10.13 */
/* ver1.1.1 released 1999.10.27 */
/* ver1.4 released 2001.06.14 */
/* last modification 2001.06.14 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <rasterfile.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <string.h>
#define SUCCESS 0
#define FAIL 1
/* rasterfile.h exists in /usr/openwin/share/include/pixrect (on titan) */
/* --- for raster data input */
struct rasin{
char *data_name;
FILE *fpin;
Bool nrm_magic; /* normal header */
Bool rvs_magic; /* ras_magic is reversed */
Bool gray; /* gray data: no header& no clr map */
Bool no_cmp; /* no color map */
Bool dir_col; /* direct color */
/*Bool color_data; */
Bool byte_encoded;/* byte_encoded */
/* rasterfileのカラーマップ(またはそれと等価)を入れる */
XColor *color;
int pixs; /* colorの長さ */
u_char *colbuf; /* 2000.11.13 */
XStandardColormap *scmap; /* 24ビットカラーデータを扱うとき用いる */
/* XGetStandardColormap関数がうまく動かないのでデータは自前 */
/* vdataはディスクから読んだラスターデータ、vdispは表示用ピクセル値配列 */
/* (colorのエントリ) */
u_char *vdata, *vdisp;
/* 2000.07.05 */
int width, height, depth, points, length, type, maptype, maplength;
/* 2000.08.29 */
int pix_span, pix_offset, r_offset, g_offset, b_offset;
};
struct Display_color{
u_char *vdata, *vdisp;
int width, height, depth, points;
XColor *color;
int pixs; /* colorの長さ */
XStandardColormap *scmap;
u_char *levav, *ctable;
};
/* --- for accessing the data 2 dimensionally 2次元アクセスのためのマクロ */
/* 注意:gccでは可能なマクロのネストがccではできない(らしい)ので、可読性
を犠牲にして、互換性のある形式で書いてある。gccだけの環境で使う時は
コメントアウトしてあるものを復活させてもよい。なお、gccで-Eオプショ
ンを用いると、マクロの展開形を見ることができる */
#define MAX_HEIGHT 1000
#define O_RED 2
#define O_GREEN 1
#define O_BLUE 0
/* cがr, g, bかに応じrasterfileのオフセットを与える */
/* カラー用2次元アクセス */
#define col_n(c) (c) == 'r' ? 2 : ((c) == 'g' ? 1 : 0 )
/*#define col_n(c) ( ((c) == "r") ? O_RED : ( ((c) == "g") ? O_GREEN
: O_BLUE ) )*/
/* nested macro is not permitted for cc, then col_n(c) is just a fiction*/
/*#define col_n(c) ( ((c) == "r") ? 2 : ( ((c) == "g") ? 1 : 0 ) )
/* 画像データに見かけ上2次元配列類似のアクセスを提供、掛算しないので高速 */
#define f_xy(data,x,y) *((data)[(y)]+(x))
/* カラー用2次元アクセス */
#define f_xyc(data,x,y,c) *( (data)[(y)] + rasin->pix_span * (x) \
+ rasin->pix_offset + ( (c) == 'r' ? rasin->r_offset : \
((c) == 'g' ? rasin->g_offset : rasin->b_offset ) ) )
/*#define f_xyc(data,x,y,c) *( (data)[(y)] + 3 * (x) + ( (c) == 'r'
? 2 : ((c) == 'g' ? 1 : 0 ) ) )*/ /* 2000.08.29 */
/* f_xycr is for supporting ras_type = 3 */
/* カラー用2次元アクセス(逆向き) */
#define f_xycr(data,x,y,c) \
*( (data)[(y)] + 3 * (x) + ( (c) == 'r' ? 0 : ((c) == 'g' ? 1 : 2 ) ) )
/*#define f_xyc(data,x,y,c) *((data)[(y)] + 3 * (x) + col_n((c)) )*/
#define f_yx(data,y,x) *((data)[(y)]+(x)) /* 好みで使えるようxy逆順を提供 */
#define f_yxc(data,y,x,c) \
*((data)[(y)] + 3 * (x) + ((c) == 'r' ? 2 : ((c) == 'g' ? 1 : 0 ) ) )
/*#define f_yxc(data,y,x,c) *((data)[(y)] + 3 * (x) + ( ((c) == "r")
? 2 : ( ((c) == "g") ? 1 : 0 )) )*/
#define f_xyc2(data,x,y,c) \
*((data)[(y)] + (rasin->pix_span) * (x) + \
(rasin->pix_offset) + ( (rasin->rvs_magic) == 0 ? 2 - (c) : (c) ) )
/*#define f_xyc2(data,x,y,c) *((data)[(y)] + 4 * (x) + 1 + (2-c) )*/
/*#define f_xyc2(data,x,y,c) *((data)[(y)] + 3 * (x) + (2-c) )*/
/* -------- 関数プロトタイプ -------- */
/*ファイルから画像データを読み出す*/
struct rasin *get_image(char *data_name, int *width, int *height, int *pixs);
/*ファイルからheader情報を取り出す*/
XColor *get_header(char *data_name, struct rasin *rasin);
int no_cmp(struct rasin *rasin); /* 2000.09.12 */
int wrt_image(char *data_name, u_char *vdata, int length, XColor *color
, int pixs, int width, int height, int depth, int type, int maptype
, int maplength, struct rasin *rasin);
/*, int maplength); 2000.11.13 */
FILE *wrt_header(char *data_name, int length, XColor *color, int pixs
, int width, int height, int depth, int type, int maptype
, int maplength, struct rasin *rasin);
/* , int width, int height, int depth, int type, int maptype
, int maplength); 2000.11.13 */
unsigned int rev_word( unsigned int in); /* 2000.07.03 */
/* 標準的rasterfile向けcolorの処理 */
u_char *set_colbuf(FILE *fpin, int pixs);
XColor *mk_nrmcmp(int pixs, u_char *colbuf);
/*XColor *mk_nrmcmp(char *data_name, struct rasin *rasin); 2000.09.07 */
/* ダイレクトカラー向けcolorの処理(標準カラーマップ形式データの生成) */
XColor *mk_dircol(char *data_name, XStandardColormap **scmap
, struct rasin *rasin);
/*XColor *mk_dircol(char *data_name, struct rasin *rasin); 2000.10.11 */
/*XColor *mk_dircmp(char *data_name, struct rasin *rasin); 2000.08.31 */
u_char *decode_vdata(u_char *vdata, struct rasin *rasin);
/* ダイレクトカラー向け、vdataからvdsipの生成 */
u_char *data_to_disp(u_char *vdata, int points, XStandardColormap *scmap
, int pixs, struct rasin *rasin);
/* grayデータ向けcolorデータの生成 */
XColor *mk_psdhdr(char *data_name, struct rasin *rasin);
XColor *mono_cmp(struct rasin *rasin);
int disp_set(void);
/* colorデータからプライベートカラーマップの生成 */
Colormap set_cmap(XColor *color, int pixs, struct rasin *rasin);
/*Colormap set_cmap(XColor *color, int pixs); 2000.08.30 */
/*int set_cmap(Window win, XColor *color, int pixs);*/
/* 表示用データvdispをcolorに従ってディスプレイに表示 */
/*ウインドウの設定*/
Window win_set(int width, int height, char *name, Colormap cmap);
/*Window win_set(int width, int height, char *name);*/
XImage *put_image(u_char *vdisp, int width, int height, int depth
, Window win, XColor *color, int pixs, int gray);
XImage *mk_image(u_char *vdisp, int width, int height, int depth
, Window win, XColor *color, int pixs, int gray);
/*XImage *put_image(u_char *vdisp, int width, int height, int depth
, Window win, XColor *color, int pixs, int gray, int bwrev);*/
u_char *dith_data(u_char *vdtata, u_char **vd, int width, int height
, XStandardColormap *scmap, struct rasin *rasin);
XStandardColormap *homo_hist(u_char **vdp, int width, int height
, int *pixs, struct Display_color *dspcol, u_char levav[][3]
, u_char ctable[][3], struct rasin *rasin);
/*XStandardColormap *homo_hist(u_char **vdp, int width, int height
, int *pixs, struct Display_color *dspcol, u_char levav[][3]
, u_char ctable[][3]); 2000.08.30 */
int prin_levavs(u_char levav[][3], u_char ctable[][3]);
int histc(u_char **vdp, int width, int height, int l, int *maxf
, u_char levav[][3], u_char ctable[][3], struct rasin *rasin);
/*, u_char levav[][3], u_char ctable[][3]); 2000.08.30 */
u_char *data_to_dsph(u_char *vdata, int points, XStandardColormap *scmap
, int pixs, u_char levav[][3], u_char ctable[][3], struct rasin *rasin);
/*, int pixs, u_char levav[][3], u_char ctable[][3]); 2000.08.30 */
戻る