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

toktx: jpeg decoder does not support four-component JPEGs. #320

Open
arpu opened this issue Oct 1, 2020 · 4 comments
Open

toktx: jpeg decoder does not support four-component JPEGs. #320

arpu opened this issue Oct 1, 2020 · 4 comments
Labels

Comments

@arpu
Copy link

arpu commented Oct 1, 2020

Hey,

jpg Images cannot be encoded
toktx --t2 --2d --genmipmap --nowarn --resize 512x1024 --bcmp --clevel 1 --qlevel 255 --srgb -- /tmp/gltfpack-DviPtt.ktx2 /tmp/gltfpack-ItLgGo.jpg => 512
tested with latest master from meshoptimizer with toktx master

attached is the image
seite1_wienerwald

@MarkCallow
Copy link
Collaborator

MarkCallow commented Oct 1, 2020

JPEG images can be encoded.

This .jpg file has 4 components which is not conformant with JFIF or EXIF and not supported by the jpeg decoder I am using, which is the same one as basis_universal. What was this file created with? Photoshop?

What is in the 4th component?

@MarkCallow MarkCallow changed the title toktx: failed to create image from JPEG decode failed Warning: unable to encode image 0, skipping toktx: jpeg decoder does not support four-component JPEGS. Oct 1, 2020
@MarkCallow MarkCallow changed the title toktx: jpeg decoder does not support four-component JPEGS. toktx: jpeg decoder does not support four-component JPEGs. Oct 1, 2020
@arpu
Copy link
Author

arpu commented Oct 1, 2020

@MarkCallow Hello no idea how this image is created, any other image i tested worked fine
some user uploaded this to a server based encoding pipe

@lexaknyazev
Copy link
Member

TL;DR: The image contains lots of Photoshop-specific data and probably uses CMYK-ish color model.

Here's the output from JPEGsnoop.


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

  Filename: [94834050-2adc4a80-0410-11eb-8ebb-3d7c69edacb9.jpg]
  Filesize: [841093] Bytes

Start Offset: 0x00000000
*** Marker: SOI (xFFD8) ***
  OFFSET: 0x00000000
 
*** Marker: APP13 (xFFED) ***
  OFFSET: 0x00000002
  Length          = 4070
  Identifier      = [Photoshop 3.0]
      8BIM: [0x03ED] Name="" Len=[0x0010] DefinedName="ResolutionInfo structure"
        Horizontal resolution                              = 300 pixels per inch
        Width unit                                         = cm
        Vertical resolution                                = 300 pixels per inch
        Height unit                                        = cm
      8BIM: [0x040D] Name="" Len=[0x0004] DefinedName="Global Angle"
        Global Angle                                       = 120 degrees
      8BIM: [0x0419] Name="" Len=[0x0004] DefinedName="Global Altitude"
        Global Altitude                                    = 30 
      8BIM: [0x03F3] Name="" Len=[0x0009] DefinedName="Print flags"
        Labels                                             = false
        Crop marks                                         = false
        Color bars                                         = false
        Registration marks                                 = false
        Negative                                           = false
        Flip                                               = false
        Interpolate                                        = false
        Caption                                            = false
        Print flags                                        = true
      8BIM: [0x040A] Name="" Len=[0x0001] DefinedName="Copyright flag"
        Copyright flag                                     = false
      8BIM: [0x2710] Name="" Len=[0x000A] DefinedName="Print flags information"
        Version                                            = 1 
        Center crop marks                                  = 0 
        Reserved                                           = 0 
        Bleed width value                                  = 0 
        Bleed width scale                                  = 2 
      8BIM: [0x03F5] Name="" Len=[0x0048] DefinedName="Color halftoning information"
        Color halftoning information                       =
         | 0x00 2F 66 66 00 01 00 6C 66 66 00 06 00 00 00 00  | ./ff...lff......
         | 0x00 01 00 2F 66 66 00 01 00 A1 99 9A 00 06 00 00  | .../ff..........
         | 0x00 00 00 01 00 32 00 00 00 01 00 5A 00 00 00 06  | .....2.....Z....
         | 0x00 00 00 00 00 01 00 35 00 00 00 01 00 2D 00 00  | .......5.....-..
         | 0x00 06 00 00 00 00 00 01                          | ........        
      8BIM: [0x03F8] Name="" Len=[0x0070] DefinedName="Color transfer functions"
        Color transfer functions                           =
         | 0x00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF  | ................
         | 0xFF FF FF FF FF FF FF FF 03 E8 00 00 00 00 FF FF  | ................
         | 0xFF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF  | ................
         | 0xFF FF FF FF 03 E8 00 00 00 00 FF FF FF FF FF FF  | ................
         | 0xFF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF  | ................
         | 0x03 E8 00 00 00 00 FF FF FF FF FF FF FF FF FF FF  | ................
         | 0xFF FF FF FF FF FF FF FF FF FF FF FF 03 E8 00 00  | ................
      8BIM: [0x0400] Name="" Len=[0x0002] DefinedName="Layer state information"
        Target layer                                       = 1 
      8BIM: [0x0402] Name="" Len=[0x0004] DefinedName="Layers group information"
        Layer #0:                                         
          Layer Group                                        = 0 
        Layer #1:                                         
          Layer Group                                        = 0 
      8BIM: [0x0408] Name="" Len=[0x0010] DefinedName="Grid and guides information"
        Version                                            = 1 
        Grid Horizontal                                    = 576 
        Grid Vertical                                      = 576 
        Number of Guide Resources                          = 0 
      8BIM: [0x041E] Name="" Len=[0x0004] DefinedName="URL List"
        URL List                                           =  | 0x00 00 00 00                                      | ....            
      8BIM: [0x041A] Name="" Len=[0x0079] DefinedName="Slices"
        Slice Header:                                     
          Version                                            = 6 
          Bound Rect (top)                                   = 0 
          Bound Rect (left)                                  = 0 
          Bound Rect (bottom)                                = 1181 
          Bound Rect (right)                                 = 572 
          Name of group of slices                            = "Ohne Titel-2"
          Number of slices                                   = 1 
          -----                                             
          Slice #0:                                         
            Slice Resource:                                   
              ID                                                 = 0 
              Group ID                                           = 0 
              Origin                                             = 0 
              Name                                               = ""
              Type                                               = 1 
              Position (top)                                     = 0 
              Position (left)                                    = 0 
              Position (bottom)                                  = 572 
              Position (right)                                   = 1181 
              URL                                                = ""
              Target                                             = ""
              Message                                            = ""
              Alt Tag                                            = ""
              Cell text is HTML                                  = false
              Cell text                                          = ""
              Horizontal alignment                               = 0 
              Vertical alignment                                 = 0 
              Alpha color                                        = 0 
              Red                                                = 0 
              Green                                              = 0 
              Blue                                               = 0 
          -----                                             
      8BIM: [0x0411] Name="" Len=[0x0001] DefinedName="ICC Untagged Profile"
        ICC Untagged Profile                               =  | 0x01                                               | .               
      8BIM: [0x0414] Name="" Len=[0x0004] DefinedName="Document-specific IDs seed number"
        Base value                                         = 2 
      8BIM: [0x040C] Name="" Len=[0x0C05] DefinedName="Thumbnail resources"
        Format                                             = 1 
        Width of thumbnail                                 = 54 pixels
        Height of thumbnail                                = 112 pixels
        Widthbytes                                         = 164 bytes
        Total size                                         = 18368 bytes
        Size after compression                             = 3049 bytes
        Bits per pixel                                     = 24 bits
        Number of planes                                   = 1 
        JFIF data                                          @ 0x00000364
      8BIM: [0x0421] Name="" Len=[0x0055] DefinedName="Version Info"
        Version                                            = 1 
        hasRealMergedData                                  = 1 
        Writer name                                        = "Adobe Photoshop"
        Reader name                                        = "Adobe Photoshop 6.0"
        File version                                       = 1 
      8BIM: [0x0406] Name="" Len=[0x0007] DefinedName="JPEG quality"
        Photoshop Save As Quality                          = 12 
        Photoshop Save Format                              = "Standard"
        Photoshop Save Progressive Scans                   = "3 Scans"
        ???                                                = 1 
 
*** Marker: APP14 (xFFEE) ***
  OFFSET: 0x00000FEA
  Length            = 14
  DCTEncodeVersion  = 100
  APP14Flags0       = 16384
  APP14Flags1       = 0
  ColorTransform    = 2 [YCCK]
 
*** Marker: DQT (xFFDB) ***
  Define a Quantization Table.
  OFFSET: 0x00000FFA
  Table length = 132
  ----
  Precision=8 bits
  Destination ID=0 (Luminance)
    DQT, Row #0:   1   1   1   1   1   1   1   1 
    DQT, Row #1:   1   1   1   1   1   1   1   1 
    DQT, Row #2:   1   1   1   1   1   1   1   2 
    DQT, Row #3:   1   1   1   1   1   1   2   2 
    DQT, Row #4:   1   1   1   1   1   2   2   3 
    DQT, Row #5:   1   1   1   1   2   2   3   3 
    DQT, Row #6:   1   1   1   2   2   3   3   3 
    DQT, Row #7:   1   1   2   2   3   3   3   3 
    Approx quality factor = 98.25 (scaling=3.50 variance=4.81)
  ----
  Precision=8 bits
  Destination ID=1 (Chrominance)
    DQT, Row #0:   1   1   1   1   2   3   3   3 
    DQT, Row #1:   1   1   1   2   3   3   3   3 
    DQT, Row #2:   1   1   1   3   3   3   3   3 
    DQT, Row #3:   1   2   3   3   3   3   3   3 
    DQT, Row #4:   2   3   3   3   3   3   3   3 
    DQT, Row #5:   3   3   3   3   3   3   3   3 
    DQT, Row #6:   3   3   3   3   3   3   3   3 
    DQT, Row #7:   3   3   3   3   3   3   3   3 
    Approx quality factor = 98.42 (scaling=3.16 variance=0.50)
 
*** Marker: SOF0 (Baseline DCT) (xFFC0) ***
  OFFSET: 0x00001080
  Frame header length = 20
  Precision = 8
  Number of Lines = 1181
  Samples per Line = 572
  Image Size = 572 x 1181
  Raw Image Orientation = Portrait
  Number of Img components = 4
    Component[1]: ID=0x01, Samp Fac=0x11 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (Y)
    Component[2]: ID=0x02, Samp Fac=0x11 (Subsamp 1 x 1), Quant Tbl Sel=0x01 (Cb)
    Component[3]: ID=0x03, Samp Fac=0x11 (Subsamp 1 x 1), Quant Tbl Sel=0x01 (Cr)
    Component[4]: ID=0x04, Samp Fac=0x11 (Subsamp 1 x 1), Quant Tbl Sel=0x00 (K)
 
*** Marker: DRI (Restart Interval) (xFFDD) ***
  OFFSET: 0x00001096
  Length     = 4
  interval   = 72
 
*** Marker: DHT (Define Huffman Table) (xFFC4) ***
  OFFSET: 0x0000109C
  Huffman table length = 418
  ----
  Destination ID = 0
  Class = 0 (DC / Lossless Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (000 total): 
    Codes of length 03 bits (006 total): 07 08 06 05 04 09 
    Codes of length 04 bits (002 total): 03 0A 
    Codes of length 05 bits (003 total): 02 01 00 
    Codes of length 06 bits (001 total): 0B 
    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: 012

  ----
  Destination ID = 1
  Class = 0 (DC / Lossless Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (000 total): 
    Codes of length 03 bits (006 total): 06 05 04 03 07 02 
    Codes of length 04 bits (003 total): 08 01 09 
    Codes of length 05 bits (001 total): 00 
    Codes of length 06 bits (001 total): 0A 
    Codes of length 07 bits (001 total): 0B 
    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: 012

  ----
  Destination ID = 0
  Class = 1 (AC Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (002 total): 01 02 
    Codes of length 03 bits (001 total): 03 
    Codes of length 04 bits (003 total): 04 11 05 
    Codes of length 05 bits (004 total): 12 06 21 07 
    Codes of length 06 bits (001 total): 13 
    Codes of length 07 bits (003 total): 22 00 08 
    Codes of length 08 bits (003 total): 31 14 41 
    Codes of length 09 bits (002 total): 32 23 
    Codes of length 10 bits (003 total): 15 09 51 
    Codes of length 11 bits (003 total): 42 16 61 
    Codes of length 12 bits (003 total): 24 33 17 
    Codes of length 13 bits (002 total): 52 71 
    Codes of length 14 bits (006 total): 81 18 62 91 25 43 
    Codes of length 15 bits (009 total): A1 B1 F0 26 34 72 0A 19 C1 
    Codes of length 16 bits (117 total): D1 35 27 E1 53 36 82 F1 92 A2 44 54 73 45 46 37 
                                         47 63 28 55 56 57 1A B2 C2 D2 E2 F2 64 83 74 93 
                                         84 65 A3 B3 C3 D3 E3 29 38 66 F3 75 2A 39 3A 48 
                                         49 4A 58 59 5A 67 68 69 6A 76 77 78 79 7A 85 86 
                                         87 88 89 8A 94 95 96 97 98 99 9A A4 A5 A6 A7 A8 
                                         A9 AA B4 B5 B6 B7 B8 B9 BA C4 C5 C6 C7 C8 C9 CA 
                                         D4 D5 D6 D7 D8 D9 DA E4 E5 E6 E7 E8 E9 EA F4 F5 
                                         F6 F7 F8 F9 FA 
    Total number of codes: 162

  ----
  Destination ID = 1
  Class = 1 (AC Table)
    Codes of length 01 bits (000 total): 
    Codes of length 02 bits (002 total): 01 02 
    Codes of length 03 bits (001 total): 03 
    Codes of length 04 bits (003 total): 11 04 21 
    Codes of length 05 bits (002 total): 12 05 
    Codes of length 06 bits (004 total): 31 06 00 22 
    Codes of length 07 bits (004 total): 13 41 51 07 
    Codes of length 08 bits (003 total): 32 61 14 
    Codes of length 09 bits (005 total): 71 08 42 81 23 
    Codes of length 10 bits (004 total): 91 15 52 A1 
    Codes of length 11 bits (004 total): 62 16 33 09 
    Codes of length 12 bits (004 total): B1 24 C1 D1 
    Codes of length 13 bits (006 total): 43 72 F0 17 E1 82 
    Codes of length 14 bits (006 total): 34 25 92 53 18 63 
    Codes of length 15 bits (005 total): 44 F1 A2 B2 26 
    Codes of length 16 bits (109 total): 35 19 54 36 45 64 27 0A 73 83 93 46 74 C2 D2 E2 
                                         F2 55 65 75 56 37 84 85 A3 B3 C3 D3 E3 F3 29 1A 
                                         94 A4 B4 C4 D4 E4 F4 95 A5 B5 C5 D5 E5 F5 28 47 
                                         57 66 38 76 86 96 A6 B6 C6 D6 E6 F6 67 77 87 97 
                                         A7 B7 C7 D7 E7 F7 48 58 68 78 88 98 A8 B8 C8 D8 
                                         E8 F8 39 49 59 69 79 89 99 A9 B9 C9 D9 E9 F9 2A 
                                         3A 4A 5A 6A 7A 8A 9A AA BA CA DA EA FA 
    Total number of codes: 162

 
*** Marker: SOS (Start of Scan) (xFFDA) ***
  OFFSET: 0x00001240
  Scan header length = 14
  Number of img components = 4
    Component[1]: selector=0x01, table=0(DC),0(AC)
    Component[2]: selector=0x02, table=1(DC),1(AC)
    Component[3]: selector=0x03, table=1(DC),1(AC)
    Component[4]: selector=0x04, 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: 0x000CD583


*** Searching Compression Signatures ***

  Signature:           01C1158E443D1C90F302FF6BE49DDD87
  Signature (Rotated): 01C1158E443D1C90F302FF6BE49DDD87
  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 :[Adobe Photoshop          ]                                       [Save As 12      ]                  

  NOTE: Photoshop IRB detected
  Based on the analysis of compression characteristics and EXIF metadata:

  ASSESSMENT: Class 1 - Image is processed/edited

@lexaknyazev
Copy link
Member

lexaknyazev commented Oct 5, 2020

@MarkCallow
We may need to give meaningful warnings on JPEG inputs with complex color space metadata.

A few highlights:

  • JFIF files (identified by APP0 with JFIF tag) are either grayscale or YCbCr. They may optionally contain an ICC profile in APP2.
  • EXIF files (identified by APP2 with EXIF tag) can contain so many configurations that correctly handling all (or even most) of them certainly requires a dedicated software package.
  • Adobe files (identified by APP13 and APP14 tags) contain extra metadata on how the image was produced. The interesting bit here is the ColorTransform flag inside APP14. YCCK means that the fourth component contains black values to restore the original CMYK image. It could be safely ignored by libKTX.

@MarkCallow MarkCallow added the bug label Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants