XForms: SELL ME A CLUE: 16-bit GreyScale into PseudoColor 8-bit

Andre M. Hedrick (hedrick@Astro.Dyer.Vanderbilt.Edu)
Thu, 5 Jun 1997 15:27:28 -0500 (CDT)

To subscribers of the xforms list from "Andre M. Hedrick" <hedrick@Astro.Dyer.Vanderbilt.Edu> :

Greetings Xformers,

Below is parts of a program that is based completely on XForms.
Everything is great, but................

I have this problem with viewing the image nicely.
My CCD camera returns an Intel Raw 16-bit value for each pixel in
the image.

<--- not important info --->
I can prepocess it as the following:

Intel Raw 16-bit == low-byte(unsigned char),high-byte(unsigned char)
Unsigned FITS == high-byte(unsigned char),low-byte(unsigned char)
Signed FITS == high-byte(char),low-byte(char)

I always use the Intel Raw 16-bit for display purposes (a given).
<--- not important info --->

As you can see from below, I use the MSB (the high-byte(unsigned char))
and pass it through a union and add 0xFF to the forth byte of my
unsigned long. Then I write it to screen with the following function:

void DrawPixel(int x, int y, unsigned long pixel);

Where (x,y,pixel) are tied to the MAIN FORM in geometry.

I know there has to be a better way than my hack to do this write to the
form/window/server display. Is there something that I have missed
in the XForms Manual? If not, would you consider adding a function
something like:

unsigned long fl_get_gs_flcolor(unsigned short int gs_val);
--- or ---
unsigned long fl_get_gs_flcolor(FL_COLOR i, unsigned short int gs_val);
--- or ---
unsigned long fl_get_gs_flcolor(FL_COLOR *index, unsigned short int gs_val);

Where the returned (unsigned long) is a scaled 8-bit rgb or assigns
the new FL_COLOR *index or FL_COLOR i to FL_FREE_COL1.

Something like this would be really great for astronomy.

I am a real novice at XWindows programming, and xforms really shortened
the learning curve to XWindows display. Someone help me out in this
problem. I really dread the task of going to raw XWindows programming
just for the sake of a colormap problem.

I can brut force the MAIN FORMS window to be StaticGrey when calling
"xcamera -visual StaticGrey", but that is hell on the eyes and monitor.

I need some simple code that will take an Intel Raw 16-bit
(unsigned short int) and return an 8-bit GreyScale value that will
go nicely into the MAIN FORM window with "xcamera -visual PseudoColor"
being the default display mode.

Has anyone done this?

I know that using a canvas may help, but again I need a CLUE on how to
write a single pixel value to the screen.

Thanks for any help in advance,
Andre Hedrick
Dyer Observatory, Vanderbilt University
hedrick@astro.dyer.vanderbilt.edu

Below is parts of the code that I think are relavent to the question.

/*
* XCamera for Linux at Dyer Observatory
*/

typedef struct
{ FL_FORM *cameraform;
FL_OBJECT *image;
<----cut---->
FL_OBJECT *doexit;
void *vdata;
long ldata;
} FD_cameraform;

FD_cameraform *fdui;
GC imageGC;
XGCValues iValues;
Window window;
Display *display;

char *p;
size_t sizetoallocate;

extern int X_EXTENT = 512; /* size of sensor in x-axis */
extern int Y_EXTENT = 512; /* size of sensor in y-axis */

union { signed char cc[2];
signed short int ii; } k;
union { unsigned char cc[4];
unsigned short int ii[2];
unsigned long ll; } m;

FD_cameraform * create_form_camera(FD_cameraform *fdui)
{ FL_OBJECT *obj;
int old_bw;

fdui = (FD_cameraform *) fl_calloc(1, sizeof(*fdui));
old_bw = fl_get_border_width();
fl_set_border_width(-2);

fdui->cameraform = fl_bgn_form(FL_UP_BOX,800,532);
obj = fl_add_box(FL_DOWN_BOX,5,5,X_EXTENT+10,Y_EXTENT+10,"");
fdui->image = obj = fl_add_box(FL_DOWN_BOX,10,10,X_EXTENT,Y_EXTENT,"");
<----cut---->
fl_end_form();
bExpose = FALSE;
fl_set_border_width(old_bw);
return fdui; }

void DrawPixel(int x, int y, unsigned long pixel)
{ iValues.foreground = pixel;
XChangeGC(display,imageGC,GCForeground,&iValues);
XDrawPoint(display,window,imageGC,(y+10),(x+10)); }

void DoFocus(int mfocus)
{ int kk;
for (kk=0;kk<mfocus;kk++)
{ expotime = Hpc_ExposeTime(hpcfd,expotime);
Hpc_Expose(hpcfd);
Hpc_Raw(hpcfd);
sizetoallocate = Hpc_ImageMalloc(hpcfd);
buf = (char *)realloc(buf,sizetoallocate);
while (buf == NULL)
buf = (char *)realloc(buf,sizetoallocate);
count = sizetoallocate;
Hpc_Read(hpcfd,buf,count);
p = (char *)&buf[0];
for (i=0;i<fysize;i++)
for (j=0;j<fxsize;j++)
{ p++;
m.cc[0] = *p++;
m.cc[1] = m.cc[0];
m.cc[2] = m.cc[0];
m.cc[3] = 0xFF;
DrawPixel(i,j,m.ll); } } }

void main(int argc, char *argv[])
{ FL_OBJECT *obj;
<----cut---->
fl_initialize(&argc, argv, "CameraDisplay", 0, 0);
fdui = create_form_camera(fdui);
<----cut---->
fl_show_form(fdui->cameraform,FL_PLACE_CENTER,FL_FULLBORDER,"XCamera");

window = fl_winget();
display = FL_FormDisplay(fdui->cameraform);
imageGC = XCreateGC(display,fl_state[fl_vmode].trailblazer,0,&iValues);
ClearImageDisplay();

if ((fl_state[fl_get_form_vclass(fdui->cameraform)].depth) != 8)
{ fl_show_form(errorform,FL_PLACE_CENTER,FL_TRANSIENT,"ERROR_Dialog");
while (fl_do_forms() != errorreturn);
fl_hide_form(errorform);
goto deptherror; }
<----cut---->
while (fl_do_forms() != fdui->doexit);
<----cut---->
XFreeGC(display,imageGC);
fl_hide_form(fdui->cameraform);
<----cut---->
exit(0);
}

_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/