void parallel_sort_iterative(RandomAccessIterator first, RandomAccessIterator last) { auto n = last - first; auto partition_size = 32768; auto num_partitions = ceil_div(n, partition_size); bulk_invoke(agency::par(num_partitions), [=](agency::parallel_agent& self) { auto begin = std::min(last, first + self.index() * partition_size); auto end = std::min(last, begin + partition_size); std::sort(begin, end); }); for(; partition_size < n; partition_size *= 2) { auto num_partitions = ceil_div(n, partition_size); bulk_invoke(agency::par(num_partitions / 2), [=](agency::parallel_agent& self) { auto begin = std::min(last, first + 2 * self.index() * partition_size); auto mid = std::min(last, begin + partition_size); auto end = std::min(last, mid + partition_size); std::inplace_merge(begin, mid, end); }); } }
void tilemap_draw(TileMap *tile_map, ImageSet *set, i32 dx, i32 dy) { unused(dx); unused(dy); V4i r = PROGRAM->screen_rect; rect_tr(&r, -PROGRAM->tx, -PROGRAM->ty); r.min_x = MAX(0, ((r.min_x) / (i32)set->cw)); r.min_y = MAX(0, ((r.min_y) / (i32)set->ch)); r.max_x = MIN((i32)tile_map->w, ceil_div(r.max_x, set->cw)); r.max_y = MIN((i32)tile_map->h, ceil_div(r.max_y, set->ch)); u16 *tile = tile_map_data(tile_map); for (i32 y = r.min_y; y != r.max_y; y++) { for (i32 x = r.min_x; x != r.max_x; x++) { if (tile[x] != 0xFFFF) { image_set_draw(x * set->cw, y * set->ch, set, tile[x], 0, 0); } } tile += tile_map->w; } }
static bool calculate_isys2401_dma_port_cfg( input_system_channel_t *channel, input_system_input_port_t *input_port, input_system_cfg_t *isys_cfg, bool is_compact_mode, isys2401_dma_port_cfg_t *cfg) { const int32_t bits_per_byte = 8; const int32_t bits_per_word = 256; int32_t memory_alignment_in_bytes = 32; int32_t bits_per_pixel; int32_t pixels_per_line; int32_t bytes_per_pixel; int32_t bytes_per_line; int32_t pixels_per_word; int32_t words_per_line; int32_t bytes_per_word; int32_t fmt_type; (void)channel; (void)input_port; bits_per_pixel = isys_cfg->input_port_resolution.bits_per_pixel; pixels_per_line = isys_cfg->input_port_resolution.pixels_per_line; fmt_type = isys_cfg->csi_port_attr.fmt_type; bytes_per_word = bits_per_word / bits_per_byte; if (is_compact_mode) { /* compact as many pixels as possible into a word */ pixels_per_word = bits_per_word / bits_per_pixel; words_per_line = ceil_div(pixels_per_line, pixels_per_word); bytes_per_line = bytes_per_word * words_per_line; } else { /* up-round "bits_per_pixel" to N times of 8-bit */ bytes_per_pixel = ceil_div(bits_per_pixel, bits_per_byte); bits_per_pixel = bytes_per_pixel * bits_per_byte; bytes_per_line = bytes_per_pixel * pixels_per_line; pixels_per_word = bits_per_word / bits_per_pixel; words_per_line = ceil_div(pixels_per_line, pixels_per_word); memory_alignment_in_bytes = calculate_input_system_alignment(fmt_type, bytes_per_pixel); } cfg->stride = CEIL_MUL(bytes_per_line, memory_alignment_in_bytes); cfg->elements = pixels_per_word; cfg->cropping = 0; cfg->width = words_per_line; return true; }
/* * Gets the output row corresponding to the encoded row for interlaced gifs */ inline uint32_t get_output_row_interlaced(uint32_t encodedRow, uint32_t height) { SkASSERT(encodedRow < height); // First pass if (encodedRow * 8 < height) { return encodedRow * 8; } // Second pass if (encodedRow * 4 < height) { return 4 + 8 * (encodedRow - ceil_div(height, 8)); } // Third pass if (encodedRow * 2 < height) { return 2 + 4 * (encodedRow - ceil_div(height, 4)); } // Fourth pass return 1 + 2 * (encodedRow - ceil_div(height, 2)); }
/// Factor numbers <= y FactorTable(int64_t y, int threads) { if (y > max()) throw primesum_error("y must be <= FactorTable::max()"); y = std::max<int64_t>(8, y); T T_MAX = std::numeric_limits<T>::max(); factor_.resize(get_index(y) + 1, T_MAX); int64_t sqrty = isqrt(y); int64_t thread_threshold = ipow(10, 7); threads = ideal_num_threads(threads, y, thread_threshold); int64_t thread_distance = ceil_div(y, threads); #pragma omp parallel for num_threads(threads) for (int t = 0; t < threads; t++) { int64_t low = 1; low += thread_distance * t; int64_t high = std::min(low + thread_distance, y); primesieve::iterator it(get_number(1) - 1); while (true) { int64_t i = 1; int64_t prime = it.next_prime(); int64_t multiple = next_multiple(prime, low, &i); int64_t min_m = prime * get_number(1); if (min_m > high) break; for (; multiple <= high; multiple = prime * get_number(i++)) { int64_t mi = get_index(multiple); // prime is smallest factor of multiple if (factor_[mi] == T_MAX) factor_[mi] = (T) prime; // the least significant bit indicates // whether multiple has an even (0) or odd (1) // number of prime factors else if (factor_[mi] != 0) factor_[mi] ^= 1; } if (prime <= sqrty) { int64_t j = 0; int64_t square = prime * prime; multiple = next_multiple(square, low, &j); // moebius(n) = 0 for (; multiple <= high; multiple = square * get_number(j++)) factor_[get_index(multiple)] = 0; } } } }
void write_bmp(const char *const file2) { FILE *fpBMP; int i, j; // Header and 3 bytes per pixel unsigned long ulBitmapSize = ceil_div(24*x_size, 32)*4*y_size+54; char ucaBitmapSize[4]; ucaBitmapSize[3] = (ulBitmapSize & 0xFF000000) >> 24; ucaBitmapSize[2] = (ulBitmapSize & 0x00FF0000) >> 16; ucaBitmapSize[1] = (ulBitmapSize & 0x0000FF00) >> 8; ucaBitmapSize[0] = (ulBitmapSize & 0x000000FF); /* Create bitmap file */ fpBMP = fopen(file2, "wb"); if (fpBMP == 0) return; /* Write header */ /* All values are in big endian order (LSB first) */ // BMP signature + filesize fprintf(fpBMP, "%c%c%c%c%c%c%c%c%c%c", 66, 77, ucaBitmapSize[0], ucaBitmapSize[1], ucaBitmapSize[2], ucaBitmapSize[3], 0, 0, 0, 0); // Image offset, infoheader size, image width fprintf(fpBMP, "%c%c%c%c%c%c%c%c%c%c", 54, 0, 0, 0, 40, 0, 0, 0, (x_size & 0x00FF), (x_size & 0xFF00) >> 8); // Image height, number of panels, num bits per pixel fprintf(fpBMP, "%c%c%c%c%c%c%c%c%c%c", 0, 0, (y_size & 0x00FF), (y_size & 0xFF00) >> 8, 0, 0, 1, 0, 24, 0); // Compression type 0, Size of image in bytes 0 because uncompressed fprintf(fpBMP, "%c%c%c%c%c%c%c%c%c%c", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); fprintf(fpBMP, "%c%c%c%c%c%c%c%c%c%c", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); fprintf(fpBMP, "%c%c%c%c", 0, 0, 0, 0); for (i = y_size - 1; i >= 0; i--) { /* in bitmaps the bottom line of the image is at the beginning of the file */ for (j = 0; j < x_size; j++) { putc(FrameBuffer[3 * (i * x_size + j) + 0], fpBMP); putc(FrameBuffer[3 * (i * x_size + j) + 1], fpBMP); putc(FrameBuffer[3 * (i * x_size + j) + 2], fpBMP); } for (j = 0; j < x_size % 4; j++) putc(0, fpBMP); } fclose(fpBMP); }
/// Find the first multiple (of prime) > low which /// is not divisible by any prime <= 7 /// static int64_t next_multiple(int64_t prime, int64_t low, int64_t* index) { int64_t quotient = ceil_div(low, prime); int64_t i = std::max(*index, get_index(quotient)); int64_t multiple = 0; for (; multiple <= low; i++) multiple = prime * get_number(i); *index = i; return multiple; }
/* See also: ia_css_dma_configure_from_info() */ static int32_t calculate_stride( int32_t bits_per_pixel, int32_t pixels_per_line, bool raw_packed, int32_t align_in_bytes) { int32_t bytes_per_line; int32_t pixels_per_word; int32_t words_per_line; int32_t pixels_per_line_padded; pixels_per_line_padded = CEIL_MUL(pixels_per_line, align_in_bytes); if (!raw_packed) bits_per_pixel = CEIL_MUL(bits_per_pixel, 8); pixels_per_word = HIVE_ISP_DDR_WORD_BITS / bits_per_pixel; words_per_line = ceil_div(pixels_per_line_padded, pixels_per_word); bytes_per_line = HIVE_ISP_DDR_WORD_BYTES * words_per_line; return bytes_per_line; }
ilka_off_t ilka_grow(struct ilka_region *r, size_t len) { len = ceil_div(len, ILKA_PAGE_SIZE) * ILKA_PAGE_SIZE; slock_lock(&r->lock); size_t old_len = r->len; size_t new_len = old_len + len; file_grow(r->fd, new_len); if (!mmap_remap(&r->mmap, old_len, new_len)) goto fail_remap; // morder_release: ensure that the region is fully grown before publishing // the new size. ilka_atomic_store(&r->len, new_len, morder_release); slock_unlock(&r->lock); return old_len; fail_remap: slock_unlock(&r->lock); return 0; }
Wheel(Primes& primes, int64_t size, int64_t low, bool sieve_primes = false) { wheelItems_.reserve(size); // primecount uses 1-indexing, 0-index is a dummy wheelItems_.push_back(WheelItem(0, 0)); for (int64_t b = 1; b < size; b++) { int64_t prime = primes[b]; int64_t quotient = ceil_div(low, prime); // calculate the first multiple of prime >= low int64_t multiple = prime * quotient; // for sieving primes we start crossing off multiples at the square if (sieve_primes && quotient < prime) { multiple = prime * prime; quotient = prime; } // calculate the next multiple of prime that is not // divisible by any of the wheel's factors (2, 3, 5, 7) uint64_t next_multiple_factor = initWheel210[quotient % 210].next_multiple_factor; multiple += prime * next_multiple_factor; int8_t wheel_index = initWheel210[quotient % 210].wheel_index; #if __cplusplus >= 201103L wheelItems_.emplace_back(multiple, wheel_index); #else wheelItems_.push_back(WheelItem(multiple, wheel_index)); #endif } }
static bool acquire_ib_buffer( int32_t bits_per_pixel, int32_t pixels_per_line, int32_t lines_per_frame, int32_t fmt_type, ib_buffer_t *buf) { const int32_t bits_per_byte = 8; int32_t memory_alignment_in_bytes; int32_t bytes_per_pixel; int32_t bytes_per_line; bytes_per_pixel = ceil_div(bits_per_pixel, bits_per_byte); bytes_per_line = bytes_per_pixel * pixels_per_line; memory_alignment_in_bytes = calculate_input_system_alignment(fmt_type, bytes_per_pixel); buf->stride = CEIL_MUL(bytes_per_line, memory_alignment_in_bytes); buf->lines = 2; /* ISYS2401 hardware can handle at most 4 lines */ (void)(lines_per_frame); return ia_css_isys_ibuf_rmgr_acquire(buf->stride * buf->lines, &buf->start_addr); }
static bool calculate_ibuf_ctrl_cfg( const input_system_channel_t *channel, const input_system_input_port_t *input_port, const input_system_cfg_t *isys_cfg, ibuf_ctrl_cfg_t *cfg) { const int32_t bits_per_byte = 8; int32_t bits_per_pixel; int32_t bytes_per_pixel; int32_t left_padding; (void)input_port; bits_per_pixel = isys_cfg->input_port_resolution.bits_per_pixel; bytes_per_pixel = ceil_div(bits_per_pixel, bits_per_byte); left_padding = CEIL_MUL(isys_cfg->output_port_attr.left_padding, ISP_VEC_NELEMS) * bytes_per_pixel; cfg->online = isys_cfg->online; cfg->dma_cfg.channel = channel->dma_channel; cfg->dma_cfg.cmd = _DMA_V2_MOVE_A2B_NO_SYNC_CHK_COMMAND; cfg->dma_cfg.shift_returned_items = 0; cfg->dma_cfg.elems_per_word_in_ibuf = 0; cfg->dma_cfg.elems_per_word_in_dest = 0; cfg->ib_buffer.start_addr = channel->ib_buffer.start_addr; cfg->ib_buffer.stride = channel->ib_buffer.stride; cfg->ib_buffer.lines = channel->ib_buffer.lines; /* * [email protected]: * "dest_buf_cfg" should be part of the input system output * port configuration. * * TODO: move "dest_buf_cfg" to the input system output * port configuration. */ /* input_buf addr only available in sched mode; this buffer is allocated in isp, crun mode addr can be passed by after ISP allocation */ if (cfg->online) { cfg->dest_buf_cfg.start_addr = ISP_INPUT_BUF_START_ADDR + left_padding; cfg->dest_buf_cfg.stride = bytes_per_pixel * isys_cfg->output_port_attr.max_isp_input_width; cfg->dest_buf_cfg.lines = LINES_OF_ISP_INPUT_BUF; } else if (isys_cfg->raw_packed) { cfg->dest_buf_cfg.stride = calculate_stride(bits_per_pixel, isys_cfg->input_port_resolution.pixels_per_line, isys_cfg->raw_packed, isys_cfg->input_port_resolution.align_req_in_bytes); } else { cfg->dest_buf_cfg.stride = channel->ib_buffer.stride; } /* * [email protected]: * "items_per_store" is hard coded as "1", which is ONLY valid * when the CSI-MIPI long packet is transferred. * * TODO: After the 1st stage of MERR+, make the proper solution to * configure "items_per_store" so that it can also handle the CSI-MIPI * short packet. */ cfg->items_per_store = 1; cfg->stores_per_frame = isys_cfg->input_port_resolution.lines_per_frame; cfg->stream2mmio_cfg.sync_cmd = _STREAM2MMIO_CMD_TOKEN_SYNC_FRAME; /* TODO: Define conditions as when to use store words vs store packets */ cfg->stream2mmio_cfg.store_cmd = _STREAM2MMIO_CMD_TOKEN_STORE_PACKETS; return true; }
constexpr bool multiply_less(T a, T b, T c) { return b == 0 ? a * b < c : a < ceil_div(c, b); }
void ia_css_bayer_io_config( const struct ia_css_binary *binary, const struct sh_css_binary_args *args) { const struct ia_css_frame *in_frame = args->in_frame; const struct ia_css_frame **out_frames = (const struct ia_css_frame **)& args->out_frame; const struct ia_css_frame_info *in_frame_info = (in_frame) ? &in_frame->info : &binary->in_frame_info; const unsigned ddr_bits_per_element = sizeof(short) * 8; const unsigned ddr_elems_per_word = ceil_div(HIVE_ISP_DDR_WORD_BITS, ddr_bits_per_element); unsigned size_get = 0, size_put = 0; unsigned offset = 0; if (binary->info->mem_offsets.offsets.param) { size_get = binary->info->mem_offsets.offsets.param->dmem.get.size; offset = binary->info->mem_offsets.offsets.param->dmem.get.offset; } if (size_get) { struct ia_css_common_io_config *to = (struct ia_css_common_io_config *)&binary->mem_params.params[IA_CSS_PARAM_CLASS_PARAM][IA_CSS_ISP_DMEM].address[offset]; struct dma_port_config config; #ifndef IA_CSS_NO_DEBUG ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ia_css_bayer_io_config() get part enter:\n"); #endif ia_css_dma_configure_from_info(&config, in_frame_info); // The base_address of the input frame will be set in the ISP to->width = in_frame_info->res.width; to->height = in_frame_info->res.height; to->stride = config.stride; to->ddr_elems_per_word = ddr_elems_per_word; #ifndef IA_CSS_NO_DEBUG ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ia_css_bayer_io_config() get part leave:\n"); #endif } if (binary->info->mem_offsets.offsets.param) { size_put = binary->info->mem_offsets.offsets.param->dmem.put.size; offset = binary->info->mem_offsets.offsets.param->dmem.put.offset; } if (size_put) { struct ia_css_common_io_config *to = (struct ia_css_common_io_config *)&binary->mem_params.params[IA_CSS_PARAM_CLASS_PARAM][IA_CSS_ISP_DMEM].address[offset]; struct dma_port_config config; #ifndef IA_CSS_NO_DEBUG ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ia_css_bayer_io_config() put part enter:\n"); #endif ia_css_dma_configure_from_info(&config, &out_frames[0]->info); to->base_address = out_frames[0]->data; to->width = out_frames[0]->info.res.width; to->height = out_frames[0]->info.res.height; to->stride = config.stride; to->ddr_elems_per_word = ddr_elems_per_word; #ifndef IA_CSS_NO_DEBUG ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE, "ia_css_bayer_io_config() put part leave:\n"); #endif } }
de265_error read_sps(bitreader* br, seq_parameter_set* sps, ref_pic_set** ref_pic_sets) { sps->video_parameter_set_id = get_bits(br,4); sps->sps_max_sub_layers = get_bits(br,3) +1; if (sps->sps_max_sub_layers>7) { return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; } sps->sps_temporal_id_nesting_flag = get_bits(br,1); read_profile_tier_level(br,&sps->profile_tier_level, true, sps->sps_max_sub_layers); sps->seq_parameter_set_id = get_uvlc(br); // --- decode chroma type --- sps->chroma_format_idc = get_uvlc(br); if (sps->chroma_format_idc == 3) { sps->separate_colour_plane_flag = get_bits(br,1); } else { sps->separate_colour_plane_flag = 0; } if (sps->separate_colour_plane_flag) { sps->ChromaArrayType = 0; } else { sps->ChromaArrayType = sps->chroma_format_idc; } sps->SubWidthC = SubWidthC [sps->chroma_format_idc]; sps->SubHeightC = SubHeightC[sps->chroma_format_idc]; // --- picture size --- sps->pic_width_in_luma_samples = get_uvlc(br); sps->pic_height_in_luma_samples = get_uvlc(br); sps->conformance_window_flag = get_bits(br,1); if (sps->conformance_window_flag) { sps->conf_win_left_offset = get_uvlc(br); sps->conf_win_right_offset = get_uvlc(br); sps->conf_win_top_offset = get_uvlc(br); sps->conf_win_bottom_offset= get_uvlc(br); } else { sps->conf_win_left_offset = 0; sps->conf_win_right_offset = 0; sps->conf_win_top_offset = 0; sps->conf_win_bottom_offset= 0; } if (sps->ChromaArrayType==0) { sps->WinUnitX = 1; sps->WinUnitY = 1; } else { sps->WinUnitX = SubWidthC[sps->chroma_format_idc]; sps->WinUnitY = SubHeightC[sps->chroma_format_idc]; } sps->bit_depth_luma = get_uvlc(br) +8; sps->bit_depth_chroma = get_uvlc(br) +8; sps->log2_max_pic_order_cnt_lsb = get_uvlc(br) +4; sps->MaxPicOrderCntLsb = 1<<(sps->log2_max_pic_order_cnt_lsb); // --- sub_layer_ordering_info --- sps->sps_sub_layer_ordering_info_present_flag = get_bits(br,1); int firstLayer = (sps->sps_sub_layer_ordering_info_present_flag ? 0 : sps->sps_max_sub_layers-1 ); for (int i=firstLayer ; i <= sps->sps_max_sub_layers-1; i++ ) { sps->sps_max_dec_pic_buffering[i] = get_uvlc(br); sps->sps_max_num_reorder_pics[i] = get_uvlc(br); sps->sps_max_latency_increase[i] = get_uvlc(br); } // copy info to all layers if only specified once if (sps->sps_sub_layer_ordering_info_present_flag) { int ref = sps->sps_max_sub_layers-1; for (int i=0 ; i < sps->sps_max_sub_layers-1; i++ ) { sps->sps_max_dec_pic_buffering[i] = sps->sps_max_dec_pic_buffering[ref]; sps->sps_max_num_reorder_pics[i] = sps->sps_max_num_reorder_pics[ref]; sps->sps_max_latency_increase[i] = sps->sps_max_latency_increase[ref]; } } sps->log2_min_luma_coding_block_size = get_uvlc(br)+3; sps->log2_diff_max_min_luma_coding_block_size = get_uvlc(br); sps->log2_min_transform_block_size = get_uvlc(br)+2; sps->log2_diff_max_min_transform_block_size = get_uvlc(br); sps->max_transform_hierarchy_depth_inter = get_uvlc(br); sps->max_transform_hierarchy_depth_intra = get_uvlc(br); sps->scaling_list_enable_flag = get_bits(br,1); if (sps->scaling_list_enable_flag) { sps->sps_scaling_list_data_present_flag = get_bits(br,1); if (sps->sps_scaling_list_data_present_flag) { assert(0); //scaling_list_data() } } sps->amp_enabled_flag = get_bits(br,1); sps->sample_adaptive_offset_enabled_flag = get_bits(br,1); sps->pcm_enabled_flag = get_bits(br,1); if (sps->pcm_enabled_flag) { sps->pcm_sample_bit_depth_luma = get_bits(br,4)+1; sps->pcm_sample_bit_depth_chroma = get_bits(br,4)+1; sps->log2_min_pcm_luma_coding_block_size = get_uvlc(br)+3; sps->log2_diff_max_min_pcm_luma_coding_block_size = get_uvlc(br); sps->pcm_loop_filter_disable_flag = get_bits(br,1); } sps->num_short_term_ref_pic_sets = get_uvlc(br); // --- allocate reference pic set --- // allocate one more for the ref-pic-set that may be sent in the slice header *ref_pic_sets = (ref_pic_set *)calloc(sizeof(ref_pic_set), sps->num_short_term_ref_pic_sets + 1); for (int i = 0; i < sps->num_short_term_ref_pic_sets; i++) { //alloc_ref_pic_set(&(*ref_pic_sets)[i], //sps->sps_max_dec_pic_buffering[sps->sps_max_sub_layers-1]); read_short_term_ref_pic_set(br,*ref_pic_sets, i, sps->num_short_term_ref_pic_sets); dump_short_term_ref_pic_set(&(*ref_pic_sets)[i]); } sps->long_term_ref_pics_present_flag = get_bits(br,1); if (sps->long_term_ref_pics_present_flag) { sps->num_long_term_ref_pics_sps = get_uvlc(br); if (sps->num_long_term_ref_pics_sps > 32) { return DE265_ERROR_CODED_PARAMETER_OUT_OF_RANGE; } for (int i = 0; i < sps->num_long_term_ref_pics_sps; i++ ) { sps->lt_ref_pic_poc_lsb_sps[i] = get_bits(br, sps->log2_max_pic_order_cnt_lsb); sps->used_by_curr_pic_lt_sps_flag[i] = get_bits(br,1); } } else { sps->num_long_term_ref_pics_sps = 0; // NOTE: missing definition in standard ! } sps->sps_temporal_mvp_enabled_flag = get_bits(br,1); sps->strong_intra_smoothing_enable_flag = get_bits(br,1); sps->vui_parameters_present_flag = get_bits(br,1); if (sps->vui_parameters_present_flag) { assert(false); /* vui_parameters() sps_extension_flag u(1) if( sps_extension_flag ) while( more_rbsp_data() ) sps_extension_data_flag u(1) rbsp_trailing_bits() */ } sps->sps_extension_flag = get_bits(br,1); if (sps->sps_extension_flag) { assert(false); } check_rbsp_trailing_bits(br); // --- compute derived values --- sps->BitDepth_Y = sps->bit_depth_luma; sps->QpBdOffset_Y = 6*(sps->bit_depth_luma-8); sps->BitDepth_C = sps->bit_depth_chroma; sps->QpBdOffset_C = 6*(sps->bit_depth_chroma-8); sps->Log2MinCbSizeY = sps->log2_min_luma_coding_block_size; sps->Log2CtbSizeY = sps->Log2MinCbSizeY + sps->log2_diff_max_min_luma_coding_block_size; sps->MinCbSizeY = 1 << sps->Log2MinCbSizeY; sps->CtbSizeY = 1 << sps->Log2CtbSizeY; sps->PicWidthInMinCbsY = sps->pic_width_in_luma_samples / sps->MinCbSizeY; sps->PicWidthInCtbsY = ceil_div(sps->pic_width_in_luma_samples, sps->CtbSizeY); sps->PicHeightInMinCbsY = sps->pic_height_in_luma_samples / sps->MinCbSizeY; sps->PicHeightInCtbsY = ceil_div(sps->pic_height_in_luma_samples,sps->CtbSizeY); sps->PicSizeInMinCbsY = sps->PicWidthInMinCbsY * sps->PicHeightInMinCbsY; sps->PicSizeInCtbsY = sps->PicWidthInCtbsY * sps->PicHeightInCtbsY; sps->PicSizeInSamplesY = sps->pic_width_in_luma_samples * sps->pic_height_in_luma_samples; if (sps->chroma_format_idc==0 || sps->separate_colour_plane_flag) { sps->CtbWidthC = 0; sps->CtbHeightC = 0; } else { sps->CtbWidthC = sps->CtbSizeY / sps->SubWidthC; sps->CtbHeightC = sps->CtbSizeY / sps->SubHeightC; } sps->Log2MinTrafoSize = sps->log2_min_transform_block_size; sps->Log2MaxTrafoSize = sps->log2_min_transform_block_size + sps->log2_diff_max_min_transform_block_size; // the following are not in the standard sps->PicWidthInTbsY = sps->PicWidthInCtbsY << (sps->Log2CtbSizeY - sps->Log2MinTrafoSize); sps->PicHeightInTbsY = sps->PicHeightInCtbsY << (sps->Log2CtbSizeY - sps->Log2MinTrafoSize); sps->PicSizeInTbsY = sps->PicWidthInTbsY * sps->PicHeightInTbsY; sps->sps_read = true; return DE265_OK; }
int JpegToBmp() { unsigned int aux, mark; int n_restarts, restart_interval, leftover; /* RST check */ int i, j; int turn; int temp; int xmsize; /* First find the SOI marker: */ //mk_mon_debug_info(9999); aux = get_next_MK(); if (aux != SOI_MK) aborted_stream(0); //if (verbose) //fprintf(stderr, "%ld:\tINFO:\tFound the SOI marker!\n", ftell(fi)); //; in_frame = 0; restart_interval = 0; for (i = 0; i < 4; i++) QTvalid[i] = 0; /* Now process segments as they appear: */ do { mark = get_next_MK(); switch (mark) { case SOF_MK: //ffc0 start of the frame //if (verbose); //fprintf(stderr, "%ld:\tINFO:\tFound the SOF marker!\n", ftell(fi)); in_frame = 1; //get_size(fi); /* header size, don't care */ get_size(); //0011 17 /* load basic image parameters */ //fgetc(fi); /* precision, 8bit, don't care */ FGETC(); //8 y_size = get_size();//FGETC() twice x_size = get_size(); mk_mon_debug_info(x_size); mk_mon_debug_info(y_size); //if (verbose); //fprintf(stderr, "\tINFO:\tImage size is %d by %d\n", x_size, y_size); //n_comp = fgetc(fi); /* # of components */ n_comp = FGETC(); mk_mon_debug_info(123456); mk_mon_debug_info(n_comp); mk_mon_debug_info(654321); //if (1) { //fprintf(stderr, "\tINFO:\t"); ////switch (n_comp) { //case 1: //printf( "Monochrome\n"); //break; //case 3: //printf( "Color\n"); // break; ////default: // printf( "Not a picture!\n"); //break; //} //fprintf(stderr, " JPEG image!\n"); //} for (i = 0; i < n_comp; i++) { /* component specifiers */ //comp[i].CID = fgetc(fi); comp[i].CID = FGETC(); //aux = fgetc(fi); aux = FGETC(); comp[i].HS = first_quad(aux); //0x11 >> 4 1 comp[i].VS = second_quad(aux); //&15 1 //comp[i].QT = fgetc(fi); comp[i].QT = FGETC(); } //if ((n_comp > 1) && verbose); /*fprintf(stderr, "\tINFO:\tColor format is %d:%d:%d, H=%d\n", comp[0].HS * comp[0].VS, comp[1].HS * comp[1].VS, comp[2].HS * comp[2].VS, comp[1].HS);*/ if (init_MCU() == -1) aborted_stream(1); /* dimension scan buffer for YUV->RGB conversion */ //FrameBuffer = (unsigned char *)mk_malloc((size_t) x_size * y_size * n_comp); ColorBuffer = (unsigned char *)mk_malloc((size_t) MCU_sx * MCU_sy * n_comp); FBuff = (FBlock *) mk_malloc(sizeof(FBlock)); PBuff = (PBlock *) mk_malloc(sizeof(PBlock)); if ( (ColorBuffer == NULL) || (FBuff == NULL) || (PBuff == NULL)) { //fprintf(stderr, "\tERROR:\tCould not allocate pixel storage!\n"); aborted_stream(2); } break; case DHT_MK: //if (verbose) //fprintf(stderr, "%ld:\tINFO:\tDefining Huffman Tables\n", ftell(fi)); if (load_huff_tables() == -1) aborted_stream(2); break; case DQT_MK: //FFDB, the following 0084 shows the table length 132 //if (verbose) //fprintf(stderr, "%ld:\tINFO:\tDefining Quantization Tables\n", ftell(fi)); if (load_quant_tables() == -1) aborted_stream(3); break; case DRI_MK: get_size(); /* skip size */ restart_interval = get_size(); mk_mon_debug_info(00000000); mk_mon_debug_info(restart_interval); mk_mon_debug_info(00000000); //if (verbose) //fprintf(stderr, "%ld:\tINFO:\tDefining Restart Interval %d\n", ftell(fi), //restart_interval); //; break; case SOS_MK: /* lots of things to do here */ //ffda //if (verbose); //fprintf(stderr, "%ld:\tINFO:\tFound the SOS marker!\n", ftell(fi)); get_size(); /* don't care */ //aux = fgetc(fi); aux = FGETC(); //03 if (aux != (unsigned int)n_comp) { //fprintf(stderr, "\tERROR:\tBad component interleaving!\n"); aborted_stream(4); } for (i = 0; i < n_comp; i++) { //aux = fgetc(fi); aux = FGETC(); if (aux != comp[i].CID) { //fprintf(stderr, "\tERROR:\tBad Component Order!\n"); aborted_stream(5); } //aux = fgetc(fi); aux = FGETC(); comp[i].DC_HT = first_quad(aux); comp[i].AC_HT = second_quad(aux); } get_size(); //fgetc(fi); /* skip things */ FGETC(); MCU_column = 0; MCU_row = 0; clear_bits(); reset_prediction(); /* main MCU processing loop here */ if (restart_interval) { n_restarts = ceil_div(mx_size * my_size, restart_interval) - 1; leftover = mx_size * my_size - n_restarts * restart_interval; /* final interval may be incomplete */ for (i = 0; i < n_restarts; i++) { //temp = restart_interval*i; for (j = 0; j < restart_interval; j++){ //turn = (temp+j) & 0x3; process_MCU();} /* proc till all EOB met */ aux = get_next_MK(); if (!RST_MK(aux)) { //fprintf(stderr, "%ld:\tERROR:\tLost Sync after interval!\n", ftell(fi)); aborted_stream(6); } else if (verbose); //fprintf(stderr, "%ld:\tINFO:\tFound Restart Marker\n", ftell(fi)); reset_prediction(); clear_bits(); } /* intra-interval loop */ } else leftover = mx_size * my_size; //picture size in units of MCUs /* process till end of row without restarts */ for (i = 0; i < leftover; i++){ //turn = i & 0x3; process_MCU(); } in_frame = 0; break; case EOI_MK: //if (verbose); //fprintf(stderr, "%ld:\tINFO:\tFound the EOI marker!\n", ftell(fi)); if (in_frame) aborted_stream(7); //if (verbose); /*fprintf(stderr, "\tINFO:\tTotal skipped bytes %d, total stuffers %d\n", passed, stuffers);*/ //fclose(fi); //mk_mon_debug_info(8888); //write_bmp(); // mk_mon_debug_info(6666); //printf("%ld,%ld", x_size * y_size * n_comp,MCU_sx * MCU_sy * n_comp); //free_structures(); return 0; break; case COM_MK: //ffee //if (verbose); //fprintf(stderr, "%ld:\tINFO:\tSkipping comments\n", ftell(fi)); skip_segment(); break; case EOF: //if (verbose); //fprintf(stderr, "%ld:\tERROR:\tRan out of input data!\n", ftell(fi)); aborted_stream(8); default: if ((mark & MK_MSK) == APP_MK) {//when read from FFEC, this will hold again //if (verbose); //fprintf(stderr, "%ld:\tINFO:\tSkipping application data\n", ftell(fi)); skip_segment(); break; } if (RST_MK(mark)) { reset_prediction(); break; } /* if all else has failed ... */ //fprintf(stderr, "%ld:\tWARNING:\tLost Sync outside scan, %d!\n", ftell(fi), mark); aborted_stream(9); break; } /* end switch */ } while (1); return 0; }
int JpegToBmp() { unsigned int aux, mark; int n_restarts, restart_interval, leftover; /* RST check */ int i, j; /* First find the SOI marker: */ aux = get_next_MK(); if (aux != SOI_MK) aborted_stream(0); in_frame = 0; restart_interval = 0; for (i = 0; i < 4; i++) QTvalid[i] = 0; /* Now process segments as they appear: */ do { mark = get_next_MK(); switch (mark) { case SOF_MK: //ffc0 start of the frame in_frame = 1; get_size(); //0011 17 /* load basic image parameters */ FGETC(); //8 y_size = get_size();//FGETC() twice x_size = get_size(); n_comp = FGETC(); for (i = 0; i < n_comp; i++) { comp[i].CID = FGETC(); aux = FGETC(); comp[i].HS = first_quad(aux); //0x11 >> 4 1 comp[i].VS = second_quad(aux); //&15 1 comp[i].QT = FGETC(); } if (init_MCU() == -1) aborted_stream(1); /* dimension scan buffer for YUV->RGB conversion */ ColorBuffer = (unsigned char *)mk_malloc((size_t) MCU_sx * MCU_sy * n_comp); // ColorBuffer = (unsigned int*)mk_malloc(sizeof(unsigned int) * MCU_sy * x_size); FBuff = (FBlock *) mk_malloc(sizeof(FBlock)); if ( (ColorBuffer == NULL) || (FBuff == NULL)) { aborted_stream(2); } break; case DHT_MK: if (load_huff_tables() == -1) aborted_stream(2); break; case DQT_MK: //FFDB, the following 0084 shows the table length 132 if (load_quant_tables() == -1) aborted_stream(3); break; case DRI_MK: get_size(); /* skip size */ restart_interval = get_size(); break; case SOS_MK: /* lots of things to do here */ //ffda get_size(); /* don't care */ aux = FGETC(); //03 if (aux != (unsigned int)n_comp) { aborted_stream(4); } for (i = 0; i < n_comp; i++) { aux = FGETC(); if (aux != comp[i].CID) { aborted_stream(5); } aux = FGETC(); comp[i].DC_HT = first_quad(aux); comp[i].AC_HT = second_quad(aux); } get_size(); FGETC(); MCU_column = 0; MCU_row = 0; clear_bits(); reset_prediction(); /* main MCU processing loop here */ if (restart_interval) { n_restarts = ceil_div(mx_size * my_size, restart_interval) - 1; leftover = mx_size * my_size - n_restarts * restart_interval; /* final interval may be incomplete */ for (i = 0; i < n_restarts; i++) { for (j = 0; j < restart_interval; j++) { process_MCU(); /* proc till all EOB met */ } aux = get_next_MK(); if (!RST_MK(aux)) { aborted_stream(6); } else if (verbose); reset_prediction(); clear_bits(); } /* intra-interval loop */ } else leftover = mx_size * my_size; //picture size in units of MCUs /* process till end of row without restarts */ for (i = 0; i < leftover; i++){ process_MCU(); } in_frame = 0; break; case EOI_MK: if (in_frame) aborted_stream(7); return 0; break; case COM_MK: //ffee skip_segment(); break; case EOF: aborted_stream(8); default: if ((mark & MK_MSK) == APP_MK) {//when read from FFEC, this will hold again skip_segment(); break; } if (RST_MK(mark)) { reset_prediction(); break; } /* if all else has failed ... */ aborted_stream(9); break; } /* end switch */ } while (1); return 0; }
int JpegToBmp() { unsigned int aux, mark; int n_restarts, restart_interval, leftover; /* RST check */ int i, j; /*No Need to do the file operation operation*/ #ifdef FILE_IO fi = fopen(file1, "rb"); if (fi == NULL) { return 0; } #else #ifdef INPUT_DMA // wait for input data to arrive //mk_mon_debug_info(0xFF); // read input file DRAM (via my cmem-out) ddr_input = (unsigned int*)(shared_pt_REMOTEADDR + 1024*1024*4); cmem_input_circ_buff = (unsigned int*) (mb1_cmemout0_BASEADDR); hw_dma_receive_addr((int*)(cmem_input_circ_buff + buff_sel * INPUT_READ_SIZE_INT), (void*)(&ddr_input[ddr_input_chunck_offset*INPUT_READ_SIZE_INT]), INPUT_READ_SIZE_INT, (void*)mb1_dma0_BASEADDR); ddr_input_chunck_offset++; buff_sel = CHANGE_BUFFER(buff_sel); for (i = 0 ; i < NUM_OF_INIT_BUFF_LOAD-1; i++) { while(hw_dma_status_addr( (void *) mb1_dma0_BASEADDR)); hw_dma_receive_addr((unsigned int*)(cmem_input_circ_buff + buff_sel * INPUT_READ_SIZE_INT), (void*)(&ddr_input[ddr_input_chunck_offset*INPUT_READ_SIZE_INT]), INPUT_READ_SIZE_INT, (void*)mb1_dma0_BASEADDR); ddr_input_chunck_offset++; buff_sel = CHANGE_BUFFER(buff_sel); } fi = (unsigned char *)(cmem_input_circ_buff); #else fi = (volatile unsigned int *)(shared_pt_REMOTEADDR+1024*1024*4); #endif #endif /* First find the SOI marker: */ aux = get_next_MK(fi); if (aux != SOI_MK) aborted_stream(fi); if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tFound the SOI marker!\n", ftell(fi)); #else //printf("%d:\tINFO:\tFound the SOI marker!\n", FTELL()); #endif } in_frame = 0; restart_interval = 0; for (i = 0; i < 4; i++) QTvalid[i] = 0; /* Now process segments as they appear: */ do { mark = get_next_MK(fi); //mk_mon_debug_info(0XFFF); //mk_mon_debug_info(mark); //mk_mon_debug_info(bit_counter); //mk_mon_debug_info(0XFFF); switch (mark) { case SOF_MK: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tFound the SOF marker!\n", ftell(fi)); #else //printf("%d:\tINFO:\tFound the SOF marker!\n", FTELL()); #endif } in_frame = 1; get_size(fi); /* header size, don't care */ /* load basic image parameters */ #ifdef FILE_IO fgetc(fi); /* precision, 8bit, don't care */ #else FGETC(fi); /* precision, 8bit, don't care */ #endif y_size = get_size(fi); x_size = get_size(fi); if (verbose) { #ifdef FILE_IO fprintf(stderr, "\tINFO:\tImage size is %d by %d\n", x_size, y_size); #else //printf("\tINFO:\tImage size is %d by %d\n", x_size, y_size); #endif } #ifdef FILE_IO n_comp = fgetc(fi); /* # of components */ #else n_comp = FGETC(fi); /* # of components */ #endif if (verbose) { #ifdef FILE_IO fprintf(stderr, "\tINFO:\t"); #else //printf("\tINFO:\t"); #endif switch (n_comp) { #ifdef FILE_IO case 1: fprintf(stderr, "Monochrome"); break; case 3: fprintf(stderr, "Color"); break; default: fprintf(stderr, "Not a"); break; #else case 1: //printf("Monochrome"); break; case 3: //printf("Color"); break; default: //printf("Not a"); break; #endif } #ifdef FILE_IO fprintf(stderr, " JPEG image!\n"); #else //printf(" JPEG image!\n"); #endif } for (i = 0; i < n_comp; i++) { #ifdef FILE_IO /* component specifiers */ comp[i].CID = fgetc(fi); aux = fgetc(fi); comp[i].HS = first_quad(aux); comp[i].VS = second_quad(aux); comp[i].QT = fgetc(fi); #else /* component specifiers */ comp[i].CID = FGETC(fi); aux = FGETC(fi); comp[i].HS = first_quad(aux); comp[i].VS = second_quad(aux); comp[i].QT = FGETC(fi); #endif } if ((n_comp > 1) && verbose) { #ifdef FILE_IO fprintf(stderr, "\tINFO:\tColor format is %d:%d:%d, H=%d\n", comp[0].HS * comp[0].VS, comp[1].HS * comp[1].VS, comp[2].HS * comp[2].VS, comp[1].HS); #else #if 0 //printf("\tINFO:\tColor format is %d:%d:%d, H=%d\n", comp[0].HS * comp[0].VS, comp[1].HS * comp[1].VS, comp[2].HS * comp[2].VS, comp[1].HS); #endif #endif } if (init_MCU() == -1) aborted_stream(fi); /* dimension scan buffer for YUV->RGB conversion */ /* TODO */ #if 0 FrameBuffer = (volatile unsigned char *)mk_malloc((size_t) x_size * y_size * n_comp); #else FrameBuffer = (unsigned int *) mb1_cmemout1_BASEADDR; #endif //ColorBuffer = (volatile unsigned char *)mk_malloc((size_t) MCU_sx * MCU_sy * n_comp); #if 0 FBuff = (FBlock *) mk_malloc(sizeof(FBlock)); #else MY_MK_MALLOC(FBuff,FBlock,1); #endif #if 0 PBuff = (PBlock *) mk_malloc(sizeof(PBlock)); #else MY_MK_MALLOC(PBuff,PBlock,1); #endif if ((FrameBuffer == NULL) /*|| (ColorBuffer == NULL)*/ || (FBuff == NULL) || (PBuff == NULL)) { #ifdef FILE_IO fprintf(stderr, "\tERROR:\tCould not allocate pixel storage!\n"); #else //printf("\tERROR:\tCould not allocate pixel storage!\n"); #endif } break; case DHT_MK: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tDefining Huffman Tables\n", ftell(fi)); #else //printf("%d:\tINFO:\tDefining Huffman Tables\n", FTELL()); #endif } if (load_huff_tables(fi) == -1) aborted_stream(fi); break; case DQT_MK: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tDefining Quantization Tables\n", ftell(fi)); #else //printf("%d:\tINFO:\tDefining Quantization Tables\n", FTELL()); #endif } if (load_quant_tables(fi) == -1) aborted_stream(fi); break; case DRI_MK: get_size(fi); /* skip size */ restart_interval = get_size(fi); if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tDefining Restart Interval %d\n", ftell(fi),restart_interval); #else //printf("%d:\tINFO:\tDefining Restart Interval %d\n", FTELL(), restart_interval); #endif } break; case SOS_MK: /* lots of things to do here */ //mk_mon_debug_info(01); //mk_mon_debug_info(bit_counter); //mk_mon_debug_info(02); if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tFound the SOS marker!\n", ftell(fi)); #else //printf("%d:\tINFO:\tFound the SOS marker!\n", FTELL(fi)); #endif } get_size(fi); /* don't care */ #ifdef FILE_IO aux = fgetc(fi); #else aux = FGETC(fi); #endif if (aux != (unsigned int)n_comp) { #ifdef FILE_IO fprintf(stderr, "\tERROR:\tBad component interleaving!\n"); #else //printf("\tERROR:\tBad component interleaving!\n"); #endif aborted_stream(fi); } for (i = 0; i < n_comp; i++) { #ifdef FILE_IO aux = fgetc(fi); #else aux = FGETC(fi); #endif if (aux != comp[i].CID) { #ifdef FILE_IO fprintf(stderr, "\tERROR:\tBad Component Order!\n"); #else //printf("\tERROR:\tBad Component Order!\n"); #endif aborted_stream(fi); } #ifdef FILE_IO aux = fgetc(fi); #else aux = FGETC(fi); #endif comp[i].DC_HT = first_quad(aux); comp[i].AC_HT = second_quad(aux); } get_size(fi); #ifdef FILE_IO fgetc(fi); /* skip things */ #else FGETC(fi); /* skip things */ #endif MCU_column = 0; MCU_row = 0; clear_bits(); reset_prediction(); /* main MCU processing loop here */ if (restart_interval) { n_restarts = ceil_div(mx_size * my_size, restart_interval) - 1; leftover = mx_size * my_size - n_restarts * restart_interval; /* final interval may be incomplete */ for (i = 0; i < n_restarts; i++) { for (j = 0; j < restart_interval; j++) { process_MCU(fi); } /* proc till all EOB met */ aux = get_next_MK(fi); if (!RST_MK(aux)) { #ifdef FILE_IO fprintf(stderr, "%ld:\tERROR:\tLost Sync after interval!\n", ftell(fi)); #else //printf("%d:\tERROR:\tLost Sync after interval!\n", FTELL()); #endif aborted_stream(fi); } else if (verbose) { //printf("%d:\tINFO:\tFound Restart Marker\n", FTELL()); } reset_prediction(); clear_bits(); } /* intra-interval loop */ } else { leftover = mx_size * my_size; } /* process till end of row without restarts */ for (i = 0; i < leftover; i++) { process_MCU(fi); } in_frame = 0; //mk_mon_debug_info(0XFEFE); //mk_mon_debug_info(0XFEFE); break; case EOI_MK: //mk_mon_debug_info(0XDEADBEE2); if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tFound the EOI marker!\n", ftell(fi)); #else //printf("%d:\tINFO:\tFound the EOI marker!\n", FTELL()); #endif } if (in_frame) { aborted_stream(fi); } if (verbose) { #ifdef FILE_IO fprintf(stderr, "\tINFO:\tTotal skipped bytes %d, total stuffers %d\n", passed, stuffers); #else //printf("\tINFO:\tTotal skipped bytes %d, total stuffers %d\n", passed, stuffers); #endif } #ifdef FILE_IO fclose(fi); #else /*Check if something has to be done!!*/ #endif #ifdef FILE_IO // write_bmp(file2); #else /*Need to implement the function to write in DDR*/ // write_bmp_to_ddr_1(); //printf_frame_buffer(); #endif #ifdef FILE_IO free_structures(); #else /*No Need to do anything as structures are static*/ //mk_mon_debug_info(0XDEADBEE1); //free_structures(); //mk_mon_debug_info(0XDEADBEE2); #endif /* signal to core 2 that the FIFO is initialized and can be read from. */ while(cheap_is_empty(producer) != 1) { #if 0 mk_mon_debug_info(producer->readc); mk_mon_debug_info(producer->writec); #endif } *fifo_sync_data = 0; DMA_SEND_BLOCKING((void *)fifo_sync, (int*)fifo_sync_data, sizeof(int),(void *)mb1_dma0_BASEADDR,DMA_flag); return 0; break; case COM_MK: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tSkipping comments\n", ftell(fi)); #else //printf("%d:\tINFO:\tSkipping comments\n", FTELL()); #endif } skip_segment(fi); break; case 0XD9: //case 0XD9: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tERROR:\tRan out of input data!\n", ftell(fi)); #else //printf("%d:\tERROR:\tRan out of input data!\n", FTELL()); #endif } aborted_stream(fi); default: if ((mark & MK_MSK) == APP_MK) { if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tSkipping application data\n", ftell(fi)); #else //printf("%d:\tINFO:\tSkipping application data\n", FTELL()); #endif } skip_segment(fi); break; } if (RST_MK(mark)) { reset_prediction(); break; } /* if all else has failed ... */ #ifdef FILE_IO fprintf(stderr, "%ld:\tWARNING:\tLost Sync outside scan, %d!\n", ftell(fi), mark); #else //printf("%d:\tWARNING:\tLost Sync outside scan, %d!\n", FTELL(), mark); #endif aborted_stream(fi); break; } /* end switch */ } while (1); return 0; }
void write_bmp_to_ddr() { volatile unsigned int *fpBMP; int i, j,a,b,c,d; /* Header and 3 bytes per pixel */ unsigned long ulBitmapSize = ceil_div(24*x_size, 32)*4*y_size+54; char ucaBitmapSize[4]; ucaBitmapSize[3] = (ulBitmapSize & 0xFF000000) >> 24; ucaBitmapSize[2] = (ulBitmapSize & 0x00FF0000) >> 16; ucaBitmapSize[1] = (ulBitmapSize & 0x0000FF00) >> 8; ucaBitmapSize[0] = (ulBitmapSize & 0x000000FF); /* Create bitmap file */ /* fpBMP = fopen(file2, "wb"); */ fpBMP = (volatile unsigned int *)(shared_pt_REMOTEADDR + 3); /* Write header */ /* All values are in big endian order (LSB first) */ /* BMP signature + filesize */ #if 0 *fpBMP++ = 66; *fpBMP++ = 77; *fpBMP++ = ucaBitmapSize[0]; *fpBMP++ = ucaBitmapSize[1];*fpBMP++ = ucaBitmapSize[2]; *fpBMP++ = ucaBitmapSize[3]; *fpBMP++ = 0; *fpBMP++ = 0; fpBMP++ = 0; *fpBMP++ = 0; *fpBMP++ = 54;*fpBMP++ = 0; *fpBMP++ = 0;*fpBMP++ = 0; *fpBMP++ =40; *fpBMP++ =0;*fpBMP++ = 0;*fpBMP++ = 0; *fpBMP++ =(x_size & 0x00FF);*fpBMP++ = (x_size & 0xFF00) >> 8; *fpBMP++ = 0 ; *fpBMP++ = 0;*fpBMP++ = (y_size & 0x00FF);*fpBMP++ = (y_size & 0xFF00) >> 8; *fpBMP++ = 0;*fpBMP++ = 0;*fpBMP++ = 1; *fpBMP++ = 0;*fpBMP++ = 24;*fpBMP++ = 0; *fpBMP++ =0;*fpBMP++ = 0; *fpBMP++ = 0; *fpBMP++ = 0;*fpBMP++ = 0;*fpBMP++ = 0; *fpBMP++ = 0;*fpBMP++ = 0;*fpBMP++ = 0; *fpBMP++ = 0;*fpBMP++ =0;*fpBMP++ = 0; *fpBMP++ = 0;*fpBMP++ = 0;*fpBMP++ = 0; *fpBMP++ = 0;*fpBMP++ = 0;*fpBMP++ = 0; *fpBMP++ = 0;*fpBMP++ = 0; *fpBMP++ =0; *fpBMP++ = 0;*fpBMP++ = 0;*fpBMP++ = 0; #else *fpBMP-- = pack_4char_int(66,77,ucaBitmapSize[0]); *fpBMP-- = pack_4char_int(ucaBitmapSize[1],ucaBitmapSize[2],ucaBitmapSize[3]); *fpBMP-- = pack_4char_int(0,0,0); *fpBMP-- = pack_4char_int(0,54,0); *fpBMP-- = pack_4char_int(0,0,40); *fpBMP-- = pack_4char_int(0,0,0); *fpBMP-- = pack_4char_int((x_size & 0x00FF),(x_size & 0xFF00) >> 8,0) ; *fpBMP-- = pack_4char_int(0, (y_size & 0x00FF),(y_size & 0xFF00) >> 8); *fpBMP-- = pack_4char_int(0, 0,1 ); *fpBMP-- = pack_4char_int(0, 24,0); *fpBMP-- = pack_4char_int(0, 0, 0); *fpBMP-- = pack_4char_int(0, 0, 0); *fpBMP-- = pack_4char_int(0, 0, 0); *fpBMP-- = pack_4char_int(0, 0, 0); *fpBMP-- = pack_4char_int(0, 0, 0); *fpBMP-- = pack_4char_int(0, 0, 0); *fpBMP-- = pack_4char_int(0, 0, 0); *fpBMP-- = pack_4char_int(0, 0, 0); #endif #if 1 //for (i = (y_size - 1); i >= 0; i--) for (i = 0; i < y_size; i++) { /* in bitmaps the bottom line of the image is at the beginning of the file */ for (j = 0; j < x_size; j++) { *fpBMP-- = pack_4char_int(FrameBuffer[3 * (i * x_size + j) + 0],FrameBuffer[3*(i*x_size+j)+1],FrameBuffer[3*(i*x_size+j)+2]); } #if 0 for (j = 0; j < x_size % 4; j++) *fpBMP++ =0; #endif } #else #endif }
/* This function is used to generate lp_byte_clk, dphy_reg, hs_to_lp_count, clk_lp_to_hs_count and clk_hs_to_lp_count */ bool intel_dsi_generate_phy_reg(struct intel_dsi *intel_dsi, struct mipi_phy_config *config) { u32 tlpx_ns, extra_byte_count, bitrate, tlpx_ui; u32 ui_num, ui_den; u32 prepare_cnt, exit_zero_cnt, clk_zero_cnt, trail_cnt; u32 ths_prepare_ns, tclk_trail_ns; u32 tclk_prepare_clkzero, ths_prepare_hszero; u32 bits_per_pixel = 24; struct drm_display_mode *mode = NULL; if ((intel_dsi == NULL) || (intel_dsi->lane_count == 0)) { DRM_ERROR("Invalid parameter.\n"); return false; } mode = intel_dsi->dev.dev_ops->get_modes(&intel_dsi->dev); if (!mode) { DRM_ERROR("Can't get a display mode.\n"); return false; } if (intel_dsi->pixel_format == VID_MODE_FORMAT_RGB666) bits_per_pixel = 18; else if (intel_dsi->pixel_format == VID_MODE_FORMAT_RGB565) bits_per_pixel = 16; bitrate = (mode->clock * bits_per_pixel) / intel_dsi->lane_count; switch (intel_dsi->escape_clk_div) { case 0: tlpx_ns = 50; break; case 1: tlpx_ns = 100; break; case 2: tlpx_ns = 200; break; default: tlpx_ns = 50; break; } switch (intel_dsi->lane_count) { case 1: case 2: extra_byte_count = 2; break; case 3: extra_byte_count = 4; break; case 4: default: extra_byte_count = 3; break; } /* * ui(s) = 1/f [f in hz] * ui(ns) = 10^9/f*10^6 [f in Mhz] -> 10^3/f(Mhz) * * LP byte clock = TLPX/8ui * * Since txddrclkhs_i is 2xUI, the count values programmed in * DPHY param register are divided by 2 * */ /* in Kbps */ ui_num = bitrate; ui_den = NS_MHZ_RATIO; tclk_prepare_clkzero = config->tclk_prepare_clkzero; ths_prepare_hszero = config->ths_prepare_hszero; /* B060 */ intel_dsi->lp_byte_clk = ceil_div(tlpx_ns * ui_num, 8 * ui_den); /* count values in UI = (ns value) * (bitrate / (2 * 10^6)) */ /* prepare count */ ths_prepare_ns = (config->ths_prepare > config->tclk_prepare) ? config->ths_prepare : config->tclk_prepare; prepare_cnt = ceil_div(ths_prepare_ns * ui_num, ui_den * 2); /* exit zero count */ exit_zero_cnt = ceil_div( (ths_prepare_hszero - ths_prepare_ns) * ui_num, ui_den * 2 ); /* * Exit zero is unified val ths_zero and ths_exit * minimum value for ths_exit = 110ns * min (exit_zero_cnt * 2) = 110/UI * exit_zero_cnt = 55/UI */ if (exit_zero_cnt < (55 * ui_num / ui_den)) if ((55 * ui_num) % ui_den) exit_zero_cnt += 1; /* clk zero count */ clk_zero_cnt = ceil_div( (tclk_prepare_clkzero - ths_prepare_ns) * ui_num, 2 * ui_den); /* trail count */ tclk_trail_ns = (config->tclk_trail > config->ths_trail) ? config->tclk_trail : config->ths_trail; trail_cnt = ceil_div(tclk_trail_ns * ui_num, 2 * ui_den); if (prepare_cnt > PREPARE_CNT_MAX || exit_zero_cnt > EXIT_ZERO_CNT_MAX || clk_zero_cnt > CLK_ZERO_CNT_MAX || trail_cnt > TRAIL_CNT_MAX) DRM_DEBUG_DRIVER("Values crossing maximum limits\n"); if (prepare_cnt > PREPARE_CNT_MAX) prepare_cnt = PREPARE_CNT_MAX; if (exit_zero_cnt > EXIT_ZERO_CNT_MAX) exit_zero_cnt = EXIT_ZERO_CNT_MAX; if (clk_zero_cnt > CLK_ZERO_CNT_MAX) clk_zero_cnt = CLK_ZERO_CNT_MAX; if (trail_cnt > TRAIL_CNT_MAX) trail_cnt = TRAIL_CNT_MAX; /* B080 */ intel_dsi->dphy_reg = exit_zero_cnt << 24 | trail_cnt << 16 | clk_zero_cnt << 8 | prepare_cnt; /* * LP to HS switch count = 4TLPX + PREP_COUNT * 2 + EXIT_ZERO_COUNT * 2 * + 10UI + Extra Byte Count * * HS to LP switch count = THS-TRAIL + 2TLPX + Extra Byte Count * Extra Byte Count is calculated according to number of lanes. * High Low Switch Count is the Max of LP to HS and * HS to LP switch count * */ tlpx_ui = ceil_div(tlpx_ns * ui_num, ui_den); /* B044 */ intel_dsi->hs_to_lp_count = ceil_div( 4 * tlpx_ui + prepare_cnt * 2 + exit_zero_cnt * 2 + 10, 8); intel_dsi->hs_to_lp_count += extra_byte_count; /* B088 */ /* LP -> HS for clock lanes * LP clk sync + LP11 + LP01 + tclk_prepare + tclk_zero + * extra byte count * 2TPLX + 1TLPX + 1 TPLX(in ns) + prepare_cnt * 2 + clk_zero_cnt * * 2(in UI) + extra byte count * In byteclks = (4TLPX + prepare_cnt * 2 + clk_zero_cnt *2 (in UI)) / * 8 + extra byte count */ intel_dsi->clk_lp_to_hs_count = ceil_div( 4 * tlpx_ui + prepare_cnt * 2 + clk_zero_cnt * 2, 8); intel_dsi->clk_lp_to_hs_count += extra_byte_count; /* HS->LP for Clock Lanes * Low Power clock synchronisations + 1Tx byteclk + tclk_trail + * Extra byte count * 2TLPX + 8UI + (trail_count*2)(in UI) + Extra byte count * In byteclks = (2*TLpx(in UI) + trail_count*2 +8)(in UI)/8 + * Extra byte count */ intel_dsi->clk_hs_to_lp_count = ceil_div(2 * tlpx_ui + trail_cnt * 2 + 8, 8); intel_dsi->clk_hs_to_lp_count += extra_byte_count; DRM_INFO("HS to LP Count 0x%x\n", intel_dsi->hs_to_lp_count); DRM_INFO("LP Byte Clock %d\n", intel_dsi->lp_byte_clk); DRM_INFO("LP to HS Clock Count 0x%x\n", intel_dsi->clk_lp_to_hs_count); DRM_INFO("HS to LP Clock Count 0x%x\n", intel_dsi->clk_hs_to_lp_count); DRM_INFO("B060 = 0x%Xx, B080 = 0x%x, B044 = 0x%x, B088 = 0x%x\n", intel_dsi->lp_byte_clk, intel_dsi->dphy_reg, intel_dsi->hs_to_lp_count, (intel_dsi->clk_lp_to_hs_count << LP_HS_SSW_CNT_SHIFT) | (intel_dsi->clk_hs_to_lp_count << HS_LP_PWR_SW_CNT_SHIFT)); kfree(mode); return true; }