login

<     >

2017-11-12 10:37:18 (UTC-02:00)

Marcel Rodrigues <marcelgmr@gmail.com>

Add ge_ prefix to function and type names to avoid conflicts.

diff --git a/README b/README
index 505a3bf..59a9bae 100644
--- a/README
+++ b/README
@@ -24,12 +24,13 @@ Limitations
 Documentation
 -------------
 
-There are  only three functions  declared in "gifenc.h":  new_gif(), add_frame()
-and close_gif().
+There   are  only   three  functions   declared  in   "gifenc.h":  ge_new_gif(),
+ge_add_frame() and ge_close_gif().
 
-The new_gif() function receives GIF global options and returns a GIF handler:
+The  ge_new_gif() function  receives GIF  global  options and  returns a  ge_GIF
+handler:
 
-    GIF *new_gif(
+    ge_GIF *ge_new_gif(
         const char *fname,                  /* GIF file name */
         uint16_t width, uint16_t height,    /* frame size */
         uint8_t *palette, int depth,        /* color table */
@@ -64,10 +65,10 @@ positive number, the  animation will  be played that number  of times. If `loop`
 is negative,  no looping  information is stored  in the GIF  file (for  most GIF
 viewers, this is equivalent to `loop` == 1, i.e., "play once").
 
-The add_frame() function reads pixel data  from a buffer and saves the resulting
-frame to the file associated with the given GIF handler:
+The  ge_add_frame() function  reads  pixel  data from  a  buffer  and saves  the
+resulting frame to the file associated with the given ge_GIF handler:
 
-    void add_frame(GIF *gif, uint16_t delay);
+    void ge_add_frame(ge_GIF *gif, uint16_t delay);
 
 The `delay` parameter  specifies how long the frame will  be shown, in hundreths
 of a second. For example, `delay` ==  100 means "show this frame for one second"
@@ -80,8 +81,8 @@ Pixel data is read from `gif->frame`, which points to a memory block like this:
 
     uint8_t _frame_[gif->width * gif->height];
 
-Note that the address of `gif->frame`  changes between calls to add_frame() (*).
-For this  reason, each  frame must  be written  in its  entirety to  the current
+Note that  the address of  `gif->frame` changes between calls  to ge_add_frame()
+(*). For this reason, each frame must  be written in its entirety to the current
 address, even if one only wants to change  a few pixels from the last frame. The
 encoder will automatically detect the  difference between two consecutive frames
 in order to minimize the size of the output.
@@ -99,21 +100,22 @@ create a frame displaying a red-on-black "F" letter like this:
         2, 0, 0, 0,
         2, 0, 0, 0
     };
-    GIF *gif = new_gif("F.gif", 4, 7, palette, depth, -1);
+    ge_GIF *gif = ge_new_gif("F.gif", 4, 7, palette, depth, -1);
     memcpy(gif->frame, pixels, sizeof(pixels));
-    add_frame(gif, 0);
-    close_gif(gif);
+    ge_add_frame(gif, 0);
+    ge_close_gif(gif);
 
-The function close_gif() finishes writting GIF  data to the file associated with
-the given GIF handle and does memory clean-up. This function must be called once
-after all  desired frames have  been added, in order  to correctly save  the GIF
-file. After calling this function, the GIF handler cannot be used anymore.
+The function  ge_close_gif() finishes writting  GIF data to the  file associated
+with the  given ge_GIF handler and  does memory clean-up. This  function must be
+called once after all desired frames have been added, in order to correctly save
+the GIF  file. After calling  this function, the  ge_GIF handler cannot  be used
+anymore.
 
-    void close_gif(GIF* gif);
+    void ge_close_gif(ge_GIF* gif);
 
 (*) The  encoder keeps two frame  buffers internally, in order  to implement the
 size  optimization. The  address of  `gif->frame` alternates  between those  two
-buffers after each call to add_frame().
+buffers after each call to ge_add_frame().
 
 
 Example

diff --git a/example.c b/example.c
index 8b96da0..5960c14 100644
--- a/example.c
+++ b/example.c
@@ -7,7 +7,7 @@ main()
     int w = 120, h = 90;
 
     /* create a GIF */
-    GIF *gif = new_gif(
+    ge_GIF *gif = ge_new_gif(
         "example.gif",  /* file name */
         w, h,           /* canvas size */
         (uint8_t []) {  /* palette */
@@ -23,9 +23,9 @@ main()
     for (i = 0; i < 4*6/3; i++) {
         for (j = 0; j < w*h; j++)
             gif->frame[j] = (i*3 + j) / 6 % 4;
-        add_frame(gif, 10);
+        ge_add_frame(gif, 10);
     }
     /* remember to close the GIF */
-    close_gif(gif);
+    ge_close_gif(gif);
     return 0;
 }

diff --git a/gifenc.c b/gifenc.c
index afc26b0..3270f6b 100644
--- a/gifenc.c
+++ b/gifenc.c
@@ -59,16 +59,16 @@ del_trie(Node *root, int degree)
     free(root);
 }
 
-static void put_loop(GIF *gif, uint16_t loop);
+static void put_loop(ge_GIF *gif, uint16_t loop);
 
-GIF *
-new_gif(
+ge_GIF *
+ge_new_gif(
     const char *fname, uint16_t width, uint16_t height,
     uint8_t *palette, int depth, int loop
 )
 {
     int i, r, g, b, v;
-    GIF *gif = calloc(1, sizeof(*gif) + 2*width*height);
+    ge_GIF *gif = calloc(1, sizeof(*gif) + 2*width*height);
     if (!gif)
         goto no_gif;
     gif->w = width; gif->h = height;
@@ -117,7 +117,7 @@ no_gif:
 }
 
 static void
-put_loop(GIF *gif, uint16_t loop)
+put_loop(ge_GIF *gif, uint16_t loop)
 {
     write(gif->fd, (uint8_t []) {'!', 0xFF, 0x0B}, 3);
     write(gif->fd, "NETSCAPE2.0", 11);
@@ -130,7 +130,7 @@ put_loop(GIF *gif, uint16_t loop)
  *   gif->offset holds position to put next *bit*
  *   gif->partial holds bits to include in next byte */
 static void
-put_key(GIF *gif, uint16_t key, int key_size)
+put_key(ge_GIF *gif, uint16_t key, int key_size)
 {
     int byte_offset, bit_offset, bits_to_write;
     byte_offset = gif->offset / 8;
@@ -151,7 +151,7 @@ put_key(GIF *gif, uint16_t key, int key_size)
 }
 
 static void
-end_key(GIF *gif)
+end_key(ge_GIF *gif)
 {
     int byte_offset;
     byte_offset = gif->offset / 8;
@@ -163,7 +163,7 @@ end_key(GIF *gif)
 }
 
 static void
-put_image(GIF *gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
+put_image(ge_GIF *gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
 {
     int nkeys, key_size, i, j;
     Node *node, *child, *root;
@@ -207,7 +207,7 @@ put_image(GIF *gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
 }
 
 static int
-get_bbox(GIF *gif, uint16_t *w, uint16_t *h, uint16_t *x, uint16_t *y)
+get_bbox(ge_GIF *gif, uint16_t *w, uint16_t *h, uint16_t *x, uint16_t *y)
 {
     int i, j, k;
     int left, right, top, bottom;
@@ -235,7 +235,7 @@ get_bbox(GIF *gif, uint16_t *w, uint16_t *h, uint16_t *x, uint16_t *y)
 }
 
 static void
-set_delay(GIF *gif, uint16_t d)
+set_delay(ge_GIF *gif, uint16_t d)
 {
     write(gif->fd, (uint8_t []) {'!', 0xF9, 0x04, 0x04}, 4);
     write_num(gif->fd, d);
@@ -243,7 +243,7 @@ set_delay(GIF *gif, uint16_t d)
 }
 
 void
-add_frame(GIF *gif, uint16_t delay)
+ge_add_frame(ge_GIF *gif, uint16_t delay)
 {
     uint16_t w, h, x, y;
     uint8_t *tmp;
@@ -267,7 +267,7 @@ add_frame(GIF *gif, uint16_t delay)
 }
 
 void
-close_gif(GIF* gif)
+ge_close_gif(ge_GIF* gif)
 {
     write(gif->fd, ";", 1);
     close(gif->fd);

diff --git a/gifenc.h b/gifenc.h
index a83758c..b8504e0 100644
--- a/gifenc.h
+++ b/gifenc.h
@@ -3,7 +3,7 @@
 
 #include <stdint.h>
 
-typedef struct GIF {
+typedef struct ge_GIF {
     uint16_t w, h;
     int depth;
     int fd;
@@ -12,13 +12,13 @@ typedef struct GIF {
     uint8_t *frame, *back;
     uint32_t partial;
     uint8_t buffer[0xFF];
-} GIF;
+} ge_GIF;
 
-GIF *new_gif(
+ge_GIF *ge_new_gif(
     const char *fname, uint16_t width, uint16_t height,
     uint8_t *palette, int depth, int loop
 );
-void add_frame(GIF *gif, uint16_t delay);
-void close_gif(GIF* gif);
+void ge_add_frame(ge_GIF *gif, uint16_t delay);
+void ge_close_gif(ge_GIF* gif);
 
 #endif /* GIFENC_H */