home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR24
/
XICON05.ZIP
/
XICON.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-09
|
10KB
|
360 lines
/* This file is xicon.c (part of XIcon)
*
* Copyright (C) 1993 by Norman Walsh
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Norman Walsh can be reached electronically at <walsh@cs.umass.edu>
* or via paper mail to:
*
* Norman Walsh
* Small Planet Software
* 87 South Silver Lane, #2
* Sunderland, MA 01375
************************************************************************/
#define EMXGCC
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef EMXGCC
/*
#define INCL_BASE
#define INCL_PM
#define SKIPTYPES
#include <os2emx.h>
*/
#include <getopt.h>
#endif /* EMXGCC */
#include "macread.h"
#include "winread.h"
#include "bitmap.h"
#include "icondata.h"
#include "os2write.h"
#include "xbmread.h"
#include "palette.h"
#include "xbmdata.h"
#include "winwrite.h"
/* Optional arguments */
#ifndef EMXGCC /* not */
extern char *optarg;
extern int optind, opterr;
#endif /* not EMXGCC */
int generic_count = 0;
generic_info *generic = NULL;
int dump_input = 0;
int write_20_format = 0;
int write_win_format = 0;
rgb_info *pc_palette = NULL;
rgb_info *mac_palette = NULL;
rgb_info *bw_palette = NULL;
extern int cvtICNp;
extern int cvticsp;
extern int cvticl4;
extern int cvtics4;
extern int MacPalette;
extern int XBMrevbits;
extern int XBMforg;
extern int XBMback;
FILE *input;
FILE *output;
FILE *maskfile;
int rc;
void error (char *msg)
{
printf("%s\n", msg);
exit(1);
}
void init_palettes()
{
pc_palette = (rgb_info *) malloc (sizeof (rgb_info) * 16);
mac_palette = (rgb_info *) malloc (sizeof (rgb_info) * 16);
bw_palette = (rgb_info *) malloc (sizeof (rgb_info) * 2);
pc_palette[ 0] = palette_color (255, 255, 255);
pc_palette[ 1] = palette_color (128, 0, 0);
pc_palette[ 2] = palette_color ( 0, 128, 0);
pc_palette[ 3] = palette_color (128, 128, 0);
pc_palette[ 4] = palette_color ( 0, 0, 128);
pc_palette[ 5] = palette_color (128, 0, 128);
pc_palette[ 6] = palette_color ( 0, 128, 128);
pc_palette[ 7] = palette_color (128, 128, 128);
pc_palette[ 8] = palette_color (204, 204, 204);
pc_palette[ 9] = palette_color (255, 0, 0);
pc_palette[10] = palette_color ( 0, 255, 0);
pc_palette[11] = palette_color (255, 255, 0);
pc_palette[12] = palette_color ( 0, 0, 255);
pc_palette[13] = palette_color (255, 0, 255);
pc_palette[14] = palette_color ( 0, 255, 255);
pc_palette[15] = palette_color ( 0, 0, 0);
mac_palette[ 0] = palette_color (255, 255, 255);
mac_palette[ 1] = palette_color ( 0, 255, 255);
mac_palette[ 2] = palette_color ( 16, 128, 255);
mac_palette[ 3] = palette_color ( 0, 0, 255);
mac_palette[ 4] = palette_color (128, 0, 255);
mac_palette[ 5] = palette_color (177, 17, 20);
mac_palette[ 6] = palette_color (212, 0, 0);
mac_palette[ 7] = palette_color (194, 194, 0);
mac_palette[ 8] = palette_color ( 0, 255, 0);
mac_palette[ 9] = palette_color ( 0, 162, 0);
mac_palette[10] = palette_color ( 75, 97, 193);
mac_palette[11] = palette_color ( 25, 159, 192);
mac_palette[12] = palette_color (224, 224, 224);
mac_palette[13] = palette_color (161, 161, 161);
mac_palette[14] = palette_color ( 82, 82, 82);
mac_palette[15] = palette_color ( 0, 0, 0);
bw_palette[0] = palette_color( 0, 0, 0);
bw_palette[1] = palette_color(255, 255, 255);
}
int main (int argc, char **argv)
{
int count;
char *inputfn, *outputfn, *maskfn;
char *arg, c;
inputfn = NULL;
outputfn = NULL;
maskfn = NULL;
maskfile = NULL;
cvtICNp = 1;
cvticsp = 1;
cvticl4 = 1;
cvtics4 = 1;
MacPalette = 0;
XBMrevbits = 1;
XBMforg = 15;
XBMback = XBM_TRANSPARENT;
init_palettes();
/* Options:
/f: foreground color
/b: background color
/d dump
/p Mac Palette
/2 Output OS/2 v2.0 icon format
/r Don't reverse bits in XBM file
/m Mask file
/w write windows format
/I Don't include ICN# resources
/# Don't include ics# resources
/l Don't include icl4 resources
/s Don't include ics4 resources
*/
fprintf(stderr, "XIcon v0.5 Copyright (c) 1993 by Norman Walsh\n");
if (argc < 2)
{
fprintf(stderr, "Usage: xicon <options> <inputfile> <outputfile>\n");
fprintf(stderr, "Where:\n");
fprintf(stderr, " <inputfile> is an icon file in Mac format (raw resource fork), Windows \n");
fprintf(stderr, " format, or X11 XBM format.\n");
fprintf(stderr, " <outputfile> is the name of the OS/2 icon file that will be created.\n");
fprintf(stderr, " <options> -2 write an OS/2 v2.0 icon file rather than a v1.2 icon file.\n");
fprintf(stderr, " -w write a Windows icon file rather than an OS/2 icon file.\n");
fprintf(stderr, " For XBM files only:\n");
fprintf(stderr, " -f C set foreground color to 'C'. C=0..15 or 't' for \n");
fprintf(stderr, " transparent, or 'r' for reverse of background.\n");
fprintf(stderr, " -b C set background color to 'C'\n");
fprintf(stderr, " -r don't reverse the bit order of the bytes in the XBM file.\n");
fprintf(stderr, " -m f Set mask file to 'f'. The mask file is ANDed with the\n");
fprintf(stderr, " background and the image. Set the bits in the mask area.\n");
fprintf(stderr, "\n");
fprintf(stderr, " For Mac files only:\n");
fprintf(stderr, " -p Use Mac palette rather than OS/2 palette.\n");
fprintf(stderr, " -I Don't include ICN# resources (32x32x1 images)\n");
fprintf(stderr, " -# Don't include ics# resources (16x16x1 images)\n");
fprintf(stderr, " -l Don't include icl4 resources (32x32x4 images)\n");
fprintf(stderr, " -s Don't include ics4 resources (16x16x4 images)\n");
fprintf(stderr, "\n");
}
opterr = 0;
#ifdef EMXGCC
optswchar = "-/";
optmode = GETOPT_ANY;
#endif /* EMXGCC */
while ((c = getopt(argc, argv, "f:b:m:dpw2rI#ls")) != EOF)
{
switch (c)
{
case 'f':
if (strcmp(optarg, "t") == 0 || strcmp(optarg, "T") == 0)
XBMforg = XBM_TRANSPARENT;
else
if (strcmp(optarg, "r") == 0 || strcmp(optarg, "R") == 0)
XBMforg = XBM_REVERSEVID;
else
{
XBMforg = (atoi(optarg) & 0x0F);
}
break;
case 'b':
if (strcmp(optarg, "t") == 0 || strcmp(optarg, "T") == 0)
XBMback = XBM_TRANSPARENT;
else
if (strcmp(optarg, "r") == 0 || strcmp(optarg, "R") == 0)
XBMback = XBM_REVERSEVID;
else
{
XBMback = (atoi(optarg) & 0x0F);
}
break;
case 'm':
maskfn = optarg;
if (access (maskfn, R_OK))
{
fprintf(stderr, "Cannot read mask file, mask ignored.\n");
maskfn = NULL;
}
break;
case 'd': /* dump */
dump_input = 1;
break;
case 'p': /* Mac Palette */
MacPalette = 1;
break;
case '2': /* Output OS/2 v2.0 icon format */
write_20_format = 1;
write_win_format = 0;
break;
case 'w': /* Output Windows format */
write_win_format = 1;
write_20_format = 0;
break;
case 'r': /* Don't reverse bits in XBM file */
XBMrevbits = 0;
break;
case 'I': /* Don't include ICN# resources */
cvtICNp = 0;
break;
case '#': /* Don't include ics# resources */
cvticsp = 0;
break;
case 'l': /* Don't include icl4 resources */
cvticl4 = 0;
break;
case 's': /* Don't include ics4 resources */
cvtics4 = 0;
break;
default:
fprintf(stderr, "Illegal option ignored.\n");
break;
}
}
for ( ; optind < argc; optind++)
{
if (inputfn == NULL)
inputfn = argv[optind];
else
if (outputfn == NULL)
outputfn = argv[optind];
else
error("Too many filenames.");
}
if (inputfn == NULL || outputfn == NULL)
error("You must specify input and output filenames.");
if (access (inputfn, R_OK))
error("Cannot read input file.");
input = fopen(inputfn, "rb");
output = fopen(outputfn, "wb");
if (output == NULL)
error("Cannot create output file.");
if (maskfn)
maskfile = fopen(maskfn, "rb");
if (maskfile != NULL)
fprintf(stderr, "Using mask from %s.\n", maskfn);
switch (QueryFileType())
{
case MacIcon:
read_mac_file();
fprintf(stderr, "Read Macintosh icon file from %s.\n", inputfn);
break;
case OS2Icon12:
case OS2Icon20:
case WinIcon:
read_win_file();
fprintf(stderr, "Read Windows icon file from %s.\n", inputfn);
break;
case XBMicon:
read_xbm_file();
fprintf(stderr, "Read X11 XBM icon file from %s.\n", inputfn);
break;
default:
error("Can't read that type of file.");
}
if (write_win_format)
{
write_win_file();
fprintf(stderr,"Wrote Windows icon file on %s.\n", outputfn);
}
else
if (write_20_format)
{
write_os2_file20();
fprintf(stderr,"Wrote OS/2 version 2.0 icon file on %s.\n", outputfn);
}
else
{
write_os2_file12();
fprintf(stderr,"Wrote OS/2 version 1.2 icon file on %s.\n", outputfn);
}
fclose(input);
fclose(output);
if (maskfile)
fclose(maskfile);
}