Annotation of 43BSDReno/contrib/isode-beta/others/quipu/photo/tty.c, revision 1.1

1.1     ! root        1: /* tty.c - display on any terminal */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/tty.c,v 7.0 89/11/23 22:01:49 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/others/quipu/photo/RCS/tty.c,v 7.0 89/11/23 22:01:49 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       tty.c,v $
        !            12:  * Revision 7.0  89/11/23  22:01:49  mrose
        !            13:  * Release 6.0
        !            14:  * 
        !            15:  */
        !            16: 
        !            17: /*
        !            18:  *                               NOTICE
        !            19:  *
        !            20:  *    Acquisition, use, and distribution of this module and related
        !            21:  *    materials are subject to the restrictions of a license agreement.
        !            22:  *    Consult the Preface in the User's Manual for the full terms of
        !            23:  *    this agreement.
        !            24:  *
        !            25:  */
        !            26: 
        !            27: 
        !            28: 
        !            29: #include "stdio.h"
        !            30: #include "quipu/photo.h"
        !            31: 
        !            32: #define GREYSCALE "#OI&\\*o=_\"-;:,.  "
        !            33: 
        !            34: char    mapping[16];
        !            35: char * strcpy ();
        !            36: 
        !            37: char    buffer[500][500];
        !            38: int     lineno = 0,
        !            39:         pos = 0;
        !            40: extern int PIC_LINESIZE;
        !            41: extern int NUMLINES;
        !            42: int     scale = 8;
        !            43: int     invert = 0;
        !            44: int     equal = 0;
        !            45: int     ln = 0;
        !            46: int     scalediv = 0;
        !            47: int     edges = 0;
        !            48: 
        !            49: char    level[128];
        !            50: char    show[128];
        !            51: char    display[50][50];
        !            52: 
        !            53: /* ARGSUSED */
        !            54: photo_start (name)
        !            55: char   *name;
        !            56: {
        !            57:        char   *ptr,
        !            58:               *getenv ();
        !            59: 
        !            60: 
        !            61:        if ((ptr = getenv ("photo_invert")) != (char *) NULL)
        !            62:                if (strcmp (ptr, "true") == 0)
        !            63:                        invert = 1;
        !            64: 
        !            65:        if ((ptr = getenv ("photo_equal")) != (char *) NULL) {
        !            66:                if (strcmp (ptr, "true") == 0)
        !            67:                        equal = 1;
        !            68:                else if (strcmp (ptr, "edge") == 0) {
        !            69:                        int     i,
        !            70:                                j;
        !            71: 
        !            72:                        for (i = 1; i < PIC_LINESIZE; i++)
        !            73:                                for (j = 1; j < NUMLINES; j++)
        !            74:                                        buffer[i][j] = 0;
        !            75:                        edges = 1;
        !            76:                }
        !            77:        }
        !            78:        if ((ptr = getenv ("photo_mapping")) != (char *) NULL)
        !            79:                (void) strcpy (mapping, ptr);
        !            80:        else
        !            81:                (void) strcpy (mapping, GREYSCALE);
        !            82: 
        !            83:        if ((ptr = getenv ("photo_scale")) != (char *) NULL) {
        !            84:                if (strcmp (ptr, "large") == 0)
        !            85:                        scale = 1;
        !            86:                else if (strcmp (ptr, "small") == 0)
        !            87:                        scale = 8;
        !            88:                else if (strcmp (ptr, "medium") == 0)
        !            89:                        scale = 4;
        !            90:        }
        !            91:        scalediv = scale * scale / 8;
        !            92: 
        !            93:        (void) printf ("\n");
        !            94:        return (0);
        !            95: }
        !            96: 
        !            97: /* ARGSUSED */
        !            98: photo_end (name)
        !            99: char   *name;
        !           100: {
        !           101:        int     i,
        !           102:                j,
        !           103:                k;
        !           104:        int     numlev;
        !           105:        int     total = 0;
        !           106:        int     totlevel = 0;
        !           107:        int     cnt;
        !           108: 
        !           109:        if (equal) {
        !           110:                numlev = scale * scale * 2;
        !           111:                for (i = 0; i < numlev; i++)
        !           112:                        level[i] = 0;
        !           113: 
        !           114:                for (i = 0; i < ln; i++)
        !           115:                        for (j = 0; j < PIC_LINESIZE / scale; j++)
        !           116:                                level[display[i][j]]++;
        !           117: 
        !           118:                for (i = 0; i < numlev; i++)
        !           119:                        totlevel += level[i];
        !           120: 
        !           121:                for (i = 0; i < numlev; i++) {
        !           122:                        total += level[i];
        !           123:                        show[i] = (total * 16) / totlevel;
        !           124:                        if (show[i] >= 16)
        !           125:                                show[i] = 15;
        !           126:                }
        !           127: 
        !           128:                for (i = 0; i < ln; i++) {
        !           129:                        for (j = 0; j < PIC_LINESIZE / scale; j++) {
        !           130:                                if (invert)
        !           131:                                        (void) putc (mapping[show[display[i][j]]],stdout);
        !           132:                                else
        !           133:                                        (void) putc (mapping[15 - show[display[i][j]]],stdout);
        !           134:                        }
        !           135:                        (void) printf ("\n");
        !           136:                }
        !           137:        } else if (edges) {
        !           138:                /* edges by expansion */
        !           139:                char    ebuf[500][500];
        !           140: 
        !           141:                for (i = 1; i < PIC_LINESIZE; i++)
        !           142:                        for (j = 1; j < NUMLINES; j++)
        !           143:                                ebuf[i][j] = 0;
        !           144: 
        !           145:                for (i = 1; i < PIC_LINESIZE; i++)
        !           146:                        for (j = 1; j < NUMLINES; j++)
        !           147:                                if (buffer[i][j] == 1) {
        !           148:                                        ebuf[i - 1][j - 1] = 1;
        !           149:                                        ebuf[i - 1][j] = 1;
        !           150:                                        ebuf[i - 1][j + 1] = 1;
        !           151:                                        ebuf[i][j - 1] = 1;
        !           152:                                        ebuf[i][j + 1] = 1;
        !           153:                                        ebuf[i + 1][j - 1] = 1;
        !           154:                                        ebuf[i + 1][j] = 1;
        !           155:                                        ebuf[i + 1][j + 1] = 1;
        !           156:                                }
        !           157:                for (i = 1; i < PIC_LINESIZE; i++)
        !           158:                        for (j = 1; j < NUMLINES; j++)
        !           159:                                if (buffer[i][j] == 1)
        !           160:                                        ebuf[i][j] = 0;
        !           161: 
        !           162:                for (lineno = 0; lineno < NUMLINES; lineno += (2 * scale)) {
        !           163:                        for (k = 0; k < PIC_LINESIZE; k += scale) {
        !           164:                                cnt = 0;
        !           165:                                for (i = k; i < k + scale; i++)
        !           166:                                        for (j = lineno; j < (2 * scale) + lineno; j++)
        !           167:                                                cnt += ebuf[i][j];
        !           168: 
        !           169: /* Need to select a grey level on the strength of the edge
        !           170:  *
        !           171:  *                             cnt *= 4;
        !           172:  *                             if (cnt == (scalediv * 16))
        !           173:  *                                     cnt = (scalediv * 16) -1;
        !           174:  *
        !           175:  * Just set "strong" edge cells "on" for now ...
        !           176:  */
        !           177:                                if (cnt > (scalediv * 2) )
        !           178:                                        cnt = (scalediv * 16) -1;
        !           179:                                else 
        !           180:                                        cnt = 0;        
        !           181: 
        !           182:                                if (invert)
        !           183:                                        (void) putc (mapping[(cnt / scalediv)],stdout);
        !           184:                                else
        !           185:                                        (void) putc (mapping[15 - (cnt / scalediv)],stdout);
        !           186:                        }
        !           187:                        (void) putc ('\n',stdout);
        !           188:                }
        !           189: 
        !           190:        }
        !           191:        return (0);
        !           192: 
        !           193: }
        !           194: 
        !           195: photo_black (length)
        !           196: int     length;
        !           197: {
        !           198:        int     i;
        !           199: 
        !           200:        if (scale == 1) {
        !           201:                for (i = pos; i < length + pos; i++)
        !           202:                        if (invert)
        !           203:                                (void) putc (' ',stdout);
        !           204:                        else
        !           205:                                (void) putc ('#',stdout);
        !           206:                return;
        !           207:        }
        !           208:        for (i = pos; i < length + pos; i++)
        !           209:                buffer[i][lineno] = 1;
        !           210:        pos += length;
        !           211: }
        !           212: 
        !           213: photo_white (length)
        !           214: int     length;
        !           215: {
        !           216:        int     i;
        !           217: 
        !           218:        if (scale == 1) {
        !           219:                for (i = pos; i < length + pos; i++)
        !           220:                        if (invert)
        !           221:                                (void) putc ('#',stdout);
        !           222:                        else
        !           223:                                (void) putc (' ',stdout);
        !           224:                return;
        !           225:        }
        !           226:        for (i = pos; i < length + pos; i++)
        !           227:                buffer[i][lineno] = 0;
        !           228:        pos += length;
        !           229: }
        !           230: 
        !           231: /* ARGSUSED */
        !           232: photo_line_end (line)
        !           233: bit_string *line;
        !           234: {
        !           235:        int     i,
        !           236:                j,
        !           237:                k,
        !           238:                cnt;
        !           239: 
        !           240:        if (scale == 1) {
        !           241:                (void) putc ('\n',stdout);
        !           242:                return;
        !           243:        }
        !           244:        lineno++;
        !           245:        pos = 0;
        !           246: 
        !           247:        if (edges)
        !           248:                return;
        !           249: 
        !           250:        if (lineno >= 2 * scale) {
        !           251:                ln++;
        !           252:                lineno = 0;
        !           253:                for (k = 0; k < PIC_LINESIZE; k += scale) {
        !           254:                        cnt = 0;
        !           255:                        for (i = k; i < k + scale; i++)
        !           256:                                for (j = 0; j < 2 * scale; j++)
        !           257:                                        cnt += buffer[i][j];
        !           258: 
        !           259:                        if (equal) {
        !           260:                                display[ln][k / scale] = cnt;
        !           261:                                continue;
        !           262:                        }
        !           263:                        if (cnt == (scalediv * 16))
        !           264:                                cnt--;
        !           265: 
        !           266: 
        !           267:                        if (invert)
        !           268:                                (void) putc (mapping[cnt / scalediv],stdout);
        !           269:                        else
        !           270:                                (void) putc (mapping[15 - (cnt / scalediv)],stdout);
        !           271:                }
        !           272: 
        !           273:                if (!equal)
        !           274:                        (void) putc ('\n',stdout);
        !           275:        }
        !           276: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.