void pushcontrol3b(int cc) { pushbit(cc%2) ; cc >>= 1 ; pushbit(cc%2) ; cc >>= 1 ; pushbit(cc) ; }
static dsk_err_t huf_encode(SQ_COMPRESS_DATA *self, int ch) { unsigned short nodepos; signed short child; if (ch < 0 || ch > SQ_EOF) return DSK_ERR_COMPRESS; /* Now find where this character ended up in the tree */ nodepos = self->huf_leaves[ch]; self->huf_nbits = 0; child = (-1 - ch); do { if (self->huf_node[nodepos].left == child) pushbit(self, 0); else if (self->huf_node[nodepos].right == child) pushbit(self, 1); else return DSK_ERR_COMPRESS; child = nodepos; nodepos = self->huf_node[nodepos].parent; } while (nodepos < MAXNODE); /* self->huf_bits holds the output bitstream (in reverse order). * Now write it out to disc */ return flipbits(self); }
static int encode(struct rubin_state *rs, long A, long B, int symbol) { long i0, i1; int ret; while ((rs->q >= UPPER_BIT_RUBIN) || ((rs->p + rs->q) <= UPPER_BIT_RUBIN)) { rs->bit_number++; ret = pushbit(&rs->pp, (rs->q & UPPER_BIT_RUBIN) ? 1 : 0, 0); if (ret) return ret; rs->q &= LOWER_BITS_RUBIN; rs->q <<= 1; rs->p <<= 1; } i0 = A * rs->p / (A + B); if (i0 <= 0) { i0 = 1; } if (i0 >= rs->p) { i0 = rs->p - 1; } i1 = rs->p - i0; if (symbol == 0) rs->p = i0; else { rs->p = i1; rs->q += i0; } return 0; }
static void end_rubin(struct rubin_state *rs) { int i; for (i = 0; i < RUBIN_REG_SIZE; i++) { pushbit(&rs->pp, (UPPER_BIT_RUBIN & rs->q) ? 1 : 0, 1); rs->q &= LOWER_BITS_RUBIN; rs->q <<= 1; } }
void pushcontrol1b(int cc) { pushbit(cc) ; }