1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| // for windows only
struct ImageClipboard
{
int a; // ???
int wid, hei; // Size
short b; // ???
short bpp; // Bits per pixels
// ??? ...
};
void convert(const void * data, int size, QImage & ret)
{
using namespace std;
const ImageClipboard * header = (ImageClipboard*) data;
qDebug() << header->wid << header->hei << header->bpp;
if(header->bpp == 32)
{
unsigned int * p = (unsigned int*)((char*)data + 52);
ret = QImage(header->wid, header->hei, QImage::Format_ARGB32);
for(int j=ret.height()-1; j>=0; --j)
for(int i=0; i<ret.width(); ++i)
{
ret.setPixel(i, j, *p++);
}
}
else if(header->bpp == 24)
{
unsigned char * p = (unsigned char*)data + 40;
ret = QImage(header->wid, header->hei, QImage::Format_ARGB32);
for(int j=ret.height()-1; j>=0; --j)
for(int i=0; i<ret.width(); ++i)
{
ret.setPixel(i, j, *p|*(p+1)<<8|*(p+2)<<16|0xFF000000);
p += 3;
}
}
else if(header->bpp == 8)
{
/// @todo palette mode indexé
unsigned char * p = (unsigned char*)data + 1064;
ret = QImage(header->wid, header->hei, QImage::Format_ARGB32);
for(int j=0; j<ret.height(); ++j)
for(int i=0; i<ret.width(); ++i)
{
ret.setPixel(i, j, *p | *p<<8 | *p<<16 | 0xFF000000);
p++;
}
}
}
void getImageFromClipboard(QPixmap & ret)
{
OpenClipboard(NULL);
UINT uFormat;
uFormat = EnumClipboardFormats(0);
while( uFormat )
{
char szFormatName[80];
GetClipboardFormatName(uFormat, (WCHAR*)szFormatName, sizeof(szFormatName));
HANDLE data = GetClipboardData(uFormat);
if(uFormat == 8)
{
FILE * f = fopen("dump/8", "wb");
fwrite(data, GlobalSize(data), 1, f);
fclose(f);
QImage im;
convert(data, GlobalSize(data), im);
ret = QPixmap::fromImage(im);
break;
}
uFormat = EnumClipboardFormats(uFormat);
}
CloseClipboard();
} |
Partager