Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
YanxinTang committed Sep 14, 2021
2 parents 7808aaf + 5569bc9 commit d286664
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ clipboard-online is an application to share cilpboard text between Windows and i
1. Run `clipboard-online` on your windows
2. Setup shortcuts on you iPhone/iPad (Open link from safari)
- Copy:
- iCloud: [https://www.icloud.com/shortcuts/547be9cbed034192ba7b8241c88ed1e5](https://www.icloud.com/shortcuts/547be9cbed034192ba7b8241c88ed1e5)
- iCloud: [https://www.icloud.com/shortcuts/a10cc2d0f1f94249b36489db102c367d](https://www.icloud.com/shortcuts/a10cc2d0f1f94249b36489db102c367d)
- ![Copy](./images/copy.png)
- Paste:
- iCloud: [https://www.icloud.com/shortcuts/a0e3553e18ac4acf9aa4562ae79aa8f7](https://www.icloud.com/shortcuts/a0e3553e18ac4acf9aa4562ae79aa8f7)
- iCloud: [https://www.icloud.com/shortcuts/45494dc6ff424ffba787b6526840c255](https://www.icloud.com/shortcuts/45494dc6ff424ffba787b6526840c255)
- ![Paste](./images/paste.png)
3. Set ip address and authkey (default is empty string)
4. Have fun...😊
Expand Down
6 changes: 3 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ clipboard-online 是一款可以帮你在 💻Windows 和 📱iOS 之间分享
2. iPhone 或 iPad 上安装快捷指令 (在 safari 中打开链接)
- Copy:
- iCloud: [https://www.icloud.com/shortcuts/1c8af082434f4d16bdbe05d09783c82d](https://www.icloud.com/shortcuts/1c8af082434f4d16bdbe05d09783c82d)
- ![复制](https://raw.githubusercontent.com/YanxinTang/clipboard-online/master/images/copy.png)
- ![复制](./images/copy.png)
- Paste:
- iCloud: [https://www.icloud.com/shortcuts/2f05ddeec40a40918357a9d40c6f5aad](https://www.icloud.com/shortcuts/2f05ddeec40a40918357a9d40c6f5aad)
- ![粘贴](https://raw.githubusercontent.com/YanxinTang/clipboard-online/master/images/paste.png)
- iCloud: [https://www.icloud.com/shortcuts/45494dc6ff424ffba787b6526840c255](https://www.icloud.com/shortcuts/45494dc6ff424ffba787b6526840c255)
- ![粘贴](./images/paste.png)

3. 设置 ip 地址和 authkey (默认是空字符串)
4. 玩的开心...😊
Expand Down
Binary file modified images/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/paste.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func getHandler(c *gin.Context) {
bmpImage, err := bmp.Decode(bmpBytesReader)
if err != nil {
logger.WithError(err).Warn("failed to decode bmp")
c.JSON(http.StatusBadRequest, gin.H{"error": "无法获取剪切板内容"})
return
}
pngBytesBuffer := new(bytes.Buffer)
if err = png.Encode(pngBytesBuffer, bmpImage); err != nil {
Expand All @@ -184,6 +186,7 @@ func getHandler(c *gin.Context) {

if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "无法获取剪切板内容"})
return
}

responseFiles := make([]ResponseFile, 0, 1)
Expand Down
33 changes: 30 additions & 3 deletions utils/clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ func (c *ClipboardService) Text() (text string, err error) {
return
}

func int32Abs(val int32) uint32 {
if val < 0 {
return uint32(-val)
}
return uint32(val)
}

func (c *ClipboardService) Bitmap() (bmpBytes []byte, err error) {
err = c.withOpenClipboard(func() error {
hMem := win.HGLOBAL(win.GetClipboardData(win.CF_DIBV5))
Expand All @@ -120,14 +127,34 @@ func (c *ClipboardService) Bitmap() (bmpBytes []byte, err error) {
defer win.GlobalUnlock(hMem)

header := (*win.BITMAPV5HEADER)(unsafe.Pointer(p))
var biSizeImage uint32
// BiSizeImage is 0 when use tencent TIM
if header.BiBitCount == 32 {
biSizeImage = 4 * int32Abs(header.BiWidth) * int32Abs(header.BiHeight)
} else {
biSizeImage = header.BiSizeImage
}

var data []byte
sh := (*reflect.SliceHeader)(unsafe.Pointer(&data))
sh.Data = uintptr(p)
sh.Cap = int(header.BiSize + header.BiSizeImage)
sh.Len = int(header.BiSize + header.BiSizeImage)
sh.Cap = int(header.BiSize + biSizeImage)
sh.Len = int(header.BiSize + biSizeImage)

// In this place, we omit AlphaMask to make sure the BiV5Header can be decoded by image/bmp
// https://github.com/golang/image/blob/35266b937fa69456d24ed72a04d75eb6857f7d52/bmp/reader.go#L177
if header.BiCompression == 3 && header.BV4RedMask == 0xff0000 && header.BV4GreenMask == 0xff00 && header.BV4BlueMask == 0xff {
header.BiCompression = win.BI_RGB

// always set alpha channel value as 0xFF to make image untransparent
// to fix screenshot from PicPick is transparent when converted to png
pixelStartAt := header.BiSize
for i := pixelStartAt + 3; i < uint32(len(data)); i += 4 {
data[i] = 0xff
}
}

bmpFileSize := 14 + header.BiSize + header.BiSizeImage
bmpFileSize := 14 + header.BiSize + biSizeImage
bmpBytes = make([]byte, bmpFileSize)

binary.LittleEndian.PutUint16(bmpBytes[0:], 0x4d42) // start with 'BM'
Expand Down

0 comments on commit d286664

Please sign in to comment.