26 lines
1.1 KiB
C++
26 lines
1.1 KiB
C++
#pragma once
|
|
#include "ocr.h"
|
|
#include <algorithm>
|
|
namespace ks::lan
|
|
{
|
|
// Send one lossless image, not PNG plus multiple uncompressed DIB copies.
|
|
inline Clip compactClipboardImage(Clip clip)
|
|
{
|
|
auto png=std::find_if(clip.formats.begin(),clip.formats.end(),[](const Format &f){return f.name==L"PNG";});
|
|
bool image=png!=clip.formats.end()||std::any_of(clip.formats.begin(),clip.formats.end(),[](const Format &f){return f.id==CF_DIB||f.id==CF_DIBV5;});
|
|
if(!image)return clip;
|
|
Bytes bytes=png!=clip.formats.end()?png->data:encodePng(decodeImage(clip));
|
|
std::erase_if(clip.formats,[](const Format &f){return f.id==CF_DIB||f.id==CF_DIBV5||f.name==L"PNG";});
|
|
clip.formats.push_back({RegisterClipboardFormatW(L"PNG"),L"PNG",std::move(bytes)});
|
|
return clip;
|
|
}
|
|
// Older applications paste DIB rather than PNG; expand only at the destination.
|
|
inline Clip clipboardImageForPaste(Clip clip)
|
|
{
|
|
bool dib=false,png=false;
|
|
for(const auto &f:clip.formats){dib|=f.id==CF_DIB||f.id==CF_DIBV5;png|=f.name==L"PNG";}
|
|
if(png&&!dib)clip.formats.push_back(imageDib(decodeImage(clip)));
|
|
return clip;
|
|
}
|
|
}
|