Giter Site home page Giter Site logo

sg3des / go-libjpeg Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hjyoun0731/go-libjpeg

0.0 0.0 0.0 2.82 MB

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

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

Go 97.88% C 1.67% Shell 0.44%

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

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

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.