cstool/debugimagewriter.h
Go to the documentation of this file.00001 /* 00002 Copyright (C) 2004 by Jorrit Tyberghein 00003 (C) 2004 by Frank Richter 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00018 */ 00019 00020 #ifndef __CS_CSTOOL_DEBUGIMAGEWRITER_H__ 00021 #define __CS_CSTOOL_DEBUGIMAGEWRITER_H__ 00022 00027 #include "csutil/csstring.h" 00028 #include "csutil/scf.h" 00029 #include "igraphic/imageio.h" 00030 #include "iutil/databuff.h" 00031 #include "iutil/vfs.h" 00032 #include "ivaria/reporter.h" 00033 00039 class CS_CRYSTALSPACE_EXPORT csDebugImageWriter 00040 { 00041 static void Report (int severity, const char* msg, ...) 00042 { 00043 #ifdef CS_DEBUG 00044 va_list arg; 00045 va_start (arg, msg); 00046 csReportV (iSCF::SCF->object_reg, severity, "crystalspace.debugimagewriter", 00047 msg, arg); 00048 va_end (arg); 00049 #endif 00050 } 00051 public: 00061 static void DebugImageWrite (iImage* image, const char* filename, ...) 00062 { 00063 #ifdef CS_DEBUG 00064 CS_ASSERT(iSCF::SCF->object_reg); 00065 csRef<iImageIO> imgsaver = 00066 CS_QUERY_REGISTRY (iSCF::SCF->object_reg, iImageIO); 00067 if (!imgsaver) 00068 { 00069 Report (CS_REPORTER_SEVERITY_ERROR, "No iImageIO"); 00070 return; 00071 } 00072 csRef<iVFS> vfs = 00073 CS_QUERY_REGISTRY (iSCF::SCF->object_reg, iVFS); 00074 if (!vfs) 00075 { 00076 Report (CS_REPORTER_SEVERITY_ERROR, "No iVFS"); 00077 return; 00078 } 00079 00080 csString finalFilename; 00081 va_list arg; 00082 va_start (arg, filename); 00083 finalFilename.FormatV (filename, arg); 00084 va_end (arg); 00085 00086 csRef<iDataBuffer> buf = imgsaver->Save (image, "image/png"); 00087 if (!buf) 00088 { 00089 Report (CS_REPORTER_SEVERITY_ERROR, "Error saving image"); 00090 return; 00091 } 00092 vfs->PushDir (); 00093 vfs->ChDir ("/tmp"); 00094 bool written = vfs->WriteFile (finalFilename, (char*)buf->GetInt8 (), 00095 buf->GetSize ()); 00096 vfs->PopDir (); 00097 if (!written) 00098 { 00099 Report (CS_REPORTER_SEVERITY_ERROR, "Could not write to %s", 00100 finalFilename.GetData ()); 00101 } 00102 #else 00103 // Make -Wall happy 00104 (void)image; 00105 (void)filename; 00106 #endif 00107 } 00108 }; 00109 00110 #endif // __CS_CSTOOL_DEBUGIMAGEWRITER_H__
Generated for Crystal Space by doxygen 1.4.7