#include "video.h"
#include "mouse.h"
#include "imago2.h"
+#include "chkalloc.h"
+
+int switch_mode(int m);
+int find_best_mode(int minx, int miny);
+void drop_equiv_modes(void);
void display8(void);
void display16(void);
static int vmlist_size, cur_vm = -1;
static void *backbuf;
+static int opt_width, opt_height;
static int opt_bpp = 16;
static const char *opt_fname;
num = num_video_modes();
vmodes = video_modes();
- if(!(vmlist = malloc(num * sizeof *vmlist))) {
+ if(!(vmlist = chk_malloc(num * sizeof *vmlist))) {
fprintf(stderr, "failed to allocate video mode list\n");
return 1;
}
init_mouse();
- modeidx = find_best_mode(img.width, img.height);
+ if(!opt_width) {
+ opt_width = img.width;
+ opt_height = img.height;
+ }
+ modeidx = find_best_mode(opt_width, opt_height);
if(switch_mode(modeidx) == -1) {
goto end;
}
end:
img_destroy(&img);
- free(backbuf);
- free(vmlist);
+ chk_free(backbuf);
+ chk_free(vmlist);
if(cur_vm >= 0) {
set_text_mode();
}
cleanup_video();
+ chk_check();
return 0;
}
vmode = vmlist + m;
cur_vm = m;
- free(backbuf);
- if(!(backbuf = malloc(vmode->ysz * vmode->pitch))) {
+ chk_free(backbuf);
+ if(!(backbuf = chk_malloc(vmode->ysz * vmode->pitch))) {
fprintf(stderr, "failed to allocate back buffer\n");
return -1;
}
int i;
static const char *usage_fmt = "Usage: %s [options] <image file>\n"
"Options:\n"
+ " -s <WxH>: choose screen resolution if available\n"
" -bpp <n>: video mode color depth (8, 15, 16, 24, 32)\n"
" -h,-help: print usage information and exit\n";
for(i=1; i<argc; i++) {
if(argv[i][0] == '-') {
- if(strcmp(argv[i], "-bpp") == 0) {
+ if(strcmp(argv[i], "-s") == 0) {
+ if(!argv[++i] || sscanf(argv[i], "%dx%d", &opt_width, &opt_height) != 2 ||
+ opt_width <= 0 || opt_height <= 0) {
+ fprintf(stderr, "invalid resolution\n");
+ return -1;
+ }
+ } else if(strcmp(argv[i], "-bpp") == 0) {
if(!argv[++i] || (opt_bpp = atoi(argv[i])) <= 0) {
fprintf(stderr, "invalid -bpp\n");
return -1;