libinfo.h File Reference

Library header. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for libinfo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define LI_UNSELECTED   0
#define LI_SELECTED   1
#define LI_OUTPUT_XPM
#define LI_OUTPUT_PPM
#define LIBINFO_VERSION   "1.2 Beta"
#define LIBINFO_DATE   "03/02/2010"
#define LIBINFO_COPYRIGHT   "Copyright (C) 2003-2010 Gary Harris <garyjharris@users.sourceforge.net>"

Typedefs

typedef unsigned char u8
typedef signed char s8
typedef unsigned short u16
typedef unsigned int u32

Functions

int LIReadDefIcon (const char *filename)
 Read images from a default icon.
int LIReadNewIcon (const char *filename)
 Read images from a NewIcon.
void LICleanUp (void)
 Release memory and clean up.
int LISetXPMTransparency (int colour, int image)
int LIWriteXPM (char *filename, int image)
 Write icon image to XPM image.
void LIGetMemoryXPM (char **xpm, int image)
int LIWritePPM (char *filename, int image)
 Write icon image to PPM image.
char * LIGetVersion (void)
char * LIGetDate (void)
char * LIGetCopyright (void)
 Get the library copyright.
u16 Get16 (u8 *p)
u32 Get32 (u8 *p)
int Read8 (u8 *buf, int len)
int ReadHeader (void)
int ReadIcon (int image)
int ReadNewicon (int image, char *name)
u8 * DecompressNewicon (u8 *src, char *name, int len, int bits)
u8 * ReadString ()
int StartTooltypes ()
u8 * GetTooltype (char *name)
int WriteXPM (char *filename, int width, int height, int ncols, u8 *palette, int image)
void GetMemoryXPM (char **amigaicon_xpm, int width, int height, int ncols, u8 *palette, int image)
int WritePPM (char *filename, int width, int height, int ncols, u8 *palette, int image)

Variables

u8 * LIBitmapUnselected
u8 * LIBitmapSelected
u8 * LIPaletteUnselected
u8 * LIPaletteSelected
int LIWidth
int LIHeight
int LINumColoursUnselected
int LINumColoursSelected
char * LIErrorString
FILE * fileIcon
u16 magic
u16 version
u16 type
u32 image1
u32 image2
u32 tool
u32 num_tooltypes

Detailed Description

Library header.

libinfo - a library to read Amiga icon files.

wxAmicon - An Amiga icon viewer. Copyright (C) 2010 Gary Harris <garyjharris@users.sourceforge.net>.

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 the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

libinfo recognizes the default Workbench and NewIcons formats.

libinfo is based on:

amicon: an Amiga icon to ppm/xpm convertor. Copyright 2001 Adam Sampson <ats@offog.org>

Definition in file libinfo.h.


Define Documentation

#define LI_OUTPUT_PPM

Define to include PPM output code.

Definition at line 63 of file libinfo.h.

#define LI_OUTPUT_XPM

Define to include XPM output code.

Definition at line 62 of file libinfo.h.

#define LI_SELECTED   1

Selected Icon Image.

Definition at line 51 of file libinfo.h.

#define LI_UNSELECTED   0

Unselected Icon Image.

Definition at line 50 of file libinfo.h.


Function Documentation

void LICleanUp ( void   ) 

Release memory and clean up.

Release memory etc.

Returns:
Nil.
Author:
Gary Harris.
Date:
17/11/03

Definition at line 319 of file libinfo.c.

00320 {
00321         free(LIPaletteSelected);
00322         free(LIPaletteUnselected);
00323         free(LIBitmapSelected);
00324         free(LIBitmapUnselected);
00325 }

char* LIGetCopyright ( void   ) 

Get the library copyright.

Get the copyright information.

Returns:
The library copyright.
Author:
Gary Harris.
Date:
17/11/03

Definition at line 368 of file libinfo.c.

00369 {
00370         return LIBINFO_COPYRIGHT;
00371 }

char* LIGetDate ( void   ) 

Get the library release date.

Returns:
Library creation date.
Author:
Gary Harris.
Date:
17/11/03

Definition at line 353 of file libinfo.c.

00354 {
00355         return LIBINFO_DATE;
00356 }

void LIGetMemoryXPM ( char **  xpm,
int  image 
)

Get an XPM image in memory.

Parameters:
xpm - a pre-allocated char** to hold the XPM data.
image - constant identifying the image to write. LI_UNSELECTED or LI_SELECTED.
Returns:
void.
Errors are written to LIErrorString.
Author:
Gary Harris.
Date:
19/01/10
Note:
This function requires a char** that is already allocated enough memory to hold the intended XPM data. You can use the parameters read from the icon to determine how much memory to allocate. You will need enough rows to hold the values line, the colour lines and the pixel data and enough columns to contain them. The pixel data is usually wider than the colour lines but may be shorter if the image is very small. See the test application for an example of how to calculate the correct dimensions. See http://en.wikipedia.org/wiki/X_PixMap for a description of the XPM format.
This function is primarily intended for use with wxWidgets' wxImage class.

Definition at line 256 of file libinfo.c.

00257 {
00258         u8      *palette;
00259         int     ncols;
00260 
00261         if(image == LI_UNSELECTED){
00262                 palette = LIPaletteUnselected;
00263                 ncols = LINumColoursUnselected;
00264         }
00265         else{
00266                 palette = LIPaletteSelected;
00267                 ncols = LINumColoursSelected;
00268         }
00269 
00270         GetMemoryXPM(xpm, LIWidth, LIHeight, ncols, palette, image);
00271 }

char* LIGetVersion ( void   ) 

Get the library version.

Returns:
The version number.
Author:
Gary Harris.
Date:
17/11/03

Definition at line 337 of file libinfo.c.

00338 {
00339         return LIBINFO_VERSION;
00340 }

int LIReadDefIcon ( const char *  filename  ) 

Read images from a default icon.

Get both default icons.

Parameters:
filename - The path to the icon.
Returns:
-1 on error, 0 otherwise.
Errors are written to LIErrorString.
Author:
Gary Harris.
Date:
17/11/03
Remarks:
23/01/10 - Return additional values based on status. 25/01/10 - Zero interface variables to prevent data persisting between reads.

Definition at line 78 of file libinfo.c.

00079 {
00080         if((fileIcon = fopen(filename, "rb")) == NULL){
00081                 LIErrorString = "Error opening input file.";
00082                 return -1;
00083         }
00084 
00085         /*  Zero interface variables.*/
00086         LIWidth = 0;
00087         LIHeight = 0;
00088         LINumColoursUnselected = 0;
00089         LINumColoursSelected = 0;
00090 
00091         if(ReadHeader() == -1)
00092                 return -1;
00093         if(ReadIcon(LI_UNSELECTED) == -1)
00094                 return -1;
00095         if(image2)
00096                 if(ReadIcon(LI_SELECTED) == -1)
00097                         return -1;
00098 
00099         fclose(fileIcon);
00100         return 0;
00101 }

int LIReadNewIcon ( const char *  filename  ) 

Read images from a NewIcon.

Get both NewIcons icons.

Parameters:
filename - The path to the icon.
Returns:
-1 on error, 0 otherwise.
Errors are written to LIErrorString.
Author:
Gary Harris.
Date:
4/12/03
Remarks:
04/12/03 - Added missing code that prevents a crash due to spurious num_tooltypes values.
23/01/10 - Return additional values based on status. 25/01/10 - Zero interface variables to prevent data persisting between reads.

Definition at line 122 of file libinfo.c.

00123 {
00124         int ret;
00125 
00126         if((fileIcon = fopen(filename, "rb")) == NULL){
00127                 LIErrorString = "Error opening input file";
00128                 return -1;
00129         }
00130 
00131         if(ReadHeader() == -1)
00132                 return -1;
00133         if(ReadIcon(LI_UNSELECTED) == -1)
00134                 return -1;
00135         if(image2)
00136                 if(ReadIcon(LI_SELECTED) == -1)
00137                         return -1;
00138         if(tool)
00139                 free(ReadString());
00140         if(StartTooltypes() == -1)
00141                 return -1;
00142 
00143         /*  Zero interface variables.*/
00144         LIWidth = 0;
00145         LIHeight = 0;
00146         LINumColoursUnselected = 0;
00147         LINumColoursSelected = 0;
00148 
00149         ret = ReadNewicon(LI_UNSELECTED, "IM1=");
00150         if(ret == -2)
00151                 /* Couldn't find unselected image. */
00152                 return -2;
00153         else if(ret == -1)
00154                 return -1;
00155         ret = ReadNewicon(LI_SELECTED, "IM2=");
00156         if(ret == -2)
00157                 /* Couldn't find selected image. */
00158                 return -3;
00159         else if(ret == -1)
00160                 return -1;
00161 
00162         fclose(fileIcon);
00163         return 0;
00164 }

int LISetXPMTransparency ( int  colour,
int  image 
)

Set transparent colour for XPM output.

Parameters:
colour - the colour to make transparent.
Returns:
-1 on error, 0 otherwise.
Errors are written to LIErrorString.
Author:
Gary Harris.
Date:
17/11/03

Definition at line 180 of file libinfo.c.

00181 {
00182         int     ncols;
00183 
00184         if(image == LI_UNSELECTED){
00185                 ncols = LINumColoursUnselected;
00186         }
00187         else{
00188                 ncols = LINumColoursSelected;
00189         }
00190 
00191         if(colour >= ncols){
00192                 LIErrorString = "Can't set colour transparency.";
00193                 return -1;
00194         }
00195         transparent = colour;
00196 
00197         return 0;
00198 }

int LIWritePPM ( char *  filename,
int  image 
)

Write icon image to PPM image.

Write an image to an PPM file.

Parameters:
filename - path to output image.
image - constant identifying the image to write. LI_UNSELECTED or LI_SELECTED.
Returns:
-1 on error, 0 otherwise.
Errors are written to LIErrorString.
Author:
Gary Harris.
Date:
17/11/03

Definition at line 290 of file libinfo.c.

00291 {
00292         u8      *palette;
00293         int     ncols;
00294 
00295         if(image == LI_UNSELECTED){
00296                 palette = LIPaletteUnselected;
00297                 ncols = LINumColoursUnselected;
00298         }
00299         else{
00300                 palette = LIPaletteSelected;
00301                 ncols = LINumColoursSelected;
00302         }
00303 
00304         return WritePPM(filename, LIWidth, LIHeight, ncols, palette, image);
00305 }

int LIWriteXPM ( char *  filename,
int  image 
)

Write icon image to XPM image.

Write an image to an XPM file.

Parameters:
filename - path to output image.
image - constant identifying the image to write. LI_UNSELECTED or LI_SELECTED.
Returns:
-1 on error, 0 otherwise.
Errors are written to LIErrorString.
Author:
Gary Harris.
Date:
17/11/03

Definition at line 215 of file libinfo.c.

00216 {
00217         u8      *palette;
00218         int     ncols;
00219 
00220         if(image == LI_UNSELECTED){
00221                 palette = LIPaletteUnselected;
00222                 ncols = LINumColoursUnselected;
00223         }
00224         else{
00225                 palette = LIPaletteSelected;
00226                 ncols = LINumColoursSelected;
00227         }
00228 
00229         return WriteXPM(filename, LIWidth, LIHeight, ncols, palette, image);
00230 }


Variable Documentation

Selected image bitmap.

Definition at line 72 of file libinfo.h.

Unselected image bitmap.

Definition at line 71 of file libinfo.h.

Error string.

Definition at line 83 of file libinfo.h.

int LIHeight

Icon height.

Definition at line 78 of file libinfo.h.

Number of colours in selected image's palette.

Definition at line 80 of file libinfo.h.

Number of colours in unselected image's palette.

Definition at line 79 of file libinfo.h.

Selected image palette.

Definition at line 74 of file libinfo.h.

Unselected image palette.

Definition at line 73 of file libinfo.h.

int LIWidth

Icon width.

Definition at line 77 of file libinfo.h.


Generated by  doxygen 1.6.2