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

image/jpeg: support for yuvj444p jpeg images #29512

Open
AshKash opened this issue Jan 2, 2019 · 1 comment
Open

image/jpeg: support for yuvj444p jpeg images #29512

AshKash opened this issue Jan 2, 2019 · 1 comment

Comments

@AshKash
Copy link

@AshKash AshKash commented Jan 2, 2019

What version of Go are you using (go version)?

go version go1.11.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/xxx/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.2/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vh/n9x4w_4d19j638bvjrl85tvm0000gn/T/go-build328625839=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ curl -o x.jpg https://stat.ameba.jp/user_images/20130130/12/k15911/4c/c4/p/o0800064012397991799.png

$ file x.jpg

x.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, progressive, precision 8, 800x640, frames 3

$ ffmpeg -i x.jpg
Input #0, image2, from 'x.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 36507 kb/s
Stream #0:0: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 800x640 [SAR 1:1 DAR 5:4], 25 tbr, 25 tbn, 25 tbc

image.DecodefConfig() and image.Decode() both throw an error for this file (did import _ image/jpeg).

Does the jpeg decoder support this pixel format? Note: the originating website has named the file as .png but it is a jpg file, so ignore that for now.

Another url with similar error: https://www.ikea.com/es/es/images/products/malm-estruc-cama-2-caj-blanco__0559854_pe662044_s4.jpg

The all open fine in the browser and other tools like ffmpeg and imagemagick.

What did you expect to see?

Expect Go to support these file like other normal image processing tools.

What did you see instead?

error decoding: image: unknown format

x

@agnivade agnivade changed the title image/jpeg support for yuvj444p jpeg images image/jpeg: support for yuvj444p jpeg images Jan 3, 2019
@agnivade agnivade added this to the Unplanned milestone Jan 3, 2019
@dlespiau
Copy link
Contributor

@dlespiau dlespiau commented Feb 9, 2021

tldr; This issues seems like a false positive and should be closed. It seems likely the author hasn't given the right buffer/reader to Decode.

  1. I've checked that the first image is still the same by running file and ffmpeg -i on a newly downloaded version of https://stat.ameba.jp/user_images/20130130/12/k15911/4c/c4/p/o0800064012397991799.png.
  2. The reported "image: unknown format" error is returned in only one case: when the Decode/DecodeConfig function can't detect the image format. The image format is determined by looking at the magic number(s) at the start of the file. For JPEG it's comparing the 2 first bytes of the io.Reader with ff d8.
  3. hexdump -C -n 16 on the first jpeg returns valid looking first bytes:
hexdump -C -n 16 issue-29512.jpeg
00000000  ff d8 ff e0 00 10 4a 46  49 46 00 01 01 00 00 01  |......JFIF......|
  1. And indeed I can run a little program that is able to decode the image linked here (pasted for reference).

My conclusion is that the author passed a reader that wasn't at the start of the file, for some reason. The only failure case possible is that the two first bytes of the reader weren't ff d8

ackage main

import (
	"encoding/hex"
	"fmt"
	"image"
	"log"
	"os"

	_ "image/jpeg"
	"image/png"
)

func hexdump(filename string, n int) error {
	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()

	data := make([]byte, n)
	_, err = f.Read(data)
	if err != nil {
		return err
	}

	fmt.Println(hex.Dump(data))

	return nil
}

func decodeConfig(filename string) error {
	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()

	config, format, err := image.DecodeConfig(f)
	if err != nil {
		return err
	}

	fmt.Println("Width:", config.Width, "Height:", config.Height, "Format:", format)

	return nil
}

func convert(filename, out string) error {
	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()

	img, _, err := image.Decode(f)
	if err != nil {
		return nil
	}

	g, err := os.Create(out)
	if err != nil {
		return err
	}
	defer g.Close()
	if err := png.Encode(g, img); err != nil {
		return err
	}
	return nil
}

func main() {
	filename := os.Args[1]

	if err := hexdump(filename, 16); err != nil {
		log.Fatal("hexdump:", err)
	}

	if err := decodeConfig(filename); err != nil {
		log.Fatal("decodeConfig", err)
	}

	convert(filename, "out.png")
}

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants