tool to fixes some issues in baseline tiffs (with extensions), see http://andreas-romeyke.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 lines
3.2 KiB

  1. /* fixes broken TIFF Files
  2. *
  3. * fixes unused tags in Baseline-TIFFs,
  4. * based on http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
  5. *
  6. * author: Andreas Romeyke, 2013
  7. * licensed under conditions of libtiff
  8. */
  9. #include "fixit_tiff.h"
  10. #include "tiff_helper.h"
  11. #include "check_baseline.h"
  12. #include <tiffio.h>
  13. /** loads a tiff, checks if all tags are only baseline tags
  14. * @param filename filename which should be processed
  15. */
  16. int check_baseline(const char * filename ) {
  17. /* load file */
  18. TIFF* tif = TIFFOpen(filename, "r");
  19. if (NULL == tif) {
  20. fprintf( stderr, "file '%s' could not be opened\n", filename);
  21. exit (FIXIT_TIFF_READ_PERMISSION_ERROR);
  22. };
  23. uint32 tag_counter=TIFFGetRawTagListCount(tif);
  24. uint32 tagidx;
  25. uint32 tags[tag_counter];
  26. for (tagidx=0; tagidx < tag_counter; tagidx++) {
  27. tags[tagidx] = TIFFGetRawTagListEntry( tif, tagidx );
  28. }
  29. /* check if only baselinetags are exists,
  30. * iterate through all tiff-tags in tiff file
  31. */
  32. for (tagidx=0; tagidx < tag_counter; tagidx++) {
  33. int found = 0;
  34. int baseline_index=0;
  35. for (baseline_index = 0; baseline_index < count_of_baselinetags; baseline_index++) {
  36. if (tags[tagidx] == baselinetags[baseline_index]) {
  37. found = 1;
  38. break;
  39. }
  40. }
  41. if (found == 0 ) {
  42. if (FLAGGED == flag_be_verbose) {
  43. printf("tiff is not a baseline, because it has additional tags for baseline rgb\n");
  44. printf("these tags are allowed only:\n");
  45. print_baseline_tags(tif);
  46. }
  47. return FIXIT_TIFF_IS_CHECKED;
  48. }
  49. }
  50. TIFFClose(tif);
  51. if (FLAGGED == flag_be_verbose) printf("tiff comes only with allowed tags for baseline rgb\n");
  52. return FIXIT_TIFF_IS_VALID;
  53. }
  54. /** loads a tiff, check if all required baselinetags exists
  55. * @param filename filename which should be processed
  56. */
  57. int check_required (const char * filename ) {
  58. /* load file */
  59. TIFF* tif = TIFFOpen(filename, "r");
  60. if (NULL == tif) {
  61. fprintf( stderr, "file '%s' could not be opened\n", filename);
  62. exit (FIXIT_TIFF_READ_PERMISSION_ERROR);
  63. };
  64. printf("these tags are required:\n");
  65. print_required_tags(tif);
  66. int tag_counter=TIFFGetRawTagListCount(tif);
  67. int tagidx;
  68. uint32 tags[tag_counter];
  69. for (tagidx=0; tagidx < tag_counter; tagidx++) {
  70. tags[tagidx] = TIFFGetRawTagListEntry( tif, tagidx );
  71. }
  72. /* check if only baselinetags are exists,
  73. * iterate through all tiff-tags in tiff file
  74. */
  75. int found = 0;
  76. for (tagidx=0; tagidx < tag_counter; tagidx++) {
  77. int baseline_index=0;
  78. for (baseline_index = 0; baseline_index < count_of_required_baselinetags; baseline_index++) {
  79. if (tags[tagidx] == required_baselinetags[baseline_index]) {
  80. found++;
  81. break;
  82. }
  83. }
  84. }
  85. printf("##### found=%i required=%i\n", found, count_of_required_baselinetags);
  86. if (found != count_of_required_baselinetags ) {
  87. if (FLAGGED == flag_be_verbose) {
  88. printf("tiff does not have all required tags for baseline rgb\n");
  89. printf("these tags are required:\n");
  90. print_required_tags(tif);
  91. }
  92. return FIXIT_TIFF_IS_CHECKED;
  93. }
  94. TIFFClose(tif);
  95. if (FLAGGED == flag_be_verbose) printf("tiff comes with all required tags for baseline rgb\n");
  96. return FIXIT_TIFF_IS_VALID;
  97. }