Closed JimBobSquarePants closed 3 years ago
From @kierenj on September 7, 2016 20:27
I realise how unhelpful this comment right here is, but TIFF decoding across the board can be really tricky to get right - there are loads of compression formats, and even fairly respected tools (from MS / Atalasoft) get it wrong even with 1-bit images. I think some archiving formats even require special licensing to implement correctly. It might be worth identifying a small subset of formats to support!
@kierenj It's certainly not an unhelpful comment. Tiff would be hard and I'm sorely tempted to let someone else figure it out and concentrate on what we have already. I'm just dreading the day someone tells me that the library is useless without it. There's always someone!
I needed to import Tiff files so I created a temporary Tiff encoder and decoder based on LibTiff.Net.
@chrisvandijk Good effort but have you benchmarked that codec? The Bitmiracle jpeg codec was about 10x slower and used 190MB more to process a small test image compared to our codec. I imagine the Tiff one will be the same. I'd be careful using it.
@Andy-Wilkinson you have been playing around with Tiff haven't you with your own stuff? I wonder if we can use some of it?
@JimBobSquarePants The code and performance is bad, but I really needed the ability to open Tiff files. It's a temporary solution until a better one.
@chrisvandijk understandable. Tiff is a complex format so I'm pushing it to the backburner until I can get everything else out of the way... Not looking forward to tackling it!
@chrisvandijk @JimBobSquarepants One big "advantage" of these naive C ports is that its really not that hard to make the first steps towards speeding & cleaning them up. Someone with time & a profiler could check it, and estimate the efforts needed reuse/refactor elements of that code.
@JimBobSquarePants I've got the basics of reading the Tiff format itself working from my own project (I started here since many Camera Raw files are mutant Tiff files). As you mention, there are a number of compression formats, but the key ones probably aren't too much trouble. The one issue with my existing codebase is that it was a bit of an experiment in a more functional style of C#, rather than how you might structure it normally.
All that said, I know a fair amount about the Tiff format now, so probably would be able to make a quick start on a true ImageSharp Tiff codec pretty easily (and share a bit of the code where I can). Would you be interested in me picking up this issue and giving it a start? (especially since you guys seem to be busy enough with the existing codec perf π)
@antonfirsov I've found with those ports though there's about a million lines more code than I'd like to read nested in there.
@Andy-Wilkinson That would be absolutely brilliant if you could! π―
I come across this library https://github.com/BitMiracle/libtiff.net which is already .netstandard compatible. It's under new BSD license https://github.com/BitMiracle/libtiff.net/blob/master/license.txt
I feel like this is a good candidate to bring support for TIFF.
What do you think?
@sandorfr We've already got a WIP TIFF PR in progress #119
The BitMiracle repositories, to put it nicely, are junk. Poorly ported, slow, bloated implementations that are useful only for testing against.
@poeman16 : Unfortunately I've had pretty much zero time to devote to working on this pull request for a while. The foundations of parsing the TIFF structure was mostly in place, with the most complex area remaining being implementations for the different compression formations, in particular those based on JPEG. There would need to be some changes to fit with any changes in the ImageSharp design since the last commit. Definitely something that could be picked up by someone.
There's been a lot of changes in the main repo since the PR was opened. We'll have to do a lot of work to update the codebase before support can be completed.
Are there any plans to support TIFF in the future, im using your library for viewing/editing Exif data
Yep, we have a Tiff branch with a lot of code written already. Post v1 we will work to complete it.
Hi @JimBobSquarePants as the others I am interested on a Tiff decoder. I need to process multipage Tiff documents from office scanner. Thanks in advance.
@antonfirsov @JimBobSquarePants @Andy-Wilkinson Can I contribute to the tiff-codec branch? I would like to commits to my branch IldarKhayrutdinov/ImageSharp/tiff-codec then create PR to the SixLabors/ImageSharp/tiff-codec.
@IldarKhayrutdinov that would be ace! π
Just a comment, I don't see it named, but there are multipage TIFF files, used extensively by a lot of scanning software, so should be accounted for?
@claunia Yes, at the moment the multipages aren't supported, I'm working on it π
Thanks @IldarKhayrutdinov for picking up the TIFF decoder. I have to confess that I've not had much input into this for a while, but I think @JimBobSquarePants has made a few updates to keep things moving along.
The biggest piece of work from what I remember was implementing all the more common compression types (see the checklist at the start of #12). Multipage TIFFs was something that was going to be a bit tricky with the rest of ImageSharp at the time, but this may be different now. There's probably a lot of performance improvements that could be done too!
Good luck... :-)
Thanks @Andy-Wilkinson You did a very good job! I'd be honored to continue your contribution :slightly_smiling_face:
Any updates to this issue, what's left to do, in need of more help?
@IldarKhayrutdinov Over to you... π
@erikarenhill @JimBobSquarePants At the moment, I have local changes and continue working, not fast, but I continue :slightly_smiling_face: If you wish, you can add support for example Jpeg (Technote 2) or YCbCr, I think, our code will not be difficult to merge into one
I have added support for decompressing Ccitt1D
and CcittGroup3Fax
.
~There is still an issue with Ccitt1D
for large images, though, but i will find that bug.
See the failing test: Tiff/Calliphora_huffman_rle.tif
: there is a difference of 0,0003%
to the Magick reference decoder.~ This is fixed now.
I have worked on the tiff encoder the last few days. The following works so far:
I will continue with the different compression methods.
Is there support for reading or writing custom tiff tags (I'm assuming they're the same as exif tags?). I was looking at the metadata code, but I see methods like GetString or GetArray are internal, and I didn't see a way to add new tags and data either.
Is there support for reading or writing custom tiff tags (I'm assuming they're the same as exif tags?). I was looking at the metadata code, but I see methods like GetString or GetArray are internal, and I didn't see a way to add new tags and data either.
We keep it the same as with EXIF, no custom tags are allowed. Only tags which are in the spec.
That's a shame, but I understand it's more effort. It is quite useful to add extra data to images (per frame). It's helpful to allow us to label images in the biotech industry.
EDIT: For clarity, my statement about the industry is purely speculation on my part. I've only ever worked at one biotech company.
It is quite useful to add extra data to images (per frame). It's helpful to allow us to label images in the biotech industry.
@JimBobSquarePants @dlemstra (Without knowing anything about the image metadata domain) I wonder how common this practice is, and how much does it go against standards? Maybe we should consider it, if it blocks (some) users?
@antonfirsov I came across files with custom tiff tags. The spec seems to allow it, quote from TIFF6.pdf (page 8):
However, if there is little or no chance that your TIFF files will escape your private environment, please consider using TIFF tags in the βreusableβ 65000-65535 range. You do not need to contact Adobe when using numbers in this range.
@IldarKhayrutdinov Hi Ildar. As far as i know, you did most of the LZW implementation. While it works for some image, it has some issues with other images for example rgb_lzw_no_predictor.tiff
(its in the Tiff test file directory, i cannot attach it here). Here are some info's about the image:
tiffinfo rgb_lzw_no_predictor.tiff
TIFF Directory at offset 0x1fed4 (130772)
Image Width: 256 Image Length: 256
Resolution: 300, 300 pixels/inch
Bits/Sample: 8
Compression Scheme: LZW
Photometric Interpretation: RGB color
FillOrder: msb-to-lsb
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 3
Rows/Strip: 256
Planar Configuration: single image plane
Page Number: 0-1
White Point: 0.3127-0.329
PrimaryChromaticities: 0.640000,0.330000,0.300000,0.600000,0.150000,0.060000
Predictor: none 1 (0x1)
The decoded image is mostly black. I have trouble finding the issue. It would be great if you could review this once again and help me finding this. All i can say so far, is that the while loop breaks after only 428 pixels are decoded.
@brianpopow Hi Brian! You've implemented so much for TIFF π It seems rgb_lzw_no_predictor.tiff
file is corrupted.
@brianpopow Hi Brian! You've implemented so much for TIFF π It seems
rgb_lzw_no_predictor.tiff
file is corrupted.
@IldarKhayrutdinov Thanks alot for looking into this. It seems, i did mess up the image when pushing it to git :confused:
I have attached it here as a zip file: rgb_lzw_no_predictor.zip
Im sorry for the inconvenience. I hope you could look into this again. I think you can spot an error faster here with LZW then i can.
@brianpopow yeah, now the bug is being reproduced, I will investigate it today
@brianpopow Hi Brian! You've implemented so much for TIFF π It seems rgb_lzw_no_predictor.tiff file is corrupted.
I think our .gitattributes
might be breaking tiff files. We should add the extensions for all known image formats.
Just pushed changes to fix that. Once #1451 is merged you can update from master
@brianpopow yeah, now the bug is being reproduced, I will investigate it today
@brianpopow done! #1457
@IldarKhayrutdinov amazing, great job! I will check it out and test it.
I am happy to announce that we have now support for decoding and encoding Tiff images with #1553 merged to the master branch.
You can try it out with our nightly build from our myget feed
For now this feature has to be activated manually by the user, which can be done in several different ways:
Configuration.Default.AddTiff();
Configuration config = new Configuration();
config.AddTiff();
using var image = Image.Load(@"image.tiff", new TiffDecoder());
@brianpopow letβs make that automatic. π
@brianpopow letβs make that automatic. π
With #1634 merged, the Tiff format is now added to the default Configuration.
Hi, i try to read a tiff image, but it throw Tiled images are not supported
.
Any plan to support Construction of image (from tile data)
?
Thank you!
No plans currently. That would require community support to implement.
From @JimBobSquarePants on August 31, 2016 1:49
We should be able to support TIFF
Useful links.
http://partners.adobe.com/public/developer/tiff/index.html
http://www.remotesensing.org/libtiff/
http://www.awaresystems.be/imaging/tiff.html
Current implementation can be found in the tiff-codec branch.
Feature Checklist
Compression Types
Photometric Interpretation Formats