1
0
mirror of synced 2024-09-24 11:38:26 +02:00

fix: Various issues with the digram and layered distribution diagrams

This commit is contained in:
WerWolv 2024-02-24 23:23:53 +01:00
parent ec69849749
commit 00b3d7809c
3 changed files with 35 additions and 36 deletions

View File

@ -74,7 +74,7 @@ namespace ImGuiExt {
#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
stbi_image_free(imageData);
STBI_FREE(imageData);
m_textureId = reinterpret_cast<ImTextureID>(static_cast<intptr_t>(texture));
}
@ -100,7 +100,7 @@ namespace ImGuiExt {
#endif
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
stbi_image_free(imageData);
STBI_FREE(imageData);
m_textureId = reinterpret_cast<ImTextureID>(static_cast<intptr_t>(texture));
}

View File

@ -115,23 +115,25 @@ namespace hex {
auto drawList = ImGui::GetWindowDrawList();
if (!m_processing) {
if (!m_texture.isValid()) {
if (!m_textureValid) {
std::vector<u32> pixels;
pixels.resize(0xFF * 0xFF, 0x00);
pixels.resize(0x100 * 0x100, 0x00);
for (size_t i = 0; i < (m_buffer.empty() ? 0 : m_buffer.size() - 1); i++) {
const auto x = m_buffer[i];
const auto y = m_buffer[i + 1];
const u8 x = m_buffer[i];
const u8 y = m_buffer[i + 1];
auto color = ImLerp(
ImColor(0xFF, 0x6D, 0x01).Value,
ImColor(0x01, 0x93, 0xFF).Value,
float(i) / m_buffer.size()) + ImVec4(m_glowBuffer[i], m_glowBuffer[i], m_glowBuffer[i], 0.0F);
color.w = m_opacity;
color.w = m_opacity;
pixels[x * 0xFF + y] = ImAlphaBlendColors(pixels[x * 0xFF + y], ImColor(color));
auto &pixel = pixels[x * 0xFF + y];
pixel = ImAlphaBlendColors(pixel, ImColor(color));
}
m_texture = ImGuiExt::Texture(reinterpret_cast<u8*>(pixels.data()), pixels.size() * 4, m_filter, 0xFF, 0xFF);
m_textureValid = m_texture.isValid();
}
auto pos = ImGui::GetWindowPos() + ImVec2(size.x * 0.025F, size.y * 0.025F);
@ -163,7 +165,7 @@ namespace hex {
m_buffer.reserve(m_sampleSize == 0 ? size : m_sampleSize);
m_byteCount = 0;
m_fileSize = size;
m_texture = ImGuiExt::Texture();
m_textureValid = false;
}
void update(u8 byte) {
@ -206,7 +208,7 @@ namespace hex {
m_glowBuffer[i] = std::min<float>(0.2F + (float(heatMap[m_buffer[i] << 8 | m_buffer[i + 1]]) / float(m_highestCount / 1000)), 1.0F);
}
m_opacity = (log10(float(m_sampleSize == 0 ? m_buffer.size() : m_sampleSize)) / log10(float(m_highestCount))) / (100.0F * m_brightness);
m_opacity = (log10(float(m_sampleSize == 0 ? m_buffer.size() : m_sampleSize)) / log10(float(m_highestCount))) / (100.0F * (1.0F - m_brightness));
}
private:
@ -223,6 +225,8 @@ namespace hex {
float m_opacity = 0.0F;
size_t m_highestCount = 0;
std::atomic<bool> m_processing = false;
bool m_textureValid = false;
ImGuiExt::Texture m_texture;
};
@ -236,20 +240,22 @@ namespace hex {
auto drawList = ImGui::GetWindowDrawList();
if (!m_processing) {
if (!m_texture.isValid()) {
if (!m_textureValid) {
std::vector<u32> pixels;
pixels.resize(0xFF * 0xFF, 0x00);
pixels.resize(0x100 * 0x100, 0x00);
for (size_t i = 0; i < (m_buffer.empty() ? 0 : m_buffer.size() - 1); i++) {
const auto x = m_buffer[i];
const auto y = (float(i) / m_buffer.size()) * 0xFF;
const u8 x = m_buffer[i];
const u8 y = (float(i) / m_buffer.size()) * 0xFF;
auto color = ImLerp(ImColor(0xFF, 0x6D, 0x01).Value, ImColor(0x01, 0x93, 0xFF).Value, float(i) / m_buffer.size()) + ImVec4(m_glowBuffer[i], m_glowBuffer[i], m_glowBuffer[i], 0.0F);
color.w = m_opacity;
color.w = m_opacity;
pixels[x * 0xFF + y] = ImAlphaBlendColors(pixels[x * 0xFF + y], ImColor(color));
auto &pixel = pixels[x * 0xFF + y];
pixel = ImAlphaBlendColors(pixel, ImColor(color));
}
m_texture = ImGuiExt::Texture(reinterpret_cast<u8*>(pixels.data()), pixels.size() * 4, m_filter, 0xFF, 0xFF);
m_textureValid = m_texture.isValid();
}
const auto pos = ImGui::GetWindowPos() + ImVec2(size.x * 0.025F, size.y * 0.025F);
@ -280,7 +286,7 @@ namespace hex {
m_buffer.reserve(m_sampleSize == 0 ? size : m_sampleSize);
m_byteCount = 0;
m_fileSize = size;
m_texture = ImGuiExt::Texture();
m_textureValid = false;
}
void update(u8 byte) {
@ -323,7 +329,7 @@ namespace hex {
m_glowBuffer[i] = std::min<float>(0.2F + (float(heatMap[m_buffer[i] << 8 | m_buffer[i + 1]]) / float(m_highestCount / 1000)), 1.0F);
}
m_opacity = (log10(float(m_sampleSize == 0 ? m_buffer.size() : m_sampleSize)) / log10(float(m_highestCount))) / (100.0F * m_brightness);
m_opacity = (log10(float(m_sampleSize == 0 ? m_buffer.size() : m_sampleSize)) / log10(float(m_highestCount))) / (100.0F * (1.0F - m_brightness));
}
private:
@ -341,6 +347,8 @@ namespace hex {
float m_opacity = 0.0F;
size_t m_highestCount = 0;
std::atomic<bool> m_processing = false;
bool m_textureValid = false;
ImGuiExt::Texture m_texture;
};

View File

@ -350,8 +350,6 @@ class InformationByteRelationshipAnalysis : public ContentRegistry::DataInformat
public:
InformationByteRelationshipAnalysis() : InformationSection("hex.builtin.information_section.relationship_analysis", "", true) {
}
~InformationByteRelationshipAnalysis() override {
}
void process(Task &task, prv::Provider *provider, Region region) override {
@ -367,15 +365,15 @@ class InformationByteRelationshipAnalysis : public ContentRegistry::DataInformat
// Loop over each byte of the selection and update each analysis
// one byte at a time to process the file only once
for (u8 byte : reader) {
m_layeredDistribution.update(byte);
m_digram.update(byte);
m_layeredDistribution.update(byte);
task.update();
}
}
void reset() override {
m_digram.reset(0);
m_layeredDistribution.reset(0);
m_digram.reset(m_sampleSize);
m_layeredDistribution.reset(m_sampleSize);
updateSettings();
}
@ -395,19 +393,12 @@ class InformationByteRelationshipAnalysis : public ContentRegistry::DataInformat
void drawContent() override {
auto availableWidth = ImGui::GetContentRegionAvail().x;
ImGui::BeginGroup();
{
ImGui::TextUnformatted("hex.builtin.information_section.relationship_analysis.digram"_lang);
m_digram.draw({ availableWidth, availableWidth });
}
ImGui::EndGroup();
ImGui::BeginGroup();
{
ImGui::TextUnformatted("hex.builtin.information_section.relationship_analysis.layered_distribution"_lang);
m_layeredDistribution.draw({ availableWidth, availableWidth });
}
ImGui::EndGroup();
ImGui::TextUnformatted("hex.builtin.information_section.relationship_analysis.digram"_lang);
m_digram.draw({ availableWidth, availableWidth });
ImGui::TextUnformatted("hex.builtin.information_section.relationship_analysis.layered_distribution"_lang);
m_layeredDistribution.draw({ availableWidth, availableWidth });
}
void load(const nlohmann::json &data) override {
@ -442,7 +433,7 @@ class InformationByteRelationshipAnalysis : public ContentRegistry::DataInformat
private:
ImGuiExt::Texture::Filter m_filter = ImGuiExt::Texture::Filter::Nearest;
u64 m_sampleSize = 0x90000;
u64 m_sampleSize = 0x9000;
float m_brightness = 0.5F;
DiagramDigram m_digram;