Render thumbnails
This commit is contained in:
		
							parent
							
								
									89ec18385b
								
							
						
					
					
						commit
						8919204a2e
					
				
							
								
								
									
										47
									
								
								image.c
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								image.c
									
									
									
									
									
								
							| @ -110,6 +110,32 @@ int img_load(img_t *img, const char *filename) { | ||||
| 	return 1; | ||||
| } | ||||
| 
 | ||||
| int img_load_thumb(thumb_t *tn, const char *filename) { | ||||
| 	int w, h; | ||||
| 	float z, zw, zh; | ||||
| 
 | ||||
| 	if (!tn) | ||||
| 		return 0; | ||||
| 	 | ||||
| 	if (!_imlib_load_image(filename)) | ||||
| 		return 0; | ||||
| 
 | ||||
| 	w = imlib_image_get_width(); | ||||
| 	h = imlib_image_get_height(); | ||||
| 	zw = (float) THUMB_SIZE / (float) w; | ||||
| 	zh = (float) THUMB_SIZE / (float) h; | ||||
| 	z = MIN(zw, zh); | ||||
| 	tn->w = z * w; | ||||
| 	tn->h = z * h; | ||||
| 
 | ||||
| 	imlib_context_set_drawable(tn->pm); | ||||
| 	imlib_render_image_part_on_drawable_at_size(0, 0, w, h, | ||||
| 	                                            0, 0, tn->w, tn->h); | ||||
| 	imlib_free_image(); | ||||
| 
 | ||||
| 	return 1; | ||||
| } | ||||
| 
 | ||||
| void img_check_pan(img_t *img, win_t *win) { | ||||
| 	if (!img || !win) | ||||
| 		return; | ||||
| @ -149,27 +175,6 @@ 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; | ||||
|  | ||||
							
								
								
									
										2
									
								
								image.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								image.h
									
									
									
									
									
								
							| @ -52,6 +52,8 @@ typedef struct img_s { | ||||
| typedef struct thumb_s { | ||||
| 	int x; | ||||
| 	int y; | ||||
| 	int w; | ||||
| 	int h; | ||||
| 	Pixmap pm; | ||||
| } thumb_t; | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										33
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								main.c
									
									
									
									
									
								
							| @ -27,6 +27,7 @@ | ||||
| #include <X11/Xutil.h> | ||||
| #include <X11/keysym.h> | ||||
| 
 | ||||
| #include "config.h" | ||||
| #include "image.h" | ||||
| #include "options.h" | ||||
| #include "util.h" | ||||
| @ -38,6 +39,7 @@ typedef enum appmode_e { | ||||
| } appmode_t; | ||||
| 
 | ||||
| void update_title(); | ||||
| void render_thumbs(); | ||||
| int check_append(const char*); | ||||
| void read_dir_rec(const char*); | ||||
| void run(); | ||||
| @ -53,6 +55,7 @@ int filecnt, fileidx; | ||||
| size_t filesize; | ||||
| 
 | ||||
| thumb_t *thumbs; | ||||
| int tvis, tcols, trows; | ||||
| 
 | ||||
| #define TITLE_LEN 256 | ||||
| char win_title[TITLE_LEN]; | ||||
| @ -137,6 +140,7 @@ int main(int argc, char **argv) { | ||||
| 
 | ||||
| 	if (options->thumbnails == 2) { | ||||
| 		mode = MODE_THUMBS; | ||||
| 		render_thumbs(); | ||||
| 	} else { | ||||
| 		mode = MODE_NORMAL; | ||||
| 		load_image(); | ||||
| @ -175,6 +179,35 @@ void update_title() { | ||||
| 	win_set_title(&win, win_title); | ||||
| } | ||||
| 
 | ||||
| void render_thumbs() { | ||||
| 	int i, cnt, x, y; | ||||
| 
 | ||||
| 	tcols = win.w / (THUMB_SIZE + 10); | ||||
| 	trows = win.h / (THUMB_SIZE + 10); | ||||
| 
 | ||||
| 	x = win.w - tcols * (THUMB_SIZE + 10) + 5; | ||||
| 	y = win.h - trows * (THUMB_SIZE + 10) + 5; | ||||
| 	cnt = MIN(tcols * trows, filecnt); | ||||
| 
 | ||||
| 	win_clear(&win); | ||||
| 
 | ||||
| 	i = 0; | ||||
| 	while (i < cnt) { | ||||
| 		thumbs[i].x = x + (THUMB_SIZE - thumbs[i].w) / 2; | ||||
| 		thumbs[i].y = y + (THUMB_SIZE - thumbs[i].h) / 2; | ||||
| 		win_draw_pixmap(&win, thumbs[i].pm, thumbs[i].x, thumbs[i].y, thumbs[i].w, | ||||
| 		                thumbs[i].h); | ||||
| 		if (++i % tcols == 0) { | ||||
| 			x = win.w - tcols * (THUMB_SIZE + 10) + 5; | ||||
| 			y += THUMB_SIZE + 10; | ||||
| 		} else { | ||||
| 			x += THUMB_SIZE + 10; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	win_draw(&win); | ||||
| } | ||||
| 
 | ||||
| int check_append(const char *filename) { | ||||
| 	if (!filename) | ||||
| 		return 0; | ||||
|  | ||||
							
								
								
									
										10
									
								
								options.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								options.c
									
									
									
									
									
								
							| @ -25,12 +25,13 @@ | ||||
| 
 | ||||
| #include "config.h" | ||||
| #include "options.h" | ||||
| #include "util.h" | ||||
| 
 | ||||
| options_t _options; | ||||
| const options_t *options = (const options_t*) &_options; | ||||
| 
 | ||||
| void print_usage() { | ||||
| 	printf("usage: sxiv [-dFfhpqrstvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); | ||||
| 	printf("usage: sxiv [-dFfhpqrsTtvZ] [-g GEOMETRY] [-z ZOOM] FILES...\n"); | ||||
| } | ||||
| 
 | ||||
| void print_version() { | ||||
| @ -54,7 +55,7 @@ void parse_options(int argc, char **argv) { | ||||
| 	_options.quiet = 0; | ||||
| 	_options.recursive = 0; | ||||
| 
 | ||||
| 	while ((opt = getopt(argc, argv, "dFfg:hpqrstvZz:")) != -1) { | ||||
| 	while ((opt = getopt(argc, argv, "dFfg:hpqrsTtvZz:")) != -1) { | ||||
| 		switch (opt) { | ||||
| 			case '?': | ||||
| 				print_usage(); | ||||
| @ -86,8 +87,11 @@ void parse_options(int argc, char **argv) { | ||||
| 			case 's': | ||||
| 				_options.scalemode = SCALE_FIT; | ||||
| 				break; | ||||
| 			case 'T': | ||||
| 				_options.thumbnails = 2; | ||||
| 				break; | ||||
| 			case 't': | ||||
| 				_options.thumbnails = 1; | ||||
| 				_options.thumbnails = MAX(_options.thumbnails, 1); | ||||
| 				break; | ||||
| 			case 'v': | ||||
| 				print_version(); | ||||
|  | ||||
							
								
								
									
										7
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								window.c
									
									
									
									
									
								
							| @ -219,6 +219,13 @@ Pixmap win_create_pixmap(win_t *win) { | ||||
| 	                     win->env.depth); | ||||
| } | ||||
| 
 | ||||
| void win_draw_pixmap(win_t *win, Pixmap pm, int x, int y, int w, int h) { | ||||
| 	if (!win) | ||||
| 		return; | ||||
| 
 | ||||
| 	XCopyArea(win->env.dpy, pm, win->pm, bgc, 0, 0, w, h, x, y); | ||||
| } | ||||
| 
 | ||||
| void win_clear(win_t *win) { | ||||
| 	win_env_t *e; | ||||
| 	XGCValues gcval; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Bert
						Bert