Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for old-style JPEG compression #7

Closed
fritz-c opened this issue Apr 19, 2017 · 29 comments
Closed

Support for old-style JPEG compression #7

fritz-c opened this issue Apr 19, 2017 · 29 comments

Comments

@fritz-c
Copy link
Contributor

fritz-c commented Apr 19, 2017

Would it be possible to support TIFF files with old-style JPEG compression used within?

For example, the image named b05937c07e0f3ce1bfd2c8c71b0220ec.tif in the archive here: https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/imagetestsuite/imagetestsuite-tiff-1.00-part3.tar.gz

(Taken from imagetestsuite)

@photopea
Copy link
Owner

UTIFF.js would probably have to call some other library for working with JPEGs. Do you actaully plan to use it in practice? Can't you convert your images to real JPEGs in some other program and then use these JPEGs instead?

@fritz-c
Copy link
Contributor Author

fritz-c commented Apr 19, 2017

I have encountered those kinds of images in practice. It's a client-facing screen that needs TIFF support, so it's difficult to ask the user to convert it themselves. If it's beyond the scope of this library, though, I won't ask you to add it in.

@photopea
Copy link
Owner

photopea commented Apr 19, 2017

Ok, I think I can add such feature, probably by calling JPEG decoder of PDFJS.

@photopea
Copy link
Owner

I was not able to use a standard JPEG decoder directly in UTIF.js. But baseline JPEG compression seems to be quite simple (see http://www.npes.org/pdf/TIFF-v6.pdf - page 95). Would you like to try and implement it?

@khmars
Copy link

khmars commented Jun 16, 2017

UTIF.decode._decodeG3 has error at line 215.

is1D = ((data[boff>>3]>>((boff&7)))&1)==1; boff++;

it fail if fo == 1.

@photopea
Copy link
Owner

Hi @khmars ... it is probably not related to JPEG compression. Can you send me an image, where the problem occurs, to support@photopea.com

BTW it is very nice to meet somebody, who understands G3 compression :)

@syvaidya
Copy link
Contributor

@photopea There are JS decoders available. One that might do the trick is available at: https://github.com/notmasteryet/jpgjs

Would you please take a look?

@photopea
Copy link
Owner

I know about JPG decoders. But I think that TIFF with JPG data are quite rare. It is better to convert such images into a standard JPG and use them as JPGs afterwards.

@syvaidya
Copy link
Contributor

I wish that such Tiff files were rare but they are pretty common. We have customers who have most of the Tiff files compressed using jpeg. If you use any of the big sized copier+scanners that you find in offices, those will generate such tiff if color scanning is done.

@photopea
Copy link
Owner

photopea commented Jun 20, 2017

These are probably some old scanners. Can't you batch-convert them to JPG with some utility right after scanning? What is your use case for these files and UTIF.js ?

@syvaidya
Copy link
Contributor

These are latest model scanners. And unfortunately we do not have control on source of the files. We are just building a generic image viewer.

By the way jpeg tiff is default output format in many of the enterprise capture products too. So it is not a "dead "format, how much ever I wish it were.

@photopea
Copy link
Owner

I don't understand JPG format well enough, to be able to connect UTIF.js with some existing JPG library. I would have to study the specification, it can take several days.

Would you be interested in donating some money to the project for this new feature? Everything would be published as open-source, free to use for the whole world forever :)

@syvaidya
Copy link
Contributor

Unfortunately, it is very difficult in our org to donate. I can help in coding if required..

@photopea
Copy link
Owner

Ok, so can you try to implement it? You can make a separate library, or use parts of UTIF.js .

@syvaidya
Copy link
Contributor

I have implemented new style JPEG compression support (Technote 2) (compression flag = 7). PR is at:

#14

It needs dependency to be added on jpg.js (https://github.com/notmasteryet/jpgjs). I have not updated package.json to mention the same. Please update accordingly, and merge the PR.

I have tested this only with 1 sample file. If you find any issue please let me know.

@photopea
Copy link
Owner

Hi, can you send me a TIFF image, for which it is useful?

@syvaidya
Copy link
Contributor

You can download from: http://support.decos.nl/berend/DOC019.zip
The file with "JPEG7" in the name should open fine now with my changes.

One more sample is available at: https://github.com/Twinside/Juicy.Pixels/raw/master/tests/tiff/quad-jpeg.tif

@syvaidya
Copy link
Contributor

Were you able to check the PR?

@syvaidya
Copy link
Contributor

syvaidya commented Aug 1, 2017

@photopea any update? Would you merge the PR?

@photopea
Copy link
Owner

photopea commented Aug 3, 2017

Hi, I am very sorry, I was a little busy. I tried to use your code. It works well with "quad-jpeg.tif", but I had problems with "DOC019-JPEG7-orientation1.tif" from the archive - it seems like it does not have the table 347. Have you tested it?

Also, is the compression type 6 a lot different than 7?

@syvaidya
Copy link
Contributor

syvaidya commented Aug 4, 2017

Sorry, I did not check with that file. As I mentioned earlier, I tested with only 1 file. I'll check out the other one. I hope it is not type 6 (even though the filename says JPEG7).

And yes, type 6 is pretty different than 7.

@syvaidya
Copy link
Contributor

syvaidya commented Aug 5, 2017

@photopea I have fixed the issue. There are cases in new JPEG compression where JPEGTables might not be separately stored. I've taken care of that case now. Please take latest from the PR.

@photopea
Copy link
Owner

photopea commented Aug 5, 2017

Ok, thank you very much. We can finally close this :)

@photopea photopea closed this as completed Aug 5, 2017
@photopea
Copy link
Owner

photopea commented Oct 8, 2017

@syvaidya I am trying to parse .CR2 files (Canon RAW photo). The format is a TIFF format and images are encoded with type 6 compression (old JPEG). So it would be really useful to have it in UTIF.js

Do you know anything more about type 6? Could we use jpg.js too to parse it (maybe after some modifications - putting the content of some tags as a prefix of data, as you do now)? What do you think?

@photopea photopea reopened this Oct 8, 2017
@syvaidya
Copy link
Contributor

syvaidya commented Oct 9, 2017

I had started implementing support for compression type 6, but it is still work in progress. It is very complicated format compared to type 7. You can try my current implementation from:

https://gist.github.com/syvaidya/fb16051f6ae9578040a0d07bef6b757d

I am not getting time and so the work has stalled for past few weeks. Not sure when I can spend time on this next.

@syvaidya
Copy link
Contributor

syvaidya commented Apr 5, 2018

@photopea were you able to support type 6 jpeg compression?

@photopea
Copy link
Owner

photopea commented Apr 5, 2018

I don't understand JPEG at all, so I did not have courage to start looking into it.

@syvaidya
Copy link
Contributor

syvaidya commented Apr 8, 2018

@photopea I have implemented type 6 support and created PR:

#28

Please check and merge if okay.

@photopea
Copy link
Owner

photopea commented Apr 8, 2018

Thanks @syvaidya ! You are amazing! :) I can finally close this issue after a year.

@photopea photopea closed this as completed Apr 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants