The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

msicon.c - functions for working with .ICO files.

SYNOPSIS

  // reading
  int error;
  ico_reader_t *file = ico_reader_open(ig, &error);
  if (!file) {
    char buffer[100];
    ico_error_message(error, buffer, sizeof(buffer));
    fputs(buffer, stderr);
    exit(1);
  }
  int count = ico_image_count(file);
  for (i = 0; i < count; ++i) {
    ico_image_t *im = ico_image_read(file, index);
    printf("%d x %d image %d\n", im->width, im->height, 
           im->direct ? "direct" : "paletted");
    ico_image_release(im);
  }
  ico_reader_close(file);

DESCRIPTION

This is intended as a general interface to reading MS Icon files, and is written to be independent of Imager, even though it is part of Imager. You just need to supply something that acts like Imager's io_glue.

It relies on icon images being generally small, and reads the entire image into memory when reading.

READING ICON FILES

ico_reader_open(ig, &error)

Parameters:

  • io_glue *ig - an Imager IO object. This must be seekable.

  • int *error - pointer to an integer which an error code will be returned in on failure.

ico_image_count
  // number of images in the file
  count = ico_image_count(file);
ico_type
  // type of file - ICON_ICON for icon, ICON_CURSOR for cursor
  type = ico_type(file);
ico_image_read

Read an image from the file given it's index.

ico_image_release

Release an image structure returned by ico_image_read.

ico_reader_close

Releases the read file structure.

WRITING ICON FILES

ico_write(ig, images, image_count, type, &error)

Parameters:

  • io_glue *ig - an Imager IO object. This only needs to implement writing for ico_write()

  • ico_image_t *images - array of images to be written.

  • int image_count - number of images

  • int type - must be ICON_ICON or ICON_CURSOR

  • int *error - set to an error code on failure.

Returns non-zero on success.

ERROR MESSAGES

ico_error_message

Converts an error code into an error message.

PRIVATE FUNCTIONS

read_packed

Reads packed data from a stream, unpacking it.

read_palette

Reads the palette data for an icon image.

read_32bit_data

Reads 32 bit image data.

read_24bit_data

Reads 24 bit image data.

read_8bit_data

Reads 8 bit image data.

read_4bit_data

Reads 4 bit image data.

read_1bit_data

Reads 1 bit image data.

read_mask

Reads the AND mask from an icon image.

ico_write_validate

Check each image to make sure it can go into an icon file.

ico_image_size

Calculate how much space the icon takes up in the file.

write_packed

Pack numbers given a format to a stream.

write_palette

Write the palette for an icon.

write_bitmapinfoheader

Write the BITMAPINFOHEADER for an icon image.

write_32_bit

Write 32-bit image data to the icon.

write_8_bit

Write 8 bit image data.

write_4_bit

Write 4 bit image data.

write_1_bit

Write 1 bit image data.

write_mask

Write the AND mask.

AUTHOR

Tony Cook <tonyc@cpan.org>

REVISION

$Revision$