home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fontutils-0.6 / imgrotate / img-output.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-27  |  2.2 KB  |  95 lines

  1. /* img-output.c: write an IMG file.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include "file-output.h"
  22.  
  23. #include "img-output.h"
  24.  
  25.  
  26. /* The file we are writing to.  */
  27. static FILE *img_output_file = NULL;
  28. static string img_output_filename;
  29.  
  30. /* Macros for convenient output.  */
  31. #define IMG_PUT_TWO(t) put_two (t, img_output_file, img_output_filename)
  32. #define IMG_PUT_FOUR(f) put_four (f, img_output_file, img_output_filename)
  33.  
  34.  
  35. /* Routines to start and end writing a file.  (For the user to call.)
  36.    We make sure the caller can't have two output files open
  37.    simultaneously. */
  38.  
  39. boolean
  40. open_img_output_file (string filename)
  41. {
  42.   assert (img_output_file == NULL);
  43.  
  44.   img_output_filename = filename;
  45.   img_output_file = fopen (filename, "w");
  46.  
  47.   return img_output_file != NULL;
  48. }
  49.  
  50.  
  51. void
  52. close_img_output_file ()
  53. {
  54.   assert (img_output_file != NULL);
  55.  
  56.   xfclose (img_output_file, img_output_filename);
  57.  
  58.   img_output_filename = NULL;
  59.   img_output_file = NULL;
  60. }
  61.  
  62.  
  63.  
  64. /* Write the header to an IMG file.  */
  65.  
  66. void
  67. put_img_header (img_header_type h)
  68. {
  69.   /* First the magic number.  */
  70.   putc (0211, img_output_file);
  71.   putc ('O', img_output_file);
  72.   putc ('P', img_output_file);
  73.   putc ('S', img_output_file);
  74.   putc (0, img_output_file);
  75.   putc (2, img_output_file);
  76.   
  77.   IMG_PUT_TWO (h.hres);
  78.   IMG_PUT_TWO (h.vres);
  79.   IMG_PUT_FOUR (0); /* The flags.  */
  80.   IMG_PUT_TWO (h.width);
  81.   IMG_PUT_TWO (h.height);
  82.   IMG_PUT_TWO (1);  /* The depth.  */
  83.   IMG_PUT_TWO (0);  /* The format.  */
  84. }
  85.  
  86.  
  87.  
  88. /* Writing routines used in other files..  */
  89.  
  90. void
  91. img_put_byte (one_byte b)
  92. {
  93.   putc (b, img_output_file);
  94. }
  95.