gLib/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

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 34 of file openX.c.

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().

00035 {
00036     int  i, j, sl, sh;
00037     char *image;
00038     int  nc = COLOR_NUM;
00039     int  width, height, dpth, dpb;
00040     int  tmp, col;
00041     unsigned short int* pnt;
00042 
00043     sWord *imagewk;
00044     XImage  *ximg;
00045     Visual  *visl;
00046     Pixmap  pmap;
00047     openX   xid;
00048 
00049     width   = gd.xs;
00050     height  = gd.ys;
00051     imagewk = gd.gp;
00052 
00053     xid = displayOpen(gd.xs, gd.ys, cflg);
00054 
00055     sl = sh = 1; 
00056     if (hc<=0) sh = -1;
00057     if (lc<0) {
00058         sl = -1;
00059         lc = SINTMAX;
00060     }
00061     if (sl<0 || sh<0) {
00062         for(i=0; i<width*height; i++){
00063             tmp = *(imagewk + i);
00064             if (sl<0) lc = Min(lc, tmp); 
00065             if (sh<0) hc = Max(hc, tmp); 
00066         }
00067     }
00068     hc = Max(hc, lc+2);
00069   
00070     visl = DefaultVisual(xid.display, xid.screen);
00071     dpth = DefaultDepth (xid.display, xid.screen);
00072     dpb  = dpth/8;
00073     if (dpb==3 && COLOR_DEPTH>=32) dpb = 4;
00074 
00075     image = (char*)malloc(width*height*dpb);
00076     for(i=0; i<width*height; i++){
00077         tmp = *(imagewk + i);
00078         if (tmp>hc) tmp = hc;  
00079         if (tmp<lc) tmp = lc;
00080         if (cflg==MONOC) tmp = (int)((double)(tmp-lc)*(nc-1)/(double)(hc-lc));
00081         else             tmp = (int)(nc-(double)(tmp-lc)*(nc-1)/(double)(hc-lc)-1);
00082 
00083         col = xid.color_index[tmp];
00084         if (dpb>=3) {
00085             for (j=0; j<dpb; j++) image[dpb*i+j] = col;     // 24,32bit
00086         }
00087         else {                                              // 16bit
00088             pnt = (unsigned short int*)&(image[dpb*i]);
00089             *pnt = col;
00090         }
00091     }
00092 
00093     pmap = XCreatePixmap(xid.display, xid.window, width, height, dpth);
00094     ximg = XCreateImage(xid.display,visl,dpth,ZPixmap,0,(char*)image,width,height,8,0);
00095     XPutImage(xid.display, pmap, xid.gc, ximg, 0, 0, 0, 0, width, height);
00096     XSetWindowBackgroundPixmap(xid.display, xid.window, pmap);
00097     XMapWindow  (xid.display, xid.window);
00098     XClearWindow(xid.display, xid.window);
00099     XFlush(xid.display);
00100 
00101     xid.id = 1;
00102     return xid;
00103 }

Here is the call graph for this function:

Here is the caller graph for this function:

void displayClose ( openX  xid  ) 

void displayClose(openX xid)

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

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

Definition at line 114 of file openX.c.

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

Referenced by disp_img().

00115 {
00116     if (xid.id >= 0) {
00117         free(xid.color_index);
00118         XFreeGC(xid.display, xid.gc);
00119         XDestroyWindow(xid.display, xid.window);
00120         XCloseDisplay(xid.display);
00121         xid.id = -1;
00122     }
00123 }

Here is the caller graph for this function:

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

Definition at line 127 of file openX.c.

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

Referenced by disp_image().

00128 {
00129     Window     root_window;
00130     XSizeHints hint;
00131     XColor     color;
00132     Colormap   cmap;
00133     XSetWindowAttributes at;
00134     openX xid;
00135 
00136     int  ir, ig, ib;
00137     unsigned long foreground, background;
00138     unsigned short values[] = {0x0, 0x4444, 0x8888, 0xcccc, 0xffff};
00139 
00140     hint.x = 0;
00141     hint.y = 0;
00142     hint.width  = xs;
00143     hint.height = ys;
00144     hint.flags  = PPosition|PSize;
00145 
00146     xid.display = XOpenDisplay(NULL);
00147     root_window = DefaultRootWindow(xid.display);
00148 
00149     xid.screen  = DefaultScreen(xid.display);
00150     foreground  = WhitePixel(xid.display, xid.screen);
00151     background  = BlackPixel(xid.display, xid.screen);
00152 
00153     xid.window  = XCreateSimpleWindow(xid.display, root_window, hint.x, hint.y, 
00154               hint.width, hint.height, 5, foreground, background);
00155     XSetStandardProperties(xid.display,xid.window,"openX","openX",None,NULL,0,&hint);
00156 
00157     xid.gc = XCreateGC(xid.display, xid.window, 0, 0);
00158     XSetBackground(xid.display, xid.gc, background);
00159     XSetForeground(xid.display, xid.gc, foreground);
00160 
00161     at.backing_store = WhenMapped;
00162     at.bit_gravity = CenterGravity;
00163     XChangeWindowAttributes(xid.display, xid.window, CWBackingStore, &at);
00164     XChangeWindowAttributes(xid.display, xid.window, CWBitGravity,   &at);
00165 
00166     XSelectInput(xid.display, xid.window, ButtonPressMask|KeyPressMask|ExposureMask);
00167     XMapRaised(xid.display, xid.window);
00168 
00169     cmap = DefaultColormap(xid.display, xid.screen);
00170     xid.color_index = (long unsigned int*)malloc(COLOR_NUM*sizeof(long));
00171     for (ir = 0; ir < 5; ir++) {
00172         for (ig = 0; ig < 5; ig++) {
00173             for (ib = 0; ib < 5; ib++) {
00174                 if (cflg==MONOC) {  // MONO 
00175                     color.red = (int)((ir+5.*ig+ib*25.)/(double)COLOR_NUM*65532.);
00176                     color.green = color.blue = color.red;
00177                 }
00178                 else {
00179                     color.red   = values[ir];
00180                     color.green = values[ig];
00181                     color.blue  = values[ib];
00182                 }
00183                 XAllocColor(xid.display, cmap, &color);
00184                 xid.color_index[ir+5*ig+25*ib] = color.pixel;
00185             }
00186         }
00187     }
00188  
00189     xid.id = 0;
00190     set_color(xid, 0.0, 0.0, 0.0);
00191     return xid;
00192 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 196 of file openX.c.

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

Referenced by displayOpen().

00197 {
00198     int ir, ig, ib;
00199 
00200     r = Max(0.0, Min(r, 1.0));
00201     g = Max(0.0, Min(g, 1.0));
00202     b = Max(0.0, Min(b, 1.0));
00203 
00204     ir = (int)(4*r + 0.5);
00205     ig = (int)(4*g + 0.5);
00206     ib = (int)(4*b + 0.5);
00207 
00208     XSetForeground(xid.display, xid.gc, xid.color_index[ir+5*ig+25*ib]);
00209 }

Here is the caller graph for this function:


Generated on 15 Nov 2023 for JunkBox_Lib by  doxygen 1.6.1