CmDebug.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "CmDebug.h"
  2. #include "CmLog.h"
  3. #include "CmException.h"
  4. #include "CmBitmapWriter.h"
  5. #include "CmFileSystem.h"
  6. #include "CmDataStream.h"
  7. namespace CamelotFramework
  8. {
  9. void Debug::logDebug(std::string msg)
  10. {
  11. mLog.logMsg(msg, "GlobalDebug");
  12. }
  13. void Debug::logInfo(std::string msg)
  14. {
  15. mLog.logMsg(msg, "GlobalInfo");
  16. }
  17. void Debug::logWarning(std::string msg)
  18. {
  19. mLog.logMsg(msg, "GlobalWarning");
  20. }
  21. void Debug::logError(std::string msg)
  22. {
  23. mLog.logMsg(msg, "GlobalError");
  24. }
  25. void Debug::log(const String& msg, const String& channel)
  26. {
  27. mLog.logMsg(msg, channel);
  28. }
  29. void Debug::writeAsBMP(UINT8* rawPixels, UINT32 bytesPerPixel, UINT32 width, UINT32 height, const String& filePath, bool overwrite) const
  30. {
  31. if(FileSystem::fileExists(filePath))
  32. {
  33. if(overwrite)
  34. FileSystem::remove(filePath);
  35. else
  36. CM_EXCEPT(FileNotFoundException, "File already exists at specified location: " + filePath);
  37. }
  38. DataStreamPtr ds = FileSystem::create(filePath);
  39. UINT32 bmpDataSize = BitmapWriter::getBMPSize(width, height, bytesPerPixel);
  40. UINT8* bmpBuffer = cm_newN<UINT8, ScratchAlloc>(bmpDataSize);
  41. BitmapWriter::rawPixelsToBMP(rawPixels, bmpBuffer, width, height, bytesPerPixel);
  42. ds->write(bmpBuffer, bmpDataSize);
  43. ds->close();
  44. cm_deleteN<ScratchAlloc>(bmpBuffer, bmpDataSize);
  45. }
  46. CM_UTILITY_EXPORT Debug& gDebug()
  47. {
  48. static Debug debug;
  49. return debug;
  50. }
  51. }