]> git.draconx.ca Git - liblbx.git/blobdiff - src/image.c
liblbx: Don't scale palette values internally.
[liblbx.git] / src / image.c
index c3abf3f643524d14e9948e54bb24529ab6685b91..98d1a31118ceb03085d14d860045ef267ed52244 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 2ooM: The Master of Orion II Reverse Engineering Project
  * Library for working with LBX image files.
- * Copyright © 2006-2011 Nick Bowler
+ * Copyright © 2006-2011, 2013 Nick Bowler
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -176,14 +176,17 @@ struct lbx_image *lbx_img_fopen(const char *file)
        FILE *f;
 
        f = fopen(file, "rb");
-       if (!f)
+       if (!f) {
+               lbx_error_raise(-errno);
                return NULL;
+       }
 
        if (fseek(f, 0, SEEK_CUR) == 0)
                return lbx_img_open(f, &lbx_default_fops, file_close);
 
        p = malloc(sizeof *p);
        if (!p) {
+               lbx_error_raise(LBX_ENOMEM);
                fclose(f);
                return NULL;
        }
@@ -410,9 +413,9 @@ lbx_img_loadpalette(void *f, const struct lbx_file_ops *fops,
                }
 
                palette[i] = (struct lbx_colour) {
-                       .red    = entry[1] << 2,
-                       .green  = entry[2] << 2,
-                       .blue   = entry[3] << 2,
+                       .red    = entry[1] & 0x3f,
+                       .green  = entry[2] & 0x3f,
+                       .blue   = entry[3] & 0x3f,
                        .active = 1,
                };
        }
@@ -448,9 +451,9 @@ lbx_img_getpalette(struct lbx_image *pub, struct lbx_colour palette[static 256])
                }
 
                palette[img->palstart + i] = (struct lbx_colour){
-                       .red    = entry[1] << 2,
-                       .green  = entry[2] << 2,
-                       .blue   = entry[3] << 2,
+                       .red    = entry[1],
+                       .green  = entry[2],
+                       .blue   = entry[3],
                        .active = 1,
                };
        }
@@ -467,10 +470,6 @@ void lbx_img_getinfo(struct lbx_image *pub, struct lbx_imginfo *info)
        struct lbx_image_priv *img = (struct lbx_image_priv *)pub;
 
        *info = (struct lbx_imginfo) {
-               .width      = pub->width,
-               .height     = pub->height,
-               .nframes    = pub->frames,
-               .chunk      = pub->chunk,
                .palettesz  = (img->flags & FLAG_PALETTE) ? img->palcount : 0,
        };