home *** CD-ROM | disk | FTP | other *** search
- #include <malloc.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <process.h>
- #include <io.h>
- #include <fcntl.h>
- #include <sys/stat.h>
-
- void main(int parnum,char *pars[],char *env[])
- {
- int bufcount,
- npkx,
- npky,
- npvx,
- npvy,
- scypcik,
- scxpcik,
- horres,
- verres,
- hfilein,
- hfileout,
- decompcik;
- char buf,
- decomps;
- char *picbuf;
- long lfilein,
- deflength;
-
- printf("PICUT v1.0ß by Psycho/TSI (C) '92\n\n");
- if(parnum!=3)
- {
- printf("Too ");
- if(parnum<3) printf("few ");
- else printf("much ");
- printf("parameters!!\n");
- printf("USAGE: PICUT <pcx file> <output file>\n\n");
- exit(EXIT_FAILURE);
- }
- if((hfilein=open(pars[1],O_RDONLY|O_BINARY))==-1||
- (hfileout=open(pars[2],O_WRONLY|O_CREAT|O_BINARY|O_TRUNC,S_IREAD|S_IWRITE))==-1)
- {
- printf("Error in file operations!!\n");
- printf("USAGE: PICUT <pcx file> <output file>\n\n");
- exit(EXIT_FAILURE);
- }
- printf("Reading picture datas...\n");
- if(lseek(hfilein,3,SEEK_SET)!=3||
- read(hfilein,&buf,1)!=1||
- lseek(hfilein,8,SEEK_SET)!=8||
- read(hfilein,&horres,2)!=2||
- read(hfilein,&verres,2)!=2||
- lseek(hfilein,128,SEEK_SET)!=128)
- {
- printf("Read error!!\n\n");
- exit(EXIT_FAILURE);
- }
- if(buf!=8)
- {
- printf("This picture is not 256 color mapped!!\n\n");
- exit(EXIT_FAILURE);
- }
- horres++;
- verres++;
- if(horres!=320||verres!=200)
- {
- printf("The picture size is not 320x200!!\n\n");
- exit(EXIT_FAILURE);
- }
- lfilein=64000L;
- printf("Allocating memory...\n");
- if((picbuf=new char[lfilein])==NULL)
- {
- printf("Not enough memory!!\n\n");
- exit(EXIT_FAILURE);
- }
- printf("Decompressing picture...\n");
- deflength=lfilein;
- bufcount=0;
- while(deflength)
- {
- if(read(hfilein,&buf,1)!=1)
- {
- printf("Read error!!\n\n");
- exit(EXIT_FAILURE);
- }
- if((buf&128)&&(buf&64))
- {
- decomps=buf-192;
- read(hfilein,&buf,1);
- for(decompcik=0;decompcik<decomps;decompcik++)
- {
- picbuf[bufcount]=buf;
- bufcount++;
- deflength--;
- }
- }
- else {
- deflength--;
- picbuf[bufcount]=buf;
- bufcount++;
- }
- }
- npkx=319;
- npky=199;
- npvx=
- npvy=0;
- printf("Cutting picture...\n");
- for(scypcik=0;scypcik<200;scypcik++)
- {
- for(scxpcik=0;scxpcik<320;scxpcik++)
- {
- if(picbuf[scypcik*320+scxpcik])
- {
- if(scxpcik<=npkx) npkx=scxpcik;
- if(scxpcik>=npvx) npvx=scxpcik;
- if(scypcik<=npky) npky=scypcik;
- if(scypcik>=npvy) npvy=scypcik;
- }
- }
- }
- printf("New size:\nx:%i y:%i\n",(npvx-npkx)+1,(npvy-npky)+1);
- printf("Writing new image...\n");
- for(scypcik=npky;scypcik<=npvy;scypcik++)
- {
- if(write(hfileout,&picbuf[scypcik*320+npkx],(npvx-npkx)+1)==-1)
- {
- printf("Error in writing!!\n\n");
- exit(EXIT_FAILURE);
- }
- }
- printf("Cutting has successful!!\n\n");
- exit(EXIT_SUCCESS);
- }
-