2008.05.23 18:55 "[Tiff] Unitialized Variable Caused a Problem in TIFFCP", by Gene Amtower

2008.05.23 18:55 "[Tiff] Unitialized Variable Caused a Problem in TIFFCP", by Gene Amtower

Hi, I'm new to the tiff mailing list AND to the libtiff tools, which I just discovered this week. I'm going to really benefit from some of the features in the current tiffcp tool.

In trying to use the bias feature of the tiffcp tool, I discovered that the tiff images I was trying to modify were reported as having more than 1 sample/pixel, so I got an error result instead of the expected processing. I spent some time with the tiffinfo tool looking at various images because I really didn't know much about the specific format of the images in question. It reported that they were compressed using the "CCITT Group 4" method, which I thought was a monochrome format, so the message about more than 1 sample/pixel was a bit confusing. I thought maybe I didn't understand enough about the image properties. In fact, I almost posted a message to this list but decided I'd do some research first.

After some exhaustive searching, what I discovered was that these particular images did not have this tag set within the tiff image directory info. Upon inspection of the tiffcp program code, I noticed that the variable that holds this particular tag value is never initiatlized, and when my images didn't have this tag, the samples/pixel value was ending up with a completely random value. When I added an initialization of this variable to "1" in the program and recompiled it, the processing worked correctly. So, I am assuming that these images must have been 1 pixel/sample but didn't have this tag set when they were created.

Is it typical of tiff images that are 1 pixel/sample to not include this tag value? If this is the case, should this variable within tiffcp be initialized to =1 so that images without this property tag are interpreted as having 1 pixel/sample rather than a random value?

The real reason for my experimentation with the bias function is to be able to add a watermark from a secondary image over the source image. I was able to rewrite the code around the bias functionality slightly to achieve my goal, and I had to disable the checks comparing image size to bias size to not require my watermark to be the same size as the source image. Obviously, add a watermark is different than removing image bias, but the principle is pretty similar. The modified code tests the watermark image for each pixel value and sets the associated image pixel with either the image pixel or watermark pixel value according to what it finds. So, it's more of a mask replace function than a bias removal function. I was confused by the fact that I had to reverse the black and white in my watermark image to get the correct functionality that I desired, and maybe somebody can explain that to me, too. It was as if the black values were treated as "0" and the white values were treated as non-zero, which seemed backwards to me.

I wondered if anyone might be interested in adding this to the tiffcp code as a new functionality rather than part of the bias functionality, since I saw a previous post in November 2007 related to watermarking with the libtiff tools. I can't be only the second person to wonder about this functionality, so there may be value in adding it to the current tiffcp code.



   PC Backup