/*************************************************************************** * Copyright (C) 2008 by semico * * mail@semico.ru * * * * 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., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include // Коды выхода BSD from @(#)sysexits.h 8.1 (Berkeley) 6/2/93 // Copyright (c) 1987, 1993 // The Regents of the University of California. All rights reserved. #define EX_USAGE 64 /* command line usage error */ #define EX_DATAERR 65 /* data format error */ #define EX_NOINPUT 66 /* cannot open input */ #define EX_NOUSER 67 /* addressee unknown */ #define EX_NOHOST 68 /* host name unknown */ #define EX_UNAVAILABLE 69 /* service unavailable */ #define EX_SOFTWARE 70 /* internal software error */ #define EX_OSERR 71 /* system error (e.g., can't fork) */ #define EX_OSFILE 72 /* critical OS file missing */ #define EX_CANTCREAT 73 /* can't create (user) output file */ #define EX_IOERR 74 /* input/output error */ #define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */ #define EX_PROTOCOL 76 /* remote error in protocol */ #define EX_NOPERM 77 /* permission denied */ #define EX_CONFIG 78 /* configuration error */ // end sysexits.h char version[]="Version 0.12"; //v 0.11 - добавление версии для win32 //v 0.12 - исправлены ошибки в help int dos=0; // 0-GNU/Linux 1-DOS 2-win32 char fname[3][256]; //0-BMP без расширения 1-BMP исходный 2-MKI int fname_vsego; // всего файлов в строке аргументов FILE *fp1,*fp2; //потоки 1-BMP 2-MKI char mes0[8]; /* ВК ПС для DOS или ВК для Linux*/ /* функции */ int bmpgetc(long); int bmp2mki(void); /*-----*/ int bmpgetc(long n) { // считывает байт из указанной позиции BMP-файла int i; int re=EOF; i=fseek(fp1,n,0); // от начала файла - SEEK_SET==0 if (i!=0) goto end; re=fgetc(fp1); end: return(re); } int bmp2mki(void) { int x,y,i,k; int re=0; int bbuf[8], ibuf[8]; // потоки fp1 и fp2 должны быть открыты if ((fp1==NULL)||(fp2==NULL)) {re=1; goto end;} // проверить параметры BMP-файла if ((bmpgetc(0)!=0x42)||(bmpgetc(1)!=0x4D)) {re=1; goto end;} // не BMP if ((bmpgetc(18)!=0x80)||(bmpgetc(22)!=0x40)) {re=1; goto end;} // не 128x64 if ((bmpgetc(26)!=1)||(bmpgetc(28)!=1)) {re=1; goto end;} // не mono // записать заголовок MKI fputc(0,fp2); fputc(0,fp2); fputc(128,fp2); fputc(64,fp2); for (y=0; y<8; y++) { for (x=0; x<16; x++) { // считать 8 байт из BMP в буфер for (i=0; i<8; i++) { k=8*y+i; // строка изображения bbuf[i]=bmpgetc(1070-16*k+x); // 1070 = 16*63 + 62 (62 - смещение в BMP) } // преобразовать из bbuf[i] (строки) в ibuf[i] (столбцы) for (i=0; i<8; i++) ibuf[i]=0; k=1; for (i=0; i<8; i++) { if ((bbuf[i]&1)==0) ibuf[7]|=k; if ((bbuf[i]&2)==0) ibuf[6]|=k; if ((bbuf[i]&4)==0) ibuf[5]|=k; if ((bbuf[i]&8)==0) ibuf[4]|=k; if ((bbuf[i]&16)==0) ibuf[3]|=k; if ((bbuf[i]&32)==0) ibuf[2]|=k; if ((bbuf[i]&64)==0) ibuf[1]|=k; if ((bbuf[i]&128)==0) ibuf[0]|=k; k*=2; } // записать ibuf[] в файл MKI for (i=0; i<8; i++) {k=fputc(ibuf[i],fp2); if (k!=ibuf[i]) re=1; } } } end: return(re); } int main(int argc, char *argv[]) { int i,j,k; char c; int re=EXIT_SUCCESS; fp1=fp2=NULL; if (dos==0) strcpy(mes0,"\n"); else strcpy(mes0,"\r\n"); // разбор строки аргументов if (argc<=1) goto nach; for (i=1; i2) j=2; strncpy(fname[j+1],argv[i],255); if (j<2) fname_vsego++; } else { c=argv[i][1]; if (c=='-') c=argv[i][2]; /* для --help и т.п.*/ if ((c=='h')||(c=='H')||(c=='?')) { /* help */ printf("bmp2mki - converter BMP (128x64, mono) to MKI file %s",mes0); printf("bmp2mki BMPfile [MKIfile] %s",mes0); printf("bmp2mki [key] %s",mes0); printf("\t-h,-H,-?\tthis help; %s",mes0); printf("\t-v,-V\tversion; %s",mes0); printf("\t-w,-W\twarranty and copyright"); goto end; } if ((c=='v')||(c=='V')) { /* version */ printf(version); if (dos==0) printf(" (GNU/Linux)"); if (dos==1) printf(" (DOS)"); if (dos==2) printf(" (Win32)"); goto end; } if ((c=='w')||(c=='W')) { /* copyleft & warranty */ printf("Copyright (C) 2007-2009 by NPP SEMIKO (Russia, Novosibirsk) %s%s",mes0,mes0); printf("This program is free software; you can redistribute it and/or modify %s",mes0); printf("it under the terms of the GNU General Public License as published by %s",mes0); printf("the Free Software Foundation; either version 2 of the License, or %s",mes0); printf("(at your option) any later version. %s%s",mes0,mes0); printf("This program is distributed in the hope that it will be useful, %s",mes0); printf("but WITHOUT ANY WARRANTY; without even the implied warranty of %s",mes0); printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %s",mes0); printf("GNU General Public License for more details. %s%s",mes0,mes0); printf("You should have received a copy of the GNU General Public License %s",mes0); printf("along with this program; if not, write to the Free Software %s",mes0); printf("Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA"); goto end; } printf("bmp2mki -h for help"); goto end; } } nach: if (fname_vsego<=0) {re=EX_USAGE; goto end;} // нет файла fp1=fopen(fname[1],"rb"); // открыть BMP как двоичный для чтения if (fp1==NULL) {re=EX_NOINPUT; goto end;} // файл MKI не открыт k=strlen(fname[1]); for (i=k; i>0; i--) { if ( (fname[1][i]=='.')&&(i0)&&(i