about summary refs log tree commit diff stats
path: root/adapter
Commit message (Collapse)AuthorAgeFilesLines
* sixel: reset chunk on transparencybptato2024-09-271-0/+1
| | | | this was causing weird artifacts
* term: prevent negative line damage, fix off by onebptato2024-09-251-2/+6
|
* sixel: support transparencybptato2024-09-241-33/+38
| | | | | | | | | | | | | | | | | | Sixel can only represent transparency for fully transparent (alpha = 0) and fully opaque (alpha = 255) pixels, i.e. we would have to do blending ourselves to do this "properly". But what do you even blend? Background color? Images? Clearly you can't do text... So instead of going down the blending route, we now just approximate the 8-bit channel with Sixel's 1-bit channel and then patch it up with dither. It does look a bit weird, but it's not *that* bad, especially compared to the previous strategy of "blend with some color which hopefully happens to be the background color" (it rarely was). Note that this requires us to handle transparent images specially in term. That is, for opaque ones, we can leave out the "clear cells affected by image" part, but for transparent ones, we must clear the entire image every time.
* Replace std/selectors with pollbptato2024-09-231-19/+16
| | | | | | | | | | | | std/selectors uses OS-specific selector APIs, which sounds good in theory (faster than poll!), but sucks for portability in practice. Sure, you can fix portability bugs, but who knows how many there are on untested platforms... poll is standard, so if it works on one computer it should work on all other ones. (I hope.) As a bonus, I rewrote the timeout API for poll, which incidentally fixes setTimeout across forks. Also, SIGWINCH should now work on all platforms (as we self-pipe instead of signalfd/kqueue magic).
* loader: mmap intermediate image files, misc refactoringbptato2024-09-227-74/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | * refactor parseHeader * optimize response blob() * add direct "to cache" mode for loader requests which sets stdout to a file, and use it for image processing * move image resizing into a separate process * mmap cache files in between processing steps when possible At last, resize is no longer a part of image decoding. Also, it feels much nicer to keep encoded image data in the same cache as everything else. The mmap operations *should* be more efficient than copying the whole RGBA data through a pipe. In practice, it only makes a difference for loading (well, now just mmapping) the encoded image into the pager, where it singlehandedly speeds up image display by 10x on my test image. For the other steps, the unfortunate fact that "tocache" must delay the next fork/exec in the pipeline until the entire image is processed seems to equal out any wins we might have gotten from skipping a single raw RGBA copy. I have tried moving the delay before the exec (it's possible with yet another pipe), but it didn't help much and made the code much uglier. (Not that tocache didn't, but I can live with this...)
* Refactor img/*bptato2024-09-151-5/+225
| | | | | I've moved most image logic to adapter, so it doesn't really make sense to have this subdir anymore.
* sixel: do not reserve palette entry for transparencybptato2024-09-121-8/+11
| | | | | | | | | Turns out this isn't actually needed. Which makes sense, as transparency doesn't have a color register at all - it's just the default state of pixels. Also, skip octree-based quantization with palette <= 2; unsurprisingly, monochrome gives much better results.
* sixel: factor out root node, fix a bugbptato2024-09-121-30/+31
|
* sixel: small optimizationsbptato2024-09-111-31/+48
| | | | | | | | * Reduce unnecessary branch allocation even more * Use linked lists to represent sixel bands Also inlined octree-based getColor for clarity, although the compiler was already doing that.
* sixel: faster quantizationbptato2024-09-111-80/+92
| | | | | | | | | | | Reduce eager allocation of whole branches for leaves; now it's done only after the first conflict (or repeated color). This makes quantization ~2x faster for images without large runs of the same color and ~2x slower for images with a lot of those. No noticeable loss in quality. I also disabled refc for the octree and turned the nodes into tagged unions, which again resulted in a ~2x speedup.
* sixel: misc optimizationsbptato2024-09-091-42/+43
|
* sixel: small optimizationbptato2024-09-081-29/+27
| | | | | | For large palettes, looping over the entire chunk list is quite slow. Store the list of active chunks in a separate sequence so we can skip the unused ones.
* md2html: code, pre, inline fixesbptato2024-09-071-120/+193
|
* term: sixel sizing & output fixesbptato2024-09-051-7/+7
| | | | | | | | | | | | * round down to number divisible by 6 for height * make pager's dispw match term's dispw even after width clamping * make *BE procs actually emit/consume big-endian (lol) * fix borked sixel set raster attributes & control string I mixed up SRA with the device control string's parameters, so instead of toggling transparency in the DCS, I was setting the second SRA parameter to 0. Which, by the way, defines the aspect ratio's denominator, and has nothing to do with transparency. Whoops.
* sixel, stbi, sandbox: fix fstat sandbox violationbptato2024-09-042-50/+44
| | | | | | | Until recently, glibc used to implement it as fstatat. So don't trap for fstatat (and for consistency, fstat), but return EPERM. Just to be sure, rewrite sixel & stbi to never call fread.
* md2html: misc inline fixesbptato2024-09-011-114/+160
| | | | | * fix whitespace-surrounded asterisk turning into emphasis * slightly refactor parseInline (it's still quite ugly...)
* sixel: special case search for few color registersbptato2024-09-011-17/+58
| | | | | | See comment for details. (Also, set the palette size based on quality for toBlob.)
* canvas: make sure we don't link to QJSbptato2024-09-011-2/+1
|
* canvas: move to separate CGI scriptbptato2024-09-013-3/+148
| | | | | | | | | | * stream: and passFd is now client-based, and accessible for buffers * Bitmap's width & height is now int, not uint64 * no more non-network Bitmap special case in the pager for canvas I just shoehorned it into the static image model, so it still doesn't render changes after page load. But at least now it doesn't crash the browser.
* sixel: fix oobbptato2024-08-301-3/+2
| | | | whoops
* term, sixel: misc image fixes, sixel optimizationbptato2024-08-301-55/+97
| | | | | | | | * expand allowed color range somewhat * update maximum sixel size on window resize * fix kitty image cropping * use faster algorithm for sixel compression (also produces less wasteful output)
* md2html: support blockquotebptato2024-08-302-10/+28
| | | | + update todo, readme
* sixel: ditheringbptato2024-08-291-42/+73
| | | | | | | | | | | | | uses floyd-steinberg - I originally tried atkinson, but liked the results with fs a bit more. also, I got rid of the half hearted attempt to skip tree traversals for color lookups, as it performs horribly with dithering. it *did* work if I set Y as the key, but it still felt wrong - well, as it turns out, octree traversal is faster anyway, so just do that. it works out nicely because we can fill in holes (from dithering) with a linear search for the nearest match as we go.
* sixel: fix borked approximation schemebptato2024-08-291-41/+29
| | | | | | | | | | | ok, of course if you search for the nearest entry after setting blue as the lowest index bits the search will be biased towards blue... let's just skip the trouble of reconstructing closest color relations by storing hashes in the octree - this way, I can ensure that the final merged colors are present in the buckets that getColor then looks at (while we're at it, also fix the color run merging code in quantize.)
* sixel: minor optimizationsbptato2024-08-281-51/+86
| | | | | | * don't emit transparency request when we don't need it * add lookup table for missing hash entries * write(2)'ize
* sixel, term: fix off-by-1's in croppingbptato2024-08-281-2/+6
| | | | & clean up outputSixelImage in general
* sixel: proper color quantizationbptato2024-08-271-37/+215
| | | | | | | | just use an octree. works fine afaict, though obviously somewhat slower than the static method (encoding is 2-pass now) & still has banding issues with many colors (will need dithering) also, fixed a bug that caused initial masks of bands to get misplaced
* stbi, jebp: use read/write instead of fread/fwritebptato2024-08-263-61/+131
| | | | | | | | glibc likes to do weird things (such as calling stat) when you use fread(3) and friends, so try to use functions that are more likely to just do a single syscall. Also, copy over some more paranoid read/write procedures to http.
* sixel: break out into a separate cgi scriptbptato2024-08-241-0/+202
| | | | | | | | This caches sixel output. Works best when the line height is a multiple of 6px, but should still be faster than the previous solution everywhere else too (simply by virtue of encoding separate images in parallel). Next step: actual color quantization
* urldec: merge into urlencbptato2024-08-112-22/+18
| | | | also, move the ln command to make all
* md2html: label headings with their levelbptato2024-08-111-1/+2
| | | | like sr.ht does
* loader: move back data URL handlingbptato2024-08-031-32/+0
| | | | | | | data URIs can get megabytes long; however, you can only stuff so many bytes into the envp. (This was thwarting my efforts to view pandoc- generated standalone HTML in Chawan.) So put `data:' back into the loader process.
* buffer, pager, config: add meta-refresh + misc fixesbptato2024-07-281-1/+1
| | | | | | | | | * buffer, pager, config: add meta-refresh value, which makes it possible to follow http-equiv=refresh META tags. * config: clean up redundant format mode parser * timeout: accept varargs for params to pass on to functions * pager: add "options" dict to JS gotoURL * twtstr: remove redundant startsWithNoCase
* jebp: fix NEON simd bugbptato2024-07-231-1/+1
| | | | | | SRCtype and DSTtype were mixed up. See https://todo.sr.ht/~bptato/chawan/14
* img: add webp decoder (jebp)bptato2024-07-203-0/+4852
| | | | | | | | | | It works fine AFAICT, just missing VP8 deblocking filters, so lossy WebP images don't look great. I have extended the API a bit to allow reading from stdin, not just paths. Otherwise, it's the same as matanui159/jebp. TODO: add loop filters
* stbi: fix incompatible function pointer typebptato2024-07-181-2/+2
| | | | clang complains about this
* img, makefile: remove png, update uninstall targetbptato2024-07-031-553/+0
|
* pager: PNGify kitty images, clear images on buffer switchbptato2024-07-021-2/+10
| | | | | | | | | | | Saves bandwidth; it's especially useful over SSH. Still not sure if this is the right solution, since it now needs two select cycles instead of one, and it does yet another copy of the image. (Unnecessarily, because stbi cannot stream its output, and stbiw cannot stream its input.) Also, to save memory, we now discard decoded images of buffers that are not being viewed.
* stbi: fix broken allocation in resizingbptato2024-06-291-1/+1
| | | | ;_;
* img, loader: add image resizing, misc fixesbptato2024-06-283-10/+2688
| | | | | | | | | | | | | | | * resize images with stb_image_resize * use tee for output handle redirection (redirectToFile blocks) * cache original image files * accept lseek in sandbox * misc stbi fixes For now, I just pulled in stb_image_resize v1. v2 is an extra 150K in size, not sure if it's worth the cost. (Either way, we can always switch later if needed, since the API is almost the same.) Next step: move sixel/kitty encoders to CGI, and cache their output in memory instead of the intermediate RGBA representation.
* stbi: allow x-unknownbptato2024-06-221-1/+1
|
* stbi: add encodersbptato2024-06-213-17/+1807
|
* img: use stb_image, drop zlib as dependencybptato2024-06-204-19/+8087
| | | | | | | Now we have decoders for gif, jpeg, bmp. Also, the in-house PNG decoder has been replaced in favor of the stbi implementation; this means we no longer depend on zlib, since stbi comes with a built in inflate implementation.
* img, loader: separate out png codec into cgi, misc improvementsbptato2024-06-201-0/+544
| | | | | | | | | | | | | | | * multi-processed and sandboxed PNG decoding & encoding (through local CGI) * improved request body passing (including support for output id as response body) * simplified & faster blob()/text() - now every request starts suspended, and OngoingData.buf has been replaced with loader's buffering capability * image caching: we no longer pull bitmaps from the container after every single getLines call Next steps: replace our bespoke PNG decoder with something more usable, add other decoders, and make them stream.
* Move JS wrapper into Monouchabptato2024-06-031-6/+2
| | | | Operation "modularize Chawan somewhat" part 3
* js: improve jsregex interfacebptato2024-06-031-71/+63
| | | | | | | It's easier to just use nested seqs here. (This also fixes reverse-search highlighting the last capture group instead of the whole match.)
* md2html: include numbers in idsbptato2024-06-031-3/+3
|
* about: markdownify & update license.htmlbptato2024-05-281-6/+6
| | | | We have a markdown converter, so why not use it?
* http: allow multiple early hintsbptato2024-05-221-1/+1
|
* man: quote keyword & sectionbptato2024-05-221-5/+5
|