I am trying to convert JPEGs to TIFFs with JPEG-compression using FreeImage.Net and C#. This works fine, however, for low-quality JPGES the TIFF-files are a lot larger than the original. I assume the TIFF-size does not depend on the original JPEG-Quality, because the output-images were always about the same size.
For example (converting a screenshot):
2065kb JPEG (quality: 100%) --> 1282kb TIFF
379kb JPEG (quality: 50%) --> 1200kb TIFF
This increase in size is not acceptable for our company, because our clients and we are dealing with quite a lot of documents.
Interestingly enough, I get about the same results when I convert the images with GIMP. Now I am wondering: is this according to the TIFF-standard or special to FreeImage/GIMP? (I think both use libtiff.dll).
I suppose there is another way, because we have a scanner in our company that produces images as JPEG-compressed TIFFs with a much smaller size. Does anyone know about another library (either free or not) that can handle this conversion more effectively, or achieve this in FreeImage?
UPDATE:
I took a look at the TIFF 6.0 specification, analyzed the files our scanner produced and was able to write a function that wraps a JPEG into a very simple TIFF container (works also with multiple JPEGs which are merged to a multi-page TIFF).
For those who know a little about TIFF: I produced a new TIFF file (with one or more IFDs, according to the number of images/pages) and wrote the raw data of an existing JPEG image into a single strip (per IFD), using the following fields/entries:
NewSubfileType = 0
ImageWidth = //(width of the original JPEG)
ImageLength = //(height of the original JPEG)
BitsPerSample = {8, 8, 8} //(count: 3)
Compression = 7 //(JPEG)
PhotometricInterpretation = 6 //(YCbCr)
StripOffsets = //(offset of raw JPEG data, count: 1)
SamplesPerPixel = 3
RowsPerStrip = //(height of the original JPEG)
StripByteCounts = //(length of raw JPEG data, count: 1)
XResolution = //(horizontal resolution of original JPEG data)
YResolution = //(vertical resolution of original JPEG data)
PlanarConfiguration = 1 (chunky)
ResolutionUnit = 2 //(Inch)
(To obtain the information of the original image, I used FreeImage, but any other image library should work as well.)
I know there could be some pitfalls I don't know about yet. It might not work with any JPEG-file. Also, I'm not sure why I had to use PhotometricInterpretation = 6
and PlanarConfiguration = 1
or some of the other fields' values. However, it works.
I suppose my problem with the other libraries was, that they produced a completely new JPEG with always the same quality (since you can only set TIFF-compression to JPEG but not specify any further options) and wrapped that into a TIFF container.
I know too now, JPEG compression in a TIFF is not exactly the best choice (it's lossy, uncommon and rarely supported, besides a JPEG-compressed TIFF not any better then a regular JPEG file). However, our clients demand that. Let's see if the above is going to be a suitable solution, or if I manage to find sth else.