1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 04:20:27 +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

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;
}