home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!elroy.jpl.nasa.gov!news.claremont.edu!ucivax!noiro.acs.uci.edu!network.ucsd.edu!ucsbcsl!ucsbuxa!6500mack
- From: 6500mack@ucsbuxa.ucsb.edu (Michael P. Mack)
- Newsgroups: comp.windows.x
- Subject: Re: need help with images
- Message-ID: <5480@ucsbcsl.ucsb.edu>
- Date: 16 Aug 92 00:43:04 GMT
- References: <BsILsB.E3D@wpi.WPI.EDU>
- Sender: root@ucsbcsl.ucsb.edu
- Lines: 32
-
- In article <BsILsB.E3D@wpi.WPI.EDU> danielg@oconnor.WPI.EDU (Daniel Matthew Gaines) writes:
-
- >i've got a greayscale image made up of 16 bit pixels that i want
- >to convert to an XImage. the problem is that when i go
- >to XPutImage i have a drawable of 8 bits (i am not able to
- >get a depth of 16) so when i do the XCreateImage i try
- >using 8 for a depth but, as expected, the image is trashed when it appears.
-
- You will need to rescale your image data so that each value is in
- the range 0..255 (ie 8 bits) and convert to unsigned char.
- A simple way is to just remove the lower byte of each pixel value, but if
- the result is lousy (because of poor contrast) then you could try an approach
- like this:
-
- int min,max;
- float scale;
-
- max = findmax(shortImageData,n);
- min = findmin(shortImageData,n);
- scale = (float)(255.9/(max-min));
- for (i=0; i<n; i++)
- ucharImageData[i] = (unsigned char)(scale*(shortImageData[i]-min));
-
- Then call XCreateImage with ucharImageData as the image data.
-
- You probably won't notice any degradation due to the compression since the
- human eye can distinguish only roughly 40 grey levels anyway.
-
-
- Mike Mack
- 6500mack@ucsbuxa.ucsb.edu
-
-