babl r308 - in trunk: . babl



Author: ok
Date: Tue Apr 15 23:06:32 2008
New Revision: 308
URL: http://svn.gnome.org/viewvc/babl?rev=308&view=rev

Log:
* babl/Makefile.am: removed babl-classes.h
* babl/babl-classes.h: removed and mostly folded into ...
* babl/babl.h:  .. this file, which has been reorganized to contain
each separate class by itself.
* babl/babl-internal.h: simplified code renamed BABL_CLASS_TEMPLATE to
be just BABL_CLASS or BABL_CLASS_MINIMAL.
* babl/babl-fish.c: (babl_fish): do not accept varargs, use use
BABL_CLASS_MINIMAL.
* babl/babl-component.c:
* babl/babl-conversion.c:
* babl/babl-extension.c:
* babl/babl-format.c:
* babl/babl-model.c:
* babl/babl-type.c: use BABL_CLASS instead of BABL_CLASS_TEMPLATE
* babl/babl-hash-table.h:
* babl/babl-list.h:
* babl/babl-db.h: changed include warning since babl-classes doesn't
exist anymore.


Removed:
   trunk/babl/babl-classes.h
Modified:
   trunk/ChangeLog
   trunk/babl/Makefile.am
   trunk/babl/babl-component.c
   trunk/babl/babl-conversion.c
   trunk/babl/babl-db.h
   trunk/babl/babl-extension.c
   trunk/babl/babl-fish.c
   trunk/babl/babl-format.c
   trunk/babl/babl-hash-table.h
   trunk/babl/babl-internal.h
   trunk/babl/babl-list.h
   trunk/babl/babl-model.c
   trunk/babl/babl-type.c
   trunk/babl/babl.h

Modified: trunk/babl/Makefile.am
==============================================================================
--- trunk/babl/Makefile.am	(original)
+++ trunk/babl/Makefile.am	Tue Apr 15 23:06:32 2008
@@ -32,7 +32,6 @@
 	babl-hash-table.c
 
 h_sources  =             		\
-	babl-classes.h			\
 	babl-db.h			\
 	babl-ids.h			\
 	babl-internal.h			\
@@ -44,8 +43,7 @@
 
 library_includedir=$(includedir)/babl-$(BABL_API_VERSION)/babl
 library_include_HEADERS =		\
-	babl.h                          \
-        babl-classes.h
+	babl.h
 
 INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/babl/base
 

Modified: trunk/babl/babl-component.c
==============================================================================
--- trunk/babl/babl-component.c	(original)
+++ trunk/babl/babl-component.c	Tue Apr 15 23:06:32 2008
@@ -127,4 +127,4 @@
   return babl;
 }
 
-BABL_CLASS_TEMPLATE (component)
+BABL_CLASS (component)

Modified: trunk/babl/babl-conversion.c
==============================================================================
--- trunk/babl/babl-conversion.c	(original)
+++ trunk/babl/babl-conversion.c	Tue Apr 15 23:06:32 2008
@@ -555,4 +555,4 @@
   return error;
 }
 
-BABL_CLASS_TEMPLATE (conversion)
+BABL_CLASS (conversion)

Modified: trunk/babl/babl-db.h
==============================================================================
--- trunk/babl/babl-db.h	(original)
+++ trunk/babl/babl-db.h	Tue Apr 15 23:06:32 2008
@@ -19,8 +19,8 @@
 #ifndef _DB_H
 #define _DB_H
 
-#ifndef _BABL_CLASSES_H
-#error  babl-db.h is only to be included after babl-classes.h
+#ifndef _BABL_H
+#error  babl-db.h is only to be included after babl.h
 #endif
 
 #include "babl-list.h"

Modified: trunk/babl/babl-extension.c
==============================================================================
--- trunk/babl/babl-extension.c	(original)
+++ trunk/babl/babl-extension.c	Tue Apr 15 23:06:32 2008
@@ -357,4 +357,4 @@
   return 0;  /* continue iterating */
 }
 
-BABL_CLASS_TEMPLATE (extension)
+BABL_CLASS (extension)

Modified: trunk/babl/babl-fish.c
==============================================================================
--- trunk/babl/babl-fish.c	(original)
+++ trunk/babl/babl-fish.c	Tue Apr 15 23:06:32 2008
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <stdarg.h>
 
+
 typedef struct _BablFindFish BablFindFish;
 
 typedef struct _BablFindFish
@@ -152,8 +153,7 @@
 
 Babl *
 babl_fish (const void *source,
-           const void *destination,
-           ...)
+           const void *destination)
 {
   const Babl *source_format      = NULL;
   const Babl *destination_format = NULL;
@@ -323,6 +323,8 @@
   return ret;
 }
 
+
+
 static int
 each_babl_fish_destroy (Babl *babl,
                         void *data)
@@ -333,6 +335,4 @@
   return 0;  /* continue iterating */
 }
 
-BABL_DEFINE_INIT (fish)
-BABL_DEFINE_DESTROY (fish)
-BABL_DEFINE_EACH (fish)
+BABL_CLASS_MINIMAL (fish);

Modified: trunk/babl/babl-format.c
==============================================================================
--- trunk/babl/babl-format.c	(original)
+++ trunk/babl/babl-format.c	Tue Apr 15 23:06:32 2008
@@ -435,4 +435,4 @@
   return loss;
 }
 
-BABL_CLASS_TEMPLATE (format)
+BABL_CLASS (format)

Modified: trunk/babl/babl-hash-table.h
==============================================================================
--- trunk/babl/babl-hash-table.h	(original)
+++ trunk/babl/babl-hash-table.h	Tue Apr 15 23:06:32 2008
@@ -19,8 +19,8 @@
 #ifndef _BABL_HASH_TABLE_H
 #define _BABL_HASH_TABLE_H
 
-#ifndef _BABL_CLASSES_H
-#error  babl-hash-table.h is only to be included after babl-classes.h
+#ifndef _BABL_H
+#error  babl-hash-table.h is only to be included after babl.h
 #endif
 
 

Modified: trunk/babl/babl-internal.h
==============================================================================
--- trunk/babl/babl-internal.h	(original)
+++ trunk/babl/babl-internal.h	Tue Apr 15 23:06:32 2008
@@ -32,8 +32,6 @@
 #include <string.h>
 #include "assert.h"
 
-
-#include "babl-classes.h"
 #undef  _BABL_INTERNAL_H
 #include "babl.h"
 #define _BABL_INTERNAL_H
@@ -177,49 +175,10 @@
 
 extern int   babl_hmpf_on_name_lookups;
 
-const char  *babl_class_name     (BablClassType klass);
+const char  *babl_class_name       (BablClassType klass);
 void         babl_internal_init    (void);
 void         babl_internal_destroy (void);
 
-#define BABL_DEFINE_EACH(type_name)                           \
-void                                                          \
-babl_##type_name##_each (BablEachFunction  each_fun,          \
-                         void             *user_data)         \
-{                                                             \
-  babl_db_each (db, each_fun, user_data);                     \
-}                                                             \
-
-#define BABL_DEFINE_LOOKUP_BY_ID(type_name)                   \
-Babl *                                                        \
-babl_##type_name##_id (int id)                                \
-{                                                             \
-  Babl *babl;                                                 \
-  babl = babl_db_exist_by_id (db, id);                        \
-  if (!babl)                                                  \
-    {                                                         \
-      babl_fatal ("%s(%i): not found", __func__, id);         \
-    }                                                         \
-  return babl;                                                \
-}
-
-#define BABL_DEFINE_LOOKUP_BY_NAME(type_name)                   \
-Babl *                                                          \
-babl_##type_name (const char *name)                             \
-{                                                               \
-  Babl *babl;                                                   \
-                                                                \
-  if (babl_hmpf_on_name_lookups)                                \
-    {                                                           \
-      babl_log ("%s(\"%s\"): hmpf!", __func__, name);           \
-    }                                                           \
-  babl = babl_db_exist_by_name (db, name);                      \
-                                                                \
-  if (!babl)                                                    \
-    {                                                           \
-      babl_fatal ("%s(\"%s\"): not found", __func__, name);     \
-    }                                                           \
-  return babl;                                                  \
-}
 
 #ifndef BABL_INIT_HOOK
 #define BABL_INIT_HOOK
@@ -234,34 +193,70 @@
 #define BABL_DESTROY_PRE_HOOK
 #endif
 
-#define BABL_DEFINE_INIT(type_name)                           \
-                                                              \
-                                                              \
+/* this template is expanded in the files including babl-internal.h,
+ * generating code, the declarations for these functions are found in
+ * the BABL_CLASS expansions done in babl.h as well, thus babl.h needs
+ * to be kept in sync with the C files.
+ */
+
+#define BABL_CLASS_MINIMAL(klass)                             \
 void                                                          \
-babl_##type_name##_init (void)                                \
+babl_##klass##_init (void)                                    \
 {                                                             \
   BABL_PRE_INIT_HOOK;                                         \
   if (!db)                                                    \
     db=babl_db_init ();                                       \
   BABL_INIT_HOOK;                                             \
-}
-
-#define BABL_DEFINE_DESTROY(type_name)                        \
+}                                                             \
+                                                              \
 void                                                          \
-babl_##type_name##_destroy (void)                             \
+babl_##klass##_destroy (void)                                 \
 {                                                             \
   BABL_DESTROY_PRE_HOOK;                                      \
-  babl_db_each (db,each_babl_##type_name##_destroy, NULL);    \
+  babl_db_each (db,each_babl_##klass##_destroy, NULL);        \
   babl_db_destroy (db);                                       \
   BABL_DESTROY_HOOK;                                          \
-}
+}                                                             \
+                                                              \
+void                                                          \
+babl_##klass##_each (BablEachFunction  each_fun,              \
+                     void             *user_data)             \
+{                                                             \
+  babl_db_each (db, each_fun, user_data);                     \
+}                                                             \
 
-#define BABL_CLASS_TEMPLATE(type_name)                        \
-BABL_DEFINE_INIT           (type_name)                        \
-BABL_DEFINE_DESTROY        (type_name)                        \
-BABL_DEFINE_LOOKUP_BY_NAME (type_name)                        \
-BABL_DEFINE_EACH           (type_name)                        \
-BABL_DEFINE_LOOKUP_BY_ID   (type_name)
+#define BABL_CLASS(klass)                                     \
+BABL_CLASS_MINIMAL(klass)                                     \
+                                                              \
+Babl *                                                        \
+babl_##klass (const char *name)                               \
+{                                                             \
+  Babl *babl;                                                 \
+                                                              \
+  if (babl_hmpf_on_name_lookups)                              \
+    {                                                         \
+      babl_log ("%s(\"%s\"): hmpf!", __func__, name);         \
+    }                                                         \
+  babl = babl_db_exist_by_name (db, name);                    \
+                                                              \
+  if (!babl)                                                  \
+    {                                                         \
+      babl_fatal ("%s(\"%s\"): not found", __func__, name);   \
+    }                                                         \
+  return babl;                                                \
+}                                                             \
+                                                              \
+Babl *                                                        \
+babl_##klass##_id (int id)                                    \
+{                                                             \
+  Babl *babl;                                                 \
+  babl = babl_db_exist_by_id (db, id);                        \
+  if (!babl)                                                  \
+    {                                                         \
+      babl_fatal ("%s(%i): not found", __func__, id);         \
+    }                                                         \
+  return babl;                                                \
+}
 
 #define BABL(obj)  ((Babl*)(obj))
 

Modified: trunk/babl/babl-list.h
==============================================================================
--- trunk/babl/babl-list.h	(original)
+++ trunk/babl/babl-list.h	Tue Apr 15 23:06:32 2008
@@ -19,11 +19,11 @@
 #ifndef _BABL_LIST_H
 #define _BABL_LIST_H
 
-#ifndef _BABL_CLASSES_H
-/* babl-classes.h contains forward declaration
+#ifndef _BABL_H
+/* babl.h contains forward declaration
  * typedef struct _BablList BablList;
  */
-#error  babl-list.h is only to be included after babl-classes.h
+#error  babl-list.h is only to be included after babl.h
 #endif
 
 

Modified: trunk/babl/babl-model.c
==============================================================================
--- trunk/babl/babl-model.c	(original)
+++ trunk/babl/babl-model.c	Tue Apr 15 23:06:32 2008
@@ -327,4 +327,4 @@
   return symmetric;
 }
 
-BABL_CLASS_TEMPLATE (model)
+BABL_CLASS (model)

Modified: trunk/babl/babl-type.c
==============================================================================
--- trunk/babl/babl-type.c	(original)
+++ trunk/babl/babl-type.c	Tue Apr 15 23:06:32 2008
@@ -252,4 +252,4 @@
   return is_symmetrical;
 }
 
-BABL_CLASS_TEMPLATE (type)
+BABL_CLASS (type)

Modified: trunk/babl/babl.h
==============================================================================
--- trunk/babl/babl.h	(original)
+++ trunk/babl/babl.h	Tue Apr 15 23:06:32 2008
@@ -24,14 +24,54 @@
 #ifndef _BABL_H
 #define _BABL_H
 
-#include "babl-classes.h"
+#include <stdlib.h>
+
 #ifdef _BABL_INTERNAL_H
 #error babl.h included after babl-internal.h
 #endif
-#ifndef _BABL_CLASSES_H
-#define Babl  void
+
+typedef union _Babl Babl;
+/* Union used for quick convenient access to any field of any BablInstance */
+
+typedef struct _BablList BablList;
+
+#ifndef BABL_HARD_MAX_PATH_LENGTH
+#define BABL_HARD_MAX_PATH_LENGTH 16
 #endif
 
+/* magic number used at the start of all babl objects, used to do
+ * differentiation in polymorphic functions. (as well as manual
+ * type check assertions).
+ */
+#define BABL_MAGIC   0xbAb100
+
+enum {
+  BABL_INSTANCE = BABL_MAGIC,
+  BABL_TYPE,
+  BABL_TYPE_INTEGER,
+  BABL_TYPE_FLOAT,
+  BABL_SAMPLING,
+  BABL_COMPONENT,
+  BABL_MODEL,
+  BABL_FORMAT,
+
+  BABL_CONVERSION,
+  BABL_CONVERSION_LINEAR,
+  BABL_CONVERSION_PLANE,
+  BABL_CONVERSION_PLANAR,
+
+  BABL_FISH,
+  BABL_FISH_REFERENCE,
+  BABL_FISH_SIMPLE,
+  BABL_FISH_PATH,
+  BABL_IMAGE,
+
+  BABL_EXTENSION,
+
+  BABL_SKY
+};
+typedef unsigned int BablClassType;
+
 /** Initialize the babl library */
 void   babl_init       (void);
 
@@ -47,70 +87,62 @@
 #define BABL_ARG_NULL_TERMINATED
 #endif
 
-#define BABL_CLASS_NO_NAME(type_name)                            \
-                                                                 \
-void   babl_##type_name##_init    (void);                        \
-void   babl_##type_name##_destroy (void);                        \
-Babl * babl_##type_name##_id      (int id);                      \
-void   babl_##type_name##_each    (BablEachFunction  each_fun,   \
-                                   void             *user_data);
-
-#define BABL_CLASS(type_name)                                    \
-                                                                 \
-BABL_CLASS_NO_NAME (type_name)                                   \
-Babl * babl_##type_name           (const char       *name);      \
-Babl * babl_##type_name##_new     (void             *first_arg,  \
-                                   ...) BABL_ARG_NULL_TERMINATED;
-
 typedef int  (*BablEachFunction) (Babl *entry,
                                   void *data);
 
-
-/****************************************************************/
-/* BablFish */                           BABL_CLASS_NO_NAME (fish)
-/*  Create a babl fish capable of converting from source_format to
- *  destination_format, source and destination can be
- *  either strings with the names of the formats or BablFormat objects.
+/* All Classes in babl have common functionality like the ability
+ * to be iterated over, common functionality is defined through these
+ * macros.
  */
-Babl * babl_fish       (const void *source_format,
-                        const void *destination_format,
-                        ...);
+#define BABL_CLASS(klass)                                    \
+                                                             \
+void   babl_##klass##_init    (void);                        \
+void   babl_##klass##_destroy (void);                        \
+Babl * babl_##klass##_id      (int id);                      \
+void   babl_##klass##_each    (BablEachFunction  each_fun,   \
+                              void             *user_data)
+
+/* creates a class that has a specific name connected to it, that
+ * also allows defining a new instance. These classes share common
+ * functionality with the non_name classes but have two extra methods,
+ * the means to lookup by name, as well as to create new named objects
+ * that later can be looked up.
+ */
+#define BABL_NAMED_CLASS(klass)                              \
+                                                             \
+BABL_CLASS (klass);                                          \
+Babl * babl_##klass           (const char       *name);      \
+Babl * babl_##klass##_new     (void             *first_arg,  \
+                              ...) BABL_ARG_NULL_TERMINATED
 
-/** Process n pixels from source to destination using babl_fish,
- *  returns number of pixels converted.
+
+
+/* common header for any item inserted into database, the actual
+ * implementation of babl-instance is in babl-internal
  */
-long   babl_process    (Babl *babl_fish,
-                        void *source,
-                        void *destination,
-                        long  n);
+typedef struct
+{
+  BablClassType  class_type;
+  int            id;      /*< a numerical id, look at 'babl-ids.h' for the reserved
+                              ones */
+  void          *creator;
+  char          *name;    /*< the name this type exists under         */
+} BablInstance;
 
-/****************************************************************/
-/* BablImage */                         BABL_CLASS_NO_NAME (image)
-/*
- * Babl images can be used for planar buffers instead of linear buffers for
- * babl_process(), BablImages are still experimental, for now BablImages can be
- * passed to babl_process, two different babl_process() functions will be
- * needed for this since the polymorphism cannot be trusted to work on linear
- * buffers.
+/**
+ * babl_name:
  *
- * Babl * babl_image (BablComponent *component1,
- *                    void          *data,
- *                    int            pitch,
- *                    int            stride,
- *                   [BablComponent *component1,
- *                    void          *data,
- *                    int            pitch,
- *                    int            stride,
- *                    ...]
- *                    NULL);
+ * Return a string decsribing a BablInstance, might work better than
+ * babl->instance.name when a good human readable name is desired.
+ *
+ * Returns: a name describing the instance.
  */
-Babl * babl_image      (void *first_component,
-                        ...) BABL_ARG_NULL_TERMINATED;
-
-
+const char *babl_name       (const Babl *babl);
+void        babl_introspect (Babl *babl); /* introspect a given BablObject     */
 
 /****************************************************************/
-/* BablType */                                   BABL_CLASS (type)
+/* BablType */
+BABL_NAMED_CLASS (type);
 /*
  * A data type that babl can have in it's buffers, requires
  * conversions to and from "double" to be registered before
@@ -122,18 +154,85 @@
  *                         ["max_val", double max_val,]
  *                         NULL);
  */
+Babl *babl_type_id     (int id);
+void  babl_type_each   (BablEachFunction  each_fun,
+                        void             *user_data);
+Babl * babl_type       (const char       *name);
+Babl * babl_type_new   (void             *first_arg,
+                        ...) BABL_ARG_NULL_TERMINATED;
+
+typedef struct
+{
+  BablInstance     instance;
+  BablList         *from_list;
+  int              bits;  /*< number of bits used to represent the data type
+                            (initially restricted to a multiple of 8) */
+  double           min_val;
+  double           max_val;
+} BablType;
+
+typedef struct
+{
+  BablType          type;
+  int               is_signed;
+  long              max;
+  long              min;
+} BablTypeInteger;
+
+typedef struct
+{
+  BablType type;
+  /* sign
+   * biased_exponent
+   * mantissa */
+} BablTypeFloat;
+
+
+/****************************************************************/
+/* BablSampling */
+BABL_CLASS (sampling);
+/**/
+Babl * babl_sampling       (int horizontal,
+                            int vertical);
+Babl *babl_sampling_id     (int id);
+void  babl_sampling_each   (BablEachFunction  each_fun,
+                            void             *user_data);
+typedef struct
+{
+  BablInstance     instance;
+  BablList         *from_list;
+  int              horizontal;
+  int              vertical;
+  char             name[4];
+} BablSampling;
 
 
 /****************************************************************/
-/* BablComponent */                         BABL_CLASS (component)
+/* BablComponent */
+BABL_NAMED_CLASS (component);
 /*
  * Babl * babl_component_new (const char *name,
  *                            NULL);
  */
+Babl *babl_component_id     (int id);
+void  babl_component_each   (BablEachFunction  each_fun,
+                        void             *user_data);
+Babl * babl_component       (const char       *name);
+Babl * babl_component_new   (void             *first_arg,
+                        ...) BABL_ARG_NULL_TERMINATED;
+
+typedef struct
+{
+  BablInstance     instance;
+  int              luma;
+  int              chroma;
+  int              alpha;
+} BablComponent;
 
 
 /****************************************************************/
-/* BablModel */                                 BABL_CLASS (model)
+/* BablModel */
+BABL_NAMED_CLASS (model);
 /*
  * Babl * babl_model_new (["name", const char *name,]
  *                        BablComponent *component1,
@@ -144,15 +243,26 @@
  * name of all the involved components.
  *
  */
+Babl *babl_model_id     (int id);
+void  babl_model_each   (BablEachFunction  each_fun,
+                        void             *user_data);
+Babl * babl_model       (const char       *name);
+Babl * babl_model_new   (void             *first_arg,
+                        ...) BABL_ARG_NULL_TERMINATED;
+
+typedef struct
+{
+  BablInstance     instance;
+  BablList         *from_list;
+  int              components;
+  BablComponent  **component;
+  BablType       **type; /*< must be doubles, used here for convenience in code */
+} BablModel;
 
-/****************************************************************/
-/* BablSampling */                   BABL_CLASS_NO_NAME (sampling)
-/**/
-Babl * babl_sampling   (int horizontal,
-                        int vertical);
 
 /****************************************************************/
-/* BablFormat */                               BABL_CLASS (format)
+/* BablFormat */
+BABL_NAMED_CLASS (format);
 /*
  * Babl * babl_format_new (["name", const char *name,]
  *                          BablModel          *model,
@@ -170,16 +280,78 @@
  * components as well. If no name is provided a (long) descriptive
  * name is used.
  */
+Babl *babl_format_id     (int id);
+void  babl_format_each   (BablEachFunction  each_fun,
+                        void             *user_data);
+Babl * babl_format       (const char       *name);
+Babl * babl_format_new   (void             *first_arg,
+                        ...) BABL_ARG_NULL_TERMINATED;
+
+typedef struct
+{
+  BablInstance     instance;
+  BablList         *from_list;
+  int              components;
+  BablComponent  **component;
+  BablType       **type;
+  void            *image_template; /* image template for use with 
+                                       linear (non-planer) images */
+
+  BablSampling   **sampling;
+  BablModel       *model;
+  int              bytes_per_pixel;
+  int              planar;
+  double           loss; /*< average relative error when converting
+                             from and to RGBA double */
+  int              visited; /* for convenience in code while searching 
+                               for conversion paths */
+} BablFormat;
 
 
 /****************************************************************/
-/* BablExtension */                         BABL_CLASS (extension)
+/* BablImage */
+BABL_CLASS (image);
 /*
- * BablExtension objects are only used internally in babl.
+ * Babl images can be used for planar buffers instead of linear buffers for
+ * babl_process(), BablImages are still experimental, for now BablImages can be
+ * passed to babl_process, two different babl_process() functions will be
+ * needed for this since the polymorphism cannot be trusted to work on linear
+ * buffers that originate outside babl's control.
+ * 
+ * Babl * babl_image (BablComponent *component1,
+ *                    void          *data,
+ *                    int            pitch,
+ *                    int            stride,
+ *                   [BablComponent *component1,
+ *                    void          *data,
+ *                    int            pitch,
+ *                    int            stride,
+ *                    ...]
+ *                    NULL);
  */
+Babl * babl_image      (void *first_component,
+                        ...) BABL_ARG_NULL_TERMINATED;
+Babl *babl_image_id     (int id);
+void  babl_image_each   (BablEachFunction  each_fun,
+                        void             *user_data);
+typedef struct
+{
+  BablInstance    instance;
+  BablFormat     *format;    /*< (if known) */
+  BablModel      *model;     /*< (always known) */
+  int             components;
+  BablComponent **component;
+  BablType      **type;
+  BablSampling  **sampling;
+  char          **data;
+  int            *pitch;
+  int            *stride;
+} BablImage;
+
 
 /****************************************************************/
-/* BablConversion */                       BABL_CLASS (conversion)
+/* BablConversion */
+BABL_NAMED_CLASS (conversion);
 /*
  * Babl * babl_conversion_new (<BablFormat *source, BablFormat *destination|
  *                              BablModel  *source, BablModel  *destination|
@@ -187,12 +359,185 @@
  *                             <"linear"|"planar">, BablConversionFunc conv_func,
  *                              NULL);
  */
+Babl *babl_conversion_id     (int id);
+void  babl_conversion_each   (BablEachFunction  each_fun,
+                        void             *user_data);
+Babl * babl_conversion       (const char       *name);
+Babl * babl_conversion_new   (void             *first_arg,
+                        ...) BABL_ARG_NULL_TERMINATED;
+
+/* Type and Format */
+typedef long (*BablFuncLinear)    (char  *src,
+                                   char  *dst,
+                                   long   n);
+
+/* Signature of functions registered for reference type
+ * conversions,
+ */
+typedef long (*BablFuncPlane)     (char  *src,
+                                   char  *dst,
+                                   int    src_pitch,
+                                   int    dst_pitch,
+                                   long   n);
+
+/* TypePlanar,ModelPlanar and FormatPlanar */
+typedef long (*BablFuncPlanar)    (int    src_bands,
+                                   char  *src[],
+                                   int    src_pitch[],
+                                   int    dst_bands,
+                                   char  *dst[],
+                                   int    dst_pitch[],
+                                   long   n);
+
+typedef struct
+BablConversion {
+  BablInstance           instance;
+  const Babl            *source;
+  const Babl            *destination;
+  long                   cost;
+  double                 error;
+  union
+    {
+      BablFuncLinear     linear;
+      BablFuncPlane      plane;
+      BablFuncPlanar     planar;
+    } function;
+  int                    processings;
+  long                   pixels;
+} BablConversion;
+
+
+/****************************************************************/
+/* BablFish */
+BABL_CLASS (fish);
+/*  Create a babl fish capable of converting from source_format to
+ *  destination_format, source and destination can be
+ *  either strings with the names of the formats or BablFormat objects.
+ */
+Babl * babl_fish       (const void *source_format,
+                        const void *destination_format);
+
+/** Process n pixels from source to destination using babl_fish,
+ *  returns number of pixels converted. 
+ */
+long   babl_process    (Babl *babl_fish,
+                        void *source,
+                        void *destination,
+                        long  n);
+
+Babl *babl_fish_id     (int id);
+void  babl_fish_each   (BablEachFunction  each_fun,
+                        void             *user_data);
+
+/* BablFish, common base class for various fishes.
+ */
+typedef struct
+{
+  BablInstance    instance;
+  const Babl     *source;
+  const Babl     *destination;
+
+  double          error;    /* the amount of noise introduced by the fish */
+
+  /* instrumentation */
+  int             processings; /* number of times the fish has been used */
+  long            pixels;      /* number of pixels translates */
+  long            usecs;       /* usecs spent within this fish */
+} BablFish;
+
+/* BablFishSimple is the simplest type of fish, wrapping a single
+ * conversion function, (note this might not be the optimal chosen
+ * conversion even if it exists)
+ *
+ * TODO: exterminate
+ */
+typedef struct
+{
+  BablFish         fish;
+  BablConversion  *conversion;
+} BablFishSimple;
+
+
+/* BablFishPath is a combination of registered conversions, both
+ * from the reference types / model conversions, and optimized format to
+ * format conversion.
+ *
+ * This is the most advanced scheduled species of fish, some future
+ * version of babl might even be evovling path fishes in a background
+ * thread, based on the fish instrumentation. For this to work in a future
+ * version transmogrification between the fish classes would be used.
+ */
+typedef struct
+{
+  BablFish         fish;
+  double           cost;   /* number of  ticks *10 + chain_length */
+  double           loss;   /* error introduced */
+  BablList         *conversion_list;
+} BablFishPath;
+
+/* BablFishReference
+ *
+ * A BablFishReference is not intended to be fast, thus the algorithm
+ * encoded can use a multi stage approach, based on the knowledge babl
+ * has encoded in the pixel formats.
+ *
+ * One of the contributions that would be welcome are new fish factories.
+ *
+ * TODO:
+ *   * make optimal use of a single allocation containing enough space
+ *     for the maximum amount of memory needed in two adjecant buffers
+ *     at any time.
+ */
+typedef struct
+{
+  BablFish         fish;
+} BablFishReference;
+
+
+/****************************************************************/
+/* BablExtension */
+BABL_NAMED_CLASS (extension);
+/*
+ * BablExtension objects are only used internally in babl.
+ */
+Babl *babl_extension_id     (int id);
+void  babl_extension_each   (BablEachFunction  each_fun,
+                        void             *user_data);
+Babl * babl_extension       (const char       *name);
+Babl * babl_extension_new   (void             *first_arg,
+                        ...) BABL_ARG_NULL_TERMINATED;
+
+typedef struct
+{
+  BablInstance   instance; /* path to .so / .dll is stored in instance name */
+  void          *dl_handle;
+  void         (*destroy) (void);
+} BablExtension;
 
 
-const char *babl_name (const Babl *babl);  /* returns the name of a babl object */
-void   babl_introspect (Babl *babl); /* introspect a given BablObject     */
+
+/* This union can be used for convenient access to any field without the need
+ * to case if the variable already is of the type Babl *
+ */
+typedef union _Babl
+{
+  BablClassType     class_type;
+  BablInstance      instance;
+  BablType          type;
+  BablSampling      sampling;
+  BablComponent     component;
+  BablModel         model;
+  BablFormat        format;
+  BablConversion    conversion;
+  BablImage         image;
+  BablFish          fish;
+  BablFishReference fish_reference;
+  BablFishSimple    fish_simple;
+  BablFishPath      fish_path;
+  BablExtension     extension;
+} _Babl;
 
 #undef BABL_CLASS
-#include <stdlib.h>
+#undef BABL_NAMED_CLASS
 
 #endif



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