/* Send the header for a block using dynamic Huffman trees: the counts, the * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ void CodeTree::send_all_trees(int lcodes, int dcodes, int blcodes) { int rank; /* index in bl_order */ assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4); assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES); // Tracev((stderr, "\nbl counts: ")); send_bits(lcodes-257, 5); /* not +255 as stated in appnote.txt 1.93a or -256 in 2.04c */ send_bits(dcodes-1, 5); /* not -3 as stated in appnote.txt */ send_bits(blcodes-4, 4); for (rank = 0; rank < blcodes; rank++) { // Tracev((stderr, "\nbl code %2d ", bl_order[rank])); send_bits(bl_tree[bl_order[rank]].Len, 3); } // Tracev((stderr, "\nbl tree: sent %ld", bits_sent)); /* send the literal tree */ send_tree(dyn_ltree, lcodes-1); // Tracev((stderr, "\nlit tree: sent %ld", bits_sent)); /* send the distance tree */ send_tree(dyn_dtree, dcodes-1); // Tracev((stderr, "\ndist tree: sent %ld", bits_sent)); }
void ZipDeflate::compress_block(zip_ct_data* ltree, zip_ct_data* dtree) { UINT dist, lx(0), code; int lc, extra; if(last_lit) do { dist = d_buf[lx]; lc = l_buf[lx++]; if(dist == 0) { send_code(lc, ltree); } else { code = _length_code[lc]; send_code(code + LITERALS + 1, ltree); extra = extra_lbits[code]; if(extra) {lc -= base_length[code]; send_bits(lc, extra);} dist--; code = d_code(dist); send_code(code, dtree); extra = extra_dbits[code]; if(extra) {dist -= base_dist[code]; send_bits(dist, extra);} } } while(lx < last_lit); send_code(END_BLOCK, ltree); }
static void issp_write_byte(struct issp_host *host, uint8_t addr, uint8_t data) { uint8_t address = addr << 1; send_bits(host, vec_write_byte_start, bits_write_byte_start); send_bits(host, &address, 7); send_bits(host, &data, 8); send_bits(host, vec_write_byte_end, bits_write_byte_end); }
static int issp_verify_security(struct issp_host *host) { uint8_t addr = 0; int ret = 0; send_vector(host, vec_read_security_setup, bits_read_security_setup); while (addr < host->pdata->security_size) { uint8_t address = addr << 1; addr++; send_vector(host, vec_sync_enable, bits_sync_enable); send_vector(host, vec_read_security_pt1, bits_read_security_pt1); pin_data_out(host); send_bits(host, &address, 7); send_vector(host, vec_read_security_pt1_end, bits_read_security_pt1_end); send_vector(host, vec_sync_disable, bits_sync_disable); send_vector(host, vec_read_security_pt2, bits_read_security_pt2); send_vector(host, vec_wait_and_poll, bits_wait_and_poll); send_vector(host, vec_read_security_pt3, bits_read_security_pt3); pin_data_out(host); send_bits(host, &address, 7); send_vector(host, vec_read_security_pt3_end, bits_read_security_pt3_end); send_vector(host, vec_wait_and_poll, bits_wait_and_poll); } addr = 0; send_vector(host, vec_sync_enable, bits_sync_enable); while (addr < host->pdata->security_size) { uint8_t data = issp_read_byte_at(host, addr++); if (data != issp_fw_get_byte(host)) { dev_err(&host->pdev->dev, "Data compare failed!\n"); ret = -EIO; break; } } send_vector(host, vec_sync_disable, bits_sync_disable); return ret; }
int register_device(struct options *opt, int fd) { struct uinput_user_dev uinput_dev = { 0 }; int rc = 0; char *domain_name = NULL; if (!rc) rc = send_bits(fd, UI_SET_EVBIT, opt->caps.evbit, EV_CNT); if (!rc && LONG_TEST_BIT(opt->caps.evbit, EV_KEY)) rc = send_bits(fd, UI_SET_KEYBIT, opt->caps.keybit, KEY_CNT); if (!rc && LONG_TEST_BIT(opt->caps.evbit, EV_REL)) rc = send_bits(fd, UI_SET_RELBIT, opt->caps.relbit, REL_CNT); if (!rc && LONG_TEST_BIT(opt->caps.evbit, EV_ABS)) rc = send_bits(fd, UI_SET_ABSBIT, opt->caps.absbit, ABS_CNT); if (!rc && LONG_TEST_BIT(opt->caps.evbit, EV_MSC)) rc = send_bits(fd, UI_SET_MSCBIT, opt->caps.mscbit, MSC_CNT); if (!rc && LONG_TEST_BIT(opt->caps.evbit, EV_LED)) rc = send_bits(fd, UI_SET_LEDBIT, opt->caps.ledbit, LED_CNT); if (!rc && LONG_TEST_BIT(opt->caps.evbit, EV_SND)) rc = send_bits(fd, UI_SET_SNDBIT, opt->caps.sndbit, SND_CNT); if (!rc && LONG_TEST_BIT(opt->caps.evbit, EV_FF)) rc = send_bits(fd, UI_SET_FFBIT, opt->caps.ffbit, FF_CNT); if (!rc && LONG_TEST_BIT(opt->caps.evbit, EV_SW)) rc = send_bits(fd, UI_SET_SWBIT, opt->caps.swbit, SW_CNT); if (rc == -1) { close(fd); return -1; } if (!opt->name) opt->name = "Forwarded input device"; domain_name = getenv("QREXEC_REMOTE_DOMAIN"); if (domain_name) { snprintf(uinput_dev.name, UINPUT_MAX_NAME_SIZE, "%s: %s", domain_name, opt->name); /* make sure string is terminated, in case it was truncated */ uinput_dev.name[UINPUT_MAX_NAME_SIZE-1] = 0; } else { strncpy(uinput_dev.name, opt->name, UINPUT_MAX_NAME_SIZE); } uinput_dev.id.bustype = BUS_USB; uinput_dev.id.vendor = opt->vendor; uinput_dev.id.product = opt->product; uinput_dev.id.version = 1; /* TODO: support for uinput_dev.abs(min|max) */ if (write_all(fd, &uinput_dev, sizeof(uinput_dev)) == -1) { return -1; } if (ioctl(fd, UI_DEV_CREATE) == -1) { perror("ioctl dev create"); return -1; } return 0; }
/* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static * trees or store, and output the encoded block to the zip file. This function * returns the total compressed length (in bytes) for the file so far. */ u32 flush_block(char *buf, u32 stored_len, int eof) //char *buf; /* input block, or NULL if too old */ //u32 stored_len; /* length of input block */ //int eof; /* true if this is the last block for a file */ { u32 opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex; /* index of last bit length code of non zero freq */ flag_buf[last_flags] = flags; /* Save the flags for the last 8 items */ /* Construct the literal and distance trees */ build_tree((tree_desc near *)(&l_desc)); build_tree((tree_desc near *)(&d_desc)); /* At this point, opt_len and static_len are the total bit lengths of * the compressed block data, excluding the tree representations. */ /* Build the bit length tree for the above two trees, and get the index * in bl_order of the last bit length code to send. */ max_blindex = build_bl_tree(); /* Determine the best encoding. Compute first the block length in bytes */ opt_lenb = (opt_len+3+7)>>3; static_lenb = (static_len+3+7)>>3; #ifdef _DEBUG input_len += stored_len; /* for debugging only */ #endif if (static_lenb <= opt_lenb) opt_lenb = static_lenb; /* If compression failed and this is the first and last block, * the whole file is transformed into a stored file: */ if (stored_len <= opt_lenb && eof && file_method != NULL && cmpr_bytelen == 0L && cmpr_len_bits == 0L) { /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ if (buf == NULL) error ("block vanished"); copy_block(buf, (unsigned)stored_len, 0); /* without header */ cmpr_bytelen = stored_len; *file_method = compStore; } else if (stored_len+4 <= opt_lenb && buf != (char*)NULL) { /* 4: two words for the lengths * /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. * Otherwise we can't have processed more than WSIZE input bytes since * the last block flush, because compression would have been * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to * transform a block into a stored block. */ send_bits((STORED_BLOCK<<1)+eof, 3); /* send block type */ cmpr_bytelen += ((cmpr_len_bits + 3 + 7) >> 3) + stored_len + 4; cmpr_len_bits = 0L; copy_block(buf, (unsigned)stored_len, 1); /* with header */ } else if (static_lenb == opt_lenb) {
static void send_all_trees( z_stream& s, int lcodes, int dcodes, int blcodes ) { send_bits( s, lcodes - 257, 5 ); send_bits( s, dcodes - 1, 5 ); send_bits( s, blcodes - 4, 4 ); for( int rank = 0 ; rank < blcodes ; rank++ ) send_bits( s, s.bl_tree[ bl_order[ rank ] ].Len, 3 ); send_tree( s, (ct_data*) s.dyn_ltree, lcodes - 1 ); send_tree( s, (ct_data*) s.dyn_dtree, dcodes - 1 ); }
/* Send a literal or distance tree in compressed form, using the codes in bl_tree. */ void CodeTree::send_tree (ct_data *tree, int max_code) { int n; /* iterates over all tree elements */ int prevlen = -1; /* last emitted length */ int curlen; /* length of current code */ int nextlen = tree[0].Len; /* length of next code */ int count = 0; /* repeat count of the current code */ int max_count = 7; /* max repeat count */ int min_count = 4; /* min repeat count */ /* tree[max_code+1].Len = -1; */ /* guard already set */ if (nextlen == 0) max_count = 138, min_count = 3; for (n = 0; n <= max_code; n++) { curlen = nextlen; nextlen = tree[n+1].Len; if (++count < max_count && curlen == nextlen) { continue; } else if (count < min_count) { do { send_code(curlen, bl_tree); } while (--count != 0); } else if (curlen != 0) { if (curlen != prevlen) { send_code(curlen, bl_tree); count--; } assert(count >= 3 && count <= 6); send_code(REP_3_6, bl_tree); send_bits(count-3, 2); } else if (count <= 10) { send_code(REPZ_3_10, bl_tree); send_bits(count-3, 3); } else { send_code(REPZ_11_138, bl_tree); send_bits(count-11, 7); } count = 0; prevlen = curlen; if (nextlen == 0) { max_count = 138, min_count = 3; } else if (curlen == nextlen) { max_count = 6, min_count = 3; } else { max_count = 7, min_count = 4; } } }
void _tr_stored_block( z_stream& s, char* buf, size_t stored_len, int last ) { send_bits( s, ( STORED_BLOCK << 1 ) + last, 3 ); copy_block( s, buf, stored_len, 1 ); }
int main( int argc, char *argv[]) { #define W 40 #define H 40 #define X 100 #define Y 100 #define ADDR "127.0.0.1" #define PORT 12345 pixel_t *dest = NULL; int size; int x = X; int y = Y; int w = W; int h = H; SOCKET sock; int port = PORT; char *addr = ADDR; int arg = 1; if (argc > arg) { addr = argv[arg++]; } sock = create_sock( port, addr); size = sizeof(*dest) * w * h; dest = malloc( sizeof( *dest) * w * h); int frame = 0; while (1) { get_bits( x, y, w, h, dest); #if 0 int i, j; printf( "about to send frame %d, dims=%dx%d :\n", frame, w, h); for (j = 0; j < h; j++) { for (i = 0; i < w; i++) { printf( " %02X:%02X:%02X", dest[j * w + i].r, dest[j * w + i].g, dest[j * w + i].b); } printf( "\n"); } #endif send_bits( sock, dest, size, w, h, frame++); #ifdef _WIN32 Sleep( 900); #else usleep( 900000); #endif } return 0; }
/* =========================================================================== * Send the header for a block using dynamic Huffman trees: the counts, the * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ void send_all_trees(int lcodes, int dcodes, int blcodes) //int lcodes, dcodes, blcodes; /* number of codes for each tree */ { int rank; /* index in bl_order */ Assert(lcodes >= 257 && dcodes >= 1 && blcodes >= 4);//, "not enough codes"); Assert(lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES);//, //"too many codes"); send_bits(lcodes-257, 5); /* not +255 as stated in appnote.txt 1.93a or -256 in 2.04c */ send_bits(dcodes-1, 5); send_bits(blcodes-4, 4); /* not -3 as stated in appnote.txt */ for (rank = 0; rank < blcodes; rank++) { send_bits(bl_tree[bl_order[rank]].Len, 3); } send_tree((ct_data near *)dyn_ltree, lcodes-1); /* send the literal tree */ send_tree((ct_data near *)dyn_dtree, dcodes-1); /* send the distance tree */ }
static int issp_prog_verify_block(struct issp_host *host, uint8_t idx) { send_vector(host, vec_sync_enable, bits_sync_enable); send_vector(host, vec_set_block_num, bits_set_block_num); pin_data_out(host); send_bits(host, &idx, 8); send_vector(host, vec_set_block_num_end, bits_set_block_num_end); send_vector(host, vec_sync_disable, bits_sync_disable); send_vector(host, vec_program_and_verify, bits_program_and_verify); return wait_and_poll(host); }
static uint8_t issp_read_byte_at(struct issp_host *host, uint8_t addr) { uint8_t address = addr << 1, data; send_vector(host, vec_read_byte_v[0], bits_read_byte_v[0]); pin_data_out(host); send_bits(host, &address, 7); generate_clocks(host, 2); data = read_byte(host); send_vector(host, vec_read_byte_v[1], bits_read_byte_v[1]); return data; }
static int issp_block_verify_setup(struct issp_host *host, uint8_t idx) { send_vector(host, vec_read_write_setup, bits_read_write_setup); send_vector(host, vec_sync_enable, bits_sync_enable); send_vector(host, vec_set_block_num, bits_set_block_num); pin_data_out(host); send_bits(host, &idx, 8); send_vector(host, vec_set_block_num_end, bits_set_block_num_end); send_vector(host, vec_sync_disable, bits_sync_disable); send_vector(host, vec_verify_setup, bits_verify_setup); return wait_and_poll(host); }
/* =========================================================================== * Send the header for a block using dynamic Huffman trees: the counts, the * lengths of the bit length codes, the literal tree and the distance tree. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. */ void send_all_trees(TState &state,int lcodes, int dcodes, int blcodes) { int rank; /* index in bl_order */ Assert(state,lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); Assert(state,lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, "too many codes"); Trace("\nbl counts: "); send_bits(state,lcodes-257, 5); /* not +255 as stated in appnote.txt 1.93a or -256 in 2.04c */ send_bits(state,dcodes-1, 5); send_bits(state,blcodes-4, 4); /* not -3 as stated in appnote.txt */ for (rank = 0; rank < blcodes; rank++) { Trace("\nbl code %2d ", bl_order[rank]); send_bits(state,state.ts.bl_tree[bl_order[rank]].dl.len, 3); } Trace("\nbl tree: sent %ld", state.bs.bits_sent); send_tree(state,(ct_data *)state.ts.dyn_ltree, lcodes-1); /* send the literal tree */ Trace("\nlit tree: sent %ld", state.bs.bits_sent); send_tree(state,(ct_data *)state.ts.dyn_dtree, dcodes-1); /* send the distance tree */ Trace("\ndist tree: sent %ld", state.bs.bits_sent); }
main() { int c; unsigned char t0; init(); #ifdef UN while (apoint!=low) { #else while (EOF!=(c=getchar())) { #endif ++low; /* send no EOF */ t[at]=t0=0x80; while (t0) { set_point(); #ifdef UN if(apoint>point){c=t0;} else {c=0;} sendb(c); #else sendb(c&t0); #endif hk=(HKSIZE+hk-t[at])%HKSIZE; hv=(HVSIZE+hv-t[at])%HVSIZE; #ifdef UN if (c==0) t[at]^=t0; t0>>=1; t[at]|=t0; #else t0>>=1; t[at]=(t[at]&c)|t0; #endif } hk+=t[at]; hv+=t[at]; hash(); at=(1+at)%TSIZE; if(at==to) backhash(); } high=low; /* send EOF */ send_bits(); flush_bits(); }
int seeprom_read(void *dst, int offset, int size) { int i; u16 *ptr = (u16 *)dst; u16 recv; if (size & 1) return -1; mask32(HW_GPIO1OUT, GP_EEP_CLK, 0); mask32(HW_GPIO1OUT, GP_EEP_CS, 0); eeprom_delay(); for (i = 0; i < size; i++) { mask32(HW_GPIO1OUT, 0, GP_EEP_CS); send_bits((0x600 | (offset + i)), 11); recv = recv_bits(16); *ptr++ = recv; mask32(HW_GPIO1OUT, GP_EEP_CS, 0); eeprom_delay(); } return size; }
static void write(struct pimhyp3_ts_data *ts, uint16_t command) { gpiod_set_value(ts->gpiod_cs,0); send_bits(ts, command, 9); gpiod_set_value(ts->gpiod_cs,1); }
static void send_tree ( z_stream& s, ct_data* tree, int max_code ) { int prevlen = -1; int curlen; int nextlen = tree[ 0 ].Len; int count = 0; int max_count = 7; int min_count = 4; if( !nextlen ) max_count = 138, min_count = 3; for( int n = 0 ; n <= max_code ; n++ ) { curlen = nextlen; nextlen = tree[ n + 1 ].Len; if( ++count < max_count && curlen == nextlen ) { continue; } else if( count < min_count ) { do { send_code( s, curlen, s.bl_tree ); } while( --count ); } else if( curlen ) { if( curlen != prevlen ) { send_code( s, curlen, s.bl_tree ); count--; } send_code( s, REP_3_6, s.bl_tree ); send_bits( s, count - 3, 2 ); } else if( count <= 10 ) { send_code( s, REPZ_3_10, s.bl_tree ); send_bits( s, count - 3, 3 ); } else { send_code( s, REPZ_11_138, s.bl_tree ); send_bits( s, count - 11, 7 ); } count = 0; prevlen = curlen; if( nextlen == 0 ) max_count = 138, min_count = 3; else if( curlen == nextlen ) max_count = 6, min_count = 3; else max_count = 7, min_count = 4; } }
/* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static * trees or store, and output the encoded block to the zip file. This function * returns the total compressed length for the file so far. */ word32 CodeTree::flush_block(byte *buf, word32 stored_len, int eof) { word32 opt_lenb, static_lenb; /* opt_len and static_len in bytes */ int max_blindex; /* index of last bit length code of non zero freq */ flag_buf[last_flags] = flags; /* Save the flags for the last 8 items */ /* Construct the literal and distance trees */ build_tree(&l_desc); // Tracev((stderr, "\nlit data: dyn %ld, stat %ld", opt_len, static_len)); build_tree(&d_desc); // Tracev((stderr, "\ndist data: dyn %ld, stat %ld", opt_len, static_len)); /* At this point, opt_len and static_len are the total bit lengths of * the compressed block data, excluding the tree representations. */ /* Build the bit length tree for the above two trees, and get the index * in bl_order of the last bit length code to send. */ max_blindex = build_bl_tree(); /* Determine the best encoding. Compute first the block length in bytes */ opt_lenb = (opt_len+3+7)>>3; static_lenb = (static_len+3+7)>>3; input_len += stored_len; /* for debugging only */ // Trace((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ", // opt_lenb, opt_len, static_lenb, static_len, stored_len, // last_lit, last_dist)); if (static_lenb <= opt_lenb) opt_lenb = static_lenb; #ifdef FORCE_METHOD if (level == 2 && buf) /* force stored block */ #else if (stored_len+4 <= opt_lenb && buf) /* 4: two words for the lengths */ #endif { /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. * Otherwise we can't have processed more than WSIZE input bytes since * the last block flush, because compression would have been * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to * transform a block into a stored block. */ /* send block type */ send_bits((STORED_BLOCK<<1)+eof, 3); compressed_len = (compressed_len + 3 + 7) & ~7L; compressed_len += (stored_len + 4) << 3; /* with header */ copy_block(buf, (unsigned)stored_len, 1); } #ifdef FORCE_METHOD else if (level == 3) /* force static trees */ #else else if (static_lenb == opt_lenb) #endif { send_bits((STATIC_TREES<<1)+eof, 3); compress_block(static_ltree,static_dtree); compressed_len += 3 + static_len; } else { send_bits((DYN_TREES<<1)+eof, 3); send_all_trees(l_desc.max_code+1, d_desc.max_code+1, max_blindex+1); compress_block(dyn_ltree,dyn_dtree); compressed_len += 3 + opt_len; } // assert (compressed_len == bits_sent); init_block(); if (eof) { // assert (input_len == isize); bi_windup(); compressed_len += 7; /* align on byte boundary */ } // Tracev((stderr,"\ncomprlen %lu(%lu) ", compressed_len>>3, // compressed_len-7*eof)); return compressed_len >> 3; }
static void send_vector(struct issp_host *host, const uint8_t *pvec, int bits) { pin_data_out(host); send_bits(host, pvec, bits); pin_data_z(host); }