PERFORCE change 219881 for review
Brooks Davis
brooks at FreeBSD.org
Wed Dec 5 00:02:38 UTC 2012
http://p4web.freebsd.org/@@219881?ac=10
Change 219881 by brooks at brooks_zenith on 2012/12/05 00:02:09
Add the ability to include a second set of slides with a second -s
argument. We can now include both briefing and demo slides
on the front page.
Affected files ...
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/pictview/Makefile#3 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/pictview/pictview.c#8 edit
Differences ...
==== //depot/projects/ctsrd/cheribsd/src/ctsrd/pictview/Makefile#3 (text+ko) ====
@@ -9,7 +9,7 @@
WARNS= 0
-LDADD+= -lde4tc -lvuln_png -lz -lm -lutil
+LDADD+= -lde4tc -limagebox -lvuln_png -lz -lm -lutil -lcheri -lpthread
# Disable the stack protector, we want to be vulnerable
SSP_CFLAGS=
==== //depot/projects/ctsrd/cheribsd/src/ctsrd/pictview/pictview.c#8 (text+ko) ====
@@ -52,6 +52,7 @@
#include <unistd.h>
#include <de4tc.h>
+#include <imagebox.h>
static pid_t browser_pid;
static pid_t kbd_pid;
@@ -370,23 +371,72 @@
* Picture viewer including PNG image loader
*****************************************************************************/
-static const int selector_nimages=4;
-static u_int32_t *selector_images[4];
+static const int selector_nimages=5;
+static u_int32_t *selector_images[5];
static char *slide_dir = NULL;
-static int slide_nimages;
-static u_int32_t **slide_images;
+static char *slide_dir2 = NULL;
+static u_int32_t *coverimage, *coverimage2;
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
+#define SEL_SLIDE_IMG2 4
-static int
-strpcmp(const void *v1, const void *v2)
+static uint32_t *
+loadcover(const char *dir)
{
+ DIR *dirp;
+ struct dirent *entry;
+ char *covername;
+ uint32_t *image;
+ int fd;
+ uint32_t c, fcol, r;
+ struct iboxstate *is;
- return (strcmp(*((const char**)v1), *((const char**)v2)));
+ covername = NULL;
+ if ((dirp = opendir(dir)) == NULL)
+ err(1, "opendir");
+ while((entry = readdir(dirp)) != NULL) {
+ /* XXX: doesn't support symlinks */
+ if (entry->d_type != DT_REG)
+ continue;
+ /* Ignore all files other than covers. */
+ if (fnmatch("*-cover-*.png", entry->d_name, 0) != 0)
+ continue;
+ covername = entry->d_name;
+ break;
+ }
+ if (covername == NULL)
+ errx(1, "No cover found in %s", dir);
+
+ if ((fd = openat(dirfd(dirp), covername, O_RDONLY)) == -1)
+ err(1, "openat(dir, %s)", covername);
+ if ((is = png_read_start(fd, fb_width, fb_height, SB_NONE)) == NULL)
+ errx(1, "Failed to start PNG decode for %s", covername);
+ if (png_read_finish(is) != 0)
+ errx(1, "png_read_finish() failed for icons.png");
+
+ image = malloc(sizeof(u_int32_t) * fb_width * fb_height);
+ if (image == NULL)
+ err(1, "malloc image]");
+ fcol = (fb_width - is->width) / 2;
+ fb_composite(image, fb_width, fb_height, fcol, 0,
+ is->buffer, is->width, is->height);
+ if (is->width != fb_width) {
+ for (r = 0; r < is->height; r++) {
+ for (c = 0; c < fcol; c++)
+ image[c + (r * fb_width)] = image[fcol + (r * fb_width)];
+ for (c = fcol + is->width; c < fb_width; c++)
+ image[c + (r * fb_width)] = image[fcol + is->width - 1 + (r * fb_width)];
+ }
+ }
+ iboxstate_free(is);
+ close(fd);
+ closedir(dirp);
+
+ return (image);
}
// initialisation - load the images to view
@@ -399,72 +449,18 @@
busy_indicator();
read_png_file("/usr/share/images/CatSword.png", bgimage, fb_width, fb_height);
- if (slide_dir == NULL) {
- slide_nimages = 3;
- if ((slide_images = malloc(sizeof(*slide_images) * slide_nimages)) == NULL)
- err(1, "malloc slide_images");
- for(j = 0; j < slide_nimages; j++)
- if ((slide_images[j] = malloc(sizeof(u_int32_t) * fb_width * fb_height)) == NULL)
- err(1, "malloc slide_images[%d]", j);
- busy_indicator();
- read_png_file("/usr/share/images/Canon-5DII-5487.png", slide_images[0], fb_width, fb_height);
- busy_indicator();
- read_png_file("/usr/share/images/Canon-5DII-4717.png", slide_images[1], fb_width, fb_height);
- busy_indicator();
- read_png_file("/usr/share/images/Canon-5DII-3816.png", slide_images[2], fb_width, fb_height);
- } else {
- DIR *dirp;
- struct dirent *entry;
- char **slidenames;
- int fd, maxslides;
+ coverimage = loadcover(slide_dir);
- if ((dirp = opendir(slide_dir)) == NULL)
- err(1, "opendir");
- slide_nimages = 0;
- maxslides = 1024;
- slidenames = malloc(sizeof(*slidenames) * maxslides);
- if (slidenames == NULL)
- err(1, "malloc slidenames");
- while((entry = readdir(dirp)) != NULL) {
- /* XXX: doesn't support symlinks */
- if (entry->d_type != DT_REG)
- continue;
- /* Ignore all files other than covers. */
- if (fnmatch("*-cover-*.png", entry->d_name, 0) != 0)
- 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);
- }
+ if (slide_dir2 != NULL)
+ coverimage2 = loadcover(slide_dir2);
+ else
+ coverimage2 = NULL;
for(j=0; j<selector_nimages; j++) {
if (j == SEL_SLIDE_IMG)
- selector_images[j] = slide_images[0];
+ selector_images[j] = coverimage;
+ else if (j == SEL_SLIDE_IMG2)
+ selector_images[j] = coverimage2;
else
if ((selector_images[j] = malloc(sizeof(u_int32_t) * fb_width * fb_height)) == NULL)
err(1, "malloc selector_images[%d]", j);
@@ -652,6 +648,9 @@
imgmap[1][2] = -1;
imgmap[2][2] = SEL_BROWSER_IMG;
+ if (slide_dir2 != NULL)
+ imgmap[1][2] = SEL_SLIDE_IMG2;
+
// display off
fb_fade2off();
@@ -699,81 +698,8 @@
return display_image;
}
-#ifdef USE_HW_ENG_CODE
-void pictview_pan()
-{
- int pan_direction = -1;
- int display_image = 0;
- int next_display_image = 0;
- int k,x,y;
- int prev_ts_x1;
- struct tsstate *ts;
-
- // display image
- for(y=0; y<fb_height; y++) {
- k=y*fb_width;
- for(x=0; x<fb_width; x++)
- fb_buf[x+k] = slide_images[display_image][x+k];
- }
- fb_post(fb_buf);
- fb_fade2on();
-
- for (;;) {
- ts = ts_poll();
- if (ts->ts_gesture == TSG2_ZOOM_OUT)
- break;
-
- if((ts->ts_count==0) && (pan_direction!=-1)) {
- // touch released so decide which image to view
- if((pan_direction==0) && (ts->ts_x1>(fb_width/2)))
- display_image = next_display_image;
- if((pan_direction==1) && (ts->ts_x1<(fb_width/2)))
- display_image = next_display_image;
- pan_direction = -1;
- for(k=0; k<fb_width*fb_height; k++)
- fb_buf[k] = slide_images[display_image][k];
- fb_post(fb_buf);
- }
-
- if(ts->ts_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 + 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 = (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);
- }
- if(pan_direction!=-1) {
- int img0, img1;
- if(pan_direction==0) {
- img0=next_display_image;
- img1=display_image;
- } else {
- img1=next_display_image;
- img0=display_image;
- }
- // printf("%1d",pan_direction);
- for(y=0; y<fb_height; y++) {
- k = y*fb_width;
- for(x=prev_ts_x1; x<ts->ts_x1; x++)
- fb_buf[x+k] = slide_images[img0][x+k];
- for(x=ts->ts_x1; x<=prev_ts_x1; x++)
- fb_buf[x+k] = slide_images[img1][x+k];
- }
- fb_post(fb_buf);
- prev_ts_x1 = ts->ts_x1;
- }
- }
- }
-}
-#else
static void
-pictview_pan(void)
+run_cheripoint(const char *dir)
{
static int pmaster;
int pslave, n;
@@ -794,7 +720,7 @@
syslog(LOG_ALERT, "login_tty failed in child: %s", strerror(errno));
err(1, "tty_login");
}
- execl("/usr/bin/cheripoint", "cheripoint", "-f", slide_dir, NULL);
+ execl("/usr/bin/cheripoint", "cheripoint", "-f", dir, NULL);
syslog(LOG_ALERT, "exec of /usr/bin/cheripoint failed: %s", strerror(errno));
err(1, "execl()");
}
@@ -834,7 +760,6 @@
}
}
}
-#endif
void
@@ -923,7 +848,9 @@
else if(display_image == SEL_BROWSER_IMG)
run_browser();
else if(display_image == SEL_SLIDE_IMG)
- pictview_pan();
+ run_cheripoint(slide_dir);
+ else if(display_image == SEL_SLIDE_IMG2)
+ run_cheripoint(slide_dir2);
}
}
@@ -931,6 +858,8 @@
static void
usage(void)
{
+ fprintf(stderr, "usage: pictview [-s <slide dir>] [-s <slide dir>]\n");
+ exit(1);
}
@@ -963,10 +892,15 @@
while ((ch = getopt(argc, argv, "s:")) != -1) {
switch (ch) {
case 's':
- slide_dir = optarg;
+ if (slide_dir == NULL)
+ slide_dir = optarg;
+ else if (slide_dir2 == NULL)
+ slide_dir2 = optarg;
+ else
+ usage();
+ break;
default:
usage();
- /* ENOKABOOMHERE */
}
}
argc -= optind;
@@ -991,12 +925,10 @@
}
}
-#ifndef USE_HW_ENG_CODE
if (slide_dir == NULL) {
+ warnx("usage: must pass in -s <dir>");
usage();
- err(1, "usage: must pass in -s <dir>");
}
-#endif
pictview();
More information about the p4-projects
mailing list