|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
extending tags in "a"ppend mode?Hi list,
should it be possible to extend the tags of (the first directory of) an existing tiff file opened in "a"ppend mode? What I'm trying to do is: + open an existing tiff file with TIFFOpen(...,"a") + create an array of TIFFFieldInfo + call TIFFMergeFieldInfo() with this array and count + Write some (string) tags that were defined in the array + close the tiff handle with TIFFClose() It seems that TIFFClose() hangs somewhere and doesn't return, which is why I suspect that what I'm trying to do is impossible. Juergen _______________________________________________ Tiff mailing list: Tiff@... http://lists.maptools.org/mailman/listinfo/tiff http://www.remotesensing.org/libtiff/ |
|
|
Re: extending tags in "a"ppend mode?Juergen Buchmueller wrote:
> Hi list, > > should it be possible to extend the tags of (the first directory of) an > existing tiff file opened in "a"ppend mode? > > What I'm trying to do is: > + open an existing tiff file with TIFFOpen(...,"a") > + create an array of TIFFFieldInfo > + call TIFFMergeFieldInfo() with this array and count > + Write some (string) tags that were defined in the array > + close the tiff handle with TIFFClose() > > It seems that TIFFClose() hangs somewhere and doesn't return, which is > why I suspect that what I'm trying to do is impossible. Juergen, It should be possible to extend the first directory with new tags by opening in "r+" (update) mode, setting the tags and closing. I don't know why you are seeing the behavior you encountered. I would have expected it to attempt to append a new image directory and complain about your not providing a complete set of tags to define an image. It might be helpful if you provided a minimal program and file demonstrating your problem. Also, in place update of directories is always an iffy procedure with libtiff but I would strongly encourage using the most recent release (3.9.1?) if you are trying this. Best regards, -- ---------------------------------------+-------------------------------------- I set the clouds in motion - turn up | Frank Warmerdam, warmerdam@... light and sound - activate the windows | http://pobox.com/~warmerdam and watch the world go round - Rush | Geospatial Programmer for Rent _______________________________________________ Tiff mailing list: Tiff@... http://lists.maptools.org/mailman/listinfo/tiff http://www.remotesensing.org/libtiff/ |
|
|
Re: extending tags in "a"ppend mode?On Wed, 28 Oct 2009 12:02:09 -0400
Frank Warmerdam <warmerdam@...> wrote: > Juergen, > > It should be possible to extend the first directory with new tags by opening > in "r+" (update) mode, setting the tags and closing. I don't know why you are > seeing the behavior you encountered. I would have expected it to attempt to > append a new image directory and complain about your not providing a complete > set of tags to define an image. Ok, I didn't know that "r+" was supported because it isn't mentioned in the docs. > It might be helpful if you provided a minimal program and file demonstrating > your problem. See attachment. This crashes when I try to run it on the file: http://pmbits.ath.cx/RECV002.TIF Compiled with (adapt include + lib paths): gcc -I/usr/pkg/include -Wl,-R/usr/pkg/lib \ -L/usr/pkg/lib -ltiff -o addtags addtags.c Run with: ./addtags somewhere/RECV002.TIF Stack backtrace: Program terminated with signal 11, Segmentation fault. #0 0x00007f7ffd98eb6a in _malloc_prefork () from /usr/lib/libc.so.12 (gdb) bt #0 0x00007f7ffd98eb6a in _malloc_prefork () from /usr/lib/libc.so.12 #1 0x00007f7ffd98edde in free () from /usr/lib/libc.so.12 #2 0x00007f7ffdc08959 in TIFFCleanup () from /usr/pkg/lib/libtiff.so.3 #3 0x00007f7ffdc089e1 in TIFFClose () from /usr/pkg/lib/libtiff.so.3 #4 0x0000000000400dbe in main () To me it looks like a double free() of some kind!? > Also, in place update of directories is always an iffy procedure with libtiff > but I would strongly encourage using the most recent release (3.9.1?) if you > are trying this. Yes, on my system (NetBSD-5.0.1) there is libtiff-3.9.1 installed. Thanks, Juergen #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <tiffio.h> static const char *some_strings[] = { "Hello, world!", "foo", "bar", "baz" }; int main(int argc, char **argv) { TIFF *hTIFF; TIFFFieldInfo *apptags; char buff[32]; const char *str; uint32_t n, ntags; int32_t res; hTIFF = TIFFOpen(argv[1], "r+"); ntags = 3; apptags = calloc(ntags, sizeof(TIFFFieldInfo)); for (n = 0; n < ntags; n++) { uint16_t id = 10000 + n; apptags[n].field_tag = id; apptags[n].field_readcount = TIFF_VARIABLE; apptags[n].field_writecount = TIFF_VARIABLE; apptags[n].field_type = TIFF_ASCII; apptags[n].field_bit = FIELD_CUSTOM; apptags[n].field_oktochange = 1; apptags[n].field_passcount = 0; snprintf(buff, sizeof(buff), "Tag %d", id); apptags[n].field_name = strdup(buff); } TIFFMergeFieldInfo(hTIFF, apptags, ntags); for (n = 0; n < ntags; n++) { str = some_strings[n]; res = TIFFSetField(hTIFF, apptags[n].field_tag, str); printf("set tag:%u to \"%s\" res:%d\n", apptags[n].field_tag, str, res); } TIFFClose(hTIFF); for (n = 0; n < ntags; n++) { if (apptags[n].field_name) free(apptags[n].field_name); } free(apptags); return 0; } _______________________________________________ Tiff mailing list: Tiff@... http://lists.maptools.org/mailman/listinfo/tiff http://www.remotesensing.org/libtiff/ |
|
|
Re: extending tags in "a"ppend mode?On Wed, 28 Oct 2009 17:28:34 +0100
Juergen Buchmueller <pullmoll@...> wrote: > See attachment. This crashes when I try to run it on the file: Funny enough the crash goes away if I choose a different name for my own tags. Perhaps a collision or lazy assumption with the autogenerated names (which would be the same)? - snprintf(buff, sizeof(buff), "Tag %d", id); + snprintf(buff, sizeof(buff), "test%d", id); Now the test program runs without error message, yet the TIFF file doesn't contain the new tags. Hmm... Juergen _______________________________________________ Tiff mailing list: Tiff@... http://lists.maptools.org/mailman/listinfo/tiff http://www.remotesensing.org/libtiff/ |
|
|
Re: extending tags in "a"ppend mode? - solvedOk, the problem seems to be solved now.
I need to choose tag names different from the ones that libtiff would use on the auto-registration when reading a file, and I need to call TIFFWriteDirectory() after writing the tags and before closing the file again. Perhaps this little episode helps others in similiar situations. Cheers, Juergen _______________________________________________ Tiff mailing list: Tiff@... http://lists.maptools.org/mailman/listinfo/tiff http://www.remotesensing.org/libtiff/ |
| Free embeddable forum powered by Nabble | Forum Help |