Commit cffba22f authored by IOhannes m zmölnig's avatar IOhannes m zmölnig
Browse files

consistent verbosity for image* plugins

parent bb6f1f48
......@@ -94,11 +94,9 @@ METHODDEF(void) my_error_exit (j_common_ptr cinfo)
imageJPEG :: imageJPEG(void)
{
//post("imageJPEG");
}
imageJPEG :: ~imageJPEG(void)
{
//post("~imageJPEG");
}
/////////////////////////////////////////////////////////
......@@ -109,9 +107,8 @@ bool imageJPEG :: load(std::string filename, imageStruct&result, gem::Properties
{
// open up the file
FILE * infile;
::verbose(2, "reading '%s' with libJPEG", filename.c_str());
if ((infile = fopen(filename.c_str(), "rb")) == NULL) {
//verbose(2, "GemImageLoad(JPEG): Unable to open image file: %s", filename.c_str());
fprintf(stderr, "[GEM:imageJPEG] Unable to open image file: %s\n", filename.c_str());
return(false);
}
......@@ -242,7 +239,7 @@ bool imageJPEG::save(const imageStruct&constimage, const std::string&filename, c
quality=fquality;
if(GL_YUV422_GEM==constimage.format) {
error("don't know how to write YUV-images with libJPEG");
fprintf(stderr, "[GEM:imageJPEG] don't know how to write YUV-images\n");
return false;
}
......@@ -250,7 +247,7 @@ bool imageJPEG::save(const imageStruct&constimage, const std::string&filename, c
jpeg_create_compress(&cinfo);
if ((outfile = fopen(filename.c_str(), "wb")) == NULL) {
error("can't open %s\n", filename.c_str());
fprintf(stderr, "[GEM:imageJPEG] can't open %s\n", filename.c_str());
return (false);
}
jpeg_stdio_dest(&cinfo, outfile);
......@@ -282,7 +279,7 @@ bool imageJPEG::save(const imageStruct&constimage, const std::string&filename, c
row_pointer = & image_buffer[rowindex * row_stride];
if(jpeg_write_scanlines(&cinfo, &row_pointer, 1) <= 0){
error("GEM: could not write line %d to image %s", cinfo.next_scanline, filename.c_str());
fprintf(stderr, "[GEM:imageJPEG] could not write line %d to image %s\n", cinfo.next_scanline, filename.c_str());
jpeg_finish_compress(&cinfo);
fclose(outfile);
jpeg_destroy_compress(&cinfo);
......
......@@ -70,9 +70,9 @@ namespace {
message += " (" + std::string(exception->description) + ")";
if(iswarning) {
verbose(1, "%s", message.c_str());
verbose(0, "[GEM:imageMAGICK] %s", message.c_str());
} else {
verbose(1, "%s", message.c_str());
verbose(0, "[GEM:imageMAGICK] %s", message.c_str());
}
return (!iswarning);
}
......@@ -86,13 +86,12 @@ namespace {
bool imageMAGICK :: load(std::string filename, imageStruct&result, gem::Properties&props)
{
bool success=false;
::verbose(2, "reading '%s' with ImageMagick", filename.c_str());
ExceptionInfo*exception=AcquireExceptionInfo();
ImageInfo*image_info=CloneImageInfo((ImageInfo *) NULL);
CopyMagickString(image_info->filename,filename.c_str(), MaxTextExtent);
Image*image=ReadImage(image_info,exception);
if(showException(exception, "magick reading problem"))
if(showException(exception, "reading problem"))
goto cleanup;
if (image == (Image *) NULL)
goto cleanup;
......@@ -113,7 +112,7 @@ bool imageMAGICK :: load(std::string filename, imageStruct&result, gem::Properti
CharPixel,
reinterpret_cast<void*>(result.data),
exception);
if(showException(exception, "magick decoding problem"))
if(showException(exception, "decoding problem"))
goto cleanup;
success=true;
......@@ -167,11 +166,11 @@ bool imageMAGICK::save(const imageStruct&image, const std::string&filename, cons
Image *mimage = ConstituteImage(pImage->xsize, pImage->ysize,
cs.c_str(), CharPixel,
pImage->data, exception);
if(showException(exception, "magick conversion problem"))
if(showException(exception, "conversion problem"))
goto cleanup;
finalImage=(pImage->upsidedown)?mimage:FlipImage( mimage, exception );
if(showException(exception, "magick flipping problem"))
if(showException(exception, "flipping problem"))
goto cleanup;
finalImage->depth=8;
......@@ -194,7 +193,7 @@ bool imageMAGICK::save(const imageStruct&image, const std::string&filename, cons
status = WriteImage(image_info, finalImage);
ex = &finalImage->exception;
#endif
if(showException(ex, "magick writing problem"))
if(showException(ex, "writing problem"))
goto cleanup;
cleanup:
......
......@@ -37,12 +37,11 @@ bool imageMAGICK :: load(std::string filename, imageStruct&result, gem::Properti
{
Magick::Image image;
try {
::verbose(2, "reading '%s' with ImageMagick", filename.c_str());
// Read a file into image object
try {
image.read( filename );
} catch (Magick::Warning e) {
verbose(1, "magick loading problem: %s", e.what());
verbose(0, "[GEM:imageMAGICK] loading problem: %s", e.what());
}
result.xsize=static_cast<GLint>(image.columns());
......@@ -62,10 +61,10 @@ bool imageMAGICK :: load(std::string filename, imageStruct&result, gem::Properti
Magick::CharPixel,
reinterpret_cast<void*>(result.data));
} catch (Magick::Warning e) {
verbose(1, "magick decoding problem: %s", e.what());
verbose(0, "[GEM:imageMAGICK] decoding problem: %s", e.what());
}
}catch( Magick::Exception e ) {
verbose(1, "magick loading image failed with: %s", e.what());
verbose(0, "[GEM:imageMAGICK] loading image failed with: %s", e.what());
return false;
}
return true;
......@@ -119,16 +118,16 @@ bool imageMAGICK::save(const imageStruct&image, const std::string&filename, cons
// finally convert and export
mimage.write(filename);
} catch (Magick::Warning e) {
verbose(1, "magick saving problem: %s", e.what());
verbose(0, "[GEM:imageMAGICK] saving problem: %s", e.what());
}
} catch (Magick::Exception e){
error("%s", e.what());
verbose(0, "[GEM:imageMAGICK] %s", e.what());
if(pImage!=&image)delete pImage; pImage=NULL;
return false;
} catch (...) {
error("imageMAGICK:: uncaught exception!");
return false;
verbose(0, "[GEM:imageMAGICK] uncaught exception!");
return false;
}
if(pImage!=&image)delete pImage; pImage=NULL;
return true;
......
......@@ -146,7 +146,6 @@ imageMAGICK :: imageMAGICK(void)
}
imageMAGICK :: ~imageMAGICK(void)
{
//post("~imageMAGICK");
}
......
......@@ -99,7 +99,7 @@ FSPathMakeFSSpec(
c2pstr(filename);
OSErr err=FSMakeFSSpec (0, 0L, filename8, spec);
if (err != noErr && err != -37){
error("GEM: recordQT: error %d in FSMakeFSSpec()", err);
verbose(0, "[GEM:imageQT] error#%d in FSMakeFSSpec()", err);
} else {
err = noErr;
}
......@@ -224,15 +224,13 @@ imageQT :: imageQT(void)
if (err = EnterMovies()) {
throw(GemException("unable to initialize QuickTime/Movies"));
}
verbose(1, "imageQT: QT init done");
verbose(1, "[GEM:imageQT] QT init done");
#endif // WINDOWS
firsttime=false;
}
//post("imageQT");
}
imageQT :: ~imageQT(void)
{
//post("~imageQT");
}
/////////////////////////////////////////////////////////
......@@ -276,11 +274,9 @@ static bool QuickTimeImage2mem(GraphicsImportComponent inImporter, imageStruct&r
imageDescH = NULL;
result.reallocate();
#ifdef __DEBUG__
post("QuickTimeImage2mem() : allocate %d bytes", result.xsize*result.ysize*result.csize);
#endif
verbose(1, "[GEM:imageQT] QuickTimeImage2mem() allocate %d bytes", result.xsize*result.ysize*result.csize);
if (result.data == NULL) {
error("Can't allocate memory for an image.");
verbose(0, "[GEM:imageQT] Can't allocate memory for an image.");
return false;
}
......@@ -295,7 +291,7 @@ static bool QuickTimeImage2mem(GraphicsImportComponent inImporter, imageStruct&r
result.data,
static_cast<long>(result.xsize * result.csize));
if (err) {
error("Can't create QTNewWorld");
verbose(0, "[GEM:imageQT] Can't create QTNewWorld");
}
::GraphicsImportSetGWorld(inImporter, gw, NULL);
......@@ -311,20 +307,20 @@ bool imageQT :: load(std::string filename, imageStruct&result, gem::Properties&p
OSErr err;
GraphicsImportComponent importer = NULL;
::verbose(2, "reading '%s' with QuickTime", filename.c_str());
::verbose(1, "[GEM:imageQT] reading '%s' with QuickTime", filename.c_str());
std::string myfilename=filename;
// does the file even exist?
if (!filename.empty()) {
FSSpec spec;
err = ::FSPathMakeFSSpec( reinterpret_cast<const UInt8*>(myfilename.c_str()), &spec);
if (err) {
error("GemImageLoad: Unable to find file: %s", filename.c_str());
error("parID : %d", spec.parID);
verbose(0, "[GEM:imageQT] Unable to find file: %s", filename.c_str());
verbose(1, "[GEM:imageQT] parID : %d", spec.parID);
return false;
}
err = ::GetGraphicsImporterForFile(&spec, &importer);
if (err) {
error("GemImageLoad: Unable to import image '%s'", filename.c_str());
verbose(0, "[GEM:imageQT] GemImageLoad: Unable to import image '%s'", filename.c_str());
return false;
}
}
......@@ -381,13 +377,13 @@ bool imageQT::save(const imageStruct&constimage, const std::string&filename, con
}
if (err != noErr) {
verbose(1, "ERROR: %d in FSPathMakeRef()", err);
verbose(1, "[GEM:imageQT] error#%d in FSPathMakeRef()", err);
}
err = ::FSGetCatalogInfo(&ref, kFSCatInfoNodeFlags, NULL, NULL, &spec, NULL);
if (err != noErr) {
verbose(1, "ERROR: %d in FSGetCatalogInfo()", err);
verbose(1, "[GEM:imageQT] error#%d in FSGetCatalogInfo()", err);
}
err = FSMakeFSSpec(spec.vRefNum, spec.parID, filename8, &spec); //this always gives an error -37 ???
......@@ -397,12 +393,12 @@ bool imageQT::save(const imageStruct&constimage, const std::string&filename, con
err = FSMakeFSSpec (0, 0L, filename8, &spec);
#endif
if (err != noErr && err != -37){
verbose(1, "GEM: imageQT: error %d in FSMakeFSSpec()", err);
verbose(1, "[GEM:imageQT] error#%d in FSMakeFSSpec()", err);
}
err = OpenADefaultComponent(GraphicsExporterComponentType, osFileType, &geComp);
if (err != noErr) {
error("ERROR: %d in OpenADefaultComponent()", err);
verbose(0, "[GEM:imageQT] error#%d in OpenADefaultComponent()", err);
return false; // FIXME:
}
......@@ -434,7 +430,7 @@ bool imageQT::save(const imageStruct&constimage, const std::string&filename, con
// i don't know, whether quicktime still needs the buffer...
if (err != noErr) {
error("ERROR: %d in QTNewGWorldFromPtr()", err);
verbose(0, "[GEM:imageQT] error#%d in QTNewGWorldFromPtr()", err);
if(data)delete[]data;
return false; // FIXME:
}
......@@ -442,7 +438,7 @@ bool imageQT::save(const imageStruct&constimage, const std::string&filename, con
// Set the input GWorld for the exporter
cErr = GraphicsExportSetInputGWorld(geComp, img);
if (cErr != noErr) {
error("ERROR: %d in GraphicsExportSetInputGWorld()", cErr);
verbose(0, "[GEM:imageQT] error#%d in GraphicsExportSetInputGWorld()", cErr);
if(data)delete[]data;
return false; // FIXME:
}
......@@ -450,7 +446,7 @@ bool imageQT::save(const imageStruct&constimage, const std::string&filename, con
// Set the output file to our FSSpec
cErr = GraphicsExportSetOutputFile(geComp, &spec);
if (cErr != noErr) {
error("ERROR: %i in GraphicsExportSetOutputFile()", cErr);
verbose(0, "[GEM:imageQT] error#%d in GraphicsExportSetOutputFile()", cErr);
if(data)delete[]data;
return false; // FIXME:
}
......@@ -486,7 +482,7 @@ bool imageQT::save(const imageStruct&constimage, const std::string&filename, con
// Export it
cErr = GraphicsExportDoExport(geComp, NULL);
if (cErr != noErr) {
error("ERROR: %i in GraphicsExportDoExport()", cErr);
verbose(0, "[GEM:imageQT] ERROR: %i in GraphicsExportDoExport()", cErr);
if(data)delete[]data;
return false; // FIXME:
}
......
......@@ -39,11 +39,9 @@ REGISTER_IMAGESAVERFACTORY ("SGI", imageSGI);
/////////////////////////////////////////////////////////
imageSGI :: imageSGI(void)
{
//post("imageSGI");
}
imageSGI :: ~imageSGI(void)
{
//post("~imageSGI");
}
/////////////////////////////////////////////////////////
......@@ -56,8 +54,6 @@ bool imageSGI :: load(std::string filename, imageStruct&result, gem::Properties&
if (!sizeofimage(filename.c_str(), &xsize, &ysize, &csize) )
return(false);
::verbose(2, "reading '%s' with SGI", filename.c_str());
result.xsize=xsize;
result.ysize=ysize;
......@@ -66,14 +62,14 @@ bool imageSGI :: load(std::string filename, imageStruct&result, gem::Properties&
} else if (csize == 1) {
result.setCsizeByFormat(GL_LUMINANCE);
} else {
//error("GemImageLoad(SGI): unknown color components in SGI file: %s", filename.c_str());
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) {
//error("GemImageLoad: error reading SGI image file: %s", filename.c_str());
fprintf(stderr, "[GEM:imageSGI] error reading SGI image file: %s\n", filename.c_str());
return false;
}
......
......@@ -34,7 +34,6 @@
#include <stdio.h>
#include "Gem/RTE.h"
//#include "m_pd.h"
/*
* from image.h
......@@ -140,7 +139,7 @@ static unsigned short getshort(FILE *inf)
size_t count=fread(buf,2,1,inf);
if(count<1){error("error reading file"); return 0;}
if(count<1){fprintf(stderr, "[GEM:imageSGI] error reading file\n"); return 0;}
return (buf[0]<<8)+(buf[1]<<0);
}
......@@ -148,7 +147,7 @@ static unsigned int32 getlong(FILE *inf)
{
unsigned char buf[4];
size_t count = fread(buf,4,1,inf);
if(count<1){error("error reading file"); return 0;}
if(count<1){fprintf(stderr, "[GEM:imageSGI] error reading file\n"); return 0;}
return (buf[0]<<24)+(buf[1]<<16)+(buf[2]<<8)+(buf[3]<<0);
}
......@@ -304,7 +303,7 @@ unsigned int32 *longimagedata(const char *name)
bpp = BPP(image->type);
if(bpp != 1 )
{
printf("longimagedata: image must have 1 byte per pix chan\n");
fprintf(stderr, "[GEM:imageSGI] longimagedata: image must have 1 byte per pix chan\n");
goto error;
}
xsize = image->xsize;
......@@ -320,7 +319,7 @@ unsigned int32 *longimagedata(const char *name)
rlebuflen = static_cast<unsigned long>(1.05*xsize)+10;
rledat = (unsigned char *)malloc(rlebuflen);
if(fseek(inf,512,SEEK_SET)<0) {
printf("longimagedata: fseek returned 0\n");
fprintf(stderr, "[GEM:imageSGI] longimagedata: fseek returned 0\n");
goto error;
}
readtab(inf,starttab,tablen);
......@@ -368,12 +367,12 @@ unsigned int32 *longimagedata(const char *name)
}
if(lengthtab[y+z*ysize]>rlebuflen)
{
printf("longimagedata: rlebuf(%lu) is too small - bad poop : %d\n", rlebuflen, lengthtab[y+z*ysize]);
fprintf(stderr, "[GEM:imageSGI] longimagedata: rlebuf(%lu) is too small - bad poop : %d\n", rlebuflen, lengthtab[y+z*ysize]);
goto error;
}
size_t count=fread(rledat,lengthtab[y+z*ysize],1,inf);
if(count<1){
error("error reading file");
fprintf(stderr, "[GEM:imageSGI] error reading file\n");
goto error;
}
......@@ -403,7 +402,7 @@ unsigned int32 *longimagedata(const char *name)
}
size_t count=fread(rledat,lengthtab[y+z*ysize],1,inf);
if(count<1){
error("error reading file");
fprintf(stderr, "[GEM:imageSGI] error reading file\n");
goto error;
}
......@@ -438,7 +437,7 @@ unsigned int32 *longimagedata(const char *name)
{
size_t count = fread(verdat,xsize,1,inf);
if(count<1){
error("error reading file");
fprintf(stderr, "[GEM:imageSGI] error reading file\n");
goto error;
}
......@@ -602,14 +601,14 @@ int longstoimage(unsigned int32 *lptr, int32 xsize, int32 ysize, int32 zsize,
case 4: case 3: case 1:
break;
default:
printf("longstoimage: invalid zsize %d (must be 1,3 or 4)\n", zsize);
fprintf(stderr, "[GEM:imageSGI] longstoimage: invalid zsize %d (must be 1,3 or 4)\n", zsize);
return 0;
}
goodwrite = 1;
outf = fopen(name,"wb");
if(!outf) {
printf("longstoimage: can't open output file\n");
fprintf(stderr, "[GEM:imageSGI] longstoimage: can't open output file\n");
return 0;
}
tablen = ysize*zsize*sizeof(int32);
......@@ -635,7 +634,7 @@ int longstoimage(unsigned int32 *lptr, int32 xsize, int32 ysize, int32 zsize,
image->max = 255;
goodwrite *= writeheader(outf, image, imgname);
if(fseek(outf,512+2*tablen,SEEK_SET) < 0) {
printf("longstoimage: fseek failed\n");
fprintf(stderr, "[GEM:imageSGI] longstoimage: fseek failed\n");
goto longstoimage_close;
}
pos = 512+2*tablen;
......@@ -656,7 +655,7 @@ int longstoimage(unsigned int32 *lptr, int32 xsize, int32 ysize, int32 zsize,
#endif
}
if(len>rlebuflen) {
printf("longstoimage: rlebuf is too small - bad poop\n");
fprintf(stderr, "[GEM:imageSGI] longstoimage: rlebuf is too small - bad poop\n");
goodwrite=0;
goto longstoimage_close;
}
......@@ -669,7 +668,7 @@ int longstoimage(unsigned int32 *lptr, int32 xsize, int32 ysize, int32 zsize,
}
if(fseek(outf,512,SEEK_SET) < 0) {
printf("longstoimage: fseek failed...\n");
fprintf(stderr, "[GEM:imageSGI] longstoimage: fseek failed...\n");
goodwrite=0;
goto longstoimage_close;
}
......@@ -685,7 +684,7 @@ int longstoimage(unsigned int32 *lptr, int32 xsize, int32 ysize, int32 zsize,
if(goodwrite)
return 1;
else {
printf("longstoimage: not enough space for image!!\n");
fprintf(stderr, "[GEM:imageSGI] longstoimage: not enough space for image!!\n");
return 0;
}
}
......
......@@ -47,18 +47,17 @@ REGISTER_IMAGESAVERFACTORY("tiff", imageTIFF);
namespace {
static void imageTIFF_verbosehandler(const int verbosity, const char*module, const char*fmt, va_list ap) {
std::string result=module;
result+=": ";
char buf[MAXPDSTRING];
vsnprintf(buf, MAXPDSTRING, fmt, ap);
buf[MAXPDSTRING-1]=0;
result+=buf;
verbose(verbosity, "%s", result.c_str());
verbose(verbosity, "[GEM:imageTIFF] %s", result.c_str());
}
static void imageTIFF_errorhandler(const char*module, const char*fmt, va_list ap) {
imageTIFF_verbosehandler(2, module, fmt, ap);
imageTIFF_verbosehandler(-2, module, fmt, ap);
}
static void imageTIFF_warnhandler(const char*module, const char*fmt, va_list ap) {
imageTIFF_verbosehandler(3, module, fmt, ap);
imageTIFF_verbosehandler(0, module, fmt, ap);
}
};
......@@ -73,7 +72,6 @@ namespace {
imageTIFF :: imageTIFF(void)
{
//post("imageTIFF");
bool firsttime=true;
if(firsttime) {
TIFFSetErrorHandler(imageTIFF_errorhandler);
......@@ -83,7 +81,6 @@ imageTIFF :: imageTIFF(void)
}
imageTIFF :: ~imageTIFF(void)
{
//post("~imageTIFF");
}
/////////////////////////////////////////////////////////
......@@ -92,7 +89,6 @@ imageTIFF :: ~imageTIFF(void)
/////////////////////////////////////////////////////////
bool imageTIFF :: load(std::string filename, imageStruct&result, gem::Properties&props)
{
::verbose(2, "reading '%s' with libTIFF", filename.c_str());
TIFF *tif = TIFFOpen(filename.c_str(), "r");
if (tif == NULL) {
return(NULL);
......@@ -136,7 +132,7 @@ bool imageTIFF :: load(std::string filename, imageStruct&result, gem::Properties
if (knownFormat) {
unsigned char *buf = new unsigned char [TIFFScanlineSize(tif)];
if (buf == NULL) {
error("GemImageLoad(TIFF): can't allocate memory for scanline buffer: %s", filename.c_str());
error("[GEM:imageTIFF] can't allocate memory for scanline buffer: %s", filename.c_str());
TIFFClose(tif);
return(false);
}
......@@ -148,7 +144,7 @@ bool imageTIFF :: load(std::string filename, imageStruct&result, gem::Properties
{
unsigned char *pixels = dstLine;
if (TIFFReadScanline(tif, buf, row, 0) < 0) {
error("GemImageLoad(TIFF): bad image data read on line: %d: %s", row, filename.c_str());
verbose(1, "[GEM:imageTIFF] bad image data read on line: %d: %s", row, filename.c_str());
TIFFClose(tif);
return false;
}
......@@ -186,20 +182,20 @@ bool imageTIFF :: load(std::string filename, imageStruct&result, gem::Properties
char emsg[1024];
TIFFRGBAImage img;
if (TIFFRGBAImageBegin(&img, tif, 0, emsg) == 0) {
//error("GemImageLoad(TIFF): Error reading in image file: %s : %s", filename, emsg);
verbose(0, "[GEM:imageTIFF] Error reading in image file: %s : %s", filename, emsg);
TIFFClose(tif);
return(false);
}
uint32*raster = reinterpret_cast<uint32*>(_TIFFmalloc(npixels * sizeof(uint32)));
if (raster == NULL) {
error("GemImageLoad(TIFF): Unable to allocate memory for image: %s", filename.c_str());
error("[GEM:imageTIFF] Unable to allocate memory for image: %s", filename.c_str());
TIFFClose(tif);
return(false);
}
if (TIFFRGBAImageGet(&img, raster, width, height) == 0) {
//error("GemImageLoad(TIFF): Error getting image data in file: %s, %s", filename, emsg);
verbose(0, "[GEM:imageTIFF] Error getting image data in file: %s, %s", filename, emsg);
_TIFFfree(raster);
TIFFClose(tif);
return(false);
......@@ -261,7 +257,7 @@ bool imageTIFF::save(const imageStruct&constimage, const std::string&filename, c
TIFF *tif = NULL;
if(GL_YUV422_GEM==constimage.format) {
error("don't know how to write YUV-images with libTIFF");
verbose(0, "[GEM:imageTIFF] don't know how to write YUV-images");
return false;
}
......@@ -325,7 +321,7 @@ bool imageTIFF::save(const imageStruct&constimage, const std::string&filename, c
unsigned char *buf = srcLine;
if (TIFFWriteScanline(tif, buf, row, 0) < 0)
{
error("GEM: could not write line %d to image %s", row, filename.c_str());
verbose(0, "[GEM:imageTIFF] could not write line %d to image %s", row, filename.c_str());
TIFFClose(tif);
delete [] buf;
return(false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment