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