This is tools.c in view mode; [Download] [Up]
/* hpcdtoppm (Hadmut's pcdtoppm) v0.4 * Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de). * Permission to use and distribute this software and its * documentation for noncommercial use and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. It is not allowed to sell this software in * any way. This software is not public domain. */ #include "hpcdtoppm.h" void clear(l,n) implane *l; int n; { dim x,y; uBYTE *ptr; ptr=l->im; for (x=0;x<l->mwidth;x++) for (y=0; y<l->mheight;y++) *(ptr++)=n; } void halve(p) implane *p; {dim w,h,x,y; uBYTE *optr,*nptr; melde("halve\n"); if ((!p) || (!p->im)) error(E_INTERN); w=p->iwidth/=2; h=p->iheight/=2; for(y=0;y<h;y++) { nptr=(p->im) + y*(p->mwidth); optr=(p->im) + 2*y*(p->mwidth); for(x=0;x<w;x++,nptr++,optr+=2) { *nptr = *optr; } } } void interpolate(p) implane *p; {dim w,h,x,y,yi; uBYTE *optr,*nptr,*uptr; melde("interpolate\n"); if ((!p) || (!p->im)) error(E_INTERN); w=p->iwidth; h=p->iheight; if(p->mwidth < 2*w ) error(E_INTERN); if(p->mheight < 2*h ) error(E_INTERN); p->iwidth=2*w; p->iheight=2*h; for(y=0;y<h;y++) {yi=h-1-y; optr=p->im+ yi*p->mwidth + (w-1); nptr=p->im+2*yi*p->mwidth + (2*w - 2); nptr[0]=nptr[1]=optr[0]; for(x=1;x<w;x++) { optr--; nptr-=2; nptr[0]=optr[0]; nptr[1]=(((int)optr[0])+((int)optr[1])+1)>>1; } } for(y=0;y<h-1;y++) {optr=p->im + 2*y*p->mwidth; nptr=optr+p->mwidth; uptr=nptr+p->mwidth; for(x=0;x<w-1;x++) { nptr[0]=(((int)optr[0])+((int)uptr[0])+1)>>1; nptr[1]=(((int)optr[0])+((int)optr[2])+((int)uptr[0])+((int)uptr[2])+2)>>2; nptr+=2; optr+=2; uptr+=2; } *(nptr++)=(((int)*(optr++))+((int)*(uptr++))+1)>>1; *(nptr++)=(((int)*(optr++))+((int)*(uptr++))+1)>>1; } optr=p->im + (2*h-2)*p->mwidth; nptr=p->im + (2*h-1)*p->mwidth; for(x=0;x<w;x++) { *(nptr++) = *(optr++); *(nptr++) = *(optr++); } } static int testbegin() {int i,j; for(i=j=0;i<32;i++) if(sbuffer[i]==0xff) j++; return (j>30); } long Skip4Base() {long cd_offset,cd_offhelp; cd_offset = L_Head + L_Base16 + L_Base4 + L_Base ; SEEK(cd_offset+3); EREADBUF; cd_offhelp=((((long)sbuffer[510])<<8)|sbuffer[511]) + 1; cd_offset+=cd_offhelp; SEEK(cd_offset); EREADBUF; while(!testbegin()) {cd_offset++; EREADBUF; } return cd_offset; } void planealloc(p,width,height) implane *p; dim width,height; {melde("planealloc\n"); p->iwidth=p->iheight=0; p->mwidth=width; p->mheight=height; p->mp = ( p->im = ( uBYTE * ) malloc (width*height*sizeof(uBYTE)) ); if(!(p->im)) error(E_MEM); } static void pastequer(gross,px,py,klein) implane *gross,*klein; dim px,py; {dim x,y; uBYTE *von,*nach; if(px+klein->iwidth > gross->iwidth) error(E_INTERN); if(py+klein->iheight > gross->iheight) error(E_INTERN); for(y=0;y<klein->iheight;y++) { von=klein->im + y * klein->mwidth; nach=gross->im + (y+py) * gross->mwidth + px; for(x=0;x<klein->iwidth;x++) *(nach++)=*(von++); } } static void pastelinks(gross,px,py,klein) implane *gross,*klein; dim px,py; {dim x,y; uBYTE *von,*nach; if(px+klein->iheight > gross->iwidth) error(E_INTERN); if(py+klein->iwidth > gross->iheight) error(E_INTERN); for(y=0;y<klein->iwidth;y++) { von=klein->im + klein->iwidth - 1 - y; nach=gross->im + (y+py) * gross->mwidth + px; for(x=0;x<klein->iheight;x++,von+=klein->mwidth) *(nach++)=*(von); } } static void pasterechts(gross,px,py,klein) implane *gross,*klein; dim px,py; {dim x,y; uBYTE *von,*nach; if(px+klein->iheight > gross->iwidth) error(E_INTERN); if(py+klein->iwidth > gross->iheight) error(E_INTERN); for(y=0;y<klein->iwidth;y++) { von=klein->im + (klein->iheight-1)*klein->mwidth + y; nach=gross->im + (y+py) * gross->mwidth + px; for(x=0;x<klein->iheight;x++,von-=klein->mwidth) *(nach++)=*(von); } } void pastein(gross,xpos,xw,ypos,yh,klein,ori) implane *gross,*klein; dim xpos,xw,ypos,yh; enum TURNS ori; { switch (ori) { case T_NONE: pastequer(gross,xpos+(xw-klein->iwidth)/2,ypos+(yh-klein->iheight)/2,klein); break; case T_LEFT: pastelinks(gross,xpos+(xw-klein->iheight)/2,ypos+(yh-klein->iwidth)/2,klein); break; case T_RIGHT:pasterechts(gross,xpos+(xw-klein->iheight)/2,ypos+(yh-klein->iwidth)/2,klein); break; case T_AUTO: default: error(E_INTERN); } } #define cro(p,d) {if(p) {p->im+=d*p->mwidth; p->iheight-=d;}} #define cru(p,d) {if(p) {p->iheight-=d;}} #define crl(p,d) {if(p) {p->im+=d; p->iwidth-=d;}} #define crr(p,d) {if(p) {p->iwidth-=d;}} void cropit(wp,hp,l,c1,c2) dim *wp,*hp; implane *l,*c1,*c2; #define w (*wp) #define h (*hp) {dim x,y,s; int nl,nr,no,nu; uBYTE *ptr; for(y=0,no=0;y<h;y++,no++) {for(x=0,ptr=(l->im)+y*(l->mwidth); x<w && (*ptr)<MAX_BLACK ;x++,ptr++); if(x<w) break; } cro(l ,no); cro(c1,no); cro(c2,no); h-=no; for(y=h-1,nu=0;y;y--,nu++) {for(x=0,ptr=(l->im)+y*(l->mwidth); x<w && (*ptr)<MAX_BLACK ;x++,ptr++); if(x<w) break; } cru(l ,nu); cru(c1,nu); cru(c2,nu); h-=nu; s=l->mwidth; for(x=0,nl=0;x<w;x++,nl++) {for(y=0,ptr=(l->im)+x; y<h && (*ptr)<MAX_BLACK ; y++, ptr+=s); if(y<h) break; } crl(l ,nl); crl(c1,nl); crl(c2,nl); w-=nl; for(x=w-1,nr=0;x;x--,nr++) {for(y=0,ptr=(l->im)+x; y<h && (*ptr)<MAX_BLACK ; y++, ptr+=s); if(y<h) break; } crr(l ,nr); crr(c1,nr); crr(c2,nr); w-=nr; if (do_melde) { if (no || nu || nr || nl ) fprintf(stderr,"Cut off %d top, %d bottom, %d left, %d right, new size is %lux%lu\n", no,nu,nl,nr,w,h); else fprintf(stderr,"Nothing cut off\n"); } #undef w #undef h }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.