nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
26.8k stars 7.72k forks source link

A progressive JPEG that gives 'bad huffman code' #79

Closed eloj closed 9 years ago

eloj commented 9 years ago

I have come across a progressive jpeg that loads in GD, OS X Preview and checks out okay with jpeginfo, but returns "bad huffman code" from stbi_load.

The image in question can be downloaded from https://unsplash.com/photos/8bMPkZgazyY/download, but you'll probably have to go there with a browser and save-as as using curl straight on the URL gives a lower resolution one.

$ jpeginfo -ic X_canal.jpg
X_canal.jpg 5184 x 3456 24bit Exif  Progressive Huffman 3967267  [OK]

$ sha1sum X_canal.jpg
95345ef7f8d26330196149e32ec09457f58c49a8  X_canal.jpg
$ md5sum X_canal.jpg
1d68c5995aeb1bf6c346039f9d6e4d8e  X_canal.jpg

It entirely possible that the image is indeed corrupt, but I thought I'd offer you the chance to look at it if you want. If it's an unsupported format I feel like the error message should be made clearer, if possible.

$ identify -verbose X_canal.jpg
Image: X_canal.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 5184x3456+0+0
  Resolution: 72x72
  Print size: 72x48
  Units: Undefined
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 129.937 (0.509558)
      standard deviation: 97.7956 (0.383512)
      kurtosis: -1.62445
      skewness: -0.101304
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 134.391 (0.527025)
      standard deviation: 74.1044 (0.290606)
      kurtosis: -1.3512
      skewness: -0.246102
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 92.2491 (0.361761)
      standard deviation: 95.85 (0.375882)
      kurtosis: -1.1492
      skewness: 0.596392
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 118.859 (0.466115)
      standard deviation: 89.8938 (0.352525)
      kurtosis: -1.36635
      skewness: 0.0719763
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Interlace: JPEG
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Compose: Over
  Page geometry: 5184x3456+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 93
  Orientation: Undefined
  Properties:
    date:create: 2015-02-04T14:22:31+01:00
    date:modify: 2014-10-16T10:33:00+02:00
    exif:ColorSpace: 1
    exif:ExifImageLength: 3456
    exif:ExifImageWidth: 5184
    exif:ExifOffset: 26
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x2,1x1,1x1
    signature: 2d5107242c6865b8d58a351a3567d178dbe21500f48169391dffde797a0a5aba
  Profiles:
    Profile-exif: 74 bytes
    Profile-icc: 3144 bytes
      Description: sRGB IEC61966-2.1
      Manufacturer: IEC http://www.iec.ch
      Model: IEC 61966-2.1 Default RGB colour space - sRGB
      Copyright: Copyright (c) 1998 Hewlett-Packard Company
  Artifacts:
    filename: X_canal.jpg
    verbose: true
  Tainted: False
  Filesize: 3.967MB
  Number pixels: 17.92M
  Pixels per second: 38.95MB
  User time: 0.460u
  Elapsed time: 0:01.459
  Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org

EDIT: Testing more images this seems very common, so not quite the white unicorn I thought I'd found.

ybungalobill commented 9 years ago

I can confirm that this happens on some JPEGs, not necessarily progressive.

nothings commented 9 years ago

ybb, can you send me such a non-progressive JPEG or a link to one? It might be the same thing or it might be something different, so I need a sample image.

ybungalobill commented 9 years ago

Err, sorry. I was too impatient to double-check. They are progressive. Here are some if you need more to test.

These say "bad huffman code": http://40.media.tumblr.com/424f289d7f2e2a02636b264693a2d159/tumblr_n9rgjzeeXY1r493ruo2_r1_500.jpg http://41.media.tumblr.com/319546120a728c619dc6e93164040f7d/tumblr_ndg8ez34Ww1qz7ywso1_500.jpg

These say "junk before marker": http://36.media.tumblr.com/80724ad0d70f6345f0d7b40e69804558/tumblr_ndjttanVnB1qz7ywso1_1280.jpg http://41.media.tumblr.com/1ce735e8c44894d245305b63f50633c8/tumblr_ndk2jm09Fi1qz7ywso1_1280.jpg

nothings commented 9 years ago

Thanks.

nothings commented 9 years ago

I'm about to do a new release, so I put some work into this, but I couldn't figure it out. I'm going to have to run these files through another jpeg decoder and see where I deviate, but getting another jpeg decoder set up will be a pain... maybe for next release.

nothings commented 9 years ago

Should be fixed in version 2.05