Esempio n. 1
0
int main(int argc, char *argv[])
{
	gzFile fp;
	kstream_t *ks;
	khash_t(s) *hash;
	mask32_t *q = 0;
	kstring_t *str;
	int i, dret, c, last = 0;

	while ((c = getopt(argc, argv, "")) >= 0) {
	}
	if (argc <= optind + 1) {
		fprintf(stderr, "Usage: uniq-dist <in.mask.fa> <in-sorted.list>\n");
		return 1;
	}

	str = (kstring_t*)calloc(1, sizeof(kstring_t));
	fprintf(stderr, "[uniq-dist] loading mask...\n");
	hash = load_mask(argv[optind]);
	fp = gzopen(argv[optind+1], "r");
	ks = ks_init(fp);
	fprintf(stderr, "[uniq-dist] calculating unique distance...\n");
	while (ks_getuntil(ks, 0, str, &dret) >= 0) {
		khint_t k;
		mask32_t *p;
		int pos;
		k = kh_get(s, hash, str->s);
		p = (k != kh_end(hash))? &kh_val(hash, k) : 0;
		ks_getuntil(ks, 0, str, &dret);
		pos = atoi(str->s) - 1;
		if (p && pos >= 0 && pos < p->ori_len) {
			if (p != q) q = p; // change of reference
			else {
				if (last >= pos) {
					fprintf(stderr, "[uniq-dist] out of order: %s:%d <= %d\n", kh_key(hash, k), pos+1, last+1);
				} else {
					for (i = last, c = 0; i < pos; ++i)
						if (p->mask[i/32] & 1u<<i%32) ++c;
					if (last > 0) printf("%s\t%d\t%d\t%d\n", kh_key(hash, k), last, pos, c);
				}
			}
			last = pos;
		}
		if (dret != '\n')
			while ((c = ks_getc(ks)) != -1 && c != '\n');
	}
	ks_destroy(ks);
	gzclose(fp);
	free(str->s); free(str);
	// hash table is not freed...
	return 0;
}
Esempio n. 2
0
int main(int argc, char *argv[])
{
	gzFile fp;
	kstream_t *ks;
	khash_t(s) *hash;
	kstring_t *str;
	int dret, c, complement = 0;

	while ((c = getopt(argc, argv, "c")) >= 0) {
		switch (c) {
			case 'c': complement = 1; break;
		}
	}
	if (argc <= optind + 1) {
		fprintf(stderr, "Usage: apply_mask_l [-c] <in.mask.fa> <in.list>\n");
		return 1;
	}

	str = (kstring_t*)calloc(1, sizeof(kstring_t));
	fprintf(stderr, "[apply_mask_l] loading mask...\n");
	hash = load_mask(argv[optind]);
	fp = gzopen(argv[optind+1], "r");
	ks = ks_init(fp);
	fprintf(stderr, "[apply_mask_l] filtering list...\n");
	while (ks_getuntil(ks, 0, str, &dret) >= 0) {
		khint_t k;
		mask32_t *p;
		int pos, do_print = 0;
		k = kh_get(s, hash, str->s);
		p = (k != kh_end(hash))? &kh_val(hash, k) : 0;
		ks_getuntil(ks, 0, str, &dret);
		pos = atoi(str->s) - 1;
		if (complement == 0) {
			if (p && pos < p->ori_len && (p->mask[pos/32]&1u<<pos%32)) do_print = 1;
		} else {
			if (p && pos < p->ori_len && (p->mask[pos/32]&1u<<pos%32) == 0) do_print = 1;
		}
		if (do_print) printf("%s\t%d", kh_key(hash, k), pos + 1);
		if (dret != '\n') {
			if (do_print) putchar('\t');
			while ((c = ks_getc(ks)) != -1 && c != '\n')
				if (do_print) putchar(c);
		}
		if (do_print) putchar('\n');
	}
	ks_destroy(ks);
	gzclose(fp);
	free(str->s); free(str);
	// hash table is not freed...
	return 0;
}
Esempio n. 3
0
static av_cold int init(AVFilterContext *ctx, const char *args)
{
    RemovelogoContext *removelogo = ctx->priv;
    int ***mask;
    int ret = 0;
    int a, b, c, w, h;
    int full_max_mask_size, half_max_mask_size;

    if (!args) {
        av_log(ctx, AV_LOG_ERROR, "An image file must be specified as argument\n");
        return AVERROR(EINVAL);
    }

    /* Load our mask image. */
    if ((ret = load_mask(&removelogo->full_mask_data, &w, &h, args, ctx)) < 0)
        return ret;
    removelogo->mask_w = w;
    removelogo->mask_h = h;

    convert_mask_to_strength_mask(removelogo->full_mask_data, w, w, h,
                                  16, &full_max_mask_size);

    /* Create the scaled down mask image for the chroma planes. */
    if (!(removelogo->half_mask_data = av_mallocz(w/2 * h/2)))
        return AVERROR(ENOMEM);
    generate_half_size_image(removelogo->full_mask_data, w,
                             removelogo->half_mask_data, w/2,
                             w, h, &half_max_mask_size);

    removelogo->max_mask_size = FFMAX(full_max_mask_size, half_max_mask_size);

    /* Create a circular mask for each size up to max_mask_size. When
       the filter is applied, the mask size is determined on a pixel
       by pixel basis, with pixels nearer the edge of the logo getting
       smaller mask sizes. */
    mask = (int ***)av_malloc(sizeof(int **) * (removelogo->max_mask_size + 1));
    if (!mask)
        return AVERROR(ENOMEM);

    for (a = 0; a <= removelogo->max_mask_size; a++) {
        mask[a] = (int **)av_malloc(sizeof(int *) * ((a * 2) + 1));
        if (!mask[a])
            return AVERROR(ENOMEM);
        for (b = -a; b <= a; b++) {
            mask[a][b + a] = (int *)av_malloc(sizeof(int) * ((a * 2) + 1));
            if (!mask[a][b + a])
                return AVERROR(ENOMEM);
            for (c = -a; c <= a; c++) {
                if ((b * b) + (c * c) <= (a * a)) /* Circular 0/1 mask. */
                    mask[a][b + a][c + a] = 1;
                else
                    mask[a][b + a][c + a] = 0;
            }
        }
    }
    removelogo->mask = mask;

    /* Calculate our bounding rectangles, which determine in what
     * region the logo resides for faster processing. */
    ff_calculate_bounding_box(&removelogo->full_mask_bbox, removelogo->full_mask_data, w, w, h, 0);
    ff_calculate_bounding_box(&removelogo->half_mask_bbox, removelogo->half_mask_data, w/2, w/2, h/2, 0);

#define SHOW_LOGO_INFO(mask_type)                                       \
    av_log(ctx, AV_LOG_VERBOSE, #mask_type " x1:%d x2:%d y1:%d y2:%d max_mask_size:%d\n", \
           removelogo->mask_type##_mask_bbox.x1, removelogo->mask_type##_mask_bbox.x2, \
           removelogo->mask_type##_mask_bbox.y1, removelogo->mask_type##_mask_bbox.y2, \
           mask_type##_max_mask_size);
    SHOW_LOGO_INFO(full);
    SHOW_LOGO_INFO(half);

    return 0;
}
Esempio n. 4
0
int main (int argc, char *argv[])
{
    GCContext    gc_context;
    GMainLoop   *mainLoop;
    GKeyFile    *keyFile;
    GThread     *displayThread;
    GThread     *inputControllerThread;
    GThread     *x11EventThread;
    int          i;

    
    GCConfig config = {
        .movie_path          = DEFAULT_MOVIE_PATH,
        .mask_path           = DEFAULT_MASK_PATH,
        .controller_path     = DEFAULT_CONTROLLER_PATH,
        .seconds_per_frame   = DEFAULT_SECONDS_PER_FRAME,
        .easing_factor       = DEFAULT_EASING_FACTOR,
        .frames_per_tick     = 0,
        .diameter_controller = 0,
        .diameter_rim        = 0,
        .ctr                 = 0,
        .fpr                 = 0,
        .number_of_frames    = 0,
        .fullscreen          = TRUE,
        .timeZone            = NULL,
    };

    Movie movie = {
        .planes             = NULL,
        .frame_offset       = 0,
        .fd_movie           = -1,
        .frame              = { .pitches = { FRAME_PITCH, 0, 0 } },
        .fd_mask            = -1,
        .mask               = { .pitches = { MASK_PITCH, 0, 0 } },
        .pre_load_surface   = VDP_INVALID_HANDLE,
        .play_direction     = DIRECTION_FORWARD,
        .ticks              = 0,
        .new_frame          = FALSE,
        .ease_to            = TRUE,
    };

    keyFile = g_key_file_new();
    if (argc > 1 && g_key_file_load_from_file(keyFile, argv[1], G_KEY_FILE_NONE, NULL)) {
        if (g_key_file_has_group(keyFile, "MAIN")) {
            if (g_key_file_has_key(keyFile, "MAIN", "utc_offset", NULL))
                config.timeZone = g_time_zone_new(g_key_file_get_string(keyFile, "MAIN", "utc_offset", NULL));
            if (g_key_file_has_key(keyFile, "MAIN", "ease_to_time", NULL))
                movie.ease_to = g_key_file_get_boolean(keyFile, "MAIN", "ease_to_time", NULL);
        }
 
        if (g_key_file_has_group(keyFile, "MOVIE")) {
           if (g_key_file_has_key(keyFile, "MOVIE", "file", NULL))
              config.movie_path = g_key_file_get_string(keyFile, "MOVIE", "file", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "mask", NULL))
              config.mask_path = g_key_file_get_string(keyFile, "MOVIE", "mask", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "seconds_per_frame", NULL))
              config.seconds_per_frame = (float)g_key_file_get_double(keyFile, "MOVIE", "seconds_per_frame", NULL);
           if (g_key_file_has_key(keyFile, "MOVIE", "easing_factor", NULL))
              config.easing_factor = (float)g_key_file_get_integer(keyFile, "MOVIE", "easing_factor", NULL);
        }
        
        if (g_key_file_has_group(keyFile, "CONTROLLER")) {
           if (g_key_file_has_key(keyFile, "CONTROLLER", "path", NULL))
              config.controller_path = g_key_file_get_string(keyFile, "CONTROLLER", "path", NULL);

           if (g_key_file_has_key(keyFile, "CONTROLLER", "diameter_controller", NULL))
              config.diameter_controller = (float)g_key_file_get_double(keyFile, "CONTROLLER", "diameter_controller", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "diameter_rim", NULL))
              config.diameter_rim = (float)g_key_file_get_double(keyFile, "CONTROLLER", "diameter_rim", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "ctr", NULL))
              config.ctr = (float)g_key_file_get_double(keyFile, "CONTROLLER", "ctr", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "fpr", NULL))
              config.fpr = (float)g_key_file_get_double(keyFile, "CONTROLLER", "fpr", NULL);
           if (g_key_file_has_key(keyFile, "CONTROLLER", "frames_per_tick", NULL))
              config.frames_per_tick = (float)g_key_file_get_double(keyFile, "CONTROLLER", "frames_per_tick", NULL);
        }

        if (g_key_file_has_group(keyFile, "SCREEN")) {
           if (g_key_file_has_key(keyFile, "SCREEN", "fullscreen", NULL))
              config.fullscreen = g_key_file_get_boolean(keyFile, "SCREEN", "fullscreen", NULL);
        }
        g_key_file_free(keyFile);
    }

    if (!config.timeZone)
        config.timeZone = g_time_zone_new_local();

    if (!config.frames_per_tick && 
        !(config.frames_per_tick = frames_per_tick(config.diameter_controller,
                                                   config.diameter_rim,
                                                   config.ctr,
                                                   config.fpr)))
    {
        g_warning("No valid tick settings, using default frames per tick: %f", DEFAULT_FRAMES_PER_TICK);
        config.frames_per_tick = DEFAULT_FRAMES_PER_TICK;
    }

    config.movie_size = get_file_size(config.movie_path);
    config.number_of_frames = config.movie_size / FRAME_SIZE;
    
    mainLoop = g_main_loop_new(NULL, FALSE);

    gc_context.g_main_loop        = mainLoop;
    gc_context.g_main_context     = g_main_loop_get_context(mainLoop);
    gc_context.window_size.width  = MOVIE_WIDTH;
    gc_context.window_size.height = MOVIE_HEIGHT;
    gc_context.exit               = FALSE;
    gc_context.movie_context      = &movie;
    gc_context.config             = &config;


    g_message("movie file: %s",                           config.movie_path);
    g_message("movie size: %lu",                          config.movie_size);
    g_message("movie frames: %lu",                        config.number_of_frames);
    g_message("movie mask file: %s",                      config.mask_path);
    g_message("frames per minute: %f",                    get_frames_per_minute(&gc_context));
    g_message("frames per day:    %lu",                   get_frames_per_day(&gc_context));
    g_message("frames per tick:   %f",                    config.frames_per_tick);
    g_message("number of days:    %d",                    get_number_of_days(&gc_context));
    g_message("current day:       %d",                    get_current_day(&gc_context));

    if (movie.ease_to) {
        movie.ease_to_frame = get_frame_offset(&gc_context, GO_TO_RAND_DAY, DAY_OFFSET_NOW);
        g_message("ease to frame:    %lu", movie.ease_to_frame);
    }

    x11_init(&gc_context);
    vdpau_init(&gc_context);

    load_movie(&gc_context);
    load_mask(&gc_context);

    g_cond_init(&movie.tick_cond);
    g_mutex_init(&movie.tick_lock);
    g_mutex_init(&movie.frame_lock);

    displayThread = g_thread_new("Display thread", display_thread, (gpointer)&gc_context);
    inputControllerThread = g_thread_new("Input controller thread", input_controller_thread, (gpointer)&gc_context);
    x11EventThread = g_thread_new("X11 Event thread", x11_event_thread, (gpointer)&gc_context);

    g_main_loop_run(mainLoop);

    gc_context.exit = TRUE;
    g_thread_join(displayThread); 
    g_thread_join(inputControllerThread); 
    g_thread_join(x11EventThread); 
    g_cond_clear(&movie.tick_cond);
    g_mutex_clear(&movie.tick_lock);
    g_mutex_clear(&movie.frame_lock);
    g_time_zone_unref(config.timeZone);
}