libinfo.c File Reference

Library functions. More...

#include "libinfo.h"
Include dependency graph for libinfo.c:

Go to the source code of this file.

Functions

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

Variables

int transparent = -1
u8 mwb_palette []

Detailed Description

Library functions.

libinfo - a library to read Amiga icon files.

Copyright (C) 2003-2010 Gary Harris <garyjharris@users.sourceforge.net>.

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.c.


Function Documentation

void LICleanUp ( void   ) 

Release memory and clean up.

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.

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.

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.

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.

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.

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

Initial value:
 {
        149, 149, 149,
        0, 0, 0,
        255, 255, 255,
        59, 103, 162,
        123, 123, 123,
        175, 175, 175,
        170, 144, 124,
        255, 169, 151
}

Magic Workbench palette

Definition at line 45 of file libinfo.c.


Generated by  doxygen 1.6.2