Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/test/test_append_to_strip.c

raw
1 /*
2 * Copyright (c) 2022, Even Rouault <even.rouault at spatialys.com>
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the names of
8 * Sam Leffler and Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Sam Leffler and Silicon Graphics.
11 *
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
13 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
14 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
17 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
18 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
20 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
22 */
23
24 /*
25 * TIFF Library
26 *
27 * Test TIFFAppendToStrip() through TIFFWriteRawStrip()
28 * Scenario of https://gitlab.com/libtiff/libtiff/-/issues/489
29 */
30
31 #include "tif_config.h"
32
33 #include <assert.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_UNISTD_H
39 #include <unistd.h>
40 #endif
41
42 #include "tiffio.h"
43
44 int main()
45 {
46 int ret;
47 TIFF *tif = TIFFOpen("test_append_to_strip.tif", "w");
48 if (tif == NULL)
49 {
50 fprintf(stderr, "Cannot create test_append_to_strip.tif");
51 return 1;
52 }
53 ret = TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
54 assert(ret);
55 ret = TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, 1);
56 assert(ret);
57 ret = TIFFSetField(tif, TIFFTAG_IMAGELENGTH, 9);
58 assert(ret);
59 ret = TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 5);
60 assert(ret);
61 ret = TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8);
62 assert(ret);
63 ret = TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1);
64 assert(ret);
65 int row;
66 for (row = 0; row < 9; ++row)
67 {
68 char c = (char)row;
69 int strip = (row < 5) ? 0 : 1;
70 ret = TIFFWriteRawStrip(tif, strip, &c, 1);
71 assert(ret == 1);
72 }
73 (void)ret;
74 TIFFClose(tif);
75 tif = TIFFOpen("test_append_to_strip.tif", "r");
76 if (tif == NULL)
77 {
78 fprintf(stderr, "Cannot create test_append_to_strip.tif");
79 return 1;
80 }
81 toff_t *panByteCounts = NULL;
82 TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &panByteCounts);
83 assert(panByteCounts);
84 int exitCode = 0;
85 if (panByteCounts[0] != 5)
86 {
87 exitCode = 1;
88 fprintf(stderr, "panByteCounts[0] = %d. Expected 5.\n",
89 (int)panByteCounts[0]);
90 }
91 if (panByteCounts[1] != 4)
92 {
93 exitCode = 1;
94 fprintf(stderr, "panByteCounts[1] = %d. Expected 4.\n",
95 (int)panByteCounts[1]);
96 }
97 for (row = 0; row < 9; ++row)
98 {
99 char c;
100 TIFFReadScanline(tif, &c, row, 0);
101 if (c != row)
102 {
103 fprintf(
104 stderr,
105 "TIFFReadScanline() for scanline %d returned %d. %d expected\n",
106 row, c, row);
107 exitCode = 1;
108 }
109 }
110 TIFFClose(tif);
111 unlink("test_append_to_strip.tif");
112 return exitCode;
113 }