tiff-bi.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* $Id: tiff-bi.c,v 1.3 2010-06-08 18:55:15 bfriesen Exp $ */
  2. /*
  3. * tiff-bi.c -- create a Class B (bilevel) TIFF file
  4. *
  5. * Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
  6. *
  7. * All Rights Reserved
  8. *
  9. * Permission to use, copy, modify, and distribute this software and its
  10. * documentation for any purpose and without fee is hereby granted,
  11. * provided that the above copyright notice appear in all copies and that
  12. * both that copyright notice and this permission notice appear in
  13. * supporting documentation, and that the name of Digital not be
  14. * used in advertising or publicity pertaining to distribution of the
  15. * software without specific, written prior permission.
  16. *
  17. * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. * SOFTWARE.
  24. */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include "tiffio.h"
  28. #define WIDTH 512
  29. #define HEIGHT WIDTH
  30. int main(int argc, char **argv)
  31. {
  32. int i;
  33. unsigned char * scan_line;
  34. TIFF * tif;
  35. if (argc != 2) {
  36. fprintf(stderr, "Usage: %s tiff-image\n", argv[0]);
  37. return 0;
  38. }
  39. if ((tif = TIFFOpen(argv[1], "w")) == NULL) {
  40. fprintf(stderr, "can't open %s as a TIFF file\n", argv[1]);
  41. return 0;
  42. }
  43. TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, WIDTH);
  44. TIFFSetField(tif, TIFFTAG_IMAGELENGTH, HEIGHT);
  45. TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 1);
  46. TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
  47. TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
  48. TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
  49. TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1);
  50. TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  51. TIFFSetField(tif, TIFFTAG_RESOLUTIONUNIT, RESUNIT_NONE);
  52. scan_line = (unsigned char *) malloc(WIDTH / 8);
  53. for (i = 0; i < (WIDTH / 8) / 2; i++)
  54. scan_line[i] = 0;
  55. for (i = (WIDTH / 8) / 2; i < (WIDTH / 8); i++)
  56. scan_line[i] = 255;
  57. for (i = 0; i < HEIGHT / 2; i++)
  58. TIFFWriteScanline(tif, scan_line, i, 0);
  59. for (i = 0; i < (WIDTH / 8) / 2; i++)
  60. scan_line[i] = 255;
  61. for (i = (WIDTH / 8) / 2; i < (WIDTH / 8); i++)
  62. scan_line[i] = 0;
  63. for (i = HEIGHT / 2; i < HEIGHT; i++)
  64. TIFFWriteScanline(tif, scan_line, i, 0);
  65. free(scan_line);
  66. TIFFClose(tif);
  67. return 0;
  68. }
  69. /*
  70. * Local Variables:
  71. * mode: c
  72. * c-basic-offset: 8
  73. * fill-column: 78
  74. * End:
  75. */