Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/intern/COM_Debug.cc
| Show All 25 Lines | |||||
| #include "BLI_fileops.h" | #include "BLI_fileops.h" | ||||
| #include "BLI_path_util.h" | #include "BLI_path_util.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_sys_types.h" | #include "BLI_sys_types.h" | ||||
| #include "BKE_appdir.h" | #include "BKE_appdir.h" | ||||
| #include "BKE_node.h" | #include "BKE_node.h" | ||||
| #include "DNA_node_types.h" | #include "DNA_node_types.h" | ||||
| #include "IMB_imbuf.h" | |||||
| #include "IMB_imbuf_types.h" | |||||
| } | } | ||||
| #include "COM_ExecutionSystem.h" | #include "COM_ExecutionSystem.h" | ||||
| #include "COM_Node.h" | #include "COM_Node.h" | ||||
| #include "COM_ReadBufferOperation.h" | #include "COM_ReadBufferOperation.h" | ||||
| #include "COM_SetValueOperation.h" | #include "COM_SetValueOperation.h" | ||||
| #include "COM_ViewerOperation.h" | #include "COM_ViewerOperation.h" | ||||
| #include "COM_WriteBufferOperation.h" | #include "COM_WriteBufferOperation.h" | ||||
| namespace blender::compositor { | namespace blender::compositor { | ||||
| int DebugInfo::m_file_index = 0; | int DebugInfo::m_file_index = 0; | ||||
| DebugInfo::NodeNameMap DebugInfo::m_node_names; | DebugInfo::NodeNameMap DebugInfo::m_node_names; | ||||
| DebugInfo::OpNameMap DebugInfo::m_op_names; | DebugInfo::OpNameMap DebugInfo::m_op_names; | ||||
| std::string DebugInfo::m_current_node_name; | std::string DebugInfo::m_current_node_name; | ||||
| std::string DebugInfo::m_current_op_name; | std::string DebugInfo::m_current_op_name; | ||||
| DebugInfo::GroupStateMap DebugInfo::m_group_states; | DebugInfo::GroupStateMap DebugInfo::m_group_states; | ||||
| static std::string operation_class_name(NodeOperation *op) | static std::string operation_class_name(const NodeOperation *op) | ||||
| { | { | ||||
| std::string full_name = typeid(*op).name(); | std::string full_name = typeid(*op).name(); | ||||
| /* Remove name-spaces. */ | /* Remove name-spaces. */ | ||||
| size_t pos = full_name.find_last_of(':'); | size_t pos = full_name.find_last_of(':'); | ||||
| BLI_assert(pos != std::string::npos); | BLI_assert(pos != std::string::npos); | ||||
| return full_name.substr(pos + 1); | return full_name.substr(pos + 1); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | if (graphviz_system(system, str, sizeof(str) - 1)) { | ||||
| std::cout << "Writing compositor debug to: " << filename << "\n"; | std::cout << "Writing compositor debug to: " << filename << "\n"; | ||||
| FILE *fp = BLI_fopen(filename, "wb"); | FILE *fp = BLI_fopen(filename, "wb"); | ||||
| fputs(str, fp); | fputs(str, fp); | ||||
| fclose(fp); | fclose(fp); | ||||
| } | } | ||||
| } | } | ||||
| static std::string get_operations_export_dir() | |||||
| { | |||||
| return std::string(BKE_tempdir_session()) + "COM_operations" + SEP_STR; | |||||
| } | |||||
| void DebugInfo::export_operation(const NodeOperation *op, MemoryBuffer *render) | |||||
| { | |||||
| ImBuf *ibuf = IMB_allocFromBuffer(NULL, | |||||
| render->getBuffer(), | |||||
| render->getWidth(), | |||||
| render->getHeight(), | |||||
| render->get_num_channels()); | |||||
| const std::string file_name = operation_class_name(op) + "_" + std::to_string(op->get_id()) + | |||||
| ".png"; | |||||
| const std::string path = get_operations_export_dir() + file_name; | |||||
| BLI_make_existing_file(path.c_str()); | |||||
| IMB_saveiff(ibuf, path.c_str(), ibuf->flags); | |||||
| IMB_freeImBuf(ibuf); | |||||
| } | |||||
| void DebugInfo::delete_operation_exports() | |||||
jbakker: This is risky.
would rather only delete .png and only files.
an incorrect placed link could do… | |||||
| { | |||||
| const std::string dir = get_operations_export_dir(); | |||||
| if (BLI_exists(dir.c_str())) { | |||||
| struct direntry *file_list; | |||||
| int num_files = BLI_filelist_dir_contents(dir.c_str(), &file_list); | |||||
| for (int i = 0; i < num_files; i++) { | |||||
| direntry *file = &file_list[i]; | |||||
| const eFileAttributes file_attrs = BLI_file_attributes(file->path); | |||||
| if (file_attrs & FILE_ATTR_ANY_LINK) { | |||||
| continue; | |||||
| } | |||||
| if (BLI_is_file(file->path) && BLI_path_extension_check(file->path, ".png")) { | |||||
| BLI_delete(file->path, false, false); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } // namespace blender::compositor | } // namespace blender::compositor | ||||
This is risky.
would rather only delete .png and only files.
an incorrect placed link could do a lot of harm.