Browse Source

- added brackets

development
Andreas Romeyke 2 years ago
parent
commit
47fa5e10d0
1 changed files with 44 additions and 26 deletions
  1. +44
    -26
      src/helper/check_tiffparse.c

+ 44
- 26
src/helper/check_tiffparse.c View File

@ -234,9 +234,9 @@ ret_t parse_header_and_endianess(ctiff_t * ctif) {
ret.returncode=tiff_read_error_header;
return ret;
}
if (header == 0x4949) endianness = 0; /* little endian */
else if (header == 0x4d4d) endianness = 1; /* big endian */
else {
if (header == 0x4949) { endianness = 0; /* little endian */
} else if (header == 0x4d4d) { endianness = 1; /* big endian */
} else {
char errmsg[VALUESTRLEN]="";
snprintf (errmsg, VALUESTRLEN, "TIFF Header error, not Byte Order Bytes for TIFF: 0x%04x", header);
if (header == 0x4550) {
@ -263,13 +263,20 @@ ret_t parse_header_and_endianess(ctiff_t * ctif) {
} else {
char errmsg[VALUESTRLEN]="";
snprintf (errmsg, VALUESTRLEN, "TIFF Header error, not a MAGIC BYTE for TIFF: 0x%04x\n", magic);
if (magic2==0x002b) strcat(errmsg, ", but could be a BigTIFF, see http://www.awaresystems.be/imaging/tiff/bigtiff.html");
if (magic2==0x0055) strcat(errmsg, ", but could be a Panasonic Raw/RW2, see http://libopenraw.freedesktop.org/wiki/Panasonic_RAW/");
if (magic2==0x01bc) strcat(errmsg, ", but could be a JPEG XR, see http://www.itu.int/rec/T-REC-T.832");
if (magic2==0x314e) strcat(errmsg, ", but could be a Navy Image FileFormat, see http://www.navsea.navy.mil/nswc/carderock/tecinfsys/cal-std/doc/28002c.pdf");
if (magic2==0x4352) strcat(errmsg, ", but could be a DNG camera profile, see http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/photoshop/pdfs/dng_spec_1.4.0.0.pdf");
if (magic2==0x4f52) strcat(errmsg, ", but could be an Olympus ORF, see http://libopenraw.freedesktop.org/wiki/Olympus_ORF/");
if (magic2==0x5352) strcat(errmsg, ", but could be an Olympus ORF, see http://libopenraw.freedesktop.org/wiki/Olympus_ORF/");
if (magic2==0x002b) { strcat(errmsg, ", but could be a BigTIFF, see http://www.awaresystems.be/imaging/tiff/bigtiff.html");
}
if (magic2==0x0055) { strcat(errmsg, ", but could be a Panasonic Raw/RW2, see http://libopenraw.freedesktop.org/wiki/Panasonic_RAW/");
}
if (magic2==0x01bc) { strcat(errmsg, ", but could be a JPEG XR, see http://www.itu.int/rec/T-REC-T.832");
}
if (magic2==0x314e) { strcat(errmsg, ", but could be a Navy Image FileFormat, see http://www.navsea.navy.mil/nswc/carderock/tecinfsys/cal-std/doc/28002c.pdf");
}
if (magic2==0x4352) { strcat(errmsg, ", but could be a DNG camera profile, see http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/photoshop/pdfs/dng_spec_1.4.0.0.pdf");
}
if (magic2==0x4f52) { strcat(errmsg, ", but could be an Olympus ORF, see http://libopenraw.freedesktop.org/wiki/Olympus_ORF/");
}
if (magic2==0x5352) { strcat(errmsg, ", but could be an Olympus ORF, see http://libopenraw.freedesktop.org/wiki/Olympus_ORF/");
}
ret = set_value_found_ret(&ret, errmsg);
ret.returncode = tiff_byteorder_error;
}
@ -317,8 +324,9 @@ ret_t get_first_IFD(ctiff_t * ctif, uint32 * ifd) {
return ret;
}
if (is_byteswapped(ctif))
if (is_byteswapped(ctif)) {
TIFFSwabShort(&count);
}
ctif->ifd0c = count;
*ifd = offset;
ret.returncode=is_valid;
@ -344,8 +352,9 @@ tag_t TIFFGetRawTagListEntry( ctiff_t * ctif, int tagidx ) {
// exit( EXIT_FAILURE );
return 0;
}
if (byteswapped)
if (byteswapped) {
TIFFSwabShort(&tagid);
}
//printf("tag idx=%i, tag=%u (0x%04x) (0x%02x) (0x%02x)\n", i, tagid, tagid, hi, lo);
return tagid;
}
@ -387,18 +396,20 @@ tag_t TIFFGetRawTagListEntry( ctiff_t * ctif, int tagidx ) {
}
void offset_swabshort(ctiff_t * ctif, uint16 * address, uint16 count) {
if (is_byteswapped(ctif))
if (is_byteswapped(ctif)) {
for (int i=0; i<count; i++, address++) {
TIFFSwabShort( address );
}
}
}
void offset_swablong(ctiff_t * ctif, uint32 * address, uint16 count) {
if (is_byteswapped(ctif))
if (is_byteswapped(ctif)) {
for (int i=0; i<count; i++, address++) {
TIFFSwabLong( address );
}
}
}
/* get count-data datastream from offset-address */
ret_t read_offsetdata(ctiff_t * ctif, const uint32 address, const uint32 count, const uint16 datatype, offset_t * offset_p, ret_t * ret_p) {
assert(NULL != offset_p);
@ -427,7 +438,7 @@ ret_t read_offsetdata(ctiff_t * ctif, const uint32 address, const uint32 count,
OFFSET_MALLOC(ctif, offset_p->data8p, uint8, count)
break;
case 2: /* 8-bit bytes w/ last byte null */
assert( sizeof(char) == sizeof(uint8));
static_assert( sizeof(char) == sizeof(uint8), "");
OFFSET_MALLOC(ctif, offset_p->datacharp, char, count)
break;
case 6: /* !8-bit signed integer */
@ -458,20 +469,20 @@ ret_t read_offsetdata(ctiff_t * ctif, const uint32 address, const uint32 count,
fprintf(stderr, "offsetdata datatype=%i not supported yet", datatype);
exit(EXIT_FAILURE);
case 11: /* !32-bit IEEE floating point */
assert( sizeof(float) == 4);
static_assert( sizeof(float) == 4, "");
OFFSET_MALLOC(ctif, offset_p->datafloatp, float, count)
break;
case 12: /* !64-bit IEEE floating point */
assert( sizeof(double) == 8);
static_assert( sizeof(double) == 8, "");
OFFSET_MALLOC(ctif, offset_p->datadoublep, double, count)
break;
case 16: /* BigTIFF 64-bit unsigned integer */
case 18: /* BigTIFF 64-bit unsigned integer (offset) */
assert( sizeof(double) == 8);
static_assert( sizeof(double) == 8, "");
OFFSET_MALLOC(ctif, offset_p->data64p, uint64, count)
break;
case 17: /* BigTIFF 64-bit signed integer */
assert( sizeof(double) == 8);
static_assert( sizeof(double) == 8, "");
OFFSET_MALLOC(ctif, offset_p->datas64p, int64, count)
break;
default: /* should not occur */
@ -511,24 +522,27 @@ ifd_entry_t TIFFGetRawTagIFDListEntry( ctiff_t * ctif, int tagidx ) {
perror ("TIFF Header ct_read error2, reading tagid from ifd0 (2bytes)");
return ifd_entry;
}
if (byteswapped)
if (byteswapped) {
TIFFSwabShort(&tagid);
}
// tag type check
uint16 tagtype;
if ( ct_read( ctif, &tagtype, 2) != 2) {
perror ("TIFF Header ct_read error2, reading tagtype from ifd0 (2bytes)");
return ifd_entry;
}
if (byteswapped)
if (byteswapped) {
TIFFSwabShort(&tagtype);
}
uint32 count;
if ( ct_read( ctif, &count, 4) != 4) {
perror ("TIFF Header ct_read error4, reading count from ifd0 (4bytes)");
return ifd_entry;
}
if (byteswapped)
if (byteswapped) {
TIFFSwabLong( &count);
}
#ifdef DEBUG
printf("\ncount=%0x\n\n", count);
#endif
@ -542,8 +556,9 @@ ifd_entry_t TIFFGetRawTagIFDListEntry( ctiff_t * ctif, int tagidx ) {
perror ("TIFF Header ct_read error4, reading value/offset from ifd0 (4bytes)");
return ifd_entry;
}
if (byteswapped)
if (byteswapped) {
TIFFSwabLong( &value_or_offset);
}
switch( tagtype) {
case 1: /* 8-bit unsigned integer */
case 2: /* 8-bit bytes w/ last byte null */
@ -729,7 +744,8 @@ ctiff_t * initialize_ctif(const char * tiff_file, ct_ioflag_t ioflag) {
void free_ctif( ctiff_t * ctif) {
assert( NULL != ctif);
if (NULL != ctif->filename) free(ctif->filename);
if (NULL != ctif->filename) { free(ctif->filename);
}
ctif->filename=NULL;
switch (ctif->ioflag) {
case is_filep: {
@ -774,8 +790,9 @@ uint32 get_next_ifd_pos(ctiff_t * ctif, uint32 actual_pos) {
return 0;
}
if (ctif->isbyteswapped)
if (ctif->isbyteswapped) {
TIFFSwabShort(&count);
}
ct_seek(ctif, 12 * count, SEEK_CUR);
uint32 offset;
if ( ct_read( ctif, &offset, 4) != 4 ) {
@ -784,8 +801,9 @@ uint32 get_next_ifd_pos(ctiff_t * ctif, uint32 actual_pos) {
//exit( EXIT_FAILURE );
return 0;
}
if (ctif->isbyteswapped)
if (ctif->isbyteswapped) {
TIFFSwabLong(&offset);
}
return offset;
}


Loading…
Cancel
Save