diff --git a/configure.ac b/configure.ac
index 7614ea8..b36d45a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -835,27 +835,18 @@ AC_CHECK_HEADER(sys/sysinfo.h,
AC_DEFINE(HAVE_SYS_SYSINFO_H, 1,
[Define to 1 if sys/sysinfo.h is available]))
-AC_MSG_CHECKING(for mediaLib 2.3)
-use_mlib25=no
-# Check for a mediaLib 2.3 function since that is what the GTK+ mediaLib
+# Check for a mediaLib 2.5 function since that is what the GTK+ mediaLib
# patch requires.
-AC_CHECK_LIB(mlib, mlib_ImageSetStruct, use_mlib=yes, use_mlib=no)
+AC_MSG_CHECKING(for mediaLib 2.5)
+use_mlib=no
+# Check for a mediaLib 2.5 function since that is what is needed for
+# gdk_rgb_convert integration.
+AC_CHECK_LIB(mlib, mlib_VideoColorRGBint_to_BGRAint, use_mlib=yes, use_mlib=no)
if test $use_mlib = yes; then
AC_DEFINE(USE_MEDIALIB, 1,
- [Define to 1 if medialib is available and should be used])
- MEDIA_LIB=-lmlib
-
- AC_MSG_CHECKING(for mediaLib 2.5)
- # Check for a mediaLib 2.5 function since that is what is needed for
- # gdk_rgb_convert integration.
- AC_CHECK_LIB(mlib, mlib_VideoColorRGBint_to_BGRAint, use_mlib25=yes, use_mlib25=no)
- if test $use_mlib25 = yes; then
- AC_DEFINE(USE_MEDIALIB25, 1,
- [Define to 1 if medialib 2.5 is available])
- fi
+ [Define to 1 if medialib 2.5 is available])
fi
AM_CONDITIONAL(USE_MEDIALIB, test $use_mlib = yes)
-AM_CONDITIONAL(USE_MEDIALIB25, test $use_mlib25 = yes)
# Checks to see if we should compile in MMX support (there will be
# a runtime test when the code is actually run to see if it should
@@ -916,7 +907,7 @@ if test $cross_compiling = yes; then
fi
GDK_PIXBUF_PACKAGES="gmodule-no-export-2.0 gobject-2.0 gio-2.0"
-GDK_PIXBUF_EXTRA_LIBS="$STATIC_LIB_DEPS $MATH_LIB $MEDIA_LIB"
+GDK_PIXBUF_EXTRA_LIBS="$STATIC_LIB_DEPS $MATH_LIB"
GDK_PIXBUF_EXTRA_CFLAGS=
GDK_PIXBUF_DEP_LIBS="`$PKG_CONFIG --libs $GDK_PIXBUF_PACKAGES $PNG_DEP_CFLAGS_PACKAGES` $GDK_PIXBUF_EXTRA_LIBS"
GDK_PIXBUF_DEP_CFLAGS="`$PKG_CONFIG --cflags gthread-2.0 $GDK_PIXBUF_PACKAGES $PNG_DEP_CFLAGS_PACKAGES` $GDK_PIXBUF_EXTRA_CFLAGS"
@@ -146,6 +146,89 @@ static void pixops_medialib_scale (guchar *dest_buf,
typedef struct _mlInterp mlInterp;
+typedef mlib_image* (*ml_ImageSetStruct) (mlib_image *image,
+ mlib_type type,
+ mlib_s32 channels,
+ mlib_s32 width,
+ mlib_s32 height,
+ mlib_s32 stride,
+ const void *data);
+typedef mlib_status (*ml_ImageChannelExtract) (mlib_image *dst,
+ mlib_image *src,
+ mlib_s32 cmask);
+typedef void * (*ml_InterpTableCreate) (mlib_type type,
+ mlib_s32 width,
+ mlib_s32 height,
+ mlib_s32 leftPadding,
+ mlib_s32 topPadding,
+ mlib_s32 subsampleBitsH,
+ mlib_s32 subsampleBitsV,
+ mlib_s32 precisionBits,
+ void * dataH,
+ void * dataV);
+typedef void (*ml_InterpTableDelete) (void *);
+typedef mlib_status (*ml_ZoomTranslateTable)(mlib_image * dst,
+ mlib_image * src,
+ mlib_d64 zoomx,
+ mlib_d64 zoomy,
+ mlib_d64 tx,
+ mlib_d64 ty,
+ void *interp_table,
+ mlib_edge edge);
+typedef mlib_status (*ml_ZoomTranslate) (mlib_image * dst,
+ mlib_image * src,
+ mlib_d64 zoomx,
+ mlib_d64 zoomy,
+ mlib_d64 tx,
+ mlib_d64 ty,
+ mlib_filter filter,
+ mlib_edge edge);
+typedef mlib_status (*ml_ZoomTranslateBlend) (mlib_image *dst,
+ const mlib_image *src,
+ mlib_d64 zoomx,
+ mlib_d64 zoomy,
+ mlib_d64 tx,
+ mlib_d64 ty,
+ mlib_filter filter,
+ mlib_edge edge,
+ mlib_blend blend,
+ mlib_s32 alpha,
+ mlib_s32 cmask);
+typedef mlib_status (*ml_ZoomTranslateTableBlend) (mlib_image *dst,
+ const mlib_image *src,
+ mlib_d64 zoomx,
+ mlib_d64 zoomy,
+ mlib_d64 tx,
+ mlib_d64 ty,
+ const void *table,
+ mlib_edge edge,
+ mlib_blend blend,
+ mlib_s32 cmask);
+typedef void (*ml_ColorRGBint_to_BGRAint) (mlib_u8 *bgra,
+ const mlib_u8 *rgb,
+ const mlib_u8 *a_array,
+ mlib_u8 a_const,
+ mlib_s32 w,
+ mlib_s32 h,
+ mlib_s32 dlb,
+ mlib_s32 slb,
+ mlib_s32 alb);
+
+
+
+static ml_ImageSetStruct _medialib_ImageSetStruct = NULL;
+static ml_ImageChannelExtract _medialib_ImageChannelExtract = NULL;
+static ml_ZoomTranslate _medialib_ZoomTranslate = NULL;
+static ml_InterpTableCreate _medialib_InterpTableCreate = NULL;
+static ml_InterpTableDelete _medialib_InterpTableDelete = NULL;
+static ml_ZoomTranslateTable _medialib_ZoomTranslateTable = NULL;
+static ml_ZoomTranslateBlend _medialib_ZoomTranslateBlend = NULL;
+static ml_ZoomTranslateTableBlend _medialib_ZoomTranslateTableBlend = NULL;
+static ml_ColorRGBint_to_BGRAint _medialib_ColorRGBint_to_BGRAint = NULL;
+
+static gboolean medialib_initialized = FALSE;
+static gboolean use_medialib = TRUE;
+
struct _mlInterp
{
double tx;
@@ -154,82 +237,152 @@ struct _mlInterp
void *interp_table;
};
-static gboolean medialib_initialized = FALSE;
-static gboolean use_medialib = TRUE;
+static void *
+dlopen_mlib (void)
+{
+ void *handle = NULL;
-/*
- * Sun mediaLib(tm) support.
- *
- *
- */
-static void
-_pixops_use_medialib ()
+ if ((handle = dlopen ("libmlib.so.2", RTLD_LAZY)) != NULL)
+ return handle;
+ if ((handle = dlopen ("/usr/lib/libmlib.so.2", RTLD_LAZY)) != NULL)
+ return handle;
+
+ return NULL;
+}
+
+static gboolean
+initialize_mediaLib (void *handle)
+{
+ _medialib_ImageSetStruct = (ml_ImageSetStruct)dlsym (handle,
+ "mlib_ImageSetStruct");
+ _medialib_ImageChannelExtract = (ml_ImageChannelExtract)dlsym (
+ handle,
+ "mlib_ImageChannelExtract");
+ _medialib_ZoomTranslate = (ml_ZoomTranslate)dlsym (handle,
+ "mlib_ImageZoomTranslate");
+
+ _medialib_InterpTableCreate = (ml_InterpTableCreate)dlsym (handle,
+ "mlib_ImageInterpTableCreate");
+ _medialib_InterpTableDelete = (ml_InterpTableDelete)dlsym (handle,
+ "mlib_ImageInterpTableDelete");
+ _medialib_ZoomTranslateTable = (ml_ZoomTranslateTable)dlsym (handle,
+ "mlib_ImageZoomTranslateTable");
+
+ _medialib_ZoomTranslateBlend = (ml_ZoomTranslateBlend)dlsym (handle,
+ "mlib_ImageZoomTranslateBlend");
+ _medialib_ZoomTranslateTableBlend = (ml_ZoomTranslateTableBlend)dlsym (
+ handle,
+ "mlib_ImageZoomTranslateTableBlend");
+
+ if (_medialib_ImageSetStruct == NULL || _medialib_ImageChannelExtract == NULL ||
+ _medialib_ZoomTranslate == NULL || _medialib_InterpTableCreate == NULL ||
+ _medialib_InterpTableDelete == NULL || _medialib_ZoomTranslateTable == NULL ||
+ _medialib_ZoomTranslateBlend == NULL ||
+ _medialib_ZoomTranslateTableBlend == NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
+static gboolean
+mlib_x86_checks (void *handle)
{
+ typedef char * (*ml_version) (void);
+ ml_version medialib_version;
char *mlib_version_string;
- char sys_info[257];
- long count;
+ char *mlib_target_isa;
- medialib_initialized = TRUE;
-
- if (getenv ("GDK_DISABLE_MEDIALIB"))
- {
- use_medialib = FALSE;
- return;
- }
+ medialib_version = (ml_version)dlsym (handle, "mlib_version");
+ if (medialib_version == NULL)
+ return FALSE;
/*
- * The imaging functions we want to use were added in mediaLib version 2.
- * So turn off mediaLib support if the user has an older version.
* mlib_version returns a string in this format:
*
* mediaLib:0210:20011101:v8plusa
* ^^^^^^^^ ^^^^ ^^^^^^^^ ^^^^^^^
* libname vers build ISALIST identifier
* date (in this case sparcv8plus+vis)
- *
+ *
* The first 2 digits of the version are the major version. The 3rd digit
* is the minor version, and the 4th digit is the micro version. So the
- * above string corresponds to version 2.1.0. In the following test we only
- * care about the major version.
+ * above string corresponds to version 2.1.0.
*/
- mlib_version_string = mlib_version ();
+ mlib_version_string = medialib_version ();
+ mlib_target_isa = &mlib_version_string[23];
- count = sysinfo (SI_ARCHITECTURE, &sys_info[0], 257);
+ /*
+ * For x86 processors mediaLib generic C implementation
+ * does not give any performance advantage so disable it.
+ */
+ if (strncmp (mlib_target_isa, "sse", 3) != 0)
+ return FALSE;
+
+ /*
+ * For x86 processors use of libumem conflicts with
+ * mediaLib, so avoid using it.
+ */
+ if (dlsym (RTLD_PROBE, "umem_alloc") != NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
+/*
+ * Sun mediaLib(tm) support.
+ *
+ *
+ */
+gboolean
+_pixops_use_medialib (void)
+{
+ void *medialib_handle = NULL;
+ char sys_info[257];
+ long count;
+ if (medialib_initialized == TRUE)
+ return TRUE;
+
+ if (use_medialib == FALSE)
+ return FALSE;
+
+ if (getenv ("GDK_DISABLE_MEDIALIB"))
+ {
+ use_medialib = FALSE;
+ return FALSE;
+ }
+
+ medialib_handle = dlopen_mlib ();
+ if (medialib_handle == NULL)
+ goto fail;
+
+ count = sysinfo (SI_ARCHITECTURE, &sys_info[0], 257);
+
if (count != -1)
{
if (strcmp (sys_info, "i386") == 0)
{
- char *mlib_target_isa = &mlib_version_string[23];
-
- /*
- * For x86 processors mediaLib generic C implementation
- * does not give any performance advantage so disable it
- */
- if (strncmp (mlib_target_isa, "sse", 3) != 0)
- {
- use_medialib = FALSE;
- return;
- }
-
- /*
- * For x86 processors use of libumem conflicts with
- * mediaLib, so avoid using it.
- */
- if (dlsym (RTLD_PROBE, "umem_alloc") != NULL)
- {
- use_medialib = FALSE;
- return;
- }
+ if (mlib_x86_checks (medialib_handle) == FALSE)
+ goto fail;
}
}
else
{
- /* Failed to get system architecture, disable mediaLib anyway */
- use_medialib = FALSE;
- return;
+ /* Failed to get system architecture, disable mediaLib */
+ goto fail;
}
+
+ if (initialize_mediaLib (medialib_handle) == FALSE)
+ goto fail;
+
+ medialib_initialized = TRUE;
+ return TRUE;
+
+fail:
+ dlclose (medialib_handle);
+ use_medialib = FALSE;
+ return FALSE;
}
#endif
@@ -1850,9 +2003,7 @@ _pixops_composite (guchar *dest_buf,
dest_region_width, dest_region_height, offset_x,
offset_y, scale_x, scale_y,
(PixopsInterpType)interp_type, overall_alpha);
- return;
-#endif
-
+#else
new_dest_buf = dest_buf + dest_y * dest_rowstride + dest_x * dest_channels;
render_x0 = dest_x - offset_x;
render_y0 = dest_y - offset_y;
@@ -1865,6 +2016,7 @@ _pixops_composite (guchar *dest_buf,
src_rowstride, src_channels, src_has_alpha, scale_x,
scale_y, (PixopsInterpType)interp_type,
overall_alpha);
+#endif
}
#ifdef USE_MEDIALIB
@@ -1967,7 +2119,7 @@ medialib_get_interpolation (mlInterp * ml_interp,
ml_interp->po_filter.y.weights[i] *= sqrt_alpha;
}
- ml_interp->interp_table = (void *) mlib_ImageInterpTableCreate (MLIB_DOUBLE,
+ ml_interp->interp_table = (void *) _medialib_InterpTableCreate (MLIB_DOUBLE,
ml_interp->po_filter.x.n, ml_interp->po_filter.y.n, leftPadding,
topPadding, SUBSAMPLE_BITS, SUBSAMPLE_BITS, 8,
ml_interp->po_filter.x.weights, ml_interp->po_filter.y.weights);
@@ -2042,25 +2194,25 @@ pixops_medialib_composite (guchar *dest_buf,
return;
}
- mlib_ImageSetStruct (&img_src, MLIB_BYTE, src_channels,
- src_width, src_height, src_rowstride, src_buf);
+ _medialib_ImageSetStruct (&img_src, MLIB_BYTE, src_channels,
+ src_width, src_height, src_rowstride, src_buf);
if (dest_x == 0 && dest_y == 0 &&
dest_width == dest_region_width &&
dest_height == dest_region_height)
{
- mlib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
- dest_width, dest_height, dest_rowstride,
- dest_buf);
+ _medialib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
+ dest_width, dest_height, dest_rowstride,
+ dest_buf);
}
else
{
mlib_u8 *data = dest_buf + (dest_y * dest_rowstride) +
(dest_x * dest_channels);
- mlib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
- dest_region_width, dest_region_height,
- dest_rowstride, data);
+ _medialib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
+ dest_region_width, dest_region_height,
+ dest_rowstride, data);
}
ml_offset_x = floor (offset_x) - dest_x;
@@ -2070,7 +2222,7 @@ pixops_medialib_composite (guchar *dest_buf,
{
blend = src_has_alpha ? MLIB_BLEND_GTK_SRC_OVER2 : MLIB_BLEND_GTK_SRC;
- mlib_ImageZoomTranslateBlend (&img_dest,
+ _medialib_ZoomTranslateBlend (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2089,7 +2241,7 @@ pixops_medialib_composite (guchar *dest_buf,
if (interp_type == PIXOPS_INTERP_BILINEAR &&
scale_x > 1.0 && scale_y > 1.0)
{
- mlib_ImageZoomTranslateBlend (&img_dest,
+ _medialib_ZoomTranslateBlend (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2108,7 +2260,7 @@ pixops_medialib_composite (guchar *dest_buf,
if (ml_interp.interp_table != NULL)
{
- mlib_ImageZoomTranslateTableBlend (&img_dest,
+ _medialib_ZoomTranslateTableBlend (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2118,7 +2270,7 @@ pixops_medialib_composite (guchar *dest_buf,
MLIB_EDGE_SRC_EXTEND_INDEF,
blend,
1);
- mlib_ImageInterpTableDelete (ml_interp.interp_table);
+ _medialib_InterpTableDelete (ml_interp.interp_table);
}
else
{
@@ -2231,12 +2383,6 @@ _pixops_scale (guchar *dest_buf,
double scale_y,
PixopsInterpType interp_type)
{
- guchar *new_dest_buf;
- int render_x0;
- int render_y0;
- int render_x1;
- int render_y1;
-
#ifdef USE_MEDIALIB
pixops_medialib_scale (dest_buf, dest_width, dest_height, dest_rowstride,
dest_channels, dest_has_alpha, src_buf, src_width,
@@ -2244,8 +2390,12 @@ _pixops_scale (guchar *dest_buf,
src_has_alpha, dest_x, dest_y, dest_region_width,
dest_region_height, offset_x, offset_y, scale_x,
scale_y, (PixopsInterpType)interp_type);
- return;
-#endif
+#else
+ guchar *new_dest_buf;
+ int render_x0;
+ int render_y0;
+ int render_x1;
+ int render_y1;
new_dest_buf = dest_buf + dest_y * dest_rowstride + dest_x * dest_channels;
render_x0 = dest_x - offset_x;
@@ -2258,6 +2408,7 @@ _pixops_scale (guchar *dest_buf,
dest_has_alpha, src_buf, src_width, src_height,
src_rowstride, src_channels, src_has_alpha,
scale_x, scale_y, (PixopsInterpType)interp_type);
+#endif
}
#ifdef USE_MEDIALIB
@@ -2290,15 +2441,6 @@ pixops_medialib_scale (guchar *dest_buf,
if (!medialib_initialized)
_pixops_use_medialib ();
- /*
- * We no longer support mediaLib 2.1 because it has a core dumping problem
- * in the mlib_ImageZoomTranslateTable function that has been corrected in
- * 2.2. Although the mediaLib_zoom function could be used, it does not
- * work properly if the source and destination images have different
- * values for "has_alpha" or "num_channels". The complicated if-logic
- * required to support both versions is not worth supporting
- * mediaLib 2.1 moving forward.
- */
if (!use_medialib)
{
_pixops_scale_real (dest_buf + dest_y * dest_rowstride + dest_x *
@@ -2317,25 +2459,25 @@ pixops_medialib_scale (guchar *dest_buf,
double ml_offset_x, ml_offset_y;
guchar *tmp_buf = NULL;
- mlib_ImageSetStruct (&img_orig_src, MLIB_BYTE, src_channels, src_width,
- src_height, src_rowstride, src_buf);
+ _medialib_ImageSetStruct (&img_orig_src, MLIB_BYTE, src_channels, src_width,
+ src_height, src_rowstride, src_buf);
if (dest_x == 0 && dest_y == 0 &&
dest_width == dest_region_width &&
dest_height == dest_region_height)
{
- mlib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
- dest_width, dest_height, dest_rowstride,
- dest_buf);
+ _medialib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
+ dest_width, dest_height, dest_rowstride,
+ dest_buf);
}
else
{
mlib_u8 *data = dest_buf + (dest_y * dest_rowstride) +
(dest_x * dest_channels);
- mlib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
- dest_region_width, dest_region_height,
- dest_rowstride, data);
+ _medialib_ImageSetStruct (&img_dest, MLIB_BYTE, dest_channels,
+ dest_region_width, dest_region_height,
+ dest_rowstride, data);
}
ml_offset_x = floor (offset_x) - dest_x;
@@ -2373,10 +2515,10 @@ pixops_medialib_scale (guchar *dest_buf,
src_channels = channels;
src_rowstride = rowstride;
- mlib_ImageSetStruct (&img_src, MLIB_BYTE, src_channels,
- src_width, src_height, src_rowstride,
- tmp_buf);
- mlib_ImageChannelExtract (&img_src, &img_orig_src, 0xE);
+ _medialib_ImageSetStruct (&img_src, MLIB_BYTE, src_channels,
+ src_width, src_height, src_rowstride,
+ tmp_buf);
+ _medialib_ImageChannelExtract (&img_src, &img_orig_src, 0xE);
}
}
}
@@ -2385,7 +2527,7 @@ pixops_medialib_scale (guchar *dest_buf,
{
if (src_channels == dest_channels)
{
- mlib_ImageZoomTranslate (&img_dest,
+ _medialib_ZoomTranslate (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2396,7 +2538,7 @@ pixops_medialib_scale (guchar *dest_buf,
}
else
{
- mlib_ImageZoomTranslateBlend (&img_dest,
+ _medialib_ZoomTranslateBlend (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2414,7 +2556,7 @@ pixops_medialib_scale (guchar *dest_buf,
if (interp_type == PIXOPS_INTERP_BILINEAR &&
scale_x > 1.0 && scale_y > 1.0)
{
- mlib_ImageZoomTranslate (&img_dest,
+ _medialib_ZoomTranslate (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2430,7 +2572,7 @@ pixops_medialib_scale (guchar *dest_buf,
if (ml_interp.interp_table != NULL)
{
- mlib_ImageZoomTranslateTable (&img_dest,
+ _medialib_ZoomTranslateTable (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2439,7 +2581,7 @@ pixops_medialib_scale (guchar *dest_buf,
MLIB_EDGE_SRC_EXTEND_INDEF);
- mlib_ImageInterpTableDelete (ml_interp.interp_table);
+ _medialib_InterpTableDelete (ml_interp.interp_table);
}
else
{
@@ -2461,7 +2603,7 @@ pixops_medialib_scale (guchar *dest_buf,
break;
}
- mlib_ImageZoomTranslate (&img_dest,
+ _medialib_ZoomTranslate (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2477,7 +2619,7 @@ pixops_medialib_scale (guchar *dest_buf,
else if (interp_type == PIXOPS_INTERP_BILINEAR &&
scale_x > 1.0 && scale_y > 1.0)
{
- mlib_ImageZoomTranslateBlend (&img_dest,
+ _medialib_ZoomTranslateBlend (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2496,7 +2638,7 @@ pixops_medialib_scale (guchar *dest_buf,
if (ml_interp.interp_table != NULL)
{
- mlib_ImageZoomTranslateTableBlend (&img_dest,
+ _medialib_ZoomTranslateTableBlend (&img_dest,
&img_src,
scale_x,
scale_y,
@@ -2506,7 +2648,7 @@ pixops_medialib_scale (guchar *dest_buf,
MLIB_EDGE_SRC_EXTEND_INDEF,
MLIB_BLEND_GTK_SRC,
1);
- mlib_ImageInterpTableDelete (ml_interp.interp_table);
+ _medialib_InterpTableDelete (ml_interp.interp_table);
}
else
{
@@ -2517,7 +2659,7 @@ pixops_medialib_scale (guchar *dest_buf,
case PIXOPS_INTERP_BILINEAR:
ml_filter = MLIB_BILINEAR;
break;
-
+
case PIXOPS_INTERP_TILES:
ml_filter = MLIB_BILINEAR;
break;
@@ -2527,7 +2669,7 @@ pixops_medialib_scale (guchar *dest_buf,
break;
}
- mlib_ImageZoomTranslate (&img_dest,
+ _medialib_ZoomTranslate (&img_dest,
&img_src,
scale_x,
scale_y,