"checkit_tiff" is an incredibly fast conformance checker for baseline TIFFs (with various 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.
87 lines
2.1 KiB
87 lines
2.1 KiB
/* rule based checks if given TIFF is a specific baseline TIFF
|
|
*
|
|
* author: Andreas Romeyke, 2015
|
|
* licensed under conditions of libtiff
|
|
* (see http://libtiff.maptools.org/misc.html)
|
|
*
|
|
*/
|
|
|
|
#include "check.h"
|
|
#include "check_helper.h"
|
|
#include <sys/stat.h>
|
|
#include <assert.h>
|
|
#ifndef _WIN32
|
|
#include <byteswap.h>
|
|
#endif
|
|
#ifdef _WIN32
|
|
#define bswap_16 _byteswap_ushort
|
|
#define bswap_32 _byteswap_ulong
|
|
#endif
|
|
/*
|
|
#define DEBUG
|
|
*/
|
|
|
|
/* dest should not exceed maxsize */
|
|
strbuff_t * secstrcat (strbuff_t * dest, const char * src) {
|
|
if (NULL != src) {
|
|
assert(NULL != dest );
|
|
size_t srclen = strlen(src);
|
|
if ((dest->pos + srclen) > dest->bufsize) {
|
|
fprintf(stderr, "max string length of dest + src (%zu + %zu) exceeds maxsize %zu\n", dest->pos, srclen, dest->bufsize);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
memcpy(dest->bufpos, src, srclen);
|
|
dest->bufpos += srclen;
|
|
// fprintf(stderr, "DEBUG: dest->pos=%zu, src len=%zu", dest->pos, srclen);
|
|
dest->pos += srclen;
|
|
// fprintf(stderr, " new dest_pos=%zu\n", dest->pos);
|
|
}
|
|
return dest;
|
|
}
|
|
|
|
char * float2str(float v) {
|
|
char array[VALUESTRLEN];
|
|
snprintf(array, sizeof(array), "%f", v);
|
|
return strdup(array);
|
|
}
|
|
|
|
char* int2str(int v) {
|
|
char array[VALUESTRLEN];
|
|
snprintf(array, sizeof(array), "%i", v);
|
|
return strdup(array);
|
|
}
|
|
|
|
char* frac2str(int d, int n) {
|
|
char array[VALUESTRLEN];
|
|
snprintf(array, sizeof(array), "%i/%i", d, n);
|
|
return strdup(array);
|
|
}
|
|
|
|
void TIFFSwabShort(uint16 *a) {
|
|
*a = bswap_16( *a );
|
|
}
|
|
|
|
void TIFFSwabLong(uint32 *a) {
|
|
*a = bswap_32( *a );
|
|
}
|
|
|
|
long long fsize(int fd) {
|
|
struct stat st;
|
|
fstat(fd, &st);
|
|
return st.st_size;
|
|
}
|
|
|
|
|
|
ret_t set_value_found_ret (ret_t * rp, const char * msg) {
|
|
assert( NULL != rp);
|
|
assert( NULL != msg);
|
|
rp->value_found=calloc(VALUESTRLEN, sizeof(char));
|
|
if (NULL == rp->value_found) {
|
|
rp->returncode=could_not_allocate_memory;
|
|
} else {
|
|
strncpy(rp->value_found, msg, VALUESTRLEN-1);
|
|
// printf("DEBUG2='%s'\n", rp->value_found);
|
|
}
|
|
return *rp;
|
|
}
|
|
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/
|