SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.49k stars 851 forks source link

No Tiff support. #12

Closed JimBobSquarePants closed 3 years ago

JimBobSquarePants commented 8 years ago

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

JimBobSquarePants commented 8 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!

JimBobSquarePants commented 8 years ago

@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!

ChrisVanDijk commented 7 years ago

I needed to import Tiff files so I created a temporary Tiff encoder and decoder based on LibTiff.Net.

JimBobSquarePants commented 7 years ago

@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?

ChrisVanDijk commented 7 years ago

@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.

JimBobSquarePants commented 7 years ago

@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!

antonfirsov commented 7 years ago

@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.

Andy-Wilkinson commented 7 years ago

@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 πŸ˜„)

JimBobSquarePants commented 7 years ago

@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! πŸ’―

sandorfr commented 7 years ago

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?

JimBobSquarePants commented 7 years ago

@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.

Andy-Wilkinson commented 6 years ago

@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.

JimBobSquarePants commented 6 years ago

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.

darl0026 commented 5 years ago

Are there any plans to support TIFF in the future, im using your library for viewing/editing Exif data

JimBobSquarePants commented 5 years ago

Yep, we have a Tiff branch with a lot of code written already. Post v1 we will work to complete it.

damianog commented 5 years ago

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.

IldarKhayrutdinov commented 5 years ago

@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.

antonfirsov commented 5 years ago

@IldarKhayrutdinov that would be ace! πŸš€

claunia commented 5 years ago

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?

IldarKhayrutdinov commented 5 years ago

@claunia Yes, at the moment the multipages aren't supported, I'm working on it πŸ™‚

Andy-Wilkinson commented 5 years ago

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... :-)

IldarKhayrutdinov commented 5 years ago

Thanks @Andy-Wilkinson You did a very good job! I'd be honored to continue your contribution :slightly_smiling_face:

erikarenhill commented 5 years ago

Any updates to this issue, what's left to do, in need of more help?

JimBobSquarePants commented 5 years ago

@IldarKhayrutdinov Over to you... πŸ˜„

IldarKhayrutdinov commented 5 years ago

@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

brianpopow commented 4 years ago

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.

brianpopow commented 4 years ago

I have worked on the tiff encoder the last few days. The following works so far:

I will continue with the different compression methods.

ptasev commented 4 years ago

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.

brianpopow commented 4 years ago

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.

ptasev commented 4 years ago

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.

antonfirsov commented 4 years ago

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?

IldarKhayrutdinov commented 4 years ago

@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.

brianpopow commented 4 years ago

@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.

IldarKhayrutdinov commented 4 years ago

@brianpopow Hi Brian! You've implemented so much for TIFF πŸ˜ƒ It seems rgb_lzw_no_predictor.tiff file is corrupted.

brianpopow commented 4 years ago

@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.

IldarKhayrutdinov commented 4 years ago

@brianpopow yeah, now the bug is being reproduced, I will investigate it today

JimBobSquarePants commented 4 years ago

@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.

JimBobSquarePants commented 4 years ago

Just pushed changes to fix that. Once #1451 is merged you can update from master

IldarKhayrutdinov commented 3 years ago

@brianpopow yeah, now the bug is being reproduced, I will investigate it today

@brianpopow done! #1457

brianpopow commented 3 years ago

@IldarKhayrutdinov amazing, great job! I will check it out and test it.

brianpopow commented 3 years ago

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:

  1. Add Tiff to the Default Configuration:
Configuration.Default.AddTiff();
  1. Or to your specific configuration:
Configuration config = new Configuration();
config.AddTiff();
  1. Provide the Tiff Decoder / Encoder explicit when loading or saving a image:
using var image = Image.Load(@"image.tiff", new TiffDecoder());
JimBobSquarePants commented 3 years ago

@brianpopow let’s make that automatic. πŸ™‚

brianpopow commented 3 years ago

@brianpopow let’s make that automatic. πŸ™‚

With #1634 merged, the Tiff format is now added to the default Configuration.

cocosip commented 2 years ago

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!

JimBobSquarePants commented 2 years ago

No plans currently. That would require community support to implement.