Exemple #1
0
bool img_load(img_t *img, const fileinfo_t *file) {
	const char *fmt;

	if (img == NULL || file == NULL || file->name == NULL || file->path == NULL)
		return false;

	if (access(file->path, R_OK) < 0 ||
	    (img->im = imlib_load_image(file->path)) == NULL)
	{
		warn("could not open image: %s", file->name);
		return false;
	}

	imlib_context_set_image(img->im);
	imlib_image_set_changes_on_disk();
	imlib_context_set_anti_alias(img->aa);

	fmt = imlib_image_format();
	/* avoid unused-but-set-variable warning */
	(void) fmt;

#if EXIF_SUPPORT
	if (streq(fmt, "jpeg"))
		exif_auto_orientate(file);
#endif
#if GIF_SUPPORT
	if (streq(fmt, "gif"))
		img_load_gif(img, file);
#endif

	img->w = imlib_image_get_width();
	img->h = imlib_image_get_height();
	img->scalemode = options->scalemode;
	img->re = false;
	img->checkpan = false;
	img->dirty = true;

	return true;
}
static int img_load( img_t *img, const char *path )
{
    ImlibLoadError err = IMLIB_LOAD_ERROR_NONE;
    Imlib_Image imimg = imlib_load_image_with_error_return( path, &err );
    
    if( img )
    {
        imlib_context_set_image( imimg );
        img->size.w =  imlib_image_get_width();
        img->size.h = imlib_image_get_height();
        // allocate buffer
        img->bytes = sizeof( DATA32 ) * (size_t)img->size.w * (size_t)img->size.h;
        img->blob = malloc( img->bytes );
        if( img->blob )
        {
            char *format = imlib_image_format();
            
            if( img_format_copy( img, format, strlen( format ) ) == 0 ){
                memcpy( img->blob, imlib_image_get_data_for_reading_only(), 
                        img->bytes );
                imlib_free_image_and_decache();
                
                img->quality = 100;
                img->resize = (img_size_t){ 0, 0 };
                return 0;
            }
            // failed to copy
            free( img->blob );
        }
        
        imlib_free_image_and_decache();
    }
    else {
        liberr2errno( err );
    }
    
    return -1;
}
Exemple #3
0
char *
gib_imlib_image_format(Imlib_Image im)
{
   imlib_context_set_image(im);
   return imlib_image_format();
}