Skip to content

Instantly share code, notes, and snippets.

@oldpatricka
Created November 2, 2018 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oldpatricka/0e3ca6f1f6de2839366e7217dfaa9023 to your computer and use it in GitHub Desktop.
Save oldpatricka/0e3ca6f1f6de2839366e7217dfaa9023 to your computer and use it in GitHub Desktop.
Simple program to undiff TIFF horizontally diffed files
package main
// Run like `cat my.dif | go run tiff-hdiff.go`
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
height := 512
width := 512
var lastVal uint32
var currentVal uint32
b := make([]byte, 0, height*width)
for row := 0; row < height; row++ {
for col := 0; col < width; col++ {
currentByte, err := reader.ReadByte()
if err != nil {
panic(err)
}
if col == 0 {
currentVal = uint32(currentByte)
} else {
currentVal = lastVal - uint32(currentByte)
}
b = append(b, byte(currentVal))
lastVal = currentVal
}
}
// Write decompressed Bytes to stdout
w := bufio.NewWriter(os.Stdout)
n, err := w.Write(b)
if err != nil {
panic(err)
}
w.Flush()
// Print summary
fmt.Fprintf(os.Stderr, "%d bytes dediffed\n", n)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment