Exemplo n.º 1
0
static int v4l2_case_take_pic(void* user_ptr, int test_num)
{
	FUNC_ENTER()
	BLTS_DEBUG("Test number %i:\n", test_num);
	v4l2_data* data = (v4l2_data*)user_ptr;

	if(!open_device (data->device))
	{
		BLTS_ERROR("Can't open device %s\n", data->device->dev_name);
		return -1;
	}

	if(init_device (data->device, data->device->requested_format.fmt.pix.width, data->device->requested_format.fmt.pix.height))
	{
		if(data->snapshot_filename != NULL)
		{
			free(data->snapshot_filename);
			data->snapshot_filename = NULL;
		}
		data->snapshot_filename = create_picture_filename(data->device);
		BLTS_DEBUG("Filename to create: '%s'\n", data->snapshot_filename);
		BLTS_DEBUG("Maximum resolution is: %ix%i\n", data->device->format.fmt.pix.width, data->device->format.fmt.pix.height);

		if(!start_capturing (data->device))
			goto err;
		if(!mainloop (data->device, 0))
			goto err;
		BLTS_DEBUG("Taking picture %s\n", data->snapshot_filename);
		if(!do_snapshot (data->device, data->snapshot_filename))
			goto err;
		// ensure that image is actual JPEG
		if(read_jpeg_image(data->snapshot_filename))
		{
			BLTS_DEBUG("Error, image %s is not JPEG standard.\n", data->snapshot_filename);
			return -1;
		}


		stop_capturing (data->device);
		uninit_device (data->device);
	}
	else
	{
		BLTS_ERROR("Can't initialize device\n");
		goto err;
	}

	close_device (data->device);
	FUNC_LEAVE()
	return 0;

err:

	stop_capturing(data->device);
	uninit_device(data->device);
	close_device(data->device);
	FUNC_LEAVE()
	return -1;
}
//#include <malloc.h>
int test_dec_from_file(int argc, const char *argv[])
{
    int width, height ,mode,flag,i;    
    char* outputdata;
    aml_image_info_t* image_info;
    if(argc < 5){        
        printf("Amlogic jpeg decoder API \n");
        printf("usage: output [filename] [width] [height] [mode] [flag]\n");
        printf("options :\n");
        printf("         filename : jpeg url in your root fs\n");
        printf("         width    : output width\n");
        printf("         height   : output height\n");
        printf("         mode     : 0/keep ratio  1/crop image 2/stretch image\n");
        printf("         flag     : 0/disable display 1/antiflicking disable&enable display  2/antiflicking enable&enable display \n ");
        return -1;    
    }else{
        printf("%s\n", argv[1]);
    }  
    width =  atoi(argv[2]);
    if((width <1)||(width > 1920)){
        printf("invalid width \n");
        return -1;    
    }
    height = atoi(argv[3]);
    if((height <1)||(height > 1080)){
        printf("invalid height \n");
        return -1;    
    }    
    mode  =  atoi(argv[4]);
    flag  =  atoi(argv[5]);    
    if((mode <0)||(mode > 2)){
        printf("invalid mode \n");
        return -1;    
    }    
    printf("url    is %s ;\n", argv[1]);
    printf("width  is %d ;\n", width);
    printf("height is %d ;\n", height);
    printf("mode   is %d ;\n", mode);
    if(amljpeg_init()<0 ) {
		printf("f*****g cmem initing error, decode exited\n");
		exit(1);
	}
    image_info = read_jpeg_image((char*)argv[1],width,height,mode,flag,flag,0);
    if(image_info){
        printf("output image width is %d\n", image_info->width);
        printf("output image height is %d\n", image_info->height);
        printf("output image depth is %d\n", image_info->depth);
        printf("output image bytes_per_line is %d\n", image_info->bytes_per_line);
        printf("output image nbytes   is %d\n", image_info->nbytes);
    }
    if(image_info){
        free(image_info);    
        image_info = NULL;
    }
    amljpeg_exit();      
    return 0;  
}
Exemplo n.º 3
0
/* Read a JPEG file into a VIPS image.
 */
int
vips__jpeg_read_file( const char *filename, VipsImage *out,
                      gboolean header_only, int shrink, gboolean fail )
{
    ReadJpeg *jpeg;
    int result;

    if( !(jpeg = readjpeg_new( out, shrink, fail )) )
        return( -1 );

    /* Here for longjmp() from vips__new_error_exit() during startup.
     */
    if( setjmp( jpeg->eman.jmp ) ) {
        (void) readjpeg_free( jpeg );

        return( -1 );
    }

    /* Set input to file.
     */
    if( readjpeg_file( jpeg, filename ) ) {
        (void) readjpeg_free( jpeg );

        return( -1 );
    }

    /* Need to read in APP1 (EXIF metadata), APP2 (ICC profile), APP13
     * (photoshop IPCT).
     */
    jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 1, 0xffff );
    jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 2, 0xffff );
    jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 13, 0xffff );

    /* Convert!
     */
    if( header_only )
        result = read_jpeg_header( jpeg, out );
    else
        result = read_jpeg_image( jpeg, out );

    /* Don't call readjpeg_free(), we're probably still live.
     */

    return( result );
}
Exemplo n.º 4
0
/**
 * im_bufjpeg2vips:
 * @buf: memory area to load
 * @len: size of memory area
 * @out: image to write
 * @header_only: set to just read the header
 *
 * Read a JPEG-formatted memory block into a VIPS image. It can read most 
 * 8-bit JPEG images, including CMYK and YCbCr.
 *
 * This function is handy for processing JPEG image thumbnails.
 *
 * See also: #VipsFormat, im_jpeg2vips().
 *
 * Returns: 0 on success, -1 on error.
 */
int
im_bufjpeg2vips( void *buf, size_t len, IMAGE *out, gboolean header_only )
{
	struct jpeg_decompress_struct cinfo;
        ErrorManager eman;
	int result;
	gboolean invert_pels;

	/* Make jpeg dcompression object.
 	 */
        cinfo.err = jpeg_std_error( &eman.pub );
	eman.pub.error_exit = new_error_exit;
	eman.pub.output_message = new_output_message;
	eman.fp = NULL;
	if( setjmp( eman.jmp ) ) {
		/* Here for longjmp() from new_error_exit().
		 */
		jpeg_destroy_decompress( &cinfo );

		return( -1 );
	}
        jpeg_create_decompress( &cinfo );

	/* Make input.
	 */
	buf_source( &cinfo, buf, len );

	/* Need to read in APP1 (EXIF metadata) and APP2 (ICC profile).
	 */
	jpeg_save_markers( &cinfo, JPEG_APP0 + 1, 0xffff );
	jpeg_save_markers( &cinfo, JPEG_APP0 + 2, 0xffff );

	/* Convert!
	 */
	result = read_jpeg_header( &cinfo, out, &invert_pels, 1 );
	if( !header_only && !result )
		result = read_jpeg_image( &cinfo, out, invert_pels );

	/* Close and tidy.
	 */
	jpeg_destroy_decompress( &cinfo );

	return( result );
}
Exemplo n.º 5
0
image_t * read_image(image_t * image)
{
        FILE * infile;
        if ((infile = fopen(image->path, "rb")) == NULL) {
                fprintf(stderr, "can't open %s\n", image->path);
                return NULL;
        }
        unsigned char sig[8];
        fread(sig, 1, 8, infile);
        if (png_sig_cmp(sig, 0, 8) == 0) {
                image = read_png_image(image, infile);
        } else if (sig[0] == 0xFF && sig[1] == 0xd8) {
                fseek(infile, 0, 0);
                image = read_jpeg_image(image, infile);
        } else {
                printf("%s is not a jpeg file\n", image->path);
                return NULL;
        }
        fclose(infile);
        return image;
}
Exemplo n.º 6
0
int
vips__jpeg_read_buffer( void *buf, size_t len, VipsImage *out,
                        gboolean header_only, int shrink, int fail )
{
    ReadJpeg *jpeg;
    int result;

    if( !(jpeg = readjpeg_new( out, shrink, fail )) )
        return( -1 );

    if( setjmp( jpeg->eman.jmp ) ) {
        (void) readjpeg_free( jpeg );

        return( -1 );
    }

    /* Set input to buffer.
     */
    readjpeg_buffer( jpeg, buf, len );

    /* Need to read in APP1 (EXIF metadata) and APP2 (ICC profile).
     */
    jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 1, 0xffff );
    jpeg_save_markers( &jpeg->cinfo, JPEG_APP0 + 2, 0xffff );

    /* Convert!
     */
    if( header_only )
        result = read_jpeg_header( jpeg, out );
    else
        result = read_jpeg_image( jpeg, out );

    /* Don't call readjpeg_free(), we're probably still live.
     */

    return( result );
}
Exemplo n.º 7
0
/* Read a JPEG file into a VIPS image.
 */
static int
jpeg2vips( const char *name, IMAGE *out, gboolean header_only )
{
	char filename[FILENAME_MAX];
	char mode[FILENAME_MAX];
	char *p, *q;
	int shrink;
	struct jpeg_decompress_struct cinfo;
        ErrorManager eman;
	FILE *fp;
	int result;
	gboolean invert_pels;
	gboolean fail_on_warn;

	/* By default, we ignore any warnings. We want to get as much of
	 * the user's data as we can.
	 */
	fail_on_warn = FALSE;

	/* Parse the filename.
	 */
	im_filename_split( name, filename, mode );
	p = &mode[0];
	shrink = 1;
	if( (q = im_getnextoption( &p )) ) {
		shrink = atoi( q );

		if( shrink != 1 && shrink != 2 && 
			shrink != 4 && shrink != 8 ) {
			im_error( "im_jpeg2vips", 
				_( "bad shrink factor %d" ), shrink );
			return( -1 );
		}
	}
	if( (q = im_getnextoption( &p )) ) {
		if( im_isprefix( "fail", q ) ) 
			fail_on_warn = TRUE;
	}

	/* Make jpeg dcompression object.
 	 */
        cinfo.err = jpeg_std_error( &eman.pub );
	eman.pub.error_exit = new_error_exit;
	eman.pub.output_message = new_output_message;
	eman.fp = NULL;
	if( setjmp( eman.jmp ) ) {
		/* Here for longjmp() from new_error_exit().
		 */
		jpeg_destroy_decompress( &cinfo );

		return( -1 );
	}
        jpeg_create_decompress( &cinfo );

	/* Make input.
	 */
        if( !(fp = im__file_open_read( filename, NULL, FALSE )) ) 
                return( -1 );
	eman.fp = fp;
        jpeg_stdio_src( &cinfo, fp );

	/* Need to read in APP1 (EXIF metadata) and APP2 (ICC profile).
	 */
	jpeg_save_markers( &cinfo, JPEG_APP0 + 1, 0xffff );
	jpeg_save_markers( &cinfo, JPEG_APP0 + 2, 0xffff );

	/* Convert!
	 */
	result = read_jpeg_header( &cinfo, out, &invert_pels, shrink );
	if( !header_only && !result )
		result = read_jpeg_image( &cinfo, out, invert_pels );

	/* Close and tidy.
	 */
	fclose( fp );
	eman.fp = NULL;
	jpeg_destroy_decompress( &cinfo );

	if( eman.pub.num_warnings != 0 ) {
		if( fail_on_warn ) {
			im_error( "im_jpeg2vips", "%s", im_error_buffer() );
			result = -1;
		}
		else {
			im_warn( "im_jpeg2vips", _( "read gave %ld warnings" ), 
				eman.pub.num_warnings );
			im_warn( "im_jpeg2vips", "%s", im_error_buffer() );
		}
	}

	return( result );
}