home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / image / part03 < prev    next >
Encoding:
Internet Message Format  |  1986-11-30  |  45.8 KB

  1. Subject:  v07i066:  Image manipulation routines in C++, Part03/05
  2. Newsgroups: mod.sources
  3. Approved: mirror!rs
  4.  
  5. Submitted by: David Sher <seismo!rochester!sher>
  6. Mod.sources: Volume 7, Issue 66
  7. Archive-name: image/Part03
  8.  
  9.  
  10. [  The Makefiles had ESCAPE and \r characters in their comment lines;
  11.    I changed them to their printable representation, the two-character
  12.    sequences ^[ and ^M, respectively.  Also, the file ascii2var/uu.test.var
  13.    had some non-ASCII characters in it; I used uuencode; the resultant
  14.    file is really ascii2var/test.var.  Also, I do not have C++ nor any
  15.    images, so I have not tested this package.  --r$  ]
  16.  
  17. #!/bin/sh
  18. # This is a shell archive.  Remove anything before this line,
  19. # then unpack it by saving it in a file and typing "sh file".
  20. # If all goes well, you will see the message "No problems found."
  21. # Wrapped by mirror!rs on Mon Nov 10 13:43:02 EST 1986
  22.  
  23. # Exit status; set to 1 on "wc" errors or if would overwrite.
  24. STATUS=0
  25. # Contents:  varc++/double_image.h++ varc++/for.h++
  26. #    varc++/iff_image.h++ varc++/iff_local.h++ varc++/iff_stdim.h++
  27. #    varc++/image.h++ varc++/long_image.h++ varc++/makefile
  28. #    varc++/var.h++ varc++/var_double_image.c++ varc++/var_image.c++
  29. #    varc++/var_long_image.c++ vartools/README vartools/var2ascii.c++
  30. #    vartools/ascii2var.c++
  31.  
  32. echo x - varc++/double_image.h++
  33. if test -f varc++/double_image.h++ ; then
  34.     echo varc++/double_image.h++ exists, putting output in $$varc++/double_image.h++
  35.     OUT=$$varc++/double_image.h++
  36.     STATUS=1
  37. else
  38.     OUT=varc++/double_image.h++
  39. fi
  40. sed 's/^X//' > $OUT <<'@//E*O*F varc++/double_image.h++//'
  41. X/*
  42. X    This file contains the definitions necessary to define an
  43. X    image whose data is 8-bit
  44. X*/
  45.  
  46. X#ifndef DOUBLE_IMAGE_H
  47. X#define DOUBLE_IMAGE_H
  48. X/* include the support for image data types */
  49. X#include <image.h++>
  50.  
  51. X/*
  52. X    the definition of the class to manage image structures
  53. X*/
  54. Xclass double_image : image_class
  55. X    {
  56. X    double *image_buffer;    // buffer to hold image
  57. X    double **image_rows;    // pointers to the rows of the image
  58. X    double **window_rows;    // pointers to the rows of the window
  59. X    /* functions for function pointers */
  60.  
  61. X    /* this version of next assumes the window has been initialized */
  62. X    int initialized_next ();
  63.  
  64. X    /* this version of prev assumes the window has been initialized */
  65. X    int initialized_prev ();
  66.  
  67. X    /* this version of next initializes the window */
  68. X    int uninitialized_next ();
  69.  
  70. X    /* this version of prev initializes the window */
  71. X    int uninitialized_prev ();
  72.  
  73. X    /* this version of next says that the operation is impossible */
  74. X    int impossible_next ();
  75.  
  76. X    /* this version of prev says that the operation is impossible */
  77. X    int impossible_prev ();
  78.  
  79. X    /* uninitialized version of get_w_e will just die */
  80. X    double uninitialized_get_w_e ( const card i , const card j );
  81.  
  82. X    /* initialized version of get_w_e */
  83. X    double initialized_get_w_e ( const card i , const card j );
  84.  
  85. X    /* uninitialized version of write_w_e will just die */
  86. X    void uninitialized_write_w_e ( const card i , const card j , const double value );
  87.  
  88. X    /* initialized version of write_w_e */
  89. X    void initialized_write_w_e ( const card i , const card j , const double value );
  90.  
  91. X    /*
  92. X    the function to write to the specified element of a window.
  93. X    it is a function pointer so that unitialized windows
  94. X    or protected images don't get read from
  95. X    */
  96. X    double (* get_w_e_pointer )( const card i , const card j  );
  97.  
  98. X    /*
  99. X    the function to write to the specified element of a window.
  100. X    it is a function pointer so that unitialized windows
  101. X    or protected images don't get read from
  102. X    can not check argument because it will point to internal
  103. X    elements
  104. X    */
  105. X    void (* write_w_e_pointer )( const card i , const card j , const double value  );
  106.  
  107. Xpublic:
  108. X    /* constructors */
  109. X    /* the constructor when the image is being read from a file */
  110. X    double_image
  111. X    ( 
  112. X    const read_image_type rit ,     // marker that the image is being read
  113. X    const FILE * image_file ,    // file for image
  114. X    const card w_width = 1 ,    // window width
  115. X    const card w_length = 1        // window length
  116. X    );
  117.  
  118. X    /* the constructor when the image is built */
  119. X    double_image
  120. X    ( 
  121. X    const create_image_type cit ,    // marker that the image is being created
  122. X    const card n_rows ,         // the number of rows in the image
  123. X    const card n_cols ,         // the number of collumns in the image
  124. X    const FILE * image_file ,    // file for image
  125. X    const card w_width = 1 ,    // window width
  126. X    const card w_length = 1     // window length
  127. X    );
  128.  
  129. X    /* destructor (who would want to destroy an image?) */
  130. X    ~double_image ( ) { ; }
  131.  
  132. X    /* access routines for parts of data structure */
  133. X    const card n_rows() { return number_rows ; }
  134. X    const card n_cols() { return number_cols ; }
  135. X    const image_prot the_prot() { return prot; }
  136. X    const card c_length() { return comment_length ; }
  137. X    const char *the_comments() { return comments ; }
  138. X    const card the_collumn() { return collumn ; }
  139. X    const card the_row() { return row ; }
  140. X    const card the_width() { return window_width ; }
  141. X    const card the_length() { return window_length ; }
  142. X    const FILE * the_file() { return file ; }
  143. X    const status image_init() { return image_status ; }
  144. X    const status window_init() { return window_status ; }
  145.  
  146. X    /* access a pointer to a particular row */
  147. X    const double * get_row( card row );
  148.  
  149. X    /* sets the comments */
  150. X    void set_comments( char * string , const card length )
  151. X    {
  152. X    this->image_class::set_comments ( string , length );
  153. X    }
  154.  
  155. X    /* adds a string to the comments */
  156. X    void add_comment( char * string , const card length )
  157. X    {
  158. X    this->image_class::add_comment ( string , length );
  159. X    }
  160.  
  161.  
  162. X    /* real versions of virtual functions */
  163. X    /* routine to write out the image to a file */
  164. X    void write ( ) ;
  165.  
  166. X    /*
  167. X    move in row n steps 
  168. X    returns 1 when that motion is legal 0 otherwise
  169. X    */
  170. X    int move_collumn ( const int n ) ;
  171.  
  172. X    /*
  173. X    move in collumn n steps
  174. X    returns 1 when that motion is legal 0 otherwise
  175. X    */
  176. X    int move_row ( const int n ) ;
  177.  
  178. X    /*
  179. X    move to specified row
  180. X    */
  181. X    void move_to_row ( const card n ) ;
  182.  
  183. X    /*
  184. X    move to specified collumn
  185. X    */
  186. X    void move_to_collumn ( const card n ) ;
  187.  
  188. X    
  189. X    /*
  190. X    the function to get the specified element of a window
  191. X    it is a function pointer so that unitialized windows
  192. X    or protected images don't get read from
  193. X    this accesses the function pointer
  194. X    */
  195. X    double get_w_e ( const card i , const card j )
  196. X    { return (( double (*) (...) )(* get_w_e_pointer)) ( this , i , j ); }
  197.  
  198. X    /*
  199. X    the fast function without checking for initialization
  200. X    of a function pointer for getting elements of a window
  201. X    Also no bounds checking!
  202. X    ( Not recommended!)
  203. X    */
  204. X    double fast_g_w_e ( const card i , const card j )
  205. X    { return window_rows[i][j]; }
  206. X    
  207. X    /*
  208. X    the function to write to the specified element of a window.
  209. X    it is a function pointer so that unitialized windows
  210. X    or protected images don't get read from
  211. X    this accesses the function pointer
  212. X    */
  213. X    void write_w_e ( const card i , const card j , const double value )
  214. X    { ((void (*) (...) )(* write_w_e_pointer)) ( this , i , j , value ); }
  215.  
  216. X    /*
  217. X    the fast function without checking for initialization
  218. X    of a function pointer for writing elements to a window
  219. X    Also no bounds checking!
  220. X    ( Not recommended!)
  221. X    */
  222. X    void fast_w_w_e ( const card i , const card j , const double value )
  223. X    { window_rows[i][j] = value; }
  224.  
  225. X    /* 
  226. X    the function call on the image gets the upper left hand 
  227. X    of the image window and returns a reference so it can be
  228. X    used as a lvalue or rvalue
  229. X    optimized so does not check that the window is initialized
  230. X    if the window is not initialized then odd things may happen
  231. X    */
  232. X    double& operator() ()
  233. X    { return **window_rows; }
  234. X    
  235. X    /* 
  236. X    move to next legal position in image
  237. X    returns 1 when there is a next legal position 0 otherwise
  238. X    if the window is not initialized then it initializes it.
  239. X    with the window in the position 0,0 (if possible)
  240. X    */
  241. X    int (* next) (...); /* this will point to member functions! */
  242.  
  243. X    /* 
  244. X    move to previous legal position in image
  245. X    returns 1 when there is a previous legal position 0 otherwise
  246. X    if the window is not initialized then it initializes it.
  247. X    with the window in the farthest position (if possible)
  248. X    */
  249. X    int (* prev) (...); /* this will point to member functions! */
  250.  
  251. X    /*
  252. X    Access for next and previous elements of images
  253. X    */
  254. X    int operator++ ( ) 
  255. X    { return (* next) ( this /* because points to member*/ ); }
  256. X    int operator-- ( ) 
  257. X    { return (* prev) ( this /* because points to member*/ ); }
  258.  
  259. X    /*
  260. X    Change the size of a window
  261. X    causes the window to become uninitialized
  262. X    */
  263. X    void resize_window ( card width , card length );
  264.  
  265. X    /*
  266. X    Causes the window to cover the entire image.
  267. X    Allows one to access any part of the image with window operations
  268. X    */
  269. X    void window_entire_image ( );
  270.  
  271. X    };
  272.  
  273. X#endif DOUBLE_IMAGE_H
  274. X/*
  275. XCopyright (C) 1986, David Sher in the University of Rochester
  276. XPermission is granted to any individual or institution to use, copy, or
  277. Xredistribute this software so long as it is not sold for profit, provided
  278. Xthis copyright notice is retained.
  279. X*/
  280. @//E*O*F varc++/double_image.h++//
  281. chmod u=rw,g=r,o=r $OUT
  282.  
  283. echo x - varc++/for.h++
  284. if test -f varc++/for.h++ ; then
  285.     echo varc++/for.h++ exists, putting output in $$varc++/for.h++
  286.     OUT=$$varc++/for.h++
  287.     STATUS=1
  288. else
  289.     OUT=varc++/for.h++
  290. fi
  291. sed 's/^X//' > $OUT <<'@//E*O*F varc++/for.h++//'
  292. X/* prevents repeated reading of file */
  293. X#ifndef FOR_H
  294. X#define FOR_H 1
  295. X/* 
  296. X    this is to define true powerful iterators for for loops
  297. X*/
  298. X#define FOR { for /* so for loop is inside a block */
  299. X#define ENDFOR } /* terminate block */
  300. X#endif FOR_H
  301. X/*
  302. XCopyright (C) 1986, David Sher in the University of Rochester
  303. XPermission is granted to any individual or institution to use, copy, or
  304. Xredistribute this software so long as it is not sold for profit, provided
  305. Xthis copyright notice is retained.
  306. X*/
  307. @//E*O*F varc++/for.h++//
  308. chmod u=rw,g=r,o=r $OUT
  309.  
  310. echo x - varc++/iff_image.h++
  311. if test -f varc++/iff_image.h++ ; then
  312.     echo varc++/iff_image.h++ exists, putting output in $$varc++/iff_image.h++
  313.     OUT=$$varc++/iff_image.h++
  314.     STATUS=1
  315. else
  316.     OUT=varc++/iff_image.h++
  317. fi
  318. sed 's/^X//' > $OUT <<'@//E*O*F varc++/iff_image.h++//'
  319. X# include  "iff_stdim.h++"
  320. X# include "iff_local.h++"
  321. X/*
  322. XCopyright (C) 1986, David Sher in the University of Rochester
  323. XPermission is granted to any individual or institution to use, copy, or
  324. Xredistribute this software so long as it is not sold for profit, provided
  325. Xthis copyright notice is retained.
  326. X*/
  327. @//E*O*F varc++/iff_image.h++//
  328. chmod u=rw,g=r,o=r $OUT
  329.  
  330. echo x - varc++/iff_local.h++
  331. if test -f varc++/iff_local.h++ ; then
  332.     echo varc++/iff_local.h++ exists, putting output in $$varc++/iff_local.h++
  333.     OUT=$$varc++/iff_local.h++
  334.     STATUS=1
  335. else
  336.     OUT=varc++/iff_local.h++
  337. fi
  338. sed 's/^X//' > $OUT <<'@//E*O*F varc++/iff_local.h++//'
  339. X/* 
  340. Xlocal.h
  341. Xdefinitions local to UR
  342.  
  343. XM. Swain 
  344. XUniversity of Rochester
  345. X8-JAN-86
  346. X*/
  347.  
  348. X# define TRUE    1
  349. X# define FALSE    0
  350.  
  351. X# define IN        0
  352. X# define OUT    1
  353.  
  354. X# define MAXFNAMELEN    30
  355. Xstatic char prog_name [ MAXFNAMELEN    ] ;
  356.  
  357. X# define MAX(a,b) ((a) > (b) ? (a) : (b))
  358. X# define MIN(a,b) ((a) < (b) ? (a) : (b))
  359. X# define ABS(a) ((a) > 0 ? (a) : -(a))
  360.  
  361. X# define getimage(ifp,annote,im) { getheader(ifp,annote);\
  362. X  im = (long *) malloc (ifp->nrows * ifp->ncols * sizeof (long));\
  363. X  getimg (ifp, im); }
  364. X/*
  365. XCopyright (C) 1986, David Sher in the University of Rochester
  366. XPermission is granted to any individual or institution to use, copy, or
  367. Xredistribute this software so long as it is not sold for profit, provided
  368. Xthis copyright notice is retained.
  369. X*/
  370. @//E*O*F varc++/iff_local.h++//
  371. chmod u=rw,g=r,o=r $OUT
  372.  
  373. echo x - varc++/iff_stdim.h++
  374. if test -f varc++/iff_stdim.h++ ; then
  375.     echo varc++/iff_stdim.h++ exists, putting output in $$varc++/iff_stdim.h++
  376.     OUT=$$varc++/iff_stdim.h++
  377.     STATUS=1
  378. else
  379.     OUT=varc++/iff_stdim.h++
  380. fi
  381. sed 's/^X//' > $OUT <<'@//E*O*F varc++/iff_stdim.h++//'
  382. X/* file: image.h  */
  383.  
  384. X/* iff: Standard image file format                    */
  385.  
  386. X/* (c) Copyright 1982,
  387. X   William S. Havens
  388. X   Laboratory for Computational Vision
  389. X   University of British Columbia
  390.  
  391. X   Adapted from image files developed by Randy Schulz at 
  392. X    the University of Wisconsin-Madison
  393. X   Differences:
  394. X    1) Uses bit-stream I/O allowing random access of arbitrary size pixels.
  395. X    2) Pixels may range in size from 0 to sizeof(long) = 32-bits.
  396. X    3) Signed/unsigned images are supported.
  397. X    4) Positive/negative images are supported.
  398. X    5) Extensible user-defined parameter space is defined.
  399. X*/
  400.  
  401. X#include  "bitio.h++"
  402.  
  403.  
  404. X/* Image file definitions                        */
  405.  
  406. X#define IMAGIC    "Imagefile"    /* Magic number for image files        */
  407. X#define    IMVERSION 2        /* iff version number            */
  408. X#define    IMBPP     8        /* Default number of bits per pixel    */
  409. X#define IMSIGNED  0        /* Default image is unsigned        */
  410. X#define    IMPOSTVE  1        /* Default image is positive encoded    */
  411. X#define    IMNPARMS  6        /* # of image parameters in header    */
  412.  
  413. X#define IMBLKSZE BBLKSZE    /* Use block size of bitio file        */
  414. X#define IMHDRSZE 1024        /* Physical header size in file        */
  415.  
  416. Xstruct image 
  417. X       {
  418. X    struct iff_bfile    *bfile;        /* bitio file pointer            */
  419. X    long    nrows;        /* Number of rows in image        */
  420. X    long    ncols;        /* Number of columns in image        */
  421. X    short    bpp;        /* Bits per pixel            */
  422. X    short    is_signed;    /* Signed / Unsigned image        */
  423. X    short    positive;    /* Positive / Negative image        */
  424. X    short    hdroffset;    /* Header offset in file in bits    */
  425. X  } ;
  426.  
  427.  
  428. Xstruct image *iopen(...), *idopen(...);
  429.  
  430. X/* Image header format    */
  431. X#define IMHDRFMT  "Imagefile version-%d: nrows = %D ncols = %D bpp = %hd signed = %hd positive = %hd\n"
  432.  
  433.  
  434. X/* Macros */
  435.  
  436. X#define getpix(ifp)        bget ((ifp)->bfile, (ifp)->bpp, (ifp)->is_signed)
  437. X#define putpix(ifp,pixel)    bput ((ifp)->bfile, pixel, (ifp)->bpp)
  438. X#define isync(ifp)        bsync ((ifp)->bfile)
  439. X#define iseek(ifp,row,col)    bseek ((ifp)->bfile, (long)((((ifp)->ncols*(row))+(col))*((ifp)->bpp)+(ifp)->hdroffset), 0)
  440. X#define ierror(ifp)        berror ((ifp)->bfile)
  441. X#define ieof(ifp)        beof ((ifp)->bfile)
  442.  
  443. X/* end of file image.h */
  444. X/*
  445. XCopyright (C) 1986, David Sher in the University of Rochester
  446. XPermission is granted to any individual or institution to use, copy, or
  447. Xredistribute this software so long as it is not sold for profit, provided
  448. Xthis copyright notice is retained.
  449. X*/
  450. @//E*O*F varc++/iff_stdim.h++//
  451. chmod u=rw,g=r,o=r $OUT
  452.  
  453. echo x - varc++/image.h++
  454. if test -f varc++/image.h++ ; then
  455.     echo varc++/image.h++ exists, putting output in $$varc++/image.h++
  456.     OUT=$$varc++/image.h++
  457.     STATUS=1
  458. else
  459.     OUT=varc++/image.h++
  460. fi
  461. sed 's/^X//' > $OUT <<'@//E*O*F varc++/image.h++//'
  462. X#ifndef IMAGE_H
  463. X#define IMAGE_H
  464. X/*
  465. X    This file contains the definitions for 
  466. X    the generic stuff for handling images
  467. X*/
  468.  
  469. X/* 
  470. X    define cardinal as integer 
  471. X    (later I might want to implement a type of integer that does
  472. X    bounds checking)
  473. X*/
  474. Xtypedef int card;
  475.  
  476. X/* tolerance for equality in floating point */
  477. Xstatic const double EPSILON = 0.0000001;    
  478.  
  479.  
  480. X/*
  481. X    Infinite loop (real useful)
  482. X*/
  483. X#define LOOP for(;;)
  484.  
  485. X/*
  486. X    define some constants for unbuffered io
  487. X*/
  488. Xstatic const int inputd = 0;
  489. Xstatic const int outputd = 1;
  490. Xstatic const int errord = 2;
  491.  
  492. X/*
  493. X    define some system routines
  494. X*/
  495. Xint read ( int fd , void * buffer , int size );
  496. Xint write ( int fd , void * buffer , int size );
  497.  
  498.  
  499. X/*
  500. X    The operations that can be applied when creating the window.
  501. X    one can read in an image or create one.
  502. X*/
  503. Xenum create_image_type { CREATE = 7 };
  504. Xenum read_image_type { READ = 4 };
  505.  
  506.  
  507. X/* protection for images */
  508. Xenum image_prot 
  509. X    { 
  510. X    CAN_READ = 1 , 
  511. X    CAN_WRITE = 2 , 
  512. X    CAN_READ_AND_WRITE = 3 ,
  513. X    CAN_NOT_DO_ANYTHING = 4
  514. X    };
  515.  
  516. X/*
  517. X    useful for determining the status of data structures
  518. X*/
  519. Xenum status { INITIALIZED = 8 , UNINITIALIZED = 16 };
  520.  
  521. X/*
  522. X    This is the abstract data type for any image
  523. X    Actually objects of this type are not useful
  524. X    it is meant to have derived types
  525. X*/
  526. Xclass image_class
  527. X    {
  528. Xpublic:
  529. X    card number_rows;        // number rows in image
  530. X    card number_cols;        // number of collumns in image
  531. X    void * header_info ;    // any further header information required by implementation
  532. X    image_prot prot;        // the protection of the image 
  533. X    card comment_length;    // the length of the comments
  534. X    char * comments ;        // comments about the image
  535. X    status image_status;    // determines when image data is initialized
  536.  
  537. X    /* position in image */
  538. X    status window_status;    // determines when the window has been initialized
  539. X    card collumn;        // the collumn
  540. X    card row;            // the row
  541. X    card window_width;        // width of possible window in image
  542. X    card window_length;        // length of possible window in image
  543. X    FILE * file;        // file associated with image
  544.  
  545. X    /* constructors for images */
  546. X    /* constructor when reading an image from a file */
  547. X    image_class
  548. X    ( 
  549. X    const read_image_type rit ,     // marker that the image is being read
  550. X    const FILE * image_file ,    // file for image
  551. X    const card w_width  ,    // window width
  552. X    const card w_length     // window length
  553. X    );
  554.  
  555. X    /* constructor for creating a new image */
  556. X    image_class
  557. X    ( 
  558. X    const create_image_type cit,    // maker that the image is being created
  559. X    const FILE * image_file ,     // the file for the image
  560. X    const card n_rows ,         // the number of rows in the image
  561. X    const card n_cols ,         // the number of collumns in the image
  562. X    const card w_width ,         // the width of the window
  563. X    const card w_length         // the length of the window
  564. X    );
  565.  
  566. X    /* destructor for images */
  567. X    ~image_class () { ; }
  568.  
  569. X    /* comment manipulation */
  570.  
  571. X    /* sets the comments */
  572. X    void set_comments( char * string , const card length );
  573.  
  574. X    /* adds a string to the comments */
  575. X    void add_comment( char * string , const card length );
  576.  
  577. X    /* for moving around in an image */
  578.  
  579.  
  580. X    /*
  581. X    move in row n steps 
  582. X    returns 1 when that motion is legal 0 otherwise
  583. X    */
  584. X    virtual int move_collumn ( const int n ) ;
  585.  
  586. X    /*
  587. X    move in collumn n steps
  588. X    returns 1 when that motion is legal 0 otherwise
  589. X    */
  590. X    virtual int move_row ( const int n ) ;
  591.  
  592. X    /*
  593. X    move to specified row
  594. X    */
  595. X    virtual void move_to_row ( const card n ) ;
  596.  
  597. X    /*
  598. X    move to specified collumn
  599. X    */
  600. X    virtual void move_to_collumn ( const card n ) ;
  601.  
  602. X    /* routine to write out the image to a file */
  603. X    virtual void write ( ) ;
  604.  
  605. X    /* change the protection from CAN_WRITE to CAN_READ_AND_WRITE */
  606. X    virtual void read_and_write ( );
  607.  
  608. X    };
  609.  
  610. X/* returns a null terminated string for comments */
  611. Xconst char * comment_string ( image_class& i );
  612.  
  613.  
  614. X#endif IMAGE_H
  615. X/*
  616. XCopyright (C) 1986, David Sher in the University of Rochester
  617. XPermission is granted to any individual or institution to use, copy, or
  618. Xredistribute this software so long as it is not sold for profit, provided
  619. Xthis copyright notice is retained.
  620. X*/
  621. @//E*O*F varc++/image.h++//
  622. chmod u=rw,g=r,o=r $OUT
  623.  
  624. echo x - varc++/long_image.h++
  625. if test -f varc++/long_image.h++ ; then
  626.     echo varc++/long_image.h++ exists, putting output in $$varc++/long_image.h++
  627.     OUT=$$varc++/long_image.h++
  628.     STATUS=1
  629. else
  630.     OUT=varc++/long_image.h++
  631. fi
  632. sed 's/^X//' > $OUT <<'@//E*O*F varc++/long_image.h++//'
  633. X/*
  634. X    This file contains the definitions necessary to define an
  635. X    image whose data is 8-bit
  636. X*/
  637.  
  638. X#ifndef LONG_IMAGE_H
  639. X#define LONG_IMAGE_H
  640. X/* include the support for image data types */
  641. X#include <image.h++>
  642.  
  643. X/*
  644. X    the definition of the class to manage image structures
  645. X*/
  646. Xclass long_image : image_class
  647. X    {
  648. X    long *image_buffer;    // buffer to hold image
  649. X    long **image_rows;    // pointers to the rows of the image
  650. X    long **window_rows;    // pointers to the rows of the window
  651. X    /* functions for function pointers */
  652.  
  653. X    /* this version of next assumes the window has been initialized */
  654. X    int initialized_next ();
  655.  
  656. X    /* this version of prev assumes the window has been initialized */
  657. X    int initialized_prev ();
  658.  
  659. X    /* this version of next initializes the window */
  660. X    int uninitialized_next ();
  661.  
  662. X    /* this version of prev initializes the window */
  663. X    int uninitialized_prev ();
  664.  
  665. X    /* this version of next says that the operation is impossible */
  666. X    int impossible_next ();
  667.  
  668. X    /* this version of prev says that the operation is impossible */
  669. X    int impossible_prev ();
  670.  
  671. X    /* uninitialized version of get_w_e will just die */
  672. X    long uninitialized_get_w_e ( const card i , const card j );
  673.  
  674. X    /* initialized version of get_w_e */
  675. X    long initialized_get_w_e ( const card i , const card j );
  676.  
  677. X    /* uninitialized version of write_w_e will just die */
  678. X    void uninitialized_write_w_e ( const card i , const card j , const long value );
  679.  
  680. X    /* initialized version of write_w_e */
  681. X    void initialized_write_w_e ( const card i , const card j , const long value );
  682.  
  683. X    /*
  684. X    the function to write to the specified element of a window.
  685. X    it is a function pointer so that unitialized windows
  686. X    or protected images don't get read from
  687. X    */
  688. X    long (* get_w_e_pointer )( const card i , const card j  );
  689.  
  690. X    /*
  691. X    the function to write to the specified element of a window.
  692. X    it is a function pointer so that unitialized windows
  693. X    or protected images don't get read from
  694. X    can not check argument because it will point to internal
  695. X    elements
  696. X    */
  697. X    void (* write_w_e_pointer )( const card i , const card j , const long value  );
  698.  
  699. Xpublic:
  700. X    /* constructors */
  701. X    /* the constructor when the image is being read from a file */
  702. X    long_image
  703. X    ( 
  704. X    const read_image_type rit ,     // marker that the image is being read
  705. X    const FILE * image_file ,    // file for image
  706. X    const card w_width = 1 ,    // window width
  707. X    const card w_length = 1        // window length
  708. X    );
  709.  
  710. X    /* the constructor when the image is built */
  711. X    long_image
  712. X    ( 
  713. X    const create_image_type cit ,    // marker that the image is being created
  714. X    const card n_rows ,         // the number of rows in the image
  715. X    const card n_cols ,         // the number of collumns in the image
  716. X    const FILE * image_file ,    // file for image
  717. X    const card w_width = 1 ,    // window width
  718. X    const card w_length = 1     // window length
  719. X    );
  720.  
  721. X    /* destructor (who would want to destroy an image?) */
  722. X    ~long_image ( ) { ; }
  723.  
  724. X    /* access routines for parts of data structure */
  725. X    const card n_rows() { return number_rows ; }
  726. X    const card n_cols() { return number_cols ; }
  727. X    const image_prot the_prot() { return prot; }
  728. X    const card c_length() { return comment_length ; }
  729. X    const char *the_comments() { return comments ; }
  730. X    const card the_collumn() { return collumn ; }
  731. X    const card the_row() { return row ; }
  732. X    const card the_width() { return window_width ; }
  733. X    const card the_length() { return window_length ; }
  734. X    const FILE * the_file() { return file ; }
  735. X    const status image_init() { return image_status ; }
  736. X    const status window_init() { return window_status ; }
  737.  
  738. X    /* access a pointer to a particular row */
  739. X    const long * get_row( card row );
  740.  
  741. X    /* sets the comments */
  742. X    void set_comments( char * string , const card length )
  743. X    {
  744. X    this->image_class::set_comments ( string , length );
  745. X    }
  746.  
  747. X    /* adds a string to the comments */
  748. X    void add_comment( char * string , const card length )
  749. X    {
  750. X    this->image_class::add_comment ( string , length );
  751. X    }
  752.  
  753.  
  754. X    /* real versions of virtual functions */
  755. X    /* routine to write out the image to a file */
  756. X    void write ( ) ;
  757.  
  758. X    /*
  759. X    move in row n steps 
  760. X    returns 1 when that motion is legal 0 otherwise
  761. X    */
  762. X    int move_collumn ( const int n ) ;
  763.  
  764. X    /*
  765. X    move in collumn n steps
  766. X    returns 1 when that motion is legal 0 otherwise
  767. X    */
  768. X    int move_row ( const int n ) ;
  769.  
  770. X    /*
  771. X    move to specified row
  772. X    */
  773. X    void move_to_row ( const card n ) ;
  774.  
  775. X    /*
  776. X    move to specified collumn
  777. X    */
  778. X    void move_to_collumn ( const card n ) ;
  779.  
  780. X    
  781. X    /*
  782. X    the function to get the specified element of a window
  783. X    it is a function pointer so that unitialized windows
  784. X    or protected images don't get read from
  785. X    this accesses the function pointer
  786. X    */
  787. X    long get_w_e ( const card i , const card j )
  788. X    { return (( long (*) (...) )(* get_w_e_pointer)) ( this , i , j ); }
  789.  
  790. X    /*
  791. X    the fast function without checking for initialization
  792. X    of a function pointer for getting elements of a window
  793. X    Also no bounds checking!
  794. X    ( Not recommended!)
  795. X    */
  796. X    long fast_g_w_e ( const card i , const card j )
  797. X    { return window_rows[i][j]; }
  798. X    
  799. X    /*
  800. X    the function to write to the specified element of a window.
  801. X    it is a function pointer so that unitialized windows
  802. X    or protected images don't get read from
  803. X    this accesses the function pointer
  804. X    */
  805. X    void write_w_e ( const card i , const card j , const long value )
  806. X    { ((void (*) (...) )(* write_w_e_pointer)) ( this , i , j , value ); }
  807.  
  808. X    /*
  809. X    the fast function without checking for initialization
  810. X    of a function pointer for writing elements to a window
  811. X    Also no bounds checking!
  812. X    ( Not recommended!)
  813. X    */
  814. X    void fast_w_w_e ( const card i , const card j , const long value )
  815. X    { window_rows[i][j] = value; }
  816.  
  817. X    /* 
  818. X    the function call on the image gets the upper left hand 
  819. X    of the image window and returns a reference so it can be
  820. X    used as a lvalue or rvalue
  821. X    optimized so does not check that the window is initialized
  822. X    if the window is not initialized then odd things may happen
  823. X    */
  824. X    long& operator() ()
  825. X    { return **window_rows; }
  826. X    
  827. X    /* 
  828. X    move to next legal position in image
  829. X    returns 1 when there is a next legal position 0 otherwise
  830. X    if the window is not initialized then it initializes it.
  831. X    with the window in the position 0,0 (if possible)
  832. X    */
  833. X    int (* next) (...); /* this will point to member functions! */
  834.  
  835. X    /* 
  836. X    move to previous legal position in image
  837. X    returns 1 when there is a previous legal position 0 otherwise
  838. X    if the window is not initialized then it initializes it.
  839. X    with the window in the farthest position (if possible)
  840. X    */
  841. X    int (* prev) (...); /* this will point to member functions! */
  842.  
  843. X    /*
  844. X    Access for next and previous elements of images
  845. X    */
  846. X    int operator++ ( ) 
  847. X    { return (* next) ( this /* because points to member*/ ); }
  848. X    int operator-- ( ) 
  849. X    { return (* prev) ( this /* because points to member*/ ); }
  850.  
  851. X    /*
  852. X    Change the size of a window
  853. X    causes the window to become uninitialized
  854. X    */
  855. X    void resize_window ( card width , card length );
  856.  
  857. X    /*
  858. X    Causes the window to cover the entire image.
  859. X    Allows one to access any part of the image with window operations
  860. X    */
  861. X    void window_entire_image ( );
  862.  
  863. X    };
  864.  
  865. X#endif LONG_IMAGE_H
  866. X/*
  867. XCopyright (C) 1986, David Sher in the University of Rochester
  868. XPermission is granted to any individual or institution to use, copy, or
  869. Xredistribute this software so long as it is not sold for profit, provided
  870. Xthis copyright notice is retained.
  871. X*/
  872. @//E*O*F varc++/long_image.h++//
  873. chmod u=rw,g=r,o=r $OUT
  874.  
  875. echo x - varc++/makefile
  876. if test -f varc++/makefile ; then
  877.     echo varc++/makefile exists, putting output in $$varc++/makefile
  878.     OUT=$$varc++/makefile
  879.     STATUS=1
  880. else
  881.     OUT=varc++/makefile
  882. fi
  883. sed 's/^X//' > $OUT <<'@//E*O*F varc++/makefile//'
  884. X# this is the makefile for the var library
  885.  
  886. X# This line constructs the library name (equal to the directory name)
  887. X# jccpwd^[!!sh^M:s/.*\///g^MILIBRARY = lib^[A.a^[
  888. XLIBRARY = libvarc++.a
  889.  
  890. X.SUFFIXES: .c++ 
  891.  
  892.  
  893. XCFLAGS = -O  -I/usr/grads/include -DVAX 
  894.  
  895. XC++FLAGS = +i $(CFLAGS)
  896.  
  897. XLIBS = -liff -lC
  898.  
  899. X# This line constructs the list of possible objects
  900. X# 2jc}ls *[A-Za-z0-9].c *.c++^[!!sh^M>}>}:g/\.c\+*$/ s//.o \\/^M
  901. XOBJS = \
  902. X    double_image.o \
  903. X    image.o \
  904. X    long_image.o \
  905. X    var_double_image.o \
  906. X    var_image.o \
  907. X    var_long_image.o 
  908.  
  909.  
  910. X.c++.o:
  911. X    c++ -c  $(C++FLAGS) $*.c++ 
  912.  
  913. X# the library is constructed by this line
  914. X$(LIBRARY) : $(OBJS)
  915. X    ar qv $(LIBRARY) $(OBJS)
  916. X    ranlib $(LIBRARY)
  917.  
  918. @//E*O*F varc++/makefile//
  919. chmod u=rw,g=r,o=r $OUT
  920.  
  921. echo x - varc++/var.h++
  922. if test -f varc++/var.h++ ; then
  923.     echo varc++/var.h++ exists, putting output in $$varc++/var.h++
  924.     OUT=$$varc++/var.h++
  925.     STATUS=1
  926. else
  927.     OUT=varc++/var.h++
  928. fi
  929. sed 's/^X//' > $OUT <<'@//E*O*F varc++/var.h++//'
  930. X/*
  931. X    This file contains the definitions necessary to use
  932. X    vision archive based stuff.
  933. X*/
  934. X#ifndef VAR_H
  935. X#define VAR_H 1
  936.  
  937. X/*
  938. X    Structure for a list of positions filenames and 
  939. X    file types
  940. X*/
  941. Xstruct band
  942. X    {
  943. X    int b_position;            // The position of a band in the pixel
  944. X    char * b_file_name;        // The name of the file
  945. X    char * b_file_type;        // The type of the file
  946. X    };
  947.  
  948. X/*
  949. X    header structure for archive files
  950. X*/
  951. Xstruct var_header
  952. X    {
  953. X    char *        vh_file_type;    // type of entire file
  954. X    int            vh_bytes_per_pixel;
  955. X    int            vh_number_bands;
  956. X    struct band *    vh_bands;    // bands to store image
  957. X    int         vh_length;    // length of image
  958. X    int         vh_width;    // width of image
  959. X    char *         vh_comments;    // the comments on the image
  960. X    char *        vh_header;    // the contents of the _.HEADER file
  961. X    };
  962.  
  963. X/*
  964. X    structure for storing color info.
  965. X    Overlay field is in for compatibility with 
  966. X    ikonas.  Also it rounds out the data structure
  967. X    so it is an integral number of words long.
  968. X*/
  969. Xstruct color_pixel
  970. X    {
  971. X    unsigned char red;        // red pixel
  972. X    unsigned char green;    // green pixel
  973. X    unsigned char blue;        // blue pixel
  974. X    unsigned char overlay;    // overlay pixel
  975. X    };
  976.  
  977. X/*
  978. X    Reads in the beginning of 
  979. X    an archive and parses the Header file
  980. X*/
  981. Xstruct var_header *
  982. Xvar_read_header(FILE * var_file);
  983.  
  984. X/*
  985. X    This is the general data reading routine that reads in any kind
  986. X    of data
  987. X*/
  988. Xvoid *
  989. Xvar_read_data(FILE * var_file , struct var_header * vh );
  990.  
  991. X/*
  992. X    Returns an array of doubles given a file that
  993. X    can be used otherwise fails
  994. X    also fills in comment field
  995. X*/
  996. Xdouble *
  997. Xvar_read_doubles(FILE * var_file , struct var_header * vh );
  998.  
  999. X/*
  1000. X    Returns an array of longs given a file that can be
  1001. X    used that way otherwise fails
  1002. X    also fills in comment field
  1003. X*/
  1004. Xlong *
  1005. Xvar_read_longs (FILE * var_file , struct var_header * vh );
  1006.  
  1007. X/*
  1008. X    Returns an array of color structures for 
  1009. X    color images
  1010. X    also fills in comment field
  1011. X*/
  1012. Xstruct color_pixel *
  1013. Xvar_read_color (FILE * var_file , struct var_header * vh );
  1014.  
  1015. X/*
  1016. X    Creates the beginning of 
  1017. X    an archive 
  1018. X*/
  1019. Xstruct var_header *
  1020. Xvar_create_header
  1021. X    (
  1022. X    char * file_type, 
  1023. X    char * comments, 
  1024. X    int bytes_per_pixel,
  1025. X    int number_bands,
  1026. X    struct band * bands,
  1027. X    int length,
  1028. X    int width
  1029. X    );
  1030.  
  1031. X/*
  1032. X    sets up the header for an array of doubles
  1033. X*/
  1034. Xstruct var_header *
  1035. Xvar_create_double_header ( int length , int width );
  1036.  
  1037. X/*
  1038. X    sets up the header for an array of longs
  1039. X*/
  1040. Xstruct var_header *
  1041. Xvar_create_long_header ( int length , int width );
  1042.  
  1043. X/*
  1044. X    sets up the header for an array of color pixels
  1045. X*/
  1046. Xstruct var_header *
  1047. Xvar_create_color_header ( int length , int width );
  1048.  
  1049. X/*
  1050. X    Writes the header and comments for a file
  1051. X    otherwise fails
  1052. X    also fills in comment field
  1053. X*/
  1054. Xvoid
  1055. Xvar_write_header(FILE * var_file , struct var_header * vh);
  1056.  
  1057. X/*
  1058. X    Writes the data out to the file as directed by the header
  1059. X*/
  1060. Xvoid
  1061. Xvar_write_data(FILE * var_file ,  struct var_header * vh , void * data );
  1062.  
  1063. X/*
  1064. X    Writes an array of doubles given a file that
  1065. X    can be used otherwise fails
  1066. X    also fills in comment field
  1067. X*/
  1068. Xvoid
  1069. Xvar_write_doubles(FILE * var_file , struct var_header * vh, double * array );
  1070.  
  1071. X/*
  1072. X    Writes an array of longs given a file that can be
  1073. X    used that way otherwise fails
  1074. X    also fills in comment field
  1075. X*/
  1076. Xvoid
  1077. Xvar_write_longs (FILE * var_file , struct var_header * vh, long * array );
  1078.  
  1079. X/*
  1080. X    Writes an array of color structures for 
  1081. X    color images
  1082. X    also fills in comment field
  1083. X*/
  1084. Xvoid
  1085. Xvar_write_color (FILE * var_file , struct var_header * vh, struct color_pixel * array );
  1086.  
  1087.  
  1088. X#endif VAR_H
  1089. X/*
  1090. XCopyright (C) 1986, David Sher in the University of Rochester
  1091. XPermission is granted to any individual or institution to use, copy, or
  1092. Xredistribute this software so long as it is not sold for profit, provided
  1093. Xthis copyright notice is retained.
  1094. X*/
  1095. @//E*O*F varc++/var.h++//
  1096. chmod u=rw,g=r,o=r $OUT
  1097.  
  1098. echo x - varc++/var_double_image.c++
  1099. if test -f varc++/var_double_image.c++ ; then
  1100.     echo varc++/var_double_image.c++ exists, putting output in $$varc++/var_double_image.c++
  1101.     OUT=$$varc++/var_double_image.c++
  1102.     STATUS=1
  1103. else
  1104.     OUT=varc++/var_double_image.c++
  1105. fi
  1106. sed 's/^X//' > $OUT <<'@//E*O*F varc++/var_double_image.c++//'
  1107. X/*
  1108. X    This is the interface between the mv image file format
  1109. X    and my c++ image handling datatype for images full of doubles
  1110. X*/
  1111. X#include <stream.h>
  1112. X#include <stdio.h>
  1113. X#include <string.h>
  1114. X#include "error.h++"
  1115. X#include "var.h++"
  1116. X#include "image.h++"
  1117. X#include "for.h++"
  1118. X#include "double_image.h++"
  1119.  
  1120. X/*
  1121. X    Reads in a double image from a mv file
  1122. X*/
  1123. Xdouble_image::double_image 
  1124. X    ( 
  1125. X    const read_image_type rit ,     // marker that the image is being read
  1126. X    const FILE * image_file ,    // file for image
  1127. X    const card w_width = 1 ,    // window width
  1128. X    const card w_length = 1        // window length
  1129. X    )
  1130. X    : ( READ , image_file ,  w_width , w_length )
  1131. X    {
  1132. X    /* check that the constructor is called correctly */
  1133. X    if ( rit != READ )
  1134. X    {
  1135. X    cerr << "constructor for double_image being called in obscure way\n";
  1136. X    abort();
  1137. X    }
  1138. X    
  1139. X    /* read in image from file */
  1140. X    struct var_header *vh = (struct var_header *) header_info;
  1141. X    double * image_buffer = var_read_doubles ( image_file , vh );
  1142. X    if (error_occured)
  1143. X    {
  1144. X    cerr << "error when reading in data from file";
  1145. X    print_errors_and_abort();
  1146. X    }
  1147. X    /* assign fields of the class */
  1148. X    comments = vh->vh_comments;
  1149. X    comment_length = strlen(vh->vh_comments);
  1150. X    number_rows = vh->vh_length;
  1151. X    number_cols = vh->vh_width;
  1152.  
  1153. X    /* allocate space for dope vector */
  1154. X    image_rows = new double * [ number_rows ];
  1155. X    /* allocate space for window dope vector */
  1156. X    window_rows = new double * [ w_length ];
  1157.  
  1158. X    /* initialize dope vector */
  1159. X    FOR(int i1 = 0 ; i1 < number_rows; i1++)
  1160. X    {
  1161. X    image_rows[i1] = image_buffer + i1*number_cols;
  1162. X    }
  1163. X    ENDFOR
  1164.  
  1165. X    /* set up the protection  so the image can be written */
  1166. X    prot = CAN_READ;
  1167.  
  1168. X    /* initialize function pointers */
  1169. X    next = &uninitialized_next;
  1170. X    prev = &uninitialized_prev;
  1171. X    get_w_e_pointer = &uninitialized_get_w_e;
  1172. X    write_w_e_pointer = &uninitialized_write_w_e;
  1173. X    }
  1174.  
  1175. X/*
  1176. X    This writes out a double image to a mv image file
  1177. X*/
  1178. Xvoid
  1179. Xdouble_image::write ( )
  1180. X    {
  1181. X    /* do the image independent stuff */
  1182. X    this->image_class::write();
  1183.  
  1184. X    /* fill in the relevant fields of the header info */
  1185. X    struct var_header *vh = var_create_double_header(number_rows,number_cols);
  1186. X    vh->vh_comments = comments;
  1187.  
  1188. X    /* put the header, comments and data out to the file */
  1189. X    var_write_doubles(file,vh,image_buffer);
  1190. X    
  1191. X    }
  1192. X/*
  1193. XCopyright (C) 1986, David Sher in the University of Rochester
  1194. XPermission is granted to any individual or institution to use, copy, or
  1195. Xredistribute this software so long as it is not sold for profit, provided
  1196. Xthis copyright notice is retained.
  1197. X*/
  1198. @//E*O*F varc++/var_double_image.c++//
  1199. chmod u=rw,g=r,o=r $OUT
  1200.  
  1201. echo x - varc++/var_image.c++
  1202. if test -f varc++/var_image.c++ ; then
  1203.     echo varc++/var_image.c++ exists, putting output in $$varc++/var_image.c++
  1204.     OUT=$$varc++/var_image.c++
  1205.     STATUS=1
  1206. else
  1207.     OUT=varc++/var_image.c++
  1208. fi
  1209. sed 's/^X//' > $OUT <<'@//E*O*F varc++/var_image.c++//'
  1210. X/*
  1211. X    This the support for generic images using the mv image file format
  1212. X*/
  1213.  
  1214. X#include <stream.h>
  1215. X#include <stdio.h>
  1216. X#include <string.h>
  1217. X#include "for.h++"
  1218. X#include "var.h++"
  1219. X#include "error.h++"
  1220. X#include "image.h++"
  1221.  
  1222. X/*
  1223. X    Reads in the data type independent header information from the
  1224. X    mv file and stores it in the relevant places
  1225. X*/
  1226. Ximage_class::image_class
  1227. X    ( 
  1228. X    const read_image_type rit ,     // marker that the image is being read
  1229. X    const FILE * image_file ,    // file for image
  1230. X    const card w_width  ,    // window width
  1231. X    const card w_length     // window length
  1232. X    )
  1233. X    {
  1234. X    /* check that the constructor is called correctly */
  1235. X    if ( rit != READ )
  1236. X    {
  1237. X    cerr << "Generic constructor for image being called in obscure way\n";
  1238. X    abort();
  1239. X    }
  1240.  
  1241. X    /* initialize using arguments */
  1242. X    file = image_file;
  1243. X    window_width = w_width;
  1244. X    window_length = w_length;
  1245.  
  1246. X    /* the header for the var file */
  1247. X    /* read in the header for the var file */
  1248. X    /* put the annotation in as comments */
  1249. X    struct var_header *vh = var_read_header(image_file);
  1250. X    /* check if error occured */
  1251. X    if (error_occured)
  1252. X    {
  1253. X    cerr << "Error when reading in header for image";
  1254. X    print_errors_and_abort();
  1255. X    }
  1256. X    /* place the header in the header slot */
  1257. X    header_info = vh;
  1258.  
  1259. X    /* a priori initializations */
  1260. X    /* status */
  1261. X    image_status = UNINITIALIZED;
  1262. X    window_status = UNINITIALIZED;
  1263. X    prot = CAN_READ;
  1264. X    }
  1265.  
  1266. X/*
  1267. X    Sets up the data type independent header information to be read 
  1268. X    out to the mv file.
  1269. X*/
  1270. Xvoid
  1271. Ximage_class::write ()
  1272. X    {
  1273. X    /* check that the protection allows the image to be written */
  1274. X    if ( (prot != CAN_WRITE) && (prot != CAN_READ_AND_WRITE))
  1275. X    {
  1276. X    cerr << "Trying to write image that is write protected to file";
  1277. X    abort();
  1278. X    }
  1279.  
  1280. X    }
  1281. X/*
  1282. XCopyright (C) 1986, David Sher in the University of Rochester
  1283. XPermission is granted to any individual or institution to use, copy, or
  1284. Xredistribute this software so long as it is not sold for profit, provided
  1285. Xthis copyright notice is retained.
  1286. X*/
  1287. @//E*O*F varc++/var_image.c++//
  1288. chmod u=rw,g=r,o=r $OUT
  1289.  
  1290. echo x - varc++/var_long_image.c++
  1291. if test -f varc++/var_long_image.c++ ; then
  1292.     echo varc++/var_long_image.c++ exists, putting output in $$varc++/var_long_image.c++
  1293.     OUT=$$varc++/var_long_image.c++
  1294.     STATUS=1
  1295. else
  1296.     OUT=varc++/var_long_image.c++
  1297. fi
  1298. sed 's/^X//' > $OUT <<'@//E*O*F varc++/var_long_image.c++//'
  1299. X/*
  1300. X    This is the interface between the mv image file format
  1301. X    and my c++ image handling datatype for images full of longs
  1302. X*/
  1303. X#include <stream.h>
  1304. X#include <stdio.h>
  1305. X#include "error.h++"
  1306. X#include "var.h++"
  1307. X#include "image.h++"
  1308. X#include "for.h++"
  1309. X#include "long_image.h++"
  1310.  
  1311. X/*
  1312. X    Reads in a long image from a mv file
  1313. X*/
  1314. Xlong_image::long_image 
  1315. X    ( 
  1316. X    const read_image_type rit ,     // marker that the image is being read
  1317. X    const FILE * image_file ,    // file for image
  1318. X    const card w_width = 1 ,    // window width
  1319. X    const card w_length = 1        // window length
  1320. X    )
  1321. X    : ( READ , image_file ,  w_width , w_length )
  1322. X    {
  1323. X    /* check that the constructor is called correctly */
  1324. X    if ( rit != READ )
  1325. X    {
  1326. X    cerr << "constructor for long_image being called in obscure way\n";
  1327. X    abort();
  1328. X    }
  1329. X    
  1330. X    /* read in image from file */
  1331. X    struct var_header *vh = (struct var_header *) header_info;
  1332. X    long * image_buffer = var_read_longs ( image_file , vh );
  1333. X    if (error_occured)
  1334. X    {
  1335. X    cerr << "error when reading in data from file";
  1336. X    print_errors_and_abort();
  1337. X    }
  1338. X    /* assign fields of the class */
  1339. X    comments = vh->vh_comments;
  1340. X    comment_length = strlen(vh->vh_comments);
  1341. X    number_rows = vh->vh_length;
  1342. X    number_cols = vh->vh_width;
  1343.  
  1344. X    /* allocate space for dope vector */
  1345. X    image_rows = new long * [ number_rows ];
  1346. X    /* allocate space for window dope vector */
  1347. X    window_rows = new long * [ w_length ];
  1348.  
  1349. X    /* initialize dope vector */
  1350. X    FOR(int i1 = 0 ; i1 < number_rows; i1++)
  1351. X    {
  1352. X    image_rows[i1] = image_buffer + i1*number_cols;
  1353. X    }
  1354. X    ENDFOR
  1355.  
  1356. X    /* set up the protection  so the image can be written */
  1357. X    prot = CAN_READ;
  1358.  
  1359. X    /* initialize function pointers */
  1360. X    next = &uninitialized_next;
  1361. X    prev = &uninitialized_prev;
  1362. X    get_w_e_pointer = &uninitialized_get_w_e;
  1363. X    write_w_e_pointer = &uninitialized_write_w_e;
  1364. X    }
  1365.  
  1366. X/*
  1367. X    This writes out a long image to a mv image file
  1368. X*/
  1369. Xvoid
  1370. Xlong_image::write ( )
  1371. X    {
  1372. X    /* do the image independent stuff */
  1373. X    this->image_class::write();
  1374.  
  1375. X    /* fill in the relevant fields of the header info */
  1376. X    struct var_header *vh = var_create_long_header(number_rows,number_cols);
  1377. X    vh->vh_comments = comments;
  1378.  
  1379. X    /* put the header, comments and data out to the file */
  1380. X    var_write_longs(file,vh,image_buffer);
  1381. X    
  1382. X    }
  1383. X/*
  1384. XCopyright (C) 1986, David Sher in the University of Rochester
  1385. XPermission is granted to any individual or institution to use, copy, or
  1386. Xredistribute this software so long as it is not sold for profit, provided
  1387. Xthis copyright notice is retained.
  1388. X*/
  1389. @//E*O*F varc++/var_long_image.c++//
  1390. chmod u=rw,g=r,o=r $OUT
  1391.  
  1392. echo x - vartools/README
  1393. if test -f vartools/README ; then
  1394.     echo vartools/README exists, putting output in $$vartools/README
  1395.     OUT=$$vartools/README
  1396.     STATUS=1
  1397. else
  1398.     OUT=vartools/README
  1399. fi
  1400. sed 's/^X//' > $OUT <<'@//E*O*F vartools/README//'
  1401. XThis is the directory in which the most useful utility routines for
  1402. Xmanipulating var files are gathered into a package.
  1403. @//E*O*F vartools/README//
  1404. chmod u=rw,g=r,o=r $OUT
  1405.  
  1406. echo x - vartools/var2ascii.c++
  1407. if test -f vartools/var2ascii.c++ ; then
  1408.     echo vartools/var2ascii.c++ exists, putting output in $$vartools/var2ascii.c++
  1409.     OUT=$$vartools/var2ascii.c++
  1410.     STATUS=1
  1411. else
  1412.     OUT=vartools/var2ascii.c++
  1413. fi
  1414. sed 's/^X//' > $OUT <<'@//E*O*F vartools/var2ascii.c++//'
  1415. X/*
  1416. X    This contains the work routine that converts an image to
  1417. X    a ascii file
  1418. X*/
  1419. X#include <stream.h>
  1420. X#include <stdio.h>
  1421. X#include <double_image.h++>
  1422. X#include "vartools.h++"
  1423.  
  1424.  
  1425. X// input is an initialized image
  1426. X// output is a file pointer open for output
  1427. X// format is the format to output each number
  1428. Xvoid
  1429. Xvar2ascii2(double_image& input , FILE *output , char *format )
  1430. X    {
  1431. X    // output the length and the width
  1432. X    fprintf(output,"%d %d",input.n_rows(),input.n_cols());
  1433.  
  1434. X    // iterate through the input image
  1435. X    while(input++)
  1436. X    {
  1437. X    // if at the beginning of a row output a carriage return
  1438. X    if(input.the_collumn() == 0)
  1439. X        {
  1440. X        fprintf(output,"\n");
  1441. X        }
  1442. X    // output the element of input
  1443. X    fprintf(output,format,input());
  1444. X    }
  1445. X    
  1446. X    // print out the comments
  1447. X    fprintf(output,"\n%s",input.the_comments());
  1448.  
  1449. X    // make sure the output goes to some file
  1450. X    fflush(output);
  1451. X    }
  1452.  
  1453. X/*
  1454. X    This is a version of var2ascii that takes an input file rather
  1455. X    than an initialized image
  1456. X*/
  1457. Xvoid
  1458. Xvar2ascii(FILE *input, FILE *output , char *format)
  1459. X    {
  1460. X    // read in the image
  1461. X    double_image input_image(READ,input);
  1462. X    // call the work function
  1463. X    var2ascii2(input_image,output,format);
  1464. X    }
  1465. X/*
  1466. XCopyright (C) 1986, David Sher in the University of Rochester
  1467. XPermission is granted to any individual or institution to use, copy, or
  1468. Xredistribute this software so long as it is not sold for profit, provided
  1469. Xthis copyright notice is retained.
  1470. X*/
  1471. @//E*O*F vartools/var2ascii.c++//
  1472. chmod u=rw,g=r,o=r $OUT
  1473.  
  1474. echo x - vartools/ascii2var.c++
  1475. if test -f vartools/ascii2var.c++ ; then
  1476.     echo vartools/ascii2var.c++ exists, putting output in $$vartools/ascii2var.c++
  1477.     OUT=$$vartools/ascii2var.c++
  1478.     STATUS=1
  1479. else
  1480.     OUT=vartools/ascii2var.c++
  1481. fi
  1482. sed 's/^X//' > $OUT <<'@//E*O*F vartools/ascii2var.c++//'
  1483. X/*
  1484. X    This contains the work routine that converts an image to
  1485. X    a ascii file
  1486. X*/
  1487. X#include <stream.h>
  1488. X#include <stdio.h>
  1489. X#include <string.h>
  1490. X#include <double_image.h++>
  1491. X#include "vartools.h++"
  1492.  
  1493.  
  1494. X// input is a file pointer to the input file
  1495. X// output is a file pointer open for output
  1496. Xvoid
  1497. Xascii2var(FILE *input , FILE *output)
  1498. X    {
  1499. X    int number_rows = -1;
  1500. X    int number_cols = -1;
  1501. X    // read the length and the width
  1502. X    fscanf(input,"%d%d",&number_rows,&number_cols);
  1503. X    // initialize the image
  1504. X    double_image output_image(CREATE,number_rows,number_cols,output);
  1505.  
  1506. X    // iterate through the output image reading in numbers
  1507. X    while(output_image++)
  1508. X    {
  1509. X    fscanf(input,"%lf",&(output_image()));
  1510. X    }
  1511. X    
  1512. X    // scan through the image until an end of file or a new line
  1513. X    char c;
  1514. X    for(;;) 
  1515. X    {
  1516. X    c = getc(input);
  1517. X    if ( c == EOF ) return ;
  1518. X    if ( c == '\n') break;
  1519. X    }
  1520.  
  1521. X    // read in the comments
  1522. X    int comments_size = 128;
  1523. X    char * comments = new char[comments_size];
  1524. X    for ( int i = 0 ; EOF != (c = getc(input)) ; i++ )
  1525. X    {
  1526. X    // if you ran out of room double the size of the comments
  1527. X    if ( i == comments_size )
  1528. X        {
  1529. X        char *new_comments = new char[comments_size + comments_size];
  1530. X        for( int j = 0 ; j < comments_size ; j++ )
  1531. X        {
  1532. X        new_comments[j] = comments[j];
  1533. X        }
  1534. X        comments_size += comments_size;
  1535. X        comments = new_comments;
  1536. X        }
  1537. X    comments[i] = c;
  1538. X    }
  1539. X    comments[i] = 0;
  1540. X    output_image.set_comments(comments,i);
  1541.  
  1542. X    // write the output to disk
  1543. X    output_image.write();
  1544. X    }
  1545. X/*
  1546. XCopyright (C) 1986, David Sher in the University of Rochester
  1547. XPermission is granted to any individual or institution to use, copy, or
  1548. Xredistribute this software so long as it is not sold for profit, provided
  1549. Xthis copyright notice is retained.
  1550. X*/
  1551. @//E*O*F vartools/ascii2var.c++//
  1552. chmod u=rw,g=r,o=r $OUT
  1553.  
  1554. echo Inspecting for damage in transit...
  1555. temp=/tmp/sharin$$; dtemp=/tmp/sharout$$
  1556. trap "rm -f $temp $dtemp; exit" 0 1 2 3 15
  1557. cat > $temp <<\!!!
  1558.      239    1271    7543 double_image.h++
  1559.       15      88     492 for.h++
  1560.        8      48     302 iff_image.h++
  1561.       31     132     735 iff_local.h++
  1562.       68     341    2328 iff_stdim.h++
  1563.      159     700    4149 image.h++
  1564.      239    1271    7497 long_image.h++
  1565.       34      94     667 makefile
  1566.      165     628    3868 var.h++
  1567.       91     375    2578 var_double_image.c++
  1568.       77     312    2018 var_image.c++
  1569.       90     373    2530 var_long_image.c++
  1570.        2      20     120 README
  1571.       56     201    1450 var2ascii.c++
  1572.       68     262    1760 ascii2var.c++
  1573.     1342    6116   38037 total
  1574. !!!
  1575. wc  varc++/double_image.h++ varc++/for.h++ varc++/iff_image.h++ varc++/iff_local.h++ varc++/iff_stdim.h++ varc++/image.h++ varc++/long_image.h++ varc++/makefile varc++/var.h++ varc++/var_double_image.c++ varc++/var_image.c++ varc++/var_long_image.c++ vartools/README vartools/var2ascii.c++ vartools/ascii2var.c++ | sed 's=[^ ]*/==' | diff -b $temp - >$dtemp
  1576. if test -s $dtemp ; then
  1577.     echo "Ouch [diff of wc output]:"
  1578.     cat $dtemp
  1579.     STATUS=1
  1580. elif test $STATUS = 0 ; then
  1581.     echo "No problems found."
  1582. else
  1583.     echo "WARNING -- PROBLEMS WERE FOUND..."
  1584. fi
  1585. exit $STATUS
  1586.