Re: XForms: Display 24 bit images

Luis IBANEZ (luisiban@club-internet.fr)
Sat, 23 May 1998 07:42:01 +0200

# To subscribers of the xforms list from Luis IBANEZ <luisiban@club-internet.fr> :

This is a multi-part message in MIME format.
--------------642528DCA576C604BB2A79FC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I'm using the canvas to display images in PC/linux and Silicon Graphics.

I have write independents routines for each visual:

Pseudocolor 8 bits
Truecolor 15 bits
Truecolor 16 bits
Truecolor 24 bits (under linux -> XFree86 -> SVGA server)
Truecolor 24 bits (under SGI)

SGI reports 24 bits but uses internal representation with 32 bits
where only the three last bytes contains data,
(maybe a padding optimization..?)

bytes are ordered as : 0BGR

so in your XCreateImage call, the las parameter
should be: 4*nx instead of 3*nx.

the 2/3 image aspect is infact a 3/4 aspect.

Visual parameters are taken from "fl_state" structure of XForms.

I'm attaching the code for initialization and for display in 24 bits
SGI.
I hope this help.

--

________________________________________________________________

Luis Eduardo IBANEZ

PhD Student Departement Image et Traitement de l'Information Ecole Nationale Superieure des Telecommunications de Bretagne Technopole de Brest-Iroise BP 832, 29285 BREST - FRANCE

tel (33)2.98.00.13.57 fax (33)2.98.00.10.98 e-mail: luis.ibanez@enst-bretagne.fr e-mail: luisiban@club-internet.fr

________________________________________________________________

--------------642528DCA576C604BB2A79FC Content-Type: text/plain; charset=us-ascii; name="InitAndDisplay.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="InitAndDisplay.cpp"

//-------------------------------------------------------- // // Create image with a particular visual // //-------------------------------------------------------- void wimage::createXImage(int nx, int ny) {

// Note: in SGI 24 bits uses 4 bytes const int Size = 4; char *data = new char[nx*ny*Size];

int offset = 0; if(!data ) { fl_show_alert("Error","wimage::createXImage",\ "Memory allocation",1); return; }

// Clear image mem buffer for(int i=0; i<nx*ny*Size; i++) data[i] = 0; Ximage = XCreateImage(fl_get_display(),\ fl_state[getVisual()].xvinfo->visual,\ fl_state[getVisual()].depth,ZPixmap,\ offset,(char *)data,nx,ny,BitmapPad,\ Size*nx);

if( !Ximage ) { fl_show_alert("Error","wimage::createXImage",\ "XCreateImage",1); } }

//-------------------------------------------------------- // // Display image // //--------------------------------------------------------

int wimage::redraw(void) const {

XPutImage(fl_get_display(),\ FL_ObjWin(image),\ *(fl_state[getVisual()].gc),\ Ximage,0,0,0,0,\ Ximage->width,\ Ximage->height); return 1;

}

//-------------------------------------------------------- // // Copy data to XImage structure // //--------------------------------------------------------

int wimageTrueColor24b::display( \ const unsigned char *red,\ const unsigned char *green,\ const unsigned char *blue, \ int mx, int my,int esc) { if( !red || !green || !blue || !mx || !my || !esc ) return 0; if( mx*esc != Ximage->width || my*esc != Ximage->height ) { resize(mx*esc,my*esc); } unsigned char *dst = (unsigned char *)(Ximage->data); // There are two additional loops to scale image // by an integer factor (esc). If it is not needed // a bit of speed can be obtained by removing this.

for(int y=0; y<my; y++) { for(int ey=0; ey<esc; ey++){ for(int x=0; x<mx; x++) { for(int ex=0; ex<esc; ex++) { *dst++ = 0; *dst++ = *blue; *dst++ = *green; *dst++ = *red; } blue++; green++; red++; } blue -= mx; green -= mx; red -= mx; } blue += mx; green += mx; red += mx; }

// visible() function test visibility of // canvas, with fl_form_is_visible() function // (important because a non-visible canvas // has no "window id" code to use in XPutImage...) if( !visible() ) return 0;

XPutImage(fl_get_display(),\ FL_ObjWin(image),\ *(fl_state[getVisual()].gc),\ Ximage,0,0,0,0,mx*esc,my*esc); return 1;

}

--------------642528DCA576C604BB2A79FC--

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