generate_etsi_300_242_pages.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * generate_etsi_300_242_pages.c - Create the test pages defined in ETSI ETS 300 242.
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2006 Steve Underwood
  9. *
  10. * All rights reserved.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2, as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*! \file */
  26. #if defined(HAVE_CONFIG_H)
  27. #include "config.h"
  28. #endif
  29. #include <stdio.h>
  30. #include <inttypes.h>
  31. #include <limits.h>
  32. #include <unistd.h>
  33. #include <fcntl.h>
  34. #include <stdlib.h>
  35. #include <time.h>
  36. #include <memory.h>
  37. #include <string.h>
  38. #if defined(HAVE_TGMATH_H)
  39. #include <tgmath.h>
  40. #endif
  41. #if defined(HAVE_MATH_H)
  42. #include <math.h>
  43. #endif
  44. #include "spandsp.h"
  45. struct
  46. {
  47. const char *name;
  48. int x_res;
  49. int y_res;
  50. int width;
  51. int length;
  52. int compression;
  53. int type;
  54. } sequence[] =
  55. {
  56. {
  57. "etsi_300_242_a4_diago1.tif",
  58. T4_X_RESOLUTION_R8,
  59. T4_Y_RESOLUTION_STANDARD,
  60. T4_WIDTH_R8_A4,
  61. 1002,
  62. COMPRESSION_CCITT_T4,
  63. 0
  64. },
  65. {
  66. "etsi_300_242_a4_diago2.tif",
  67. T4_X_RESOLUTION_R8,
  68. T4_Y_RESOLUTION_STANDARD,
  69. T4_WIDTH_R8_A4,
  70. 1002,
  71. COMPRESSION_CCITT_T4,
  72. 1
  73. },
  74. {
  75. "etsi_300_242_a4_duration1.tif",
  76. T4_X_RESOLUTION_R8,
  77. T4_Y_RESOLUTION_STANDARD,
  78. T4_WIDTH_R8_A4,
  79. 237,
  80. COMPRESSION_CCITT_T4,
  81. 2
  82. },
  83. {
  84. "etsi_300_242_a4_duration2.tif",
  85. T4_X_RESOLUTION_R8,
  86. T4_Y_RESOLUTION_STANDARD,
  87. T4_WIDTH_R8_A4,
  88. 237,
  89. COMPRESSION_CCITT_T4,
  90. 3
  91. },
  92. {
  93. "etsi_300_242_a4_error.tif",
  94. T4_X_RESOLUTION_R8,
  95. T4_Y_RESOLUTION_STANDARD,
  96. T4_WIDTH_R8_A4,
  97. 400,
  98. COMPRESSION_CCITT_T4,
  99. 4
  100. },
  101. {
  102. "etsi_300_242_a4_impress.tif",
  103. T4_X_RESOLUTION_R8,
  104. T4_Y_RESOLUTION_STANDARD,
  105. T4_WIDTH_R8_A4,
  106. 1079,
  107. COMPRESSION_CCITT_T4,
  108. 5
  109. },
  110. {
  111. "etsi_300_242_a4_stairstep.tif",
  112. T4_X_RESOLUTION_R8,
  113. T4_Y_RESOLUTION_STANDARD,
  114. T4_WIDTH_R8_A4,
  115. 1728,
  116. COMPRESSION_CCITT_T4,
  117. 6
  118. },
  119. {
  120. "etsi_300_242_a4_white.tif",
  121. T4_X_RESOLUTION_R8,
  122. T4_Y_RESOLUTION_STANDARD,
  123. T4_WIDTH_R8_A4,
  124. 1100,
  125. COMPRESSION_CCITT_T4,
  126. 7
  127. },
  128. {
  129. "etsi_300_242_a4_white_2p.tif",
  130. T4_X_RESOLUTION_R8,
  131. T4_Y_RESOLUTION_STANDARD,
  132. T4_WIDTH_R8_A4,
  133. 1100,
  134. COMPRESSION_CCITT_T4,
  135. 7
  136. },
  137. { /* Second page of the above file */
  138. "",
  139. T4_X_RESOLUTION_R8,
  140. T4_Y_RESOLUTION_STANDARD,
  141. T4_WIDTH_R8_A4,
  142. 1100,
  143. COMPRESSION_CCITT_T4,
  144. 7
  145. },
  146. {
  147. "etsi_300_242_a4_impress_white.tif",
  148. T4_X_RESOLUTION_R8,
  149. T4_Y_RESOLUTION_STANDARD,
  150. T4_WIDTH_R8_A4,
  151. 1079,
  152. COMPRESSION_CCITT_T4,
  153. 5
  154. },
  155. { /* Second page of the above file */
  156. "",
  157. T4_X_RESOLUTION_R8,
  158. T4_Y_RESOLUTION_STANDARD,
  159. T4_WIDTH_R8_A4,
  160. 1100,
  161. COMPRESSION_CCITT_T4,
  162. 7
  163. },
  164. {
  165. NULL,
  166. 0,
  167. 0,
  168. 0,
  169. 0
  170. },
  171. };
  172. int photo_metric = PHOTOMETRIC_MINISWHITE;
  173. int fill_order = FILLORDER_LSB2MSB;
  174. static void set_pixel(uint8_t buf[], int row, int pixel)
  175. {
  176. row--;
  177. buf[row*1728/8 + pixel/8] |= (0x80 >> (pixel & 0x07));
  178. }
  179. /*- End of function --------------------------------------------------------*/
  180. static void set_pixel_range(uint8_t buf[], int row, int start, int end)
  181. {
  182. int i;
  183. for (i = start; i <= end; i++)
  184. set_pixel(buf, row, i);
  185. }
  186. /*- End of function --------------------------------------------------------*/
  187. static void clear_pixel(uint8_t buf[], int row, int pixel)
  188. {
  189. row--;
  190. buf[row*1728/8 + pixel/8] &= ~(0x80 >> (pixel & 0x07));
  191. }
  192. /*- End of function --------------------------------------------------------*/
  193. static void clear_pixel_range(uint8_t buf[], int row, int start, int end)
  194. {
  195. int i;
  196. for (i = start; i <= end; i++)
  197. clear_pixel(buf, row, i);
  198. }
  199. /*- End of function --------------------------------------------------------*/
  200. static void clear_row(uint8_t buf[], int width)
  201. {
  202. memset(buf, 0, width/8 + 1);
  203. }
  204. /*- End of function --------------------------------------------------------*/
  205. static int create_white_page(TIFF *tiff_file)
  206. {
  207. uint8_t image_buffer[8192];
  208. int row;
  209. /* TSB-85 WHITE page. */
  210. for (row = 0; row < 1100; row++)
  211. {
  212. clear_row(image_buffer, 1728);
  213. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  214. {
  215. printf("Write error at row %d.\n", row);
  216. exit(2);
  217. }
  218. }
  219. return 1100;
  220. }
  221. /*- End of function --------------------------------------------------------*/
  222. static int create_stairstep_page(TIFF *tiff_file)
  223. {
  224. uint8_t image_buffer[8192];
  225. int row;
  226. int start_pixel;
  227. int i;
  228. /* TSB-85 STAIRSTEP page. */
  229. start_pixel = 0;
  230. for (row = 0; row < 1728; row++)
  231. {
  232. clear_row(image_buffer, 1728);
  233. set_pixel_range(image_buffer, 1, start_pixel, start_pixel + 63);
  234. if (photo_metric != PHOTOMETRIC_MINISWHITE)
  235. {
  236. for (i = 0; i < 1728/8; i++)
  237. image_buffer[i] = ~image_buffer[i];
  238. }
  239. #if 0
  240. if (fill_order != FILLORDER_LSB2MSB)
  241. bit_reverse(image_buffer, image_buffer, 1728/8);
  242. #endif
  243. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  244. {
  245. printf("Write error at row %d.\n", row);
  246. exit(2);
  247. }
  248. start_pixel += 64;
  249. if (start_pixel >= 1728)
  250. start_pixel = 0;
  251. }
  252. return 1728;
  253. }
  254. /*- End of function --------------------------------------------------------*/
  255. static int create_diago1_page(TIFF *tiff_file)
  256. {
  257. uint8_t image_buffer[1728/8 + 1];
  258. int row;
  259. /* ETSI ETS 300 242 B.5.1 One dimensional coding test chart - the DIAGO1 page. */
  260. for (row = 0; row < 1001; row++)
  261. {
  262. clear_row(image_buffer, 1728);
  263. set_pixel_range(image_buffer, 1, row, 1727);
  264. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  265. {
  266. printf("Write error at row %d.\n", row);
  267. exit(2);
  268. }
  269. }
  270. clear_row(image_buffer, 1728);
  271. set_pixel_range(image_buffer, 1, 0, 1727);
  272. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  273. {
  274. printf("Write error at row %d.\n", row);
  275. exit(2);
  276. }
  277. return 1002;
  278. }
  279. /*- End of function --------------------------------------------------------*/
  280. static int create_diago2_page(TIFF *tiff_file)
  281. {
  282. uint8_t image_buffer[1728/8 + 1];
  283. int row;
  284. /* ETSI ETS 300 242 B.5.1 One dimensional coding test chart - the DIAGO2 page. */
  285. for (row = 0; row < 1001; row++)
  286. {
  287. clear_row(image_buffer, 1728);
  288. set_pixel_range(image_buffer, 1, row + 728, 1727);
  289. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  290. {
  291. printf("Write error at row %d.\n", row);
  292. exit(2);
  293. }
  294. }
  295. clear_row(image_buffer, 1728);
  296. set_pixel_range(image_buffer, 1, 0, 1727);
  297. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  298. {
  299. printf("Write error at row %d.\n", row);
  300. exit(2);
  301. }
  302. return 1002;
  303. }
  304. /*- End of function --------------------------------------------------------*/
  305. static int create_impress_page(TIFF *tiff_file)
  306. {
  307. int j;
  308. int row;
  309. uint8_t *page;
  310. /* ETSI ETS 300 242 B.5.2 Printing resolution - the IMPRESS page */
  311. if ((page = malloc(1079*1728/8)) == NULL)
  312. return 0;
  313. memset(page, 0, 1079*1728/8);
  314. set_pixel_range(page, 1, 0, 1727);
  315. for (row = 2; row <= 78; row++)
  316. {
  317. set_pixel_range(page, row, 850, 850 + 27);
  318. set_pixel_range(page, row, 850 + 27 + 745, 850 + 27 + 745 + 26);
  319. }
  320. for (row = 80; row <= 117; row++)
  321. {
  322. for (j = 0; j < 1728; j += 2)
  323. set_pixel(page, row, j);
  324. }
  325. for (row = 118; row <= 155; row++)
  326. {
  327. for (j = 1; j < 1728; j += 2)
  328. set_pixel(page, row, j);
  329. }
  330. for (row = 194; row <= 231; row += 2)
  331. set_pixel_range(page, row, 0, 1727);
  332. for (row = 270; row <= 276; row++)
  333. set_pixel_range(page, row, 60, 60 + 1607);
  334. for (j = 0; j < 1728; j += 27)
  335. set_pixel(page, 315, j);
  336. for (row = 354; row <= 480; row++)
  337. set_pixel_range(page, row, 209, 768);
  338. for (row = 358; row <= 476; row++)
  339. clear_pixel_range(page, row, 488, 489);
  340. clear_pixel_range(page, 417, 217, 760);
  341. for (row = 354; row <= 357; row++)
  342. set_pixel_range(page, row, 962, 1521);
  343. for (row = 477; row <= 480; row++)
  344. set_pixel_range(page, row, 962, 1521);
  345. for (row = 358; row <= 476; row++)
  346. set_pixel_range(page, row, 962, 969);
  347. for (row = 358; row <= 476; row++)
  348. set_pixel_range(page, row, 1514, 1521);
  349. for (row = 358; row <= 476; row++)
  350. set_pixel(page, row, 1241);
  351. set_pixel_range(page, 417, 970, 1513);
  352. for (row = 354; row <= 1079; row++)
  353. set_pixel(page, row, 864);
  354. for (row = 157; row <= 926; row++)
  355. set_pixel_range(page, row, 884, 899);
  356. for (row = 0; row < 1079; row++)
  357. {
  358. if (TIFFWriteScanline(tiff_file, page + row*1728/8, row, 0) < 0)
  359. {
  360. printf("Write error at row %d.\n", row);
  361. exit(2);
  362. }
  363. }
  364. free(page);
  365. return 1079;
  366. }
  367. /*- End of function --------------------------------------------------------*/
  368. static int create_duration1_page(TIFF *tiff_file)
  369. {
  370. uint8_t image_buffer[1728/8 + 1];
  371. int row;
  372. int i;
  373. /* ETSI ETS 300 242 B.5.3 Acceptance of total coded scan line duration - the DURATION1 page */
  374. row = 0;
  375. clear_row(image_buffer, 1728);
  376. set_pixel_range(image_buffer, 1, 0, 1727);
  377. if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
  378. {
  379. printf("Write error at row %d.\n", row);
  380. exit(2);
  381. }
  382. for ( ; row < 117; row++)
  383. {
  384. clear_row(image_buffer, 1728);
  385. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  386. {
  387. printf("Write error at row %d.\n", row);
  388. exit(2);
  389. }
  390. }
  391. clear_row(image_buffer, 1728);
  392. set_pixel_range(image_buffer, 1, 0, 1727);
  393. if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
  394. {
  395. printf("Write error at row %d.\n", row);
  396. exit(2);
  397. }
  398. clear_row(image_buffer, 1728);
  399. for (i = 1; i < 1728; i += 2)
  400. set_pixel(image_buffer, 1, i);
  401. if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
  402. {
  403. printf("Write error at row %d.\n", row);
  404. exit(2);
  405. }
  406. clear_row(image_buffer, 1728);
  407. set_pixel_range(image_buffer, 1, 0, 1727);
  408. if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
  409. {
  410. printf("Write error at row %d.\n", row);
  411. exit(2);
  412. }
  413. for ( ; row < 236; row++)
  414. {
  415. clear_row(image_buffer, 1728);
  416. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  417. {
  418. printf("Write error at row %d.\n", row);
  419. exit(2);
  420. }
  421. }
  422. clear_row(image_buffer, 1728);
  423. set_pixel_range(image_buffer, 1, 0, 1727);
  424. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  425. {
  426. printf("Write error at row %d.\n", row);
  427. exit(2);
  428. }
  429. return 237;
  430. }
  431. /*- End of function --------------------------------------------------------*/
  432. static int create_duration2_page(TIFF *tiff_file)
  433. {
  434. return create_duration1_page(tiff_file);
  435. }
  436. /*- End of function --------------------------------------------------------*/
  437. static int create_error_page(TIFF *tiff_file)
  438. {
  439. uint8_t image_buffer[1728/8 + 1];
  440. int row;
  441. int start_pixel;
  442. int i;
  443. /* ETSI ETS 300 242 B.5.4 Copy quality criteria - the ERROR page. */
  444. for (row = 0; row < 68; row++)
  445. {
  446. clear_row(image_buffer, 1728);
  447. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  448. {
  449. printf("Write error at row %d.\n", row);
  450. exit(2);
  451. }
  452. }
  453. clear_row(image_buffer, 1728);
  454. set_pixel_range(image_buffer, 1, 0, 1727);
  455. if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
  456. {
  457. printf("Write error at row %d.\n", row);
  458. exit(2);
  459. }
  460. clear_row(image_buffer, 1728);
  461. if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
  462. {
  463. printf("Write error at row %d.\n", row);
  464. exit(2);
  465. }
  466. for (i = 0; i < 10; i++)
  467. {
  468. for (start_pixel = 16; start_pixel <= 1616; start_pixel += 64)
  469. {
  470. clear_row(image_buffer, 1728);
  471. set_pixel_range(image_buffer, 1, start_pixel, start_pixel + 63);
  472. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  473. {
  474. printf("Write error at row %d.\n", row);
  475. exit(2);
  476. }
  477. row++;
  478. }
  479. }
  480. clear_row(image_buffer, 1728);
  481. if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
  482. {
  483. printf("Write error at row %d.\n", row);
  484. exit(2);
  485. }
  486. clear_row(image_buffer, 1728);
  487. set_pixel_range(image_buffer, 1, 0, 1727);
  488. if (TIFFWriteScanline(tiff_file, image_buffer, row++, 0) < 0)
  489. {
  490. printf("Write error at row %d.\n", row);
  491. exit(2);
  492. }
  493. for (row = 332; row < 400; row++)
  494. {
  495. clear_row(image_buffer, 1728);
  496. if (TIFFWriteScanline(tiff_file, image_buffer, row, 0) < 0)
  497. {
  498. printf("Write error at row %d.\n", row);
  499. exit(2);
  500. }
  501. }
  502. return 400;
  503. }
  504. /*- End of function --------------------------------------------------------*/
  505. int main(int argc, char *argv[])
  506. {
  507. TIFF *tiff_file;
  508. struct tm *tm;
  509. time_t now;
  510. char buf[133];
  511. float x_resolution;
  512. float y_resolution;
  513. int i;
  514. int image_length;
  515. int opt;
  516. photo_metric = PHOTOMETRIC_MINISWHITE;
  517. fill_order = FILLORDER_LSB2MSB;
  518. while ((opt = getopt(argc, argv, "ir")) != -1)
  519. {
  520. switch (opt)
  521. {
  522. case 'i':
  523. photo_metric = PHOTOMETRIC_MINISBLACK;
  524. break;
  525. case 'r':
  526. fill_order = FILLORDER_MSB2LSB;
  527. break;
  528. default:
  529. //usage();
  530. exit(2);
  531. break;
  532. }
  533. }
  534. tiff_file = NULL;
  535. for (i = 0; sequence[i].name; i++)
  536. {
  537. if (sequence[i].name[0])
  538. {
  539. if (tiff_file)
  540. TIFFClose(tiff_file);
  541. if ((tiff_file = TIFFOpen(sequence[i].name, "w")) == NULL)
  542. exit(2);
  543. }
  544. /* Prepare the directory entry fully before writing the image, or libtiff complains */
  545. TIFFSetField(tiff_file, TIFFTAG_COMPRESSION, sequence[i].compression);
  546. if (sequence[i].compression == COMPRESSION_CCITT_T4)
  547. {
  548. TIFFSetField(tiff_file, TIFFTAG_T4OPTIONS, GROUP3OPT_FILLBITS); // | GROUP3OPT_2DENCODING);
  549. TIFFSetField(tiff_file, TIFFTAG_FAXMODE, FAXMODE_CLASSF);
  550. }
  551. TIFFSetField(tiff_file, TIFFTAG_IMAGEWIDTH, sequence[i].width);
  552. TIFFSetField(tiff_file, TIFFTAG_BITSPERSAMPLE, 1);
  553. TIFFSetField(tiff_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
  554. TIFFSetField(tiff_file, TIFFTAG_SAMPLESPERPIXEL, 1);
  555. TIFFSetField(tiff_file, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
  556. TIFFSetField(tiff_file, TIFFTAG_PHOTOMETRIC, photo_metric);
  557. TIFFSetField(tiff_file, TIFFTAG_FILLORDER, fill_order);
  558. x_resolution = sequence[i].x_res/100.0f;
  559. y_resolution = sequence[i].y_res/100.0f;
  560. TIFFSetField(tiff_file, TIFFTAG_XRESOLUTION, floorf(x_resolution*2.54f + 0.5f));
  561. TIFFSetField(tiff_file, TIFFTAG_YRESOLUTION, floorf(y_resolution*2.54f + 0.5f));
  562. TIFFSetField(tiff_file, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH);
  563. TIFFSetField(tiff_file, TIFFTAG_SOFTWARE, "spandsp");
  564. if (gethostname(buf, sizeof(buf)) == 0)
  565. TIFFSetField(tiff_file, TIFFTAG_HOSTCOMPUTER, buf);
  566. TIFFSetField(tiff_file, TIFFTAG_IMAGEDESCRIPTION, "Blank test image");
  567. TIFFSetField(tiff_file, TIFFTAG_MAKE, "soft-switch.org");
  568. TIFFSetField(tiff_file, TIFFTAG_MODEL, "test data");
  569. time(&now);
  570. tm = localtime(&now);
  571. sprintf(buf,
  572. "%4d/%02d/%02d %02d:%02d:%02d",
  573. tm->tm_year + 1900,
  574. tm->tm_mon + 1,
  575. tm->tm_mday,
  576. tm->tm_hour,
  577. tm->tm_min,
  578. tm->tm_sec);
  579. TIFFSetField(tiff_file, TIFFTAG_DATETIME, buf);
  580. image_length = sequence[i].length;
  581. TIFFSetField(tiff_file, TIFFTAG_PAGENUMBER, 0, 1);
  582. TIFFSetField(tiff_file, TIFFTAG_CLEANFAXDATA, CLEANFAXDATA_CLEAN);
  583. TIFFSetField(tiff_file, TIFFTAG_ROWSPERSTRIP, 128);
  584. TIFFSetField(tiff_file, TIFFTAG_IMAGELENGTH, image_length);
  585. TIFFCheckpointDirectory(tiff_file);
  586. /* Write the image first.... */
  587. switch (sequence[i].type)
  588. {
  589. case 0:
  590. /* The DIAGO1 page */
  591. image_length = create_diago1_page(tiff_file);
  592. break;
  593. case 1:
  594. /* The DIAGO2 page */
  595. image_length = create_diago2_page(tiff_file);
  596. break;
  597. case 2:
  598. /* The DURATION1 page */
  599. image_length = create_duration1_page(tiff_file);
  600. break;
  601. case 3:
  602. /* The DURATION2 page */
  603. image_length = create_duration2_page(tiff_file);
  604. break;
  605. case 4:
  606. /* The ERROR page */
  607. image_length = create_error_page(tiff_file);
  608. break;
  609. case 5:
  610. /* The IMPRESS page */
  611. image_length = create_impress_page(tiff_file);
  612. break;
  613. case 6:
  614. /* A stairstep of 64 pixel dashes */
  615. image_length = create_stairstep_page(tiff_file);
  616. break;
  617. case 7:
  618. /* A white A4 page */
  619. image_length = create_white_page(tiff_file);
  620. break;
  621. }
  622. /* ....then the directory entry, and libtiff is happy. */
  623. if (image_length != sequence[i].length)
  624. {
  625. printf("Length mismatch - %d: %d vs %d\n", i, image_length, sequence[i].length);
  626. exit(2);
  627. }
  628. TIFFWriteDirectory(tiff_file);
  629. }
  630. if (tiff_file)
  631. TIFFClose(tiff_file);
  632. return 0;
  633. }
  634. /*- End of function --------------------------------------------------------*/
  635. /*- End of file ------------------------------------------------------------*/