JunkBox_Lib  1.10.2
openX.c File Reference

X-Winow 表示用関数 More...

#include "openX.h"
Include dependency graph for openX.c:

Go to the source code of this file.

Functions

openX disp_image (WSGraph gd, int lc, int hc, int cflg)
 
void displayClose (openX xid)
 
openX displayOpen (int xs, int ys, int cflg)
 
void set_color (openX xid, double r, double g, double b)
 

Detailed Description

Version
2.11
Author
Fumi.Iseki (C)

Definition in file openX.c.

Function Documentation

◆ disp_image()

openX disp_image ( WSGraph  gd,
int  lc,
int  hc,
int  cflg 
)

openX disp_image(WSGraph gd, int lc, int hc, int cflg)

グラフィックデータ gdをディスプレイ上に表示する.

Parameters
gd表示するグラフィックデータ.
lcコントラスト調整.これより小さい輝度値は表示しない.0より小さい(-1以下の)場合は自動調整する.
hcコントラスト調整.これより大きい輝度値は表示しない.0以下の場合は自動調整する.
cflg表示モード MONOC: グレースケール表示.COLOR: カラー表示 (未サポート)
Returns
表示したウィンドウの識別子.
Attention
正しく表示されない場合は,openX.h の COLOR_DEPTH を変更する.
Bug:
カラーデプスが8bitでは正しく表示されない. 表示モードの COLORは完全にサポートされていないので表示がおかしくなる.

Definition at line 32 of file openX.c.

33 {
34  int i, j, sl, sh;
35  char *image;
36  int nc = COLOR_NUM;
37  int width, height, dpth, dpb;
38  int tmp, col;
39  unsigned short int* pnt;
40 
41  sWord *imagewk;
42  XImage *ximg;
43  Visual *visl;
44  Pixmap pmap;
45  openX xid;
46 
47  width = gd.xs;
48  height = gd.ys;
49  imagewk = gd.gp;
50 
51  xid = displayOpen(gd.xs, gd.ys, cflg);
52 
53  sl = sh = 1;
54  if (hc<=0) sh = -1;
55  if (lc<0) {
56  sl = -1;
57  lc = SINTMAX;
58  }
59  if (sl<0 || sh<0) {
60  for(i=0; i<width*height; i++){
61  tmp = *(imagewk + i);
62  if (sl<0) lc = Min(lc, tmp);
63  if (sh<0) hc = Max(hc, tmp);
64  }
65  }
66  hc = Max(hc, lc+2);
67 
68  visl = DefaultVisual(xid.display, xid.screen);
69  dpth = DefaultDepth (xid.display, xid.screen);
70  dpb = dpth/8;
71  if (dpb==3 && COLOR_DEPTH>=32) dpb = 4;
72 
73  image = (char*)malloc(width*height*dpb);
74  if (image!=NULL) memset(image, 0, width*height*dpb);
75 
76  for(i=0; i<width*height; i++){
77  tmp = *(imagewk + i);
78  if (tmp>hc) tmp = hc;
79  if (tmp<lc) tmp = lc;
80  if (cflg==MONOC) tmp = (int)((double)(tmp-lc)*(nc-1)/(double)(hc-lc));
81  else tmp = (int)(nc-(double)(tmp-lc)*(nc-1)/(double)(hc-lc)-1);
82 
83  col = xid.color_index[tmp];
84  if (dpb>=3) {
85  for (j=0; j<dpb; j++) image[dpb*i+j] = col; // 24,32bit
86  }
87  else { // 16bit
88  pnt = (unsigned short int*)&(image[dpb*i]);
89  *pnt = col;
90  }
91  }
92 
93  pmap = XCreatePixmap(xid.display, xid.window, width, height, dpth);
94  ximg = XCreateImage(xid.display,visl,dpth,ZPixmap,0,(char*)image,width,height,8,0);
95  XPutImage(xid.display, pmap, xid.gc, ximg, 0, 0, 0, 0, width, height);
96  XSetWindowBackgroundPixmap(xid.display, xid.window, pmap);
97  XMapWindow (xid.display, xid.window);
98  XClearWindow(xid.display, xid.window);
99  XFlush(xid.display);
100 
101  xid.id = 1;
102  return xid;
103 }
#define Min(x, y)
Definition: common.h:250
#define Max(x, y)
Definition: common.h:247
short sWord
2Byte
Definition: common.h:335
#define SINTMAX
Definition: common.h:204
openX displayOpen(int xs, int ys, int cflg)
Definition: openX.c:125
#define COLOR_DEPTH
Definition: openX.h:33
#define COLOR_NUM
Definition: openX.h:47
#define MONOC
Definition: openX.h:45
int xs
xサイズ. 4Byte.
Definition: gdata.h:43
sWord * gp
グラフィックデータへのポインタ. xs*ys*zs*2Byte.
Definition: gdata.h:47
int ys
yサイズ. 4Byte.
Definition: gdata.h:44
Definition: openX.h:35
int screen
Definition: openX.h:40
GC gc
Definition: openX.h:39
int id
Definition: openX.h:36
Display * display
Definition: openX.h:37
unsigned long * color_index
Definition: openX.h:41
Window window
Definition: openX.h:38

References COLOR_DEPTH, openX::color_index, COLOR_NUM, openX::display, displayOpen(), openX::gc, WSGraph::gp, openX::id, Max, Min, MONOC, openX::screen, SINTMAX, openX::window, WSGraph::xs, and WSGraph::ys.

Referenced by disp_img().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ displayClose()

void displayClose ( openX  xid)

void displayClose(openX xid)

表示したウィンドウを閉じる.

Parameters
xid閉じたいウィンドウの識別子.

Definition at line 113 of file openX.c.

114 {
115  if (xid.id >= 0) {
116  free(xid.color_index);
117  XFreeGC(xid.display, xid.gc);
118  XDestroyWindow(xid.display, xid.window);
119  XCloseDisplay(xid.display);
120  xid.id = -1;
121  }
122 }

References openX::color_index, openX::display, openX::gc, openX::id, and openX::window.

Referenced by disp_img().

Here is the caller graph for this function:

◆ displayOpen()

openX displayOpen ( int  xs,
int  ys,
int  cflg 
)

Definition at line 125 of file openX.c.

126 {
127  Window root_window;
128  XSizeHints hint;
129  XColor color;
130  Colormap cmap;
131  XSetWindowAttributes at;
132  openX xid;
133 
134  int ir, ig, ib;
135  unsigned long foreground, background;
136  unsigned short values[] = {0x0, 0x4444, 0x8888, 0xcccc, 0xffff};
137 
138  hint.x = 0;
139  hint.y = 0;
140  hint.width = xs;
141  hint.height = ys;
142  hint.flags = PPosition|PSize;
143 
144  xid.display = XOpenDisplay(NULL);
145  root_window = DefaultRootWindow(xid.display);
146 
147  xid.screen = DefaultScreen(xid.display);
148  foreground = WhitePixel(xid.display, xid.screen);
149  background = BlackPixel(xid.display, xid.screen);
150 
151  xid.window = XCreateSimpleWindow(xid.display, root_window, hint.x, hint.y,
152  hint.width, hint.height, 5, foreground, background);
153  XSetStandardProperties(xid.display,xid.window,"openX","openX",None,NULL,0,&hint);
154 
155  xid.gc = XCreateGC(xid.display, xid.window, 0, 0);
156  XSetBackground(xid.display, xid.gc, background);
157  XSetForeground(xid.display, xid.gc, foreground);
158 
159  at.backing_store = WhenMapped;
160  at.bit_gravity = CenterGravity;
161  XChangeWindowAttributes(xid.display, xid.window, CWBackingStore, &at);
162  XChangeWindowAttributes(xid.display, xid.window, CWBitGravity, &at);
163 
164  XSelectInput(xid.display, xid.window, ButtonPressMask|KeyPressMask|ExposureMask);
165  XMapRaised(xid.display, xid.window);
166 
167  cmap = DefaultColormap(xid.display, xid.screen);
168  xid.color_index = (long unsigned int*)malloc(COLOR_NUM*sizeof(long));
169  if (xid.color_index!=NULL) memset(xid.color_index, 0, COLOR_NUM*sizeof(long));
170 
171  for (ir = 0; ir < 5; ir++) {
172  for (ig = 0; ig < 5; ig++) {
173  for (ib = 0; ib < 5; ib++) {
174  if (cflg==MONOC) { // MONO
175  color.red = (int)((ir+5.*ig+ib*25.)/(double)COLOR_NUM*65532.);
176  color.green = color.blue = color.red;
177  }
178  else {
179  color.red = values[ir];
180  color.green = values[ig];
181  color.blue = values[ib];
182  }
183  XAllocColor(xid.display, cmap, &color);
184  xid.color_index[ir+5*ig+25*ib] = color.pixel;
185  }
186  }
187  }
188 
189  xid.id = 0;
190  set_color(xid, 0.0, 0.0, 0.0);
191  return xid;
192 }
void set_color(openX xid, double r, double g, double b)
Definition: openX.c:195

References openX::color_index, COLOR_NUM, openX::display, openX::gc, openX::id, MONOC, openX::screen, set_color(), and openX::window.

Referenced by disp_image().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_color()

void set_color ( openX  xid,
double  r,
double  g,
double  b 
)

Definition at line 195 of file openX.c.

196 {
197  int ir, ig, ib;
198 
199  r = Max(0.0, Min(r, 1.0));
200  g = Max(0.0, Min(g, 1.0));
201  b = Max(0.0, Min(b, 1.0));
202 
203  ir = (int)(4*r + 0.5);
204  ig = (int)(4*g + 0.5);
205  ib = (int)(4*b + 0.5);
206 
207  XSetForeground(xid.display, xid.gc, xid.color_index[ir+5*ig+25*ib]);
208 }

References openX::color_index, openX::display, openX::gc, Max, and Min.

Referenced by displayOpen().

Here is the caller graph for this function: