[babl] carry around user data in BablConversion
- From: Ãyvind KolÃs <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] carry around user data in BablConversion
- Date: Sun, 18 Mar 2012 14:18:09 +0000 (UTC)
commit fc2c0afa0f26a970cfdee28511a676e392415fd9
Author: Ãyvind KolÃs <pippin gimp org>
Date: Sun Mar 18 14:17:04 2012 +0000
carry around user data in BablConversion
Having the user data for relevant conversions directly in BablConversion
permits avoiding branches in the dispatch code. Branches in dispatch code
is evil, thus desinging the rest around avoiding that.
babl/babl-conversion.c | 38 ++++++++++++++++----------------------
babl/babl-conversion.h | 4 ++--
babl/babl-palette.c | 22 ++++++++++++----------
babl/babl-types.h | 6 ++----
4 files changed, 32 insertions(+), 38 deletions(-)
---
diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c
index ccf1b51..b88ab1f 100644
--- a/babl/babl-conversion.c
+++ b/babl/babl-conversion.c
@@ -32,7 +32,8 @@ conversion_new (const char *name,
Babl *destination,
BablFuncLinear linear,
BablFuncPlane plane,
- BablFuncPlanar planar)
+ BablFuncPlanar planar,
+ void *user_data)
{
Babl *babl = NULL;
@@ -103,6 +104,8 @@ conversion_new (const char *name,
babl->conversion.pixels = 0;
babl->conversion.processings = 0;
+ babl->conversion.data = user_data;
+
if (babl->class_type == BABL_CONVERSION_LINEAR &&
BABL (babl->conversion.source)->class_type == BABL_MODEL)
{
@@ -130,6 +133,7 @@ conversion_new (const char *name,
src_format,
dst_format,
"linear", linear,
+ "data", user_data,
NULL);
babl->conversion.error = 0.0;
}
@@ -181,6 +185,7 @@ babl_conversion_new (void *first_arg,
int type = 0;
int got_func = 0;
const char *arg = first_arg;
+ void *user_data= NULL;
Babl *source;
Babl *destination;
@@ -203,6 +208,11 @@ babl_conversion_new (void *first_arg,
id = va_arg (varg, int);
}
+ else if (!strcmp (arg, "data"))
+ {
+ user_data = va_arg (varg, void*);
+ }
+
else if (!strcmp (arg, "linear"))
{
if (got_func++)
@@ -270,7 +280,8 @@ babl_conversion_new (void *first_arg,
babl = babl_db_exist (db, id, name);
}
- babl = conversion_new (name, id, source, destination, linear, plane, planar);
+ babl = conversion_new (name, id, source, destination, linear, plane, planar,
+ user_data);
/* Since there is not an already registered instance by the required
* id/name, inserting newly created class into database.
@@ -288,21 +299,7 @@ babl_conversion_linear_process (BablConversion *conversion,
void *destination,
long n)
{
- void *source_data;
- void *destination_data;
-
- if (conversion->source->instance.class_type == BABL_MODEL)
- {
- source_data = conversion->source->model.data;
- destination_data = conversion->destination->model.data;
- }
- else
- {
- source_data = conversion->source->format.model->data;
- destination_data = conversion->destination->format.model->data;
- }
- return conversion->function.linear (source, destination, n, source_data,
- destination_data);
+ return conversion->function.linear (source, destination, n, conversion->data);
}
static long
@@ -316,8 +313,7 @@ babl_conversion_plane_process (BablConversion *conversion,
return conversion->function.plane (source, destination,
src_pitch, dst_pitch,
n,
- conversion->source->model.data,
- conversion->destination->model.data);
+ conversion->data);
}
static long
@@ -344,8 +340,7 @@ babl_conversion_planar_process (BablConversion *conversion,
dst_data,
destination->pitch,
n,
- conversion->source->model.data,
- conversion->destination->model.data);
+ conversion->data);
}
long
@@ -563,7 +558,6 @@ babl_conversion_error (BablConversion *conversion)
fish_reference->fish.pixels -= test_pixels;
fish_destination_to_rgba->fish.pixels -= 2 * test_pixels;
-
babl_free (source);
babl_free (destination);
babl_free (destination_rgba_double);
diff --git a/babl/babl-conversion.h b/babl/babl-conversion.h
index 336ec57..15e34a1 100644
--- a/babl/babl-conversion.h
+++ b/babl/babl-conversion.h
@@ -33,8 +33,7 @@ typedef long (*BablFuncPlane) (const char *src,
int src_pitch,
int dst_pitch,
long n,
- void *src_model_data,
- void *dst_model_data);
+ void *user_data);
typedef struct
@@ -50,6 +49,7 @@ BablConversion {
BablFuncPlane plane;
BablFuncPlanar planar;
} function;
+ void *data; /* user data */
int processings;
long pixels;
} BablConversion;
diff --git a/babl/babl-palette.c b/babl/babl-palette.c
index afae01e..fc912f1 100644
--- a/babl/babl-palette.c
+++ b/babl/babl-palette.c
@@ -21,6 +21,9 @@
#include <stdio.h>
#include <assert.h>
#include "babl.h"
+#include "babl-memory.h"
+
+void babl_sanity (void);
typedef struct BablPalette
{
@@ -107,7 +110,6 @@ static long
rgba_to_pal (char *src,
char *dst,
long n,
- void *foo,
void *dst_model_data)
{
BablPalette **palptr = dst_model_data;
@@ -150,7 +152,6 @@ static long
rgba_to_pala (char *src,
char *dst,
long n,
- void *foo,
void *dst_model_data)
{
BablPalette **palptr = dst_model_data;
@@ -197,8 +198,7 @@ static long
pal_to_rgba (char *src,
char *dst,
long n,
- void *src_model_data,
- void *foo)
+ void *src_model_data)
{
BablPalette **palptr = src_model_data;
BablPalette *pal = *palptr;
@@ -224,12 +224,11 @@ static long
pal_u8_to_rgba_u8 (char *src,
char *dst,
long n,
- void *src_model_data,
- void *foo)
+ void *src_model_data)
{
BablPalette **palptr = src_model_data;
- assert(palptr);
BablPalette *pal;
+ assert (palptr);
pal = *palptr;
assert(pal);
while (n--)
@@ -253,8 +252,7 @@ static long
pala_to_rgba (char *src,
char *dst,
long n,
- void *src_model_data,
- void *foo)
+ void *src_model_data)
{
BablPalette **palptr = src_model_data;
BablPalette *pal = *palptr;
@@ -288,7 +286,6 @@ void babl_new_palette (const char *name, Babl **format_u8,
{
Babl *model;
Babl *model_no_alpha;
- Babl *f_pal_double;
Babl *f_pal_u8;
Babl *f_pal_a_u8;
BablPalette **palptr;
@@ -341,6 +338,7 @@ void babl_new_palette (const char *name, Babl **format_u8,
model,
babl_model ("RGBA"),
"linear", pala_to_rgba,
+ "data", palptr,
NULL
);
@@ -348,6 +346,7 @@ void babl_new_palette (const char *name, Babl **format_u8,
babl_model ("RGBA"),
model,
"linear", rgba_to_pala,
+ "data", palptr,
NULL
);
@@ -355,6 +354,7 @@ void babl_new_palette (const char *name, Babl **format_u8,
model_no_alpha,
babl_model ("RGBA"),
"linear", pal_to_rgba,
+ "data", palptr,
NULL
);
@@ -362,6 +362,7 @@ void babl_new_palette (const char *name, Babl **format_u8,
babl_model ("RGBA"),
model_no_alpha,
"linear", rgba_to_pal,
+ "data", palptr,
NULL
);
@@ -369,6 +370,7 @@ void babl_new_palette (const char *name, Babl **format_u8,
f_pal_u8,
babl_format ("RGBA u8"),
"linear", pal_u8_to_rgba_u8,
+ "data", palptr,
NULL);
babl_set_user_data (model, palptr);
diff --git a/babl/babl-types.h b/babl/babl-types.h
index ea30b7f..9729e04 100644
--- a/babl/babl-types.h
+++ b/babl/babl-types.h
@@ -36,8 +36,7 @@ typedef union _Babl Babl;
typedef long (*BablFuncLinear) (const char *src,
char *dst,
long n,
- void *src_model_data,
- void *dst_model_data);
+ void *user_data);
/* TypePlanar,ModelPlanar and FormatPlanar */
typedef long (*BablFuncPlanar) (int src_bands,
@@ -47,7 +46,6 @@ typedef long (*BablFuncPlanar) (int src_bands,
char *dst[],
int dst_pitch[],
long n,
- void *src_model_data,
- void *dst_model_data);
+ void *user_data);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]