1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-02 14:15:46 +01:00

wrlib: added support for imagemagick third-party lib

It uses to provide some missing common image format
like SVG, BMP, PICT, ...
This commit is contained in:
David Maciejak
2014-03-08 11:02:08 +08:00
committed by Carlos R. Mafra
parent b6ffe90ec4
commit bb69682b88
10 changed files with 183 additions and 2 deletions

View File

@@ -64,6 +64,10 @@ if USE_WEBP
libwraster_la_SOURCES += load_webp.c
endif
if USE_MAGICK
libwraster_la_SOURCES += load_magick.c
endif
AM_CPPFLAGS = $(DFLAGS) @HEADER_SEARCH_PATH@
libwraster_la_LIBADD = @LIBRARY_SEARCH_PATH@ @GFXLIBS@ @XLIBS@ @LIBXMU@ -lm

View File

@@ -39,12 +39,13 @@ typedef enum {
IM_PPM = 4,
IM_JPEG = 5,
IM_GIF = 6,
IM_WEBP = 7
IM_WEBP = 7,
IM_MAGICK = 8
} WRImgFormat;
/* How many image types we have. */
/* Increase this when adding new image types! */
#define IM_TYPES 7
#define IM_TYPES 8
/*
* Function for Loading in a specific format
@@ -73,6 +74,10 @@ RImage *RLoadGIF(const char *file, int index);
RImage *RLoadWEBP(const char *file);
#endif
#ifdef USE_MAGICK
RImage *RLoadMagick(const char *file_name);
#endif
/*
* Function for Saving in a specific format
*/

View File

@@ -72,6 +72,7 @@ LIBWRASTER3
RRotateImage;
RSaveImage;
RScaleImage;
RShutdown;
RSmoothScaleImage;
RSupportedFileFormats;

View File

@@ -103,6 +103,13 @@ char **RSupportedFileFormats(void)
return tmp;
}
/* cleaning third-party libs at shutdown */
void RShutdown() {
#ifdef USE_MAGICK
MagickWandTerminus();
#endif
}
static void init_cache(void)
{
char *tmp;
@@ -165,8 +172,16 @@ RImage *RLoadImage(RContext * context, const char *file, int index)
return NULL;
case IM_UNKNOWN:
#ifdef USE_MAGICK
/* generic file format support using ImageMagick
* BMP, PCX, PICT, SVG, ...
*/
image = RLoadMagick(file);
break;
#else
RErrorCode = RERR_BADFORMAT;
return NULL;
#endif
case IM_XPM:
image = RLoadXPM(context, file);

88
wrlib/load_magick.c Normal file
View File

@@ -0,0 +1,88 @@
/* load_magick.c - load image file using ImageMagick
*
* Raster graphics library
*
* Copyright (c) 2014 Window Maker Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "config.h"
#include <X11/Xlib.h>
#include <wand/magick_wand.h>
#include "wraster.h"
#include "imgformat.h"
RImage *RLoadMagick(const char *file_name)
{
RImage *image = NULL;
unsigned char *ptr;
unsigned long w,h;
MagickWand *m_wand = NULL;
MagickBooleanType mrc;
MagickBooleanType hasAlfa;
PixelWand *bg_wand = NULL;
MagickWandGenesis();
/* Create a wand */
m_wand = NewMagickWand();
/* set the default background as transparent */
bg_wand = NewPixelWand();
PixelSetColor(bg_wand, "none");
MagickSetBackgroundColor(m_wand, bg_wand);
/* Read the input image */
if (!MagickReadImage(m_wand, file_name)) {
RErrorCode = RERR_BADIMAGEFILE;
goto bye;
}
w = MagickGetImageWidth(m_wand);
h = MagickGetImageHeight(m_wand);
hasAlfa = MagickGetImageAlphaChannel(m_wand);
image = RCreateImage(w, h, (unsigned int) hasAlfa);
if (!image) {
RErrorCode = RERR_NOMEMORY;
goto bye;
}
ptr = image->data;
if (hasAlfa == MagickTrue)
mrc = MagickExportImagePixels(m_wand, 0, 0, (size_t)w, (size_t)h, "RGBA", CharPixel, ptr);
else
mrc = MagickExportImagePixels(m_wand, 0, 0, (size_t)w, (size_t)h, "RGB", CharPixel, ptr);
if (mrc == MagickFalse) {
RErrorCode = RERR_BADIMAGEFILE;
RReleaseImage(image);
goto bye;
}
bye:
/* Tidy up */
DestroyPixelWand(bg_wand);
MagickClearException(m_wand);
m_wand = DestroyMagickWand(m_wand);
return image;
}

View File

@@ -431,7 +431,11 @@ RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor **colors,
RImage *RRenderInterwovenGradient(unsigned width, unsigned height,
RColor colors1[2], int thickness1,
RColor colors2[2], int thickness2);
/*
* Cleaning
*/
void RShutdown();
/*
* Convertion into X Pixmaps