1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
////////////////////////////////////////////////////////
//
// GEM - Graphics Environment for Multimedia
//
// zmoelnig@iem.at
//
// Implementation file
//
// Copyright (c) 1997-1999 Mark Danks.
// Copyright (c) Gnther Geiger.
// Copyright (c) 2001-2011 IOhannes m zmlnig. forum::fr::umlute. IEM. zmoelnig@iem.at
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
//
/////////////////////////////////////////////////////////
/* this implements ImageMagick loading/saving using Magick++ */
#include "imageMAGICK.h"
#include "Gem/RTE.h"
#include "Gem/GemGL.h"
#include <Magick++.h>
using namespace gem::plugins;
namespace MagickCore {};
using namespace MagickCore;
namespace MagickLib {};
using namespace MagickLib;
/////////////////////////////////////////////////////////
// really open the file ! (OS dependent)
//
/////////////////////////////////////////////////////////
bool imageMAGICK :: load(std::string filename, imageStruct&result,
gem::Properties&props)
{
Magick::Image image;
try {
// Read a file into image object
try {
image.read( filename );
} catch (Magick::Warning&e) {
verbose(0, "[GEM:imageMAGICK] loading problem: %s", e.what());
}
result.xsize=static_cast<GLint>(image.columns());
result.ysize=static_cast<GLint>(image.rows());
result.setCsizeByFormat(GL_RGBA_GEM);
result.reallocate();
result.upsidedown=true;
try {
image.write(0,0,result.xsize,result.ysize,
#ifdef __APPLE__
"ARGB",
#else
"RGBA",
#endif
Magick::CharPixel,
reinterpret_cast<void*>(result.data));
} catch (Magick::Warning&e) {
verbose(0, "[GEM:imageMAGICK] decoding problem: %s", e.what());
}
} catch (Magick::Exception&e) {
verbose(0, "[GEM:imageMAGICK] loading image failed with: %s", e.what());
return false;
}
return true;
}
bool imageMAGICK::save(const imageStruct&image, const std::string&filename,
const std::string&mimetype, const gem::Properties&props)
{
imageStruct*img=const_cast<imageStruct*>(&image);
imageStruct*pImage=img;
std::string cs;
switch(img->format) {
case GL_LUMINANCE:
cs="K";
break;
case GL_RGBA:
#ifdef __APPLE__
cs="ABGR";
#else
cs="RGBA";
#endif
break;
/* coverity[unterminated_default] */
default:
pImage=new imageStruct();
pImage->convertFrom(img, GL_RGB);
case GL_RGB:
cs="RGB";
break;
case GL_BGRA_EXT:
#ifdef __APPLE__
cs="ARGB";
#else
cs="BGRA";
#endif
break;
}
try {
Magick::Image mimage(pImage->xsize, pImage->ysize, cs, Magick::CharPixel,
pImage->data);
// since openGL is upside down
if(!pImage->upsidedown) {
mimage.flip();
}
// 8 bits per channel are enough!
// LATER make this dependent on the image->type
mimage.depth(8);
double quality;
if(props.get("quality", quality)) {
mimage.quality(quality);
}
try {
// finally convert and export
mimage.write(filename);
} catch (Magick::Warning&e) {
verbose(0, "[GEM:imageMAGICK] saving problem: %s", e.what());
}
} catch (Magick::Exception&e) {
verbose(0, "[GEM:imageMAGICK] %s", e.what());
if(pImage!=&image) {
delete pImage;
}
pImage=NULL;
return false;
} catch (...) {
verbose(0, "[GEM:imageMAGICK] uncaught exception!");
return false;
}
if(pImage!=&image) {
delete pImage;
}
pImage=NULL;
return true;
}
|