Esempio n. 1
0
/**
 * Initialise initrd
 *
 * @ret rc		Return status code
 */
static int initrd_init ( void ) {
	struct image *image;
	int rc;

	/* Do nothing if no initrd was specified */
	if ( ! initrd_phys ) {
		DBGC ( colour, "RUNTIME found no initrd\n" );
		return 0;
	}
	if ( ! initrd_len ) {
		DBGC ( colour, "RUNTIME found empty initrd\n" );
		return 0;
	}
	DBGC ( colour, "RUNTIME found initrd at [%x,%x)\n",
	       initrd_phys, ( initrd_phys + initrd_len ) );

	/* Allocate image */
	image = alloc_image();
	if ( ! image ) {
		DBGC ( colour, "RUNTIME could not allocate image for "
		       "initrd\n" );
		rc = -ENOMEM;
		goto err_alloc_image;
	}
	image_set_name ( image, "<INITRD>" );

	/* Allocate and copy initrd content */
	image->data = umalloc ( initrd_len );
	if ( ! image->data ) {
		DBGC ( colour, "RUNTIME could not allocate %zd bytes for "
		       "initrd\n", initrd_len );
		rc = -ENOMEM;
		goto err_umalloc;
	}
	image->len = initrd_len;
	memcpy_user ( image->data, 0, phys_to_user ( initrd_phys ), 0,
		      initrd_len );

	/* Mark initrd as consumed */
	initrd_phys = 0;

	/* Register image */
	if ( ( rc = register_image ( image ) ) != 0 ) {
		DBGC ( colour, "RUNTIME could not register initrd: %s\n",
		       strerror ( rc ) );
		goto err_register_image;
	}

	/* Drop our reference to the image */
	image_put ( image );

	return 0;

 err_register_image:
 err_umalloc:
	image_put ( image );
 err_alloc_image:
	return rc;
}
Esempio n. 2
0
/**
 * Initialise command line
 *
 * @ret rc		Return status code
 */
static int cmdline_init ( void ) {
	userptr_t cmdline_user;
	char *cmdline;
	size_t len;
	int rc;

	/* Do nothing if no command line was specified */
	if ( ! cmdline_phys ) {
		DBGC ( colour, "RUNTIME found no command line\n" );
		return 0;
	}
	cmdline_user = phys_to_user ( cmdline_phys );
	len = ( strlen_user ( cmdline_user, 0 ) + 1 /* NUL */ );

	/* Allocate and copy command line */
	cmdline_copy = malloc ( len );
	if ( ! cmdline_copy ) {
		DBGC ( colour, "RUNTIME could not allocate %zd bytes for "
		       "command line\n", len );
		rc = -ENOMEM;
		goto err_alloc_cmdline_copy;
	}
	cmdline = cmdline_copy;
	copy_from_user ( cmdline, cmdline_user, 0, len );
	DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
	       cmdline, cmdline_phys );

	/* Mark command line as consumed */
	cmdline_phys = 0;

	/* Strip unwanted cruft from the command line */
	cmdline_strip ( cmdline, "BOOT_IMAGE=" );
	cmdline_strip ( cmdline, "initrd=" );
	while ( isspace ( *cmdline ) )
		cmdline++;
	DBGC ( colour, "RUNTIME using command line \"%s\"\n", cmdline );

	/* Prepare and register image */
	cmdline_image.data = virt_to_user ( cmdline );
	cmdline_image.len = strlen ( cmdline );
	if ( cmdline_image.len ) {
		if ( ( rc = register_image ( &cmdline_image ) ) != 0 ) {
			DBGC ( colour, "RUNTIME could not register command "
			       "line: %s\n", strerror ( rc ) );
			goto err_register_image;
		}
	}

	/* Drop our reference to the image */
	image_put ( &cmdline_image );

	return 0;

 err_register_image:
	image_put ( &cmdline_image );
 err_alloc_cmdline_copy:
	return rc;
}
Esempio n. 3
0
/**
 * Free downloader object
 *
 * @v refcnt		Downloader reference counter
 */
static void downloader_free ( struct refcnt *refcnt ) {
	struct downloader *downloader =
		container_of ( refcnt, struct downloader, refcnt );

	image_put ( downloader->image );
	free ( downloader );
}
Esempio n. 4
0
// Reading the data from memory, converting it to RGB, and then showing the picture
void show_video( IMAGE_CONTEXT *image_ctx, uchar **frame, uchar thres[3][256], int color, int bf, int bc, bool *halt )
{
	XImage *xImage1 = image_ctx->xImage;
	XEvent event;

	uchar Y, U, V;
	uchar R, G, B;
	int pix_c = 0;
	int by_s, by_e, bx_s, bx_e, ys, ye, us, ue, vs, ve;


	uchar *imageLine1 = (uchar*) xImage1 -> data;


	for( int i = 0; i < g_height; i++ ) {
	    for( int j = 0; j < 3*g_width; j += 3 ) {

            Y = frame[i][ j + 0 ];
            U = frame[i][ j + 1 ];
            V = frame[i][ j + 2 ];

            yuv_to_rgb( Y, U, V, &R, &G, &B );
            imageLine1[ 4*pix_c + 0 ] = R;
            imageLine1[ 4*pix_c + 1 ] = G;
            imageLine1[ 4*pix_c + 2 ] = B;
            imageLine1[ 4*pix_c + 3 ] = 255;


            pix_c++;
	    }
	}

	image_put( image_ctx );

	if ( XPending( image_ctx->display ) > 0 ) {
		XNextEvent( image_ctx->display, &event );


		if( event.type == KeyPress ) {
		    if( event.xkey.keycode == 65 ) {     // if SPACE is pressed
                if( *halt == false ) *halt = true;
                else *halt = false;
		    } else
                memcpy( thres, last_thres, 768 );
		}

        if( event.type == ButtonPress ) {

            memcpy( last_thres, thres, 768 );
            by_s = 0; by_e = g_height; bx_s = 0; bx_e = g_width;

            if( event.xbutton.y - bf + 1 >= 0 ) by_s = event.xbutton.y - bf + 1;
            if( event.xbutton.y + bf <= g_height ) by_e = event.xbutton.y + bf;
            if( event.xbutton.x - bf + 1 >= 0 ) bx_s = event.xbutton.x - bf + 1;
            if( event.xbutton.x + bf <= g_width ) bx_e = event.xbutton.x + bf;

            for( int i = by_s; i < by_e; i++ ) for( int j = bx_s; j < bx_e; j++ ) {

                Y = frame[i][ 3*j + 0 ];
                U = frame[i][ 3*j + 1 ];
                V = frame[i][ 3*j + 2 ];

                ys = 0;
                ye = 256;
                us = 0;
                ue = 256;
                vs = 0;
                ve = 256;
                if( Y - bc + 1 >= 0 ) ys = Y - bc + 1;
                if( Y + bc <= 256 ) ye = Y + bc;
                if( U - bc + 1 >= 0 ) us = U - bc + 1;
                if( U + bc <= 256 ) ue = U + bc;
                if( V - bc + 1 >= 0 ) vs = V - bc + 1;
                if( V + bc <= 256 ) ve = V + bc;


                for( int k = ys; k < ye; k++ ) thres[0][k] |= 1 << color;
                for( int k = us; k < ue; k++ ) thres[1][k] |= 1 << color;
                for( int k = vs; k < ve; k++ ) thres[2][k] |= 1 << color;
            }
        }
	}
}
Esempio n. 5
0
void show_threshold( IMAGE_CONTEXT *image_ctx, uchar **frame, uchar thres[3][256], int color, int bf, int bc )
{
    XImage *xImage1 = image_ctx->xImage;
    XEvent event;
	uchar Y, U, V;
	int pix_c = 0;
	bool col;
	int by_s, by_e, bx_s, bx_e, ys, ye, us, ue, vs, ve;

	uchar *imageLine1 = (uchar*) xImage1 -> data;


    for( int i = 0; i < g_height; i++ ) {
	    for( int j = 0; j < 3*g_width; j += 3 ) {

            Y = frame[i][ j + 0 ];
            U = frame[i][ j + 1 ];
            V = frame[i][ j + 2 ];

            col = isColor( thres, Y, U, V, color );

            if( col ) for(int i=0; i<4; i++) imageLine1[ 4*pix_c + i ] = 255;
            else for(int i=0; i<4; i++) imageLine1[ 4*pix_c + i ] = 0;


            pix_c++;
	    }
	}


	image_put( image_ctx );



	if ( XPending( image_ctx->display ) > 0 ) {

	    XNextEvent( image_ctx->display, &event );

	    if( event.type == KeyPress ) {
	        memcpy( thres, last_thres, 768 );
	    }

	    if( event.type == ButtonPress ) {

            memcpy( last_thres, thres, 768 );

            by_s = 0; by_e = g_height; bx_s = 0; bx_e = g_width;

            if( event.xbutton.y - bf + 1 >= 0 ) by_s = event.xbutton.y - bf + 1;
            if( event.xbutton.y + bf <= g_height ) by_e = event.xbutton.y + bf;
            if( event.xbutton.x - bf + 1 >= 0 ) bx_s = event.xbutton.x - bf + 1;
            if( event.xbutton.x + bf <= g_width ) bx_e = event.xbutton.x + bf;

            for( int i = by_s; i < by_e; i++ ) for( int j = bx_s; j < bx_e; j++ ) {

                Y = frame[i][ 3*j + 0 ];
                U = frame[i][ 3*j + 1 ];
                V = frame[i][ 3*j + 2 ];

                ys = 0;
                ye = 256;
                us = 0;
                ue = 256;
                vs = 0;
                ve = 256;
                if( Y - bc + 1 >= 0 ) ys = Y - bc + 1;
                if( Y + bc <= 256 ) ye = Y + bc;
                if( U - bc + 1 >= 0 ) us = U - bc + 1;
                if( U + bc <= 256 ) ue = U + bc;
                if( V - bc + 1 >= 0 ) vs = V - bc + 1;
                if( V + bc <= 256 ) ve = V + bc;


                for( int k = ys; k < ye; k++ ) thres[0][k] &= ~( 1 << color );
                for( int k = us; k < ue; k++ ) thres[1][k] &= ~( 1 << color );
                for( int k = vs; k < ve; k++ ) thres[2][k] &= ~( 1 << color );
            }
	    }
	}
}