Hi,

here's a patch for dfbsee to handle multiple files.
Forward / backward is bound to <return> <backspace>.
(I'd rather liked <space> instead of <return> but that's
already bound). The images which were already loaded,
are cached.

E.g.:
# dfbsee file1.png file2.png file3.jpg ...

-- 
   Johannes
Index: main.c
===================================================================
RCS file: /cvs/directfb/DFBSee/src/main.c,v
retrieving revision 1.23
diff -c -w -c -w -r1.23 main.c
*** main.c      2001/05/31 13:46:24     1.23
--- main.c      2001/06/04 20:48:13
***************
*** 20,25 ****
--- 20,26 ----
   */
  
  #include <stdio.h>
+ #include <stdlib.h> /* free */
  #include <unistd.h>
  #include <sys/time.h>
  
***************
*** 253,258 ****
--- 254,310 ----
    interface_show_zoom (scale);
  }
  
+ #define GET_SURFACE                                                        \
+ do {                                                                       \
+   char show_loading = 0;                                                   \
+   interface_draw_background ();                                            \
+   interface_show_title (surface->filename);                                \
+                                                                            \
+   if (!surface->image && !surface->video)                                  \
+     {                                                                      \
+       interface_show_message (dest, "Loading ...");                        \
+       show_loading = 1;                                                    \
+       surface->image = image_load (surface->filename, &width, &height);    \
+     }                                                                      \
+                                                                            \
+   if (!surface->image && !surface->video)                                  \
+     surface->video = video_load (surface->filename, &width, &height);      \
+                                                                            \
+   if ((!surface->image && !surface->video) || (width <= 0 || height <= 0)) \
+     {                                                                      \
+       printf ("\nSorry, no suitable media provider found for file '%s'\n", \
+             surface->filename);                                          \
+       return 1;                                                            \
+     }                                                                      \
+                                                                            \
+   if (show_loading)                                                        \
+     {                                                                      \
+       interface_show_message (image_area, NULL);                           \
+       interface_show_size (width, height);                                 \
+     }                                                                      \
+                                                                            \
+   if (surface->video)                                                      \
+     {                                                                      \
+       DFBCardCapabilities caps;                                            \
+       dfb->GetCardCapabilities (dfb, &caps);                               \
+                                                                            \
+       if (caps.acceleration_mask & DFXL_STRETCHBLIT)                       \
+       {                                                                  \
+         printf ("Using hardware-accelerated StretchBlits.\n");           \
+                                                                            \
+         dsc.flags       = DSDESC_PIXELFORMAT|DSDESC_WIDTH|DSDESC_HEIGHT; \
+         dsc.pixelformat = DSPF_RGB16;                                    \
+         dsc.width       = width;                                         \
+         dsc.height      = height;                                        \
+         dsc.caps        = DSCAPS_VIDEOONLY;                              \
+                                                                            \
+         dfb->CreateSurface (dfb, &dsc, &video_surface);                  \
+       }                                                                  \
+     }                                                                      \
+                                                                            \
+   show_media (surface->image, surface->video, dest);                       \
+ } while (0)
+ 
  int
  main (int    argc, 
        char **argv)
***************
*** 262,280 ****
    IDirectFBInputBuffer   *keybuffer;
    IDirectFBSurface       *image_area;
    IDirectFBSurface       *dest;
-   IDirectFBSurface       *image = NULL;
-   IDirectFBVideoProvider *video = NULL;
  
!   char *filename   = NULL;
    int quit         = 0;
    int video_paused = 0;
    int width, height;
  
    DFBCHECK (DirectFBInit (&argc, &argv));
  
!   filename = options_parse (argc, argv);
  
!   if (!filename)
      return 1;
  
    /* create the super interface */
--- 314,330 ----
    IDirectFBInputBuffer   *keybuffer;
    IDirectFBSurface       *image_area;
    IDirectFBSurface       *dest;
  
!   dfbsee_surface* surface;
    int quit         = 0;
    int video_paused = 0;
    int width, height;
  
    DFBCHECK (DirectFBInit (&argc, &argv));
  
!   surface = options_parse (argc, argv);
  
!   if (!surface)
      return 1;
  
    /* create the super interface */
***************
*** 309,356 ****
    image_area = interface_init ();
  
    dest = fullscreen ? primary : image_area;
- 
-   interface_draw_background ();
-   interface_show_title (filename);
- 
-   interface_show_message (dest, "Loading ...");
- 
-   image = image_load (filename, &width, &height);
- 
-   if (!image)
-     video = video_load (filename, &width, &height);
- 
-   if ((!image && !video) || (width <= 0 || height <= 0))
-     {
-       printf ("\nSorry, no suitable media provider found for file '%s'\n",
-             filename);
-       return 1;
-     }
  
!   interface_show_message (image_area, NULL);
!   interface_show_size (width, height);
  
-   if (video)
-     {
-       DFBCardCapabilities caps;
-       dfb->GetCardCapabilities (dfb, &caps);
- 
-       if (caps.acceleration_mask & DFXL_STRETCHBLIT)
-       {
-         printf ("Using hardware-accelerated StretchBlits.\n");
- 
-         dsc.flags       = DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_HEIGHT;
-         dsc.pixelformat = DSPF_RGB16;
-         dsc.width       = width;
-         dsc.height      = height;
-         dsc.caps        = DSCAPS_VIDEOONLY;
- 
-         dfb->CreateSurface (dfb, &dsc, &video_surface);
-       }
-     }
- 
-   show_media (image, video, dest);
- 
    while (!quit)
      {
        DFBInputEvent evt;
--- 359,367 ----
    image_area = interface_init ();
  
    dest = fullscreen ? primary : image_area;
  
!   GET_SURFACE;
  
    while (!quit)
      {
        DFBInputEvent evt;
***************
*** 363,406 ****
            {
              switch (evt.keycode)
                {
                case DIKC_HOME:
!                 if (video)
                      {
!                       video->SeekTo (video, 0);
                        video_pos_update ();
                      }
                  break;
  
                case DIKC_END:
!                 if (video)
                    {
                      double len;
!                     if (video->GetLength (video, &len) == DFB_OK
                          && len > 10.0) 
                          {
!                           video->SeekTo (video, len - 10.0);
                            video_pos_update ();
                          }
                    }
                  break;
  
                case DIKC_SPACE:
!                 if (video)
                    {
                      if (video_paused)
!                       show_media (image, video, dest);
                      else
!                       video->Stop (video);
  
                      video_paused = !video_paused;
                    }
                  break;
  
                case DIKC_LEFT:
!                 if (video)
                    {
                      double pos;
!                     if (video->GetPos (video, &pos) != DFB_OK)
                        break;
  
                      if (evt.modifiers & DIMK_CTRL)
--- 374,427 ----
            {
              switch (evt.keycode)
                {
+               case DIKC_ENTER:
+                 surface = surface->next;
+                 GET_SURFACE;
+                 video_paused = 0;
+                 break;
+               case DIKC_BACKSPACE:
+                 surface = surface->prev;
+                 GET_SURFACE;
+                 video_paused = 0;
+                 break;
                case DIKC_HOME:
!                 if (surface->video)
                      {
!                       surface->video->SeekTo (surface->video, 0);
                        video_pos_update ();
                      }
                  break;
  
                case DIKC_END:
!                 if (surface->video)
                    {
                      double len;
!                     if (surface->video->GetLength (surface->video, &len) == DFB_OK
                          && len > 10.0) 
                          {
!                           surface->video->SeekTo (surface->video, len - 10.0);
                            video_pos_update ();
                          }
                    }
                  break;
  
                case DIKC_SPACE:
!                 if (surface->video)
                    {
                      if (video_paused)
!                       show_media (surface->image, surface->video, dest);
                      else
!                       surface->video->Stop (surface->video);
  
                      video_paused = !video_paused;
                    }
                  break;
  
                case DIKC_LEFT:
!                 if (surface->video)
                    {
                      double pos;
!                     if (surface->video->GetPos (surface->video, &pos) != DFB_OK)
                        break;
  
                      if (evt.modifiers & DIMK_CTRL)
***************
*** 413,428 ****
                      if (pos < 0.0)
                        pos = 0.0;
  
!                     video->SeekTo (video, pos);
                        video_pos_update ();
                    }
                  break;
  
                case DIKC_RIGHT:
!                 if (video)
                    {
                      double pos;
!                     if (video->GetPos (video, &pos) != DFB_OK)
                        break;
  
                        if (evt.modifiers & DIMK_CTRL)
--- 434,449 ----
                      if (pos < 0.0)
                        pos = 0.0;
  
!                     surface->video->SeekTo (surface->video, pos);
                        video_pos_update ();
                    }
                  break;
  
                case DIKC_RIGHT:
!                 if (surface->video)
                    {
                      double pos;
!                     if (surface->video->GetPos (surface->video, &pos) != DFB_OK)
                        break;
  
                        if (evt.modifiers & DIMK_CTRL)
***************
*** 432,438 ****
                        else
                          pos += 10.0;
                           
!                       video->SeekTo (video, pos);
                        video_pos_update ();
                      }
                  break;
--- 453,459 ----
                        else
                          pos += 10.0;
                           
!                       surface->video->SeekTo (surface->video, pos);
                        video_pos_update ();
                      }
                  break;
***************
*** 441,461 ****
                  fullscreen = !fullscreen;
                    dest = fullscreen ? primary : image_area;
                    interface_draw_background ();
!                   interface_show_title (filename);
                    interface_show_size (width, height);
!                   show_media (image, video, dest);
                  video_paused = 0;
                  break;
  
                case DIKC_Z:
                    zoom = !zoom;
!                   show_media (image, video, dest);
                  video_paused = 0;
                  break;
  
                case DIKC_R:
                  override_ratio = !override_ratio;
!                   show_media (image, video, dest);
                  video_paused = 0;
                  break;
  
--- 462,482 ----
                  fullscreen = !fullscreen;
                    dest = fullscreen ? primary : image_area;
                    interface_draw_background ();
!                   interface_show_title (surface->filename);
                    interface_show_size (width, height);
!                   show_media (surface->image, surface->video, dest);
                  video_paused = 0;
                  break;
  
                case DIKC_Z:
                    zoom = !zoom;
!                   show_media (surface->image, surface->video, dest);
                  video_paused = 0;
                  break;
  
                case DIKC_R:
                  override_ratio = !override_ratio;
!                   show_media (surface->image, surface->video, dest);
                  video_paused = 0;
                  break;
  
***************
*** 467,473 ****
                        ratio = calc_size (width, height, 1.0, dest, NULL);
                      }
                    ratio += 0.1;
!                   show_media (image, video, dest);
                  video_paused = 0;
                    break;
  
--- 488,494 ----
                        ratio = calc_size (width, height, 1.0, dest, NULL);
                      }
                    ratio += 0.1;
!                   show_media (surface->image, surface->video, dest);
                  video_paused = 0;
                    break;
  
***************
*** 479,492 ****
                        ratio = calc_size (width, height, 1.0, dest, NULL);
                      }
                    ratio = MAX (ratio - 0.1, 0.1);
!                   show_media (image, video, dest);
                  video_paused = 0;
                    break;
                    
                  case DIKC_M:
                    zoom = 1;
                    ratio = calc_size (width, height, 1000.0, dest, NULL);
!                   show_media (image, video, dest);
                  video_paused = 0;
                    break;
                    
--- 500,513 ----
                        ratio = calc_size (width, height, 1.0, dest, NULL);
                      }
                    ratio = MAX (ratio - 0.1, 0.1);
!                   show_media (surface->image, surface->video, dest);
                  video_paused = 0;
                    break;
                    
                  case DIKC_M:
                    zoom = 1;
                    ratio = calc_size (width, height, 1000.0, dest, NULL);
!                   show_media (surface->image, surface->video, dest);
                  video_paused = 0;
                    break;
                    
***************
*** 504,514 ****
    video_pos_thread_stop ();
    interface_deinit ();
  
!   if (image)
!     image->Release (image);
! 
!   if (video)
!     video->Release (video);
  
    if (video_surface)
      video_surface->Release (video_surface);
--- 525,543 ----
    video_pos_thread_stop ();
    interface_deinit ();
  
!   /* cleaning up */
!   surface->prev->next = (dfbsee_surface*)0; /* terminate */
!   while (surface)
!     {
!       dfbsee_surface* tmp;
!       if (surface->image)
!       surface->image->Release (surface->image);
!       if (surface->video)
!       surface->video->Release (surface->video);
!       tmp = surface->next;
!       free(surface);
!       surface = tmp;
!     }
  
    if (video_surface)
      video_surface->Release (video_surface);
Index: options.c
===================================================================
RCS file: /cvs/directfb/DFBSee/src/options.c,v
retrieving revision 1.1
diff -c -w -c -w -r1.1 options.c
*** options.c   2001/05/17 16:50:07     1.1
--- options.c   2001/06/04 20:48:13
***************
*** 30,40 ****
  #include "options.h"
  
  
! char *
  options_parse (int    argc, 
                 char **argv)
  {
!   char *filename     = NULL;
    int print_usage    = 0;
    int print_version  = 0;
    int i;
--- 30,40 ----
  #include "options.h"
  
  
! dfbsee_surface*
  options_parse (int    argc, 
                 char **argv)
  {
!   dfbsee_surface* surface = (dfbsee_surface*)0;
    int print_usage    = 0;
    int print_version  = 0;
    int i;
***************
*** 84,108 ****
              print_usage = 1;
            }
        }
!       else if (i == (argc - 1))
        {
!         filename = argv[i];
        }
        else
!         print_usage = 1;
      }
  
    if (print_version)
      {
        printf ("DFBSee version " VERSION "\n");
!       return NULL;
      }
  
!   if (print_usage || !filename)
      {
        printf ("DFBSee version " VERSION
              " - an Image Viewer and Video Player using DirectFB\n"
!             "\n" "Usage: %s [options] <filename>\n\n", argv[0]);
        printf ("Options:\n"
              "  -v, --version                Print version information.\n"
              "  -f, --fullscreen             Start in fullscreen mode.\n"
--- 84,130 ----
              print_usage = 1;
            }
        }
!       else
!       {
!         if (access (argv[i], R_OK))
!             printf ("\nCan not access file '%s': %s\n", argv[i], strerror (errno));
!         else
            {
!             dfbsee_surface* new_surface = (dfbsee_surface*) malloc(sizeof 
(dfbsee_surface));
!             if (!new_surface)
!               {
!                 perror(__FILE__ ": new_surface");
!                 return (dfbsee_surface*)0;
                }
+             new_surface->filename = argv[i];
+             new_surface->image = (IDirectFBSurface*)0;
+             new_surface->video = (IDirectFBVideoProvider*)0;
+             if (surface)
+               {
+                 surface->prev->next = new_surface;
+                 new_surface->prev = surface->prev;
+               }
              else
!               {
!                 surface = new_surface;
!               }
!             surface->prev = new_surface;
!             new_surface->next = surface;
            }
+       }
+     }
  
    if (print_version)
      {
        printf ("DFBSee version " VERSION "\n");
!       return (dfbsee_surface*)0;
      }
  
!   if (print_usage || !surface)
      {
        printf ("DFBSee version " VERSION
              " - an Image Viewer and Video Player using DirectFB\n"
!             "\n" "Usage: %s [options] <file> [...]\n\n", argv[0]);
        printf ("Options:\n"
              "  -v, --version                Print version information.\n"
              "  -f, --fullscreen             Start in fullscreen mode.\n"
***************
*** 110,123 ****
              "  -r, --override-ratio [n:n]   Override aspect ratio.\n"
              "  -m, --mode <nnn>x<nnn>@<nn>  Switch framebuffer to nnn x nnn @ nn 
bpp.\n");
        return NULL;
-     }
- 
-   if (access (filename, R_OK))
-     {
-       printf ("\nCan not access file '%s': %s\n", filename, strerror (errno));
-       return NULL;
      }
! 
!   return filename;
  }
  
--- 132,138 ----
              "  -r, --override-ratio [n:n]   Override aspect ratio.\n"
              "  -m, --mode <nnn>x<nnn>@<nn>  Switch framebuffer to nnn x nnn @ nn 
bpp.\n");
        return NULL;
      }
!   return surface;
  }
  
Index: options.h
===================================================================
RCS file: /cvs/directfb/DFBSee/src/options.h,v
retrieving revision 1.1
diff -c -w -c -w -r1.1 options.h
*** options.h   2001/05/17 16:50:07     1.1
--- options.h   2001/06/04 20:48:13
***************
*** 22,29 ****
  #ifndef __OPTIONS_H__
  #define __OPTIONS_H__
  
  
! char * options_parse (int    argc, 
                        char **argv);
  
  
--- 22,36 ----
  #ifndef __OPTIONS_H__
  #define __OPTIONS_H__
  
+ typedef struct dfbsee_surface {
+     char* filename;
+     IDirectFBSurface *image;
+     IDirectFBVideoProvider *video;
+     struct dfbsee_surface* next;
+     struct dfbsee_surface* prev;
+ } dfbsee_surface;
  
! dfbsee_surface* options_parse (int    argc, 
                                 char **argv);
  
  

Reply via email to