static void convert_mat(struct W2XConv *conv, cv::Mat &image, int denoise_level, double scale, int dst_w, int dst_h, int blockSize, enum w2xc::image_format fmt) { if (denoise_level != 0) { apply_denoise(conv, image, denoise_level, blockSize, fmt); } if (scale != 1.0) { // calculate iteration times of 2x scaling and shrink ratio which will use at last int iterTimesTwiceScaling = static_cast<int>(std::ceil(std::log2(scale))); double shrinkRatio = 0.0; if (static_cast<int>(scale) != std::pow(2, iterTimesTwiceScaling)) { shrinkRatio = scale / std::pow(2.0, static_cast<double>(iterTimesTwiceScaling)); } apply_scale(conv, image, iterTimesTwiceScaling, blockSize, fmt); if (shrinkRatio != 0.0) { cv::Size lastImageSize = image.size(); lastImageSize.width = dst_w; lastImageSize.height = dst_h; cv::resize(image, image, lastImageSize, 0, 0, cv::INTER_LINEAR); } } }
void input_bb (struct lto_input_block *ib, enum LTO_tags tag, struct data_in *data_in, struct function *fn, int count_materialization_scale) { unsigned int index; basic_block bb; gimple_stmt_iterator bsi; /* This routine assumes that CFUN is set to FN, as it needs to call basic GIMPLE routines that use CFUN. */ gcc_assert (cfun == fn); index = streamer_read_uhwi (ib); bb = BASIC_BLOCK_FOR_FUNCTION (fn, index); bb->count = apply_scale (streamer_read_gcov_count (ib), count_materialization_scale); bb->frequency = streamer_read_hwi (ib); bb->flags = streamer_read_hwi (ib); /* LTO_bb1 has statements. LTO_bb0 does not. */ if (tag == LTO_bb0) return; bsi = gsi_start_bb (bb); tag = streamer_read_record_start (ib); while (tag) { gimple stmt = input_gimple_stmt (ib, data_in, fn, tag); gsi_insert_after (&bsi, stmt, GSI_NEW_STMT); /* After the statement, expect a 0 delimiter or the EH region that the previous statement belongs to. */ tag = streamer_read_record_start (ib); lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null); if (tag == LTO_eh_region) { HOST_WIDE_INT region = streamer_read_hwi (ib); gcc_assert (region == (int) region); add_stmt_to_eh_lp (stmt, region); } tag = streamer_read_record_start (ib); } tag = streamer_read_record_start (ib); while (tag) { input_phi (ib, bb, data_in, fn); tag = streamer_read_record_start (ib); } }
unsigned int execute_fixup_cfg (void) { basic_block bb; gimple_stmt_iterator gsi; int todo = gimple_in_ssa_p (cfun) ? TODO_verify_ssa : 0; gcov_type count_scale; edge e; edge_iterator ei; count_scale = GCOV_COMPUTE_SCALE (cgraph_get_node (current_function_decl)->count, ENTRY_BLOCK_PTR->count); ENTRY_BLOCK_PTR->count = cgraph_get_node (current_function_decl)->count; EXIT_BLOCK_PTR->count = apply_scale (EXIT_BLOCK_PTR->count, count_scale); FOR_EACH_EDGE (e, ei, ENTRY_BLOCK_PTR->succs) e->count = apply_scale (e->count, count_scale); FOR_EACH_BB (bb) { bb->count = apply_scale (bb->count, count_scale); for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { gimple stmt = gsi_stmt (gsi); tree decl = is_gimple_call (stmt) ? gimple_call_fndecl (stmt) : NULL; if (decl) { int flags = gimple_call_flags (stmt); if (flags & (ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE)) { if (gimple_purge_dead_abnormal_call_edges (bb)) todo |= TODO_cleanup_cfg; if (gimple_in_ssa_p (cfun)) { todo |= TODO_update_ssa | TODO_cleanup_cfg; update_stmt (stmt); } } if (flags & ECF_NORETURN && fixup_noreturn_call (stmt)) todo |= TODO_cleanup_cfg; } if (maybe_clean_eh_stmt (stmt) && gimple_purge_dead_eh_edges (bb)) todo |= TODO_cleanup_cfg; } FOR_EACH_EDGE (e, ei, bb->succs) e->count = apply_scale (e->count, count_scale); /* If we have a basic block with no successors that does not end with a control statement or a noreturn call end it with a call to __builtin_unreachable. This situation can occur when inlining a noreturn call that does in fact return. */ if (EDGE_COUNT (bb->succs) == 0) { gimple stmt = last_stmt (bb); if (!stmt || (!is_ctrl_stmt (stmt) && (!is_gimple_call (stmt) || (gimple_call_flags (stmt) & ECF_NORETURN) == 0))) { stmt = gimple_build_call (builtin_decl_implicit (BUILT_IN_UNREACHABLE), 0); gimple_stmt_iterator gsi = gsi_last_bb (bb); gsi_insert_after (&gsi, stmt, GSI_NEW_STMT); } } } if (count_scale != REG_BR_PROB_BASE) compute_function_frequency (); /* We just processed all calls. */ if (cfun->gimple_df) vec_free (MODIFIED_NORETURN_CALLS (cfun)); /* Dump a textual representation of the flowgraph. */ if (dump_file) gimple_dump_cfg (dump_file, dump_flags); if (current_loops && (todo & TODO_cleanup_cfg)) loops_state_set (LOOPS_NEED_FIXUP); return todo; }
void hpgs_reader_set_default_transformation (hpgs_reader *reader) { // transformation matrix for user to PS coordinates. int angle = reader->y_size >= reader->x_size ? 90 : 0; hpgs_point p1 = reader->P1; hpgs_point p2 = reader->P2; angle += reader->rotation; if ((angle % 180) == 90) { p2.y -= p1.y; p1.y = 0.0; } reader->world_matrix.dx = reader->frame_x + p1.x * HP_TO_PT; reader->world_matrix.dy = reader->frame_y + p1.y * HP_TO_PT; switch (angle % 360) { case 90: reader->world_matrix.mxx = 0.0; reader->world_matrix.mxy = -HP_TO_PT; reader->world_matrix.myx = HP_TO_PT; reader->world_matrix.myy = 0.0; break; case 180: reader->world_matrix.mxx = -HP_TO_PT; reader->world_matrix.mxy = 0.0; reader->world_matrix.myx = 0.0; reader->world_matrix.myy = -HP_TO_PT; break; case 270: reader->world_matrix.mxx = 0.0; reader->world_matrix.mxy = HP_TO_PT; reader->world_matrix.myx = -HP_TO_PT; reader->world_matrix.myy = 0.0; break; default: // 0 reader->world_matrix.mxx = HP_TO_PT; reader->world_matrix.mxy = 0.0; reader->world_matrix.myx = 0.0; reader->world_matrix.myy = HP_TO_PT; } #ifdef HPGS_DEBUG_XFORM hpgs_log("xform: %10g %10g %10g\n",reader->world_matrix.dx,reader->world_matrix.mxx,reader->world_matrix.mxy); hpgs_log("xform: %10g %10g %10g\n",reader->world_matrix.dy,reader->world_matrix.myx,reader->world_matrix.myy); #endif apply_scale(reader,&p1,&p2); reader->world_scale = sqrt (fabs(reader->world_matrix.mxx * reader->world_matrix.myy - reader->world_matrix.mxy * reader->world_matrix.myx ) ); // finally transform from model space to the page. hpgs_matrix_concat(&reader->total_matrix,&reader->page_matrix,&reader->world_matrix); reader->total_scale = reader->page_scale * reader->world_scale; }
int w2xconv_convert(struct W2XConv *conv, const cv::Mat& src, cv::Mat& image_dst, int denoise_level, double scale, int blockSize) { double time_start = getsec(); bool is_rgb = (conv->impl->scale2_models[0]->getNInputPlanes() == 3); bool png_rgb = true; float bkgd_r = 1.0f; float bkgd_g = 1.0f; float bkgd_b = 1.0f; cv::Mat image_src = src.clone(); enum w2xc::image_format fmt; int src_depth = CV_MAT_DEPTH(image_src.type()); int src_cn = CV_MAT_CN(image_src.type()); cv::Mat image = cv::Mat(image_src.size(), CV_32FC3); cv::Mat alpha; if (is_rgb) { if (png_rgb) { if (src_cn == 4) { // save alpha alpha = cv::Mat(image_src.size(), CV_32FC1); if (src_depth == CV_16U) { preproc_rgba2rgb<unsigned short, 65535, 2, 0>(&image, &alpha, &image_src, bkgd_r, bkgd_g, bkgd_b); } else { preproc_rgba2rgb<unsigned char, 255, 2, 0>(&image, &alpha, &image_src, bkgd_r, bkgd_g, bkgd_b); } } else { preproc_rgb2rgb<unsigned short, 65535, 2, 0>(&image, &image_src); } } else { preproc_rgb2rgb<unsigned char, 255, 2, 0>(&image, &image_src); } fmt = w2xc::IMAGE_RGB_F32; } else { //if (png_rgb) { // if (src_cn == 4) { // // save alpha // alpha = cv::Mat(image_src.size(), CV_32FC1); // if (src_depth == CV_16U) { // preproc_rgba2yuv<unsigned short, 65535, 2, 0>(&image, &alpha, &image_src, // bkgd_r, bkgd_g, bkgd_b); // } else { // preproc_rgba2yuv<unsigned char, 255, 2, 0>(&image, &alpha, &image_src, // bkgd_r, bkgd_g, bkgd_b); // } // } else { // preproc_rgb2yuv<unsigned short, 65535, 2, 0>(&image, &image_src); // } //} else { // preproc_rgb2yuv<unsigned char, 255, 2, 0>(&image, &image_src); //} if (image_src.channels() > 1) cv::cvtColor(image_src, image, CV_RGB2YUV); else image = image_src.clone(); fmt = w2xc::IMAGE_Y; } if (denoise_level != 0) { apply_denoise(conv, image, denoise_level, blockSize, fmt); } if (scale != 1.0) { // calculate iteration times of 2x scaling and shrink ratio which will use at last int iterTimesTwiceScaling = static_cast<int>(std::ceil(std::log2(scale))); double shrinkRatio = 0.0; if (static_cast<int>(scale) != std::pow(2, iterTimesTwiceScaling)) { shrinkRatio = scale / std::pow(2.0, static_cast<double>(iterTimesTwiceScaling)); } apply_scale(conv, image, iterTimesTwiceScaling, blockSize, fmt); if (shrinkRatio != 0.0) { cv::Size lastImageSize = image.size(); lastImageSize.width = static_cast<int>(static_cast<double>(lastImageSize.width * shrinkRatio)); lastImageSize.height = static_cast<int>(static_cast<double>(lastImageSize.height * shrinkRatio)); cv::resize(image, image, lastImageSize, 0, 0, cv::INTER_LINEAR); } } if (alpha.empty()) { //image_dst = cv::Mat(image.size(), CV_MAKETYPE(src_depth,3)); //if (is_rgb) { // if (src_depth == CV_16U) { // postproc_rgb2rgb<unsigned short, 65535, 2, 0>(&image_dst, &image); // } else { // postproc_rgb2rgb<unsigned char, 255, 2, 0>(&image_dst, &image); // } //} else { // if (src_depth == CV_16U) { // postproc_yuv2rgb<unsigned short, 65535, 0, 2>(&image_dst, &image); // } else { // postproc_yuv2rgb<unsigned char, 255, 0, 2>(&image_dst, &image); // } //} image_dst = image.clone(); } else { image_dst = cv::Mat(image.size(), CV_MAKETYPE(src_depth,4)); if (image.size() != alpha.size()) { cv::resize(alpha, alpha, image.size(), 0, 0, cv::INTER_LINEAR); } image_dst = image.clone(); //cv::cvtColor(image, image_dst, ) //if (is_rgb) { // if (src_depth == CV_16U) { // postproc_rgb2rgba<unsigned short, 65535, 2, 0>(&image_dst, &image, &alpha, bkgd_r, bkgd_g, bkgd_b); // } else { // postproc_rgb2rgba<unsigned char, 255, 2, 0>(&image_dst, &image, &alpha, bkgd_r, bkgd_g, bkgd_b); // } //} else { // if (src_depth == CV_16U) { // postproc_yuv2rgba<unsigned short, 65535, 0, 2>(&image_dst, &image, &alpha, bkgd_r, bkgd_g, bkgd_b); // } else { // postproc_yuv2rgba<unsigned char, 255, 0, 2>(&image_dst, &image, &alpha, bkgd_r, bkgd_g, bkgd_b); // } //} } double time_end = getsec(); conv->flops.process_sec += time_end - time_start; //printf("== %f == \n", conv->impl->env.transfer_wait); return 0; }