]> git.draconx.ca Git - liblbx.git/blobdiff - src/image.c
liblbx: Kill byteorder.h.
[liblbx.git] / src / image.c
index 4f335d07298c56e94d63be9156c1a7d6477f7920..888515b45293ad22b5815f4be9a8885fe3136f5e 100644 (file)
@@ -26,7 +26,6 @@
 #include <assert.h>
 #include <errno.h>
 
-#include "byteorder.h"
 #include "pack.h"
 #include "misc.h"
 #include "lbx.h"
@@ -155,16 +154,18 @@ struct lbx_image *lbximg_fopen(FILE *f)
 
 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;
@@ -173,14 +174,16 @@ static int _lbx_drawrow(int first, struct lbx_image *img)
        }
 
        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;
 
@@ -193,8 +196,7 @@ static int _lbx_drawrow(int first, struct lbx_image *img)
                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;
@@ -203,7 +205,6 @@ static int _lbx_drawrow(int first, struct lbx_image *img)
                img->currentx += xval;
 
                count = type;
-
        }
 
        if (count > img->width - img->currentx) {
@@ -222,7 +223,7 @@ static int _lbx_drawrow(int first, struct lbx_image *img)
                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;
        }