+#include "imext.h"
#include "msicon.h"
#include <string.h>
#include <stdlib.h>
image->hotspot_y = hotspot_y;
}
- image->width = width;
- image->height = height;
+ /* a width or height of zero here indicates a width/height of 256 */
+ image->width = width ? width : 256;
+ image->height = height ? height : 256;
image->offset = image_offset;
image->size = bytes_in_res;
}
ico_image_t const *image = images + i;
int bits, colors;
int size = ico_image_size(image, &bits, &colors);
+ int width_byte = image->width == 256 ? 0 : image->width;
+ int height_byte = image->height == 256 ? 0 : image->height;
if (type == ICON_ICON) {
- if (!write_packed(ig, "bbbbwwdd", image->width, image->height,
+ if (!write_packed(ig, "bbbbwwdd", width_byte, height_byte,
colors, 0, 1, bits, (unsigned long)size,
(unsigned long)current_offset)) {
*error = ICOERR_Write_Failure;
else if (hotspot_y >= image->height)
hotspot_y = image->height - 1;
- if (!write_packed(ig, "bbbbwwdd", image->width, image->height,
+ if (!write_packed(ig, "bbbbwwdd", width_byte, height_byte,
colors, 0, hotspot_x, hotspot_y, (unsigned long)size,
(unsigned long)current_offset)) {
*error = ICOERR_Write_Failure;
case 'd':
p = va_arg(ap, long *);
- *p = bufp[0] + (bufp[1] << 8) + (bufp[2] << 16) + (bufp[3] << 24);
+ *p = bufp[0] + (bufp[1] << 8) + (bufp[2] << 16) + ((unsigned long)bufp[3] << 24);
bufp += 4;
break;
for (i = 0; i < image_count; ++i) {
ico_image_t const *image = images + i;
- if (image->width < 1 || image->width > 255) {
+ if (image->width < 1 || image->width > 256) {
*error = ICOERR_Invalid_Width;
return 0;
}
- if (image->height < 1 || image->height > 255) {
+ if (image->height < 1 || image->height > 256) {
*error = ICOERR_Invalid_Height;
return 0;
}
static int
write_1_bit(i_io_glue_t *ig, ico_image_t const *image, int *error) {
int line_size = (image->width + 31) / 32 * 4;
- unsigned char *writebuf = malloc(line_size);
+ unsigned char *writebuf;
unsigned char *outp;
unsigned char const *data, *pixelp;
int x,y;
if (!write_palette(ig, image, error))
return 0;
+ writebuf = malloc(line_size);
if (!writebuf) {
*error = ICOERR_Out_Of_Memory;
return 0;