Created
November 2, 2018 20:46
-
-
Save oldpatricka/0e3ca6f1f6de2839366e7217dfaa9023 to your computer and use it in GitHub Desktop.
Simple program to undiff TIFF horizontally diffed files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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