Fixed X11 BMP and other bitmap conversion. Had data alignment
problems.
This commit is contained in:
parent
4b212ad704
commit
fdf4b2604d
|
@ -31,47 +31,36 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
// BMP is little-endian
|
// BMP is little-endian
|
||||||
static inline
|
|
||||||
UInt16
|
static
|
||||||
toLE(UInt16 data)
|
void
|
||||||
|
toLE(UInt8*& dst, UInt16 src)
|
||||||
{
|
{
|
||||||
union x16 {
|
dst[0] = static_cast<UInt8>(src & 0xffu);
|
||||||
UInt8 n8[2];
|
dst[1] = static_cast<UInt8>((src >> 8) & 0xffu);
|
||||||
UInt16 n16;
|
dst += 2;
|
||||||
} c;
|
|
||||||
c.n8[0] = static_cast<UInt8>(data & 0xffu);
|
|
||||||
c.n8[1] = static_cast<UInt8>((data >> 8) & 0xffu);
|
|
||||||
return c.n16;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static
|
||||||
SInt32
|
void
|
||||||
toLE(SInt32 data)
|
toLE(UInt8*& dst, SInt32 src)
|
||||||
{
|
{
|
||||||
union x32 {
|
dst[0] = static_cast<UInt8>(src & 0xffu);
|
||||||
UInt8 n8[4];
|
dst[1] = static_cast<UInt8>((src >> 8) & 0xffu);
|
||||||
SInt32 n32;
|
dst[2] = static_cast<UInt8>((src >> 16) & 0xffu);
|
||||||
} c;
|
dst[3] = static_cast<UInt8>((src >> 24) & 0xffu);
|
||||||
c.n8[0] = static_cast<UInt8>(data & 0xffu);
|
dst += 4;
|
||||||
c.n8[1] = static_cast<UInt8>((data >> 8) & 0xffu);
|
|
||||||
c.n8[2] = static_cast<UInt8>((data >> 16) & 0xffu);
|
|
||||||
c.n8[3] = static_cast<UInt8>((data >> 24) & 0xffu);
|
|
||||||
return c.n32;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static
|
||||||
UInt32
|
void
|
||||||
toLE(UInt32 data)
|
toLE(UInt8*& dst, UInt32 src)
|
||||||
{
|
{
|
||||||
union x32 {
|
dst[0] = static_cast<UInt8>(src & 0xffu);
|
||||||
UInt8 n8[4];
|
dst[1] = static_cast<UInt8>((src >> 8) & 0xffu);
|
||||||
UInt32 n32;
|
dst[2] = static_cast<UInt8>((src >> 16) & 0xffu);
|
||||||
} c;
|
dst[3] = static_cast<UInt8>((src >> 24) & 0xffu);
|
||||||
c.n8[0] = static_cast<UInt8>(data & 0xffu);
|
dst += 4;
|
||||||
c.n8[1] = static_cast<UInt8>((data >> 8) & 0xffu);
|
|
||||||
c.n8[2] = static_cast<UInt8>((data >> 16) & 0xffu);
|
|
||||||
c.n8[3] = static_cast<UInt8>((data >> 24) & 0xffu);
|
|
||||||
return c.n32;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
|
@ -178,20 +167,21 @@ CXWindowsClipboardAnyBitmapConverter::toIClipboard(const CString& image) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill BMP info header with little-endian data
|
// fill BMP info header with little-endian data
|
||||||
CBMPInfoHeader infoHeader;
|
UInt8 infoHeader[40];
|
||||||
infoHeader.biSize = toLE(40);
|
UInt8* dst = infoHeader;
|
||||||
infoHeader.biWidth = toLE(w);
|
toLE(dst, static_cast<UInt32>(40));
|
||||||
infoHeader.biHeight = toLE(h);
|
toLE(dst, static_cast<SInt32>(w));
|
||||||
infoHeader.biPlanes = toLE(1);
|
toLE(dst, static_cast<SInt32>(h));
|
||||||
infoHeader.biBitCount = toLE(depth);
|
toLE(dst, static_cast<UInt16>(1));
|
||||||
infoHeader.biCompression = toLE(0); // BI_RGB
|
toLE(dst, static_cast<UInt16>(depth));
|
||||||
infoHeader.biSizeImage = image.size();
|
toLE(dst, static_cast<UInt32>(0)); // BI_RGB
|
||||||
infoHeader.biXPelsPerMeter = toLE(2834); // 72 dpi
|
toLE(dst, static_cast<UInt32>(image.size()));
|
||||||
infoHeader.biYPelsPerMeter = toLE(2834); // 72 dpi
|
toLE(dst, static_cast<SInt32>(2834)); // 72 dpi
|
||||||
infoHeader.biClrUsed = toLE(0);
|
toLE(dst, static_cast<SInt32>(2834)); // 72 dpi
|
||||||
infoHeader.biClrImportant = toLE(0);
|
toLE(dst, static_cast<UInt32>(0));
|
||||||
|
toLE(dst, static_cast<UInt32>(0));
|
||||||
|
|
||||||
// construct image
|
// construct image
|
||||||
return CString(reinterpret_cast<const char*>(&infoHeader),
|
return CString(reinterpret_cast<const char*>(infoHeader),
|
||||||
sizeof(infoHeader)) + rawBMP;
|
sizeof(infoHeader)) + rawBMP;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,19 +35,32 @@ fromLEU32(const UInt8* data)
|
||||||
(static_cast<UInt32>(data[3]) << 24);
|
(static_cast<UInt32>(data[3]) << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static
|
||||||
UInt32
|
void
|
||||||
toLE(UInt32 data)
|
toLE(UInt8*& dst, char src)
|
||||||
{
|
{
|
||||||
union x32 {
|
dst[0] = static_cast<UInt8>(src);
|
||||||
UInt8 n8[4];
|
dst += 1;
|
||||||
UInt32 n32;
|
}
|
||||||
} c;
|
|
||||||
c.n8[0] = static_cast<UInt8>(data & 0xffu);
|
static
|
||||||
c.n8[1] = static_cast<UInt8>((data >> 8) & 0xffu);
|
void
|
||||||
c.n8[2] = static_cast<UInt8>((data >> 16) & 0xffu);
|
toLE(UInt8*& dst, UInt16 src)
|
||||||
c.n8[3] = static_cast<UInt8>((data >> 24) & 0xffu);
|
{
|
||||||
return c.n32;
|
dst[0] = static_cast<UInt8>(src & 0xffu);
|
||||||
|
dst[1] = static_cast<UInt8>((src >> 8) & 0xffu);
|
||||||
|
dst += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void
|
||||||
|
toLE(UInt8*& dst, UInt32 src)
|
||||||
|
{
|
||||||
|
dst[0] = static_cast<UInt8>(src & 0xffu);
|
||||||
|
dst[1] = static_cast<UInt8>((src >> 8) & 0xffu);
|
||||||
|
dst[2] = static_cast<UInt8>((src >> 16) & 0xffu);
|
||||||
|
dst[3] = static_cast<UInt8>((src >> 24) & 0xffu);
|
||||||
|
dst += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -88,15 +101,15 @@ CString
|
||||||
CXWindowsClipboardBMPConverter::fromIClipboard(const CString& bmp) const
|
CXWindowsClipboardBMPConverter::fromIClipboard(const CString& bmp) const
|
||||||
{
|
{
|
||||||
// create BMP image
|
// create BMP image
|
||||||
CBMPHeader header;
|
UInt8 header[14];
|
||||||
char* type = reinterpret_cast<char*>(&header.type);
|
UInt8* dst = header;
|
||||||
type[0] = 'B';
|
toLE(dst, 'B');
|
||||||
type[1] = 'M';
|
toLE(dst, 'M');
|
||||||
header.size = toLE(14 + bmp.size());
|
toLE(dst, 14 + bmp.size());
|
||||||
header.reserved1 = 0;
|
toLE(dst, static_cast<UInt16>(0));
|
||||||
header.reserved2 = 0;
|
toLE(dst, static_cast<UInt16>(0));
|
||||||
header.offset = toLE(14 + 40);
|
toLE(dst, static_cast<UInt32>(14 + 40));
|
||||||
return CString(reinterpret_cast<const char*>(&header), 14) + bmp;
|
return CString(reinterpret_cast<const char*>(header), 14) + bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
CString
|
CString
|
||||||
|
|
Loading…
Reference in New Issue