#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;
}