More or less rewrote cursor conversion code: it's now working as expected.

Note, this code needs to be reviewed for PPC; do they really work with little endian RGBA?


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16960 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-04-01 18:36:50 +00:00
parent 92eab70620
commit 61212865dc
+26 -28
View File
@@ -15,12 +15,14 @@
expands the R5 API. expands the R5 API.
*/ */
#include "CursorManager.h"
#include "ServerCursor.h" #include "ServerCursor.h"
#include <ByteOrder.h>
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
#include "CursorManager.h"
using std::nothrow; using std::nothrow;
@@ -67,7 +69,9 @@ ServerCursor::ServerCursor(const uint8* data)
// This API has serious problems and should be deprecated(but supported) in R2 // This API has serious problems and should be deprecated(but supported) in R2
// Now that we have all the setup, we're going to map (for now) the cursor // Now that we have all the setup, we're going to map (for now) the cursor
// to RGBA32. Eventually, there will be support for 16 and 8-bit depths // to RGBA32 (little endian). Eventually, there will be support for 16 and
// 8-bit depths
// NOTE: review this once we have working PPC graphics cards (big endian).
if (data) { if (data) {
_AllocateBuffer(); _AllocateBuffer();
uint8* buffer = Bits(); uint8* buffer = Bits();
@@ -75,39 +79,33 @@ ServerCursor::ServerCursor(const uint8* data)
return; return;
fInitialized = true; fInitialized = true;
uint32 black = 0xFF000000; uint32 black = 0xff000000;
uint32 white = 0xFFFFFFFF; uint32 white = 0xffffffff;
uint16* cursorpos = (uint16*)(data + 4); uint16* cursorBits = (uint16*)(data + 4);
uint16* maskpos = (uint16*)(data + 36); uint16* transparencyBits = (uint16*)(data + 36);
fHotSpot.Set(data[3], data[2]); fHotSpot.Set(data[3], data[2]);
uint32* bmppos;
uint16 cursorflip;
uint16 maskflip;
uint16 cursorval;
uint16 maskval;
uint16 powval;
// for each row in the cursor data // for each row in the cursor data
for (int32 j = 0; j < 16; j++) { for (int32 j = 0; j < 16; j++) {
bmppos = (uint32*)(buffer + (j * BytesPerRow())); uint32* bits = (uint32*)(buffer + (j * BytesPerRow()));
// On intel, our bytes end up swapped, so we must swap them back // On intel, our bytes end up swapped, so we must swap them back
cursorflip = (cursorpos[j] & 0xFF) << 8; uint16 cursorLine = __swap_int16(cursorBits[j]);
cursorflip |= (cursorpos[j] & 0xFF00) >> 8; uint16 transparencyLine = __swap_int16(transparencyBits[j]);
maskflip = (maskpos[j] & 0xFF) << 8; uint16 mask = 1 << 15;
maskflip |= (maskpos[j] & 0xFF00) >> 8;
// for each column in each row of cursor data // for each column in each row of cursor data
for (int32 i = 0; i < 16; i++) { for (int32 i = 0; i < 16; i++, mask >>= 1) {
// Get the values and dump them to the bitmap // Get the values and dump them to the bitmap
powval = 1 << (15 - i); uint16 cursorBit = cursorLine & mask;
cursorval = cursorflip & powval; if (cursorBit)
maskval = maskflip & powval; bits[i] = black;
bmppos[i] = maskval > 0 ? (cursorval != 0 ? black : white) else if (transparencyLine & mask)
: 0x00000000; bits[i] = white;
else
bits[i] = 0x00000000;
} }
} }