Browse Source

* src/io.c:

+ Removed a useless message.
  * src/bitmap.c examples/view.c:
    + Really fixed the endianness issue.
tags/v0.99.beta14
Sam Hocevar sam 21 years ago
parent
commit
5fafff6d58
3 changed files with 24 additions and 13 deletions
  1. +2
    -2
      examples/view.c
  2. +22
    -10
      src/bitmap.c
  3. +0
    -1
      src/io.c

+ 2
- 2
examples/view.c View File

@@ -61,11 +61,11 @@ int main(int argc, char **argv)
if(*(char *)&rmask == 0x12) if(*(char *)&rmask == 0x12)
#endif #endif
{ {
rmask = 0x00ff0000; gmask = 0x0000ff00; bmask = 0x000000ff; rmask = 0x0000ff00; gmask = 0x00ff0000; bmask = 0xff000000;
} }
else else
{ {
rmask = 0x0000ff00; gmask = 0x00ff0000; bmask = 0xff000000; rmask = 0x00ff0000; gmask = 0x0000ff00; bmask = 0x000000ff;
} }


/* Initialise libcaca */ /* Initialise libcaca */


+ 22
- 10
src/bitmap.c View File

@@ -37,6 +37,10 @@ typedef unsigned short uint16_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
#endif #endif


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

#include <stdlib.h> #include <stdlib.h>


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


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


switch(bitmap->bpp / 8) switch(bitmap->bpp / 8)
{ {
case 4: case 4:
bits = ((uint32_t)pixels[0] << 24) | bits = *(uint32_t *)pixels;
((uint32_t)pixels[1] << 16) |
((uint32_t)pixels[2] << 8) |
((uint32_t)pixels[3]);
break; break;
case 3: case 3:
bits = ((uint32_t)pixels[0] << 16) | {
((uint32_t)pixels[1] << 8) | #ifdef HAVE_ENDIAN_H
((uint32_t)pixels[2]); 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; break;
}
case 2: case 2:
bits = ((uint16_t)pixels[0] << 8) | bits = *(uint16_t *)pixels;
((uint16_t)pixels[1]);
break; break;
case 1: case 1:
default: default:


+ 0
- 1
src/io.c View File

@@ -170,7 +170,6 @@ unsigned int caca_get_event(void)
return event; 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 */ /* Unknown escape sequence: return the ESC key */
return CACA_EVENT_KEY_PRESS | '\x1b'; return CACA_EVENT_KEY_PRESS | '\x1b';
} }


||||||
x
 
000:0
Loading…
Cancel
Save