Permalink
Browse files

First things for thumbnail mode

  • Loading branch information...
1 parent e8ed491 commit 7b497406136dabcce280bae3886a88ee77ebc1e7 @muennich committed Feb 16, 2011
Showing with 55 additions and 2 deletions.
  1. +2 −0 config.h
  2. +21 −0 image.c
  3. +7 −0 image.h
  4. +8 −0 main.c
  5. +6 −2 options.c
  6. +1 −0 options.h
  7. +8 −0 window.c
  8. +2 −0 window.h
View
@@ -19,3 +19,5 @@ static const float zoom_levels[] = {
12.5, 25.0, 50.0, 75.0,
100.0, 150.0, 200.0, 400.0, 800.0
};
+
+#define THUMB_SIZE 50
View
@@ -149,6 +149,27 @@ int img_fit(img_t *img, win_t *win) {
return oz != img->zoom;
}
+int img_load_thumb(thumb_t *tn, const char *filename) {
+ int w;
+ int h;
+
+ if (!tn)
+ return 0;
+
+ if (!_imlib_load_image(filename))
+ return 0;
+
+ w = imlib_image_get_width();
+ h = imlib_image_get_height();
+
+ imlib_context_set_drawable(tn->pm);
+ imlib_render_image_part_on_drawable_at_size(0, 0, w, h,
+ 0, 0, THUMB_SIZE, THUMB_SIZE);
+ imlib_free_image();
+
+ return 1;
+}
+
void img_render(img_t *img, win_t *win) {
int sx, sy, sw, sh;
int dx, dy, dw, dh;
View
@@ -49,11 +49,18 @@ typedef struct img_s {
int h;
} img_t;
+typedef struct thumb_s {
+ int x;
+ int y;
+ Pixmap pm;
+} thumb_t;
+
void img_init(img_t*, win_t*);
void img_free(img_t*);
int img_check(const char*);
int img_load(img_t*, const char*);
+int img_load_thumb(thumb_t*, const char*);
void img_render(img_t*, win_t*);
View
@@ -46,6 +46,8 @@ const char **filenames;
int filecnt, fileidx;
size_t filesize;
+thumb_t *thumbs;
+
#define TITLE_LEN 256
char win_title[TITLE_LEN];
@@ -119,6 +121,12 @@ int main(int argc, char **argv) {
win_open(&win);
img_init(&img, &win);
+ if (options->thumbnails) {
+ thumbs = (thumb_t*) s_malloc(filecnt * sizeof(thumb_t));
+ for (i = 0; i < filecnt; ++i)
+ img_load_thumb(&thumbs[i], filenames[i]);
+ }
+
load_image();
img_render(&img, &win);
update_title();
View
@@ -30,7 +30,7 @@ options_t _options;
const options_t *options = (const options_t*) &_options;
void print_usage() {
- printf("usage: sxiv [-dFfhpqrsvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
+ printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n");
}
void print_version() {
@@ -45,6 +45,7 @@ void parse_options(int argc, char **argv) {
_options.scalemode = SCALE_MODE;
_options.zoom = 1.0;
_options.aa = 1;
+ _options.thumbnails = 0;
_options.fixed = 0;
_options.fullscreen = 0;
@@ -53,7 +54,7 @@ void parse_options(int argc, char **argv) {
_options.quiet = 0;
_options.recursive = 0;
- while ((opt = getopt(argc, argv, "dFfg:hpqrsvZz:")) != -1) {
+ while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) {
switch (opt) {
case '?':
print_usage();
@@ -85,6 +86,9 @@ void parse_options(int argc, char **argv) {
case 's':
_options.scalemode = SCALE_FIT;
break;
+ case 't':
+ _options.thumbnails = 1;
+ break;
case 'v':
print_version();
exit(0);
View
@@ -29,6 +29,7 @@ typedef struct options_s {
scalemode_t scalemode;
float zoom;
unsigned char aa;
+ unsigned char thumbnails;
unsigned char fixed;
unsigned char fullscreen;
View
@@ -211,6 +211,14 @@ void win_toggle_fullscreen(win_t *win) {
SubstructureNotifyMask, &ev);
}
+Pixmap win_create_pixmap(win_t *win) {
+ if (!win)
+ return 0;
+
+ return XCreatePixmap(win->env.dpy, win->xwin, THUMB_SIZE, THUMB_SIZE,
+ win->env.depth);
+}
+
void win_clear(win_t *win) {
win_env_t *e;
XGCValues gcval;
View
@@ -63,6 +63,8 @@ int win_moveresize(win_t*, int, int, unsigned int, unsigned int);
void win_toggle_fullscreen(win_t*);
+Pixmap win_create_pixmap(win_t*);
+
void win_clear(win_t*);
void win_draw(win_t*);

0 comments on commit 7b49740

Please sign in to comment.