Skip to content

Specific jpeg images result in very strange saved images (corrupted?) #817

Closed

Description

@LarsWesselius

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

When loading an image using Image.Load and saving it again, using image.Save(). the resulting image is very different from the original, loaded image without doing any mutations.

Steps to Reproduce

.NET Core 2.1 Console app. Use
using (Image<Rgba32> image = Image.Load("8.jpg")) { image.Save("8-saved.jpg"); }
As the only code in Main and run with 8.jpg in your working directory (see attached).

This is the image being loaded (8.jpg):
8

This is the resulting image after saving:
8-saved

System Configuration

  • ImageSharp version: SixLabors.ImageSharp v1.0.0-beta0006
  • Other ImageSharp packages and versions: None
  • Environment (Operating system, version and so on): Windows 10, latest. .NET Core 2.1 console application
  • .NET Framework version: .NET Core 2.1
  • Additional information:

Activity

  1. JimBobSquarePants commented on Jan 25, 2019

    @JimBobSquarePants
    Member

    JpegSnoop Output

    It's YccK I wonder if we are not parsing the color mode properly. cc/ @antonfirsov

    Nope. Everything looks fine. It's happening after the scan decoder I think.

    JPEGsnoop 1.8.0 by Calvin Hass
      http://www.impulseadventure.com/photo/
      -------------------------------------
    
      Filename: [C:\Users\james\source\repos\ImageSharp.Test\images\cutoff.jpg]
      Filesize: [31527] Bytes
    
    Start Offset: 0x00000000
    *** Marker: SOI (xFFD8) ***
      OFFSET: 0x00000000
     
    *** Marker: APP0 (xFFE0) ***
      OFFSET: 0x00000002
      Length     = 16
      Identifier = [JFIF]
      version    = [1.1]
      density    = 72 x 72 DPI (dots per inch)
      thumbnail  = 0 x 0
     
    *** Marker: APP14 (xFFEE) ***
      OFFSET: 0x00000014
      Length            = 14
      DCTEncodeVersion  = 100
      APP14Flags0       = 0
      APP14Flags1       = 0
      ColorTransform    = 0 [Unknown (RGB or CMYK)]
     
    *** Marker: DQT (xFFDB) ***
      Define a Quantization Table.
      OFFSET: 0x00000024
      Table length = 67
      ----
      Precision=8 bits
      Destination ID=0 (Luminance)
        DQT, Row #0:   2   2   1   2   3   6   7   9 
        DQT, Row #1:   2   2   2   3   4   8   8   8 
        DQT, Row #2:   2   2   2   3   6   8  10   8 
        DQT, Row #3:   2   2   3   4   7  12  11   9 
        DQT, Row #4:   3   3   5   8  10  15  14  11 
        DQT, Row #5:   3   5   8   9  11  15  16  13 
        DQT, Row #6:   7   9  11  12  14  17  17  14 
        DQT, Row #7:  10  13  13  14  16  14  14  14 
        Approx quality factor = 92.96 (scaling=14.08 variance=1.37)
     
    *** Marker: SOF0 (Baseline DCT) (xFFC0) ***
      OFFSET: 0x00000069
      Frame header length = 20
      Precision = 8
      Number of Lines = 290
      Samples per Line = 400
      Image Size = 400 x 290
      Raw Image Orientation = Landscape
      Number of Img components = 4
        Component[1]: ID=0x43, Samp Fac=0x22 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (Y)
        Component[2]: ID=0x4D, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x00 (Cb)
        Component[3]: ID=0x59, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x00 (Cr)
        Component[4]: ID=0x4B, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x00 (K)
     
    *** Marker: DHT (Define Huffman Table) (xFFC4) ***
      OFFSET: 0x0000007F
      Huffman table length = 29
      ----
      Destination ID = 0
      Class = 0 (DC / Lossless Table)
        Codes of length 01 bits (001 total): 00 
        Codes of length 02 bits (000 total): 
        Codes of length 03 bits (002 total): 05 06 
        Codes of length 04 bits (002 total): 04 07 
        Codes of length 05 bits (003 total): 02 03 08 
        Codes of length 06 bits (001 total): 09 
        Codes of length 07 bits (001 total): 01 
        Codes of length 08 bits (000 total): 
        Codes of length 09 bits (000 total): 
        Codes of length 10 bits (000 total): 
        Codes of length 11 bits (000 total): 
        Codes of length 12 bits (000 total): 
        Codes of length 13 bits (000 total): 
        Codes of length 14 bits (000 total): 
        Codes of length 15 bits (000 total): 
        Codes of length 16 bits (000 total): 
        Total number of codes: 010
    
     
    *** Marker: DHT (Define Huffman Table) (xFFC4) ***
      OFFSET: 0x0000009E
      Huffman table length = 65
      ----
      Destination ID = 0
      Class = 1 (AC Table)
        Codes of length 01 bits (000 total): 
        Codes of length 02 bits (001 total): 01 
        Codes of length 03 bits (003 total): 02 03 04 
        Codes of length 04 bits (003 total): 00 05 11 
        Codes of length 05 bits (003 total): 06 12 21 
        Codes of length 06 bits (002 total): 07 31 
        Codes of length 07 bits (004 total): 13 22 41 51 
        Codes of length 08 bits (004 total): 08 14 32 61 
        Codes of length 09 bits (005 total): 15 23 42 71 81 
        Codes of length 10 bits (002 total): 91 A1 
        Codes of length 11 bits (005 total): 16 33 52 B1 C1 
        Codes of length 12 bits (004 total): 09 24 62 D1 
        Codes of length 13 bits (001 total): 72 
        Codes of length 14 bits (003 total): 17 43 E1 
        Codes of length 15 bits (005 total): 18 25 34 82 F0 
        Codes of length 16 bits (001 total): F1 
        Total number of codes: 046
    
     
    *** Marker: SOS (Start of Scan) (xFFDA) ***
      OFFSET: 0x000000E1
      Scan header length = 14
      Number of img components = 4
        Component[1]: selector=0x43, table=0(DC),0(AC)
        Component[2]: selector=0x4D, table=0(DC),0(AC)
        Component[3]: selector=0x59, table=0(DC),0(AC)
        Component[4]: selector=0x4B, table=0(DC),0(AC)
      Spectral selection = 0 .. 63
      Successive approximation = 0x00
    
      NOTE: Scan parsing doesn't support CMYK files yet.
     
    *** Marker: EOI (End of Image) (xFFD9) ***
      OFFSET: 0x00007B25
    
    
    *** Searching Compression Signatures ***
    
      Signature:           011D2972762547222591CBAA7C61AF23
      Signature (Rotated): 01A6F243D0894ED6B08CD932F2C5F096
      File Offset:         0 bytes
      Chroma subsampling:  ?x?
      EXIF Make/Model:     NONE
      EXIF Makernotes:     NONE
      EXIF Software:       NONE
    
      Searching Compression Signatures: (3347 built-in, 0 user(*) )
    
              EXIF.Make / Software        EXIF.Model                            Quality           Subsamp Match?
              -------------------------   -----------------------------------   ----------------  --------------
         SW :[IJG Library              ]                                       [093 Gray        ]                  
    
        The following IJG-based editors also match this signature:
         SW :[GIMP                     ]                                       [093 Gray        ]                  
         SW :[IrfanView                ]                                       [093 Gray        ]                  
         SW :[idImager                 ]                                       [093 Gray        ]                  
         SW :[FastStone Image Viewer   ]                                       [093 Gray        ]                  
         SW :[NeatImage                ]                                       [093 Gray        ]                  
         SW :[Paint.NET                ]                                       [093 Gray        ]                  
         SW :[Photomatix               ]                                       [093 Gray        ]                  
         SW :[XnView                   ]                                       [093 Gray        ]                  
    
      Based on the analysis of compression characteristics and EXIF metadata:
    
      ASSESSMENT: Class 1 - Image is processed/edited
    
      This may be a new software editor for the database.
      If this file is processed, and editor doesn't appear in list above,
      PLEASE ADD TO DATABASE with [Tools->Add Camera to DB]
    
    
    
  2. LarsWesselius commented on Jan 25, 2019

    @LarsWesselius
    Author

    Opening and saving it in Paint for example produces a smaller jpeg which does work in ImageSharp.
    8-working

  3. JimBobSquarePants commented on Jan 25, 2019

    @JimBobSquarePants
    Member

    @LarsWesselius I imagine paint is reencoding it to YCbCr. Just running a debug pass on the image now.

  4. added this to the 1.0.0-rc1 milestone on Jan 25, 2019
  5. added a commit that references this issue on Feb 14, 2019
    6fd7f4f
  6. added a commit that references this issue on Feb 15, 2019
    5a9b84e
  7. added a commit that references this issue on Nov 11, 2019
    3f362c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions