question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LosslessJpegDecoder is undefined

See original GitHub issue

Expected Behavior

Jimp should be able to process DNG files.

Current Behavior

Jimp throws an error LosslessJpegDecoder is undefined.

Failure Information (for bugs)

import Jimp from 'jimp';

I’m using Jimp within an AWS Lambda function. When I import Jimp to perform conversion on a DNG to base64, I get the error LosslessJpegDecoder is undefined. This occurs before I perform any image processing.

I’ve found the line in jimp.js that appears to instantiate a LosslessJpegDecoder, and I can’t see where a LosslessJpegDecoder would be defined. From jimp@0.4.0, jimp.js:31737:

	if(img["t262"]==32803) // lossless JPEG (used in DNG files) is not available in JpegDecoder.
	{
		var bps = img["t258"][0], dcdr = new LosslessJpegDecoder();

I can’t find any references to LosslessJpegDecoder anywhere else in the code. Where is this supposed to come from?

I have found a snippet of code identical to the snippet above in the utif package (https://github.com/photopea/UTIF.js/blob/master/UTIF.js). I believe Jimp uses utif but I’m not sure how. It’s possible that this is utif’s problem, not Jimp’s, but since I’m not directly relying on utif I thought I would open this issue.

Steps to Reproduce

  1. Import jimp in an AWS Lambda function.

Screenshots

Context

This problem occurs in an AWS Lambda function.

  • Jimp Version: 0.4.0
  • Operating System: AWS Lambda … probably AmazonLinux
  • Node version: 8.10

Failure Logs

2018-10-24T15:00:40.166Z - error: Error in vision processing LosslessJpegDecoder is not defined

Notes

It’s possible that this is a utif problem, not a jimp problem, but since they contain some identical code I wanted to ask in both places. Thank you for your help.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:19

github_iconTop GitHub Comments

1reaction
hipstersmoothiecommented, Oct 27, 2018

@rdhenderson see what i was saying? I never knew a try/catch was so scary

0reactions
hishamcommented, Jan 19, 2022

Thanks @rdhenderson. Yes it works - all that’s needed is for @jimp/type-tiff to update its utif dependency to 3.1.0.

In the meantime I just installed the latest utif as a dependency on my project and overwrote the UTIF decoder with as follows:

    Jimp.decoders[Jimp.MIME_TIFF] = (data: Buffer) => {
      const ifds = UTIF.decode(data);
      const page = ifds[0];
      UTIF.decodeImage(data, page);
      const rgba = UTIF.toRGBA8(page);

      return {
        data: Buffer.from(rgba as ArrayBuffer),
        width: page.width,
        height: page.height,
      };
    };
Read more comments on GitHub >

github_iconTop Results From Across the Web

Lossless JPEG · Issue #402 · libjpeg-turbo/libjpeg-turbo - GitHub
my problem was trying to create samples to verify decoding worked, and as far as i know, only ffmpeg has an encoder and...
Read more >
jpeg-lossless-decoder-js - npm
A JavaScript JPEG Lossless decoder.. Latest version: 2.0.4, last published: 5 years ago. Start using jpeg-lossless-decoder-js in your ...
Read more >
Does JPEG allow lossless encoding? - Stack Overflow
No. Even with no quantization, the RGB to YCbCr transformation is lossy in the low few bits. Also the chroma channels are then...
Read more >
fast jpeg lossless decoding - Kaggle
Explore and run machine learning code with Kaggle Notebooks | Using data from multiple data sources.
Read more >
Decoding JPEG Lossless, Non-hierarchical, 1st Order Prediction
Codec : JPEG Lossless, Non-Hierarchical, First-Order Prediction (Process 14 [Selection Value 1]): ... OnReceiveAbort has Source=Unknown & Reason=Unspecified
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found