mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-06 05:25:41 -05:00
screenshot: fix thumbnail preview
This commit is contained in:
@@ -217,9 +217,13 @@ func runScreenshot(config screenshot.Config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.Notify {
|
if config.Notify {
|
||||||
|
thumbData, thumbW, thumbH := bufferToRGBThumbnail(result.Buffer, 256)
|
||||||
screenshot.SendNotification(screenshot.NotifyResult{
|
screenshot.SendNotification(screenshot.NotifyResult{
|
||||||
FilePath: filePath,
|
FilePath: filePath,
|
||||||
Clipboard: config.Clipboard,
|
Clipboard: config.Clipboard,
|
||||||
|
ImageData: thumbData,
|
||||||
|
Width: thumbW,
|
||||||
|
Height: thumbH,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,6 +263,51 @@ func writeImageToStdout(buf *screenshot.ShmBuffer, format screenshot.Format, qua
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bufferToRGBThumbnail(buf *screenshot.ShmBuffer, maxSize int) ([]byte, int, int) {
|
||||||
|
srcW, srcH := buf.Width, buf.Height
|
||||||
|
scale := 1.0
|
||||||
|
if srcW > maxSize || srcH > maxSize {
|
||||||
|
if srcW > srcH {
|
||||||
|
scale = float64(maxSize) / float64(srcW)
|
||||||
|
} else {
|
||||||
|
scale = float64(maxSize) / float64(srcH)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dstW := int(float64(srcW) * scale)
|
||||||
|
dstH := int(float64(srcH) * scale)
|
||||||
|
if dstW < 1 {
|
||||||
|
dstW = 1
|
||||||
|
}
|
||||||
|
if dstH < 1 {
|
||||||
|
dstH = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
data := buf.Data()
|
||||||
|
rgb := make([]byte, dstW*dstH*3)
|
||||||
|
|
||||||
|
for y := 0; y < dstH; y++ {
|
||||||
|
srcY := int(float64(y) / scale)
|
||||||
|
if srcY >= srcH {
|
||||||
|
srcY = srcH - 1
|
||||||
|
}
|
||||||
|
for x := 0; x < dstW; x++ {
|
||||||
|
srcX := int(float64(x) / scale)
|
||||||
|
if srcX >= srcW {
|
||||||
|
srcX = srcW - 1
|
||||||
|
}
|
||||||
|
si := srcY*buf.Stride + srcX*4
|
||||||
|
di := (y*dstW + x) * 3
|
||||||
|
if si+2 < len(data) {
|
||||||
|
rgb[di+0] = data[si+2] // R
|
||||||
|
rgb[di+1] = data[si+1] // G
|
||||||
|
rgb[di+2] = data[si+0] // B
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rgb, dstW, dstH
|
||||||
|
}
|
||||||
|
|
||||||
func runScreenshotRegion(cmd *cobra.Command, args []string) {
|
func runScreenshotRegion(cmd *cobra.Command, args []string) {
|
||||||
config := getScreenshotConfig(screenshot.ModeRegion)
|
config := getScreenshotConfig(screenshot.ModeRegion)
|
||||||
runScreenshot(config)
|
runScreenshot(config)
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ const (
|
|||||||
type NotifyResult struct {
|
type NotifyResult struct {
|
||||||
FilePath string
|
FilePath string
|
||||||
Clipboard bool
|
Clipboard bool
|
||||||
|
ImageData []byte
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendNotification(result NotifyResult) {
|
func SendNotification(result NotifyResult) {
|
||||||
@@ -36,8 +39,27 @@ func SendNotification(result NotifyResult) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hints := map[string]dbus.Variant{}
|
hints := map[string]dbus.Variant{}
|
||||||
if result.FilePath != "" && !result.Clipboard {
|
if len(result.ImageData) > 0 && result.Width > 0 && result.Height > 0 {
|
||||||
hints["image-path"] = dbus.MakeVariant(result.FilePath)
|
rowstride := result.Width * 3
|
||||||
|
hints["image_data"] = dbus.MakeVariant(struct {
|
||||||
|
Width int32
|
||||||
|
Height int32
|
||||||
|
Rowstride int32
|
||||||
|
HasAlpha bool
|
||||||
|
BitsPerSample int32
|
||||||
|
Channels int32
|
||||||
|
Data []byte
|
||||||
|
}{
|
||||||
|
Width: int32(result.Width),
|
||||||
|
Height: int32(result.Height),
|
||||||
|
Rowstride: int32(rowstride),
|
||||||
|
HasAlpha: false,
|
||||||
|
BitsPerSample: 8,
|
||||||
|
Channels: 3,
|
||||||
|
Data: result.ImageData,
|
||||||
|
})
|
||||||
|
} else if result.FilePath != "" {
|
||||||
|
hints["image_path"] = dbus.MakeVariant(result.FilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
summary := "Screenshot captured"
|
summary := "Screenshot captured"
|
||||||
|
|||||||
Reference in New Issue
Block a user