Tom94 / tev

High dynamic range (HDR) image viewer for graphics people
BSD 3-Clause "New" or "Revised" License
1.02k stars 86 forks source link

Vector graphics over IPC #200

Closed Tom94 closed 1 year ago

Tom94 commented 1 year ago

Adds support for sending vector graphics commands over IPC to annotate images.

For example, this can be used to highlight the latest rendered part of an image (supposing that tev is used as the frontend for a renderer). You can view a sample of how this can be accomplished by running src/python/ipc-example.py. Another use case would be marking NaNs, infinities, or otherwise unexpected values, depending on context.

Implements #175

@mmp let me know if this is interesting for you and you have early feedback. :)

Here's sample Python code to draw a rectangle:

import tev
with tev.Ipc() as tev_ipc:
    # Assumes that an image named "image" has been opened or created beforehand
    tev_ipc.update_vector_graphics("image", [
        tev.vg_begin_path(),
        tev.vg_rect(x, y, width, height),
        #Alternatively: draw rectangle manually
        # tev.vg_move_to(x, y),
        # tev.vg_line_to(x, y + height),
        # tev.vg_line_to(x + width, y + height),
        # tev.vg_line_to(x + width, y),
        # tev.vg_close_path(),
        tev.vg_stroke(),
    ])

Here's sample C++ code to draw a rectangle:

#include <tev/Ipc.h>
#include <tev/VectorGraphics.h>

using namespace tev;

Ipc ipc; // Will connect to running instance of tev if one exists
if (!ipc.isPrimaryInstance()) {
    IpcPacket packet;

    // Assumes that an image named "image" has been opened or created beforehand
    packet.setVectorGraphics("image", false, false, {
        VgCommand::begin_path(),
        VgCommand::rect(x, y, width, height),
        //Alternatively: draw rectangle manually
        // VgCommand::move_to(x, y),
        // VgCommand::line_to(x, y + height),
        // VgCommand::line_to(x + width, y + height),
        // VgCommand::line_to(x + width, y),
        // VgCommand::close_path(),
        VgCommand::stroke(),
    });
    ipc.sendToPrimaryInstance(packet);
}
mmp commented 1 year ago

Nice! That's an impressive amount of functionality available (Beziers even!). No immediate feedback but I'll think about uses of it (and try some experiments.) For the use case of nan/inf, I'd argue that tev is better placed to report those, since it has more flexibility in how it displays information and since it sees them just the same as the renderer. So I think the bigger value is from things that only the renderer knows; beyond "I just finished these pixels", I'll think more about other things like that that could be interesting...