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

1.1     ! root        1: /* interface.c - bit manipulation utility routines */
        !             2: 
        !             3: #ifndef        lint
        !             4: static char *rcsid = "$Header: /f/osi/others/quipu/photo/RCS/interface.c,v 7.0 89/11/23 22:01:44 mrose Rel $";
        !             5: #endif
        !             6: 
        !             7: /* 
        !             8:  * $Header: /f/osi/others/quipu/photo/RCS/interface.c,v 7.0 89/11/23 22:01:44 mrose Rel $
        !             9:  *
        !            10:  *
        !            11:  * $Log:       interface.c,v $
        !            12:  * Revision 7.0  89/11/23  22:01:44  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: /* This file contains utility routines used by both the                 */
        !            33: /* encoding and decoding programs.                                      */
        !            34: /* The routines are concerned with getting and setting bits of          */
        !            35: /* a bit string.                                                        */
        !            36: 
        !            37: /* All these routine work in basically the same way.
        !            38: /* a mask is used to get at each individual bit within
        !            39: /* a byte.  Each time the next bit is required, the
        !            40: /* mask is shifted right, when the mask is zero, the byte is either
        !            41: /* written to the file, or the next byte read in depending upon the
        !            42: /* routine.
        !            43: */
        !            44: 
        !            45: int PIC_LINESIZE,STOP,NUMLINES;
        !            46: 
        !            47: /* ROUTINE:     Get_bit                                                 */
        !            48: /*                                                                      */
        !            49: /* SYNOPSIS:    Gets the next bit from the input.                       */
        !            50: /*              Returns 0 if it is a zero.                              */
        !            51: /*              Returns 1 if it is a one                                */
        !            52: char
        !            53: get_bit (lineptr)
        !            54: 
        !            55: bit_string * lineptr;      /* the line to get the bit from */
        !            56: 
        !            57: {
        !            58: unsigned char    result;
        !            59: 
        !            60:    /* Anding the mask and the data gives a 0 if the bit masked is 0, 1 otherwis
        !            61: e */
        !            62:    result = lineptr->mask & lineptr->pos;
        !            63: 
        !            64:    lineptr->mask  >>= 1;
        !            65: 
        !            66:    if (lineptr->mask == 0) {
        !            67:       lineptr->pos = *lineptr->dbuf++;
        !            68:       lineptr->mask = BIT_MASK;
        !            69:       }
        !            70: 
        !            71:    if( result != 0 )    /* may not be 1, may be 0001000 for example */
        !            72:        result = 1;
        !            73: 
        !            74:    return ( (char) result );
        !            75: }
        !            76: 
        !            77: 
        !            78: 
        !            79: /* ROUTINE:   Set_bit                                                   */
        !            80: /*                                                                      */
        !            81: /* SYNOPSIS:  Sets the next bit of the bit string pointed to by         */
        !            82: /*            lineptr to a one.                                         */
        !            83: 
        !            84: set_bit (lineptr)
        !            85: 
        !            86: bit_string *  lineptr;
        !            87: 
        !            88: {
        !            89:    /* This sets the masked bit */
        !            90:    lineptr->pos |= lineptr->mask;
        !            91: 
        !            92:    lineptr->mask  >>= 1;
        !            93: 
        !            94:    if (lineptr->mask == 0) {
        !            95:       *lineptr->dbuf++ = lineptr->pos;
        !            96:       lineptr->mask = BIT_MASK;
        !            97:       }
        !            98: 
        !            99: }
        !           100: 
        !           101: 
        !           102: 
        !           103: 
        !           104: /* ROUTINE:   Clr_bit                                                   */
        !           105: /*                                                                      */
        !           106: /* SYNOPSIS:  clears the next bit of the bit string pointed to by       */
        !           107: /*            lineptr.  i.e set it to zero.                             */
        !           108: 
        !           109: clr_bit (lineptr)
        !           110: 
        !           111: bit_string *  lineptr;
        !           112: 
        !           113: {
        !           114:     /* clear the masked bit */
        !           115:    lineptr->pos &=   ~(lineptr->mask) ;
        !           116: 
        !           117:    lineptr->mask  >>= 1;         /* right shift the mask */
        !           118: 
        !           119:    if (lineptr->mask == 0) {     /* may need to move on to the next byte */
        !           120:       *lineptr->dbuf++ = lineptr->pos;
        !           121:       lineptr->mask = BIT_MASK;
        !           122:       }
        !           123: 
        !           124: }
        !           125: 
        !           126: 
        !           127: 
        !           128: 

unix.superglobalmegacorp.com

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