Beispiel #1
0
/* Loop over all child structs in the children list and free them */
static void free_children(struct tracy_ll *children)
{
    struct tracy_child *tc;
    struct tracy_ll_item *cur = children->head;

    /* Walk over all items in the list */
    while(cur) {
        tc = cur->data;

        /* Detach or kill */
        if (tc->attached) {
            fprintf(stderr, _b("Detaching from child %d")"\n", tc->pid);
            PTRACE_CHECK_NORETURN(PTRACE_DETACH, tc->pid, NULL, NULL);
            /* TODO: What can we do in case of failure? */
        } else {
            fprintf(stderr, _b("Killing child %d")"\n", tc->pid);
            tracy_kill_child(tc);
        }

        /* Free data and fetch next item */
        cur = cur->next;
    }

    return;
}
Beispiel #2
0
/* the key schedule routine */
void keySched(BYTE M[], int N, u32 **S, u32 K[40], int *k)
{
    u32 Mo[4], Me[4];
    int i, j;
    BYTE vector[8];
    u32 A, B;

    *k = (N + 63) / 64;
    *S = (u32*)malloc(sizeof(u32) * (*k));

    for (i = 0; i < *k; i++)
    {
	Me[i] = BSWAP(((u32*)M)[2*i]);
	Mo[i] = BSWAP(((u32*)M)[2*i+1]);
    }

    for (i = 0; i < *k; i++)
    {
	for (j = 0; j < 4; j++) vector[j] = _b(Me[i], j);
	for (j = 0; j < 4; j++) vector[j+4] = _b(Mo[i], j);
	(*S)[(*k)-i-1] = RSMatrixMultiply(vector);
    }
    for (i = 0; i < 20; i++)
    {
	A = h(2*i*RHO, Me, *k);
	B = ROL(h(2*i*RHO + RHO, Mo, *k), 8);
	K[2*i] = A+B;
	K[2*i+1] = ROL(A + 2*B, 9);
    }
}	
XMFLOAT4 TransferFunction::operator()(int isoValue) {
	float alp = _a(isoValue) < 0 ? 0 : (_a(isoValue) > 1 ? 1 : _a(isoValue));
	float red = _r(isoValue) < 0 ? 0 : (_r(isoValue) > 1 ? 1 : _r(isoValue));
	float gre = _g(isoValue) < 0 ? 0 : (_g(isoValue) > 1 ? 1 : _g(isoValue));
	float blu = _b(isoValue) < 0 ? 0 : (_b(isoValue) > 1 ? 1 : _b(isoValue));
	return XMFLOAT4(red, gre, blu, alp);
}
Beispiel #4
0
Matrix<double> Triangle::B()
{
	Matrix<double> Result(3);
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			Result[i][j]=_b(i)*_b(j);
	return Result;
}
Beispiel #5
0
static gboolean app_bus_callback(GstBus *bus, GstMessage *message, gpointer data)
{
    app_data_t     *app = data;
    GMainLoop      *loop = app->loop;

    switch (GST_MESSAGE_TYPE(message))
    {
    case GST_MESSAGE_ERROR:
    {
        GError     *err;
        gchar      *debug;

        /* ...dump error-message reported by the GStreamer */
        gst_message_parse_error (message, &err, &debug);
        TRACE(ERROR, _b("execution failed: %s"), err->message);
        g_error_free(err);
        g_free(debug);

        /* ...right now this is a fatal error */
        BUG(1, _x("breakpoint"));

        /* ...and terminate the loop */
        g_main_loop_quit(loop);
        break;
    }

    case GST_MESSAGE_EOS:
    {
        /* ...end-of-stream encountered; break the loop */
        TRACE(INFO, _b("execution completed"));
        g_main_loop_quit(loop);
        break;
    }

    case GST_MESSAGE_STATE_CHANGED:
    {
        /* ...state has changed; test if it is start or stop */
        if (GST_MESSAGE_SRC(message) == GST_OBJECT_CAST(app->pipe))
        {
            GstState        old, new, pending;
        
            /* ...parse state message */
            gst_message_parse_state_changed(message, &old, &new, &pending);

            TRACE(INFO, _b("transition from %d to %d"), old, new);
        }

        break;
    }
    
    default:
        /* ...ignore message */
        TRACE(0, _b("ignore message: %s"), gst_message_type_get_name(GST_MESSAGE_TYPE(message)));
    }
Beispiel #6
0
Datei: engine.c Projekt: fizx/sit
static long
_b(Engine *engine, long min, long max) {
  if (max <= min) return max;
  if (max == min + 1) return max;
  long middle = (max + min) / 2;
  if(engine_get_document(engine, middle)) {
    return _b(engine, min, middle);
  } else {
    return _b(engine, middle, max);
  }
}
Beispiel #7
0
static void blend_single(image_t * frame, ASS_Image *img)
{
    int x, y;
    unsigned char opacity = 255 - _a(img->color);
    unsigned char r = _r(img->color);
    unsigned char g = _g(img->color);
    unsigned char b = _b(img->color);

    unsigned char *src;
    unsigned char *dst;

    src = img->bitmap;
    dst = frame->buffer + img->dst_y * frame->stride + img->dst_x * 3;
    for (y = 0; y < img->h; ++y) {
        for (x = 0; x < img->w; ++x) {
            unsigned k = ((unsigned) src[x]) * opacity / 255;
            // possible endianness problems
            dst[x * 3] = (k * b + (255 - k) * dst[x * 3]) / 255;
            dst[x * 3 + 1] = (k * g + (255 - k) * dst[x * 3 + 1]) / 255;
            dst[x * 3 + 2] = (k * r + (255 - k) * dst[x * 3 + 2]) / 255;
        }
        src += img->stride;
        dst += frame->stride;
    }
}
/* ...create display data */
display_data_t * display_create(void)
{
    display_data_t     *display = &__display;
    pthread_attr_t      attr;
    int                 r;

    /* ...reset display data */
    memset(display, 0, sizeof(*display));

    XInitThreads();

    /* ...connect to X server display */
    display->display = XOpenDisplay(NULL);
    if (display->display == NULL)
    {
        goto error;
    }

    /* ...initialize thread attributes (joinable, default stack size) */
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    /* ...wait until display thread starts? */
    TRACE(INIT, _b("X11 display interface initialized"));

    return display;

error_epoll:

error_disp:

error:
    return NULL;
}
Beispiel #9
0
DjinniBinary * cw__test_helpers_id_binary(DjinniBinary * b) {
    std::unique_ptr<DjinniBinary> _b(b);
    try {
        return DjinniBinary::fromCpp(::testsuite::TestHelpers::id_binary(DjinniBinary::toCpp(std::move(_b)))).release();
    }
    CW_TRANSLATE_EXCEPTIONS_RETURN(0);
}
Beispiel #10
0
Datei: engine.c Projekt: fizx/sit
long
engine_min_document_id(Engine *engine) {
  long drs = sizeof(DocRef);
  long bound = (engine->docs->written - engine->docs->capacity) / drs - 1;
  if(bound < 0) bound = -1;
  return _b(engine, bound, engine_last_document_id(engine));
}
void opengl_scene::draw( const CView& v ) {
	opengl_static_scene::draw( );
	RECT r;
	v.GetClientRect(&r);
	gl_point a(0.0f, 0.0f);
	gl_point b(((GLfloat)r.right)/2.0f, (GLfloat)r.bottom/2.0f);
	gl_point c((GLfloat)r.right, 0.0f);
	color.purple( );
	if(rand( ) % 2) s1.draw(gl_triangle(a,b,c));
	
	
	gl_point _a(0.0f, (GLfloat)r.bottom);
	gl_point _b(((GLfloat)r.right)/2.0f, (GLfloat)r.bottom/2.0f);
	gl_point _c((GLfloat)r.right, (GLfloat)r.bottom);
	color.red( );
	if(rand( ) % 2) s2.draw( gl_triangle(_a, _b, _c));

	
	gl_point A(((GLfloat)r.right)/2.0f, (GLfloat)r.bottom/2.0f);
	gl_point B(((GLfloat)r.right), (GLfloat)r.bottom);
	gl_point C((GLfloat)r.right, 0.0f);
	color.lime( );
	if(rand( ) % 2) s3.draw( gl_triangle(A, B, C));



}
Beispiel #12
0
int ZMatQRSolver_NR3::solve( double *b, double *x ) {
	// solve Ax = b, must call decompose() first.
	VecDoub _b( rows, b, 1 );
	VecDoub _x( cols, x, 1 );
	pNRqr->solve( _b, _x );
	return 1;
}
Beispiel #13
0
int
main(int argc, char **argv)
{
    int		errflag = 0;
    int		sts;
    int		c;

    __pmSetProgname(argv[0]);

    indomp = (__pmInDom_int *)&indom;

    while ((c = getopt(argc, argv, "D:")) != EOF) {
	switch (c) {

#ifdef PCP_DEBUG
	case 'D':	/* debug flag */
	    sts = __pmParseDebug(optarg);
	    if (sts < 0) {
		fprintf(stderr, "%s: unrecognized debug flag specification (%s)\n",
		    pmProgname, optarg);
		errflag++;
	    }
	    else
		pmDebug |= sts;
	    break;
#endif

	case '?':
	default:
	    errflag++;
	    break;
	}
    }

    if (errflag) {
	fprintf(stderr, "Usage: %s [-D...] [a|b|c|d|...|i 1|2|3}\n", pmProgname);
	exit(1);
    }

    while (optind < argc) {
	if (strcmp(argv[optind], "a") == 0) _a(0, 1, 1);
	else if (strcmp(argv[optind], "b") == 0) _b();
	else if (strcmp(argv[optind], "c") == 0) _c();
	else if (strcmp(argv[optind], "d") == 0) _a(1, 0, 1);
	else if (strcmp(argv[optind], "e") == 0) _e(0);
	else if (strcmp(argv[optind], "f") == 0) _e(3600);
	else if (strcmp(argv[optind], "g") == 0) _g();
	else if (strcmp(argv[optind], "h") == 0) _h();
	else if (strcmp(argv[optind], "i") == 0) {
	    optind++;
	    _i(atoi(argv[optind]));
	}
	else if (strcmp(argv[optind], "j") == 0) _j();
	else
	    fprintf(stderr, "torture_cache: no idea what to do with option \"%s\"\n", argv[optind]);
	optind++;
    }

    exit(0);
}
Beispiel #14
0
static void blend_single(SDL_Surface * frame, ASS_Image *img)
{
    int x, y;
    unsigned char opacity = 255 - _a(img->color);
    unsigned char r = _r(img->color);
    unsigned char g = _g(img->color);
    unsigned char b = _b(img->color);

    unsigned char *src;
    unsigned char *dst;

    src = img->bitmap;
    dst = frame->pixels;

    for (y = 0; y < img->h; ++y) {
        for (x = 0; x < img->w; ++x) {
            unsigned k = ((unsigned) src[x]) * opacity / 255;
            // possible endianness problems
            dst[x * 4] = (k * b + (255 - k) * dst[x * 4]) / 255;
            dst[x * 4 + 1] = (k * g + (255 - k) * dst[x * 4 + 1]) / 255;
            dst[x * 4 + 2] = (k * r + (255 - k) * dst[x * 4 + 2]) / 255;
            dst[x * 4 + 3] = k;
        }
        src += img->stride;
        dst += frame->pitch;
    }
}
Beispiel #15
0
/*!
  Create a vpMbScanLineEdge from two points while ordering them.

  \param a : First point of the line.
  \param b : Second point of the line.

  \return Resulting vpMbScanLineEdge.
*/
vpMbScanLine::vpMbScanLineEdge
vpMbScanLine::makeMbScanLineEdge(const vpPoint &a, const vpPoint &b)
{
  vpColVector _a(3);
  vpColVector _b(3);

  _a[0] = std::ceil((a.get_X() * 1e8) * 1e-6);
  _a[1] = std::ceil((a.get_Y() * 1e8) * 1e-6);
  _a[2] = std::ceil((a.get_Z() * 1e8) * 1e-6);

  _b[0] = std::ceil((b.get_X() * 1e8) * 1e-6);
  _b[1] = std::ceil((b.get_Y() * 1e8) * 1e-6);
  _b[2] = std::ceil((b.get_Z() * 1e8) * 1e-6);

  bool b_comp = false;
  for(unsigned int i = 0 ; i < 3 ; ++i)
    if (_a[i] < _b[i])
    {
      b_comp = true;
      break;
    }
    else if(_a[i] > _b[i])
      break;

  if (b_comp)
    return std::make_pair(_a, _b);

  return std::make_pair(_b, _a);
}
Beispiel #16
0
static void assRender(VSFrameRef *dst, VSFrameRef *alpha, const VSAPI *vsapi,
                      ASS_Image *img)
{
    uint8_t *planes[4];
    int strides[4], p;

    for(p = 0; p < 4; p++) {
        VSFrameRef *fr = p == 3 ? alpha : dst;

        planes[p] = vsapi->getWritePtr(fr, p % 3);
        strides[p] = vsapi->getStride(fr, p % 3);
        memset(planes[p], 0, strides[p] * vsapi->getFrameHeight(fr, p % 3));
    }

    while(img) {
        uint8_t *dstp[4], *alphap, *sp, color[4];
        uint16_t outa;
        int x, y, k;

        if(img->w == 0 || img->h == 0) {
            img = img->next;
            continue;
        }

        color[0] = _r(img->color);
        color[1] = _g(img->color);
        color[2] = _b(img->color);
        color[3] = _a(img->color);

        dstp[0] = planes[0] + (strides[0] * img->dst_y) + img->dst_x;
        dstp[1] = planes[1] + (strides[1] * img->dst_y) + img->dst_x;
        dstp[2] = planes[2] + (strides[2] * img->dst_y) + img->dst_x;
        dstp[3] = planes[3] + (strides[3] * img->dst_y) + img->dst_x;
        alphap = dstp[3];
        sp = img->bitmap;

        for(y = 0; y < img->h; y++) {
            for(x = 0; x < img->w; x++) {
                k = div255(sp[x] * color[3]);
                outa = k * 255 + (alphap[x] * (255 - k));

                if(outa != 0) {
                    dstp[0][x] = blend(k, color[0], alphap[x], dstp[0][x], outa);
                    dstp[1][x] = blend(k, color[1], alphap[x], dstp[1][x], outa);
                    dstp[2][x] = blend(k, color[2], alphap[x], dstp[2][x], outa);
                    dstp[3][x] = div255(outa);
                }
            }

            dstp[0] += strides[0];
            dstp[1] += strides[1];
            dstp[2] += strides[2];
            dstp[3] += strides[3];
            alphap += strides[3];
            sp += img->stride;
        }

        img = img->next;
    }
}
Beispiel #17
0
/* ...initialize GL-processing context */
static int app_context_init(widget_data_t *widget, void *data)
{
    app_data_t     *app = data;
    window_data_t  *window = (window_data_t *)widget;
    int             W = widget_get_width(widget);
    int             H = widget_get_height(widget);
    
    /* ...initialize surround-view engine (dimensions are fixed?) */
    CHK_ERR(app->sv = sview_engine_init(app->sv_cfg, 1280, 800), -errno);

    
    
    /* ...create UI layer */
    CHK_ERR(app->gui = gui_create(window, app), -errno);

//    /* ...display context is shared with all windows; context is surfaceless */
//    eglMakeCurrent(display->egl.dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, display->egl.ctx);
//    BUG(eglGetCurrentContext() == EGL_NO_CONTEXT, _x("invalid egl context"));
//    
//    sview_engine_destroy(app->sv);
//    app->sv = sview_engine_init(app->sv_cfg, 1280, 800);
//    
//    sview_engine_destroy(app->sv);
//    app->sv = sview_engine_init(app->sv_cfg, 1280, 800);
//    
//    sview_bv_reinit(app->sv,app->sv_cfg, 1280, 800);
    
    TRACE(INIT, _b("run-time initialized: %u*%u"), W, H);

    return 0;
}
Beispiel #18
0
/* ...keyboard event processing */
static inline widget_data_t * app_key_event(app_data_t *app, widget_data_t *widget, widget_key_event_t *event)
{
    pthread_mutex_lock(&app->access);

    if (app->flags & APP_FLAG_SVIEW)
    {
        if (event->type == WIDGET_EVENT_KEY_PRESS)
        {
            TRACE(DEBUG, _b("Key pressed: %i"), event->code);
            sview_engine_keyboard_key(app->sv, event->code, event->state);
        }
    }
    else
    {
#ifdef ENABLE_OBJDET
        if (event->type == WIDGET_EVENT_KEY_PRESS)
        {
            objdet_engine_keyboard_key(app->od, event->code, event->state);
        }
#endif
    }

    pthread_mutex_unlock(&app->access);

    return widget;
}
Beispiel #19
0
/* ...draw multiline string - hmm; need to put that stuff into display */
static inline void draw_string(cairo_t *cr, const char *fmt, ...)
{
	char                    buffer[4096], *p, *end;
	cairo_text_extents_t    text_extents;
	cairo_font_extents_t    font_extents;
	va_list                 argp;

	cairo_save(cr);
	cairo_select_font_face(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size(cr, 40);
	cairo_font_extents(cr, &font_extents);

	va_start(argp, fmt);
	vsnprintf(buffer, sizeof(buffer), fmt, argp);
	va_end(argp);

    for (p = buffer; *p; p = end + 1)
    {
        /* ...output single line */
		((end = strchr(p, '\n')) != NULL ? *end = 0 : 0);
		cairo_show_text(cr, p);
		cairo_text_extents (cr, p, &text_extents);
		cairo_rel_move_to (cr, -text_extents.x_advance, font_extents.height);
        TRACE(0, _b("print text-line: <%f,%f>"), text_extents.x_advance, font_extents.height);

        /* ...stop when last line processes */
        if (!end)   break;
    }

    /* ...restore drawing context */
	cairo_restore(cr);
}
Beispiel #20
0
 void _rseek_head(void) const
 noexcept {
     assert(_pos != nullptr);
     while(!mbs::is_valid_head_byte(_b())) {
         --_pos;
     }
 }
Beispiel #21
0
int main()
{
    __block int var = 0;
    int shouldbe = 0;
    void (^b)(void) = ^{ var++; /*printf("var is at %p with value %d\n", &var, var);*/ };
    __typeof(b) _b;
    //printf("before copy...\n");
    b(); ++shouldbe;
    size_t i;

    for (i = 0; i < 10; i++) {
            _b = Block_copy(b); // make a new copy each time
            assert(_b);
            ++shouldbe;
            _b();               // should still update the stack
            Block_release(_b);
    }

    //printf("after...\n");
    b(); ++shouldbe;

    if (var != shouldbe) {
        fail("var is %d but should be %d", var, shouldbe);
    }

    succeed(__FILE__);
}
Beispiel #22
0
/* ...process new input buffer submitted from camera */
static int sview_input_process(void *data, int i, GstBuffer *buffer)
{
    app_data_t     *app = data;

    BUG(i >= CAMERAS_NUMBER, _x("invalid camera index: %d"), i);

    TRACE(DEBUG, _b("camera-%d: input buffer received"), i);

    /* ...get queue access lock */
    pthread_mutex_lock(&app->lock);

    /* ...check if playback is enabled */
    if ((app->flags & APP_FLAG_EOS) == 0)
    {
        /* ...place buffer into main rendering queue (take ownership) */
        g_queue_push_tail(&app->render[i], buffer), gst_buffer_ref(buffer);

        /* ...indicate buffer is available */
        app->frames &= ~(1 << i);
        
        /* ...schedule processing if all buffers are ready */
        if ((app->frames & ((1 << CAMERAS_NUMBER) - 1)) == 0)
        {
            /* ...all buffers available; trigger surround-view scene processing */
            window_schedule_redraw(app->window);
        }
    }

    /* ...release queue access lock */
    pthread_mutex_unlock(&app->lock);

    return 0;
}
Beispiel #23
0
static void tst6() {
    params_ref      ps;
    reslimit        rlim;
    nlsat::solver s(rlim, ps);
    anum_manager & am     = s.am();
    nlsat::pmanager & pm  = s.pm();
    nlsat::assignment as(am);
    nlsat::explain& ex    = s.get_explain();
    nlsat::var x0, x1, x2, a, b, c, d;
    a  = s.mk_var(false);
    b  = s.mk_var(false);
    c  = s.mk_var(false);
    d  = s.mk_var(false);
    x0 = s.mk_var(false);
    x1 = s.mk_var(false);
    x2 = s.mk_var(false);

    polynomial_ref p1(pm), p2(pm), p3(pm), p4(pm), p5(pm);
    polynomial_ref _x0(pm), _x1(pm), _x2(pm);
    polynomial_ref _a(pm), _b(pm), _c(pm), _d(pm);
    _x0 = pm.mk_polynomial(x0);
    _x1 = pm.mk_polynomial(x1);
    _x2 = pm.mk_polynomial(x2);
    _a  = pm.mk_polynomial(a);
    _b  = pm.mk_polynomial(b);
    _c  = pm.mk_polynomial(c);
    _d  = pm.mk_polynomial(d);

    p1 = (_a*(_x0^2)) + _x2 + 2;
    p2 = (_b*_x1) - (2*_x2) - _x0 + 8;
    nlsat::scoped_literal_vector lits(s);
    lits.push_back(mk_gt(s, p1));
    lits.push_back(mk_gt(s, p2));
    lits.push_back(mk_gt(s, (_c*_x0) + _x2 + 1));
    lits.push_back(mk_gt(s, (_d*_x0) - _x1 + 5*_x2));

    scoped_anum zero(am), one(am), two(am);
    am.set(zero, 0);
    am.set(one,  1);
    am.set(two,  2);
    as.set(0, one);
    as.set(1, one);
    as.set(2, two);
    as.set(3, two);
    as.set(4, two);
    as.set(5, one);
    as.set(6, one);
    s.set_rvalues(as);


    project(s, ex, x0, 2, lits.c_ptr());
    project(s, ex, x1, 3, lits.c_ptr());
    project(s, ex, x2, 3, lits.c_ptr());
    project(s, ex, x2, 2, lits.c_ptr());
    project(s, ex, x2, 4, lits.c_ptr());
    project(s, ex, x2, 3, lits.c_ptr()+1);


}
Beispiel #24
0
const bool XG_TextBox::Load(XG_Container* handle){
	XG_Component::Load(handle);
	this->Set_Size(this->w,this->h);
	Texture _b(1,this->data.Get_Font()->Get_H_Font());
	Image _render(_b);
	this->cursore=_render;
	return this->UpDate_Render();
}
Beispiel #25
0
/**
 * set Bathymetry b in all grid cells (incl. ghost/boundary layers)
 * using the specified bathymetry function;
 * bathymetry source terms are re-computed
 */
void SWE_Block::setBathymetry(float (*_b)(float, float)) {

  for(int i=0; i<nx+2*nghosts; i++)
	for(int j=0; j<ny+2*nghosts; j++)
      b[i][j] = _b(offsetX + (i-nghosts+0.5f)*dx, offsetY + (j-nghosts+0.5f)*dy);

  synchBathymetryAfterWrite();
}
Beispiel #26
0
/**
 * set Bathymetry b in all grid cells (incl. ghost/boundary layers)
 * using the specified bathymetry function;
 * bathymetry source terms are re-computed
 */
void SWE_Block::setBathymetry(float (*_b)(float, float)) {

  for(int i=0; i<=nx+1; i++)
    for(int j=0; j<=ny+1; j++)
      b[i][j] = _b(offsetX + (i-0.5f)*dx, offsetY + (j-0.5f)*dy);

  synchBathymetryAfterWrite();
}
void SWE::setBathymetry(float(*_b)(float, float))
{
#pragma omp parallel for
	for (int i = 0; i < nx + 2; i++)
		for (int j = 0; j < nx + 2; j++)
			b[li(nx + 2, i, j)] = _b((i - 0.5f) * dx, (j - 0.5f) * dy);

	computeBathymetrySources();
}
/// @brief Draw subtitles
/// @param frame
/// @param time
/// @return
///
void LibassSubtitlesProvider::DrawSubtitles(AegiVideoFrame &frame,double time) {
	// Set size
	ass_set_frame_size(ass_renderer, frame.w, frame.h);

	// Get frame
	ASS_Image* img = ass_render_frame(ass_renderer, ass_track, int(time * 1000), NULL);

	// libass actually returns several alpha-masked monochrome images.
	// Here, we loop through their linked list, get the colour of the current, and blend into the frame.
	// This is repeated for all of them.
	while (img) {
		// Get colours
		unsigned int opacity = 255 - ((unsigned int)_a(img->color));
		unsigned int r = (unsigned int)_r(img->color);
		unsigned int g = (unsigned int)_g(img->color);
		unsigned int b = (unsigned int) _b(img->color);

		// Prepare copy
		int src_stride = img->stride;
		int dst_stride = frame.pitch;
		const unsigned char *src = img->bitmap;

		unsigned char *dst = frame.data;
		if (frame.flipped) {
			dst += dst_stride * (frame.h - 1);
			dst_stride *= -1;
		}
		dst += (img->dst_y * dst_stride + img->dst_x * 4);

		// Copy image to destination frame
		for (int y = 0; y < img->h; y++) {
			unsigned char *dstp = dst;

			for (int x = 0; x < img->w; ++x) {
				unsigned int k = ((unsigned)src[x]) * opacity / 255;
				unsigned int ck = 255 - k;

				*dstp = (k * b + ck * *dstp) / 255;
				++dstp;

				*dstp = (k * g + ck * *dstp) / 255;
				++dstp;

				*dstp = (k * r + ck * *dstp) / 255;
				++dstp;

				++dstp;
			}

			dst += dst_stride;
			src += src_stride;
		}

		// Next image
		img = img->next;
	}
}
Beispiel #29
0
/* ...buffer completion hook (tbd - need that at all?) */
static void __objdet_buffer_release(void *cdata, void *cookie)
{
    GstBuffer      *buffer = cookie;

    TRACE(DEBUG, _b("buffer %p released by engine (count=%d)"), buffer, GST_MINI_OBJECT_REFCOUNT(buffer));

    /* ...release buffer handle */
    gst_buffer_unref(buffer);
}
Beispiel #30
0
/* ...buffer allocation from frontal camera (object detection engine) */
static int objdet_input_alloc(void *data, GstBuffer *buffer)
{
    app_data_t         *app = data;
    vsink_meta_t       *vmeta = gst_buffer_get_vsink_meta(buffer);
    int                 w = vmeta->width, h = vmeta->height;
    objdet_meta_t      *ometa;

    if (app->f_width)
    {
        /* ...verify buffer dimensions are valid */
        CHK_ERR(w == app->f_width && h == app->f_height, -EINVAL);
    }
    else
    {
        int     W = window_get_width(app->window);
        int     H = window_get_height(app->window);

        /* ...check dimensions are valid */
        CHK_ERR(w && h, -EINVAL);

        /* ...set buffer dimensions */
        app->f_width = w, app->f_height = h;

        /* ...initialize object detection engine */
        CHK_ERR(app->od = objdet_engine_init(&objdet_callback, app, w, h, __pixfmt_yuv_bpp(vmeta->format), app->od_cfg), -errno);

        /* ...create a viewport for data visualization */
        texture_scale_to_window(&app->view, app->window, w, h, &app->matrix);
        
        //texture_set_view_scale(&app->view, 0, 0, W, H, W, H, w, h);


        /* ...create transformation matrix */
        if (0)
        {
            cairo_matrix_t     *m = &app->matrix;
            
            m->xx = (double) W / w, m->xy = 0, m->x0 = 0;
            m->yx = 0, m->yy = (double) H / h, m->y0 = 0;
        }        
    }

    /* ...allocate texture to wrap the buffer */
    CHK_ERR(vmeta->priv = texture_create(w, h, vmeta->plane, vmeta->format), -errno);

    /* ...add custom buffer metadata */
    CHK_ERR(ometa = gst_buffer_add_objdet_meta(buffer), -(errno = ENOMEM));
    CHK_ERR(ometa->buf = texture_map(vmeta->priv, CL_MEM_READ_ONLY), -errno);
    GST_META_FLAG_SET(ometa, GST_META_FLAG_POOLED);

    /* ...add custom destructor to the buffer */
    gst_mini_object_weak_ref(GST_MINI_OBJECT(buffer), __destroy_od_texture, app);

    TRACE(INFO, _b("front-camera input buffer %p allocated (%p)"), buffer, ometa->buf);

    return 0;
}