X-Git-Url: https://git.draconx.ca/gitweb/liblbx.git/blobdiff_plain/03c280a6c4bec42b1d4617b6d9e0bad1b9bbc80d..3d1e13378f4e3cd29bd2698fed4552024f87e9c2:/src/image.c diff --git a/src/image.c b/src/image.c index c3abf3f..f68f2da 100644 --- a/src/image.c +++ b/src/image.c @@ -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 @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "pack.h" @@ -176,14 +177,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; } @@ -277,6 +281,15 @@ static unsigned char **allocframebuffer(size_t width, size_t height) unsigned char **new, *tmp; size_t i; + if (height > SIZE_MAX / sizeof *new) { + lbx_error_raise(LBX_ENOMEM); + return NULL; + } + + /* Ensure that there is at least one row in the framebuffer. */ + if (height == 0 || width == 0) + width = height = 1; + tmp = calloc(height, width); if (!tmp) { lbx_error_raise(LBX_ENOMEM); @@ -410,9 +423,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 +461,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 +480,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, };