GithubHelp home page GithubHelp logo

Comments (2)

mdouchement avatar mdouchement commented on August 15, 2024 1

Hello, I think it's because rgbe.Decode uses a bufio.NewReader with a buffer of 4096 bytes. The next image has been partially read during the decoding of the first image.
Decoder assumes that only one image is read.

Alternatively, you can use a bytes.Reader that is seekable:

package main

import (
	"bytes"
	"image"
	"io"
	"os"

	"github.com/mdouchement/hdr"
	"github.com/mdouchement/hdr/codec/rgbe"
)

func main() {
	f, err := os.Open("memorial_o876.hdr")
	check(err)
	defer f.Close()

	m, _, err := image.Decode(f)
	check(err)

	img := m.(hdr.Image)

	var buf bytes.Buffer
	err = rgbe.Encode(&buf, img)
	check(err)

	n := buf.Len()

	err = rgbe.Encode(&buf, img)
	check(err)

	r := bytes.NewReader(buf.Bytes())

	_, err = rgbe.Decode(r)
	check(err)

	_, err = r.Seek(int64(n), io.SeekStart) // Set the start of the second image
	check(err)

	_, err = rgbe.Decode(r)
	check(err)
}

func check(err error) {
	if err != nil {
		panic(err)
	}
}

from hdr.

NicolasBuecher avatar NicolasBuecher commented on August 15, 2024

Oh god, I didn't expect a response so fast and so complete.
So this a feature, not a bug! 😄

That was how I intended to go through the issue, but I couldn't sleep without understanding why I had to do that.

Thank you very much for your time!

from hdr.

Related Issues (13)

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.