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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
////////////////////////////////////////////////////////
//
// GEM - Graphics Environment for Multimedia
//
// zmoelnig@iem.at
//
// Implementation file
//
// Copyright (c) 1997-1999 Mark Danks.
// Copyright (c) Günther Geiger.
// Copyright (c) 2001-2011 IOhannes m zmölnig. forum::für::umläute. 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.
//
/////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <string.h>
#include "imageSGI.h"
#include "Gem/RTE.h"
#include "sgiimage.h"
#include "plugins/PluginFactory.h"
using namespace gem::plugins;
REGISTER_IMAGELOADERFACTORY("SGI", imageSGI);
REGISTER_IMAGESAVERFACTORY ("SGI", imageSGI);
/////////////////////////////////////////////////////////
//
// imageSGI
//
/////////////////////////////////////////////////////////
// Constructor
//
/////////////////////////////////////////////////////////
imageSGI :: imageSGI(void)
{
}
imageSGI :: ~imageSGI(void)
{
}
/////////////////////////////////////////////////////////
// really open the file ! (OS dependent)
//
/////////////////////////////////////////////////////////
bool imageSGI :: load(std::string filename, imageStruct&result,
gem::Properties&props)
{
int32 xsize, ysize, csize;
if (!sizeofimage(filename.c_str(), &xsize, &ysize, &csize) ) {
return(false);
}
result.xsize=xsize;
result.ysize=ysize;
if (csize == 4 || csize == 3) {
result.setCsizeByFormat(GEM_RGBA);
} else if (csize == 1) {
result.setCsizeByFormat(GEM_GRAY);
} else {
fprintf(stderr,
"[GEM:imageSGI] unknown color components in SGI file: %s\n",
filename.c_str());
return(false);
}
result.reallocate();
unsigned int32 *readData = longimagedata((char *)filename.c_str());
if (!readData) {
fprintf(stderr, "[GEM:imageSGI] error reading SGI image file: %s\n",
filename.c_str());
return false;
}
unsigned char *src = reinterpret_cast<unsigned char*>(readData);
const int yStride = result.xsize * result.csize;
unsigned char *dst = &(result.data[0]) + yStride * (result.ysize - 1);
// do RGBA data
if (csize == 4) {
while (ysize--) {
unsigned char *pixels = dst;
int count = xsize;
while(count--) {
pixels[chRed] = src[0];
pixels[chGreen] = src[1];
pixels[chBlue] = src[2];
pixels[chAlpha] = src[3];
pixels += 4;
src += 4;
}
dst -= yStride;
}
} else if (csize == 3) {
// do RGB data
while (ysize--) {
unsigned char *pixels = dst;
int count = xsize;
while(count--) {
pixels[chRed] = src[0];
pixels[chGreen] = src[1];
pixels[chBlue] = src[2];
pixels[chAlpha] = 255;;
pixels += 4;
src += 4;
}
dst -= yStride;
}
} else {
// do grayscale
while (ysize--) {
unsigned char *pixels = dst;
int count = xsize;
while(count--) {
pixels[0] = src[0];
pixels++;
src += 4;
}
dst -= yStride;
}
}
free(readData);
return true;
}
bool imageSGI::save(const imageStruct&image, const std::string&filename,
const std::string&mimetype, const gem::Properties&props)
{
imageStruct img;
image.convertTo(&img, GEM_RGBA);
unsigned int32*data=(unsigned int32*)img.data;
std::string name="";
if (!props.get("imagename", name)) {
name = std::string("Gem image");
}
int result=0;
if(data) {
result=longstoimage(data, img.xsize, img.ysize, 4, filename.c_str(),
name.c_str());
}
return (0!=result);
}
float imageSGI::estimateSave(const imageStruct&img,
const std::string&filename, const std::string&mimetype,
const gem::Properties&props)
{
float result=0;
if("image/sgi" == mimetype) {
result+=100;
} else if ("image/x-rgb" == mimetype) {
result+=50;
}
if(gem::Properties::UNSET != props.type("imagename")) {
result+=1.;
}
return result;
}
void imageSGI::getWriteCapabilities(std::vector<std::string>&mimetypes,
gem::Properties&props)
{
mimetypes.clear();
props.clear();
mimetypes.push_back("image/sgi");
mimetypes.push_back("image/x-rgb"); // ??
gem::any value=std::string("");
props.set("imagename", value);
}
|