Skip to content

Commit

Permalink
* src/io.c:
Browse files Browse the repository at this point in the history
    + Removed a useless message.
  * src/bitmap.c examples/view.c:
    + Really fixed the endianness issue.
  • Loading branch information
samhocevar committed Nov 30, 2003
1 parent ec6f084 commit 5fafff6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ int main(int argc, char **argv)
if(*(char *)&rmask == 0x12)
#endif
{
rmask = 0x00ff0000; gmask = 0x0000ff00; bmask = 0x000000ff;
rmask = 0x0000ff00; gmask = 0x00ff0000; bmask = 0xff000000;
}
else
{
rmask = 0x0000ff00; gmask = 0x00ff0000; bmask = 0xff000000;
rmask = 0x00ff0000; gmask = 0x0000ff00; bmask = 0x000000ff;
}

/* Initialise libcaca */
Expand Down
32 changes: 22 additions & 10 deletions src/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#endif

#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif

#include <stdlib.h>

#include "caca.h"
Expand Down Expand Up @@ -236,26 +240,34 @@ static void get_rgb_default(struct caca_bitmap *bitmap, uint8_t *pixels,
int x, int y, unsigned int *r,
unsigned int *g, unsigned int *b)
{
unsigned int bits;
uint32_t bits;

pixels += (bitmap->bpp / 8) * x + bitmap->pitch * y;

switch(bitmap->bpp / 8)
{
case 4:
bits = ((uint32_t)pixels[0] << 24) |
((uint32_t)pixels[1] << 16) |
((uint32_t)pixels[2] << 8) |
((uint32_t)pixels[3]);
bits = *(uint32_t *)pixels;
break;
case 3:
bits = ((uint32_t)pixels[0] << 16) |
((uint32_t)pixels[1] << 8) |
((uint32_t)pixels[2]);
{
#ifdef HAVE_ENDIAN_H
if(__BYTE_ORDER == __BIG_ENDIAN)
#else
static const uint32_t rmask = 0x12345678;
if(*(uint8_t *)&rmask == 0x12)
#endif
bits = ((uint32_t)pixels[0] << 16) |
((uint32_t)pixels[1] << 8) |
((uint32_t)pixels[2]);
else
bits = ((uint32_t)pixels[2] << 16) |
((uint32_t)pixels[1] << 8) |
((uint32_t)pixels[0]);
break;
}
case 2:
bits = ((uint16_t)pixels[0] << 8) |
((uint16_t)pixels[1]);
bits = *(uint16_t *)pixels;
break;
case 1:
default:
Expand Down
1 change: 0 additions & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ unsigned int caca_get_event(void)
return event;
}

caca_printf(0,0, "unknown esc sequence %2x %2x %2x %2x %2x\n", '\x1b', keybuf[0], keybuf[1], keybuf[2], keybuf[3]);
/* Unknown escape sequence: return the ESC key */
return CACA_EVENT_KEY_PRESS | '\x1b';
}
Expand Down

0 comments on commit 5fafff6

Please sign in to comment.