Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I delete tiff tags using the LibTiff.Net 2.3 library

I can't seem to find any documentation of how to delete a tiff tag using the LibTiff.Net library. I love the library but this one method is important to what I need to do. At one point I was hoping that I could just set a tag and set it's value to nothing. I had hoped that would work but that was a negative.

Anyone know how to delete a tiff tag using the LibTiff.Net library?

like image 663
Arvo Bowen Avatar asked Feb 24 '12 02:02

Arvo Bowen


People also ask

What is liblibtiff TIFF?

LibTiff.Net provides support for the Tag Image File Format (TIFF), a widely used format for storing image data.

Can I use TIFF tags in the library?

While the TIFF specification permits an arbitrary set of tags to be defined and used in a file, the library only understands a limited set of tags. Any unknown tags that are encountered in a file are ignored.

How do I use libtiff in my code?

Using LIBTIFF in your code. #include <tiffio.h> TIFF *tif=TIFFOpen ("input.tif", "r"); [Note: Though it works under Win32, you should not use the C-"malloc/free" and the C++-"new/delete" functions/operators to do the memory management for the reading buffer]

Is it possible to edit the contents of TIFF file?

Note that unlike the stdio library TIFF image files may not be opened for both reading and writing; there is no support for altering the contents of a TIFF file. libtiffbuffers much information associated with writing a valid TIFF image.


2 Answers

Please have a look at TiffCP utility (and especially its source code) shipped with LibTiff.Net.

LibTiff.Net doesn't offer methods for removing tags (the same is true for LibTiff). You will need to implement part of TiffCP functionality in order to achieve that.

Basically, you will need to copy all tags you wish to retain, and copy pixels data without decoding and re-encoding it.

Please also have a look at Convert a multi-strip TIFF image to a single-strip one sample. It shows how to copy tags and copy raw (undecoded data) from one image to another. The sample actually decodes data in some cases because it needs to change number of strips, but you won't need to decode data.

like image 145
Bobrovsky Avatar answered Oct 11 '22 23:10

Bobrovsky


I think you will have to basically copy the input file to a new TIFF image filtering out the tags you don't want in the process. Take a look at the tiffcp utility which is part of the regular libtiff distribution. It sort of does that, minus filtering.

Disclaimer: I've never used LibTiff.Net and am assuming that it is very similar to the LibTiff.

Take a look at tiffcp.c

First it manually copies/sets some known tags such as resolution, compression, colors etc. Then it copies all a set of tags that can be copied w/o preprocessing:

for (p = tags; p < &tags[NTAGS]; p++)
    CopyTag(p->tag, p->count, p->type);

Then it copies the actual pixel data. This will from what I recollect, drop any tags that are not known to tiffcp. If your tag that you want to drop is in the list, you can trivially drop it by removing it from that list.

like image 43
MK. Avatar answered Oct 11 '22 23:10

MK.