Пример #1
0
void ASVolume_parseGnomeIconString (ASVolume *v)
{
	if (v) { 
		static char signature[] = ". GThemedIcon ";
		destroy_string (&(v->idString));

		if (v->icon) {
			ASImage *tmp = GIcon2ASImage (v->icon);
			gchar* str = g_icon_to_string (v->icon);

			show_activity ("volume added with icon \"%s\".", str);

			if (str) {
				if (strncmp (str, signature, sizeof(signature)-1) == 0)
					parse_token (&str [sizeof(signature)-1], &(v->idString));
				safefree (str);
			}

			if (tmp) {
				int l, t, r, b;
				get_asimage_closure (tmp, &l, &t, &r, &b, 10);
				v->iconIm = tile_asimage (Scr.asv, tmp, l, t, r+1-l, b+1-t, 0x4F7F7F7F, ASA_ASImage, 100, ASIMAGE_QUALITY_DEFAULT);
				safe_asimage_destroy (tmp);
			}					
		
			LOCAL_DEBUG_OUT ("Icon asim = %p", v->iconIm);
		}
		if (!v->idString)
			v->idString = mystrdup ("unknown");
	}
}
Пример #2
0
int main(int argc, char* argv[])
{
	char *image_file = "rose512.jpg" ;
	ASImage *im ;
	ASVisual *asv ;
	int screen = 0, depth = 24;
	Display *dpy = NULL;

	/* see ASView.1 : */
	set_application_name( argv[0] );
#if (HAVE_AFTERBASE_FLAG==1)
	set_output_threshold(OUTPUT_LEVEL_DEBUG);
#ifdef DEBUG_ALLOCS
	fprintf( stderr, "have DEBUG_ALLOCS\n");
#endif
#ifdef AFTERBASE_DEBUG_ALLOCS
	fprintf( stderr, "have AFTERBASE_DEBUG_ALLOCS\n");
#endif
#endif

	if( argc > 1 )
	{
		if( strcmp( argv[1], "-h" ) == 0 )
		{
			usage();
			return 0;
		}
		image_file = argv[1] ;
	}else
	{
		show_warning( 	"Image filename was not specified. "
						"Using default: \"%s\"", image_file );
		usage();
	}
#ifndef X_DISPLAY_MISSING
	dpy = XOpenDisplay(NULL);
	XSynchronize (dpy, True);
	_XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW", 
										False);
	screen = DefaultScreen(dpy);
	depth = DefaultDepth( dpy, screen );
#endif	
	/* see ASView.3 : */
	asv = create_asvisual( dpy, screen, depth, NULL );
	/* asv = create_asvisual_for_id( dpy, screen, depth, 0x28, None, NULL ); */

	/* see ASView.2 : */
	im = file2ASImage( image_file, 0xFFFFFFFF, SCREEN_GAMMA, 0, getenv("IMAGE_PATH"), NULL );

	/* The following could be used to dump JPEG version of the image into
	 * stdout : */
	/* 	ASImage2file( im, NULL, NULL, ASIT_Jpeg, NULL ); 
		ASImage2file( im, NULL, "asview.png", ASIT_Png, NULL );
		ASImage2file( im, NULL, "asview.gif", ASIT_Gif, NULL );
	*/

	if( im != NULL )
	{
#ifndef X_DISPLAY_MISSING
		Window w ;
#if 0
		/* test example for get_asimage_channel_rects() : */
		XRectangle *rects ;	unsigned int rects_count =0; int i ;
		rects = get_asimage_channel_rects( im, IC_ALPHA, 10, 
											&rects_count );
		fprintf( stderr, " %d rectangles generated : \n", rects_count );
		for( i = 0 ; i < rects_count ; ++i )
			fprintf( stderr, "\trect[%d]=%dx%d%+d%+d;\n", 
					 i, rects[i].width, rects[i].height, 
					 rects[i].x, rects[i].y );
#endif


#if 0		 
		/* test example for fill_asimage : */
		fill_asimage(asv, im, 0, 0, 50, 50, 0xFFFF0000);
		fill_asimage(asv, im, 50, 50, 100, 50, 0xFFFF0000);
		fill_asimage(asv, im, 0, 100, 200, 50, 0xFFFF0000);
		fill_asimage(asv, im, 150, 0, 50, 50, 0xFFFF0000);
#endif
#if 0
		/* test example for conversion to argb32 :*/
		{
			ASImage *tmp = tile_asimage( asv, im, 0, 0, im->width, im->height, TINT_NONE, ASA_ARGB32, 
										  0, ASIMAGE_QUALITY_DEFAULT );	 
			destroy_asimage( &im );
			set_flags( tmp->flags, ASIM_DATA_NOT_USEFUL|ASIM_XIMAGE_NOT_USEFUL );
			im = tmp ;
		}		   
#endif		   
		/* see ASView.4 : */
		w = create_top_level_window( asv, DefaultRootWindow(dpy), 32, 32,
			                         im->width, im->height, 1, 0, NULL,
									 "ASView", image_file );
		if( w != None )
		{
			Pixmap p ;
	  		
			XMapRaised   (dpy, w);
			XSync(dpy,False);
			/* see ASView.5 : */
	  		p = create_visual_pixmap( asv, DefaultRootWindow(dpy), im->width, im->height, 0 );
	
			{
				START_TIME(started);
				/* for( int i = 0 ; i < 100 ; ++i )  To test performance! */
				asimage2drawable( asv, p, im, NULL, 0, 0, 0, 0, im->width, im->height, False);
				SHOW_TIME("", started);
			}
			/* print_storage(NULL); */
			destroy_asimage( &im );
			/* see common.c:set_window_background_and_free(): */
			p = set_window_background_and_free( w, p );
		}
		/* see common.c: wait_closedown() : */
		wait_closedown(w);
		dpy = NULL;
		
		/* no longer need this - lets clean it up :*/
		destroy_asvisual( asv, False );
		asv = NULL ;

#else
		/* writing result into the file */
		ASImage2file( im, NULL, "asview.png", ASIT_Png, NULL );
#endif
	}

#ifdef DEBUG_ALLOCS
    /* different cleanups of static memory pools : */
    flush_ashash_memory_pool();
	asxml_var_cleanup();
	custom_color_cleanup();
    build_xpm_colormap( NULL );
	flush_default_asstorage();
	/* requires libAfterBase */
	print_unfreed_mem();
#endif

    return 0 ;
}
Пример #3
0
static void display_image_view (ASGtkImageView * iv)
{
	ASImage *im = iv->image_entry ? iv->image_entry->preview : NULL;
	GdkPixbuf *pb = NULL;
	ASImage *scaled = NULL, *tiled = NULL;
	int scaled_w, scaled_h;
	int tiled_h, tiled_w;
	ASVisual *asv = get_screen_visual (NULL);
	int view_w, view_h;

	if (im == NULL) {
		gtk_image_set_from_stock (GTK_IMAGE (iv->view),
															GTK_STOCK_MISSING_IMAGE,
															GTK_ICON_SIZE_BUTTON);
		return;
	}
#if 1
	view_w = iv->view_width;
	view_h = iv->view_height;
	if (view_w <= 0 || view_h <= 0)
		return;

	scaled_w = im->width;
	scaled_h = im->height;

	if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_SCALE_TO_VIEW)) {
		if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_TILE_TO_ASPECT)
				&& iv->aspect_x > 0 && iv->aspect_y > 0) {
			scaled_w = (im->width * view_w) / iv->aspect_x;
			scaled_h = (im->height * view_h) / iv->aspect_y;
		} else {
			scaled_w = view_w;
			scaled_h = view_h;
		}
	} else if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_SCALE_TO_ASPECT)
						 && iv->aspect_x > 0 && iv->aspect_y > 0) {
		scaled_w = iv->aspect_x;
		scaled_h = iv->aspect_y;
	}

	tiled_w = scaled_w;
	tiled_h = scaled_h;

	if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_TILE_TO_ASPECT)
			&& iv->aspect_x > 0 && iv->aspect_y > 0) {
		if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_SCALE_TO_VIEW)) {
			if (tiled_w < view_w)
				tiled_w = view_w;
			if (tiled_h < view_h)
				tiled_h = view_h;
		} else {
			if (tiled_w < iv->aspect_x)
				tiled_w = iv->aspect_x;
			if (tiled_h < iv->aspect_y)
				tiled_h = iv->aspect_y;
		}
	}
	if (get_flags (iv->flags, ASGTK_IMAGE_VIEW_TILE_TO_VIEW)) {
		if (tiled_w < view_w)
			tiled_w = view_w;
		if (tiled_h < view_h)
			tiled_h = view_h;
	}


	LOCAL_DEBUG_OUT ("scaled size is %dx%d, tiled size %dx%d", scaled_w,
									 scaled_h, tiled_w, tiled_h);
	if (scaled_w != im->width || scaled_h != im->height) {
		scaled =
				scale_asimage (asv, im, scaled_w, scaled_h, ASA_ASImage, 0,
											 ASIMAGE_QUALITY_DEFAULT);
		if (scaled)
			im = scaled;
	}

	if (tiled_w != im->width || tiled_h != im->height) {
		tiled = tile_asimage (asv, im, 0, 0, tiled_w, tiled_h,
													TINT_LEAVE_SAME, ASA_ASImage, 0,
													ASIMAGE_QUALITY_DEFAULT);
		if (tiled)
			im = tiled;
	}

	pb = ASImage2GdkPixbuf (im);
	if (tiled)
		destroy_asimage (&tiled);
	if (scaled)
		destroy_asimage (&scaled);
	if (pb) {
		gtk_image_set_from_pixbuf (GTK_IMAGE (iv->view), pb);
		g_object_unref (pb);
	}
	LOCAL_DEBUG_OUT ("####!!! recquisition is %dx%d",
									 GTK_WIDGET (iv->view)->requisition.width,
									 GTK_WIDGET (iv->view)->requisition.height);
#endif
}