Giter Site home page Giter Site logo

goheif's Introduction

Build Status Coverage Status Go Report Card

GoHeif - A go gettable decoder/converter for HEIC based on libde265

Intel and ARM supported

Install

go get github.com/tagatac/goheif

  • Code Sample
func main() {
	flag.Parse()
	...
  
	fin, fout := flag.Arg(0), flag.Arg(1)
	fi, err := os.Open(fin)
	if err != nil {
		log.Fatal(err)
	}
	defer fi.Close()

	exif, err := goheif.ExtractExif(fi)
	if err != nil {
		log.Printf("Warning: no EXIF from %s: %v\n", fin, err)
	}

	img, err := goheif.Decode(fi)
	if err != nil {
		log.Fatalf("Failed to parse %s: %v\n", fin, err)
	}

	fo, err := os.OpenFile(fout, os.O_RDWR|os.O_CREATE, 0644)
	if err != nil {
		log.Fatalf("Failed to create output file %s: %v\n", fout, err)
	}
	defer fo.Close()

	w, _ := newWriterExif(fo, exif)
	err = jpeg.Encode(w, img, nil)
	if err != nil {
		log.Fatalf("Failed to encode %s: %v\n", fout, err)
	}

	log.Printf("Convert %s to %s successfully\n", fin, fout)
}

What is done

  • Changes make to @bradfitz's (https://github.com/bradfitz) golang heif parser

    • Some minor bugfixes
    • A few new box parsers, noteably 'iref' and 'hvcC'
  • Include libde265's source code (SSE by default enabled) and a simple golang binding

  • A Utility heic2jpg to illustrate the usage.

License

  • heif and libde265 are in their own licenses

  • goheif.go, libde265 golang binding and the heic2jpg utility are in MIT license

Credits

TODO

  • Upstream the changes to heif?

goheif's People

Contributors

adrium avatar eleniums avatar jdeng avatar mikegleasonjr avatar raducrisan1 avatar tagatac avatar

Watchers

 avatar

goheif's Issues

Use submodules for copied code

I actually spent some time on this, and the rabbit hole goes deeper than you would expect. Here's what I've gleaned:

  • The libde265 repo uses CMake to generate intermediate files based on the target platform.
  • The goheif repo has made enough of these changes directly to the source to allow the build to pass.
  • A SWIG wrapper may be the way to go for automated integration of a CMake-based C++ library into a Go library, but SWIG usage is not simple.

Here are the differences between https://github.com/strukturag/libde265/tree/v1.0.8/libde265 and https://github.com/adrium/goheif/tree/master/libde265/libde265:

diff --git a/libde265/cabac.cc b/libde265/cabac.cc
index 102bc57e..6ea5b5ba 100644
--- a/libde265/cabac.cc
+++ b/libde265/cabac.cc
@@ -416,8 +416,6 @@ int  decode_CABAC_TR_bypass(CABAC_decoder* decoder, int cRiceParam, int cTRMax)
 }


-#define MAX_PREFIX 32
-
 int  decode_CABAC_EGk_bypass(CABAC_decoder* decoder, int k)
 {
   int base=0;
@@ -433,7 +431,7 @@ int  decode_CABAC_EGk_bypass(CABAC_decoder* decoder, int k)
         n++;
       }

-      if (n == k+MAX_PREFIX) {
+      if (n == k+32) {
         return 0; // TODO: error
       }
     }
diff --git a/libde265/fallback-motion.cc b/libde265/fallback-motion.cc
index 1ac41da4..3a386e23 100644
--- a/libde265/fallback-motion.cc
+++ b/libde265/fallback-motion.cc
@@ -475,8 +475,8 @@ void put_qpel_0_0_fallback_16(int16_t *out, ptrdiff_t out_stride,



-static int extra_before[4] = { 0,3,3,2 };
-static int extra_after [4] = { 0,3,4,4 };
+static int fallback_extra_before[4] = { 0,3,3,2 };
+static int fallback_extra_after [4] = { 0,3,4,4 };

 template <class pixel_t>
 void put_qpel_fallback(int16_t *out, ptrdiff_t out_stride,
@@ -484,10 +484,10 @@ void put_qpel_fallback(int16_t *out, ptrdiff_t out_stride,
                        int nPbW, int nPbH, int16_t* mcbuffer,
                        int xFracL, int yFracL, int bit_depth)
 {
-  int extra_left   = extra_before[xFracL];
-  //int extra_right  = extra_after [xFracL];
-  int extra_top    = extra_before[yFracL];
-  int extra_bottom = extra_after [yFracL];
+  int extra_left   = fallback_extra_before[xFracL];
+  //int extra_right  = fallback_extra_after [xFracL];
+  int extra_top    = fallback_extra_before[yFracL];
+  int extra_bottom = fallback_extra_after [yFracL];

   //int nPbW_extra = extra_left + nPbW + extra_right;
   int nPbH_extra = extra_top  + nPbH + extra_bottom;
diff --git a/libde265/slice.cc b/libde265/slice.cc
index e85ecc61..5e8a6f8e 100644
--- a/libde265/slice.cc
+++ b/libde265/slice.cc
@@ -2444,8 +2444,6 @@ static int decode_coeff_abs_level_greater2(thread_context* tctx,
 }


-#define MAX_PREFIX 64
-
 static int decode_coeff_abs_level_remaining(thread_context* tctx,
                                             int cRiceParam)
 {
@@ -2457,7 +2455,7 @@ static int decode_coeff_abs_level_remaining(thread_context* tctx,
     prefix++;
     codeword = decode_CABAC_bypass(&tctx->cabac_decoder);

-    if (prefix>MAX_PREFIX) {
+    if (prefix>64) {
       return 0; // TODO: error
     }
   }

Originally posted by @tagatac in jdeng#21 (comment)

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.