ply-image: Add --print-resolution flag.

This adds a new flag that instructs ply-image to print the
space-separated framebuffer width and height to stdout.

I'm also updating the usage method to list all flags.

BUG=chrome-os-partner:10047
TEST=manual: --print-resolution works; previous behavior still works too

Change-Id: I52a3c0570384026247b95c4ab2b642fe26f2edd4
Reviewed-on: https://gerrit.chromium.org/gerrit/27075
Reviewed-by: Daniel Erat <derat@chromium.org>
Tested-by: Daniel Erat <derat@chromium.org>
Commit-Ready: Daniel Erat <derat@chromium.org>
diff --git a/src/ply-image.c b/src/ply-image.c
index 8bffdfa..9bebe07 100644
--- a/src/ply-image.c
+++ b/src/ply-image.c
@@ -291,10 +291,21 @@
 
 static int usage(void) {
   fprintf(stderr,
-          "usage: ply-image --clear <hexcolor>\n"
-          "       ply-image [--gamma <gammafile>] "
-          "[--location <x>,<y> | --offset <[+|-]x>,<[+|-]y>] "
-          "<frame> [<frame> ...]\n");
+          "usage: ply-image [OPTION]... [FILE]...\n"
+          "Copy one or more images to the framebuffer.\n"
+          "\n"
+          "Options:\n"
+          "  --clear=0xRRGGBB         hexadecimal framebuffer clear color\n"
+          "  --debug                  print debugging info to stderr\n"
+          "  --frame-interval=MSEC    time interval between images\n"
+          "  --gamma=FILE             file containing gamma ramps\n"
+          "  --help                   display this message\n"
+          "  --location=X,Y           image location relative to top left\n"
+          "                           corner of framebuffer\n"
+          "  --offset=[+|-]X,[+|-]Y   image location as offset from center\n"
+          "                           of framebuffer\n"
+          "  --print-resolution       print space-separated framebuffer\n"
+          "                           width and height to stdout\n");
   exit(EXIT_FAILURE);
 }
 
@@ -409,13 +420,14 @@
 }
 
 
-#define FLAG_CLEAR      'c'
-#define FLAG_DEBUG      'D'
-#define FLAG_FRAME      'f'
-#define FLAG_GAMMA      'g'
-#define FLAG_HELP       'h'
-#define FLAG_LOCATION   'l'
-#define FLAG_OFFSET     'o'
+#define FLAG_CLEAR             'c'
+#define FLAG_DEBUG             'D'
+#define FLAG_FRAME             'f'
+#define FLAG_GAMMA             'g'
+#define FLAG_HELP              'h'
+#define FLAG_LOCATION          'l'
+#define FLAG_OFFSET            'o'
+#define FLAG_PRINT_RESOLUTION  'p'
 
 static struct option command_options[] = {
   { "clear", required_argument, NULL, FLAG_CLEAR },
@@ -425,13 +437,16 @@
   { "help", no_argument, NULL, FLAG_HELP },
   { "location", required_argument, NULL, FLAG_LOCATION },
   { "offset", required_argument, NULL, FLAG_OFFSET },
+  { "print-resolution", no_argument, NULL, FLAG_PRINT_RESOLUTION },
   { NULL, 0, NULL, 0 },
 };
 
 
 int main(int argc, char **argv) {
   int clear = 0;
-  bool location_assigned = false, offset_assigned = false;
+  bool location_assigned = false;
+  bool offset_assigned = false;
+  bool print_resolution = false;
   ply_frame_buffer_t *buffer;
 
   /*
@@ -455,6 +470,7 @@
 
     if (c == FLAG_DEBUG) {
       debug = 1;
+      continue;
     }
 
     if (c == FLAG_CLEAR) {
@@ -494,6 +510,11 @@
       offset_assigned = true;
       continue;
     }
+
+    if (c == FLAG_PRINT_RESOLUTION) {
+      print_resolution = true;
+      continue;
+    }
   }
 
   if (location_assigned && offset_assigned) {
@@ -508,11 +529,16 @@
     return errno;
   }
 
+  ply_frame_buffer_area_t fb_area;
+  ply_frame_buffer_get_size(buffer, &fb_area);
+
+  if (print_resolution) {
+    printf("%d %d\n", fb_area.width, fb_area.height);
+  }
+
   if (debug) {
-    ply_frame_buffer_area_t area;
-    ply_frame_buffer_get_size(buffer, &area);
     fprintf(stderr, "screen dimensions:  %lux%lu\n",
-                    area.width, area.height);
+            fb_area.width, fb_area.height);
   }
 
   if (clear) {