Ключевые слова:ico, xpm, convert, example, (найти похожие документы)
_ RU.LINUX (2:5077/15.22) ___________________________________________ RU.LINUX _
From : Victor Vislobokov 2:5054/69.34 04 Oct 98 00:09:42
Subj : Re: ico -> xpm ?
________________________________________________________________________________
Hello Nicol!
Да, люди. Смотрю я на вас. Уже alchemy стали предлагать.
В свое время и нашел маленькую утилитку, которая как раз это
и делает. Сырцы всего 3 кила. Смотри ниже. Автор KiDong Lee,
Корея.
Сам сырец:
,,,
(o o) File: icotoxpm.c
- ---*reiss*------*schnippel*------oOO--(_)--OOo-------*knabber*-----*fetz*---
/*
icotoxpm - convert MS-Windows icon file to XPM file
version 1.1
Copyright 1996 Lee Ki Dong
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define TRANSPARENT 16
void usage(void);
int main(int argc, char **argv)
{
const char color_sym[17] = "0rgybmcaARGYBMCW ";
const char header[5] = {0, 0, 1, 0};
char *filename;
int array[32][32];
int n, i, x, y, color, mask;
FILE *fpin, *fpout;
if (argc < 2)
{
usage();
exit(1);
}
/* multiple argument */
for (n = 1; n < argc; n++)
{
/* open icon(*.ico) file */
fpin = fopen(argv[n], "r");
if (fpin == NULL)
{
fprintf(stderr, "%s: %s: %s.\n", argv[0], argv[1], strerror(errno));
exit(1);
}
/* identify icon file */
for (i = 0; i < 4 ;i++)
{
if(fgetc(fpin) != header[i])
{
fprintf(stderr, "%s: %s is not a icon file.\n", argv[0],
argv[n]);
goto next;
}
}
/* generate xpm filename */
filename = argv[n];
filename[strlen(argv[n]) - 4] = '\0';
strcat(filename, ".xpm");
/* open xpm file */
fpout = fopen(filename, "w");
if (fpout == NULL)
{
fprintf(stderr, "icotoxpm: %s.\n", strerror(errno));
exit(1);
}
printf("Converting to %s ...\n", filename);
/* write xpm header */
filename[strlen(argv[n]) - 4] = '\0';
fprintf(fpout, "/* XPM */\n\
static char *%s[] = {\n\
/* %s pixmap\n\
* width height ncolors chars_per_pixel */\n\
\"32 32 17 1 \",\n\
/* colors */\n\
\"%c c black m black s s_black \",\n\
\"%c c red4 m black s s_darkred \",\n\
\"%c c green4 m black s s_darkgreen \",\n\
\"%c c yellow4 m black s s_darkyellow \",\n\
\"%c c blue4 m black s s_darkblue \",\n\
\"%c c magenta4 m black s s_darkmagenta \",\n\
\"%c c cyan4 m black s s_darkcyan \",\n\
\"%c c gray50 m black s s_darkgray \",\n\
\"%c c gray75 m white s s_gray \",\n\
\"%c c red m white s s_red \",\n\
\"%c c green m white s s_green \",\n\
\"%c c yellow m white s s_yellow \",\n\
\"%c c blue m white s s_blue \",\n\
\"%c c magenta m white s s_magenta \",\n\
\"%c c cyan m white s s_cyan \",\n\
\"%c c white m white s s_white \",\n\
\"%c c none m white s none \",\n\
/* pixels */\n", filename, filename, color_sym[0], color_sym[1], color_sym[2],
color_sym[3], color_sym[4], color_sym[5], color_sym[6],
color_sym[7], color_sym[8], color_sym[9], color_sym[10],
color_sym[11], color_sym[12], color_sym[13], color_sym[14],
color_sym[15], color_sym[16]);
/* read icon file (XOR mask) */
for (y = 0; y < 32; y++)
{
fseek(fpin, 126 + 16 * (31 - y), SEEK_SET);
for (x = 0; x < 32; x += 2)
{
color = fgetc(fpin);
array[x][y] = color >> 4;
array[x + 1][y] = color & 0x0f;
}
}
/* transparent area (AND mask) */
for (y = 0; y < 32; y++)
{
fseek(fpin, 126 + (32*32/2) + 4 * (31 - y), SEEK_SET);
for (x = 0; x < 32; x += 8)
{
mask = fgetc(fpin);
for (i = 0; i < 8; i++)
if ((mask >> (7 - i)) & 1 == 1)
array [x + i][y] = TRANSPARENT;
}
}
/* write xpm file */
for (y = 0; y < 32; y++)
{
fprintf(fpout, "\"");
for (x = 0; x < 32; x += 2) {
color = fgetc(fpin);
fputc(color_sym[array[x][y]], fpout);
fputc(color_sym[array[x+1][y]], fpout);
}
fprintf(fpout,"\"");
if (y != 1)
fprintf(fpout, ",\n");
else
fprintf(fpout, "\n");
}
fprintf(fpout, "};");
/* close files */
fclose(fpout);
next:
fclose(fpin);
}
exit(0);
}
void usage(void)
{
fprintf(stderr, "usage : icotoxpm [filename]\n");
exit(1);
}
- ---*reiss*------*schnippel*--------------------------*knabber*-----*fetz*---
И к нему Makefile:
,,,
(o o) File: Makefile
- ---*reiss*------*schnippel*------oOO--(_)--OOo-------*knabber*-----*fetz*---
.SUFFIXES = .c .o
CC = gcc
INC =
LIBS =
CFLAGS = $(INC) -Wall -O6
OBJS = icotoxpm.o
SRCS = icotoxpm.c
TARGET = icotoxpm
all : $(TARGET)
$(TARGET) : $(OBJS)
$(CC) -o $@ $(OBJS) $(LIBS)
dep :
gccmakedep $(INC) $(SRCS)
clean :
rm -rf $(OBJS) $(TARGET) core
new :
$(MAKE) clean
$(MAKE)
install :
$(MAKE)
cp $(TARGET) /usr/local/bin
- ---*reiss*------*schnippel*--------------------------*knabber*-----*fetz*---
Все проблемы. Гы.
Спешу уверить в своем глубоком уважении. Виктор
--- reiss*------*schnippel*------oOO--(_)--OOo-------*knabber*-----*fetz*--- * Origin: FEddy - based on FEddi by Oliver Graf (2:5054/69.34)