Imageprocessor: ImageFormatException: Unknown component selector

Created on 19 Mar 2016  路  17Comments  路  Source: JimBobSquarePants/ImageProcessor

Hi,

I'm trying to add an image processing functionality to my ASP.NET Core project, and I'm getting the following exception while attempting to create a new Image instance:

ImageProcessorCore.ImageFormatException: Unknown component selector
at ImageProcessorCore.Formats.JpegDecoderCore.processSOS(Int32 n)
at ImageProcessorCore.Formats.JpegDecoderCore.Decode(Stream stream, ImageBase image, Boolean configOnly)
at ImageProcessorCore.Formats.JpegDecoder.Decode(Image image, Stream stream)
at ImageProcessorCore.Image.Load(Stream stream, IList1 formats) at ImageProcessorCore.Image..ctor(Stream stream) at OkLive.Web.UI.Controllers.HomeController.<CreateConversationThumbnail>d__4.MoveNext() in C:\Users\gbyah\Documents\Visual Studio 2015\Projects\OkLive vNext\src\OkLive.Web.UI\Controllers\HomeController.cs:line 86 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft.AspNet.Mvc.Controllers.ControllerActionExecutor.d__81.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Microsoft.AspNet.Mvc.Controllers.ControllerActionInvoker.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeActionFilterAsync>d__53.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AspNet.Mvc.Controllers.FilterActionInvoker.<InvokeAsync>d__44.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Mvc.Infrastructure.MvcRouteHandler.<RouteAsync>d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Routing.Template.TemplateRoute.<RouteAsync>d__27.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Routing.RouteCollection.<RouteAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Builder.RouterMiddleware.<Invoke>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Builder.Extensions.MapMiddleware.<Invoke>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at IdentityModel.AspNet.ScopeValidation.ScopeValidationMiddleware.<Invoke>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at IdentityServer4.AccessTokenValidation.IdentityServerAuthenticationMiddleware.<Invoke>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Builder.Extensions.MapMiddleware.<Invoke>d__3.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.<Invoke>d__18.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Microsoft.AspNet.Authentication.AuthenticationMiddleware1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNet.Authentication.AuthenticationMiddleware`1.d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNet.IISPlatformHandler.IISPlatformHandlerMiddleware.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNet.Diagnostics.StatusCodePagesMiddleware.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.AspNet.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()

Ways to reproduce:

  • Download a profile picture from FB.
  • Instantiating a new Image:

            using (var stream = System.IO.File.OpenRead(@"C:\Users\gbyah\Desktop\foo.jpg"))
            {
                //return File(buffer, "image/jpeg");
                var image = new Image(stream);
            }

I've tested the code with the images attached to the project samples, and they do work correctly. I'm wonering maybe Facebook images lack of some meta information?

bug core

Most helpful comment

This image decoding is fixed with #351

I have another sample image (http://www.reasoft.com/tutorials/web/img/progress.jpg) that fails though -- still looking at that.

All 17 comments

Hi there,

Thanks for this.

It seems that within the images saved by Facebook there are multiple SOS (Start of scan) markers. This will be due to the images being saved in progressive format.

Oddly when parsing the second marker the ProcessSOS method returns the number of components as 1, previous scans are 3. I've been reading about and it looks to me like LibJpeg.NET uses similar logic.

@mweber26 Could you please compare our version to the golang to see if they suffer the same issue? I don't know how to do that.

Cheers

James

JPEGsnoop output of this image.

It's this marker that seems to be throwing everything out of whack. I'm going to investigate a better way to identify the huffman tables.

*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00001317
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x02, table=1(DC),1(AC)
  Spectral selection = 1 .. 63
  Successive approximation = 0x01

Here's the image:

fb


JPEGsnoop 1.7.5 by Calvin Hass
  http://www.impulseadventure.com/photo/
  -------------------------------------

  Filename: [C:\Development\GitHub\ImageProcessor\tests\ImageProcessorCore.Tests\TestImages\Formats\Jpg\fb.jpg]
  Filesize: [15787] Bytes

Start Offset: 0x00000000
*** Marker: SOI (xFFD8) ***
  OFFSET: 0x00000000

*** Marker: APP0 (xFFE0) ***
  OFFSET: 0x00000002
  Length     = 16
  Identifier = [JFIF]
  version    = [1.2]
  density    = 1 x 1 (aspect ratio)
  thumbnail  = 0 x 0

*** Marker: COM (Comment) (xFFFE) ***
  OFFSET: 0x00000014
  Comment length = 4
    Comment=*.

*** Marker: APP2 (xFFE2) ***
  OFFSET: 0x0000001A
  Length          = 540
  Identifier      = [ICC_PROFILE]
    ICC Profile:
      Marker Number = 1 of 1
        Profile Size                      : 524 bytes
        Preferred CMM Type                : 'lcms' (0x6C636D73)
        Profile Version                   : 0.2.1.0 (0x02100000)
        Profile Device/Class              : Display Device profile ('mntr' (0x6D6E7472))
        Data Colour Space                 : rgbData ('RGB ' (0x52474220))
        Profile connection space (PCS)    : 'XYZ ' (0x58595A20)
        Profile creation date             : 2012-01-25 03:41:57
        Profile file signature            : 'acsp' (0x61637370)
        Primary platform                  : Apple Computer, Inc. ('APPL' (0x4150504C))
        Profile flags                     : 0x00000000
        Profile flags                       > Profile not embedded
        Profile flags                       > Profile can't be used independently of embedded
        Device Manufacturer               : '....' (0x00000000)
        Device Model                      : '....' (0x00000000)
        Device attributes                 : 0x00000000_00000000
        Device attributes                   > Reflective
        Device attributes                   > Glossy
        Device attributes                   > Media polarity = negative
        Device attributes                   > Black & white media
        Rendering intent                  : Perceptual
        Profile creator                   : 'lcms' (0x6C636D73)
        Profile ID                        : 0x00000000_00000000_00000000_00000000

*** Marker: DQT (xFFDB) ***
  Define a Quantization Table.
  OFFSET: 0x00000238
  Table length = 67
  ----
  Precision=8 bits
  Destination ID=0 (Luminance)
    DQT, Row #0:   8   6   5   8  12  20  26  31 
    DQT, Row #1:   6   6   7  10  13  29  30  28 
    DQT, Row #2:   7   7   8  12  20  29  35  28 
    DQT, Row #3:   7   9  11  15  26  44  40  31 
    DQT, Row #4:   9  11  19  28  34  55  52  39 
    DQT, Row #5:  12  18  28  32  41  52  57  46 
    DQT, Row #6:  25  32  39  44  52  61  60  51 
    DQT, Row #7:  36  46  48  49  56  50  52  50 
    Approx quality factor = 74.75 (scaling=50.51 variance=0.81)

*** Marker: DQT (xFFDB) ***
  Define a Quantization Table.
  OFFSET: 0x0000027D
  Table length = 67
  ----
  Precision=8 bits
  Destination ID=1 (Chrominance)
    DQT, Row #0:   9   9  12  24  50  50  50  50 
    DQT, Row #1:   9  11  13  33  50  50  50  50 
    DQT, Row #2:  12  13  28  50  50  50  50  50 
    DQT, Row #3:  24  33  50  50  50  50  50  50 
    DQT, Row #4:  50  50  50  50  50  50  50  50 
    DQT, Row #5:  50  50  50  50  50  50  50  50 
    DQT, Row #6:  50  50  50  50  50  50  50  50 
    DQT, Row #7:  50  50  50  50  50  50  50  50 
    Approx quality factor = 74.74 (scaling=50.52 variance=0.19)

*** Marker: SOF2 (Progressive DCT, Huffman) (xFFC2) ***
  OFFSET: 0x000002C2
  Frame header length = 17
  Precision = 8
  Number of Lines = 336
  Samples per Line = 276
  Image Size = 276 x 336
  Raw Image Orientation = Portrait
  Number of Img components = 3
    Component[1]: ID=0x00, Samp Fac=0x22 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (Lum: Y)
    Component[2]: ID=0x01, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x01 (Chrom: Cb)
    Component[3]: ID=0x02, Samp Fac=0x11 (Subsamp 2 x 2), Quant Tbl Sel=0x01 (Chrom: Cr)

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x000002D5
  Huffman table length = 27
  ----
  Destination ID = 0
  Class = 0 (DC / Lossless Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (001 total): 04 
    Codes of length 03 bits (005 total): 00 02 03 05 06 
    Codes of length 04 bits (001 total): 01 
    Codes of length 05 bits (001 total): 07 
    Codes of length 06 bits (000 total): 
    Codes of length 07 bits (000 total): 
    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: 008


*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x000002F2
  Huffman table length = 24
  ----
  Destination ID = 1
  Class = 0 (DC / Lossless Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (003 total): 00 01 03 
    Codes of length 03 bits (001 total): 02 
    Codes of length 04 bits (001 total): 04 
    Codes of length 05 bits (000 total): 
    Codes of length 06 bits (000 total): 
    Codes of length 07 bits (000 total): 
    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: 005


*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x0000030C
  Huffman table length = 24
  ----
  Destination ID = 1
  Class = 0 (DC / Lossless Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (003 total): 00 01 03 
    Codes of length 03 bits (001 total): 02 
    Codes of length 04 bits (001 total): 04 
    Codes of length 05 bits (000 total): 
    Codes of length 06 bits (000 total): 
    Codes of length 07 bits (000 total): 
    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: 005


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00000326
  Scan header length = 12
  Number of img components = 3
    Component[1]: selector=0x00, table=0(DC),0(AC)
    Component[2]: selector=0x01, table=1(DC),1(AC)
    Component[3]: selector=0x02, table=1(DC),1(AC)
  Spectral selection = 0 .. 0
  Successive approximation = 0x01

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x00000935
  Huffman table length = 43
  ----
  Destination ID = 0
  Class = 1 (AC Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (002 total): 02 03 
    Codes of length 03 bits (002 total): 01 04 
    Codes of length 04 bits (001 total): 00 
    Codes of length 05 bits (002 total): 11 12 
    Codes of length 06 bits (006 total): 05 10 13 20 31 32 
    Codes of length 07 bits (002 total): 21 33 
    Codes of length 08 bits (002 total): 14 22 
    Codes of length 09 bits (002 total): 34 41 
    Codes of length 10 bits (003 total): 15 23 30 
    Codes of length 11 bits (001 total): 24 
    Codes of length 12 bits (001 total): 42 
    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: 024


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00000962
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x00, table=0(DC),0(AC)
  Spectral selection = 1 .. 5
  Successive approximation = 0x02

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x000012EE
  Huffman table length = 39
  ----
  Destination ID = 1
  Class = 1 (AC Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (002 total): 00 01 
    Codes of length 03 bits (002 total): 02 11 
    Codes of length 04 bits (001 total): 10 
    Codes of length 05 bits (004 total): 03 20 21 31 
    Codes of length 06 bits (001 total): 12 
    Codes of length 07 bits (004 total): 13 30 41 51 
    Codes of length 08 bits (001 total): 22 
    Codes of length 09 bits (005 total): 32 40 42 50 61 
    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: 020


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00001317
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x02, table=1(DC),1(AC)
  Spectral selection = 1 .. 63
  Successive approximation = 0x01

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x0000142A
  Huffman table length = 36
  ----
  Destination ID = 1
  Class = 1 (AC Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (002 total): 00 01 
    Codes of length 03 bits (002 total): 02 11 
    Codes of length 04 bits (001 total): 10 
    Codes of length 05 bits (004 total): 03 20 21 31 
    Codes of length 06 bits (002 total): 12 30 
    Codes of length 07 bits (002 total): 13 41 
    Codes of length 08 bits (003 total): 22 40 51 
    Codes of length 09 bits (001 total): 50 
    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: 017


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00001450
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x01, table=1(DC),1(AC)
  Spectral selection = 1 .. 63
  Successive approximation = 0x01

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x0000155A
  Huffman table length = 51
  ----
  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 (002 total): 00 02 
    Codes of length 04 bits (003 total): 03 10 11 
    Codes of length 05 bits (006 total): 12 20 21 31 41 51 
    Codes of length 06 bits (005 total): 22 32 61 71 81 
    Codes of length 07 bits (002 total): 13 30 
    Codes of length 08 bits (005 total): 04 33 42 72 91 
    Codes of length 09 bits (004 total): 14 52 62 A1 
    Codes of length 10 bits (003 total): 23 82 B1 
    Codes of length 11 bits (001 total): 43 
    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: 032


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x0000158F
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x00, table=0(DC),0(AC)
  Spectral selection = 6 .. 63
  Successive approximation = 0x02

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x00001D3E
  Huffman table length = 40
  ----
  Destination ID = 0
  Class = 1 (AC Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (002 total): 00 01 
    Codes of length 03 bits (002 total): 11 21 
    Codes of length 04 bits (001 total): 31 
    Codes of length 05 bits (003 total): 10 41 51 
    Codes of length 06 bits (004 total): 20 61 71 A1 
    Codes of length 07 bits (002 total): 81 91 
    Codes of length 08 bits (002 total): B1 F0 
    Codes of length 09 bits (003 total): 30 C1 D1 
    Codes of length 10 bits (001 total): E1 
    Codes of length 11 bits (001 total): F1 
    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: 021


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00001D68
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x00, table=0(DC),0(AC)
  Spectral selection = 1 .. 63
  Successive approximation = 0x21

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x000028B9
  Scan header length = 12
  Number of img components = 3
    Component[1]: selector=0x00, table=0(DC),0(AC)
    Component[2]: selector=0x01, table=1(DC),1(AC)
    Component[3]: selector=0x02, table=1(DC),1(AC)
  Spectral selection = 0 .. 0
  Successive approximation = 0x10

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x000029E4
  Huffman table length = 32
  ----
  Destination ID = 1
  Class = 1 (AC Table)
    Codes of length 01 bits (001 total): 01 
    Codes of length 02 bits (001 total): 00 
    Codes of length 03 bits (001 total): 11 
    Codes of length 04 bits (000 total): 
    Codes of length 05 bits (003 total): 10 21 31 
    Codes of length 06 bits (000 total): 
    Codes of length 07 bits (003 total): 20 41 51 
    Codes of length 08 bits (001 total): 30 
    Codes of length 09 bits (001 total): 61 
    Codes of length 10 bits (001 total): 40 
    Codes of length 11 bits (001 total): 50 
    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: 013


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00002A06
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x02, table=1(DC),1(AC)
  Spectral selection = 1 .. 63
  Successive approximation = 0x10

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x00002B55
  Huffman table length = 32
  ----
  Destination ID = 1
  Class = 1 (AC Table)
    Codes of length 01 bits (001 total): 01 
    Codes of length 02 bits (000 total): 
    Codes of length 03 bits (002 total): 00 11 
    Codes of length 04 bits (003 total): 10 21 31 
    Codes of length 05 bits (001 total): 20 
    Codes of length 06 bits (001 total): 41 
    Codes of length 07 bits (000 total): 
    Codes of length 08 bits (003 total): 30 51 61 
    Codes of length 09 bits (001 total): 71 
    Codes of length 10 bits (001 total): 40 
    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: 013


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00002B77
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x01, table=1(DC),1(AC)
  Spectral selection = 1 .. 63
  Successive approximation = 0x10

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x00002CEA
  Huffman table length = 40
  ----
  Destination ID = 0
  Class = 1 (AC Table)
    Codes of length 01 bits (001 total): 01 
    Codes of length 02 bits (000 total): 
    Codes of length 03 bits (002 total): 00 11 
    Codes of length 04 bits (001 total): 21 
    Codes of length 05 bits (003 total): 31 41 51 
    Codes of length 06 bits (003 total): 10 61 71 
    Codes of length 07 bits (004 total): 81 91 A1 B1 
    Codes of length 08 bits (003 total): 20 C1 F0 
    Codes of length 09 bits (001 total): D1 
    Codes of length 10 bits (001 total): E1 
    Codes of length 11 bits (001 total): F1 
    Codes of length 12 bits (001 total): 30 
    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: 021


*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00002D14
  Scan header length = 8
  Number of img components = 1
    Component[1]: selector=0x00, table=0(DC),0(AC)
  Spectral selection = 1 .. 63
  Successive approximation = 0x10

  NOTE: Scan parsing doesn't support this SOF mode.

*** Marker: EOI (End of Image) (xFFD9) ***
  OFFSET: 0x00003DA9


*** Searching Compression Signatures ***

  Signature:           0182408A81A4ABF04D4A34A8A5E98C58
  Signature (Rotated): 012D821C6AB210E2A753BE053B8F55D0
  File Offset:         0 bytes
  Chroma subsampling:  2x2
  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?
          -------------------------   -----------------------------------   ----------------  --------------
     CAM:[SONY                     ] [CYBERSHOT U                        ] [                ] Yes              
     SW :[Adobe Photoshop 7.0      ]                                       [Save As 07      ]                  
     SW :[Apple Quicktime          ]                                       [0466-0467       ]                  
     SW :[Digital Photo Professiona]                                       [05              ]                  
     SW :[IJG Library              ]                                       [075             ]                  
     SW :[MS Paint                 ]                                       [                ]                  
     SW :[MS Visio                 ]                                       [                ]                  
     SW :[ZoomBrowser EX           ]                                       [low             ]                  

    The following IJG-based editors also match this signature:
     SW :[GIMP                     ]                                       [075             ]                  
     SW :[IrfanView                ]                                       [075             ]                  
     SW :[idImager                 ]                                       [075             ]                  
     SW :[FastStone Image Viewer   ]                                       [075             ]                  
     SW :[NeatImage                ]                                       [075             ]                  
     SW :[Paint.NET                ]                                       [075             ]                  
     SW :[Photomatix               ]                                       [075             ]                  
     SW :[XnView                   ]                                       [075             ]                  

  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]

Progressive does appear to be in the golang version. I will fix and submit a pull request.

Thank you guys for the fast responses and dedicated work! You're awesome!

Ok -- found the first problem. There was a problem with the go conversion. I have fixed that but the image still doesn't decode. I will continue to search for the problem.

I have verified that the image does work with golang. So I just have to track down the conversion error I made.

This image decoding is fixed with #351

I have another sample image (http://www.reasoft.com/tutorials/web/img/progress.jpg) that fails though -- still looking at that.

Awesome work @mweber26!

Fixed progress.jpg with pull request #352

Excellent! @YahavGB I've merged those fixes in and tested against both images. Everything now works as expected.

Much appreciated @mweber26. I'm gonna have a good dig through those classes to get a much better understanding of what is going on.

It's not that complicated. I'm not sure you would have found these bugs since they were just golang conversion issues and without reviewing the go source I don't think they would be obvious. But you can certainly learn a lot about jpeg from that code now.

Definitely! I'm going to be refactoring a few things to more closely match my style and add a lot of commenting for other developers. I've got a great book which goes through the entire spec in great detail.

Hi

I'm trying to use an image processing in my ASP.NET Core. I am uploading images from web as stream. With some images is ok, but with other is not. I have newest version from repo.

Image image = new Image(stream);

Exception message: "Bad RST marker"

Stack trace:

w ImageProcessorCore.Formats.JpegDecoderCore.ProcessSOS(Int32 n)
w ImageProcessorCore.Formats.JpegDecoderCore.Decode(Stream stream, ImageBase image, Boolean configOnly)
w ImageProcessorCore.Formats.JpegDecoder.Decode(Image image, Stream stream)
w ImageProcessorCore.Image.Load(Stream stream, IList`1 formats)
w ImageProcessorCore.Image..ctor(Stream stream, IImageFormat[] formats)
w Spire.ThumbnailServer.Helpers.ImageResizer.ResizeImage(Stream stream, ImageSize imageSize)

For png

Cannott load: 'System.IO.Compression, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

ImageProcessorCore.Formats.ZlibInflateStream..ctor(Stream stream)
w ImageProcessorCore.Formats.PngDecoderCore.ReadScanlines(MemoryStream dataStream, Single[] pixels, IColorReader colorReader, PngColorTypeInformation colorTypeInformation)
w ImageProcessorCore.Formats.PngDecoderCore.Decode(Image image, Stream stream)
w ImageProcessorCore.Formats.PngDecoder.Decode(Image image, Stream stream)
w ImageProcessorCore.Image.Load(Stream stream, IList`1 formats)
w ImageProcessorCore.Image..ctor(Stream stream)
w

Any ideas pls?

Regards

Artur

For the jpeg image, we will need a copy of the jpeg you are trying to open.

Thanks @mweber26 for picking this up :+1:

Thx a lot. Now it works. Do you have any idea about png?

@ArturGol That looks like a reference error in your solution to me. I can't download your png to test, it keeps timing out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

magic-john picture magic-john  路  7Comments

SergeBerwert picture SergeBerwert  路  4Comments

AtomicSpider picture AtomicSpider  路  3Comments

DocCaliban picture DocCaliban  路  4Comments

nul800sebastiaan picture nul800sebastiaan  路  7Comments