home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / sci / image / processi / 1689 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.7 KB  |  55 lines

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jhunix.hcf.jhu.edu!fmsrl7!destroyer!gatech!swrinde!network.ucsd.edu!pitstop.ucsd.edu!spl
  2. From: spl@pitstop.ucsd.edu (Steve Lamont)
  3. Newsgroups: sci.image.processing
  4. Subject: Re: conversion to xv formats
  5. Date: 22 Jan 1993 22:17:40 GMT
  6. Organization: University of Calif., San Diego/Microscopy and Imaging Resource
  7. Lines: 43
  8. Message-ID: <1jprq4INN320@network.ucsd.edu>
  9. References: <1993Jan22.184317.1411@igor.tamri.com>
  10. NNTP-Posting-Host: pitstop.ucsd.edu
  11.  
  12. In article <1993Jan22.184317.1411@igor.tamri.com> ilya@igor.tamri.com (Ilya Simovsky) writes:
  13. >Dear gurus:
  14. >Could anybody, please, advise me where I can find a program for UNIX to convert
  15. >a 16 bit binary grayscale image (i.e a file with say 256*256 short int) to one
  16. >of the following formats : GIF, JPEG, TIFF, PBM, PGM, PPM, X11 bitmap, Utah Raster Toolkit RLE, PDS/VICAR, Sun Rasterfile, PM.
  17.  
  18. #include <stdio.h>
  19.  
  20. /*
  21.  * Raw 16 bit to pgm "translator"
  22.  * Copyright abandoned.
  23.  */
  24.  
  25. main()
  26.  
  27. {
  28.  
  29.     short int inbuffer[256 * 256];
  30.     char outbuffer[256 * 256];
  31.     int i;
  32.  
  33.     fread( inbuffer, sizeof( short int ), 256 * 256, stdin );
  34.  
  35.     for ( i = 0; i < 256 * 256; i++ )
  36.     outbuffer[i] = inbuffer[i] >> 8;
  37.  
  38.     printf( "P5\n256 256\n255\n" );
  39.     fwrite( outbuffer, sizeof( char ), 256 * 256, stdout );
  40.  
  41.     exit( 0 );
  42.  
  43. }
  44.  
  45. Error checking and enhancements are left as an exercise for the student.
  46.  
  47. I mean, it ain't that difficult...
  48.  
  49.                             spl
  50. -- 
  51. Steve Lamont, SciViGuy -- (619) 534-7968 -- spl@szechuan.ucsd.edu
  52. UCSD Microscopy and Imaging Resource/UCSD Med School/La Jolla, CA 92093-0608
  53. "The English are drinking the better beer in Bavaria."
  54.             - Archibald Macleish, "Lines for an Interment"
  55.