• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ MAXCODE函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中MAXCODE函数的典型用法代码示例。如果您正苦于以下问题:C++ MAXCODE函数的具体用法?C++ MAXCODE怎么用?C++ MAXCODE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MAXCODE函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: output

static void
output(int code)
{
    cur_accum &= masks[cur_bits];

    if (cur_bits > 0)
        cur_accum |= ((long)code << cur_bits);
    else
        cur_accum = code;

    cur_bits += n_bits;

    while( cur_bits >= 8 ) {
        char_out( (int)((unsigned int) cur_accum & 0xff) );
        cur_accum >>= 8;
        cur_bits -= 8;
    }

    /*
     * If the next entry is going to be too big for the code size, then
     * increase it, if possible.
     */
    if (free_ent > maxcode || clear_flg) {
        if (clear_flg) {
            maxcode = MAXCODE (n_bits = g_init_bits);
            clear_flg = 0;
        } else {
            n_bits++;

            if ( n_bits == maxbits )
                maxcode = maxmaxcode;
            else
                maxcode = MAXCODE(n_bits);
        }
    }

    if (code == EOFCode) {
        /* At EOF, write the rest of the buffer */
        while( cur_bits > 0 ) {
            char_out( (int)((unsigned int)cur_accum & 0xff) );
            cur_accum >>= 8;
            cur_bits -= 8;
        }

        flush_char();
        fflush( g_outfile );

#ifdef FOO
        if(ferror( g_outfile))
            FatalError("unable to write GIF file");
#endif
    }
}
开发者ID:ArielleBassanelli,项目名称:gempak,代码行数:53,代码来源:hdfgifwr.c


示例2: output

static void output(int code, struct aap *a)
{
  a->cur_accum &= masks[a->cur_bits];

  if (a->cur_bits > 0)
    a->cur_accum |= ((long)code << a->cur_bits);
  else
    a->cur_accum = code;
	
  a->cur_bits += a->n_bits;

  while( a->cur_bits >= 8 ) {
    char_out( (int) (a->cur_accum & 0xff), a );
    a->cur_accum >>= 8;
    a->cur_bits -= 8;
  }

  /*
   * If the next entry is going to be too big for the code size,
   * then increase it, if possible.
   */

  if (a->free_ent > a->maxcode || a->clear_flg) {

    if( a->clear_flg ) {
      a->maxcode = MAXCODE (a->n_bits = a->g_init_bits);
      a->clear_flg = 0;
    }
    else {
      a->n_bits++;
      if ( a->n_bits == XV_BITS )
	a->maxcode = (1<<XV_BITS);
      else
	a->maxcode = MAXCODE(a->n_bits);
    }
  }
	
  if( code == a->EOFCode ) {
    /* At EOF, write the rest of the buffer */
    while( a->cur_bits > 0 ) {
      char_out( (int)(a->cur_accum & 0xff), a );
      a->cur_accum >>= 8;
      a->cur_bits -= 8;
    }

    flush_char(a);
	
    fflush( a->g_outfile );

  }
}
开发者ID:msabhijith,项目名称:dgate,代码行数:51,代码来源:xvgifwr.cpp


示例3: output

LOCAL void
output (gif_dest_ptr dinfo, code_int code)
/* Emit a code of n_bits bits */
/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */
{
  dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits;
  dinfo->cur_bits += dinfo->n_bits;

  while (dinfo->cur_bits >= 8) {
    CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
    dinfo->cur_accum >>= 8;
    dinfo->cur_bits -= 8;
  }

  /*
   * If the next entry is going to be too big for the code size,
   * then increase it, if possible.  We do this here to ensure
   * that it's done in sync with the decoder's codesize increases.
   */
  if (dinfo->free_code > dinfo->maxcode) {
    dinfo->n_bits++;
    if (dinfo->n_bits == MAX_LZW_BITS)
      dinfo->maxcode = LZW_TABLE_SIZE; /* free_code will never exceed this */
    else
      dinfo->maxcode = MAXCODE(dinfo->n_bits);
  }
}
开发者ID:F5000,项目名称:spree,代码行数:27,代码来源:wrgif.cpp


示例4: MAXCODE

int CsObjectInt::InitComp (BYTE_TYP * outbuf,
                     SAP_INT    outlen,
                     SAP_INT    sumlen)
/*--------------------------------------------------------------------*/
/* Setup header info                                                  */
/* Clear hash table                                                   */
/* Initialize static variables for compression                        */
/*--------------------------------------------------------------------*/
{
  if (outlen < CS_HEAD_SIZE)       /* too small ......................*/
    return CS_E_OUT_BUFFER_LEN;

  if (sumlen <= 0L)
    return CS_E_INVALID_SUMLEN;

  csc.clear_flg      = 0;              /* init compression states ........*/
  csc.ratio          = 0;

  csc.block_compress = BLOCK_MASK;
  csc.maxbits        = CS_BITS;

  csc.checkpoint     = CHECK_GAP;
  csc.maxcode        = MAXCODE (csc.n_bits = INIT_CS_BITS);
  csc.maxmaxcode     = (CODE_INT)1 << CS_BITS;
  csc.free_ent       = ((csc.block_compress) ? FIRST : 256);
  csc.hsize          = HSIZE;
  CL_HASH (csc.hsize);         /* clear hash table .......................*/
                           /* fill in header informations ............*/
  CsSetHead (outbuf, sumlen,
             (BYTE_TYP) ((CS_VERSION << 4) | CS_ALGORITHM),
             (BYTE_TYP) (csc.maxbits | csc.block_compress));

  return 0;
}
开发者ID:jcmuniz,项目名称:pysap,代码行数:34,代码来源:vpa106cslzc.cpp


示例5: while

//-----------------------------------------------------------------
// write an LZW code 
void mgLZWEncode::writeCode(
  mgLZWCode nCode)
{
  // Uses nCurAccum and nCurBits to reblock into 8-bit bytes
  m_curAccum |= ((long) nCode) << m_curBits;
  m_curBits += m_bits;

  while (m_curBits >= 8) 
  {
    writeLZWByte(m_curAccum & 0xFF);
    m_curAccum >>= 8;
    m_curBits -= 8;
  }

  // If the next entry is going to be too big for the code size,
  // then increase it, if possible.  We do this here to ensure
  // that it's done in sync with the decoder's codesize increases.

  if (m_freeCode > m_maxCode) 
  {
    m_bits++;
    if (m_bits == MAX_LZW_BITS)
      m_maxCode = LZW_TABLE_SIZE; // free_code will never exceed this
    else m_maxCode = MAXCODE(m_bits);
  }
}
开发者ID:Kelimion,项目名称:SeaOfMemes,代码行数:28,代码来源:mgLZW.cpp


示例6: LZWPreEncode

/*
 * Reset encoding state at the start of a strip.
 */
static int
LZWPreEncode(TIFF* tif, uint16 s)
{
	LZWCodecState *sp = EncoderState(tif);

	(void) s;
	assert(sp != NULL);

	if( sp->enc_hashtab == NULL )
        {
            tif->tif_setupencode( tif );
        }

	sp->lzw_nbits = BITS_MIN;
	sp->lzw_maxcode = MAXCODE(BITS_MIN);
	sp->lzw_free_ent = CODE_FIRST;
	sp->lzw_nextbits = 0;
	sp->lzw_nextdata = 0;
	sp->enc_checkpoint = CHECK_GAP;
	sp->enc_ratio = 0;
	sp->enc_incount = 0;
	sp->enc_outcount = 0;
	/*
	 * The 4 here insures there is space for 2 max-sized
	 * codes in LZWEncode and LZWPostDecode.
	 */
	sp->enc_rawlimit = tif->tif_rawdata + tif->tif_rawdatasize-1 - 4;
	cl_hash(sp);		/* clear hash table */
	sp->enc_oldcode = (hcode_t) -1;	/* generates CODE_CLEAR in LZWEncode */
	return (1);
}
开发者ID:cyberCBM,项目名称:DetectO,代码行数:34,代码来源:tif_lzw.c


示例7: clearHash

//-----------------------------------------------------------------
// reset compressor and issue a clear code
void mgLZWEncode::clearBlock()
{
  clearHash();			// delete all the symbols 

  m_freeCode = m_clearCode + 2;
  writeCode(m_clearCode);	// inform decoder 
  m_bits = m_initBits;	// reset code size 
  m_maxCode = MAXCODE(m_bits);
}
开发者ID:Kelimion,项目名称:SeaOfMemes,代码行数:11,代码来源:mgLZW.cpp


示例8: clear_block

clear_block (gif_dest_ptr dinfo)
/* Reset compressor and issue a Clear code */
{
  clear_hash(dinfo);			/* delete all the symbols */
  dinfo->free_code = dinfo->ClearCode + 2;
  output(dinfo, dinfo->ClearCode);	/* inform decoder */
  dinfo->n_bits = dinfo->init_bits;	/* reset code size */
  dinfo->maxcode = MAXCODE(dinfo->n_bits);
}
开发者ID:deepmatrix,项目名称:blaxxun-cc3d,代码行数:9,代码来源:wrgif.c


示例9: compress_init

compress_init (gif_dest_ptr dinfo, int i_bits)
{
  
  dinfo->n_bits = i_bits;
  dinfo->maxcode = MAXCODE(dinfo->n_bits);
  dinfo->ClearCode = (1 << (i_bits - 1));
  dinfo->EOFCode = dinfo->ClearCode + 1;
  dinfo->code_counter = dinfo->ClearCode + 2;
  
  dinfo->bytesinpkt = 0;
  dinfo->cur_accum = 0;
  dinfo->cur_bits = 0;
  
  output(dinfo, dinfo->ClearCode);
}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:15,代码来源:wrgif.c


示例10: compress_init

compress_init (gif_dest_ptr dinfo, int i_bits)
/* Initialize pseudo-compressor */
{
  /* init all the state variables */
  dinfo->n_bits = i_bits;
  dinfo->maxcode = MAXCODE(dinfo->n_bits);
  dinfo->ClearCode = (1 << (i_bits - 1));
  dinfo->EOFCode = dinfo->ClearCode + 1;
  dinfo->code_counter = dinfo->ClearCode + 2;
  /* init output buffering vars */
  dinfo->bytesinpkt = 0;
  dinfo->cur_accum = 0;
  dinfo->cur_bits = 0;
  /* GIF specifies an initial Clear code */
  output(dinfo, dinfo->ClearCode);
}
开发者ID:DankRank,项目名称:rom-properties,代码行数:16,代码来源:wrgif.c


示例11: MAXCODE

//-----------------------------------------------------------------
// constructor
mgLZWEncode::mgLZWEncode()
{
  m_hashCode = new mgLZWCode[HASH_SIZE];
  m_hashValue = new mgLZWHash[HASH_SIZE];

  // init all the state variables
  m_bits = m_initBits = 9;  // data size + 1
  m_maxCode = MAXCODE(m_bits);
  m_clearCode = ((mgLZWCode) 1 << (m_initBits - 1));
  m_EOFCode = m_clearCode + 1;
  m_freeCode = m_clearCode + 2;
  m_firstByte = TRUE;	// no waiting symbol yet

  // init output buffering vars
  m_curAccum = 0;
  m_curBits = 0;

  clearHash();        // clear hash table
}
开发者ID:Kelimion,项目名称:SeaOfMemes,代码行数:21,代码来源:mgLZW.cpp


示例12: compress_init

compress_init (gif_dest_ptr dinfo, int i_bits)
/* Initialize LZW compressor */
{
  /* init all the state variables */
  dinfo->n_bits = dinfo->init_bits = i_bits;
  dinfo->maxcode = MAXCODE(dinfo->n_bits);
  dinfo->ClearCode = ((code_int) 1 << (i_bits - 1));
  dinfo->EOFCode = dinfo->ClearCode + 1;
  dinfo->free_code = dinfo->ClearCode + 2;
  dinfo->first_byte = TRUE;	/* no waiting symbol yet */
  /* init output buffering vars */
  dinfo->bytesinpkt = 0;
  dinfo->cur_accum = 0;
  dinfo->cur_bits = 0;
  /* clear hash table */
  clear_hash(dinfo);
  /* GIF specifies an initial Clear code */
  output(dinfo, dinfo->ClearCode);
}
开发者ID:deepmatrix,项目名称:blaxxun-cc3d,代码行数:19,代码来源:wrgif.c


示例13: lzwInit

int lzwInit(lzw_streamp strm)
{
    struct lzw_internal_state *state;
    hcode_t code;

    state = cli_malloc(sizeof(struct lzw_internal_state));
    if (state == NULL) {
        strm->msg = "failed to allocate state";
        return LZW_MEM_ERROR;
    }

    /* general state setup */
    state->nbits = BITS_MIN;
    state->nextdata = 0;
    state->nextbits = 0;

    /* dictionary setup */
    state->dec_codetab = cli_calloc(CSIZE, sizeof(code_t));
    if (state->dec_codetab == NULL) {
        free(state);
        strm->msg = "failed to allocate code table";
        return LZW_MEM_ERROR;
    }

    for (code = 0; code < CODE_BASIC; code++) {
        state->dec_codetab[code].next = NULL;
        state->dec_codetab[code].length = 1;
        state->dec_codetab[code].value = code;
        state->dec_codetab[code].firstchar = code;
    }

    state->dec_restart = 0;
    state->dec_nbitsmask = MAXCODE(BITS_MIN);
    state->dec_free_entp = state->dec_codetab + CODE_FIRST;
    state->dec_oldcodep = &state->dec_codetab[CODE_CLEAR];
    state->dec_maxcodep = &state->dec_codetab[state->dec_nbitsmask-1];

    strm->state = state;
    return LZW_OK;
}
开发者ID:chushuai,项目名称:clamav-devel,代码行数:40,代码来源:lzwdec.c


示例14: compress

static void compress(int init_bits, FILE *outfile, byte *data, int len)
{
    register long fcode;
    register int i = 0;
    register int c;
    register int ent;
    register int disp;
    register int hsize_reg;
    register int hshift;

    /*
     * Set up the globals:  g_init_bits - initial number of bits g_outfile -
     * pointer to output file
     */
    g_init_bits = init_bits;
    g_outfile   = outfile;

    /* initialize 'compress' globals */
    maxbits = XV_BITS;
    maxmaxcode = 1<<XV_BITS;
    memset(htab, 0, sizeof(htab));
    memset(codetab, 0, sizeof(codetab));
    hsize = HSIZE;
    free_ent = 0;
    clear_flg = 0;
    in_count = 1;
    out_count = 0;
    cur_accum = 0;
    cur_bits = 0;

    /* Set up the necessary values */
    out_count = 0;
    clear_flg = 0;
    in_count = 1;
    maxcode = MAXCODE(n_bits = g_init_bits);

    ClearCode = (1 << (init_bits - 1));
    EOFCode = ClearCode + 1;
    free_ent = ClearCode + 2;

    char_init();
    ent = pc2nc[*data++];
    len--;

    hshift = 0;
    for (fcode = (long)hsize; fcode < 65536L; fcode *= 2L )
        hshift++;

    hshift = 8 - hshift; /* set hash code range bound */

    hsize_reg = hsize;
    cl_hash( (count_int) hsize_reg); /* clear hash table */

    output(ClearCode);

    while (len) {
        c = pc2nc[*data++];
        len--;
        in_count++;

        fcode = (long)(((long) c << maxbits) + ent);
        i = (((int) c << hshift) ^ ent);    /* xor hashing */

        if ( HashTabOf (i) == fcode ) {
            ent = CodeTabOf (i);
            continue;
        } else if ( (long)HashTabOf (i) < 0) {
            /* empty slot */
            goto nomatch;
        }

        disp = hsize_reg - i;   /* secondary hash (after G. Knott) */

        if ( i == 0 )
            disp = 1;

probe:
        if ((i -= disp) < 0)
            i += hsize_reg;

        if (HashTabOf (i) == fcode) {
            ent = CodeTabOf (i);
            continue;
        }

        if ((long)HashTabOf (i) >= 0)
            goto probe;

nomatch:
        output(ent);
        out_count++;
        ent = c;

        if (free_ent < maxmaxcode) {
            CodeTabOf (i) = free_ent++; /* code -> hashtable */
            HashTabOf (i) = fcode;
        } else {
            cl_block();
        }
    }
//.........这里部分代码省略.........
开发者ID:ArielleBassanelli,项目名称:gempak,代码行数:101,代码来源:hdfgifwr.c


示例15: LZWDecodeCompat

static int
LZWDecodeCompat(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s)
{
	LZWCodecState *sp = DecoderState(tif);
	char *op = (char*) op0;
	long occ = (long) occ0;
	char *tp;
	u_char *bp;
	int code, nbits;
	long nextbits, nextdata, nbitsmask;
	code_t *codep, *free_entp, *maxcodep, *oldcodep;

	(void) s;
	assert(sp != NULL);
	/*
	 * Restart interrupted output operation.
	 */
	if (sp->dec_restart) {
		long residue;

		codep = sp->dec_codep;
		residue = codep->length - sp->dec_restart;
		if (residue > occ) {
			/*
			 * Residue from previous decode is sufficient
			 * to satisfy decode request.  Skip to the
			 * start of the decoded string, place decoded
			 * values in the output buffer, and return.
			 */
			sp->dec_restart += occ;
			do {
				codep = codep->next;
			} while (--residue > occ);
			tp = op + occ;
			do {
				*--tp = codep->value;
				codep = codep->next;
			} while (--occ);
			return (1);
		}
		/*
		 * Residue satisfies only part of the decode request.
		 */
		op += residue, occ -= residue;
		tp = op;
		do {
			*--tp = codep->value;
			codep = codep->next;
		} while (--residue);
		sp->dec_restart = 0;
	}

	bp = (u_char *)tif->tif_rawcp;
	nbits = sp->lzw_nbits;
	nextdata = sp->lzw_nextdata;
	nextbits = sp->lzw_nextbits;
	nbitsmask = sp->dec_nbitsmask;
	oldcodep = sp->dec_oldcodep;
	free_entp = sp->dec_free_entp;
	maxcodep = sp->dec_maxcodep;

	while (occ > 0) {
		NextCode(tif, sp, bp, code, GetNextCodeCompat);
		if (code == CODE_EOI)
			break;
		if (code == CODE_CLEAR) {
			free_entp = sp->dec_codetab + CODE_FIRST;
			nbits = BITS_MIN;
			nbitsmask = MAXCODE(BITS_MIN);
			maxcodep = sp->dec_codetab + nbitsmask;
			NextCode(tif, sp, bp, code, GetNextCodeCompat);
			if (code == CODE_EOI)
				break;
			*op++ = (char) code, occ--;
			oldcodep = sp->dec_codetab + code;
			continue;
		}
		codep = sp->dec_codetab + code;

		/*
	 	 * Add the new entry to the code table.
	 	 */
		if (free_entp < &sp->dec_codetab[0] ||
			free_entp >= &sp->dec_codetab[CSIZE]) {
			TIFFError(tif->tif_name,
			"LZWDecodeCompat: Corrupted LZW table at scanline %d",
			tif->tif_row);
			return (0);
		}

		free_entp->next = oldcodep;
		if (free_entp->next < &sp->dec_codetab[0] ||
			free_entp->next >= &sp->dec_codetab[CSIZE]) {
			TIFFError(tif->tif_name,
			"LZWDecodeCompat: Corrupted LZW table at scanline %d",
			tif->tif_row);
			return (0);
		}
		free_entp->firstchar = free_entp->next->firstchar;
		free_entp->length = free_entp->next->length+1;
//.........这里部分代码省略.........
开发者ID:AlexHayton,项目名称:decoda,代码行数:101,代码来源:tif_lzw.c


示例16: compress

static void
compress(
	int init_bits,
	FILE *outfile,
	ifun_t* ReadValue
)
{
    register long fcode;
    register code_int i = 0;
    register int c;
    register code_int ent;
    register code_int disp;
    register code_int hsize_reg;
    register int hshift;

    /*
     * Set up the globals:  g_init_bits - initial number of bits
     *                      g_outfile   - pointer to output file
     */
    g_init_bits = init_bits;
    g_outfile = outfile;
    /*
     * Set up the necessary values
     */
    offset = 0;
    out_count = 0;
    clear_flg = 0;
    in_count = 1;
    maxcode = MAXCODE(n_bits = g_init_bits);
    ClearCode = (1 << (init_bits - 1));
    EOFCode = ClearCode + 1;
    free_ent = ClearCode + 2;
    char_init();
    ent = GIFNextPixel( ReadValue );
    hshift = 0;
    for ( fcode = (long) hsize;  fcode < 65536L; fcode *= 2L )
        hshift++;
    hshift = 8 - hshift;                /* set hash code range bound */
    hsize_reg = hsize;
    cl_hash( (count_int) hsize_reg);            /* clear hash table */
    output( (code_int)ClearCode );
    while ( (c = GIFNextPixel( ReadValue )) != EOF ) {
        in_count++;
        fcode = (long) (((long) c << maxbits) + ent);
        /* i = (((code_int)c << hshift) ~ ent); */   /* xor hashing */
        i = (((code_int)c << hshift) ^ ent);    /* xor hashing */
        if ( HashTabOf (i) == fcode ) {
            ent = CodeTabOf (i);
            continue;
        } else if ( (long)HashTabOf (i) < 0 )      /* empty slot */
            goto nomatch;
        disp = hsize_reg - i;           /* secondary hash (after G. Knott) */
        if ( i == 0 )
            disp = 1;
probe:
        if ( (i -= disp) < 0 )
            i += hsize_reg;
        if ( HashTabOf (i) == fcode ) {
            ent = CodeTabOf (i);
            continue;
        }
        if ( (long)HashTabOf (i) > 0 )
            goto probe;
nomatch:
        output ( (code_int) ent );
        out_count++;
        ent = c;
        if ( free_ent < maxmaxcode ) {
            CodeTabOf (i) = free_ent++; /* code -> hashtable */
            HashTabOf (i) = fcode;
        } else
                cl_block();
    }
    /*
     * Put out the final code.
     */
    output( (code_int)ent );
    out_count++;
    output( (code_int) EOFCode );
    return;
}
开发者ID:MITSustainableDesignLab,项目名称:Daysim,代码行数:81,代码来源:ra_gif.c


示例17: decrunch_compress

int decrunch_compress(xmp_file in, xmp_file out)
{
	char_type *stackp;
	code_int code;
	int finchar;
	code_int oldcode;
	code_int incode;
	int inbits;
	int posbits;
	int outpos;
	int insize;
	int bitmask;
	code_int free_ent;
	code_int maxcode;
	code_int maxmaxcode;
	int n_bits;
	int rsize;
	int maxbits;
	int block_mode;
	int i;

	long bytes_in;			/* Total number of byte from input */
	long bytes_out;			/* Total number of byte to output */
	char_type inbuf[IBUFSIZ + 64];	/* Input buffer */
	char_type outbuf[OBUFSIZ + 2048];/* Output buffer */
	count_int htab[HSIZE];
	unsigned short codetab[HSIZE];

	bytes_in = 0;
	bytes_out = 0;
	insize = 0;

	rsize = xmp_fread(inbuf, 1, IBUFSIZ, in);
	insize += rsize;

	if (insize < 3 || inbuf[0] != MAGIC_1 || inbuf[1] != MAGIC_2) {
		return -1;
	}

	maxbits = inbuf[2] & BIT_MASK;
	block_mode = inbuf[2] & BLOCK_MODE;
	maxmaxcode = MAXCODE(maxbits);

	if (maxbits > BITS) {
		/*fprintf(stderr,
		   "%s: compressed with %d bits, can only handle %d bits\n",
		   (*ifname != '\0' ? ifname : "stdin"), maxbits, BITS);
		   exit_code = 4; */
		return -1;
	}

	bytes_in = insize;
	maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
	bitmask = (1 << n_bits) - 1;
	oldcode = -1;
	finchar = 0;
	outpos = 0;
	posbits = 3 << 3;

	free_ent = ((block_mode) ? FIRST : 256);

	clear_tab_prefixof();	/* As above, initialize the first
				   256 entries in the table. */

	for (code = 255; code >= 0; --code)
		tab_suffixof(code) = (char_type) code;

	do {
	      resetbuf:;
		{
			int i;
			int e;
			int o;

			o = posbits >> 3;
			e = o <= insize ? insize - o : 0;

			for (i = 0; i < e; ++i)
				inbuf[i] = inbuf[i + o];

			insize = e;
			posbits = 0;
		}

		if (insize < sizeof(inbuf) - IBUFSIZ) {
			if ((rsize = xmp_fread(inbuf + insize, 1, IBUFSIZ, in)) < 0)
				return -1;

			insize += rsize;
		}

		inbits = ((rsize > 0) ? (insize - insize % n_bits) << 3 :
			  (insize << 3) - (n_bits - 1));

		while (inbits > posbits) {
			if (free_ent > maxcode) {
				posbits = ((posbits - 1) + ((n_bits << 3) -
							    (posbits - 1 +
							     (n_bits << 3)) %
							    (n_bits << 3)));
//.........这里部分代码省略.........
开发者ID:bithorder,项目名称:libxmp,代码行数:101,代码来源:uncompress.c


示例18: compress

void 
compress(void)
{
	register long   fcode;
	register code_int i = 0;
	register int    c;
	register code_int ent;
	register int    disp;
	register code_int hsize_reg;
	register int    hshift;


	offset = 0;
	bytes_out = 3;		/* includes 3-byte header mojo */
	out_count = 0;
	clear_flg = 0;
	ratio = 0;
	in_count = 1;
	checkpoint = CHECK_GAP;
	maxcode = MAXCODE(n_bits = INIT_BITS);
	free_ent = ((block_compress) ? (FIRST) : (256));

	ent = getbyte();

	hshift = 0;
	for (fcode = (long) hsize; fcode < 65536L; fcode *= 2L) {
		hshift++;
	}

	hshift = 8 - hshift;	/* set hash code range bound */

	hsize_reg = hsize;
	cl_hash((count_int) hsize_reg);	/* clear hash table */


	while (InCnt > 0) {	/* apsim_loop 11 0 */
		int             apsim_bound111 = 0;

		c = getbyte();	/* decrements InCnt */

		in_count++;
		fcode = (long) (((long) c << maxbits) + ent);
		i = ((c << hshift) ^ ent);	/* xor hashing */

		if (htabof(i) == fcode) {
			ent = codetabof(i);
			continue;
		} else if ((long) htabof(i) < 0) {	/* empty slot */
			goto nomatch;
		}
		disp = hsize_reg - i;	/* secondary hash (after G. Knott) */
		if (i == 0) {
			disp = 1;
		}
probe:

		if ((i -= disp) < 0) {	/* apsim_loop 111 11 */
			i += hsize_reg;
		}
		if (htabof(i) == fcode) {
			ent = codetabof(i);
			continue;
		}
		if ((long) htabof(i) > 0 && (++apsim_bound111 < in_count))
			goto probe;
nomatch:

		out_count++;
		ent = c;
		if (free_ent < maxmaxcode) {
			codetabof(i) = free_ent++;	/* apsim_unknown codetab */
			htabof(i) = fcode;	/* apsim_unknown htab */
		} else if (((count_int) in_count >= checkpoint) && (block_compress)) {
			cl_block();
		}
	}
	if (bytes_out > in_count) {	/* exit(2) if no savings */
		exit_stat = 2;
	}
	return;
}
开发者ID:alexjordan,项目名称:patmos-benchmarks,代码行数:81,代码来源:compress.c


示例19: memset

/*
 * Open LZW file
 */
hidden_in_another_lib
lzwFile *lzw_fdopen(int fd)
{
	lzwFile *ret;
	unsigned char buf[3];

	if (read(fd, buf, 3) != 3)
		goto err_out;

	if (buf[0] != LZW_MAGIC_1 || buf[1] != LZW_MAGIC_2 || buf[2] & 0x60)
		goto err_out;

	if ((ret = malloc(sizeof(*ret))) == NULL)
		goto err_out;

	memset(ret, 0x00, sizeof(*ret));
	ret->fd = fd;
	ret->eof = 0;
	ret->inbuf = malloc(sizeof(unsigned char) * IN_BUFSIZE);
	ret->outbuf = malloc(sizeof(unsigned char) * OUT_BUFSIZE);
	ret->stackp = NULL;
	ret->insize = 3; /* we read three bytes above */
	ret->outpos = 0;
	ret->rsize = 0;

	ret->flags = buf[2];
	ret->maxbits = ret->flags & 0x1f;    /* Mask for 'number of compresssion bits' */
	ret->block_mode = ret->flags & 0x80;

	ret->n_bits = INIT_BITS;
	ret->maxcode = MAXCODE(INIT_BITS) - 1;
	ret->bitmask = (1<<INIT_BITS)-1;
	ret->oldcode = -1;
	ret->finchar = 0;
	ret->posbits = 3<<3;
	ret->free_ent = ((ret->block_mode) ? FIRST : 256);

	/* initialize the first 256 entries in the table */
	memset(ret->codetab, 0x00, sizeof(ret->codetab));
	for (ret->code = 255; ret->code >= 0; --ret->code)
		ret->htab[ret->code] = ret->code;

	if (ret->inbuf == NULL || ret->outbuf == NULL) {
		errno = ENOMEM;
		goto err_out_free;
	}
	if (ret->maxbits > BITS) {
		errno = EINVAL;
		goto err_out_free;
	}

	return ret;

err_out:
	errno = EINVAL;
	return NULL;

err_out_free:
	if (ret->inbuf) free(ret->inbuf);
	if (ret->outbuf) free(ret->outbuf);
	free(ret);
	return NULL;
}
开发者ID:bindle,项目名称:securecoreutils,代码行数:66,代码来源:lzw.c


示例20: compress

static void
compress(int init_bits, gdIOCtxPtr outfile, gdImagePtr im, GifCtx *ctx)
{
    register long fcode;
    register code_int i /* = 0 */;
    register int c;
    register code_int ent;
    register code_int disp;
    register code_int hsize_reg;
    register int hshift;

    /*
     * Set up the globals:  g_init_bits - initial number of bits
     *                      g_outfile   - pointer to output file
     */
    ctx->g_init_bits = init_bits;
    ctx->g_outfile = outfile;

    /*
     * Set up the necessary values
     */
    ctx->offset = 0;
    ctx->out_count = 0;
    ctx->clear_flg = 0;
    ctx->in_count = 1;
    ctx->maxcode = MAXCODE(ctx->n_bits = ctx->g_init_bits);

    ctx->ClearCode = (1 << (init_bits - 1));
    ctx->EOFCode = ctx->ClearCode + 1;
    ctx->free_ent = ctx->ClearCode + 2;

    char_init(ctx);

    ent = GIFNextPixel( im, ctx );

    hshift = 0;
    for ( fcode = (long) hsize;  fcode < 65536L; fcode *= 2L )
        ++hshift;
    hshift = 8 - hshift;                /* set hash code range bound */

    hsize_reg = hsize;
    cl_hash( (count_int) hsize_reg, ctx );            /* clear hash table */

    output( (code_int)ctx->ClearCode, ctx );

#ifdef SIGNED_COMPARE_SLOW
    while ( (c = GIFNextPixel( im )) != (unsigned) EOF ) {
#else /*SIGNED_COMPARE_SLOW*/
    while ( (c = GIFNextPixel( im, ctx )) != EOF ) {  /* } */
#endif /*SIGNED_COMPARE_SLOW*/

        ++(ctx->in_count);

        fcode = (long) (((long) c << maxbits) + ent);
        i = (((code_int)c << hshift) ^ ent);    /* xor hashing */

        if ( HashTabOf (i) == fcode ) {
            ent = CodeTabOf (i);
            continue;
        } else if ( (long)HashTabOf (i) < 0 )      /* empty slot */
            goto nomatch;
        disp = hsize_reg - i;           /* secondary hash (after G. Knott) */
        if ( i == 0 )
            disp = 1;
probe:
        if ( (i -= disp) < 0 )
            i += hsize_reg;

        if ( HashTabOf (i) == fcode ) {
            ent = CodeTabOf (i);
            continue;
        }
        if ( (long)HashTabOf (i) > 0 )
            goto probe;
nomatch:
        output ( (code_int) ent, ctx );
        ++(ctx->out_count);
        ent = c;
#ifdef SIGNED_COMPARE_SLOW
        if ( (unsigned) ctx->free_ent < (unsigned) maxmaxcode) {
#else /*SIGNED_COMPARE_SLOW*/
        if ( ctx->free_ent < maxmaxcode ) {  /* } */
#endif /*SIGNED_COMPARE_SLOW*/
            CodeTabOf (i) = ctx->free_ent++; /* code -> hashtable */
            HashTabOf (i) = fcode;
        } else
                cl_block(ctx);
    }
    /*
     * Put out the final code.
     */
    output( (code_int)ent, ctx );
    ++(ctx->out_count);
    output( (code_int) ctx->EOFCode, ctx );
}

/*****************************************************************
 * TAG( output )
 *
 * Output the given code.
//.........这里部分代码省略.........
开发者ID:KonstantinKuklin,项目名称:php-src,代码行数:101,代码来源:gd_gif_out.c



注:本文中的MAXCODE函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ MAYBE_LOCK函数代码示例发布时间:2022-05-30
下一篇:
C++ MAX3函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap