aboutsummaryrefslogtreecommitdiff
path: root/sixel.c (follow)
Commit message (Collapse)AuthorAgeLines
* config: tweak.surface-bit-depth: add support for 16-bit surfacesDaniel Eklöf2025-05-03-1/+12
| | | | | | | | | This adds supports for 16-bit surfaces, using the new PIXMAN_a16b16g16r16 buffer format. This maps to WL_SHM_FORMAT_ABGR16161616 (little-endian). Use the new 16-bit surfaces by default, when gamma-correct-blending=yes.
* config: tweak.surface-bit-depth now defaults to 'auto'Daniel Eklöf2025-05-01-2/+2
| | | | | | | | | | | When set to 'auto', use 10-bit surfaces if gamma-correct blending is enabled, and 8-bit surfaces otherwise. Note that we may still fallback to 8-bit surfaces (without disabling gamma-correct blending) if the compositor does not support 10-bit surfaces. Closes #2082
* render: gamma-correct blendingDaniel Eklöf2025-03-05-16/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This implements gamma-correct blending, which mainly affects font rendering. The implementation requires compile-time availability of the new color-management protocol (available in wayland-protocols >= 1.41), and run-time support for the same in the compositor (specifically, the EXT_LINEAR TF function and sRGB primaries). How it works: all colors are decoded from sRGB to linear (using a lookup table, generated in the exact same way pixman generates it's internal conversion tables) before being used by pixman. The resulting image buffer is thus in decoded/linear format. We use the color-management protocol to inform the compositor of this, by tagging the wayland surfaces with the 'ext_linear' image attribute. Sixes: all colors are sRGB internally, and decoded to linear before being used in any sixels. Thus, the image buffers will contain linear colors. This is important, since otherwise there would be a decode/encode penalty every time a sixel is blended to the grid. Emojis: we require fcft >= 3.2, which adds support for sRGB decoding color glyphs. Meaning, the emoji pixman surfaces can be blended directly to the grid, just like sixels. Gamma-correct blending is enabled by default *when the compositor supports it*. There's a new option to explicitly enable/disable it: gamma-correct-blending=no|yes. If set to 'yes', and the compositor does not implement the required color-management features, warning logs are emitted. There's a loss of precision when storing linear pixels in 8-bit channels. For this reason, this patch also adds supports for 10-bit surfaces. For now, this is disabled by default since such surfaces only have 2 bits for alpha. It can be enabled with tweak.surface-bit-depth=10-bit. Perhaps, in the future, we can enable it by default if: * gamma-correct blending is enabled * the user has not enabled a transparent background
* config: add color.sixelN optionsDaniel Eklöf2024-10-23-36/+7
| | | | These options allows you to configure the default sixel color palette.
* sixel: default bg color is now taken from the sixel palette, not the ANSI bg colorDaniel Eklöf2024-09-05-33/+4
| | | | | | | | | | | | | | | | The wording in the original VT340 documentation is vague: Pixel positions specified as 0 are set to the current background color. What does that mean? We _thought_ it meant the current ANSI background color, as set with e.g. CSI 4x m. It's still all a bit vague, but seeing that we have separate palettes for text and graphic (should we?), it doesn't make sense to use the ANSI background color as the default sixel background color. So, use entry 0 from the sixel palette instead.
* term: performance: use a bitfield to track which ascii printer to useDaniel Eklöf2024-06-26-0/+11
| | | | | | | | | | | The things affecting which ASCII printer we use have grown... Instead of checking everything inside term_update_ascii_printer(), use a bitfield. Anything affecting the printer used, must now set a bit in this bitfield. This makes term_update_ascii_printer() much faster, since all it needs to do is check if the bitfield is zero or not.
* sixel: comment: document the P1 parameterDaniel Eklöf2024-05-22-1/+7
| | | | (and no, it's no longer unimplemented)
* sixel: don't allow pan/pad changes after sixel data has been emittedDaniel Eklöf2024-04-15-3/+23
| | | | | | | | | | | | | | | | | Changing pan/pad changes the sixel's aspect ratio. While I don't know for certain what a real VT340 would do, I suspect it would change the aspect ratio of all subsequent sixels, but not those already emitted. The way we implement sixels in foot, makes this behavior hard to implement. We currently don't resize the image properly if the aspect ratio is changed, but not the RA area. We have code that assumes all sixel lines have the same aspect ratio, etc. Since no "normal" applications change the aspect ratio in the middle of a sixel, simply disallow it, and print a warning. This also fixes a crash, when writing sixels after having modified the aspect ratio.
* sixel: also set 'alloc_height', when short-cutting a resize operationDaniel Eklöf2024-04-15-2/+5
| | | | | | | | | | In some cases, a sixel may be resized vertically, while still having a zero-width. In this case, the resize operations are short-cutted, and no actual allocations are done. However, we forgot to set 'alloc_height' when doing so. As a result, the trimming code (when the sixel is "done"), trimmed away the entire sixel.
* sixel: abuse wmemset() when initializing a freshly allocated image bufferDaniel Eklöf2024-03-25-36/+76
| | | | | | | | wmemset() is heavily optimized, and in some cases, *much* faster than manually initializing the new image pixels. Furthermore, assume calloc() is better at initializing memory to zero, and use that when initializing new pixels in a transparent image.
* sixel: fix cursor positioning when image is split up into severalDaniel Eklöf2024-03-18-1/+6
|
* sixel: hopefully handle image height correctly when trimmingDaniel Eklöf2024-03-18-4/+16
| | | | | | | | | | | When trimming trailing empty rows from the final image, handle the RA region correctly: * If image is transparent, trim down to the last non-empty pixel row, regardless of whether it is inside or outside the RA region. * If image is opaque, trim down to either the last non-empty pixel row, or the RA region, whatever is the largest height.
* sixel: RA region does not affect the text cursor positionDaniel Eklöf2024-03-18-2/+84
| | | | | | | | | | | | | | | | | | | | | | | The raster attributes is, really, just a way to erase an area. And, if the sixel is transparent, it's a nop. The final text cursor position depends, not on our image size (which is based on RA), but on the final graphical cursor position. However, we do want to continue using it as a hint of the final image size, to be able to pre-allocate the backing buffer. So, here's what we do: * When trimming trailing transparent rows, only trim the *image*, if the graphical cursor is positioned on the last sixel row, *and* the sixel is transparent. * Opaque sixels aren't trimmed at all, since RA in this acts as an erase that fills the RA region with the background color. * The graphical cursor position is always adjusted (i.e. trimmed), since it affects the text cursor position. * The text cursor position is now calculated from the graphical cursor position, instead of the image height.
* sixel: trim trailing, fully transparent sixel rowsDaniel Eklöf2024-03-18-11/+38
| | | | See https://github.com/hpjansson/chafa/issues/192
* sixel: place cursor on the last character row touched by the sixelDaniel Eklöf2024-03-18-12/+4
| | | | | | | | | | | | | | | | After emitting a sixel, place the cursor on the character row touched by the last sixel. The last sixel _may_ not be a multiple of 6 pixels, *if* the sixel had an explicit width/height set via raster attributes. This is an intended deviation from the DEC cursor placement algorithm, where the cursor is placed on the character row touched by the last sixel's *upper* pixel. The adjusted algorithm implemented here makes it much easier for applications to handle text-after-sixels, since they can now simply assume a single text newline is required to move the cursor to a character row not touched by the sixel.
* sixel: disable debug loggingDaniel Eklöf2024-03-16-1/+1
|
* sixel: initialize the color table to colors used by the VT340Daniel Eklöf2024-03-15-3/+36
|
* sixel: don't try to emit a sixel if we're outside the image's boundariesDaniel Eklöf2024-03-07-0/+3
| | | | Closes #1634
* sixel: debug: sixel image _may_ be zero-sizedDaniel Eklöf2024-03-07-1/+2
| | | | | For example, and single GNL (Graphical New Line) will result in a sixel with a non-zero height, but a zero width.
* sixel: we no longer need the extra newlineDaniel Eklöf2024-03-07-3/+2
| | | | Since we never place the cursor *under* the sixel anymore.
* sixel: debug: fix logged width/height values when emitting sixelDaniel Eklöf2024-03-07-1/+1
| | | | | image.width and image.height are the scaled dimensions, and these haven't been set when the log message is printed.
* sixel: performance improvementsDaniel Eklöf2024-03-06-28/+60
| | | | | | | | | | | | | * Store pointer to current pixel (i.e. pixel we're about to write to), instead of a row-byte-offset. This way, we don't have to calculate the offset into the backing image every time we emit a sixel band. * Pass data pointer directly to sixel_add_*(), to avoid having to calculate an offset into the backing image. * Special case adding a single 1:1 sixel. This removes a for loop, and simplifies state (position) updates. It is likely LTO does this for us, but this way, we get it optimized in non-LTO builds as well.
* sixel: fix row height calculation in resize_vertically()Daniel Eklöf2024-03-06-1/+2
| | | | | | | | | In resize_vertically(), we assumed a sixel is 6 pixels tall. This is mostly true, but not for non-1:1 sixels. Or, to be more precise, not for sixels where 'pan' != 1. This caused us to allocate too little backing memory, resulting in a crash when we later tried to write to the image.
* Don't use fancy Unicode quotes, stick to ASCIIDaniel Eklöf2024-02-06-8/+8
|
* sixel: erase: fix clearing of cell->attrs.cleanDaniel Eklöf2023-10-12-1/+1
| | | | | | | | | When erasing a sixel, the cells underneath it must be marked as 'dirty', in order to be re-rendered. This was not being done correctly; the for loop loops *from* the start col, meaning the *end* col is *not* sixel->pos.col, as that's the *number* of columns, not the *end* column.
* sixel: fix regression for DECGRI with a repeat count of 0CismonX2023-07-10-2/+10
|
* sixel: re-scale images when the cell dimensions changeDaniel Eklöf2023-06-30-71/+195
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this patch, when the cell dimensions changed (i.e. when the font size changes), sixel images were either removed (the new cell dimensions are smaller than the old), or simply kept at their original size (new cell dimensions are larger). With this patch, sixels are instead resized. This means a sixel *always* occupies the same number of rows and columns, regardless of how much the font size is changed. This is done by maintaining two sets of image data and pixman images, as well as their dimensions. These two sets are the new ‘original’ and ‘scaled’ members of the sixel struct. The "top-level" pixman image pointer, and the ‘width’ and ‘height’ members either point to the "original", or the "scaled" version. They are invalidated as soon as the cell dimensions change. They, and the ‘scaled’ image is updated on-demand (when we need to render a sixel). Note that the ‘scaled’ image is always NULL when the current cell dimensions matches the ones used when emitting the sixel (to save run-time memory). Closes #1383
* sixel: add_ar_11(): manually unroll loopDaniel Eklöf2023-06-29-7/+18
| | | | This generates both smaller, and faster code
* sixel: refactor: shorten very verbose switch case statementsDaniel Eklöf2023-06-29-53/+14
|
* sixel: special case parsing of images with an aspect ratio of 1:1Daniel Eklöf2023-06-29-22/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | Images with an aspect ratio of 1:1 are by far the most common (though not the default). It makes a lot of sense, performance wise, to special case them. Specifically, the sixel_add() function benefits greatly from this, as it is the inner most, most heavily executed function when parsing a sixel image. sixel_add_many() also benefits, since allows us to drop a multiplication. Since sixel_add_many() always called first (no other call sites call sixel_add() directly), this has a noticeable effect on performance. Another thing that helps (though not as much), and not specifically with AR 1:1 images, is special casing DECGRI a bit. Up until now, it simply updated the current sixel parameter value. The problem is that the default parameter value is 0. But, a value of 0 should be treated as 1. By adding a special ‘repeat_count’ variable to the sixel struct, we can initialize it to ‘1’ when we see DECGRI, and then simply overwrite it as the parameter value gets updated. This allows us to drop an if..else when emitting the sixel.
* sixel: assert upper pixel of last sixel maps to last image row, *or lower*Daniel Eklöf2023-06-24-0/+2
|
* sixel: ensure enough rows have been scrolled in, to fit the imageDaniel Eklöf2023-06-24-4/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When emitting a sixel, we need to: a) scroll terminal content to ensure the new image fits b) position the text cursor Recent changes in the cursor positioning logic meant we reduced the number of linefeeds, to ensure 1) sixels could be printed to the bottom row without scrolling the terminal contents, and 2) the cursor was positioned on the last sixel row. Except, we’re not actually positioning the cursor on the last sixel row. We’re positioning it on the text row that maps to the *upper* pixel of the last sixel. In most cases, this _is_ the last row of the sixel. But for certain combinations of font and image sizes, it may be higher up. This patch fixes a regression, where the terminal contents weren’t scrolled up enough for certain images, causing a crash when trying to dirty a not-yet scrolled in row. The fix is this: * Always scroll by the number of rows occupied by the image, minus one. This ensures the image "fits". * Adjust the cursor position, if necessary.
* sixel: resize(): handle no size changeDaniel Eklöf2023-06-24-0/+3
|
* sixel: regression: linefeed count for chunked up sixel imageDaniel Eklöf2023-06-24-1/+6
| | | | All image chunks but the last *should* scroll the screen content.
* sixel: minor fixes after implementing support for non-1:1 aspect ratiosDaniel Eklöf2023-06-24-17/+29
| | | | | | | * Lazy initialize image height. This is necessary to prevent garbage from being rendered for "empty" sixels. * Fix plotting of non-1:1 pixels * Fix calculation of height in resize(), for non-1:1 aspect ratios
* sixel: stop cropping images to the last non-transparent rowDaniel Eklöf2023-06-24-21/+0
|
* sixel: respect sixel aspect ratioDaniel Eklöf2023-06-24-14/+40
| | | | | | | | That is, parse P1 when initializing a new sixel, and don’t ignore pad/pad in the raster attributes command. The default aspect ratio is 2:1, but most sixels will override it in the raster attributes command (to 1:1).
* sixel: fix cursor positioning logicDaniel Eklöf2023-06-24-20/+17
| | | | | | | | | | | | | | | | | | This adjusts the logic that positions the text cursor after emitting a sixel, when sixel scrolling mode is *enabled*. We’ve always mimicked XTerm’s behavior. However, XTerm recently changed its behavior, to better match that of an VT382. Now, the cursor is placed *on* the last row of the sixel, instead of on a new row after the sixel. This allows applications to print sixels to the bottom row of the terminal, without causing the content to scroll. Finally, there was a bug in the horizontal positioning of the cursor; it was placed on the *first* column of the row, instead of on the first column of the sixel.
* sixel: apply background alpha when P2=0 or P2=2, and current bg color is the default bg colorDaniel Eklöf2023-05-31-4/+18
| | | | Closes #1360
* Tag a couple variables with UNUSED, to fix warnings with clang-15Daniel Eklöf2023-02-12-1/+1
| | | | Closes #1278
* sixel: don’t crash when sixel image exceeds current sixel max heightDaniel Eklöf2022-10-13-1/+1
| | | | | | | | | | | | When we try to resize a sixel past the current max height, we set col > image-width to signal this. This means ‘width’ could be smaller than ‘col’. When calculating how many sixels to emit in sixel_add_many(), we didnt’ account for this. The resulting value was -1, converted to ‘unsigned’. I.e. a very large value. This resulted in an assert triggering in sixel_add() in debug builds, and a crash in release builds.
* sixel: add sixel_reflow_grid()Daniel Eklöf2022-10-10-62/+66
| | | | | | | | | This function reflows all sixels in the specified grid. The pre-existing sixel_reflow() function is a shortcut for sixel_reflow_grid(term, &term->normal) sixel_reflow_grid(term, &term->alt);
* sixel/terminal: use the new grid and selection APIsDaniel Eklöf2022-04-25-31/+24
| | | | | | | Use grid_row_abs_to_sb() instead of manually “rebasing” row numbers. Use selection_get_{start,end}() to retrieve the current selection coordinates.
* sixel: revert to default state when an invalid DECGRI character is receivedDaniel Eklöf2022-02-04-0/+5
|
* sixel: DECGRI (repeat) with a count of 0 should emit a single sixelDaniel Eklöf2022-02-04-0/+2
|
* sixel: resize: truncate instead of failing, when new size exceeds max sizeDaniel Eklöf2022-02-04-13/+19
| | | | | If the size we’re trying to set exceeds the configured max size, truncate instead of failing.
* sixel: VT state’s bg color may now be an index, rather than an actual color valueDaniel Eklöf2021-12-26-3/+18
|
* term: track cell color sourceDaniel Eklöf2021-11-20-1/+1
| | | | | | | | | | | | | Each cell now tracks it’s current color source: * default fg/bg * base16 fg/bg (maps to *both* the regular and bright colors) * base256 fg/bg * RGB Note that we don’t have enough bits to separate the regular from the bright colors. These _shouldn’t_ be the same, so we ought to be fine...
* sixel: call decsixel() directly, instead of going through sixel_put()Daniel Eklöf2021-09-05-2/+2
|
* sixel: avoid looking up color from palette for each sixelDaniel Eklöf2021-09-05-3/+3
| | | | | | Instead, do the palette lookup when we receive the DECGCI (i.e. when the palette entry is selected), and store the actual color value in our sixel struct.
* sixel: calculate default bg once, in initDaniel Eklöf2021-09-05-15/+10
| | | | | | | | We have all information we need to calculate the default background color in sixel_init(): * Whether the image have transparency or not * The current ANSI background color
* sixel: destroy(): don’t unref a NULL pixman imageDaniel Eklöf2021-07-18-2/+3
|
* sixel: fix crash when splitting up an image across the scrollbackDaniel Eklöf2021-06-24-12/+10
| | | | | | | | | | | | | | | If an image was split up across the scrollback, and the first image chunk was resized due to it being blended with an already existing sixel, we crashed. The reason being the second chunk, emitted *after* the scrollback, tried to memcpy() image data from a now-free:d image buffer. The fix is pretty simple: create copies for *all* chunks when an image has to be split up across the scrollback. Previously, the first chunk re-used the source image buffer. Closes #608
* sixel: add support for overlapping sixelsDaniel Eklöf2021-06-09-17/+222
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Writing a sixel on top of an already existing sixel currently has the following limitations in foot: * The parts of the first sixel that is covered by the new sixel are removed, completely. Even if the new sixel has transparent areas. I.e. writing a transparent sixel on top of another sixel *replaces* the first sixel with the new sixel, instead of layering them on top of each other. * The second sixel erases the first sixel cell-wise. That is, a sixel whose size isn’t a multiple of the cell dimensions will leave unsightly holes in the first sixel. This patch takes care of both issues. The first one is actually the easiest one: all we need to do is calculate the intersection, and blend the two images. To keep things relatively simple, we use the pixman image from the *new* image, and use the ‘OVER_REVERSE’ operation to blend the new image over the old one. That is, the old image is still split into four tiles (top, left, right, bottom), just like before. But instead of throwing away the fifth middle tile, we blend it with the new image. As an optimization, this is only done if the new image has transparency (P1=1). The second problem is solved by detecting when we’re erasing an area from the second image that is larger than the new image. In this case, we enlarge the new image, and copy the old image into the new one. Finally, when we enlarge the new image, there may be areas in the new image that is *not* covered by the old image. These areas are made transparent. The end result is: * Each cell is covered by at *most* 1 sixel image. I.e. the total numbers of sixels are finite. This is important for the ‘mpv --vo=sixel’ use case - we don’t want to end up with thousands of sixels layered on top of each other. * Writing an opaque sixel on top of another sixel has _almost_ zero performance impact. Especially if the two sixels have the same size, so that we don’t have to resize the new image. Again, important for the ‘mpv --vo=sixel’ use case. Closes #562
* sixel: don’t *ever* shrink image below its SRA sizeDaniel Eklöf2021-05-16-6/+6
| | | | | | | | | | | | | | If the image was accompanied with a “Set Raster Attributes” (SRA) command, make sure we *never* shrink the image below the size specified in the SRA. Images are normally shrunk when their bottom rows are fully transparent. This enables sixels that aren’t a multiple of 6 to be emitted, without also emitting an SRA command. But if there *is* an SRA command, obey it. Verified against XTerm-367
* sixel: don’t emit sixels that will end up covering more than the entire scrollbackDaniel Eklöf2021-05-08-2/+16
| | | | | | | This limit can be reached by the sixel alone, or the sixel + the final newline. Closes #494
* sixel: fix assertion: image is allowed to cover the entire scrollbackDaniel Eklöf2021-05-08-1/+1
|
* sixel: unhook: tighten up the condition needed for us to free image data pre-maturelyDaniel Eklöf2021-04-07-5/+5
|
* sixel: sixel_fini(): free image dataDaniel Eklöf2021-04-07-0/+1
| | | | | Normally, this data is always free:d indirectly, when the sixel image that took over ownership is destroyed. But let’s play it safe.
* sixel: fix double free caused by bad free() in sixel_colors_set()Daniel Eklöf2021-03-30-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | sixel_color_set() is called when the number of (sixel) color registers is changed. It frees the current palette, and changes the “palette size” variable. Originally, we only had a single palette. This is the one free:d by sixel_color_set(). Later, we added support for private vs. shared palettes. With this change, we now have one palette that is “never” free:d (the shared one), and a private palette that is always free:d after a sixel has been emitted. ‘sixel.palette’ is a pointer to the palette currently in use, and should only be accessed **while emitting a sixel**. This is the pointer sixel_color_set() free:d. So for example, if ‘sixel.palette’ pointed to the shared palette, we’d free the shared palette. But, we didn’t reset ‘sixel.shared_palette’, causing a double free later on. Closes #427
* sixel: free backing buffer if final image size is zeroDaniel Eklöf2021-03-28-0/+5
|
* sixel: initialize max_non_empty_row_no to -1, not 0Daniel Eklöf2021-03-28-3/+7
| | | | | | | | | | | | | 0 is a perfectly valid row number, and if max_non_empty_row_no==0, that means we have *1* sixel row, and after trimming the image, the image will have a height of 6 pixels. If the sixel sequence is empty (or at least doesn’t emit any non-empty pixels), then trimming the image should result in an image height of 0. When max_non_empty_row_no is initialized to -1, it will still have that value in unhook(), which makes the final image height 0.
* term: runtime switch between a ‘fast’ and a ‘generic’ ASCII print functionDaniel Eklöf2021-03-16-0/+7
| | | | | | | | | | | | | | | | | | | | | | | term_print() is called whenever the client application “prints” something to the grid. It is called for both ASCII and UTF-8 characters, and needs to handle sixels, insert mode and ASCII vs. graphical charsets. Since it’s on the hot path, this becomes unnecessarily slow. This patch adds a “fast” version of term_print(), tailored for the common case: ASCII characters in non-insert mode, without any sixels and non-graphical charsets. A new function, term_update_ascii_printer(), has been added, and must be called whenever: * The currently selected charset *index* changes * The currently selected charset changes (from ASCII to graphical, or vice verse) * Sixels are added to the grid * Sixels are removed from the grid * Insert mode is enabled/disabled
* sixel: sixel_overwrite_at_cursor(): early exit when the image list is emptyDaniel Eklöf2021-03-14-0/+3
| | | | | | | | This avoids a call to sixel_overwrite_by_row() (where we also exit early if the image list is empty). This saves a couple of instructions to set up the arguments for sixel_overwrite_by_row().
* sixel: max geometry should be max geometry, not current window sizeDaniel Eklöf2021-03-14-2/+2
| | | | | | | | | “current geometry” will report whatever value is the smallest; the max geometry or the current window size. But “max geometry” always returns the configured max geometry. This aligns foot’s behavior with XTerm.
* sixel: implement P2=1 - transparent pixelsDaniel Eklöf2021-03-11-17/+36
| | | | | | | | | | | | | | | | | | | | | | | | When P2=1, empty pixels are transparent. This patch also changes the behavior of P2=0|2, from setting empty pixels to the default background color, to instead use the *current* background color. To implement this, a couple of changes are needed: * Sixel pixels always use alpha=1.0, except for *empty* cells when P2=1 (i.e. transparent pixels). * The renderer draws sixels with the OVER operator, instead of the SRC operator. * The renderer *must* now render the cells beneath the sixel. As an optimization, this is only done for sixels where P2=1. I.e. for fully opaque sixels, there’s no need to render the cells beneath. The sixel renderer isn’t yet hooked into the multi-threaded renderer. This means *rows* (not just the cells) beneath maybe-transparent sixels are rendered single-threaded. Closes #391.
* sixel: decgra: set max-non-empty-row-no when resizing the imageDaniel Eklöf2021-03-11-0/+1
| | | | | | | | | | | | | This ensures we don’t trim off bottom rows in unhook(). This could happen either because the application used “Set Raster Attributes” to configure an image size larger than the sixels later emitted. Or, the last sixel row contains empty pixel rows. In either case, the size set with “Set Raster Attributes” defines the *minimum* image size; the image may still end up being larger.
* sixel: decgri: handle a repeat count of 0, by ignoring itDaniel Eklöf2021-03-11-2/+11
|
* sixel: add: add sixel_add_many(), improving performance of DECGRIDaniel Eklöf2021-03-11-24/+27
| | | | | | | | | | | DECGRI, i.e. repeat sixel character, only need to do image resizing, and updating the current ‘column’ value *once*. By adding sixel_add_many(), and doing the size/resize checking there, the performance of sixel_add() is made much simpler. This boosts performance quite noticeably when the application is emitting many and/or long repeat sequences.
* sixel: add: calculate absolute row no inside the loopDaniel Eklöf2021-03-11-2/+3
| | | | | | This results in the same number of instructions inside the loop, with a ‘lea’ instead of a ‘mov’, but simplifies the post-loop logic to update the global state.
* sixel: add: increase data pointer instead of offsetDaniel Eklöf2021-03-11-3/+3
| | | | | Same ‘add’ instruction to increase the offset, but simpler ‘mov’ instruction when writing the pixel data.
* sixel: decgri: avoid load inside for-loopDaniel Eklöf2021-03-11-1/+2
|
* sixel: add optimized resize_horizontally() and resize_vertically()Daniel Eklöf2021-03-11-2/+78
| | | | | The resize operations performed in the “hot” path either change the width, or the height, but not both at the same time.
* sixel: empty pixels in the last sixel row doesn’t contribute to the image heightDaniel Eklöf2021-03-11-1/+17
| | | | | | | | | | | | | | All-empty pixels rows in the last sixel row should not be included in the final sixel image. This allows applications to emit sixels whose height is not a multiple of 6, and is how XTerm works. This is done by tracking the largest row number that contains non-empty pixels. In unhook, when emitting the image, the image height is adjusted based on this value.
* sixel: resize: width is no longer a multiple of 6Daniel Eklöf2021-03-11-16/+4
|
* sixel: set ‘col’ outside image boundaries when we’ve reached max heightDaniel Eklöf2021-03-11-3/+13
| | | | | | | | | | | | | | This is to optimize sixel_add(). It already checks ‘pos’, to see if it needs to resize the image, and if the resize fails (either due to allocation failures, or because we’ve reached the maximum width), we bail out. We need to do the same thing for height. But, we don’t want to add another check to sixel_add() since its’s performance critical. By setting ‘col’ outside the image boundaries when ‘row’ reaches the maximum image height, we can “re-use” the existing code in sixel_add().
* sixel: remove ‘max_col’Daniel Eklöf2021-03-11-12/+3
| | | | The image width *is* the maximum number of columns we’ve seen.
* sixel: adjust image height when processing ‘-’Daniel Eklöf2021-03-11-8/+8
|
* sixel: resize: check new width/height against max geometry earlyDaniel Eklöf2021-03-11-9/+9
|
* Revert "sixel: resize: always round up height to a multiple of 6"Daniel Eklöf2021-03-11-4/+6
| | | | | | | | | | | | | | | | | | | | | | | This reverts commit 5a9d70da837c20a9641d6cbadccc962a8e5a4283. This broke jexer. Comparing with what XTerm does, we can see that it updates its image height for *each* pixel in *each* sixel. I.e. empty pixels at the bottom of a sixel will not increase the image size. Foot currently bumps the image height 6 pixels at a time, i.e. always a whole pixel. Given this, always rounding up the height to the nearest multiple of 6 (say, for example, when responding to a DECGRA command), is wrong. Now, we use the image size specified in DECGRA as is, while still allowing the image to grow beyond that if necessary. What’s left to do, if we want to behave *exactly* like XTerm, is stop growing the image with 6 pixels at a time when dynamically adjusting the image size.
* sixel: add: use de-reference the term struct for each access to the backing imageDaniel Eklöf2021-03-11-7/+10
|
* sixel: get rid of an ‘imul’ in sixel_add()Daniel Eklöf2021-03-11-2/+4
| | | | | | | | By storing the current row’s byte offset into the backing image in the terminal struct. This replaces the ‘imul’ with a load, which can potentially be slow. But, this data should already be in the cache.
* sixel: add: resize is already checking against the current max geometryDaniel Eklöf2021-03-11-6/+0
|
* sixel: resize: don’t resize beyond the current max geometryDaniel Eklöf2021-03-11-0/+14
|
* sixel: unhook: make sure image height is within boundsDaniel Eklöf2021-03-11-0/+4
| | | | | | | | When we allocate the backing buffer, the number of allocated rows is a multiple of 6. When persisting the image, make sure its height does not exceed the current maximum height.
* sixel: add: simplify check for resize neededDaniel Eklöf2021-03-11-1/+1
| | | | | Since the image height is always a multiple of 6, there’s no need to round up the image height.
* sixel: resize: always round up height to a multiple of 6Daniel Eklöf2021-03-11-6/+4
| | | | Sixels are always a multiple of six.
* sixel: fixup row is multiple of 6Daniel Eklöf2021-03-11-1/+1
|
* sixel: calculate alpha when updating the paletteDaniel Eklöf2021-03-11-9/+6
| | | | | Calculate color, with alpha, when updating the palette instead of every time we *use* the palette.
* sixel: pre-calculate color before calling sixel_add()Daniel Eklöf2021-03-11-3/+11
| | | | | This improves performance of DECGRI, since we now only need to calculate the color once for the entire repeat sequence.
* sixel: ignore invalid sixel characters in DECGRI (repeat)Daniel Eklöf2021-03-11-1/+11
|
* sixel: avoid multiplication inside the inner sixel emitter loopDaniel Eklöf2021-03-11-6/+6
|
* sixel: store current row position in pixels, not charactersDaniel Eklöf2021-03-11-6/+5
|
* sixel: size provided by DECGRA does *not* limit the sixel sizeDaniel Eklöf2021-03-06-6/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Foot has, up until now, used a fixed image size when the application used DECGRA (Raster Attributes) to “configure” the image size. This was based on a misunderstanding, that this was how you emitted sixels where the height was *not* a multiple of 6. This isn’t the case. The VT340 documentation is actually pretty clear about this: Ph and Pv do not limit the size of the image defined by the sixel data. However, Ph and Pv let you omit background sixel data from the image definition and still have a color background. They also provide a concise way for the application or terminal to encode the size of an image. This is also how XTerm behaves. Test image: \EPq "1;1;1;1 #0;2;0;0;0#1;2;100;100;0#2;2;0;100;0 #1~~@@vv@@~~@@~~$ #2??}}GG}}??}}??- #1!14@ \E\ This uses DECGRA to set the image size to 1x1. The sixel however is *not* clipped to 1x1, but is resized to 14x12
* sixel: don’t go past the bottom scroll margin when sixel scrolling is disabledDaniel Eklöf2021-02-26-1/+1
| | | | | | | | When sixel scrolling is disabled (private mode 80 is off), and scroll margins have been set, XTerm seems to ignore the top margin (sixel still begins at (0,0)), but does not go past the bottom margin. This patch implements the same behavior in foot.
* sixel: implement private mode 80 - sixel scrollingDaniel Eklöf2021-02-26-38/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When enabled (the default), sixels behave much like normal output; the start where the cursor is, and the cursor moves with the sixel. I.e. after emitting a sixel the cursor is left after the image; either to the right, if private mode 8452 is enabled, or otherwise on the next line. Terminal content is scrolled up if the sixel is larger than the screen. When disabled, sixels *always* start at (0,0), the cursor never moves, and the terminal content never scrolls. In other words, the ‘disabled’ mode is a much simpler mode. All we need to do to support both modes is re-write the sixel-emitting loop to: * break early if we’re “out of rows”, i.e. we’ve reached the bottom of the screen. * not linefeed, or move the cursor when scrolling is disabled This patch also fixes a bug in the (new) implementation of private mode 8452. When emitting a sixel, we may break it up into smaller pieces, to ensure a single sixel (as tracked internally) does not cross the scrollback wrap-around. The code that checked if we should do a linefeed or not, would skip the linefeed on the last row of *each* such sixel piece. The correct thing to do is to skip it only on the last row of the *last* piece. I chose not to fix this bug in a separate patch since doing so would have meant re-writing it again when implementing private mode 80.
* sixel: implement private mode 8452 - cursor positioning after sixelDaniel Eklöf2021-02-23-2/+22
| | | | | | | | | | When disabled (the default), the cursor is positioned on a new line after emitting a sixel image. When enabled, the cursor is positioned to the right of the sixel image. Closes #363
* sixel: free private color registers on unhookDaniel Eklöf2021-02-23-11/+6
|
* sixel: implement private mode 1070 - private color paletteDaniel Eklöf2021-02-23-6/+26
| | | | | | | | | When enabled (the default), sixels use private color registers. That is, the color palette from the last sixel is *not* re-used. When disabled, sixels share (i.e. re-use) the same color palette. Closes #362
* debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes2021-01-16-35/+35
|