forked from speedie/spmenu
image sizes can now be much, much larger without issue
This commit is contained in:
parent
3f7bc43bf4
commit
1ca66919f1
38
libs/img.c
38
libs/img.c
|
@ -45,29 +45,35 @@ loadimage(const char *file, int *width, int *height)
|
|||
}
|
||||
|
||||
void
|
||||
scaleimage(int width, int height)
|
||||
scaleimage(int *width, int *height)
|
||||
{
|
||||
int nwidth, nheight;
|
||||
float aspect = 1.0f;
|
||||
|
||||
if (width > height)
|
||||
aspect = (float)imagesize/width;
|
||||
if (imagewidth > *width)
|
||||
aspect = (float)(*width)/imagewidth;
|
||||
else
|
||||
aspect = (float)imagesize/height;
|
||||
aspect = (float)imagewidth/(*width);
|
||||
|
||||
nwidth = width * aspect;
|
||||
nheight = height * aspect;
|
||||
nwidth = *width * aspect;
|
||||
nheight = *height * aspect;
|
||||
|
||||
if(nwidth == width && nheight == height)
|
||||
if(nwidth == *width && nheight == *height)
|
||||
return;
|
||||
|
||||
image = imlib_create_cropped_scaled_image(0,0,width,height,nwidth,nheight);
|
||||
image = imlib_create_cropped_scaled_image(0,0,*width,*height,nwidth,nheight);
|
||||
|
||||
imlib_free_image();
|
||||
|
||||
if (!image)
|
||||
if(!image)
|
||||
return;
|
||||
|
||||
imlib_context_set_image(image);
|
||||
|
||||
*width = nwidth;
|
||||
*height = nheight;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -80,8 +86,10 @@ loadimagecache(const char *file, int *width, int *height)
|
|||
struct passwd *pw = NULL;
|
||||
|
||||
/* just load and don't store or try cache */
|
||||
if(imagesize > 256) {
|
||||
if (longestedge > 256) {
|
||||
loadimage(file, width, height);
|
||||
if (image)
|
||||
scaleimage(width, height);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -97,7 +105,7 @@ loadimagecache(const char *file, int *width, int *height)
|
|||
|
||||
/* which cache do we try? */
|
||||
dsize = "normal";
|
||||
if (imagesize > 128)
|
||||
if (longestedge > 128)
|
||||
dsize = "large";
|
||||
|
||||
slen = snprintf(NULL, 0, "file://%s", file)+1;
|
||||
|
@ -134,11 +142,11 @@ loadimagecache(const char *file, int *width, int *height)
|
|||
|
||||
loadimage(buf, width, height);
|
||||
|
||||
if (image && *width < imagesize && *height < imagesize) {
|
||||
if (image && *width < imagewidth && *height < imageheight) {
|
||||
imlib_free_image();
|
||||
image = NULL;
|
||||
} else if(image && (*width > imagesize || *height > imagesize)) {
|
||||
scaleimage(*width, *height);
|
||||
} else if(image && (*width > imagewidth || *height > imageheight)) {
|
||||
scaleimage(width, height);
|
||||
}
|
||||
|
||||
/* we are done */
|
||||
|
@ -154,7 +162,7 @@ loadimagecache(const char *file, int *width, int *height)
|
|||
return;
|
||||
}
|
||||
|
||||
scaleimage(*width, *height);
|
||||
scaleimage(width, height);
|
||||
imlib_image_set_format("png");
|
||||
createifnexist_rec(buf);
|
||||
imlib_save_image(buf);
|
||||
|
|
|
@ -16,7 +16,8 @@ static int minwidth = 500; /* Minimum width */
|
|||
static int centered = 0; /* Whether or not to center spmenu by default */
|
||||
|
||||
/* Image options */
|
||||
static int imagesize = 86; /* Default image size */
|
||||
static int imagewidth = 86; /* Default image width */
|
||||
static int imageheight = 86; /* Default image height */
|
||||
static int imagegaps = 0; /* Image gaps */
|
||||
static int imageposition = 0; /* Image position (0: Top, 1: Bottom, 2: Center, 3: Top center) */
|
||||
static int generatecache = 0; /* Generate image cache by default */
|
||||
|
|
42
spmenu.c
42
spmenu.c
|
@ -168,7 +168,6 @@ static void drawmenu(void);
|
|||
#include "colors.h" /* Include colors */
|
||||
#include "xresources.h" /* Include .Xresources */
|
||||
|
||||
|
||||
static char * cistrstr(const char *s, const char *sub);
|
||||
static int (*fstrncmp)(const char *, const char *, size_t) = strncasecmp;
|
||||
static char *(*fstrstr)(const char *, const char *) = cistrstr;
|
||||
|
@ -177,6 +176,8 @@ static char *(*fstrstr)(const char *, const char *) = cistrstr;
|
|||
#include "libs/mode.c"
|
||||
|
||||
#if USEIMAGE
|
||||
static int longestedge = 0; /* longest edge */
|
||||
|
||||
#include "libs/img.h"
|
||||
#include "libs/img.c"
|
||||
#endif
|
||||
|
@ -472,8 +473,8 @@ drawmenu(void)
|
|||
|
||||
if (lines > 0) {
|
||||
#if USEIMAGE
|
||||
if (imagesize)
|
||||
x += imagegaps + imagesize;
|
||||
if (imagewidth)
|
||||
x += imagegaps + imagewidth;
|
||||
#endif
|
||||
/* draw grid */
|
||||
int i = 0;
|
||||
|
@ -1423,7 +1424,7 @@ readstdin(void)
|
|||
items[i].image = NULL;
|
||||
}
|
||||
|
||||
if (generatecache && imagesize <= 256 && items[i].image && strcmp(items[i].image, limg?limg:"")) {
|
||||
if (generatecache && longestedge <= 256 && items[i].image && strcmp(items[i].image, limg?limg:"")) {
|
||||
loadimagecache(items[i].image, &w, &h);
|
||||
fprintf(stdout, "-!- Generating thumbnail for: %s\n", items[i].image);
|
||||
}
|
||||
|
@ -1441,13 +1442,13 @@ readstdin(void)
|
|||
}
|
||||
#if USEIMAGE
|
||||
if (!limg)
|
||||
imagesize = 0;
|
||||
longestedge = imagegaps = 0;
|
||||
#endif
|
||||
inputw = items ? TEXTWM(items[imax].text) : 0;
|
||||
lines = MIN(lines, i);
|
||||
#if USEIMAGE
|
||||
if(lines * drw->font->h < imagesize)
|
||||
lines = imagesize/drw->font->h+2;
|
||||
if(lines * drw->font->h < imagewidth)
|
||||
lines = imagewidth/drw->font->h+2;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1499,23 +1500,27 @@ run(void)
|
|||
continue;
|
||||
|
||||
if (sel && sel->image && strcmp(sel->image, limg ? limg : "")) {
|
||||
if (imagesize)
|
||||
if (longestedge)
|
||||
loadimagecache(sel->image, &width, &height);
|
||||
} else if ((!sel || !sel->image) && image) {
|
||||
imlib_free_image();
|
||||
image = NULL;
|
||||
} if (image && imagesize) {
|
||||
} if (image && longestedge) {
|
||||
int leftmargin = imagegaps;
|
||||
|
||||
if (!imageposition) { /* top mode = 0 */
|
||||
imlib_render_image_on_drawable(leftmargin+(imagesize-width)/2, bh+imagegaps);
|
||||
if (height > width)
|
||||
width = height;
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, bh+imagegaps);
|
||||
} else if (imageposition == 1) { /* bottom mode = 1 */
|
||||
imlib_render_image_on_drawable(leftmargin+(imagesize-width)/2, mh-height-imagegaps);
|
||||
if (height > width)
|
||||
width = height;
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, mh-height-imagegaps);
|
||||
} else if (imageposition == 2) { /* center mode = 2 */
|
||||
imlib_render_image_on_drawable(leftmargin+(imagesize-width)/2, (mh-bh-height)/2+bh);
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (mh-bh-height)/2+bh);
|
||||
} else {
|
||||
int minh = MIN(imagesize, mh-bh-imagegaps*2);
|
||||
imlib_render_image_on_drawable(leftmargin+(imagesize-width)/2, (minh-height)/2+bh+imagegaps);
|
||||
int minh = MIN(height, mh-bh-imagegaps*2);
|
||||
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (minh-height)/2+bh+imagegaps);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2015,7 +2020,12 @@ main(int argc, char *argv[])
|
|||
colors[SchemeInput][ColBg] = argv[++i];
|
||||
colors[SchemePrompt][ColFg] = argv[++i];
|
||||
} else if (!strcmp(argv[i], "-is")) { /* image size */
|
||||
imagesize = atoi(argv[++i]);
|
||||
char buf[255];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
memcpy(buf, argv[++i], sizeof(buf)-1);
|
||||
|
||||
if(sscanf(buf, "%dx%d", &imagewidth, &imageheight) == 1)
|
||||
imageheight = imagewidth;
|
||||
|
||||
/* spmenu colors */
|
||||
} else if (!strcmp(argv[i], "-nif")) { /* normal item foreground color */
|
||||
|
@ -2092,6 +2102,8 @@ main(int argc, char *argv[])
|
|||
else
|
||||
usage();
|
||||
|
||||
longestedge = MAX(imagewidth, imageheight);
|
||||
|
||||
if (mode) {
|
||||
selkeys = 1;
|
||||
allowkeys = 1;
|
||||
|
|
|
@ -115,7 +115,8 @@ ResourcePref resources[] = {
|
|||
{ "hidemode", INTEGER, &hidemode },
|
||||
{ "histnodup", INTEGER, &histnodup },
|
||||
{ "casesensitive", INTEGER, &casesensitive },
|
||||
{ "imagesize", INTEGER, &imagesize },
|
||||
{ "imagewidth", INTEGER, &imagewidth },
|
||||
{ "imageheight", INTEGER, &imageheight },
|
||||
{ "imagegaps", INTEGER, &imagegaps },
|
||||
{ "imageposition", INTEGER, &imageposition },
|
||||
{ "generatecache", INTEGER, &generatecache },
|
||||
|
|
Loading…
Reference in a new issue