babl r300 - in trunk: . babl



Author: ok
Date: Tue Apr  1 23:39:28 2008
New Revision: 300
URL: http://svn.gnome.org/viewvc/babl?rev=300&view=rev

Log:
* babl/babl-classes.h:
* babl/babl-conversion.c:
* babl/babl-db.c:
* babl/babl-fish-path.c:
* babl/babl-fish.c:
* babl/babl-format.c: 
* babl/babl-internal.h:
* babl/babl-introspect.c:
* babl/babl-list.c:
* babl/babl-list.h:
* babl/babl-model.c:
* babl/babl-sampling.c:
* babl/babl-sanity.c:
* babl/babl-type.c:
* babl/babl-util.[ch]: applied patch from Jan Heller that improves
readability by using the newly introduced BablList structure.


Modified:
   trunk/ChangeLog
   trunk/babl/babl-classes.h
   trunk/babl/babl-conversion.c
   trunk/babl/babl-db.c
   trunk/babl/babl-fish-path.c
   trunk/babl/babl-fish.c
   trunk/babl/babl-format.c
   trunk/babl/babl-internal.h
   trunk/babl/babl-introspect.c
   trunk/babl/babl-list.c
   trunk/babl/babl-list.h
   trunk/babl/babl-model.c
   trunk/babl/babl-sampling.c
   trunk/babl/babl-sanity.c
   trunk/babl/babl-type.c
   trunk/babl/babl-util.c
   trunk/babl/babl-util.h

Modified: trunk/babl/babl-classes.h
==============================================================================
--- trunk/babl/babl-classes.h	(original)
+++ trunk/babl/babl-classes.h	Tue Apr  1 23:39:28 2008
@@ -76,6 +76,7 @@
 
 
 typedef union _Babl Babl;
+typedef struct _BablList BablList;
 
 /* common header for any item inserted into database */
 typedef struct
@@ -109,7 +110,7 @@
 typedef struct
 {
   BablInstance     instance;
-  BablConversion **from;  /*< NULL terminated list of conversions from class */
+  BablList         *from_list;
   int              bits;  /*< number of bits used to represent the data type
                             (initially restricted to a multiple of 8) */
   double           min_val;
@@ -136,7 +137,7 @@
 typedef struct
 {
   BablInstance     instance;
-  BablConversion **from; /*< NULL terminated list of conversions from class */
+  BablList         *from_list;
   int              horizontal;
   int              vertical;
   char             name[4];
@@ -154,7 +155,7 @@
 typedef struct
 {
   BablInstance     instance;
-  BablConversion **from; /*< NULL terminated list of conversions from class */
+  BablList         *from_list;
   int              components;
   BablComponent  **component;
   BablType       **type; /*< must be doubles, used here for convenience in code */
@@ -163,7 +164,7 @@
 typedef struct
 {
   BablInstance     instance;
-  BablConversion **from; /*< NULL terminated list of conversions from class */
+  BablList         *from_list;
   int              components;
   BablComponent  **component;
   BablType       **type;

Modified: trunk/babl/babl-conversion.c
==============================================================================
--- trunk/babl/babl-conversion.c	(original)
+++ trunk/babl/babl-conversion.c	Tue Apr  1 23:39:28 2008
@@ -275,7 +275,9 @@
    * id/name, inserting newly created class into database.
    */
   babl_db_insert (db, babl);
-  babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl);
+  if (!source->type.from_list)
+    source->type.from_list = babl_list_init_with_size (BABL_CONVERSIONS);
+  babl_list_insert (source->type.from_list, babl);  
   return babl;
 }
 

Modified: trunk/babl/babl-db.c
==============================================================================
--- trunk/babl/babl-db.c	(original)
+++ trunk/babl/babl-db.c	Tue Apr  1 23:39:28 2008
@@ -111,7 +111,7 @@
               BablEachFunction each_fun,
               void            *user_data)
 {
-  babl_list_each_temp (db->babl_list, each_fun, user_data);
+  babl_list_each (db->babl_list, each_fun, user_data);
 }
 
 

Modified: trunk/babl/babl-fish-path.c
==============================================================================
--- trunk/babl/babl-fish-path.c	(original)
+++ trunk/babl/babl-fish-path.c	Tue Apr  1 23:39:28 2008
@@ -141,10 +141,10 @@
       temp_chain[temp_conversions] = NULL;
       babl_assert (from);
       babl_assert (from->class_type == BABL_FORMAT);
-      if (!from->format.from)
+      if (!from->format.from_list)
         return 0;
 
-      babl_list_each ((void **) from->format.from,
+      babl_list_each (from->format.from_list,
                       chain_gen_each,
                       &context);
     }
@@ -152,12 +152,11 @@
     {
       if (BABL (temp_chain[temp_conversions - 1]) &&
           BABL (temp_chain[temp_conversions - 1]->destination)->
-          format.from)
+          format.from_list)
 
         babl_list_each (
-          (void **)
           BABL (temp_chain[temp_conversions - 1]->destination)->
-          format.from,
+          format.from_list,
           chain_gen_each,
           &context);
     }
@@ -250,15 +249,16 @@
 assert_conversion_find (void *source,
                         void *destination)
 {
-  int    i = 0;
-  Babl **conversion;
+  int      i = 0;
+  BablList *conversion_list;
+  Babl     *conversion;
 
-  conversion = (void *) BABL (source)->type.from;
-  while (conversion && conversion[i])
+  conversion_list = BABL (source)->type.from_list;
+  for (i = 0; i < babl_list_size (conversion_list); i++)
     {
-      if (conversion[i]->conversion.destination == destination)
-        return (Babl *) conversion[i];
-      i++;
+      conversion = BABL (conversion_list->items[i]);
+      if (conversion->conversion.destination == destination)
+        return conversion;
     }
   babl_fatal ("failed, aborting");
   return NULL;

Modified: trunk/babl/babl-fish.c
==============================================================================
--- trunk/babl/babl-fish.c	(original)
+++ trunk/babl/babl-fish.c	Tue Apr  1 23:39:28 2008
@@ -41,7 +41,7 @@
 {
   void *data = (void*)destination;
 
-  babl_list_each ((void *) BABL (source)->type.from, match_conversion, &data);
+  babl_list_each (BABL (source)->type.from_list, match_conversion, &data);
   if (data == (void*)destination) /* didn't change */
     return NULL;
   return data;

Modified: trunk/babl/babl-format.c
==============================================================================
--- trunk/babl/babl-format.c	(original)
+++ trunk/babl/babl-format.c	Tue Apr  1 23:39:28 2008
@@ -27,7 +27,8 @@
 each_babl_format_destroy (Babl *babl,
                           void *data)
 {
-  babl_free (babl->format.from);
+  if (babl->format.from_list)
+    babl_list_destroy (babl->format.from_list);
   babl_free (babl);
 
   return 0;  /* continue iterating */
@@ -74,7 +75,7 @@
                       sizeof (int) * (components) +
                       sizeof (int) * (components));
 
-  babl->format.from      = NULL;
+  babl->format.from_list = NULL;
   babl->format.component = (void *) (((char *) babl) + sizeof (BablFormat));
   babl->format.type      = (void *) (((char *) babl->format.component) + sizeof (BablComponent *) * (components));
   babl->format.sampling  = (void *) (((char *) babl->format.type) + sizeof (BablType *) * (components));
@@ -110,7 +111,7 @@
 
 static char buf[512] = "";
 
-static const char *
+static char *
 create_name (BablModel      *model,
              int             components,
              BablComponent **component,

Modified: trunk/babl/babl-internal.h
==============================================================================
--- trunk/babl/babl-internal.h	(original)
+++ trunk/babl/babl-internal.h	Tue Apr  1 23:39:28 2008
@@ -25,6 +25,7 @@
 
 #define BABL_MAX_COMPONENTS       32
 #define BABL_HARD_MAX_PATH_LENGTH  8
+#define BABL_CONVERSIONS           5
 
 #include <stdlib.h>
 #include <stdio.h>

Modified: trunk/babl/babl-introspect.c
==============================================================================
--- trunk/babl/babl-introspect.c	(original)
+++ trunk/babl/babl-introspect.c	Tue Apr  1 23:39:28 2008
@@ -78,37 +78,22 @@
 }
 
 #ifdef BABL_LOG
-static int list_length (void **list)
-{
-  void **ptr;
-  int    len = 0;
-
-  ptr = list;
-  while (NULL != *ptr)
-    {
-      ptr++;
-      len++;
-    }
-  return len;
-}
-
 
 static void
 item_conversions_introspect (Babl *babl)
 {
-  void **ptr;
-
-  if (babl->type.from)
-    babl_log ("\t\tconversions from %s: %i",
-              babl->instance.name, list_length ((void **) (babl->type.from)));
-
-  ptr = (void **) babl->type.from;
+  int i;
+  BablList *list;
 
-  while (ptr && NULL != *ptr)
+  list = babl->type.from_list;
+  if (list) 
     {
-      babl_log ("\t\t\t'%s'", ((Babl *) (*ptr))->instance.name);
-      ptr++;
-    }
+      babl_log ("\t\tconversions from %s: %i",
+                babl->instance.name, babl_list_size (list));
+
+      for (i = 0; i < babl_list_size (list); i++)
+        babl_log ("\t\t\t'%s'", BABL (list->items[i])->instance.name);
+   }
 }
 
 static void

Modified: trunk/babl/babl-list.c
==============================================================================
--- trunk/babl/babl-list.c	(original)
+++ trunk/babl/babl-list.c	Tue Apr  1 23:39:28 2008
@@ -16,11 +16,8 @@
  * <http://www.gnu.org/licenses/>.
  */
 
-/* Implementation of list data structure. This is a bit superior
- * to the list implementation in babl-util.c.
+/* Implementation of list data structure. 
  * Copyright (C) 2008, Jan Heller
- *
- * TODO: migrate babl to BablList
  */
 
 #include "babl-internal.h"
@@ -30,11 +27,19 @@
 BablList *
 babl_list_init (void)
 {
+  return babl_list_init_with_size (BABL_LIST_INITIAL_SIZE);
+}
+
+BablList *
+babl_list_init_with_size (int initial_size)
+{
   BablList *list = babl_calloc (sizeof (BablList), 1);
 
   babl_assert (list);
 
-  list->size = BABL_LIST_INITIAL_SIZE;
+  if (initial_size == 0)
+    initial_size = 1;
+  list->size = initial_size;
   list->count = 0;
   list->items = NULL;
   if (list->size) 
@@ -81,13 +86,10 @@
     list->items[list->count++] = item;
 }
 
-/* TODO: Rename babl_list_each_temp to babl_list_each after the list migration
- */
-
 void
-babl_list_each_temp (BablList         *list,
-                     BablEachFunction each_fun,
-                     void             *user_data)
+babl_list_each (BablList         *list,
+                BablEachFunction each_fun,
+                void             *user_data)
 {
   int i;
 

Modified: trunk/babl/babl-list.h
==============================================================================
--- trunk/babl/babl-list.h	(original)
+++ trunk/babl/babl-list.h	Tue Apr  1 23:39:28 2008
@@ -20,12 +20,13 @@
 #define _BABL_LIST_H
 
 #ifndef _BABL_CLASSES_H
+/* babl-classes.h contains forward declaration
+ * typedef struct _BablList BablList;
+ */
 #error  babl-list.h is only to be included after babl-classes.h
 #endif
 
 
-typedef struct _BablList BablList;
-
 typedef struct _BablList
 {
   int  count;
@@ -37,6 +38,9 @@
 BablList *
 babl_list_init (void);
 
+BablList *
+babl_list_init_with_size (int initial_size);
+
 void
 babl_list_destroy (BablList *list);
 
@@ -48,9 +52,9 @@
                   Babl     *item);
 
 void
-babl_list_each_temp (BablList      *list,
-                     BablEachFunction each_fun,
-                     void             *user_data);
+babl_list_each (BablList      *list,
+                BablEachFunction each_fun,
+                void             *user_data);
 
 
 #endif

Modified: trunk/babl/babl-model.c
==============================================================================
--- trunk/babl/babl-model.c	(original)
+++ trunk/babl/babl-model.c	Tue Apr  1 23:39:28 2008
@@ -27,7 +27,8 @@
 each_babl_model_destroy (Babl *babl,
                          void *data)
 {
-  babl_free (babl->model.from);
+  if (babl->model.from_list)
+    babl_list_destroy (babl->model.from_list);
   babl_free (babl);
   return 0;  /* continue iterating */
 }
@@ -72,7 +73,7 @@
   strcpy (babl->instance.name, name);
   memcpy (babl->model.component, component, sizeof (BablComponent *) * components);
 
-  babl->model.from = NULL;
+  babl->model.from_list  = NULL;
   return babl;
 }
 

Modified: trunk/babl/babl-sampling.c
==============================================================================
--- trunk/babl/babl-sampling.c	(original)
+++ trunk/babl/babl-sampling.c	Tue Apr  1 23:39:28 2008
@@ -46,7 +46,8 @@
 each_babl_sampling_destroy (Babl *babl,
                             void *data)
 {
-  babl_free (babl->sampling.from);
+  if (babl->sampling.from_list)
+    babl_list_destroy (babl->sampling.from_list);
   return 0;  /* continue iterating */
 }
 

Modified: trunk/babl/babl-sanity.c
==============================================================================
--- trunk/babl/babl-sanity.c	(original)
+++ trunk/babl/babl-sanity.c	Tue Apr  1 23:39:28 2008
@@ -36,22 +36,20 @@
 {
   /* ensure that every type has reference conversions to
    * and from double */
-  void **ptr;
-  int    ok;
+  int      ok, i;
+  BablList *list;
 
   ok = 0;
-  if (babl->type.from)
+  list = babl->type.from_list;
+  if (list)
     {
-      ptr = (void **) babl->type.from;
-
-      while (ptr && NULL != *ptr)
+      for (i = 0; i < babl_list_size (list); i++)
         {
-          if (babl_conversion_destination ((Babl *) (*ptr)) == babl_type_id (BABL_DOUBLE))
+          if (babl_conversion_destination ((Babl *) list->items[i]) == babl_type_id (BABL_DOUBLE))
             {
               ok = 1;
               break;
             }
-          ptr++;
         }
     }
   if (!ok)
@@ -71,22 +69,20 @@
 {
   /* ensure that every type has reference conversions to
    * and from rgba */
-  void **ptr;
-  int    ok;
+  int      ok, i;
+  BablList *list;
 
   ok = 0;
-  if (babl->model.from)
+  list = babl->model.from_list;
+  if (list)
     {
-      ptr = (void **) babl->model.from;
-
-      while (ptr && NULL != *ptr)
+      for (i = 0; i < babl_list_size (list); i++)
         {
-          if (babl_conversion_destination ((Babl *) (*ptr)) == babl_model_id (BABL_RGBA))
+          if (babl_conversion_destination ((Babl *) list->items[i]) == babl_model_id (BABL_RGBA))
             {
               ok = 1;
               break;
             }
-          ptr++;
         }
     }
   if (!ok)

Modified: trunk/babl/babl-type.c
==============================================================================
--- trunk/babl/babl-type.c	(original)
+++ trunk/babl/babl-type.c	Tue Apr  1 23:39:28 2008
@@ -28,7 +28,8 @@
 each_babl_type_destroy (Babl *babl,
                         void *data)
 {
-  babl_free (babl->type.from);
+  if (babl->type.from_list)
+    babl_list_destroy (babl->type.from_list);
   babl_free (babl);
   return 0;  /* continue iterating */
 }
@@ -44,13 +45,13 @@
   babl_assert (bits != 0);
   babl_assert (bits % 8 == 0);
 
-  babl                = babl_malloc (sizeof (BablType) + strlen (name) + 1);
-  babl->instance.name = (void *) ((char *) babl + sizeof (BablType));
-  babl->class_type    = BABL_TYPE;
-  babl->instance.id   = id;
+  babl                 = babl_malloc (sizeof (BablType) + strlen (name) + 1);
+  babl->instance.name  = (void *) ((char *) babl + sizeof (BablType));
+  babl->class_type     = BABL_TYPE;
+  babl->instance.id    = id;
   strcpy (babl->instance.name, name);
-  babl->type.bits = bits;
-  babl->type.from = NULL;
+  babl->type.bits      = bits;
+  babl->type.from_list = NULL;
 
   return babl;
 }

Modified: trunk/babl/babl-util.c
==============================================================================
--- trunk/babl/babl-util.c	(original)
+++ trunk/babl/babl-util.c	Tue Apr  1 23:39:28 2008
@@ -16,66 +16,9 @@
  * <http://www.gnu.org/licenses/>.
  */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 #include <math.h>
-#include "babl-memory.h"
 #include "babl-internal.h"
 
-static int list_length (void **list)
-{
-  void **ptr;
-  int    len = 0;
-
-  ptr = list;
-  while (NULL != *ptr)
-    {
-      ptr++;
-      len++;
-    }
-  return len;
-}
-
-void
-babl_add_ptr_to_list (void ***list,
-                      void   *new)
-{
-  int orig_len = 0;
-
-  if (*list)
-    {
-      orig_len = list_length (*list);
-    }
-
-  *list = babl_realloc ((*list),
-                        sizeof (void *) * (orig_len + 2));
-
-  if (!(*list))
-    {
-      babl_fatal ("failed to realloc");
-    }
-
-  (*list)[orig_len]     = new;
-  (*list)[orig_len + 1] = NULL;
-}
-
-void
-babl_list_each (void           **list,
-                BablEachFunction each_fun,
-                void            *user_data)
-{
-  int i;
-
-  if (!list)
-    return;
-  for (i = 0; i < list_length (list); i++)
-    {
-      if (each_fun ((Babl *) list[i], user_data))
-        break;
-    }
-}
-
 #include <sys/time.h>
 #include <time.h>
 

Modified: trunk/babl/babl-util.h
==============================================================================
--- trunk/babl/babl-util.h	(original)
+++ trunk/babl/babl-util.h	Tue Apr  1 23:39:28 2008
@@ -19,16 +19,6 @@
 #ifndef _BABL_UTIL_H
 #define _BABL_UTIL_H
 
-#include <math.h>
-
-void   babl_add_ptr_to_list (void       ***list,
-                             void         *new);
-
-void
-babl_list_each (void             **list,
-                BablEachFunction   each_fun,
-                void              *user_data);
-
 long
 babl_ticks     (void);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]