@@ -713,44 +713,44 @@ func unfavoriteStencilDevnet(w http.ResponseWriter, r *http.Request) {
713
713
}
714
714
715
715
func worldImageToPixelData (imageData []byte , scaleFactor int , worldId int ) ([]int , error ) {
716
- img , _ , err := image .Decode (bytes .NewReader (imageData ))
717
- if err != nil {
718
- return nil , err
719
- }
720
-
721
- colors , err := core .PostgresQuery [ColorType ]("SELECT hex FROM WorldsColors WHERE world_id = $1 ORDER BY color_key" , worldId )
722
- if err != nil {
723
- return nil , err
724
- }
725
-
726
- colorCount := len (colors )
727
- palette := make ([]color.Color , colorCount )
728
- for i := 0 ; i < colorCount ; i ++ {
729
- colorHex := colors [i ]
730
- palette [i ] = hexToRGBA (colorHex )
731
- }
732
-
733
- bounds := img .Bounds ()
734
- width , height := bounds .Max .X , bounds .Max .Y
735
- scaledWidth := width / scaleFactor
736
- scaledHeight := height / scaleFactor
737
- pixelData := make ([]int , scaledWidth * scaledHeight )
738
-
739
- for y := 0 ; y < height ; y += scaleFactor {
740
- for x := 0 ; x < width ; x += scaleFactor {
741
- newX := x / scaleFactor
742
- newY := y / scaleFactor
743
- rgba := color .RGBAModel .Convert (img .At (x , y )).(color.RGBA )
744
- if rgba .A < 128 { // Consider pixels with less than 50% opacity as transparent
745
- pixelData [newY * scaledWidth + newX ] = 0xFF
746
- } else {
747
- closestIndex := findClosestColor (rgba , palette )
748
- pixelData [newY * scaledWidth + newX ] = closestIndex
749
- }
750
- }
751
- }
752
-
753
- return pixelData , nil
716
+ img , _ , err := image .Decode (bytes .NewReader (imageData ))
717
+ if err != nil {
718
+ return nil , err
719
+ }
720
+
721
+ colors , err := core .PostgresQuery [ColorType ]("SELECT hex FROM WorldsColors WHERE world_id = $1 ORDER BY color_key" , worldId )
722
+ if err != nil {
723
+ return nil , err
724
+ }
725
+
726
+ colorCount := len (colors )
727
+ palette := make ([]color.Color , colorCount )
728
+ for i := 0 ; i < colorCount ; i ++ {
729
+ colorHex := colors [i ]
730
+ palette [i ] = hexToRGBA (colorHex )
731
+ }
732
+
733
+ bounds := img .Bounds ()
734
+ width , height := bounds .Max .X , bounds .Max .Y
735
+ scaledWidth := width / scaleFactor
736
+ scaledHeight := height / scaleFactor
737
+ pixelData := make ([]int , scaledWidth * scaledHeight )
738
+
739
+ for y := 0 ; y < height ; y += scaleFactor {
740
+ for x := 0 ; x < width ; x += scaleFactor {
741
+ newX := x / scaleFactor
742
+ newY := y / scaleFactor
743
+ rgba := color .RGBAModel .Convert (img .At (x , y )).(color.RGBA )
744
+ if rgba .A < 128 { // Consider pixels with less than 50% opacity as transparent
745
+ pixelData [newY * scaledWidth + newX ] = 0xFF
746
+ } else {
747
+ closestIndex := findClosestColor (rgba , palette )
748
+ pixelData [newY * scaledWidth + newX ] = closestIndex
749
+ }
750
+ }
751
+ }
752
+
753
+ return pixelData , nil
754
754
}
755
755
756
756
func getStencilPixelData (w http.ResponseWriter , r * http.Request ) {
0 commit comments