login

<     >

2015-08-03 11:56:37 (UTC-03:00)

Marcel Rodrigues <marcelgmr@gmail.com>

Improve example usage.

diff --git a/gifenc.c b/gifenc.c
index 995c494..3972281 100644
--- a/gifenc.c
+++ b/gifenc.c
@@ -227,23 +227,34 @@ close_gif(GIF* gif)
     free(gif);
 }
 
-#if 1
+#ifdef MAIN
 int
 main()
 {
     int i, j;
     int w = 120, h = 90;
-    GIF *gif = new_gif("example.gif", w, h, (uint8_t []) {
-        0x00, 0x00, 0x00,
-        0xFF, 0x00, 0x00,
-        0x00, 0xFF, 0x00,
-        0x00, 0x00, 0xFF,
-    }, 2, 0);
+
+    /* create a GIF */
+    GIF *gif = new_gif(
+        "example.gif",  /* file name */
+        w, h,           /* canvas size */
+        (uint8_t []) {  /* palette */
+            0x00, 0x00, 0x00, /* 0 -> black */
+            0xFF, 0x00, 0x00, /* 1 -> red */
+            0x00, 0xFF, 0x00, /* 2 -> green */
+            0x00, 0x00, 0xFF, /* 3 -> blue */
+        },
+        2,              /* palette depth == log2(# of colors) */
+        0               /* infinite loop */
+    );
+    /* draw some frames */
     for (i = 0; i < 4*6/3; i++) {
         for (j = 0; j < w*h; j++)
             gif->cur[j] = (i*3 + j) / 6 % 4;
         add_frame(gif, 10);
     }
+    /* remember to close the GIF */
     close_gif(gif);
+    return 0;
 }
 #endif