示例#1
0
/* Open an image, returning the best version of that image for thumbnailing. 
 *
 * libjpeg supports fast shrink-on-read, so if we have a JPEG, we can ask 
 * VIPS to load a lower resolution version.
 */
static VipsImage *
thumbnail_open( VipsObject *process, const char *filename )
{
	const char *loader;
	VipsImage *im;

	vips_info( "vipsthumbnail", "thumbnailing %s", filename );

	if( linear_processing )
		vips_info( "vipsthumbnail", "linear mode" ); 

	if( !(loader = vips_foreign_find_load( filename )) )
		return( NULL );

	vips_info( "vipsthumbnail", "selected loader is %s", loader ); 

	if( strcmp( loader, "VipsForeignLoadJpegFile" ) == 0 ) {
		int jpegshrink;

		/* This will just read in the header and is quick.
		 */
		if( !(im = vips_image_new_from_file( filename, NULL )) )
			return( NULL );

		jpegshrink = thumbnail_find_jpegshrink( im );

		g_object_unref( im );

		vips_info( "vipsthumbnail", 
			"loading jpeg with factor %d pre-shrink", 
			jpegshrink ); 

		if( !(im = vips_image_new_from_file( filename, 
			"access", VIPS_ACCESS_SEQUENTIAL,
			"shrink", jpegshrink,
			NULL )) )
			return( NULL );
	}
	else {
		/* All other formats.
		 */
		if( !(im = vips_image_new_from_file( filename, 
			"access", VIPS_ACCESS_SEQUENTIAL,
			NULL )) )
			return( NULL );
	}

	vips_object_local( process, im );

	return( im ); 
}
示例#2
0
文件: type.c 项目: alon/libvips
static void
transform_g_string_array_image( const GValue *src_value, GValue *dest_value )
{
	char *str;
	int n;
	char *p, *q;
	int i;
	GObject **array;

	/* We need a copy of the string, since we insert \0 during
	 * scan.
	 */
	str = g_value_dup_string( src_value );
	n = 0;
	for( p = str; (q = vips_break_token( p, " " )); p = q ) 
		n += 1;
	g_free( str );

	vips_value_set_array_object( dest_value, n );
	array = vips_value_get_array_object( dest_value, NULL );

	str = g_value_dup_string( src_value );
	for( i = 0, p = str; (q = vips_break_token( p, " " )); i++, p = q )
		if( !(array[i] = G_OBJECT( vips_image_new_from_file( p ) )) ) {
			/* Set the dest to length zero to indicate error.
			 */
			vips_value_set_array_object( dest_value, 0 );
			g_free( str );
			return;
		}
	g_free( str );
}
示例#3
0
int 
main( int argc, char **argv )
{
        VipsImage *global;
        VipsImage **t;

        if( VIPS_INIT( argv[0] ) )
                return( -1 );

        global = vips_image_new();
        t = (VipsImage **) vips_object_local_array( VIPS_OBJECT( global ), 5 );

	VipsInterpolate *interp = vips_interpolate_new( "bilinear" );

        if( !(t[0] = vips_image_new_from_file( argv[1],
                "access", VIPS_ACCESS_SEQUENTIAL,
                NULL )) )
                vips_error_exit( NULL );

        t[1] = vips_image_new_matrixv( 3, 3, 
                -1.0, -1.0, -1.0, 
                -1.0, 16.0, -1.0,
                -1.0, -1.0, -1.0 );
        vips_image_set_double( t[1], "scale", 8 );

        if( vips_extract_area( t[0], &t[2], 
                100, 100, t[0]->Xsize - 200, t[0]->Ysize - 200, NULL ) ||
                vips_similarity( t[2], &t[3], 
			"scale", 0.9, 
			"interpolate", interp, 
			NULL ) ||
                vips_conv( t[3], &t[4], t[1], NULL ) ||
                vips_image_write_to_file( t[4], argv[2], NULL ) )
                vips_error_exit( NULL ); 

        g_object_unref( global );
        g_object_unref( interp );

        return( 0 );
}
示例#4
0
/* Some interpolators look a little soft, so we have an optional sharpening
 * stage.
 */
static VipsImage *
thumbnail_sharpen( VipsObject *process )
{
	VipsImage *mask;

	if( strcmp( convolution_mask, "none" ) == 0 ) 
		mask = NULL; 
	else if( strcmp( convolution_mask, "mild" ) == 0 ) {
		mask = vips_image_new_matrixv( 3, 3,
			-1.0, -1.0, -1.0,
			-1.0, 32.0, -1.0,
			-1.0, -1.0, -1.0 );
		vips_image_set_double( mask, "scale", 24 );
	}
	else
		if( !(mask = 
			vips_image_new_from_file( convolution_mask, NULL )) )
			vips_error_exit( "unable to load sharpen mask" ); 

	if( mask )
		vips_object_local( process, mask );

	return( mask );
}
示例#5
0
文件: load.c 项目: jcupitt/gegl-vips
static void
gegl_load_prepare (GeglOperation * operation)
{
  GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
  GeglNode *node = operation->node;

  guint64 hash;

  printf ("gegl_load_prepare: 1\n");

  hash = 0;
  hash = GEGL_VIPS_HASH_STRING( hash, o->path );

  if (!node->vips_image || node->vips_hash != hash)
    {
      VipsImage *image;
      VipsImage *t[10];

      image = vips_image_new ("p");

      /*
      // load as linear float with a LUT
      if (vips_image_new_array (VIPS_OBJECT(image), t, 4) ||
        !(t[3] = vips_image_new_from_file (o->path, "r")) ||
	 im_identity (t[0], 1) ||
	 im_powtra (t[0], t[1], 1.0 / 2.4) ||
	 im_lintra (255.0 / pow (255.0, 1.0 / 2.4), t[1], 0.0, t[2]) ||
	 im_maplut (t[3], image, t[2]))
	{
	  gegl_vips_error ("load");
	  g_object_unref (image);
	  return;
	}
		 */

      /*
      // load as linear float with a LUT, add an alpha channel
      if (vips_image_new_array (VIPS_OBJECT(image), t, 10) ||
        !(t[0] = vips_image_new_from_file (o->path, "r")) ||
	 im_black (t[1], 1, 1, 1) ||
	 im_lintra (1, t[1], 255.0, t[2]) ||
	 im_clip2fmt (t[2], t[3], VIPS_FORMAT_UCHAR) ||
	 im_embed (t[3], t[4], 1, 0, 0, t[0]->Xsize, t[0]->Ysize) ||
	 im_bandjoin (t[0], t[4], t[5]) ||
	 im_identity (t[6], 1) ||
	 im_powtra (t[6], t[7], 1.0 / 2.4) ||
	 im_lintra (255.0 / pow (255.0, 1.0 / 2.4), t[7], 0.0, t[8]) ||
	 im_maplut (t[5], image, t[8]))
	{
	  gegl_vips_error ("load");
	  g_object_unref (image);
	  return;
	}
		 */

      /*
      // load as linear float, no LUT
      if (vips_image_new_array (VIPS_OBJECT(image), t, 4) ||
        !(t[0] = vips_image_new_from_file (o->path, "r")) ||
	 im_lintra (1.0 / 255.0, t[0], 0.0, t[1]) ||
	 im_powtra (t[1], image, 1.0 / 2.4))
	{
	  gegl_vips_error ("load");
	  g_object_unref (image);
	  return;
	}
	 */

      /*
      // load as linear float, no LUT, add an alpha channel
      if (vips_image_new_array (VIPS_OBJECT(image), t, 8) ||
        !(t[0] = vips_image_new_from_file (o->path, "r")) ||
	 im_black (t[2], 1, 1, 1) ||
	 im_lintra (1, t[2], 255.0, t[3]) ||
	 im_clip2fmt (t[3], t[4], VIPS_FORMAT_UCHAR) ||
	 im_embed (t[4], t[5], 1, 0, 0, t[0]->Xsize, t[0]->Ysize) ||
	 im_bandjoin (t[0], t[5], t[6]) ||
	 im_lintra (1.0 / 255.0, t[6], 0.0, t[7]) ||
	 im_powtra (t[7], image, 1.0 / 2.4))
	{
	  gegl_vips_error ("load");
	  g_object_unref (image);
	  return;
	}
	*/

      /*

	 int version

       */
	if (!(image = vips_image_new_from_file (o->path, "r")))
	  {
	    gegl_vips_error ("load");
	    return;
	  }


      node->vips_image = image;
      node->vips_hash = hash;

      printf ("gegl_load_prepare:\n");
      printf ("\tpath = %s\n", o->path);
      printf ("\tattaching to node = %p\n", node);
    }

  return;
}
示例#6
0
/* Open an image, returning the best version of that image for thumbnailing. 
 *
 * libjpeg supports fast shrink-on-read, so if we have a JPEG, we can ask 
 * VIPS to load a lower resolution version.
 */
static VipsImage *
thumbnail_open( VipsObject *process, const char *filename )
{
	const char *loader;
	VipsImage *im;

	vips_info( "vipsthumbnail", "thumbnailing %s", filename );

	if( linear_processing )
		vips_info( "vipsthumbnail", "linear mode" ); 

	if( !(loader = vips_foreign_find_load( filename )) )
		return( NULL );

	vips_info( "vipsthumbnail", "selected loader is %s", loader ); 

	if( strcmp( loader, "VipsForeignLoadJpegFile" ) == 0 ) {
		int jpegshrink;

		/* This will just read in the header and is quick.
		 */
		if( !(im = vips_image_new_from_file( filename, NULL )) )
			return( NULL );

		jpegshrink = thumbnail_find_jpegshrink( im );

		g_object_unref( im );

		vips_info( "vipsthumbnail", 
			"loading jpeg with factor %d pre-shrink", 
			jpegshrink ); 

		/* We can't use UNBUFERRED safely on very-many-core systems.
		 */
		if( !(im = vips_image_new_from_file( filename, 
			"access", VIPS_ACCESS_SEQUENTIAL,
			"shrink", jpegshrink,
			NULL )) )
			return( NULL );
	}
	else if( strcmp( loader, "VipsForeignLoadPdfFile" ) == 0 ||
		strcmp( loader, "VipsForeignLoadSvgFile" ) == 0 ) {
		double shrink;

		/* This will just read in the header and is quick.
		 */
		if( !(im = vips_image_new_from_file( filename, NULL )) )
			return( NULL );

		shrink = calculate_shrink( im ); 

		g_object_unref( im );

		vips_info( "vipsthumbnail", 
			"loading PDF/SVG with factor %g pre-shrink", 
			shrink ); 

		/* We can't use UNBUFERRED safely on very-many-core systems.
		 */
		if( !(im = vips_image_new_from_file( filename, 
			"access", VIPS_ACCESS_SEQUENTIAL,
			"scale", 1.0 / shrink,
			NULL )) )
			return( NULL );
	}
	else if( strcmp( loader, "VipsForeignLoadWebpFile" ) == 0 ) {
		double shrink;

		/* This will just read in the header and is quick.
		 */
		if( !(im = vips_image_new_from_file( filename, NULL )) )
			return( NULL );

		shrink = calculate_shrink( im ); 

		g_object_unref( im );

		vips_info( "vipsthumbnail", 
			"loading webp with factor %g pre-shrink", 
			shrink ); 

		/* We can't use UNBUFERRED safely on very-many-core systems.
		 */
		if( !(im = vips_image_new_from_file( filename, 
			"access", VIPS_ACCESS_SEQUENTIAL,
			"shrink", (int) shrink,
			NULL )) )
			return( NULL );
	}
	else {
		/* All other formats. We can't use UNBUFERRED safely on 
		 * very-many-core systems.
		 */
		if( !(im = vips_image_new_from_file( filename, 
			"access", VIPS_ACCESS_SEQUENTIAL,
			NULL )) )
			return( NULL );
	}

	vips_object_local( process, im );

	return( im ); 
}
示例#7
0
/* Open an image, returning the best version of that image for thumbnailing. 
 *
 * jpegs can have embedded thumbnails ... use that if it's large enough.
 *
 * libjpeg supports fast shrink-on-read, so if we have a JPEG, we can ask 
 * VIPS to load a lower resolution version.
 */
static VipsImage *
thumbnail_open( VipsObject *process, const char *filename )
{
	const char *loader;
	VipsImage *im;

	vips_info( "vipsthumbnail", "thumbnailing %s", filename );

	if( linear_processing )
		vips_info( "vipsthumbnail", "linear mode" ); 

	if( !(loader = vips_foreign_find_load( filename )) )
		return( NULL );

	vips_info( "vipsthumbnail", "selected loader is %s", loader ); 

	if( strcmp( loader, "VipsForeignLoadJpegFile" ) == 0 ) {
		VipsImage *thumb;

		/* This will just read in the header and is quick.
		 */
		if( !(im = vips_image_new_from_file( filename )) )
			return( NULL );

		/* Try to read an embedded thumbnail. If we find one, use that
		 * instead.
		 */
		if( (thumb = thumbnail_get_thumbnail( im )) ) { 
			/* @thumb has not been fully decoded yet ... 
			 * we must not close @im
			 * until we're done with @thumb.
			 */
			vips_object_local( VIPS_OBJECT( thumb ), im );

			im = thumb;
		}
		else {
			int jpegshrink;

			vips_info( "vipsthumbnail", 
				"processing main jpeg image" );

			jpegshrink = thumbnail_find_jpegshrink( im );

			g_object_unref( im );

			vips_info( "vipsthumbnail", 
				"loading jpeg with factor %d pre-shrink", 
				jpegshrink ); 

			if( vips_foreign_load( filename, &im,
				"access", VIPS_ACCESS_SEQUENTIAL,
				"shrink", jpegshrink,
				NULL ) )
				return( NULL );
		}
	}
	else {
		/* All other formats.
		 */
		if( vips_foreign_load( filename, &im,
			"access", VIPS_ACCESS_SEQUENTIAL,
			NULL ) )
			return( NULL );
	}

	vips_object_local( process, im );

	return( im ); 
}