Esempio n. 1
0
static int config_props(AVFilterLink *inlink)
{
    VignetteContext *s = inlink->dst->priv;
    AVRational sar = inlink->sample_aspect_ratio;

    s->desc = av_pix_fmt_desc_get(inlink->format);
    s->var_values[VAR_W]  = inlink->w;
    s->var_values[VAR_H]  = inlink->h;
    s->var_values[VAR_TB] = av_q2d(inlink->time_base);
    s->var_values[VAR_R]  = inlink->frame_rate.num == 0 || inlink->frame_rate.den == 0 ?
        NAN : av_q2d(inlink->frame_rate);

    if (!sar.num || !sar.den)
        sar.num = sar.den = 1;
    if (sar.num > sar.den) {
        s->xscale = av_q2d(av_div_q(sar, s->aspect));
        s->yscale = 1;
    } else {
        s->yscale = av_q2d(av_div_q(s->aspect, sar));
        s->xscale = 1;
    }
    s->dmax = hypot(inlink->w / 2., inlink->h / 2.);
    av_log(s, AV_LOG_DEBUG, "xscale=%f yscale=%f dmax=%f\n",
           s->xscale, s->yscale, s->dmax);

    s->fmap_linesize = FFALIGN(inlink->w, 32);
    s->fmap = av_malloc_array(s->fmap_linesize, inlink->h * sizeof(*s->fmap));
    if (!s->fmap)
        return AVERROR(ENOMEM);

    if (s->eval_mode == EVAL_MODE_INIT)
        update_context(s, inlink, NULL);

    return 0;
}
Esempio n. 2
0
File: sha1.cpp Progetto: wyrover/mmh
		void sha1_generator::add_data(const void * p_data_raw, t_size p_data_size)
		{
			t_size w_position = (m_size_data_total%64);
			t_uint8 * w8 = (t_uint8*)w.get_ptr();
			const t_uint8 * p_data = (const t_uint8*)p_data_raw;

			for (t_size i = 0; i < p_data_size; i++)
			{
				//meh endianness
				t_size index = w_position - (w_position%4) + 3 - (w_position%4);
				w8[index] = p_data[i];
				if (++w_position == 64) {update_context(); w_position = 0;}
			}

			m_size_data_total += p_data_size;
		}
Esempio n. 3
0
/*Each thread will called this function*/
void *worker_compress(void *arg)
{
    int ret, jdx;
    uint32_t count = 0;
    uint32_t point = 0;
    char header[128] =
    { 0 };
    ctx_t ctx1;
    margs_t *args = (margs_t *) arg;
    ctx_t *ctx = &(args->nums);
    file_container_t *fnames = args->fnames;
    int idx = args->idx;
    int bitsToLoss = args->bitsToLoss;
    sprintf(header, "thread %d", idx);
    init_context(&ctx1);
    point = fnames->size / 10 + 1;

    if (point < 10)
    {
        point = 10;
    }

    while (get_next_file(fnames, &jdx) > -1)
    {
        reset_context(&ctx1);
        ret = zip_compress(&ctx1, fnames->srcs[jdx], fnames->dsts[jdx], bitsToLoss);

        if (ret != 0)
        {
            continue;
        }

        print_context_info(&ctx1, "Context Info in Worker Compress");
        update_context(ctx, &ctx1);
        count += 1;

        if (count % point == 0)
        {
            //print the speeds for all the files
            //ctx_print_more(ctx, header);
            print_context_info(ctx, header);
        }
    }

    return 0;
}
Esempio n. 4
0
void *worker_uncompress(void *arg)
{
    int ret, file_idx;
    uint32_t count = 0;
    uint32_t point = 0;
    char header[128] =
    { 0 };
    ctx_t ctx2;
    margs_t *args = (margs_t *) arg;
    ctx_t *ctx = &(args->nums);
    file_container_t *fnames = args->fnames;
    int idx = args->idx;
    sprintf(header, "thread %d", idx);
    init_context(&ctx2);
    point = fnames->size / 10 + 1;

    if (point < 10)
    {
        point = 10;
    }

    while (get_next_file(fnames, &file_idx) > -1)
    {
        reset_context(&ctx2);
        ret = zip_uncompress(&ctx2, fnames->srcs[file_idx], fnames->dsts[file_idx]);

        if (ret != 0)
        {
            continue;
        }

        count += 1;
        //print the speeds for current file
        print_context_info(&ctx2, "Context Info in Worker Uncompress");
        update_context(ctx, &ctx2);

        if (count % point == 0)
        {
            print_context_info(ctx, header);
        }
    }

    return 0;
}
Esempio n. 5
0
/* -------------------------------------------- */
int64_t handle_them(file_container_t *fnames, int threadNum, int type, int bitsToLoss)
{
    int i;
    ctx_t total;
    margs_t *args;
    pthread_t *threads;
    args = malloc(sizeof(margs_t) * threadNum);
    memset(args, 0, sizeof(margs_t) * threadNum);
    threads = malloc(sizeof(pthread_t) * threadNum);
    memset(threads, 0, sizeof(pthread_t) * threadNum);

    for (i = 0; i < threadNum; i++)
    {
        args[i].idx = i;
        args[i].fnames = fnames;
        init_context(&(args[i].nums));
        args[i].bitsToLoss = bitsToLoss;

        if (type == 0)
        {
            pthread_create(&(threads[i]), NULL, worker_compress, &args[i]);
        }

        else if (type == 1)
        {
            pthread_create(&(threads[i]), NULL, worker_uncompress, &args[i]);
        }
    }

    init_context(&total);

    for (i = 0; i < threadNum; i++)
    {
        pthread_join(threads[i], NULL);
        update_context(&total, &(args[i].nums));
    }

    //ctx_print_more(&total, "Overall");
    print_context_info(&total, "[Overall] Context Info In handle_them()");
    free(threads);
    free(args);
    return total.allFileSize;
}
Esempio n. 6
0
/*
 * Parse the given string and find the bct file name.
 *
 * @param context	The main context pointer
 * @param token  	The parse token value
 * @param rest   	String to parse
 * @return 0 and 1 for success and failure
 */
static int
parse_bct_file(build_image_context *context, parse_token token, char *rest)
{
	char   filename[MAX_BUFFER];

	assert(context != NULL);
	assert(rest != NULL);

	/* Parse the file name. */
	rest = parse_filename(rest, filename, MAX_BUFFER);
	if (rest == NULL)
		return 1;

	/* Parsing has finished - set the bctfile */
	context->bct_filename = filename;
	/* Read the bct file to buffer */
	read_bct_file(context);
	update_context(context);
	return 0;
}
Esempio n. 7
0
bool DiskManager::write_page(Page * page)
{
  if( !page->is_dirty() ) return true;
  if( !update_context(page->get_fname()))
    return false;
  
  if(fseek(file_ , page->get_pid()*Page::PAGE_SIZE , SEEK_SET)){
    Utils::log("[DiskManager] can't change offset in file",ERROR);
    return false;
  }
#ifdef IO_DISK_M
  Utils::log("[DiskManager] write in file page: "+ std::to_string(page->get_pid()));
#endif
  if( fwrite(page->get_data(),sizeof(char),Page::PAGE_SIZE,file_) != Page::PAGE_SIZE ){
    Utils::log("[DiskManager] can't write in file",ERROR);
    return false;
  }
  page->reset_dirty();
  return true;
}
Esempio n. 8
0
bool DiskManager::read_page(Page * page)
{
  if( !update_context(page->get_fname()))
    return false;
    
  if( !is_allocated(page->get_pid()) )
    return true;
   
  if(fseek(file_ , page->get_pid()*Page::PAGE_SIZE , SEEK_SET)){
    Utils::log("[DiskManager] can't change offset in file",ERROR);
    return false;
  }
#ifdef IO_DISK_M
  Utils::log("[DiskManager] read in file page: "+ std::to_string(page->get_pid()) );
#endif
  if( fread(page->get_data(),sizeof(char),Page::PAGE_SIZE,file_) != Page::PAGE_SIZE ){
    Utils::log("[DiskManager] can't read from file",ERROR);
    return false;
  }
  return true;
}
Esempio n. 9
0
File: parse.c Progetto: ASpade/mulk
static size_t write_data_cb(void *ptr, size_t size, size_t nmemb, void *outstream)
{
	size_t nmemb_writed = 0;
	buffer_t *buffer = outstream;

	if (!buffer || !ptr)
		return 0;

	if (buffer->file_pt) {
#ifdef ENABLE_METALINK
		if (buffer->chunk) {
			off_t offset = buffer->chunk->start + buffer->chunk->pos, byte_writed;

			if ((buffer->chunk->pos + size * nmemb) > buffer->chunk->length)
				return 0;

			nmemb_writed = fwrite_offset(ptr, size, nmemb, offset, buffer->file_pt);
			fflush(buffer->file_pt);
			byte_writed = size * nmemb_writed;
			buffer->chunk->pos += byte_writed;

#ifdef ENABLE_CHECKSUM
		    if (buffer->chunk->checksum.cs_type != CS_NONE && byte_writed > 0)
				update_context(&buffer->chunk->checksum, ptr, byte_writed);
#endif /* ENABLE_CHECKSUM */
		}
		else
#endif /* ENABLE_METALINK */
		{
			nmemb_writed = fwrite(ptr, size, nmemb, buffer->file_pt);
			fflush(buffer->file_pt);
		}
	}

	return nmemb_writed * size;
}
Esempio n. 10
0
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
{
    unsigned x, y, direct = 0;
    AVFilterContext *ctx = inlink->dst;
    VignetteContext *s = ctx->priv;
    AVFilterLink *outlink = ctx->outputs[0];
    AVFrame *out;

    if (av_frame_is_writable(in)) {
        direct = 1;
        out = in;
    } else {
        out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
        if (!out) {
            av_frame_free(&in);
            return AVERROR(ENOMEM);
        }
        av_frame_copy_props(out, in);
    }

    if (s->eval_mode == EVAL_MODE_FRAME)
        update_context(s, inlink, in);

    if (s->desc->flags & AV_PIX_FMT_FLAG_RGB) {
        uint8_t       *dst = out->data[0];
        const uint8_t *src = in ->data[0];
        const float *fmap = s->fmap;
        const int dst_linesize = out->linesize[0];
        const int src_linesize = in ->linesize[0];
        const int fmap_linesize = s->fmap_linesize;

        for (y = 0; y < inlink->h; y++) {
            uint8_t       *dstp = dst;
            const uint8_t *srcp = src;

            for (x = 0; x < inlink->w; x++, dstp += 3, srcp += 3) {
                const float f = fmap[x];

                dstp[0] = av_clip_uint8(srcp[0] * f + get_dither_value(s));
                dstp[1] = av_clip_uint8(srcp[1] * f + get_dither_value(s));
                dstp[2] = av_clip_uint8(srcp[2] * f + get_dither_value(s));
            }
            dst += dst_linesize;
            src += src_linesize;
            fmap += fmap_linesize;
        }
    } else {
        int plane;

        for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++) {
            uint8_t       *dst = out->data[plane];
            const uint8_t *src = in ->data[plane];
            const float *fmap = s->fmap;
            const int dst_linesize = out->linesize[plane];
            const int src_linesize = in ->linesize[plane];
            const int fmap_linesize = s->fmap_linesize;
            const int chroma = plane == 1 || plane == 2;
            const int hsub = chroma ? s->desc->log2_chroma_w : 0;
            const int vsub = chroma ? s->desc->log2_chroma_h : 0;
            const int w = AV_CEIL_RSHIFT(inlink->w, hsub);
            const int h = AV_CEIL_RSHIFT(inlink->h, vsub);

            for (y = 0; y < h; y++) {
                uint8_t *dstp = dst;
                const uint8_t *srcp = src;

                for (x = 0; x < w; x++) {
                    const double dv = get_dither_value(s);
                    if (chroma) *dstp++ = av_clip_uint8(fmap[x << hsub] * (*srcp++ - 127) + 127 + dv);
                    else        *dstp++ = av_clip_uint8(fmap[x        ] *  *srcp++              + dv);
                }
                dst += dst_linesize;
                src += src_linesize;
                fmap += fmap_linesize << vsub;
            }
        }
    }

    if (!direct)
        av_frame_free(&in);
    return ff_filter_frame(outlink, out);
}