Ejemplo n.º 1
0
int main() {
	Connection *working;
	Surface *insurface;
	Surface *outsurface;
	DecodeParams decodeparams;
	int ret;
	FILE *out;
	int i;

	insurface = surface_init(640, 480);
	if(insurface == NULL) {
		fprintf(stderr, "Couldn't allocate memory.\n");
		return(-1);
	}
	outsurface = surface_init(640, 480);
	if(outsurface == NULL) {
		fprintf(stderr, "Couldn't allocate memory.\n");
		return(-1);
	}

	for(i = 0; i < 640 * 480; i++) {
		insurface->luma[i] = 127;
	}
	for(i = 0; i < 640 * 480; i++) {
		outsurface->luma[i] = 0;
	}

	decodeparams.syncthresh = 0.9;
	decodeparams.fuzzyness = 2;
	decodeparams.autolevel = 0.9;
	decodeparams.autostride = 0.9;

	working = NULL;
	ret = analog_encode(&working, insurface, 10);
	if(ret < 0) {
		fprintf(stderr, "Encode failed.\n");
		return(-2);
	}

/*	srand(time(NULL));
	for(i = 0; i < working->length; i++) {
		working->stream[i] += (double)(rand() % 2000) / 100 - 10;
	}
*/
	ret = analog_decode(working, outsurface, &decodeparams);
	if(ret < 0) {
		fprintf(stderr, "Decode failed.\n");
		return(-2);
	}

	out = fopen("out.bin", "wb");
	fwrite(outsurface->luma, outsurface->width * outsurface->height, 1, out);
	fclose(out);

	return(0);
}
Ejemplo n.º 2
0
int tvh_init(tvh_object_t *tvh) {
  DEBUG("initilizing TVHPlayer");

  avcodec_init();
  avcodec_register_all();

  pthread_mutex_init(&tvh->mutex, NULL);

  tvh->ao = malloc(sizeof(aout_sys_t));
  memset(tvh->ao, 0, sizeof(aout_sys_t));

  tvh->acs = malloc(sizeof(acodec_sys_t));
  memset(tvh->acs, 0, sizeof(acodec_sys_t));

  tvh->vo = malloc(sizeof(vout_sys_t));
  memset(tvh->vo, 0, sizeof(vout_sys_t));

  tvh->vcs = malloc(sizeof(vcodec_sys_t));
  memset(tvh->vcs, 0, sizeof(vcodec_sys_t));

  if(opensles_init(tvh->ao) < 0) {
    ERROR("Unable to initilize OpenSL ES");
    return -1;
  }

  opensles_set_callback(tvh->ao, &tvh_audio_callback, tvh);

  if(surface_init(tvh->vo) < 0) {
    ERROR("Unable to initilize the surface library");
    return -1;
  }
  return 0;
}
Ejemplo n.º 3
0
int main(int argc, char* argv[]) {

	s40 = sur40_get_device_handle();
	if (s40==NULL) return 0;
	surface_init( s40 );

        surface_set_vsvideo(s40);
        surface_set_irlevel(s40);
        surface_set_preprocessor(s40);

 	glutInitWindowSize(VIDEO_RES_X,VIDEO_RES_Y);
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH );
	glutCreateWindow("surfaceview");

	initGL();

	// make functions known to GLUT
	glutKeyboardFunc(keyboard);
	glutDisplayFunc(display);
	glutReshapeFunc(resize);
	glutIdleFunc(idle);

	// start the action
	glutMainLoop();

	sur40_close_device(s40);
	return 0;
}
Ejemplo n.º 4
0
Archivo: terminal.c Proyecto: jo-va/yak
void term_init(int term, vbe_mode_info_t *mode_info, 
               int x, int y, int w, int h, int fg_color, int bg_color, int scroll)
{
    term_surf[term].fb_w = mode_info->res_x;
    term_surf[term].fb_h = mode_info->res_y;
    term_surf[term].fb_bpp = mode_info->bpp;
    term_surf[term].ox = x;
    term_surf[term].oy = y;
    term_surf[term].x = term_surf[term].y = 0;
    term_surf[term].w = w;
    term_surf[term].h = h;
    term_surf[term].fg_color = fg_color;
    term_surf[term].bg_color = bg_color;
    term_surf[term].scroll = scroll;

    term_surf[term].framebuffer = term_surf[term].backbuffer = (unsigned char *)LFB_BASE;

    term_surf[term].rend = &term_rend[term];
    surface_init(&term_surf[term]);

    if ((bg_color & 0x00ffffff) != 0)
        term_surf[term].rend->clear(&term_surf[term]);

    current_term = term;
}
Ejemplo n.º 5
0
static int
yuvp_init(glw_video_t *gv)
{
  const glw_video_config_t *gvc = &gv->gv_cfg_cur;
  int i;

  memset(gv->gv_cmatrix_cur, 0, sizeof(float) * 16);

  for(i = 0; i < gvc->gvc_nsurfaces; i++)
    surface_init(gv, &gv->gv_surfaces[i], gvc);
  return 0;
}
Ejemplo n.º 6
0
PyMODINIT_FUNC PyInit_atlantis(void)
{
	PyObject *module;

	module = PyModule_Create(&atlantis_module);

	if (module == NULL) {
		return NULL;
	}

	surface_init(240, 160);

	return module;
}
Ejemplo n.º 7
0
static int64_t
video_opengl_newframe(glw_video_t *gv, video_decoder_t *vd, int flags)
{
  hts_mutex_assert(&gv->gv_surface_mutex);

  glw_video_surface_t *gvs;

  while((gvs = TAILQ_FIRST(&gv->gv_parked_queue)) != NULL) {
    TAILQ_REMOVE(&gv->gv_parked_queue, gvs, gvs_link);
    surface_init(gv, gvs);
  }

  glw_need_refresh(gv->w.glw_root, 0);

  gv_color_matrix_update(gv);
  return glw_video_newframe_blend(gv, vd, flags, &gv_surface_pixmap_release, 1);
}
Ejemplo n.º 8
0
static int64_t
gvv_newframe(glw_video_t *gv, video_decoder_t *vd0, int flags)
{
  video_decoder_t *vd = gv->gv_vd;
  media_pipe_t *mp = gv->gv_mp;

  gv->gv_cmatrix_cur[0] = (gv->gv_cmatrix_cur[0] * 3.0f +
			   gv->gv_cmatrix_tgt[0]) / 4.0f;

  if(flags & GLW_REINITIALIZE_VDPAU) {

    int i;
    for(i = 0; i < GLW_VIDEO_MAX_SURFACES; i++)
      gv->gv_surfaces[i].gvs_vdpau_surface = VDP_INVALID_HANDLE;

    gv->gv_engine = NULL;

    mp_send_cmd(mp, &mp->mp_video, MB_CTRL_REINITIALIZE);

    drain(gv, &gv->gv_displaying_queue);
    drain(gv, &gv->gv_decoded_queue);
    hts_cond_signal(&gv->gv_avail_queue_cond);

    return AV_NOPTS_VALUE;
  }

  glw_video_surface_t *gvs;

  while((gvs = TAILQ_FIRST(&gv->gv_parked_queue)) != NULL) {
    TAILQ_REMOVE(&gv->gv_parked_queue, gvs, gvs_link);
    surface_init(gv, gvs);
  }

  glw_need_refresh(gv->w.glw_root, 0);
  return glw_video_newframe_blend(gv, vd, flags, &gv_surface_pixmap_release, 1);
}
Ejemplo n.º 9
0
int main( int argc, char* argv[] ) {

	uint8_t buffer[VIDEO_BUFFER_SIZE];
	surface_blob blob[256];
	int result,frame = 0;

	usb_dev_handle* s40 = usb_get_device_handle( ID_MICROSOFT, ID_SURFACE );

	surface_init( s40 );

	while (1) {
		result = surface_get_blobs( s40, blob );
		if (result <= 0) continue;
		printf("%d blobs\n",result);
		for (int i = 0; i < result; i++)
			printf("    x: %d y: %d size: %d\n",blob[i].pos_x,blob[i].pos_y,blob[i].area);
		if ((frame++ % 60) == 0) printf("status 0x%08x\n",surface_get_status(s40));
	}

	surface_get_image( s40, buffer );
	FILE* foo = fopen("surface.raw","w+");
	fwrite(buffer,VIDEO_BUFFER_SIZE,1,foo);
	fclose(foo);
}
Ejemplo n.º 10
0
static int
vdpau_init(glw_video_t *gv)
{
  const glw_video_config_t *gvc = &gv->gv_cfg_cur;
  vdpau_dev_t *vd = gv->w.glw_root->gr_be.gbr_vdpau_dev;
  int i, nconfs;
  VdpStatus st;
  GLXFBConfig *fbconfig;

  for(i = 0; i < GLW_VIDEO_MAX_SURFACES; i++)
    gv->gv_surfaces[i].gvs_vdpau_surface = VDP_INVALID_HANDLE;

  gv->gv_vdpau_pq = VDP_INVALID_HANDLE;
  gv->gv_vdpau_pqt = VDP_INVALID_HANDLE;

  gv->gv_vdpau_initialized = 0;

  /* Pixmap */
  fbconfig = glXChooseFBConfig(vd->vd_dpy, 0, pixmap_attribs, &nconfs);
  if(nconfs < 1) {
    TRACE(TRACE_ERROR, "VDPAU", "Unable to find fbconfig for pixmap");
    return -1;
  }

  XWindowAttributes wndattribs;
  XGetWindowAttributes(vd->vd_dpy, DefaultRootWindow(vd->vd_dpy), &wndattribs);

  gv->gv_xpixmap = XCreatePixmap(vd->vd_dpy, glXGetCurrentDrawable(),
				 VDPAU_PIXMAP_WIDTH, VDPAU_PIXMAP_HEIGHT,
				 wndattribs.depth);

  gv->gv_glx_pixmap = glXCreatePixmap(vd->vd_dpy, *fbconfig, 
				      gv->gv_xpixmap, glx_pixmap_attribs);

  /* Presentation queue */
  st = vd->vdp_presentation_queue_target_create_x11(vd->vd_dev, gv->gv_xpixmap,
						    &gv->gv_vdpau_pqt);

  if(st != VDP_STATUS_OK) {
    TRACE(TRACE_ERROR, "VDPAU", "Unable to create pixmap target");
    return -1;
  }

  st = vd->vdp_presentation_queue_create(vd->vd_dev, gv->gv_vdpau_pqt,
					 &gv->gv_vdpau_pq);

  if(st != VDP_STATUS_OK) {
    TRACE(TRACE_ERROR, "VDPAU", "Unable to create presentation queue");
    return -1;
  }

  /* Video mixer */
  st = vdpau_mixer_create(vd, &gv->gv_vm, 
			  gvc->gvc_width[0], gvc->gvc_height[0]);
			  

  if(st != VDP_STATUS_OK) {
    TRACE(TRACE_ERROR, "VDPAU", "Unable to create video mixer");
    return -1;
  }
  

  /* Surfaces */
  for(i = 0; i < gvc->gvc_nsurfaces; i++) {
    if(surface_init(vd, gv, &gv->gv_surfaces[i], gvc)) {
      return -1;
    }
  }
  gv->gv_nextpts = AV_NOPTS_VALUE;
  return 0;
}
Ejemplo n.º 11
0
// change flight mode and perform any necessary initialisation
// returns true if mode was successfully set
bool Sub::set_mode(control_mode_t mode, mode_reason_t reason)
{
    // boolean to record if flight mode could be set
    bool success = false;

    // return immediately if we are already in the desired mode
    if (mode == control_mode) {
        prev_control_mode = control_mode;
        prev_control_mode_reason = control_mode_reason;

        control_mode_reason = reason;
        return true;
    }

    switch (mode) {
    case ACRO:
        success = acro_init();
        break;

    case STABILIZE:
        success = stabilize_init();
        break;

    case ALT_HOLD:
        success = althold_init();
        break;

    case AUTO:
        success = auto_init();
        break;

    case CIRCLE:
        success = circle_init();
        break;

    case GUIDED:
        success = guided_init();
        break;

    case SURFACE:
        success = surface_init();
        break;

#if POSHOLD_ENABLED == ENABLED
    case POSHOLD:
        success = poshold_init();
        break;
#endif

    case MANUAL:
        success = manual_init();
        break;

    default:
        success = false;
        break;
    }

    // update flight mode
    if (success) {
        // perform any cleanup required by previous flight mode
        exit_mode(control_mode, mode);

        prev_control_mode = control_mode;
        prev_control_mode_reason = control_mode_reason;

        control_mode = mode;
        control_mode_reason = reason;
        logger.Write_Mode(control_mode, control_mode_reason);

        // update notify object
        notify_flight_mode(control_mode);

#if CAMERA == ENABLED
        camera.set_is_auto_mode(control_mode == AUTO);
#endif

#if AC_FENCE == ENABLED
        // pilot requested flight mode change during a fence breach indicates pilot is attempting to manually recover
        // this flight mode change could be automatic (i.e. fence, battery, GPS or GCS failsafe)
        // but it should be harmless to disable the fence temporarily in these situations as well
        fence.manual_recovery_start();
#endif
    } else {
        // Log error that we failed to enter desired flight mode
        Log_Write_Error(ERROR_SUBSYSTEM_FLIGHT_MODE,mode);
    }

    // return success or failure
    return success;
}
Ejemplo n.º 12
0
/* was geo_fxyd */
static int
geo_fit_xy(
        geomap_fit_t* const fit,
        surface_t* const sf1,
        surface_t* const sf2,
        const size_t ncoord,
        const int xfit,
        const coord_t* const input,
        const coord_t* const ref,
        /* Output */
        int* has_secondary,
        double* const weights,
        double* const residual,
        stimage_error_t* error) {

    bbox_t              bbox;
    double*             zfit      = NULL;
    const double* const z = (double*)input + (xfit ? 0 : 1);
    surface_t           savefit;
    surface_fit_error_e fit_error = surface_fit_error_ok;
    size_t              i         = 0;
    int                 status    = 1;

    assert(fit);
    assert(sf1);
    assert(sf2);
    assert(ref);
    assert(weights);
    assert(residual);
    assert(has_secondary);
    assert(error);

    surface_new(&savefit);

    surface_free(sf1);
    surface_free(sf2);

    *has_secondary = 1;

    zfit = malloc_with_error(ncoord * sizeof(double), error);
    if (zfit == NULL) goto exit;

    bbox_copy(&fit->bbox, &bbox);
    bbox_make_nonsingular(&bbox);

    if (xfit) {
        switch(fit->fit_geometry) {
        case geomap_fit_shift:
            if (surface_init(
                        &savefit, fit->function, 2, 2, xterms_none, &bbox,
                        error)) goto exit;
            surface_free(sf1);
            if (surface_init(
                        sf1, fit->function, 1, 1, xterms_none, &bbox,
                        error)) goto exit;
            for (i = 0; i < ncoord; ++i) {
                zfit[i] = z[i<<1] - ref[i].x;
            }

            if (surface_fit(
                        sf1, ncoord, ref, zfit, weights,
                        surface_fit_weight_user, &fit_error, error)) goto exit;

            if (fit->function == surface_type_polynomial) {
                savefit.coeff[0] = sf1->coeff[0];
                savefit.coeff[1] = 1.0;
                savefit.coeff[2] = 0.0;
            } else {
                savefit.coeff[0] = sf1->coeff[0] + (bbox.max.x + bbox.min.x) / 2.0;
                savefit.coeff[1] = (bbox.max.x - bbox.min.x) / 2.0;
                savefit.coeff[2] = 0.0;
            }
            surface_free(sf1);
            if (surface_copy(&savefit, sf1, error)) goto exit;
            *has_secondary = 0;
            break;

        case geomap_fit_xyscale:
            if (surface_init(
                        sf1, fit->function, 2, 1, xterms_none, &bbox,
                        error)) goto exit;
            if (surface_fit(
                        sf1, ncoord, ref, z, weights,
                        surface_fit_weight_user, &fit_error, error)) goto exit;
            *has_secondary = 0;
            break;

        default:
            if (surface_init(
                        sf1, fit->function, 2, 2, xterms_none, &bbox,
                        error)) goto exit;
            if (surface_fit(
                        sf1, ncoord, ref, z, weights,
                        surface_fit_weight_user, &fit_error, error)) goto exit;

            if (fit->xxorder > 2 || fit->xyorder > 2 ||
                fit->xxterms == xterms_full) {
                if (surface_init(
                            sf2, fit->function, fit->xxorder, fit->xyorder,
                            fit->xxterms, &fit->bbox, error)) {
                    surface_free(sf1);
                    goto exit;
                }
            } else {
                *has_secondary = 0;
            }
            break;
        }
    } else {
        switch(fit->fit_geometry) {
        case geomap_fit_shift:
            if (surface_init(
                        &savefit, fit->function, 2, 2, xterms_none, &bbox,
                        error)) goto exit;
            surface_free(sf1);
            if (surface_init(
                        sf1, fit->function, 1, 1, xterms_none, &bbox,
                        error)) goto exit;
            for (i = 0; i < ncoord; ++i) {
                zfit[i] = z[i<<1] - ref[i].y;
            }
            if (surface_fit(
                        sf1, ncoord, ref, zfit, weights,
                        surface_fit_weight_user, &fit_error, error)) goto exit;
            if (fit->function == surface_type_polynomial) {
                savefit.coeff[0] = sf1->coeff[0];
                savefit.coeff[1] = 0.0;
                savefit.coeff[2] = 1.0;
            } else {
                savefit.coeff[0] = sf1->coeff[0] + (bbox.min.y + bbox.max.y) / 2.0;
                savefit.coeff[1] = 0.0;
                savefit.coeff[2] = (bbox.max.y - bbox.min.y) / 2.0;
            }
            surface_free(sf1);
            if (surface_copy(&savefit, sf1, error)) goto exit;

            *has_secondary = 0;
            break;

        case geomap_fit_xyscale:
            if (surface_init(
                        sf1, fit->function, 1, 2, xterms_none, &bbox,
                        error)) goto exit;
            if (surface_fit(
                        sf1, ncoord, ref, z, weights,
                        surface_fit_weight_user, &fit_error, error)) goto exit;
            *has_secondary = 0;
            break;

        default:
            if (surface_init(
                        sf1, fit->function, 2, 2, xterms_none, &bbox,
                        error)) goto exit;
            if (surface_fit(
                        sf1, ncoord, ref, z, weights,
                        surface_fit_weight_user, &fit_error, error)) goto exit;
            if (fit->yxorder > 2 || fit->yyorder > 2 ||
                fit->yxterms == xterms_full) {
                if (surface_init(
                            sf2, fit->function, fit->yxorder, fit->yyorder,
                            fit->yxterms, &bbox, error)) goto exit;
            } else {
                *has_secondary = 0;
            }

            break;
        }
    }

    if (_geo_fit_xy_validate_fit_error(
                fit_error, xfit, fit->projection, error)) goto exit;

    if (surface_vector(sf1, ncoord, ref, residual, error)) goto exit;
    for (i = 0; i < ncoord; ++i) {
        residual[i] = z[i<<1] - residual[i];
    }

    /* Calculate the higher-order fit */
    if (*has_secondary) {
        if (surface_fit(
                    sf2, ncoord, ref, residual, weights,
                    surface_fit_weight_user, &fit_error, error)) goto exit;
        if (_geo_fit_xy_validate_fit_error(
                    fit_error, xfit, fit->projection, error)) goto exit;

        if (surface_vector(sf2, ncoord, ref, zfit, error)) goto exit;
        for (i = 0; i < ncoord; ++i) {
            residual[i] = zfit[i] - residual[i];
        }
    }

    /* Compute the number of zero weighted points */
    fit->n_zero_weighted = count_zero_weighted(ncoord, weights);

    /* Calculate the RMS of the fit */
    if (xfit) {
        fit->xrms = 0.0;
        for (i = 0; i < ncoord; ++i) {
            fit->xrms += weights[i] * residual[i] * residual[i];
        }
    } else {
        fit->yrms = 0.0;
        for (i = 0; i < ncoord; ++i) {
            fit->yrms += weights[i] * residual[i] * residual[i];
        }
    }

    fit->ncoord = ncoord;

    status = 0;

 exit:

    surface_free(&savefit);
    free(zfit);

    return status;
}
Ejemplo n.º 13
0
static int
compute_surface_coefficients(
        const surface_type_e function,
        const bbox_t* const bbox,
        const coord_t* const i0,
        const coord_t* const r0,
        const coord_t* const cthetac,
        const coord_t* const sthetac,
        surface_t* const sx1,
        surface_t* const sy1,
        stimage_error_t* const error) {

    int       status = 1;

    assert(bbox);
    assert(i0);
    assert(r0);
    assert(cthetac);
    assert(sthetac);
    assert(sx1);
    assert(sy1);
    assert(error);

    /* Compute the x fit coefficients */
    if (surface_init(
                sx1, function, 2, 2, xterms_none, bbox, error)) goto exit;

    if (function == surface_type_polynomial) {
        sx1->coeff[0] = i0->x - (r0->x*cthetac->x + r0->y*sthetac->x);
        sx1->coeff[1] = cthetac->x;
        sx1->coeff[2] = sthetac->x;
    } else {
        sx1->coeff[0] = i0->x - (r0->x*cthetac->x + r0->y*sthetac->x) + \
            cthetac->x*(bbox->max.x + bbox->min.x)/2.0 + \
            sthetac->x*(bbox->max.y + bbox->min.y)/2.0;
        sx1->coeff[1] = cthetac->x * (bbox->max.x - bbox->min.x) / 2.0;
        sx1->coeff[2] = sthetac->x * (bbox->max.y - bbox->min.y) / 2.0;
    }

    /* Compute the y fit coefficients */
    if (surface_init(
                sy1, function, 2, 2, xterms_none, bbox, error)) goto exit;

    if (function == surface_type_polynomial) {
        sy1->coeff[0] = i0->y - (-r0->x*sthetac->y + r0->y*cthetac->y);
        sy1->coeff[1] = -sthetac->y;
        sy1->coeff[2] = cthetac->y;
    } else {
        sy1->coeff[0] = i0->y - (-r0->x*sthetac->y + r0->y*cthetac->y) - \
            sthetac->y*(bbox->max.x + bbox->min.x) / 2.0 +              \
            cthetac->y*(bbox->max.y + bbox->min.y) / 2.0;
        sy1->coeff[1] = -sthetac->y * (bbox->max.x - bbox->min.x) / 2.0;
        sy1->coeff[2] = cthetac->y * (bbox->max.y - bbox->min.y) / 2.0;
    }

    status = 0;

 exit:

    return 0;
}