void feh_edit_inplace(winwidget w, int op) { int tmp; Imlib_Image old = NULL; Imlib_Load_Error err = IMLIB_LOAD_ERROR_NONE; if (!w->file || !w->file->data || !FEH_FILE(w->file->data)->filename) return; if (!strcmp(gib_imlib_image_format(w->im), "jpeg") && !path_is_url(FEH_FILE(w->file->data)->filename)) { feh_edit_inplace_lossless(w, op); feh_reload_image(w, 1, 1); return; } old = imlib_load_image_with_error_return(FEH_FILE(w->file->data)->filename, &err); if ((old != NULL) && (err == IMLIB_LOAD_ERROR_NONE)) { imlib_context_set_image(old); if (op == INPLACE_EDIT_FLIP) imlib_image_flip_vertical(); else if (op == INPLACE_EDIT_MIRROR) imlib_image_flip_horizontal(); else imlib_image_orientate(op); gib_imlib_save_image_with_error_return(old, FEH_FILE(w->file->data)->filename, &err); gib_imlib_free_image(old); if (err) feh_imlib_print_load_error(FEH_FILE(w->file->data)->filename, w, err); feh_reload_image(w, 1, 1); } else { /* * Image was opened using curl/magick or has been deleted after * opening it */ imlib_context_set_image(w->im); if (op == INPLACE_EDIT_FLIP) imlib_image_flip_vertical(); else if (op == INPLACE_EDIT_MIRROR) imlib_image_flip_horizontal(); else { imlib_image_orientate(op); tmp = w->im_w; FEH_FILE(w->file->data)->info->width = w->im_w = w->im_h; FEH_FILE(w->file->data)->info->height = w->im_h = tmp; } im_weprintf(w, "unable to edit in place. Changes have not been saved."); winwidget_render_image(w, 1, 0); } return; }
static inline ImageObject * _imlib2_open(char *filename, int use_cache) { Imlib_Image *image; Imlib_Load_Error error = IMLIB_LOAD_ERROR_NONE; if (use_cache){ image = imlib_load_image_with_error_return(filename, &error); }else{ image = imlib_load_image_immediately_without_cache(filename); } CHECK_LOAD_ERROR(error); #ifdef DEVELOP imlib_context_set_image(image); DEBUG("width %d", imlib_image_get_width()); DEBUG("height %d", imlib_image_get_height()); #endif return ImageObject_New(image); }
static Imlib_Image regenerate_from_original(const char *filename, int size) { /* load image */ Imlib_Load_Error err; Imlib_Image orig = imlib_load_image_with_error_return(filename, &err); if (orig == NULL) { const char *errmsg = imlib_load_error_string(err); warnx("couldn't load %s for thumbnailing: %s", filename, errmsg); return NULL; /* XXX do what with error message? extra param? */ } imlib_context_set_image(orig); struct coord image_dim = COORD( imlib_image_get_width(), imlib_image_get_height() ); /* make thumbnail, but without upscaling smaller images. */ struct coord thumb_dim = coord_downscale_to_fit(image_dim, COORD(size, size)); Imlib_Image thumb = imlib_create_cropped_scaled_image(0, 0, image_dim.width, image_dim.height, thumb_dim.width, thumb_dim.height ); /* can free original image now */ imlib_context_set_image(orig); imlib_free_image(); /* done */ if (thumb == NULL) { warnx("error while downscaling %s for thumbnailing", filename); return NULL; } return thumb; }
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; }
unsigned int slop::GLSelectRectangle::loadImage( unsigned int* texture, std::string path ) { glActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glGenTextures( 1, texture ); glBindTexture( GL_TEXTURE_2D, *texture ); Imlib_Load_Error err; Imlib_Image image = imlib_load_image_with_error_return( path.c_str(), &err ); if ( err != IMLIB_LOAD_ERROR_NONE ) { std::string message = "Failed to load image: "; message += path; message += "\n\t"; switch( err ) { default: { message += "unknown error "; message += (int)err; message += "\n"; break; } case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS: message += "out of file descriptors\n"; break; case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: message += "out of memory\n"; break; case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: message += "path contains too many symbolic links\n"; break; case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: message += "path points outside address space\n"; break; case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: message += "path component is not a directory\n"; break; case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: message += "path component is non-existant (~ isn't expanded inside quotes!)\n"; break; case IMLIB_LOAD_ERROR_PATH_TOO_LONG: message += "path is too long\n"; break; case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: message += "no loader for file format (unsupported format)\n"; break; case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: { message += "not enough disk space\n"; break; } case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: { message += "file does not exist\n"; break; } case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: { message += "file is a directory\n"; break; } case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: { message += "permission denied\n"; break; } } throw std::runtime_error( message.c_str() ); return *texture; } imlib_context_set_image( image ); DATA32* data = imlib_image_get_data_for_reading_only(); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, imlib_image_get_width(), imlib_image_get_height(), 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)data ); if ( GLEW_VERSION_3_0 ) { glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST ); glGenerateMipmap( GL_TEXTURE_2D ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR ); } else { glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); } glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); imlib_free_image(); glDisable(GL_TEXTURE_2D); return *texture; }
int feh_load_image(Imlib_Image * im, feh_file * file) { Imlib_Load_Error err; enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK } image_source = SRC_IMLIB; char *tmpname = NULL; char *real_filename = NULL; D(("filename is %s, image is %p\n", file->filename, im)); if (!file || !file->filename) return 0; /* Handle URLs */ if ((!strncmp(file->filename, "http://", 7)) || (!strncmp(file->filename, "https://", 8)) || (!strncmp(file->filename, "ftp://", 6))) { image_source = SRC_HTTP; if ((tmpname = feh_http_load_image(file->filename)) == NULL) err = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST; } else *im = imlib_load_image_with_error_return(file->filename, &err); if ((err == IMLIB_LOAD_ERROR_UNKNOWN) || (err == IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT)) { image_source = SRC_MAGICK; tmpname = feh_magick_load_image(file->filename); } if ((image_source != SRC_IMLIB) && tmpname) { *im = imlib_load_image_with_error_return(tmpname, &err); if (im) { real_filename = file->filename; file->filename = tmpname; feh_file_info_load(file, *im); file->filename = real_filename; #ifdef HAVE_LIBEXIF file->ed = exif_get_data(tmpname); #endif } if ((image_source == SRC_MAGICK) || !opt.keep_http) unlink(tmpname); free(tmpname); } if ((err) || (!im)) { if (opt.verbose && !opt.quiet) { fputs("\n", stdout); reset_output = 1; } feh_imlib_print_load_error(file->filename, NULL, err); D(("Load *failed*\n")); return(0); } #ifdef HAVE_LIBEXIF file->ed = exif_get_data(file->filename); #endif D(("Loaded ok\n")); return(1); }
int feh_load_image(Imlib_Image * im, feh_file * file) { Imlib_Load_Error err = IMLIB_LOAD_ERROR_NONE; enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK } image_source = SRC_IMLIB; char *tmpname = NULL; char *real_filename = NULL; #ifdef HAVE_LIBEXIF ExifEntry *entry; #endif D(("filename is %s, image is %p\n", file->filename, im)); if (!file || !file->filename) return 0; if (path_is_url(file->filename)) { image_source = SRC_HTTP; if ((tmpname = feh_http_load_image(file->filename)) == NULL) err = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST; } else *im = imlib_load_image_with_error_return(file->filename, &err); if ((err == IMLIB_LOAD_ERROR_UNKNOWN) || (err == IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT)) { image_source = SRC_MAGICK; tmpname = feh_magick_load_image(file->filename); } if ((image_source != SRC_IMLIB) && tmpname) { *im = imlib_load_image_with_error_return(tmpname, &err); if (im) { real_filename = file->filename; file->filename = tmpname; feh_file_info_load(file, *im); file->filename = real_filename; #ifdef HAVE_LIBEXIF file->ed = exif_get_data(tmpname); #endif } if ((image_source == SRC_MAGICK) || !opt.keep_http) unlink(tmpname); free(tmpname); } if ((err) || (!im)) { if (opt.verbose && !opt.quiet) { fputs("\n", stdout); reset_output = 1; } feh_imlib_print_load_error(file->filename, NULL, err); D(("Load *failed*\n")); return(0); } #ifdef HAVE_LIBEXIF file->ed = exif_get_data(file->filename); if (file->ed) { entry = exif_content_get_entry(file->ed->ifd[EXIF_IFD_0], 0x0112); if (entry != NULL) { if (*(entry->data) == 3) gib_imlib_image_orientate(*im, 2); else if (*(entry->data) == 6) gib_imlib_image_orientate(*im, 1); else if (*(entry->data) == 8) gib_imlib_image_orientate(*im, 3); } } #endif D(("Loaded ok\n")); return(1); }
int gib_imlib_load_image(Imlib_Image * im, char *filename) { Imlib_Load_Error err; imlib_context_set_progress_function(NULL); if (!filename) return (0); *im = imlib_load_image_with_error_return(filename, &err); if ((err) || (!im)) { /* Check error code */ switch (err) { case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: gib_weprintf("%s - File does not exist", filename); break; case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: gib_weprintf("%s - Directory specified for image filename", filename); break; case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: gib_weprintf("%s - No read access to directory", filename); break; case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: gib_weprintf("%s - No Imlib2 loader for that file format", filename); break; case IMLIB_LOAD_ERROR_PATH_TOO_LONG: gib_weprintf("%s - Path specified is too long", filename); break; case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: gib_weprintf("%s - Path component does not exist", filename); break; case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: gib_weprintf("%s - Path component is not a directory", filename); break; case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: gib_weprintf("%s - Path points outside address space", filename); break; case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: gib_weprintf("%s - Too many levels of symbolic links", filename); break; case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: gib_eprintf("While loading %s - Out of memory", filename); break; case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS: gib_eprintf("While loading %s - Out of file descriptors", filename); break; case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: gib_weprintf("%s - Cannot write to directory", filename); break; case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: gib_weprintf("%s - Cannot write - out of disk space", filename); break; case IMLIB_LOAD_ERROR_UNKNOWN: default: gib_weprintf ("While loading %s - Unknown error. Attempting to continue", filename); break; } return (0); } return (1); }