Skip to content

Commit 4394fe0

Browse files
committed
Fixing shuffled image
1 parent e0c01b1 commit 4394fe0

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

chipper/pkg/wirepod/sdkapp/server.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"image"
99
"image/jpeg"
10+
"image/png"
1011
"io"
1112
"net/http"
1213
"os"
@@ -154,36 +155,38 @@ func SdkapiHandler(w http.ResponseWriter, r *http.Request) {
154155
}
155156
//resizedImg := resizeImage(img, 184, 96)
156157

157-
bounds := img.Bounds()
158+
// bounds := img.Bounds()
158159

159-
rgbValues := make([][][3]uint8, bounds.Dy()) // height
160+
// rgbValues := make([][][3]uint8, bounds.Dy()) // height
160161

161-
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
162-
rgbRow := make([][3]uint8, bounds.Dx()) // width
162+
// for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
163+
// rgbRow := make([][3]uint8, bounds.Dx()) // width
163164

164-
for x := bounds.Min.X; x < bounds.Max.X; x++ {
165-
//get current pixel color
166-
f := img.At(x, y)
165+
// for x := bounds.Min.X; x < bounds.Max.X; x++ {
166+
// //get current pixel color
167+
// f := img.At(x, y)
167168

168-
r, g, b, _ := f.RGBA()
169-
r8 := uint8(r >> 8)
170-
g8 := uint8(g >> 8)
171-
b8 := uint8(b >> 8)
169+
// r, g, b, _ := f.RGBA()
170+
// r8 := uint8(r >> 8)
171+
// g8 := uint8(g >> 8)
172+
// b8 := uint8(b >> 8)
172173

173-
//store RGB values
174-
rgbRow[x] = [3]uint8{r8, g8, b8}
175-
}
174+
// //store RGB values
175+
// rgbRow[x] = [3]uint8{r8, g8, b8}
176+
// }
176177

177-
rgbValues[y] = rgbRow
178-
}
178+
// rgbValues[y] = rgbRow
179+
// }
179180

180181
// Reads the image and handles possible errors
181-
faceBytes, err := imageToBytes(img)
182+
var buf bytes.Buffer
183+
err = png.Encode(&buf, img)
182184
if err != nil {
183185
http.Error(w, "Error reading image: "+err.Error(), http.StatusInternalServerError)
184186
return
185187
}
186188

189+
faceBytes := buf.Bytes()
187190
ctx := r.Context()
188191
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
189192
defer cancel()

0 commit comments

Comments
 (0)