Пример #1
0
//! Writes a result line to a file
void RegistrationResult::write(std::ostream &out) const {
  algebra::VectorD<4> quaternion = R_.get_quaternion();
  char c = '|';
  out << get_image_index() << c << get_projection_index() << c << get_phi() << c
      << get_theta() << c << get_psi() << c << quaternion[0] << c
      << quaternion[1] << c << quaternion[2] << c << quaternion[3] << c
      << get_shift()[0] << c << get_shift()[1] << c << get_ccc() << c
      << std::endl;
}
Пример #2
0
void Overlap::get_shift(Image r,Image g,Image b)
{
    if (max2(max3(r.n_rows,g.n_rows,b.n_rows),r.n_cols)>MAX_IM_SIZE)
    {
        get_shift(bilin_interpolation(r,r.n_rows/SIZE_CHANGE,r.n_cols/SIZE_CHANGE),
                  bilin_interpolation(g,g.n_rows/SIZE_CHANGE,g.n_cols/SIZE_CHANGE),
                  bilin_interpolation(b,b.n_rows/SIZE_CHANGE,b.n_cols/SIZE_CHANGE));
        green_i_shift*=SIZE_CHANGE;
        green_j_shift*=SIZE_CHANGE;
        blue_i_shift*=SIZE_CHANGE;
        blue_j_shift*=SIZE_CHANGE;
        fill_chanels(r,g,b);
        standart_deviation(red,green,h_r,h_g,green_i_shift,green_j_shift);
        green_i_shift=min_i_sh;
        green_j_shift=min_j_sh;
        standart_deviation(red,blue,h_r,h_b,blue_i_shift,blue_j_shift);
        blue_i_shift=min_i_sh;
        blue_j_shift=min_j_sh;
    }
    else
    {
        fill_chanels(r,g,b);
        standart_deviation(red,green,h_r,h_g,0,0);
        green_i_shift=min_i_sh;
        green_j_shift=min_j_sh;
        standart_deviation(red,blue,h_r,h_b,0,0);
        blue_i_shift=min_i_sh;
        blue_j_shift=min_j_sh;
    }
}
Пример #3
0
void RegistrationResult::show(std::ostream &out) const {
  algebra::VectorD<4> quaternion = R_.get_quaternion();
  out << "Name: " << get_name() << " Image index: " << get_image_index()
      << " Projection index: " << get_projection_index()
      << " (Phi,Theta,Psi) = ( " << get_phi() << " , " << get_theta() << " , "
      << get_psi() << " ) | Shift (x,y) " << get_shift()
      << " CCC = " << get_ccc() << " Quaternion " << quaternion;
}
static uint32_t assemble_shift(instruction_t *instr)
{
    /* PRE:  Take a valid and legal pointer to an instruction.
     * POST: Check the presence of the shift and in case it applies it. */

    assert (instr != NULL);
   
    /* The offset is a register so we set the BIT_I: */
    uint32_t shift_result = 0x0000000;
    uint32_t BIT_I        = 1 << 25;
    uint8_t rm            = 0;
 
    if (instr->no_of_ops > 2)
        rm = get_reg_int(instr->ops[2]);
    else
        rm = get_reg_int(instr->ops[1] + 4);
 
    regex_t rec_shift_reg;
    regex_t rec_shift_exp;
    regmatch_t shift_pos[1];
   
    /* We use regex to check if the instructions contains a shift and to save 
     * the index of the start and end of the shift: */
    check_and_compile_regex(&rec_shift_reg, RE_SHIFT_REG, REG_EXTENDED);
    check_and_compile_regex(&rec_shift_exp, RE_SHIFT_EXP, REG_EXTENDED);
 
    int reg_match = !regexec(&rec_shift_reg, instr->instr_str, 1, shift_pos, 0);
    int exp_match = !regexec(&rec_shift_exp, instr->instr_str, 1, shift_pos, 0);
 
    /* Check if we have a shift with register or a shift with expression */
    if (reg_match || exp_match) {
 
        int start_shift = shift_pos->rm_so;
        int end_shift = shift_pos->rm_eo;
 
        char *shift_name
            = cut_string(instr->instr_str, start_shift, start_shift + 3);
 
        uint32_t reg_or_exp
            = (reg_match ? reg_to_int : string_to_int)
                (cut_string(instr->instr_str, start_shift + 3, end_shift));
 
        regfree(&rec_shift_reg);
        regfree(&rec_shift_exp);
 
        /* Calculate the shift given the shift name, a string containing the 
         * value of the register or the expression shifted, the index of rm, 
         * and an int to indicate if the shift use a register (1) or an 
         * expression (0) */
        shift_result = get_shift(shift_name, reg_or_exp, rm, reg_match);
    }
   
    regfree(&rec_shift_reg);
    regfree(&rec_shift_exp);
 
    /* If there is not shift we return the index of rm */
    return shift_result | BIT_I | rm;
}
Пример #5
0
uint32_t InputEventKey::get_scancode_with_modifiers() const {

	uint32_t sc = scancode;
	if (get_control())
		sc |= KEY_MASK_CTRL;
	if (get_alt())
		sc |= KEY_MASK_ALT;
	if (get_shift())
		sc |= KEY_MASK_SHIFT;
	if (get_metakey())
		sc |= KEY_MASK_META;

	return sc;
}
Пример #6
0
String InputEventKey::as_text() const {

	String kc = keycode_get_string(scancode);
	if (kc == String())
		return kc;

	if (get_metakey()) {
		kc = find_keycode_name(KEY_META) + ("+" + kc);
	}
	if (get_alt()) {
		kc = find_keycode_name(KEY_ALT) + ("+" + kc);
	}
	if (get_shift()) {
		kc = find_keycode_name(KEY_SHIFT) + ("+" + kc);
	}
	if (get_control()) {
		kc = find_keycode_name(KEY_CONTROL) + ("+" + kc);
	}
	return kc;
}
Пример #7
0
static int jacosub_read_header(AVFormatContext *s)
{
    AVBPrint header;
    AVIOContext *pb = s->pb;
    char line[JSS_MAX_LINESIZE];
    JACOsubContext *jacosub = s->priv_data;
    int shift_set = 0; // only the first shift matters
    int merge_line = 0;
    int i, ret;

    AVStream *st = avformat_new_stream(s, NULL);
    if (!st)
        return AVERROR(ENOMEM);
    avpriv_set_pts_info(st, 64, 1, 100);
    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
    st->codec->codec_id   = AV_CODEC_ID_JACOSUB;

    jacosub->timeres = 30;

    av_bprint_init(&header, 1024+FF_INPUT_BUFFER_PADDING_SIZE, 4096);

    while (!avio_feof(pb)) {
        int cmd_len;
        const char *p = line;
        int64_t pos = avio_tell(pb);
        int len = ff_get_line(pb, line, sizeof(line));

        p = jss_skip_whitespace(p);

        /* queue timed line */
        if (merge_line || timed_line(p)) {
            AVPacket *sub;

            sub = ff_subtitles_queue_insert(&jacosub->q, line, len, merge_line);
            if (!sub)
                return AVERROR(ENOMEM);
            sub->pos = pos;
            merge_line = len > 1 && !strcmp(&line[len - 2], "\\\n");
            continue;
        }

        /* skip all non-compiler commands and focus on the command */
        if (*p != '#')
            continue;
        p++;
        i = get_jss_cmd(p[0]);
        if (i == -1)
            continue;

        /* trim command + spaces */
        cmd_len = strlen(cmds[i]);
        if (av_strncasecmp(p, cmds[i], cmd_len) == 0)
            p += cmd_len;
        else
            p++;
        p = jss_skip_whitespace(p);

        /* handle commands which affect the whole script */
        switch (cmds[i][0]) {
        case 'S': // SHIFT command affect the whole script...
            if (!shift_set) {
                jacosub->shift = get_shift(jacosub->timeres, p);
                shift_set = 1;
            }
            av_bprintf(&header, "#S %s", p);
            break;
        case 'T': // ...but must be placed after TIMERES
            jacosub->timeres = strtol(p, NULL, 10);
            if (!jacosub->timeres)
                jacosub->timeres = 30;
            else
                av_bprintf(&header, "#T %s", p);
            break;
        }
    }

    /* general/essential directives in the extradata */
    ret = avpriv_bprint_to_extradata(st->codec, &header);
    if (ret < 0)
        return ret;

    /* SHIFT and TIMERES affect the whole script so packet timing can only be
     * done in a second pass */
    for (i = 0; i < jacosub->q.nb_subs; i++) {
        AVPacket *sub = &jacosub->q.subs[i];
        read_ts(jacosub, sub->data, &sub->pts, &sub->duration);
    }
    ff_subtitles_queue_finalize(&jacosub->q);

    return 0;
}
Пример #8
0
 basic_packed_pixel_proxy(reference ref, size_t index)
     : m_ref(ref),
       m_shift(get_shift(index))
 {
 }
Пример #9
0
///Сохранение и уменьшение скринота в массив - сохранение изображения
//1)Снятие скриншота с сохранением указателя
//2)Уменьшение изображения по указателю
//3)Сохранение изображение
void get_screen (string filenom)
{
    Display *disp;
    Window root;
    XWindowAttributes watts;
    XImage *image;
    cairo_surface_t *surface;
    unsigned int width;
    unsigned int height;
    int stride;
    /*Глобальная перменная - замер времени выполнения участков кода*/

    disp = XOpenDisplay(NULL);
    root = DefaultRootWindow(disp);
    //Взять скрин с окна с именем в заголовке "FCEUX 2.2.1"
    root = windowWithName(disp, root,"FCEUX 2.2.1");
    XGetWindowAttributes(disp, root, &watts);
    width = watts.width;
    height = watts.height;

    image = XGetImage(disp, root, watts.x, watts.y, width, height, AllPlanes,ZPixmap);
    stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, width);
    unsigned char *datapng = (unsigned char *) malloc (stride * height);
    int red_shift= get_shift(image->red_mask);
    int green_shift= get_shift(image->green_mask);
    int blue_shift= get_shift(image->blue_mask);


    //Массив с пикселями изображения
    //map< int ,map <int , map < int, unsigned char > > > in;

    for (int y = 0; y < height; ++y)
    {
        for (int x = 0; x < width; ++x) {
            unsigned long pixel = XGetPixel(image, x, y);
            unsigned char red = (image->red_mask & pixel) >> red_shift;
            unsigned char green = (image->green_mask & pixel) >> green_shift;
            unsigned char blue = (image->blue_mask & pixel) >> blue_shift;
            /*
            in[y][x][0]=blue;
            in[y][x][1]=green;
            in[y][x][2]=red;
            */
            //Буффер записи в файл
            datapng[y * stride + x * 4 + 0]=blue;
            datapng[y * stride + x * 4 + 1]=green;
            datapng[y * stride + x * 4 + 2]=red;
            in[y][x][0]=red;
            in[y][x][1]=green;
            in[y][x][2]=blue;
        }
    }

    const float tx = float(width) / nwidth;
    const float ty = float(height) / nheight;
    const int components = 3;
    const int bytes_per_row = width * components;

    const int components2 = components;
    const int bytes_per_row2=width * components;

    int a, b, c, d, index;
    unsigned char Ca, Cb, Cc;
    unsigned char C[5];
    unsigned char d0, d2, d3, a0, a1, a2, a3;

    for (int i = 0; i < nheight; ++i)
    {
        for (int j = 0; j < nwidth; ++j)
        {

            const int x = int(tx * j);
            const int y = int(ty * i);
            const float dx = tx * j - x;
            const float dy = ty * i - y;

            index = y * bytes_per_row + x * components;
            a = y * bytes_per_row + (x + 1) * components;
            b = (y + 1) * bytes_per_row + x * components;
            c = (y + 1) * bytes_per_row + (x + 1) * components;

            for (int k = 0; k < 3; ++k)
            {
                for (int jj = 0; jj <= 3; ++jj)
                {
                    //Беруться пиксели из входящего изображения
                    d0 = in[(y - 1 + jj)][(x - 1)][k] - in[(y - 1 + jj)][x][k];

                    d2 = in[(y - 1 + jj)][(x + 1)][k] - in[(y - 1 + jj)][x][k];

                    d3 = in[(y - 1 + jj)][(x + 2)][k] - in[(y - 1 + jj)][x][k];

                    a0 = in[(y - 1 + jj)][x][k];

                    //Вычисляются параметры
                    a1 = -1.0 / 3 * d0 + d2 - 1.0 / 6 * d3;
                    a2 = 1.0 / 2 * d0 + 1.0 / 2 * d2;
                    a3 = -1.0 / 6 * d0 - 1.0 / 2 * d2 + 1.0 / 6 * d3;
                    C[jj] = a0 + a1 * dx + a2 * dx * dx + a3 * dx * dx * dx;

                    d0 = C[0] - C[1];
                    d2 = C[2] - C[1];
                    d3 = C[3] - C[1];
                    a0 = C[1];
                    a1 = -1.0 / 3 * d0 + d2 -1.0 / 6 * d3;
                    a2 = 1.0 / 2 * d0 + 1.0 / 2 * d2;
                    a3 = -1.0 / 6 * d0 - 1.0 / 2 * d2 + 1.0 / 6 * d3;
                    Cc = a0 + a1 * dy + a2 * dy * dy + a3* dy * dy * dy;

                    //Буффер записи в файл
                    // datapng[i * stride + j * 4 + k]=Cc;
                    //Запись в массив изображения
                    pixels_image[i][j][k]=(int)Cc;

                }
            }
        }
    }

    //Сохранение изображения

    string filename;
    filename="output/"+filenom+".png";
    const char*  filename2=filename.c_str();
    surface = cairo_image_surface_create_for_data(
                  datapng,
                  CAIRO_FORMAT_RGB24,
                  width, height,
                  stride);
    cairo_surface_write_to_png(
        surface,
        filename2
    );
    cairo_surface_destroy(surface);
    free(datapng);

}
Пример #10
0
static int jacosub_read_header(AVFormatContext *s)
{
    AVBPrint header;
    AVIOContext *pb = s->pb;
    char line[JSS_MAX_LINESIZE];
    JACOsubContext *jacosub = s->priv_data;
    int shift_set = 0; // only the first shift matters
    int merge_line = 0;
    int i;

    AVStream *st = avformat_new_stream(s, NULL);
    if (!st)
        return AVERROR(ENOMEM);
    avpriv_set_pts_info(st, 64, 1, 100);
    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
    st->codec->codec_id   = CODEC_ID_JACOSUB;

    jacosub->timeres = 30;

    av_bprint_init(&header, 1024+FF_INPUT_BUFFER_PADDING_SIZE, 4096);

    while (!url_feof(pb)) {
        int cmd_len;
        const char *p = line;
        int64_t pos = avio_tell(pb);

        ff_get_line(pb, line, sizeof(line));

        p = jss_skip_whitespace(p);

        /* queue timed line */
        if (merge_line || timed_line(p)) {
            SubEntry *subs, *sub;
            const int len = strlen(line);

            if (merge_line) {
                char *tmp;
                const int old_len = strlen(sub->line);

                sub = &subs[jacosub->nsub];
                tmp = av_realloc(sub->line, old_len + len + 1);
                if (!tmp)
                    return AVERROR(ENOMEM);
                sub->line = tmp;
                strcpy(sub->line + old_len, line);
            } else {
                subs = av_realloc(jacosub->subs,
                                  sizeof(*jacosub->subs) * (jacosub->nsub+1));
                if (!subs)
                    return AVERROR(ENOMEM);
                jacosub->subs = subs;
                sub = &subs[jacosub->nsub];
                sub->pos  = pos;
                sub->line = av_strdup(line);
                if (!sub->line)
                    return AVERROR(ENOMEM);
            }
            merge_line = len > 1 && !strcmp(&line[len - 2], "\\\n");
            if (!merge_line)
                jacosub->nsub++;
            continue;
        }

        /* skip all non-compiler commands and focus on the command */
        if (*p != '#')
            continue;
        p++;
        i = get_jss_cmd(p[0]);
        if (i == -1)
            continue;

        /* trim command + spaces */
        cmd_len = strlen(cmds[i]);
        if (av_strncasecmp(p, cmds[i], cmd_len) == 0)
            p += cmd_len;
        else
            p++;
        p = jss_skip_whitespace(p);

        /* handle commands which affect the whole script */
        switch (cmds[i][0]) {
        case 'S': // SHIFT command affect the whole script...
            if (!shift_set) {
                jacosub->shift = get_shift(jacosub->timeres, p);
                shift_set = 1;
            }
            av_bprintf(&header, "#S %s", p);
            break;
        case 'T': // ...but must be placed after TIMERES
            jacosub->timeres = strtol(p, NULL, 10);
            av_bprintf(&header, "#T %s", p);
            break;
        }
    }

    /* general/essential directives in the extradata */
    av_bprint_finalize(&header, (char **)&st->codec->extradata);
    st->codec->extradata_size = header.len + 1;

    /* SHIFT and TIMERES affect the whole script so packet timing can only be
     * done in a second pass */
    for (i = 0; i < jacosub->nsub; i++) {
        SubEntry *sub = &jacosub->subs[i];
        read_ts(jacosub, sub->line, &sub->start, &sub->end);
    }
    qsort(jacosub->subs, jacosub->nsub, sizeof(*jacosub->subs), cmp_timed_sub);

    return 0;
}
Пример #11
0
Image Overlap::shift_the_im(Image r,Image g,Image b)
{
    get_shift(r,g,b);
    return shifted_image(r,g,b);
}