GithubHelp home page GithubHelp logo

pixiv / go-libjpeg Goto Github PK

View Code? Open in Web Editor NEW
153.0 98.0 53.0 2.82 MB

An implementation of Go binding for libjpeg (or libjpeg-turbo).

License: BSD 3-Clause "New" or "Revised" License

Go 97.85% C 1.70% Shell 0.45%

go-libjpeg's Introduction

go-libjpeg

GoDoc Build Status

An implementation of Go binding for LibJpeg (preferably libjpeg-turbo).

The core codes are picked from go-thumber and rewritten to compatible with image.Image interface.

Usage

import "github.com/pixiv/go-libjpeg/jpeg"

func main() {
    // Decoding JPEG into image.Image
    io, err := os.Open("in.jpg")
    if err != nil {
        log.Fatal(err)
    }
    img, err := jpeg.Decode(io, &jpeg.DecoderOptions{})
    if err != nil {
        log.Fatalf("Decode returns error: %v\n", err)
    }

    // Encode JPEG
    f, err := os.Create("out.jpg")
    if err != nil {
        panic(err)
    }
    w := bufio.NewWriter(f)
    if err := jpeg.Encode(w, img, &jpeg.EncoderOptions{Quality: 90}); err != nil {
        log.Printf("Encode returns error: %v\n", err)
        return
    }
    w.Flush()
    f.Close()
}

See test code to read full features.

Features

  • Raw JPEG decoding in YCbCr color.
  • Decoding with color conversion into RGB/RGBA (RGBA conversion is only supported with libjpeg-turbo).
  • Scaled decoding.
  • Encoding from some color models (YCbCr, RGB and RGBA).

Benchmark

$ go test -bench . -benchtime 10s
...
BenchmarkDecode                     1000          26345730 ns/op
BenchmarkDecodeIntoRGB               500          30886383 ns/op
BenchmarkDecodeWithNativeJPEG        300          49815928 ns/op
...

With libjpeg-turbo:

BenchmarkDecode                     2000           9557646 ns/op
BenchmarkDecodeIntoRGB              1000          12676414 ns/op
BenchmarkDecodeWithNativeJPEG        300          45836153 ns/op

go-libjpeg is about 1.9x faster than image/jpeg. With libjpeg-turbo, it can make more faster (about 4.8x faster than image/jpeg).

Dependencies

  • Go 1.6 or later.

  • libjpeg (preferably libjpeg-turbo)

    DecodeIntoRGBA can only work if go-libjpeg is built with libjpeg-turbo. Because DecdeIntoRGBA uses JCS_ALPHA_EXTENSIONS. You can use DecodeIntoRGB and convert to image.RGBA if can not use libjpeg-turbo.

License

Copyright (c) 2014 pixiv Inc. All rights reserved.

See LICENSE.

go-libjpeg's People

Contributors

bayandin avatar captaincodeman avatar codeskyblue avatar edvakf avatar harukasan avatar rosylilly avatar saturday06 avatar thinxer avatar umemori avatar unak avatar walf443 avatar ykzts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-libjpeg's Issues

Memory leak

Both compress.go and decompress.go leak memory. The cinfo structs are malloced in new_decompress but never freeed in destroy_decompress.

selecting libjpeg or libjpeg-turbo

By default the package links against libjpeg on my ubuntu 16.04. However, libjpeg-turbo8 is also available. I was hoping that the turbo library would be selected at compile time, but it seems go-libjpeg favours libjpeg, at least on my system. In the cgo header somwhere I noticed there is a "-ljpeg" presumably this will therefore only link against libjpeg. Could you advice how I would select libjpeg-turbo instead?

Cheers,
Hrob.

Streaming image decoding via go channels

For interactive programs, it is useful to be able to decode large images in pieces in order to improve responsiveness. I have implemented a draft version of a "streaming" API which returns Subimages on a go channel if a channel is passed to the jpeg.Decode function. See here:

https://github.com/gmp216/go-libjpeg/tree/streaming

If no channel is provided, the Decode function should perform as before. This is useful but not fully implemented yet since rgb.Image does not implement the Subimage function that is available for most of the built-in image types (DecodeRGB and DecodeIntoRGB return Subimages with the wrong bounds).

Example:

fd,err := os.Open(filename)
ch := make(chan image.Image)
go func() {
    for im := range(ch) {
        ...
    }
}()
i,err := jpeg.Decode(fd,&jpeg.DecoderOptions{},ch)
...

Any thoughts on this implementation are appreciated. Currently it is not possible to specify the number of lines (or max pixels) to return in each Subimage. This could possibly be added as an option in jpeg.DecoderOptions.

"SIGSEGV: segmentation violation" in parallel processing of corrupted image

One more crash found by go-fuzz.

Run the following program on the following input:

// +build ignore

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"

	"github.com/pixiv/go-libjpeg/jpeg"
)

func processImage(data []byte, times int) {
	for i := 0; i < times; i++ {
		jpeg.DecodeConfig(bytes.NewReader(data))
	}
	fmt.Println("Done")
}

func main() {
	data, err := ioutil.ReadFile(os.Args[1])
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}

	for i := 0; i < 16; i++ {
		go processImage(data, 100)
	}

	fmt.Scanln()
}

a9db04212c08d15adf35b50454df05adbc1f18d9 (it shows as corrupted image as expected)

it crashes like this:

...
Corrupt JPEG data: 9455 extraneous bytes before marker 0xe9
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xafffffe pc=0x4208527]

runtime stack:
runtime.throw(0x40ee7ab, 0x2a)
	/usr/local/Cellar/go/1.12.9/libexec/src/runtime/panic.go:617 +0x72
runtime.sigpanic()
	/usr/local/Cellar/go/1.12.9/libexec/src/runtime/signal_unix.go:374 +0x4a9

goroutine 25 [syscall]:
runtime.cgocall(0x40ab780, 0xc0001f4eb8, 0xc000086d80)
	/usr/local/Cellar/go/1.12.9/libexec/src/runtime/cgocall.go:128 +0x5b fp=0xc0001f4e88 sp=0xc0001f4e50 pc=0x40050cb
github.com/pixiv/go-libjpeg/jpeg._Cfunc_read_header(0xaa000d0, 0x1, 0x0)
	_cgo_gotypes.go:904 +0x4d fp=0xc0001f4eb8 sp=0xc0001f4e88 pc=0x40a80ed
github.com/pixiv/go-libjpeg/jpeg.readHeader.func1(0xaa000d0, 0xc000000008)
	/Users/bayandin/go/src/github.com/pixiv/go-libjpeg/jpeg/decompress.go:187 +0x5e fp=0xc0001f4ef0 sp=0xc0001f4eb8 pc=0x40a96ee
github.com/pixiv/go-libjpeg/jpeg.readHeader(0xaa000d0, 0x40efab8, 0xc0001f4f88)
	/Users/bayandin/go/src/github.com/pixiv/go-libjpeg/jpeg/decompress.go:187 +0x2f fp=0xc0001f4f28 sp=0xc0001f4ef0 pc=0x40a877f
github.com/pixiv/go-libjpeg/jpeg.DecodeConfig(0x4104ce0, 0xc00013cd80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/bayandin/go/src/github.com/pixiv/go-libjpeg/jpeg/decompress.go:487 +0xb6 fp=0xc0001f4f58 sp=0xc0001f4f28 pc=0x40a88d6
main.processImage(0xc0000be000, 0x53f5b, 0x5415b, 0x64)
	/Users/bayandin/go/src/github.com/pixiv/go-libjpeg/test.go:16 +0x4a fp=0xc0001f4fc0 sp=0xc0001f4f58 pc=0x40aaa7a
runtime.goexit()
	/usr/local/Cellar/go/1.12.9/libexec/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc0001f4fc8 sp=0xc0001f4fc0 pc=0x40546a1
created by main.main
	/Users/bayandin/go/src/github.com/pixiv/go-libjpeg/test.go:29 +0xc4
...

here is the full output (if needed): full-output.log

go version go1.12.9 linux/amd64
libjpeg-turbo 2.0.2
repo is on commit 3da21a74767d9ffe29fcad7484ddd745f99e9f4c

Partially decode images

There is an interesting issue here golang/go#10447 , it would be great if you can support that in some way. Maybe to not return nil, err, but image, err where and if possible. Browsers are usually very tolerant and will try their best to display images, even if they are invalid. That can be useful in many cases I guess, not just for browsers.

go-libjpeg error jpeglib.h not found

When I run the following I get this error:
jerald$ go get github.com/pixiv/go-libjpeg/jpeg
go/src/github.com/pixiv/go-libjpeg/jpeg/compress.go:6:10: fatal error: 'jpeglib.h' file not found
#include "jpeglib.h"

Any advice?

Edit: Never mind. It was an oversight on my part. I just ran brew install jpeg and the issue was fixed.

SEGV on DecodeConfig

reported by @Gaillard in #36:

"""
I am also getting another seg fault going through DecodeConfig, maybe unrelated. I don't have a test case for that one though, just the stack.

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x2 addr=0x7f6f88000388 pc=0x7f6f88000388]

runtime stack:
runtime.throw(0x1a7eb53, 0x2a)
    /usr/local/go/src/runtime/panic.go:566 +0x95
runtime.sigpanic()
    /usr/local/go/src/runtime/sigpanic_unix.go:12 +0x2cc

goroutine 49 [syscall, locked to thread]:
runtime.cgocall(0xbea500, 0xc420349638, 0xc400000000)
    /usr/local/go/src/runtime/cgocall.go:131 +0x110 fp=0xc420349608 sp=0xc4203495c8
NAME/vendor/github.com/pixiv/go-libjpeg/jpeg._Cfunc_new_decompress(0x0)
    ??:0 +0x4a fp=0xc420349638 sp=0xc420349608
NAME/vendor/github.com/pixiv/go-libjpeg/jpeg.DecodeConfig(0x25127e0, 0xc4202a20e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /home/gaillard/go/src/NAME/vendor/github.com/pixiv/go-libjpeg/jpeg/decompress.go:323 +0xa4 fp=0xc420349688 sp=0xc420349638

"""

install error jpeglib.h

Tried to install it to my Raspberry Pi 3B with Raspbian Stretch and Go 1.10.1 but got this error:

pi@BM-Raspi-Server:~ $ go get github.com/barnacs/compy
# github.com/pixiv/go-libjpeg/jpeg
go/src/github.com/pixiv/go-libjpeg/jpeg/compress.go:6:21: fatal error: jpeglib.h: No such file or directory
 #include "jpeglib.h"
                     ^
compilation terminated.

How can I fix it?

YCbCr 4:2:0 reads from out of bounds memory

During encoding I think YCbCr 4:2.0 may read from locations of the Cb and Cr planes that are out of bounds.

I also think it happens when the image width/height is not a multiple of 16 (8?).

E.g. 1280x720 is fine while 1920x1080 is not (8 pixel rows missing for being multiple of 16).

Primarily manifests itself on Windows platform. It seems to crash here quite reliably while on Linux and macOS it accepts the read (may be just a random factor).

One can work around it by over-allocating the YCbCr image buffers, but it is not obvious to the user, but I'm also unsure what actually happens with the bogus data that is then read (does it corrupt the originally expected image data?).

go-libjpeg integration

Purpose

We are now working with two LibJPEG bindings (public go-libjpeg and the another private one).
The issue aims to integrate these projects.

TODO

  • 1. Backporting error handling to go-libjpeg
  • 2. Make public low-level decoding/encoding functions
  • 3. Delete the private one

Related issues

Encoder options for chroma subsampling?

Hi,

I want to control the chroma subsampling ratios for encoding.
Now it's the same as the src image. Is there any way I can set a different value?

Thank you very much! Any help is much appreciated.

Encoding *image.NRGBA

Hello, I'm currently using 'github.com/disintegration/imaging' for image transformations and want to encode resulting image to jpeg using mozjpeg with this bindings. But 'disintegration/imaging' library returns images in NRGBA format, which go-libjpeg cannot understand.

Should NRGBA be added to this bindings or should I convert image from NRGBA to one of supported color schemes?

Seg fault going through DecodeIntoRGBA with DisableFancyUpsampling = true

When I leave DisableFancyUpsampling to false it is fine.

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x80 addr=0x0 pc=0x7f6c467b5eb7]

runtime stack:
runtime.throw(0x616bd5, 0x2a)
	/usr/local/go/src/runtime/panic.go:566 +0x95
runtime.sigpanic()
	/usr/local/go/src/runtime/sigpanic_unix.go:12 +0x2cc

goroutine 11 [syscall, locked to thread]:
runtime.cgocall(0x5a6260, 0xc42004fcb0, 0x0)
	/usr/local/go/src/runtime/cgocall.go:131 +0x110 fp=0xc42004fc68 sp=0xc42004fc28
NAME/vendor/github.com/pixiv/go-libjpeg/jpeg._Cfunc_jpeg_read_scanline(0x7f6c380008c0, 0xc4200bc000, 0x2, 0x0)
	??:0 +0x4d fp=0xc42004fcb0 sp=0xc42004fc68
NAME/vendor/github.com/pixiv/go-libjpeg/jpeg.readScanLines(0x7f6c380008c0, 0xc4200bc000, 0x16e3600, 0x16e3600, 0x2ee0)
	/home/gaillard/go/src/NAME/vendor/github.com/pixiv/go-libjpeg/jpeg/decompress.go:305 +0x120 fp=0xc42004fd00 sp=0xc42004fcb0
NAME/vendor/github.com/pixiv/go-libjpeg/jpeg.DecodeIntoRGBA(0x8ec580, 0xc42002e020, 0xc42004fdd8, 0xc42009e000, 0x0, 0x0)
	/home/gaillard/go/src/NAME/vendor/github.com/pixiv/go-libjpeg/jpeg/decompress.go:297 +0x33d fp=0xc42004fda0 sp=0xc42004fd00

... lines from our code ...

Nice library, is this a known issue?

I'm testing this on amd64 on version 1.5.1 of libjpeg-turbo.

Support to encode image.RGBA?

It seems right now jpeg.Encode() can only take image.Gray and image.YCBCr.
Is it possible to support image.RGBA? I have images generated by image/draw, which cannot be image.YCBCr.

Encoding after decoding failed: unsupported image type

Here is another issue I found with the help of go-fuzz:
I'm able to decode data but aren't able to encode it back.

package main

import (
	"bytes"
	"fmt"

	"github.com/pixiv/go-libjpeg/jpeg"
)

func main() {
	data := []byte("\xff\xd8\xff\xdb\x00C\x000000000000000" +
		"00000000000000000000" +
		"00000000000000000000" +
		"00000000000\xff\xc0\x00\x11\b\x00000" +
		"\x03R\"\x00G\x11\x00B\x11\x00\xff\xda\x00\f\x03R\x00G\x00B" +
		"\x00")

	img, err := jpeg.Decode(bytes.NewReader(data), &jpeg.DecoderOptions{})
	if err != nil {
		return
	}

	var w bytes.Buffer
	err = jpeg.Encode(&w, img, &jpeg.EncoderOptions{})
	if err != nil {
		panic(err)
	}
}

It prints

Invalid SOS parameters for sequential JPEG
panic: unsupported image type

I use go version go1.12.9 darwin/amd64, libjpeg-turbo 2.0.2

Support pkg-config installs of libjpeg please?

You may wish to solve this a different way so i didn't do a PR, but simply adding this line right after the #cgo LDFLAGS in jpeg/jpeg.go allows modern systems with pkg-config setups to work; then setting PKG_CONFIG_PATH is enough to get even weird install locations to work

#cgo LDFLAGS: -ljpeg
#cgo pkg-config: libjpeg

Supports decoding RGB, CMYK and YCCK images.

Go 1.5 adds to support decoding RGB, CMYK and YCCK JPEGs.

We should follow this change, but image.CMYK struct is provided only Go 1.5 (added here: golang/go@b5c3a9e) and later, probably.

We can not bind library version to runtime version in current Go build system, so we have some plans:

  • Implements own image.CMYK struct that implements to image.Image interface.
  • Support only Go 1.5 and later.
  • ...

getting error while go get github.com/pixiv/go-libjpeg/jpeg

# github.com/pixiv/go-libjpeg/jpeg
go/pkg/mod/github.com/pixiv/[email protected]/jpeg/compress.go:6:10: fatal error: jpeglib.h: No such file or directory
 #include "jpeglib.h"
          ^~~~~~~~~~~
compilation terminated.

The above block appears while executing go get, any idea what to do next.
Any help would be appreciated.
Best regards
Ashutosh

signal SIGSEGV: segmentation violation

I'm playing with go-fuzz and have found a crash:

package main

import (
	"bytes"

	"github.com/pixiv/go-libjpeg/jpeg"
)

func main() {
	data := []byte("\xff\xd8\xff\xdb\x00C\x000000000000000" +
		"00000000000000000000" +
		"00000000000000000000" +
		"00000000000\xff\xc9\x00\v\b00\x000" +
		"\x01\x01\x14\x00\xff\xda\x00\b\x01\x010\x00?\x0000")
	jpeg.Decode(bytes.NewReader(data), &jpeg.DecoderOptions{})
}
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f321d858a60]

runtime stack:
runtime.throw(0x4d5feb, 0x2a)
	/usr/local/go/src/runtime/panic.go:617 +0x72
runtime.sigpanic()
	/usr/local/go/src/runtime/signal_unix.go:374 +0x4a9

goroutine 1 [syscall]:
runtime.cgocall(0x495f40, 0xc000040e60, 0x495f00)
	/usr/local/go/src/runtime/cgocall.go:128 +0x5b fp=0xc000040e30 sp=0xc000040df8 pc=0x405f7b
github.com/pixiv/go-libjpeg/jpeg._Cfunc_decode_gray(0x21257e0, 0xc0000a2000, 0x2000000040)
	_cgo_gotypes.go:678 +0x45 fp=0xc000040e60 sp=0xc000040e30 pc=0x490ec5
github.com/pixiv/go-libjpeg/jpeg.decodeGray.func3(0x21257e0, 0xc000040ef0, 0x20)
	/go/src/github.com/pixiv/go-libjpeg/jpeg/decompress.go:189 +0x96 fp=0xc000040ea8 sp=0xc000040e60 pc=0x493b96
github.com/pixiv/go-libjpeg/jpeg.decodeGray(0x21257e0, 0xc000096140, 0xc000040f48, 0xc000040f01)
	/go/src/github.com/pixiv/go-libjpeg/jpeg/decompress.go:189 +0xe1 fp=0xc000040ee8 sp=0xc000040ea8 pc=0x4920c1
github.com/pixiv/go-libjpeg/jpeg.Decode(0x4e9480, 0xc00007e1b0, 0xc000040f58, 0x0, 0x0, 0x0, 0x0)
	/go/src/github.com/pixiv/go-libjpeg/jpeg/decompress.go:164 +0x151 fp=0xc000040f20 sp=0xc000040ee8 pc=0x491e21
main.main()
	/go/test.go:15 +0xe4 fp=0xc000040f98 sp=0xc000040f20 pc=0x495634
runtime.main()
	/usr/local/go/src/runtime/proc.go:200 +0x20c fp=0xc000040fe0 sp=0xc000040f98 pc=0x42d82c
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000040fe8 sp=0xc000040fe0 pc=0x455351
exit status 2

go version go1.12.9 linux/amd64
libjpeg-turbo 2.0.2

Slowness compared to calling cjpeg directly

Hi,

I'm trying to get up to speed using this library as a wrapper around mozjpeg.

This is possibly due to a misunderstanding on my part... But I noticed that running a Go script which is equivalent to calling cjpeg directly performs worse. Running the following two snippets on this image produces the following results.

package main

import (
	"log"
	"os"

	"github.com/pixiv/go-libjpeg/jpeg"
)

func main() {
	f, err := os.Open("test-1.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	m, err := jpeg.Decode(f, &jpeg.DecoderOptions{})
	if err != nil {
		log.Fatal(err)
	}

	fOut, err := os.Create("test-1.compressed.jpg")
	if err != nil {
		log.Fatal(err)
	}
	defer fOut.Close()

	if err := jpeg.Encode(fOut, m, &jpeg.EncoderOptions{Quality: 75}); err != nil {
		log.Fatal(err)
	}
}

root@bf5cf2b9311b:/go/src/tmp# time ./tmp
real    0m3.563s
user    0m3.400s
sys     0m0.100s
root@bf5cf2b9311b:/go/src/tmp# time /opt/mozjpeg/bin/cjpeg -quality 75 test-1.jpg  > test-1.compressed.jpg

real    0m2.391s
user    0m2.300s
sys     0m0.060s

Would appreciate any ideas!

How to fix JCS_EXT_RGBA is not supported on osx?

I run app with next env on osx

CGO_CFLAGS=-I/usr/local/opt/jpeg/include
CGO_CFLAGS_ALLOW=-Xpreprocessor
CGO_ENABLED=1
CGO_LDFLAGS=-L/usr/local/opt/jpeg/lib

Get an error on jpeg.Encode

JCS_EXT_RGBA is not supported (probably built without libjpeg-turbo)

thank you

illegal text-relocation to _jpeg_resync_to_restart

Static link jpeg-turbo (libjpeg.a)
#cgo LDFLAGS: /usr/local/opt/jpeg-turbo/lib/libjpeg.a
ld: illegal text-relocation (/usr/local/opt/jpeg-turbo/lib/libjpeg.dylib)
/usr/local/Cellar/go/HEAD/libexec/pkg/tool/darwin_amd64/6l: running clang failed: exit status 1
ld: illegal text-relocation to '_jpeg_resync_to_restart' in /usr/local/opt/jpeg-turbo/lib/libjpeg.dylib from 'github.com/pixiv/go-libjpeg/jpeg.init' in /var/folders/7b/6wvl7vm52bz4t29fxktsxbmw0000gn/T/go-link-976456270/go.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

~ tree /usr/local/opt/jpeg-turbo/lib/
/usr/local/opt/jpeg-turbo/lib/
├── libjpeg.8.0.2.dylib
├── libjpeg.8.dylib -> libjpeg.8.0.2.dylib
├── libjpeg.a
├── libjpeg.dylib -> libjpeg.8.0.2.dylib
├── libturbojpeg.0.1.0.dylib
├── libturbojpeg.0.dylib -> libturbojpeg.0.1.0.dylib
├── libturbojpeg.a
└── libturbojpeg.dylib -> libturbojpeg.0.1.0.dylib

test fails with libjpeg on Mac

I was trying around with this branch #15 and found out that there is a failing test using libjpeg whereas it is passing with libjpeg-turbo.

$ CGO_CFLAGS=-I/usr/local/opt/jpeg/include CGO_LDFLAGS=-L/usr/local/opt/jpeg/lib go test -a -test.v .
=== RUN   TestDecode
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecode (1.70s)
=== RUN   TestDecodeScaled
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecodeScaled (0.12s)
=== RUN   TestDecodeIntoRGBA
--- SKIP: TestDecodeIntoRGBA (0.00s)
    jpeg_test.go:109: This build is not support DecodeIntoRGBA.
=== RUN   TestDecodeScaledIntoRGBA
--- SKIP: TestDecodeScaledIntoRGBA (0.00s)
    jpeg_test.go:128: This build is not support DecodeIntoRGBA.
=== RUN   TestDecodeScaledIntoRGB
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecodeScaledIntoRGB (0.12s)
=== RUN   TestDecodeSubsampledImage
 - test: checkerboard_444.jpg
 - test: checkerboard_440.jpg
 - test: checkerboard_422.jpg
 - test: checkerboard_420.jpg
--- PASS: TestDecodeSubsampledImage (0.07s)
=== RUN   TestDecodeAndEncode
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecodeAndEncode (0.07s)
=== RUN   TestDecodeAndEncodeSubsampledImages
 - test: checkerboard_444.jpg
 - test: checkerboard_440.jpg
 - test: checkerboard_422.jpg
 - test: checkerboard_420.jpg
--- PASS: TestDecodeAndEncodeSubsampledImages (0.01s)
=== RUN   TestDecodeConfig
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecodeConfig (0.00s)
=== RUN   TestNewYCbCrAlignedWithLandscape
--- PASS: TestNewYCbCrAlignedWithLandscape (0.00s)
=== RUN   TestNewYCbCrAlignedWithPortrait
--- PASS: TestNewYCbCrAlignedWithPortrait (0.00s)
=== RUN   TestDecodeTestdataFromGoStdlib
--- FAIL: TestDecodeTestdataFromGoStdlib (0.11s)
    testdata_test.go:110: testdata/video-001.221212.jpeg: at (93, 0): got {96 11 0 255} want {34 106 166}
FAIL
exit status 1
FAIL    github.com/pixiv/go-libjpeg/jpeg    2.209s
$ CGO_CFLAGS=-I/usr/local/opt/jpeg-turbo/include CGO_LDFLAGS=-L/usr/local/opt/jpeg-turbo/lib go test -a -test.v .
=== RUN   TestDecode
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecode (1.69s)
=== RUN   TestDecodeScaled
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecodeScaled (0.11s)
=== RUN   TestDecodeIntoRGBA
--- SKIP: TestDecodeIntoRGBA (0.00s)
    jpeg_test.go:109: This build is not support DecodeIntoRGBA.
=== RUN   TestDecodeScaledIntoRGBA
--- SKIP: TestDecodeScaledIntoRGBA (0.00s)
    jpeg_test.go:128: This build is not support DecodeIntoRGBA.
=== RUN   TestDecodeScaledIntoRGB
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecodeScaledIntoRGB (0.13s)
=== RUN   TestDecodeSubsampledImage
 - test: checkerboard_444.jpg
 - test: checkerboard_440.jpg
 - test: checkerboard_422.jpg
 - test: checkerboard_420.jpg
--- PASS: TestDecodeSubsampledImage (0.06s)
=== RUN   TestDecodeAndEncode
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecodeAndEncode (0.03s)
=== RUN   TestDecodeAndEncodeSubsampledImages
 - test: checkerboard_444.jpg
 - test: checkerboard_440.jpg
 - test: checkerboard_422.jpg
 - test: checkerboard_420.jpg
--- PASS: TestDecodeAndEncodeSubsampledImages (0.01s)
=== RUN   TestDecodeConfig
 - test: cosmos.jpg
 - test: kinkaku.jpg
--- PASS: TestDecodeConfig (0.00s)
=== RUN   TestNewYCbCrAlignedWithLandscape
--- PASS: TestNewYCbCrAlignedWithLandscape (0.00s)
=== RUN   TestNewYCbCrAlignedWithPortrait
--- PASS: TestNewYCbCrAlignedWithPortrait (0.00s)
=== RUN   TestDecodeTestdataFromGoStdlib
--- PASS: TestDecodeTestdataFromGoStdlib (0.11s)
PASS
ok      github.com/pixiv/go-libjpeg/jpeg    2.149s

libjpeg version 8g and libjpeg-turbo 1.4.1 installed with homebrew.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.