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

JpegDecoder is undefined when jpgjs is loaded - module.exports is empty #32

Closed
makr28 opened this issue Apr 25, 2018 · 19 comments
Closed

Comments

@makr28
Copy link

makr28 commented Apr 25, 2018

I have a node project and I did an "npm install utif". This correctly brought in pako and jpgjs as well.
Pako can be found and is fine. But jpgjs module.exports is not being set.

In jpgjs line 102
if (typeof exports === "function") {
module.exports = {
JpegImage: JpegImage,
JpegDecoder: JpegDecoder,
JpxDecoder: JpxDecoder,
Jbig2Decoder: Jbig2Decoder
};
}

Looking in the debugger typeof exports evaluates to 'object'

This may be an issue with Jpg.js but I wanted to ask if you had come across this issue?

Thanks

added notes:
-Using npm version 8.9.4
-I am going thru the require('jpgjs') code path to load jpegDecoder

@photopea
Copy link
Owner

Hi, I never used npm or Node.js . I use UTIF.js in a web browser.

Maybe @Scimonster could help us?

@makr28
Copy link
Author

makr28 commented Apr 26, 2018

Thanks, I'll try logging an issue with jpg.js

@makr28
Copy link
Author

makr28 commented Apr 26, 2018

Oh also, can you please release the current version to npm? Thanks

@makr28
Copy link
Author

makr28 commented Apr 26, 2018

@photopea Hi, I figured out what was wrong with jpg.js but they have not been active for a few years. I forked jpgjs to my github (https://github.com/makr28/jpgjs) would you be willing to switch the dependency to it? If you don't like that idea would you be willing to fork it and put the change that fixes it in?

Thanks!

@photopea
Copy link
Owner

The JpegDecoder that I use along with UTIF.js is a copy-pasted fragment of pdf.js , see here: mozilla/pdf.js#6128

TIFF files containing JPEG compression are a "legacy thing". I recommend to convert them all to a regular JPEG and then use these JPEGs. Other compressions (CCITT, LZW, PackBits) are included in UTIF.js and do not require any additional library.

@photopea
Copy link
Owner

@syvaidya You are the one who understands JPEG! :) Could we insert all necessary parts of JpegDecoder into UTIF.js (only those JPEG features, that can be used in TIFFs)? How much code would it be? It is a bit unpractical to have a dependency.

@makr28
Copy link
Author

makr28 commented Apr 26, 2018

In your package.json you have:

"dependencies": {
"jpgjs": "github:notmasteryet/jpgjs",

So you already are pulling in the dependency

@makr28
Copy link
Author

makr28 commented Apr 26, 2018

If you want to take that dependency out, I can just put my version of jpg.js as a dependency in my project. Otherwise if I do npm install, it may overwrite mine with this one

@Scimonster
Copy link
Collaborator

Scimonster commented Apr 26, 2018 via email

@makr28
Copy link
Author

makr28 commented Apr 26, 2018

Thanks

@makr28
Copy link
Author

makr28 commented Apr 28, 2018

Actually testing with the dependency take out of utif.js's node modules, it doesn't work right, so we do need you to keep the dependency in your package.json but switch it to the working version.

It's the only way utif will work for node projects. This shouldnt affect what you use utif for as you dont use the node_modules folder or package.json in your projects but node projects will. And since you already have the dependency there, it won't be adding anything to utif.

Thanks :)

@k1nger
Copy link

k1nger commented Apr 30, 2018

Yes Tiff files containing JPEG is a legacy thing, but there are many files still in existence today that are still that data type. Unfortunately managing long standing enterprise applications we need this support as well.

JPGJG was forked from mozilla/pdf.js 3-4 years ago. mozilla/pdf.js has long since enhanced their jpgjs while this has remained stagnant and unresponsive. That and it doesn't even follow modern ecmascript standards which is causing the bug in this issue.

+1 to either remove the dependency and add in the functionality to support jpeg natively with utif or to pull in a more modern one that can be used with modern javascript development practices.

@photopea
Copy link
Owner

@k1nger I would like to ask Mozilla to publish their JPEG decoders as a separate library (and maintain it in that library), and pdf.js would have a dependency on that library. Otherwise, Github would be filled with dozens of copy-pasted fragments of pdf.js, which are not maintained by anybody anymore. Would you support me and help me emphasize this to pdf.js developers?

@k1nger
Copy link

k1nger commented Apr 30, 2018

Yup, I think that's a good idea. I found the issue you created on the mozilla/pdfjs repo. I'll start reading up there.

@photopea
Copy link
Owner

@k1nger I see you already found my post: mozilla/pdf.js#8966 . Can others also kindly ask Mozilla to publish a separate JPEG decoder? Please? :)

@makr28
Copy link
Author

makr28 commented Apr 30, 2018

@photopea Another way would be to change your package.json where you are currently pulling in the unworking jpg.js to pull in pdf.js and switch the require to use their version of jpg.js and the jpegDecoder.

I support your campaign to have pdf js extract the jpegdecoder and I will comment on the issue but as of right now it doesn't look like they are going to anytime soon :(

If you aren't going to switch the jpg.js dependency then can you please remove the line "jpgjs": "github:notmasteryet/jpgjs", from your package.json as it is currently useless if it doesn't export the jpegdecoder correctly. And to make UTIF work for NodeJs projects can you please remove the require line and add a method to set jpegDecoder to a variable passed in. These proposed changes only affect Node projects.

As with @k1nger I am also working in enterprise software that requires us to support older tiff images.

Thanks

@k1nger
Copy link

k1nger commented May 3, 2018

@Scimonster Have you made any progress with what you were looking into?

@photopea Since it looks like Mozilla is unresponsive I think it may be best to move forward with this issue and drop another release to npm. I can help.

@Scimonster
Copy link
Collaborator

I switched the dependency to @makr28's fork of jpgjs and pushed it to NPM. Sorry it's taken me so long, i haven't been around very much. If someone else wants to take over managing the NPM side of things i'm happy to let them, assuming @photopea agrees.

@makr28
Copy link
Author

makr28 commented May 10, 2018

Thanks @Scimonster

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