Do not use those silly inline functions

master
Yevgen Muntyan 2007-03-20 16:44:34 -05:00
parent b97723fcf0
commit ae8aa9e074
1 changed files with 8 additions and 48 deletions

View File

@ -29,65 +29,25 @@ typedef enum {
} HelperCmdCode;
typedef union {
char chars[4];
unsigned num;
} CharsToUInt;
inline static char UINT_TO_CHAR_FIRST (unsigned a)
inline static unsigned
CHARS_TO_UINT (guchar first, guchar second)
{
CharsToUInt c;
c.num = a;
return c.chars[1];
}
inline static char UINT_TO_CHAR_SECOND (unsigned a)
{
CharsToUInt c;
c.num = a;
return c.chars[0];
}
inline static void UINT_TO_CHARS (unsigned a, char *v)
{
CharsToUInt c;
c.num = a;
v[0] = c.chars[1];
v[1] = c.chars[0];
}
inline static unsigned CHARS_TO_UINT (char first, char second)
{
CharsToUInt c;
c.chars[2] = c.chars[3] = 0;
c.chars[0] = second;
c.chars[1] = first;
return c.num;
}
inline static unsigned CHARS_TO_UINT_S (char *v)
{
CharsToUInt c;
c.chars[2] = c.chars[3] = 0;
c.chars[0] = v[1];
c.chars[1] = v[0];
return c.num;
return ((unsigned) second << 2) + first;
}
#define SIZE_CMD_LEN 6
inline static const char *set_size_cmd (unsigned width, unsigned height)
inline static const char *set_size_cmd (guint16 width, guint16 height)
{
static char cmd[SIZE_CMD_LEN] = {
HELPER_CMD_CHAR,
HELPER_SET_SIZE,
0, 0, 0, 0
};
cmd[2] = UINT_TO_CHAR_FIRST (width);
cmd[3] = UINT_TO_CHAR_SECOND (width);
cmd[4] = UINT_TO_CHAR_FIRST (height);
cmd[5] = UINT_TO_CHAR_SECOND (height);
cmd[2] = width & 0xFF;
cmd[3] = (width & 0xFF00) >> 2;
cmd[4] = height & 0xFF;
cmd[5] = (height & 0xFF00) >> 2;
return cmd;
}