Skip to content

image position/extend addressing mode and metrics #13

@jerch

Description

@jerch

For placing and sizing an image there are different ways/metrics possible.

preliminary considerations

As prior art we only have the SIXEL way, plus the newer SIXEL implementations (somewhat broken in this regard).

The SIXEL way:

  • initial position is determined either by origin of active text cell (SIXEL_SCROLL=on) or as origin of viewport (SIXEL_SCROLL=off)
  • image comes with size in pixels
  • a pixel maps to a certain screen extend based on inch (has similarities to pt in CSS)
  • screen extend setting is provided in every sequence
  • text cells itself are meant to be sized in that screen extend as a fixed width/height ratio

Newer SIXEL implementations ignore these settings and instead map pixels 1:1 to screen pixels. While this enables pixel perfect output, it makes autoscaling based on certain TE settings impossible.

To not end up in the same trap, we need to find a good metrics abstraction, that tries to respect:

  • preserve text-image proportions across different font sizes (cell coverage must not change)
  • preserve inner image proportions (a drawn circle may not reshape into an ellipsis), this is actually a hard one for font size changes, that dont scale perfectly proportional in 1:2 and prolly needs a keepAspectRatio on the sequence.
  • sequence may not change due to changed font size in TE
  • How about subcell addressing?

In a TE we basically have these dimensions given:

  • viewport extend in number of cells (COLS x ROWS)
  • final TE with output representation: cell size in screen pixels (close to font-size/2 : font-size)
  • multiplexer: no predefined cell size (not yet?)

means we have only 2 reliable metrics we can count on - a cell as base unit or the viewport extend in terms of number of cells.

Proposal 1: relative positioning and sizing to cell size

A naive way to deal with the limited entry metrics we have, is to derive all positioning and extend calculations only on discrete cells:

  • origin: at current active cell (top-left corner) or given by some xy values denoting cells
  • extend: number of cells in xy direction (bottom-right corner)
  • image scales in either direction to fit (plus a keepAspectRatio flag and align modes for images that should preserve image proportions)
  • no explicit image pixel to screen pixel relation (gets implicit calculated by the extend and alignment settings)
  • easy to comprehend for app devs - everything gets scaled in terms of text cells
  • ✔️ preserves cell coverage
  • ✔️ preserves image proportions with keepAspectRatio flag
  • ✔️ sequence is stable across font size changes
  • ❌ no direct subcell addressing possible (still can be faked by offsetting the pixels in the image, but unreliable due to unknown cell extend in the first place)

To also allow subcell addressing, this approach could be extended in a way to also address fractions of a cell. If done as float values, the size notions will behave pretty much like rem in CSS, with the difference of having distinct bases for width (1 = one text cell width) and height (1 = one text cell height). But not sure yet, if we really need subcell addressing at all.

Proposal 2: absolute positioning and pixel sizing in terms of a custom unit

Implement something similar to SIXEL's way with units and explicit pixel sizing:

  • image pixel: some size in terms of units
  • text cell size: some size in terms of units
  • origin: at current active cell (upper-left corner) or given by some xy values denoting unit offset from top-left of viewport
  • extend: not explicitly set (uses image pixels instead)
  • changing font size: image pixels are resized in terms of units, keeping cell size stable
  • again a keepAspectRatio flag and align modes can indicate, whether to keep image proportions.
  • ✔️ preserves cell coverage (given if cell size is kept stable)
  • ✔️ preserves image proportions with keepAspectRatio flag
  • ✔️ sequence is stable across font size changes
  • ✔️ allows stable direct subcell addressing, since we have a virtual cell size defined prehand

Pros & Cons

  • ease of implementation
    On a first glance, 1.) seems to be much easier to implement, even with float numbering. Ofc floats cannot be expressed in sequence params directly, thus would need some thinking/shaping (maybe with sub params like ... ; 30 : 2 ; ... for 30,2). Proposal 2.) seems slightly more complicated to implement, as it needs an additional indirection over the virtual unit. Same with keepAspectRatio - it needs an additional correction calculation to level stretching artefacts from the base pixel size.
  • ease of usage
    Imho proposal 1.) is easier to grasp by app devs, as the basic metrics is in terms of text cells. Furthermore 1.) does not need any image transformation at all if we always expect image extend values on the sequence. For 2.) the image has to be converted into new pixel dimensions to fit the right extend on the TE. If the text cell size in units shall be configurable, the app furthermore needs to know that size prehand.
  • flexibility
    Proposal 2.) is more flexible, as it would allow to redefine text cell and image pixel size in units. This additional indirection make perfect up/down scaling much easier. But it still shares the same problems as 1.) when font size changes dont scale perfectly in a stable ratio.
  • multiplexer
    Both proposals should work with multiplexers. 1.) has the disadvantage to treat an image as a whole without knowing, how image pixels map to cells, while 2.) would allow to slice parts of the image (certain pixel areas).

There might be other proposals or variants of the two above, that make more sense in the end. Plz lets discuss the details (sorry for so much texting) 😸

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions