Revision: 48485
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48485
Author:   campbellbarton
Date:     2012-07-02 08:37:59 +0000 (Mon, 02 Jul 2012)
Log Message:
-----------
code cleanup

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c

Modified: 
branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c
===================================================================
--- branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c  
2012-07-02 08:30:29 UTC (rev 48484)
+++ branches/soc-2011-tomato/source/blender/windowmanager/intern/wm_playanim.c  
2012-07-02 08:37:59 UTC (rev 48485)
@@ -1,6 +1,4 @@
-/**
- * $Id: playanim.c 17755 2008-12-09 04:57:42Z bdiego $
- *
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -22,26 +20,29 @@
  *
  * The Original Code is: all of this file.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Campbell Barton
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/windowmanager/intern/wm_playanim.c
+ *  \ingroup wm
+ *
+ * \note This file uses ghost directly and none of the WM definitions.
+ *       this could be made into its own module, alongside creator/
+ */
+
 #include <sys/types.h>
 #include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #ifndef WIN32
-#include <unistd.h>
-#include <sys/times.h>
-#include <sys/wait.h>
+#  include <unistd.h>
+#  include <sys/times.h>
+#  include <sys/wait.h>
 #else
-#include <io.h>
+#  include <io.h>
 #endif
 #include "MEM_guardedalloc.h"
 
@@ -63,12 +64,12 @@
 #include "BIF_glutil.h"
 
 #ifdef WITH_QUICKTIME
-#ifdef _WIN32
-#include <QTML.h>
-#include <Movies.h>
-#elif defined(__APPLE__)
-#include <QuickTime/Movies.h>
-#endif /* __APPLE__ */
+#  ifdef _WIN32
+#    include <QTML.h>
+#    include <Movies.h>
+#  elif defined(__APPLE__)
+#    include <QuickTime/Movies.h>
+#  endif /* __APPLE__ */
 #endif /* WITH_QUICKTIME */
 
 #include "DNA_scene_types.h"
@@ -168,13 +169,8 @@
        return(event);
 }
 
-/* ***************** gl_util.c ****************** */
-
-
-
-
-typedef struct pict {
-       struct pict *next, *prev;
+typedef struct PlayAnimPict {
+       struct PlayAnimPict *next, *prev;
        char *mem;
        int size;
        char *name;
@@ -182,9 +178,9 @@
        struct anim *anim;
        int frame;
        int IB_flags;
-}Pict;
+} PlayAnimPict;
 
-static struct ListBase _picsbase = {0, 0};
+static struct ListBase _picsbase = {NULL, NULL};
 static struct ListBase *picsbase = &_picsbase;
 static int fromdisk = FALSE;
 static int fstep = 1;
@@ -203,10 +199,10 @@
        return (ptottime < 0);
 }
 
-static void toscreen(Pict *picture, struct ImBuf *ibuf)
+static void toscreen(PlayAnimPict *picture, struct ImBuf *ibuf)
 {
 
-       if (ibuf == 0) {
+       if (ibuf == NULL) {
                printf("no ibuf !\n");
                return;
        }
@@ -224,10 +220,10 @@
        pupdate_time();
 
        if (picture && (qualN & (SHIFT | LMOUSE))) {
-               char str[512];
+               char str[32 + FILE_MAX];
                cpack(-1);
-               glRasterPos2f(0.02f,  0.03f);
-               sprintf(str, "%s | %.2f frames/s\n", picture->name, fstep / 
swaptime);
+               glRasterPos2f(0.02f, 0.03f);
+               BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s\n", 
picture->name, fstep / swaptime);
 #if 0 // XXX25
                BMF_DrawString(G.fonts, str);
 #endif
@@ -239,12 +235,12 @@
 static void build_pict_list(char *first, int totframes, int fstep)
 {
        int size, pic, file;
-       char *mem, name[512];
+       char *mem, filepath[FILE_MAX];
 //     short val;
-       struct pict *picture = 0;
-       struct ImBuf *ibuf = 0;
+       PlayAnimPict *picture = NULL;
+       struct ImBuf *ibuf = NULL;
        int count = 0;
-       char str[512];
+       char str[32 + FILE_MAX];
        struct anim *anim;
 
        if (IMB_isanim(first)) {
@@ -257,40 +253,42 @@
                        }
 
                        for (pic = 0; pic < IMB_anim_get_duration(anim, 
IMB_TC_NONE); pic++) {
-                               picture = (Pict *)MEM_callocN(sizeof(Pict), 
"Pict");
+                               picture = (PlayAnimPict 
*)MEM_callocN(sizeof(PlayAnimPict), "Pict");
                                picture->anim = anim;
                                picture->frame = pic;
                                picture->IB_flags = IB_rect;
-                               sprintf(str, "%s : %d", first, pic + 1);
+                               BLI_snprintf(str, sizeof(str), "%s : %d", 
first, pic + 1);
                                picture->name = strdup(str);
                                BLI_addtail(picsbase, picture);
                        }
                }
-               else printf("couldn't open anim %s\n", first);
+               else {
+                       printf("couldn't open anim %s\n", first);
+               }
        }
        else {
 
-               strcpy(name, first);
+               BLI_strncpy(filepath, first, sizeof(filepath));
 
                pupdate_time();
                ptottime = 1.0;
 
-/*
-     O_DIRECT
-            If set, all reads and writes on the resulting file descriptor will
-            be performed directly to or from the user program buffer, provided
-            appropriate size and alignment restrictions are met.  Refer to the
-            F_SETFL and F_DIOINFO commands in the fcntl(2) manual entry for
-            information about how to determine the alignment constraints.
-            O_DIRECT is a Silicon Graphics extension and is only supported on
-            local EFS and XFS file systems.
- */
+               /* O_DIRECT
+                *
+                * If set, all reads and writes on the resulting file 
descriptor will
+                * be performed directly to or from the user program buffer, 
provided
+                * appropriate size and alignment restrictions are met.  Refer 
to the
+                * F_SETFL and F_DIOINFO commands in the fcntl(2) manual entry 
for
+                * information about how to determine the alignment constraints.
+                * O_DIRECT is a Silicon Graphics extension and is only 
supported on
+                * local EFS and XFS file systems.
+                */
 
-               while (IMB_ispic(name) && totframes) {
-                       file = open(name, O_BINARY | O_RDONLY, 0);
+               while (IMB_ispic(filepath) && totframes) {
+                       file = open(filepath, O_BINARY | O_RDONLY, 0);
                        if (file < 0) return;
-                       picture = (struct pict *)MEM_callocN(sizeof(struct 
pict), "picture");
-                       if (picture == 0) {
+                       picture = (PlayAnimPict 
*)MEM_callocN(sizeof(PlayAnimPict), "picture");
+                       if (picture == NULL) {
                                printf("Not enough memory for pict struct \n");
                                close(file);
                                return;
@@ -308,7 +306,7 @@
 
                        if (fromdisk == FALSE) {
                                mem = (char *)MEM_mallocN(size, "build pic 
list");
-                               if (mem == 0) {
+                               if (mem == NULL) {
                                        printf("Couldn't get memory\n");
                                        close(file);
                                        MEM_freeN(picture);
@@ -316,17 +314,19 @@
                                }
 
                                if (read(file, mem, size) != size) {
-                                       printf("Error while reading %s\n", 
name);
+                                       printf("Error while reading %s\n", 
filepath);
                                        close(file);
                                        MEM_freeN(picture);
                                        MEM_freeN(mem);
                                        return;
                                }
                        }
-                       else mem = 0;
+                       else {
+                               mem = NULL;
+                       }
 
                        picture->mem = mem;
-                       picture->name = strdup(name);
+                       picture->name = strdup(filepath);
                        close(file);
                        BLI_addtail(picsbase, picture);
                        count++;
@@ -334,8 +334,13 @@
                        pupdate_time();
 
                        if (ptottime > 1.0) {
-                               if (picture->mem) ibuf = 
IMB_ibImageFromMemory((unsigned char *)picture->mem, picture->size, 
picture->IB_flags, picture->name);
-                               else ibuf = IMB_loadiffname(picture->name, 
picture->IB_flags);
+                               if (picture->mem) {
+                                       ibuf = IMB_ibImageFromMemory((unsigned 
char *)picture->mem, picture->size,
+                                                                    
picture->IB_flags, picture->name);
+                               }
+                               else {
+                                       ibuf = IMB_loadiffname(picture->name, 
picture->IB_flags);
+                               }
                                if (ibuf) {
                                        toscreen(picture, ibuf);
                                        IMB_freeImBuf(ibuf);
@@ -344,7 +349,7 @@
                                ptottime = 0.0;
                        }
 
-                       BLI_newname(name, +fstep);
+                       BLI_newname(filepath, +fstep);
 
 #if 0 // XXX25
                        while (qtest()) {
@@ -406,12 +411,13 @@
 void playanim(int argc, const char **argv)
 {
        struct ImBuf *ibuf = 0;
-       struct pict *picture = 0;
-       char name[512];
+       PlayAnimPict *picture = 0;
+       char filepath[FILE_MAX];
        short val = 0, go = TRUE, ibufx = 0, ibufy = 0;
        int event, stopped = FALSE;
        GHOST_TUns32 maxwinx, maxwiny;
-       short /*  c233 = FALSE, */ /*  yuvx = FALSE, */ once = FALSE, sstep = 
FALSE, wait2 = FALSE, /*  resetmap = FALSE, */ pause = 0;
+       /* short c233 = FALSE, yuvx = FALSE; */ /* UNUSED */
+       short once = FALSE, sstep = FALSE, wait2 = FALSE, /*  resetmap = FALSE, 
*/ pause = 0;
        short pingpong = FALSE, direction = 1, next = 1, turbo = FALSE, /*  
doubleb = TRUE, */ noskip = FALSE;
        int sizex, sizey, ofsx, ofsy, i;
        /* This was done to disambiguate the name for use under c++. */
@@ -442,7 +448,7 @@
                                        if (argc > 3) {
                                                double fps = atof(argv[2]);
                                                double fps_base = atof(argv[3]);
-                                               if (fps == 0) {
+                                               if (fps == 0.0) {
                                                        fps = 1;
                                                        printf("invalid fps,"
                                                               "forcing 1\n");
@@ -478,7 +484,9 @@
                        argc--;
                        argv++;
                }
-               else break;
+               else {
+                       break;
+               }
        }
 
 #ifdef WITH_QUICKTIME
@@ -501,27 +509,32 @@
        G.have_quicktime = TRUE;
 #endif /* WITH_QUICKTIME */
 
-       if (argc > 1) strcpy(name, argv[1]);
+       if (argc > 1) {
+               BLI_strncpy(filepath, argv[1], sizeof(filepath));
+       }
        else {
-               BLI_current_working_dir(name, sizeof(name));
-               if (name[strlen(name) - 1] != '/') strcat(name, "/");
+               BLI_current_working_dir(filepath, sizeof(filepath));
+               BLI_add_slash(filepath);
        }
 
-       if (IMB_isanim(name)) {
-               anim = IMB_open_anim(name, IB_rect, 0);
+       if (IMB_isanim(filepath)) {
+               anim = IMB_open_anim(filepath, IB_rect, 0);
                if (anim) {
                        ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, 
IMB_PROXY_NONE);
                        IMB_close_anim(anim);
                        anim = NULL;
                }
        }
-       else if (!IMB_ispic(name)) {
+       else if (!IMB_ispic(filepath)) {
                exit(1);
        }
 
-       if (ibuf == 0) ibuf = IMB_loadiffname(name, IB_rect);
-       if (ibuf == 0) {
-               printf("couldn't open %s\n", name);
+       if (ibuf == NULL) {
+               ibuf = IMB_loadiffname(filepath, IB_rect);
+       }
+
+       if (ibuf == NULL) {
+               printf("couldn't open %s\n", filepath);
                exit(1);
        }
 
@@ -575,15 +588,15 @@
                efra = MAXFRAME;
        }
 
-       build_pict_list(name, (efra - sfra) + 1, fstep);
+       build_pict_list(filepath, (efra - sfra) + 1, fstep);
 
        for (i = 2; i < argc; i++) {
-               strcpy(name, argv[i]);
-               build_pict_list(name, (efra - sfra) + 1, fstep);
+               BLI_strncpy(filepath, argv[i], sizeof(filepath));
+               build_pict_list(filepath, (efra - sfra) + 1, fstep);
        }
 
        IMB_freeImBuf(ibuf);
-       ibuf = 0;
+       ibuf = NULL;
 
        pupdate_time();
        ptottime = 0;
@@ -591,29 +604,46 @@
        while (go) {
                if (pingpong) direction = -direction;
 
-               if (direction == 1) picture = picsbase->first;
-               else picture = picsbase->last;
+               if (direction == 1) {
+                       picture = picsbase->first;
+               }
+               else {
+                       picture = picsbase->last;
+               }
 
-               if (picture == 0) {
+               if (picture == NULL) {
                        printf("couldn't find pictures\n");
                        go = FALSE;
                }
                if (pingpong) {
-                       if (direction == 1) picture = picture->next;
-                       else picture = picture->prev;
+                       if (direction == 1) {
+                               picture = picture->next;
+                       }
+                       else {
+                               picture = picture->prev;
+                       }
                }
                if (ptottime > 0.0) ptottime = 0.0;
 
                while (picture) {
-                       if (ibuf != 0 && ibuf->ftype == 0) IMB_freeImBuf(ibuf);

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to