home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / windows / x / 15283 < prev    next >
Encoding:
Internet Message Format  |  1992-08-15  |  1.5 KB

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