Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages
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/vfs.h" 00031 #include "ivaria/reporter.h" 00032 00037 class CS_CSTOOL_EXPORT csDebugImageWriter 00038 { 00039 static void Report (int severity, const char* msg, ...) 00040 { 00041 #ifdef CS_DEBUG 00042 va_list arg; 00043 va_start (arg, msg); 00044 csReportV (iSCF::SCF->object_reg, severity, "crystalspace.debugimagewriter", 00045 msg, arg); 00046 va_end (arg); 00047 #endif 00048 } 00049 public: 00058 static void DebugImageWrite (iImage* image, const char* filename, ...) 00059 { 00060 #ifdef CS_DEBUG 00061 CS_ASSERT(iSCF::SCF->object_reg); 00062 csRef<iImageIO> imgsaver = 00063 CS_QUERY_REGISTRY (iSCF::SCF->object_reg, iImageIO); 00064 if (!imgsaver) 00065 { 00066 Report (CS_REPORTER_SEVERITY_ERROR, "No iImageIO"); 00067 return; 00068 } 00069 csRef<iVFS> vfs = 00070 CS_QUERY_REGISTRY (iSCF::SCF->object_reg, iVFS); 00071 if (!vfs) 00072 { 00073 Report (CS_REPORTER_SEVERITY_ERROR, "No iVFS"); 00074 return; 00075 } 00076 00077 csString finalFilename; 00078 va_list arg; 00079 va_start (arg, filename); 00080 finalFilename.FormatV (filename, arg); 00081 va_end (arg); 00082 00083 csRef<iDataBuffer> buf = imgsaver->Save (image, "image/png"); 00084 if (!buf) 00085 { 00086 Report (CS_REPORTER_SEVERITY_ERROR, "Error saving image"); 00087 return; 00088 } 00089 vfs->PushDir (); 00090 vfs->ChDir ("/tmp"); 00091 bool written = vfs->WriteFile (finalFilename, (char*)buf->GetInt8 (), 00092 buf->GetSize ()); 00093 vfs->PopDir (); 00094 if (!written) 00095 { 00096 Report (CS_REPORTER_SEVERITY_ERROR, "Could not write to %s", 00097 finalFilename.GetData ()); 00098 } 00099 #endif 00100 } 00101 }; 00102 00103 #endif // __CS_CSTOOL_DEBUGIMAGEWRITER_H__
Generated for Crystal Space by doxygen 1.3.9.1