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

Increase hash size for Screens.Hash() #70

Merged
merged 1 commit into from
Sep 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package encode

import (
"bytes"
"encoding/binary"
"crypto/sha256"
"encoding/json"
"fmt"
"image"
"image/color"
"image/gif"
"time"

"github.com/harukasan/go-libwebp/webp"
"github.com/mitchellh/hashstructure/v2"
"github.com/pkg/errors"
"tidbyt.dev/pixlet/render"
)
Expand Down Expand Up @@ -69,14 +69,13 @@ func (s *Screens) Hash() ([]byte, error) {
hashable.Images = s.images
}

sum, err := hashstructure.Hash(hashable, hashstructure.FormatV2, nil)
j, err := json.Marshal(hashable)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "marshaling render tree to JSON")
}

buf := make([]byte, binary.MaxVarintLen64)
n := binary.PutUvarint(buf, sum)
return buf[:n], nil
h := sha256.Sum256(j)
return h[:], nil
}

// Renders a screen to WebP. Optionally pass filters for
Expand Down