+++ /dev/null
-#ifndef BYTEORDER_H_
-#define BYTEORDER_H_
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdint.h>
-
-static inline uint16_t _flip16(uint16_t val)
-{
- uint16_t hostval;
- int i;
-
- for (i = 0; i < sizeof val; i++)
- ((uint8_t *)&hostval)[i] = ((uint8_t *)&val)[sizeof val - i];
-}
-
-static inline uint32_t _flip32(uint32_t val)
-{
- uint32_t hostval;
- int i;
-
- for (i = 0; i < sizeof val; i++)
- ((uint8_t *)&hostval)[i] = ((uint8_t *)&val)[sizeof val - i];
-}
-
-#ifdef WORDS_BIGENDIAN
-# define letohs(x) _flip16(x)
-# define letohl(x) _flip32(x)
-#else
-# define letohs(x) ((uint16_t)(x))
-# define letohl(x) ((uint16_t)(x))
-#endif
-
-#endif
#include <assert.h>
#include <errno.h>
-#include "byteorder.h"
#include "pack.h"
#include "misc.h"
#include "lbx.h"
static int _lbx_drawrow(int first, struct lbx_image *img)
{
- uint16_t type, yval, count, xval;
+ unsigned short type, count, yval, xval;
+ unsigned char buf[4];
unsigned char *pos;
- unsigned char abyss;
size_t rc;
assert(img->framedata);
assert(img->mask);
- if (fread(&type, sizeof type, 1, img->f) != 1) goto readerr;
- type = letohs(type); img->foff += sizeof type;
+ if (fread(buf, 1, sizeof buf, img->f) != sizeof buf)
+ goto readerr;
+ img->foff += 4;
+ type = unpack_16_le(buf+0);
if (first) {
img->currentx = 0;
}
if (type == 0) {
- if (fread(&yval, sizeof yval, 1, img->f) != 1) goto readerr;
- yval = letohs(yval); img->foff += sizeof yval;
+ yval = unpack_16_le(buf+2);
if (yval == 1000)
return 1;
- if (fread(&count, sizeof count, 1, img->f) != 1) goto readerr;
- count = letohs(count); img->foff += sizeof count;
- if (fread(&xval, sizeof xval, 1, img->f) != 1) goto readerr;
- xval = letohs(xval); img->foff += sizeof xval;
+
+ if (fread(buf, 1, sizeof buf, img->f) != sizeof buf)
+ goto readerr;
+ img->foff += 4;
+ count = unpack_16_le(buf+0);
+
+ xval = unpack_16_le(buf+2);
if (xval == 1000)
return 1;
img->currenty += yval;
img->currentx = xval;
} else {
- if (fread(&xval, sizeof xval, 1, img->f) != 1) goto readerr;
- xval = letohs(xval); img->foff += sizeof xval;
+ xval = unpack_16_le(buf+2);
if (img->width - img->currentx <= xval) {
lbx_errno = LBX_EFORMAT;
img->currentx += xval;
count = type;
-
}
if (count > img->width - img->currentx) {
goto readerr;
if (count % 2) {
- if (fread(&abyss, 1, 1, img->f) != 1)
+ if (fread(buf, 1, 1, img->f) != 1)
goto readerr;
img->foff += 1;
}