diff options
author | Alexander Neumann <alexander.neumann@picos-software.com> | 2020-09-03 10:32:00 +0200 |
---|---|---|
committer | Alexander Neumann <alexander.neumann@picos-software.com> | 2020-09-03 10:32:00 +0200 |
commit | 5ebea424928b3a09e29868db27755b0afc5d9228 (patch) | |
tree | 850d34827110d86b23c87ac0ab039a8582a71e9d | |
parent | ComboBox/ListBox: Keep current selection on model reset if possible (diff) | |
download | wireguard-windows-5ebea424928b3a09e29868db27755b0afc5d9228.tar.xz wireguard-windows-5ebea424928b3a09e29868db27755b0afc5d9228.zip |
Bitmap: Reduce fake array size for 32 bit
-rw-r--r-- | bitmap.go | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -296,7 +296,7 @@ func (bmp *Bitmap) ToImage() (*image.RGBA, error) { func (bmp *Bitmap) hasTransparency() (bool, error) { if bmp.transparencyStatus == transparencyUnknown { - if err := bmp.withPixels(func(bi *win.BITMAPINFO, hdc win.HDC, pixels *[2 << 30]dibPixel, pixelsLen int) error { + if err := bmp.withPixels(func(bi *win.BITMAPINFO, hdc win.HDC, pixels *[maxPixels]bgraPixel, pixelsLen int) error { for i := 0; i < pixelsLen; i++ { if pixels[i].A == 0x00 { bmp.transparencyStatus = transparencyTransparent @@ -318,7 +318,7 @@ func (bmp *Bitmap) hasTransparency() (bool, error) { } func (bmp *Bitmap) postProcess() error { - return bmp.withPixels(func(bi *win.BITMAPINFO, hdc win.HDC, pixels *[2 << 30]dibPixel, pixelsLen int) error { + return bmp.withPixels(func(bi *win.BITMAPINFO, hdc win.HDC, pixels *[maxPixels]bgraPixel, pixelsLen int) error { for i := 0; i < pixelsLen; i++ { switch pixels[i].A { case 0x00: @@ -340,14 +340,16 @@ func (bmp *Bitmap) postProcess() error { }) } -type dibPixel struct { +type bgraPixel struct { B byte G byte R byte A byte } -func (bmp *Bitmap) withPixels(f func(bi *win.BITMAPINFO, hdc win.HDC, pixels *[2 << 30]dibPixel, pixelsLen int) error) error { +const maxPixels = 2 << 27 + +func (bmp *Bitmap) withPixels(f func(bi *win.BITMAPINFO, hdc win.HDC, pixels *[maxPixels]bgraPixel, pixelsLen int) error) error { var bi win.BITMAPINFO bi.BmiHeader.BiSize = uint32(unsafe.Sizeof(bi.BmiHeader)) @@ -363,7 +365,7 @@ func (bmp *Bitmap) withPixels(f func(bi *win.BITMAPINFO, hdc win.HDC, pixels *[2 hPixels := win.GlobalAlloc(win.GHND, uintptr(bi.BmiHeader.BiSizeImage)) defer win.GlobalFree(hPixels) - pixels := (*[2 << 30]dibPixel)(win.GlobalLock(hPixels)) + pixels := (*[maxPixels]bgraPixel)(win.GlobalLock(hPixels)) defer win.GlobalUnlock(hPixels) bi.BmiHeader.BiCompression = win.BI_RGB |