From owner-p4-projects@FreeBSD.ORG Tue Jul 24 21:47:18 2012 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 71A431065673; Tue, 24 Jul 2012 21:47:17 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 28C5D106564A for ; Tue, 24 Jul 2012 21:47:17 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 1072C8FC15 for ; Tue, 24 Jul 2012 21:47:17 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id q6OLlGaP010396 for ; Tue, 24 Jul 2012 21:47:16 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id q6OLlGV0010393 for perforce@freebsd.org; Tue, 24 Jul 2012 21:47:16 GMT (envelope-from brooks@freebsd.org) Date: Tue, 24 Jul 2012 21:47:16 GMT Message-Id: <201207242147.q6OLlGV0010393@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 214875 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Jul 2012 21:47:19 -0000 http://p4web.freebsd.org/@@214875?ac=10 Change 214875 by brooks@brooks_ecr_current on 2012/07/24 21:47:02 Add a new -s option to pictview that replaces the hardcoded set of photos with the files in a directory. All regular files in the directory are loaded in alphabetical order and must be PNG files. The existance of other types of files is currently an error. Affected files ... .. //depot/projects/ctsrd/beribsd/src/ctsrd/pictview/pictview.c#12 edit Differences ... ==== //depot/projects/ctsrd/beribsd/src/ctsrd/pictview/pictview.c#12 (text+ko) ==== @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -365,61 +366,113 @@ * Picture viewer including PNG image loader *****************************************************************************/ -static const int pictview_numimg=7; -//static u_int32_t* pictview_imgs[pictview_numimg]; -static u_int32_t* pictview_imgs[7]; -static int pictview_browser_img; -static int pictview_quill_img; -static int pictview_term_img; -static int pictview_num_photo; +static const int selector_nimages=4; +static u_int32_t *selector_images[4]; +static char *slide_dir = NULL; +static int slide_nimages; +static u_int32_t **slide_images; +static u_int32_t *bgimage; + +#define SEL_SLIDE_IMG 0 +#define SEL_QUILL_IMG 1 +#define SEL_TERM_IMG 2 +#define SEL_BROWSER_IMG 3 +static int +strpcmp(const void *v1, const void *v2) +{ -/* -void -show_text_buffer(void) -{ - int j; - fb_fade2off(); - // display background - for(j=0; jd_type != DT_REG) + continue; + if (slide_nimages == maxslides) { + maxslides *= 2; + slidenames = realloc(slidenames, sizeof(*slidenames) * maxslides); + if (slidenames == NULL) + err(1, "realloc slidenames"); + } + slidenames[slide_nimages] = strdup(entry->d_name); + if (slidenames[slide_nimages] == NULL) + err(1, "strdup"); + slide_nimages++; + } + qsort(slidenames, slide_nimages, sizeof(*slidenames), &strpcmp); + slide_images = malloc(sizeof(*slide_images) * slide_nimages); + if (slide_images == NULL) + err(1, "malloc slide_images"); + for (j = 0; j < slide_nimages; j++) { + slide_images[j] = malloc(sizeof(u_int32_t) * fb_width * fb_height); + if (slide_images[j] == NULL) + err(1, "malloc slide_images[%d]", j); + if ((fd = openat(dirfd(dirp), slidenames[j], O_RDONLY)) == -1) + err(1, "openat(slide_dir, %s)", slidenames[j]); + if (read_png_fd(fd, slide_images[j], fb_width, fb_height) != 0) + errx(1, "failed to read png %s", slidenames[j]); + close(fd); + free(slidenames[j]); + } + closedir(dirp); + free(slidenames); + } + + for(j=0; j0) { + if(imgmap[xi][yi]>=0) { int x,y; int x0 = (fb_width/tile)*xi + ((fb_width/tile)-(fb_width/scale))/2; int y0 = (fb_height/tile)*yi + ((fb_height/tile)-(fb_height/scale))/2; int img = imgmap[xi][yi]; for(y=0; ypictview_num_photo)) { - printf("pictview_pan assertion error: display_image=%1d out of range\n", - display_image); - display_image = next_display_image = 1; - } - // display image for(y=0; yts_count==1) { if((pan_direction==-1) && (ts->ts_x1>(5*fb_width/6))) { // pan image to right pan_direction=1; - next_display_image = (display_image % pictview_num_photo)+1; + next_display_image = (display_image + 1) % slide_nimages; prev_ts_x1 = fb_width-1; //printf("display_image=%1d next_display_image=%1d\n",display_image,next_display_image); } if((pan_direction==-1) && (ts->ts_x1<(fb_width/6))) { // pan image to left pan_direction=0; - next_display_image = ((pictview_num_photo+display_image-2) % pictview_num_photo)+1; + next_display_image = (display_image == 0) ? slide_nimages - 1 : display_image - 1; prev_ts_x1 = 0; - // printf("display_image=%1d next_display_image=%1d\n",display_image,next_display_image); + //printf("display_image=%1d next_display_image=%1d\n",display_image,next_display_image); } if(pan_direction!=-1) { int img0, img1; @@ -555,9 +603,9 @@ for(y=0; yts_x1; x++) - fb_buf[x+k] = pictview_imgs[img0][x+k]; + fb_buf[x+k] = slide_images[img0][x+k]; for(x=ts->ts_x1; x<=prev_ts_x1; x++) - fb_buf[x+k] = pictview_imgs[img1][x+k]; + fb_buf[x+k] = slide_images[img1][x+k]; } fb_post(fb_buf); prev_ts_x1 = ts->ts_x1; @@ -632,24 +680,6 @@ void -pictview_slideshow() -{ - int j, k; - // while no pinch gesture, display slide show - while(!((touch_count==2) && (touch_gesture==0x49))) { - multitouch_pole(); - for(j=1; j<=pictview_num_photo; j++) { - // printf("display image %1d\n",j); - fb_fade2off(); - fb_post(pictview_imgs[j]); - fb_fade2on(); - sleep(3); - } - } -} - - -void pictview(void) { int display_image; @@ -663,24 +693,29 @@ while(1) { display_image = pictview_selector(); - if(display_image == pictview_term_img) + if(display_image == SEL_TERM_IMG) keyboard_on(); // show_text_buffer(); - else if(display_image == pictview_quill_img) + else if(display_image == SEL_QUILL_IMG) pen_drawing(); - else if(display_image == pictview_browser_img) + else if(display_image == SEL_BROWSER_IMG) run_browser(); - else if((display_image>=1) && (display_image<=pictview_num_photo)) - pictview_pan(display_image); + else if(display_image == SEL_SLIDE_IMG) + pictview_pan(); } } +static void +usage(void) +{ +} + int main(int argc, char *argv[]) { - int tty; + int ch, tty; char *devpath; struct sigaction act; @@ -702,9 +737,20 @@ if (sigaction(SIGCHLD, &act, 0)) err(1, "sigacation"); - if (argc > 2) - errx(1, "usage: pictview [tty]"); - if (argc == 2) { + while ((ch = getopt(argc, argv, "s:")) != -1) { + switch (ch) { + case 's': + slide_dir = optarg; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argc > 1) + errx(1, "usage: pictview [-s ] [tty]"); + if (argc == 1) { kbdfd = -1; if (argv[1][0] != '/') asprintf(&devpath, "/dev/%s", argv[1]);