Browse Source

- improved help

- fixed logical-or in cleantag checks
- removed superflous assertion
- fixed comment
- fixed some printf-warnings
tags/v0.1.2
Andreas Romeyke 2 years ago
parent
commit
85b2379684
8 changed files with 45 additions and 45 deletions
  1. +2
    -2
      src/archeological_tools/find_potential_IFD_offsets.c
  2. +4
    -4
      src/check_icc_header.c
  3. +8
    -8
      src/cleanup_baseline.c
  4. +5
    -6
      src/cleanup_tag.c
  5. +7
    -7
      src/cleanup_tagtypes.c
  6. +11
    -10
      src/fixit_tiff.c
  7. +2
    -2
      src/fixit_tiff.h
  8. +6
    -6
      src/tiff_helper.c

+ 2
- 2
src/archeological_tools/find_potential_IFD_offsets.c View File

@@ -52,7 +52,7 @@ void scan_file_for_ifds(const char * infile, const char * outfile) {
/* for each odd address, do */
for (uint32 address = 8; address < filesize; address+=2) {
if (address % 1024 == 0) {
printf ("\r%li %%", (uint64) 100*address/filesize);
printf ("\r%lu %%", (uint64) 100*address/filesize);
}
lseek( fd_in, address, SEEK_SET);
/* check if "count of tags" is greater 4 (hard criteria) */
@@ -75,7 +75,7 @@ void scan_file_for_ifds(const char * infile, const char * outfile) {
has_baselinetags[i]=0;
}
int sorted = 0;
lseek( fd_in, address
lseek( fd_in, address
+ 2 /* countoftags */
, SEEK_SET);
int last_tagid = 0;


+ 4
- 4
src/check_icc_header.c View File

@@ -1,7 +1,7 @@
/* checks ICC Profile, using Spec http://www.color.org/specification/ICC1v43_2010-12.pdf */
#include "fixit_tiff.h"
#include "check_icc_header.h"
/*
/*
#define USE_WARNING
#ifdef USE_WARNING
#define FAIL(...) {fprintf(stderr, __VA_ARGS__); return 1;};
@@ -117,7 +117,7 @@ int parse_icc_header_v240_v430(unsigned long iccsize, char * iccdata, unsigned l
) FAIL("connection space data ('%s') should be one of following strings: 'XYZ ' 'Lab '", connectionspacedata);
/* -- */
// datetime 24-35
char datetime[20]; snprintf(datetime, 20, "%.4d:%.2d:%.2d %.2d:%.2d:%.2d",
char datetime[20]; snprintf(datetime, 20, "%.4d:%.2d:%.2d %.2d:%.2d:%.2d",
((iccdata[24] & 0x00ff)<<8 | (iccdata[25] & 0x00ff)), // yyyy
((iccdata[26] & 0x00ff)<<8 | (iccdata[27] & 0x00ff)), // MM
((iccdata[28] & 0x00ff)<<8 | (iccdata[29] & 0x00ff)), // DD
@@ -222,12 +222,12 @@ int check_icc_header (const char * filename ) {
fprintf( stderr, "file '%s' could not be opened\n", filename);
exit (FIXIT_TIFF_READ_PERMISSION_ERROR);
};
/* find date-tag and fix it */
/* find icc-tag and fix it */
char *iccprofile=NULL;
uint32 count=0;
int returncode = 0;
int found=TIFFGetField(tif, TIFFTAG_ICCPROFILE, &count, &iccprofile);
if (1==found) { /* there exists a datetime field */
if (1==found) { /* there exists a ICC profile field */
unsigned long errsize=1024;
char errmsg[errsize];
returncode = parse_icc(count, iccprofile, errsize, errmsg);


+ 8
- 8
src/cleanup_baseline.c View File

@@ -1,10 +1,10 @@
/* fixes broken TIFF Files
*
*
* fixes unused tags in Baseline-TIFFs,
* based on http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
*
* author: Andreas Romeyke, 2013
* licensed under conditions of libtiff
* licensed under conditions of libtiff
*/


@@ -37,19 +37,19 @@ int cleanup_baseline(const char * filename ) {
/* iterate through all tiff-tags in tiff file
* delete all tags not in baselinetags
*/
for (tagidx=0; tagidx < tag_counter; tagidx++) {
printf ("found tag %i [0x%x] (%i)\n", tags[tagidx],tags[tagidx], tagidx);
for (tagidx=0; tagidx < tag_counter; tagidx++) {
printf ("found tag %u [0x%x] (%u)\n", tags[tagidx],tags[tagidx], tagidx);
int found = 0;
int baseline_index=0;
for (baseline_index = 0; baseline_index < count_of_baselinetags; baseline_index++) {
if (tags[tagidx] == baselinetags[baseline_index]) {
printf ("DEBUG tag=%i base=%i idx=%i\n", tags[tagidx], baselinetags[baseline_index], baseline_index);
found = 1;
if (tags[tagidx] == baselinetags[baseline_index]) {
printf ("DEBUG tag=%u base=%i idx=%i\n", tags[tagidx], baselinetags[baseline_index], baseline_index);
found = 1;
break;
}
}
if (found == 0 ) {
if (FLAGGED == flag_be_verbose) printf("removed tag %i\n", tags[tagidx]);
if (FLAGGED == flag_be_verbose) printf("removed tag %u\n", tags[tagidx]);
TIFFUnsetField(tif, tags[tagidx]);
}
}


+ 5
- 6
src/cleanup_tag.c View File

@@ -1,10 +1,10 @@
/* fixes broken TIFF Files
*
*
* fixes unused tags in Baseline-TIFFs,
* based on http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
*
* author: Andreas Romeyke, 2013
* licensed under conditions of libtiff
* licensed under conditions of libtiff
*/


@@ -39,7 +39,7 @@ int cleanup_tag(const char * filename, uint32 tag_to_remove ) {
for (tagidx=0; tagidx < tag_counter; tagidx++) {
uint32 tag = TIFFGetRawTagListEntry( tif, tagidx );
if (tag == tag_to_remove) {
if (FLAGGED == flag_be_verbose) printf("removed tag %i\n", tags[tagidx]);
if (FLAGGED == flag_be_verbose) printf("removed tag %u\n", tags[tagidx]);
/* via TIFFGetRawTagListEntry we have the tag read
* now we should seek 10 bytes forward and read the entire IFD block until (including) end
* then we should seek n*12 + 4 bytes backward and write
@@ -48,12 +48,12 @@ int cleanup_tag(const char * filename, uint32 tag_to_remove ) {
* count-1
*/
off_t actual_pos = lseek(fd, -2, SEEK_CUR);
if (actual_pos < 0) {
if (actual_pos < 0) {
perror("TIFF seek error in IFD0");
exit(EXIT_FAILURE);
}
off_t next_tag = lseek(fd, 12, SEEK_CUR); /* 12 bytes forward to next IFD */
if (next_tag < 0) {
if (next_tag < 0) {
perror("TIFF seek error in IFD0");
exit(EXIT_FAILURE);
}
@@ -92,7 +92,6 @@ int cleanup_tag(const char * filename, uint32 tag_to_remove ) {
if (TIFFIsByteSwapped(tif))
TIFFSwabShort(&count);
count--;
assert(count >= 0);
if (TIFFIsByteSwapped(tif)) // Swab again to write correctly out
TIFFSwabShort(&count);
//printf("(-1) count=%i (0x%04x)\n", count, count);


+ 7
- 7
src/cleanup_tagtypes.c View File

@@ -1,10 +1,10 @@
/* fixes broken TIFF Files
*
*
* fixes wrong tagtypes of tags in Baseline-TIFFs,
* based on http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
*
* author: Andreas Romeyke, 2013-2017
* licensed under conditions of libtiff
* licensed under conditions of libtiff
*/


@@ -41,7 +41,7 @@ const char * _tagtype( uint16 tagtype ) {
void _replace_type(TIFF * tif, uint32 tag, uint16 found, uint16 newtype) {
if (TIFFIsByteSwapped(tif))
TIFFSwabShort(&newtype);
printf("found fieldtype=%s (%i) for tag=%i, try to repair with type=%s (%i)\n", _tagtype(found), found, tag, _tagtype(newtype), newtype);
printf("found fieldtype=%s (%i) for tag=%u, try to repair with type=%s (%i)\n", _tagtype(found), found, tag, _tagtype(newtype), newtype);
/* via TIFFGetRawTagListEntry we have the tag
* read, the next 2 bytes are the type */
int fd = TIFFFileno( tif);
@@ -72,10 +72,10 @@ int cleanup_tagtype(const char * filename, uint32 tag_to_fix ) {
for (tagidx=0; tagidx < tag_counter; tagidx++) {
uint32 tag = TIFFGetRawTagListEntry( tif, tagidx );
if (tag == tag_to_fix) {
if (FLAGGED == flag_be_verbose) printf("tag to fix %i\n", tags[tagidx]);
if (FLAGGED == flag_be_verbose) printf("tag to fix %u\n", tags[tagidx]);
const struct _TIFFField * fip = TIFFFieldWithTag(tif, tag);
if (NULL == fip) {
fprintf(stderr, "tagtype correction for tag %i fails, because requested tag does not exist (file '%s')\n", tag, filename);
fprintf(stderr, "tagtype correction for tag %u fails, because requested tag does not exist (file '%s')\n", tag, filename);
exit (FIXIT_TIFF_CMDLINE_ARGUMENTS_ERROR);
}
switch (tag) {
@@ -97,8 +97,8 @@ int cleanup_tagtype(const char * filename, uint32 tag_to_fix ) {
}
break;
}
default:
fprintf(stderr, "tagtype correction for tag %i not supported yet (file '%s')\n", tag, filename);
default:
fprintf(stderr, "tagtype correction for tag %u not supported yet (file '%s')\n", tag, filename);
exit (FIXIT_TIFF_CMDLINE_ARGUMENTS_ERROR);
}
}


+ 11
- 10
src/fixit_tiff.c View File

@@ -1,10 +1,10 @@
/* fixes broken TIFF Files
*
*
* fixes invalid DateTime-field in Baseline-TIFFs,
* based on http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
*
* author: Andreas Romeyke, 2013
* licensed under conditions of libtiff
* licensed under conditions of libtiff
*/


@@ -26,15 +26,16 @@ void help () {
printf ("\t-q disables describing messages\n");
printf ("\t-t try to fix tagorder (dangerous)\n");
printf ("\t-x tag clean tiff from given tag\n");
printf ("\t-p try to repair preferred CMM type in ICC header profile (autocorrect misspelled entries or erase 'Lino' to zero)\n");
printf ("\t-p try to repair ICC header profile, correct preferred CMM type (autocorrect misspelled entries or erase 'Lino' to zero)\n");
printf ("\t or to fix CMM version (replaces only the version-string)\n");
printf ("\t-e try to repair wrong tagtype\n");
printf ("\tHint: 'fixit_tiff -i <infile> -o <outfile>' repairs date only\n");
}


/** copy infile to outfile
* @param inf string with infile name
* @param outf string with outfile name
/** copy infile to outfile
* @param inf string with infile name
* @param outf string with outfile name
*/
void copy_file (const char * inf, const char * outf) {
FILE * in = fopen( inf, "rb");
@@ -92,7 +93,7 @@ int main (int argc, char * argv[]) {
flag_tagorder=FLAGGED;
break;
case 'c': /* reports only if repair needed */
flag_check_only = FLAGGED;
flag_check_only = FLAGGED;
break;
case 'q': /* disables describing messages */
flag_be_verbose = UNFLAGGED;
@@ -128,7 +129,7 @@ int main (int argc, char * argv[]) {
}
/* added additional checks */
/* TODO: add check that no inline and no check if cleantag */
if ((UNFLAGGED != clean_tag) && (clean_tag < 254) || (clean_tag > 65535)) {
if ((UNFLAGGED != clean_tag) && ((clean_tag < 254) || (clean_tag > 65535))) {
fprintf(stderr, "The option '-x' expects a value in range 254..65535, see '%s -h' for details\n", argv[0]);
exit(FIXIT_TIFF_CMDLINE_ARGUMENTS_ERROR);
}
@@ -156,8 +157,8 @@ int main (int argc, char * argv[]) {

exit (
check_required(infilename) ||
check_baseline(infilename) ||
check_datetime(infilename)
check_baseline(infilename) ||
check_datetime(infilename)
);

}


+ 2
- 2
src/fixit_tiff.h View File

@@ -24,7 +24,7 @@
#define FIXIT_TIFF_WRITE_ERROR -22
#define FIXIT_TIFF_READ_ERROR -23

/** 20 comes from TIFF definition
/** 20 comes from TIFF definition
*/
#define TIFFDATETIMELENGTH 20

@@ -98,5 +98,5 @@ const static uint32 required_baselinetags[count_of_required_baselinetags]={



#endif
#endif
/* _FIXIT_TIFF */

+ 6
- 6
src/tiff_helper.c View File

@@ -1,10 +1,10 @@
/* fixes broken TIFF Files
*
*
* fixes unused tags in Baseline-TIFFs,
* based on http://www.awaresystems.be/imaging/tiff/tifftags/baseline.html
*
* author: Andreas Romeyke, 2013
* licensed under conditions of libtiff
* licensed under conditions of libtiff
*/


@@ -23,7 +23,7 @@ int TIFFGetRawTagListCount (TIFF * tif) {
if (TIFFIsByteSwapped(tif))
TIFFSwabLong(&offset);
// printf("diroffset to %i (0x%04lx)\n", offset, offset);
//printf("byte swapped? %s\n", (TIFFIsByteSwapped(tif)?"true":"false"));
//printf("byte swapped? %s\n", (TIFFIsByteSwapped(tif)?"true":"false"));
/* read and seek to IFD address */
lseek(fd, (off_t) offset, SEEK_SET);
uint16 count;
@@ -64,7 +64,7 @@ void print_baseline_tags (TIFF * tif) {
printf ("tag count=%i, [*] means: tag is a baseline tag\n", tag_counter);
for (tagidx=0; tagidx < tag_counter; tagidx++) {
tags[tagidx] = TIFFGetRawTagListEntry( tif, tagidx );
}
}
for (tagidx=0; tagidx < tag_counter; tagidx++) {
int found = 0;
for (i=0; i<count_of_baselinetags; i++) {
@@ -74,7 +74,7 @@ void print_baseline_tags (TIFF * tif) {
break;
}
}
printf ("\ttag %5i (0x%4x) %s\n", tags[tagidx], tags[tagidx], (found==1?"[*]":""));
printf ("\ttag %5u (0x%4x) %s\n", tags[tagidx], tags[tagidx], (found==1?"[*]":""));
}
}

@@ -86,7 +86,7 @@ void print_required_tags (TIFF * tif) {
printf ("[*] means: tag already exists\n");
for (tagidx=0; tagidx < tag_counter; tagidx++) {
tags[tagidx] = TIFFGetRawTagListEntry( tif, tagidx );
}
}
for (i=0; i<count_of_required_baselinetags; i++) {
int found = 0;
for (tagidx=0; tagidx < tag_counter; tagidx++) {


Loading…
Cancel
Save