|
@@ -4,6 +4,9 @@ import (
|
|
|
"encoding/binary"
|
|
"encoding/binary"
|
|
|
"flag"
|
|
"flag"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "image"
|
|
|
|
|
+ "image/color"
|
|
|
|
|
+ "image/png"
|
|
|
"log"
|
|
"log"
|
|
|
"net"
|
|
"net"
|
|
|
"os"
|
|
"os"
|
|
@@ -40,6 +43,8 @@ func main() {
|
|
|
|
|
|
|
|
rawImage := RemoveHeaders(bytes)
|
|
rawImage := RemoveHeaders(bytes)
|
|
|
|
|
|
|
|
|
|
+ SaveImage(rawImage, width, heigth, *name, *color)
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func SendRequest(socket net.Conn, resolution int, _mode string, adf bool) (int, int) {
|
|
func SendRequest(socket net.Conn, resolution int, _mode string, adf bool) (int, int) {
|
|
@@ -116,6 +121,38 @@ readPackets:
|
|
|
return scanBytes
|
|
return scanBytes
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func SaveImage(data []byte, width int, height int, name string, color string) {
|
|
|
|
|
+
|
|
|
|
|
+ log.Println("Saving image...")
|
|
|
|
|
+
|
|
|
|
|
+ _, compression := GetCompressionMode(color)
|
|
|
|
|
+
|
|
|
|
|
+ if compression != "JPEG" {
|
|
|
|
|
+
|
|
|
|
|
+ img := image.NewGray(image.Rectangle{
|
|
|
|
|
+ image.Point{0, 0},
|
|
|
|
|
+ image.Point{width, height},
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ for y := 0; y < height-40; y++ {
|
|
|
|
|
+
|
|
|
|
|
+ for x := 0; x < width; x++ {
|
|
|
|
|
+ img.SetGray(x, y, colorToGray(data[y*width+x]))
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ file, _ := os.Create(name)
|
|
|
|
|
+ png.Encode(file, img)
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ os.WriteFile(name, data, 0644)
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func colorToGray(byte byte) color.Gray {
|
|
|
|
|
+ return color.Gray{Y: byte}
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func HandleError(err error) {
|
|
func HandleError(err error) {
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|