static int32_t read_int32(ios_t *s) { int b0 = read_uint8(s); int b1 = read_uint8(s); int b2 = read_uint8(s); int b3 = read_uint8(s); return b0 | (b1<<8) | (b2<<16) | (b3<<24); }
mapnik::raster_ptr pgraster_wkb_reader::read_rgba(mapnik::box2d<double> const& bbox, uint16_t width, uint16_t height) { mapnik::image_rgba8 im(width, height, true, true); // Start with plain white (ABGR or RGBA depending on endiannes) im.set(0xffffffff); uint8_t nodataval; for (int bn=0; bn<numBands_; ++bn) { uint8_t type = read_uint8(&ptr_); int pixtype = BANDTYPE_PIXTYPE(type); int offline = BANDTYPE_IS_OFFDB(type) ? 1 : 0; int hasnodata = BANDTYPE_HAS_NODATA(type) ? 1 : 0; MAPNIK_LOG_DEBUG(pgraster) << "pgraster_wkb_reader: band " << bn << " type:" << pixtype << " offline:" << offline << " hasnodata:" << hasnodata; if ( offline ) { MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: offline band " << bn << " unsupported"; continue; } if ( pixtype > PT_8BUI || pixtype < PT_8BSI ) { MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: band " << bn << " type " << type << " unsupported"; continue; } uint8_t tmp = read_uint8(&ptr_); if ( ! bn ) nodataval = tmp; else if ( tmp != nodataval ) { MAPNIK_LOG_WARN(pgraster) << "pgraster_wkb_reader: band " << bn << " nodataval " << tmp << " != band 0 nodataval " << nodataval; } int ps = 4; // sizeof(image::pixel_type) uint8_t * image_data = im.bytes(); for (int y=0; y<height_; ++y) { for (int x=0; x<width_; ++x) { uint8_t val = read_uint8(&ptr_); // y * width_ * ps is the row (ps is pixel size) // x * ps is the column int off = y * width_ * ps + x * ps; // Pixel space is RGBA image_data[off+bn] = val; } } } mapnik::raster_ptr raster = std::make_shared<mapnik::raster>(bbox, im, 1.0); raster->set_nodata(0xffffffff); return raster; }
static void parse_cliloc(const char *p, const char *end) { int a = read_uint32_le(&p, end); int b = read_uint16_le(&p, end); const char *start = p; // first go through it one pass to count the number of strings and total string size int string_count = 0; int total_string_size = 0; while(p < end) { read_uint32_le(&p, end); read_uint8(&p, end); int length = read_uint16_le(&p, end); p += length; if (length > 0) { string_count += 1; total_string_size += length + 1; // include null terminator } } // rewind p = start; cliloc_entry_count = string_count; cliloc_entries = (ml_cliloc_entry *)malloc(sizeof(ml_cliloc_entry) * string_count); int next_index = 0; while(p < end) { int id = read_sint32_le(&p, end); read_uint8(&p, end); int length = read_uint16_le(&p, end); if (length > 0) { ml_cliloc_entry *entry = &cliloc_entries[next_index]; entry->id = id; char *s = (char *)malloc(length+1); s[length-1] = '\0'; read_ascii_fixed(&p, end, s, length); entry->s = s; next_index += 1; } } for (int i = 0; i < string_count; i++) { ml_cliloc_entry *entry = &cliloc_entries[i]; //printf("%d, %d: %s\n", i, entry->id, entry->s); } }
static void parse_tiledata(const char *p, const char *end) { int remaining_bytes = (int)(end - p); int block_count = (remaining_bytes-512*32*(8+2+20)) / (4 + 32*(8+1+1+4+2+2+2+1+20)); item_data_entry_count = 32*block_count; tile_datas = (ml_tile_data_entry *)malloc(512*32*sizeof(ml_tile_data_entry)); item_datas = (ml_item_data_entry *)malloc(item_data_entry_count * sizeof(ml_item_data_entry)); // 512*4 + 512*32*(8+2+20) bytes // first, 512 land data for (int i = 0; i < 512*32; i++) { // every 32 entries have a header of unknown use if (i % 32 == 0) { read_uint32_le(&p, end); } ml_tile_data_entry *tile_data = &tile_datas[i]; tile_data->flags = read_uint64_le(&p, end); tile_data->texture = read_uint16_le(&p, end); // hmm can this be used instead of the rotation of land gfx? read_ascii_fixed(&p, end, tile_data->name, 20); //printf("%d: %08llx %d %s\n", i, (unsigned long long)flags, texture, name); } int i = 0; while (p < end) { // every 32 entries have a header of unknown use if (i % 32 == 0) { read_uint32_le(&p, end); } ml_item_data_entry *item_data = &item_datas[i]; item_data->flags = read_uint64_le(&p, end); item_data->weight = read_uint8(&p, end); item_data->quality = read_uint8(&p, end); item_data->quantity = read_uint32_le(&p, end); item_data->animation = read_uint16_le(&p, end); read_uint16_le(&p, end); read_uint16_le(&p, end); item_data->height = read_uint8(&p, end); read_ascii_fixed(&p, end, item_data->name, 20); //printf("%d: %08llx %d %s\n", i, (unsigned long long)flags, animation, name); i += 1; } }
void Squeezer_chunk_header_t::read_from_file(FILE * in) { chunk_mark[0] = read_uint8(in); chunk_mark[1] = read_uint8(in); chunk_mark[2] = read_uint8(in); chunk_mark[3] = read_uint8(in); number_of_bytes = read_uint64(in); number_of_samples = read_uint32(in); chunk_type = read_uint32(in); compression_error.read_from_file(in); }
CMp4_stss_box CMp4_stss_box::mp4_read_stss_box(FILE *f, int size) //level 8 关键帧列表 { CMp4_stss_box box_ss; printf("\t\t\t\t\t+%s\n", "stss"); box_ss.size= size; box_ss.type= 's'|'t'<<8|'s'<<16|'s'<<24; box_ss.version= read_uint8(f); fread(box_ss.flags, sizeof(box_ss.flags), 1, f); box_ss.number_of_entries = read_uint32_lit(f);//关键帧的数目 printf("\t\t\t\t\t\t\tflags: %u\n", box_ss.flags[0]|box_ss.flags[1]|box_ss.flags[2]); printf("number of entries: %u\n",box_ss.number_of_entries); printf("entries:\n"); box_ss.sync_sample_table = new uint32_t[box_ss.number_of_entries]; unsigned int cur_pos=_ftelli64(f); for(int i =0; i < box_ss.number_of_entries; ++i) { _fseeki64(f,cur_pos,SEEK_SET); box_ss.sync_sample_table[i] = read_uint32_lit(f);//关键帧的序号 /* if (i<10)*/ //{ printf("%6u ", box_ss.sync_sample_table[i]); if( (i)%10 == 0)printf("\n"); //} cur_pos+=4; } printf("\n"); return box_ss; }
static __inline__ int decode_adpcm_sample_frame(Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; wav_t *w = (wav_t *) internal->decoder_private; fmt_t *fmt = w->fmt; ADPCMBLOCKHEADER *headers = fmt->fmt.adpcm.blockheaders; SDL_RWops *rw = internal->rw; int i; int max = fmt->wChannels; Sint32 delta; Uint8 nib = fmt->fmt.adpcm.nibble; for (i = 0; i < max; i++) { Uint8 byte; Sint16 iCoef1 = fmt->fmt.adpcm.aCoef[headers[i].bPredictor].iCoef1; Sint16 iCoef2 = fmt->fmt.adpcm.aCoef[headers[i].bPredictor].iCoef2; Sint32 lPredSamp = ((headers[i].iSamp1 * iCoef1) + (headers[i].iSamp2 * iCoef2)) / FIXED_POINT_COEF_BASE; if (fmt->fmt.adpcm.nibble_state == 0) { BAIL_IF_MACRO(!read_uint8(rw, &nib), NULL, 0); fmt->fmt.adpcm.nibble_state = 1; do_adpcm_nibble(nib >> 4, &headers[i], lPredSamp); } /* if */ else {
static __inline__ int read_adpcm_block_headers(Sound_Sample *sample) { Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque; SDL_RWops *rw = internal->rw; wav_t *w = (wav_t *) internal->decoder_private; fmt_t *fmt = w->fmt; ADPCMBLOCKHEADER *headers = fmt->fmt.adpcm.blockheaders; int i; int max = fmt->wChannels; if (w->bytesLeft < fmt->wBlockAlign) { sample->flags |= SOUND_SAMPLEFLAG_EOF; return(0); } /* if */ w->bytesLeft -= fmt->wBlockAlign; for (i = 0; i < max; i++) BAIL_IF_MACRO(!read_uint8(rw, &headers[i].bPredictor), NULL, 0); for (i = 0; i < max; i++) BAIL_IF_MACRO(!read_le16(rw, &headers[i].iDelta), NULL, 0); for (i = 0; i < max; i++) BAIL_IF_MACRO(!read_le16(rw, &headers[i].iSamp1), NULL, 0); for (i = 0; i < max; i++) BAIL_IF_MACRO(!read_le16(rw, &headers[i].iSamp2), NULL, 0); fmt->fmt.adpcm.samples_left_in_block = fmt->fmt.adpcm.wSamplesPerBlock; fmt->fmt.adpcm.nibble_state = 0; return(1); } /* read_adpcm_block_headers */
/** * Reads a variable length integer. */ std::uint64_t read_var_int() { std::uint64_t ret = 0; std::uint8_t size = read_uint8(); if (size < 253) { ret = size; } else if (size == 253) { ret = read_uint16(); } else if (size == 254) { ret = read_uint32(); } else if (size == 255) { ret = read_uint64(); } else { assert(0); } return ret; }
static int send_rtp(const uint8_t *pkt, size_t len, void *arg){ struct sync_state* pss = (struct sync_state*)arg; pthread_mutex_lock(&pss->mutex); pss->event = true; pss->pt = read_uint8(&pkt[1]); uint16_t seq = read_uint16(&pkt[2]); uint32_t timestamp = read_uint32(&pkt[4]); pss->ssrc = read_uint32(&pkt[8]); pss->seq_diff = seq - pss->prev_seq; if(pss->seq_diff < 0) { pss->seq_diff += 0xffff; } pss->prev_seq = seq; pss->timestamp_diff = timestamp - pss->prev_timestamp; if(pss->timestamp_diff < 0) { pss->timestamp_diff += 0xfffffff; } pss->prev_timestamp = timestamp; memcpy(pss->packet_buf, pkt, len); pss->nbytes = len; pthread_cond_signal(&pss->cond); pthread_mutex_unlock(&pss->mutex); return 0; }
static uint8_t SPICE_GNUC_UNUSED consume_uint8(uint8_t **ptr) { uint8_t val; val = read_uint8(*ptr); *ptr += 1; return val; }
CMp4_stsc_box CMp4_stsc_box::mp4_read_stsc_box(FILE *f, int size) //level 8 { CMp4_stsc_box box_sc; box_sc.size=size; box_sc.type= 's'|'t'<<8|'s'<<16|'c'<<24; printf("\t\t\t\t\t+%s\n", "stsc"); box_sc.version = read_uint8(f); fread(&box_sc.flags, sizeof(box_sc.flags), 1, f); box_sc.map_amount = read_uint32_lit(f);//sample-to-chunk 的数目 printf("map-amount: %u\n", box_sc.map_amount); box_sc.scmap= new mp4_list_t[box_sc.map_amount]; printf("first chunk:\tsamples-per-chunk:\tsample-description-ID\n"); /*这个表类似于行程编码,第一个first chunk 减去第二个first chunk 就是一共有多少个trunk 包含相同的sample 数目,这样通过不断的叠加,就可以得到一共有多少个chunk,每个chunk 包含多 少个sample,以及每个chunk 对应的description。*/ unsigned int cur_pos=_ftelli64(f); for(int i = 0; i < box_sc.map_amount; ++i){ _fseeki64(f,cur_pos,SEEK_SET); box_sc.scmap[i].first_chunk_num = read_uint32_lit(f); box_sc.scmap[i].sample_amount_in_cur_table = read_uint32_lit(f); box_sc.scmap[i].sample_description_id = read_uint32_lit(f); cur_pos+=12; } for (int i=0;i<10;i++) { printf("%13d", box_sc.scmap[i].first_chunk_num); printf("\t%13d", box_sc.scmap[i].sample_amount_in_cur_table); printf("\t%13d\n", box_sc.scmap[i].sample_description_id); } std::cout<<"stsc:chunk_num="<<box_sc.scmap[box_sc.map_amount-1].first_chunk_num<<std::endl; return box_sc; }
void streamProcessor() { while(1) { #ifndef SW #ifdef PIPELINE __loop_pipelining_on__(32,2,1); #endif #endif float x = read_float32("x_pipe"); float y = read_float32("y_pipe"); uint8_t op_code = read_uint8("op_pipe"); float result = 0; if(op_code == 0) result = x*y; else if(op_code == 1) result = x+y; else if(op_code == 2) result = (x*x) - (y*y); else if(op_code == 3) result = (x + y) * (x + y); else result = 0; write_float32("z_pipe",result); } }
address read_v6_address(InIt&& in) { address_v6::bytes_type bytes; for (auto& b : bytes) b = read_uint8(in); return address_v6(bytes); }
/*final box */ CMp4_mdhd_box CMp4_mdhd_box::mp4_read_mdhd_box(FILE *f, int size) { // printf("\t\t\t+mdhd\n"); CMp4_mdhd_box box; std::cout<<"\t\t\t\t\tmdhd"<<std::endl; int k = 0; \ unsigned char p[5]; \ int inner_size = 0; box.size = size; box.type = 'm' | 'd'<<8 | 'h'<<16 | 'd'<<24; box.version = read_uint8(f); fread(&box.flags, sizeof(box.flags), 1, f); box.creation_time = read_uint32_lit(f); box.modification_time = read_uint32_lit(f); box.timescale = read_uint32_lit(f); box.duration = read_uint32_lit(f); box.language = read_uint16_big(f); box.pre_defined = read_uint16_big(f); printf("\t\t\t\t\tflags: 0x%x\n", box.flags[2] | box.flags[1] | box.flags[0]); printf("\t\t\t\t\tcreation time: %u\n", box.creation_time); printf("\t\t\t\t\tmodifaction time: %u\n", box.modification_time); printf("\t\t\t\ttimescale: %u\n", box.timescale); printf("\t\t\t\tduration: %u\n", box.duration); printf("\t\t\t\tlanguage: %u\n", box.language); printf("\t\t\t\tpre-defined: %u\n", box.pre_defined); printf("\n"); return box; }
//--------------------------------------------------------------------------------------------- int32_t BitMessage::read_string(char* buffer, int32_t buffer_size) const { int l = 0; int c; read_byte_align(); while(1) { c = read_uint8(); if (c <= 0 || c >= 255) { break; } // translate all fmt spec to avoid crash bugs in string routines if ( c == '%' ) { c = '.'; } // we will read past any excessively long string, so // the following data can be read, but the string will // be truncated if (l < buffer_size - 1) { buffer[l] = c; l++; } } buffer[l] = 0; return l; }
CMp4_stco_box CMp4_stco_box::mp4_read_stco_box(FILE *f, int size)//定义了每个thunk在媒体流中的位置 { CMp4_stco_box box_co; printf("\t\t\t\t\t+%s\n", "stco"); box_co.size=size; box_co.type= 's'|'t'<<8|'c'<<16|'o'<<24; box_co.version= read_uint8(f); fread(box_co.flags, sizeof(box_co.flags), 1, f); box_co.chunk_offset_amount= read_uint32_lit(f); printf("chunk offest amount: %u\n", box_co.chunk_offset_amount); printf("chunk offset:\n"); box_co.chunk_offset_from_file_begin = new uint32_t[box_co.chunk_offset_amount]; unsigned int cur_pos=_ftelli64(f); for(int i = 0 ; i < box_co.chunk_offset_amount; i++){ _fseeki64(f,cur_pos,SEEK_SET); box_co.chunk_offset_from_file_begin[i] = read_uint32_lit(f); cur_pos+=4; } for (int i=0;i<30;i++) { std::cout<<box_co.chunk_offset_from_file_begin[i]<<" "; if((i+1) % 10 == 0) printf("\n"); } return box_co; }
void read_uint8_n(const char *id, uint8_t* buf, int buf_len) { int i; for(i = 0; i < buf_len; i++) { buf[i] = read_uint8((char*) id); } }
address read_v6_address(InIt& in) { typedef address_v6::bytes_type bytes_t; bytes_t bytes; for (bytes_t::iterator i = bytes.begin() , end(bytes.end()); i != end; ++i) *i = read_uint8(in); return address_v6(bytes); }
//--------------------------------------------------------------------------------------------- void BitMessage::read_netaddr(os::NetAddress* addr) const { for (int i = 0; i < 4; i++) { addr->m_address[i] = read_uint8(); } addr->m_port = read_uint16(); }
CMp4_stts_box CMp4_stts_box::mp4_read_stts_box(FILE *f, int size) //level 8 time-to-sample { CMp4_stts_box box_ts; printf("\t\t\t\t\t+%s\n", "stts"); box_ts.size= size; box_ts.type= 's'|'t'<<8|'t'<<16|'s'<<24; box_ts.version= read_uint8(f); fread(box_ts.flags, sizeof(box_ts.flags), 1, f); box_ts.number_of_entries=read_uint32_lit(f);//条目:time-to-sample 的数目 printf("flags: %u\n",box_ts.flags[0]|box_ts.flags[1]|box_ts.flags[2]); //printf("%x\n",); printf("number of entries: %u\n",box_ts.number_of_entries); /*int cur=ftell(f); cout<<"cur:"<<cur<<endl;*/ printf("entries:\n"); //box_ts.time_to_sample_table = new uint32_t[box_ts.number_of_entries]; /*结构:sample count:有相同duration 的连续sample 的数目; sample duration:每个sample 的duration*/ box_ts.sample_count=new uint32_t[box_ts.number_of_entries]; box_ts.sample_duration=new uint32_t[box_ts.number_of_entries]; int m=0,n=0; unsigned int cur_pos=_ftelli64(f); for(int i = 0; i < box_ts.number_of_entries*2; ++i) { _fseeki64(f,cur_pos,SEEK_SET); if (i%2) { box_ts.sample_duration[m]=read_uint32_lit(f); if (i<100) { std::cout<<box_ts.sample_duration[m]<<" "; } m++; } else { box_ts.sample_count[n]=read_uint32_lit(f); if (i<100) { std::cout<<box_ts.sample_count[n]<<" "; } n++; } if((i+1)%20 == 0&&i<100) printf("\n"); cur_pos+=4; } int tim=0,num=0; for (int i=0;i<box_ts.number_of_entries;i++) { tim+=box_ts.sample_count[i]*box_ts.sample_duration[i]; num+=box_ts.sample_count[i]; } std::cout<<"tim="<<tim<<" "<<"num="<<num<<std::endl; printf("\n"); return box_ts; }
void dC33() { uint32_t result; while(1) { uint8_t s = read_uint8("start_dc_33"); __CrossProcess(X3,X3,0,result); write_uint32("result_dc_33", result); } }
void dC22() { uint32_t result; while(1) { uint8_t s = read_uint8("start_dc_22"); __CrossProcess(X2,X2,0,result); write_uint32("result_dc_22", result); } }
void dC01() { uint32_t result; while(1) { uint8_t s = read_uint8("start_dc_01"); __CrossProcess(X0,X1,CHUNK_SIZE,result); write_uint32("result_dc_01", result); } }
void dC11() { uint32_t result; while(1) { uint8_t s = read_uint8("start_dc_11"); __CrossProcess(X1,X1,0,result); write_uint32("result_dc_11", result); } }
// calculate all pairwise errors. void dC00() { uint32_t result; while(1) { uint8_t s = read_uint8("start_dc_00"); __CrossProcess(X0,X0,0,result); write_uint32("result_dc_00", result); } }
void dC12() { uint32_t result; while(1) { uint8_t s = read_uint8("start_dc_12"); __CrossProcess(X1,X2,CHUNK_SIZE,result); write_uint32("result_dc_12", result); } }
void dC23() { uint32_t result; while(1) { uint8_t s = read_uint8("start_dc_23"); __CrossProcess(X2,X3,CHUNK_SIZE,result); write_uint32("result_dc_23", result); } }
static void parse_statics_block(const char *p, const char *end, ml_statics_block **sb) { long size = end - p; int statics_count = size / 7; int statics_block_size = sizeof(ml_statics_block) + statics_count * sizeof((*sb)->statics[0]); *sb = (ml_statics_block *)malloc(statics_block_size); (*sb)->statics_count = statics_count; for (int i = 0; i < 8*8; i++) { (*sb)->roof_heights[i] = -1; } //printf("statics_count. %d\n", statics_count); for (int i = 0; i < statics_count; i++) { int tile_id = read_sint16_le(&p, end); int dx = read_uint8(&p, end); int dy = read_uint8(&p, end); int z = read_sint8(&p, end); read_uint16_le(&p, end); // unknown (*sb)->statics[i].tile_id = tile_id; (*sb)->statics[i].dx = dx; (*sb)->statics[i].dy = dy; (*sb)->statics[i].z = z; ml_item_data_entry *item_data = ml_get_item_data(tile_id); if (item_data->flags & 0x10000000) { // is roof! if ((*sb)->roof_heights[dx+dy*8] == -1 || z > (*sb)->roof_heights[dx+dy*8]) // higher than existing roof? { (*sb)->roof_heights[dx+dy*8] = z; } } //printf("%d %d %d %d\n", tile_id, dx, dy, z); } }
static int read_uint8_array(uint8_t* buffer, uint8_t *array, size_t n) { size_t i; int ret = 0; for (i = 0;i < n;++i) { int size = read_uint8(buffer, &array[i]); buffer += size; ret += size; } return ret; }