File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -139,14 +139,15 @@ func (img Image[T]) setPixel(index int, c T) {
139139 case zeroColor .BitsPerPixel () == 1 :
140140 // Monochrome.
141141 x := index % int (img .width )
142- y := index / int ( img . width )
143- offset := x + ( y / 8 ) * int ( img . width )
142+ offset := index / 8
143+
144144 ptr := (* byte )(unsafe .Add (img .data , offset ))
145145 if c != zeroColor {
146- * ((* byte )(ptr )) |= 1 << uint8 (y % 8 )
146+ * ((* byte )(ptr )) |= ( 1 << ( 7 - uint8 (x % 8 )) )
147147 } else {
148- * ((* byte )(ptr )) &^= 1 << uint8 (y % 8 )
148+ * ((* byte )(ptr )) &^= ( 1 << ( 7 - uint8 (x % 8 )) )
149149 }
150+
150151 return
151152 case zeroColor .BitsPerPixel ()% 8 == 0 :
152153 // Each color starts at a whole byte offset.
@@ -200,9 +201,10 @@ func (img Image[T]) Get(x, y int) T {
200201 case zeroColor .BitsPerPixel () == 1 :
201202 // Monochrome.
202203 var c Monochrome
203- offset := x + (y / 8 )* int (img .width )
204+ offset := index / 8
205+ bits := index - (offset * 8 )
204206 ptr := (* byte )(unsafe .Add (img .data , offset ))
205- c = (* ptr >> uint8 (y % 8 ) & 0x1 ) == 1
207+ c = (( * ptr >> ( 7 - uint8 (bits ))) & 0x1 ) > 0
206208 return any (c ).(T )
207209 case zeroColor .BitsPerPixel ()% 8 == 0 :
208210 // Colors like RGB565, RGB888, etc.
You can’t perform that action at this time.
0 commit comments