Repository navigation
Zorg.Pdf's gaps: memory inputs, ShrinkTo, Convert, IsOpaque, and an experimental canvas - #19
Merged
Merged
Conversation
A file inside a larger buffer no longer has to be copied into its own array. The byte[] methods forward to the new ones; RS0026 is suppressed with the reason, since no argument converts equally well to both. Doc crefs name the byte[] overloads.
Maps a public box to the internal shrink target the pipeline already sets, using the same Inside fit, so Decode with ShrinkTo then Fit gives the pipeline's pixels. The pipeline's own target still wins. Decoding never resizes: formats without a reduced decode come out at full size.
Convert changes the pixel layout: 8 to 16 bits and back exactly, grey by Rec. 709 luma, alpha dropped only when every pixel is opaque (otherwise it throws and points at Flatten). Vector paths for the common 8-bit pairs, 16-bit RGBA rows for the rest. IsOpaque scans alpha, stopping at the first chunk with a translucent pixel. Nothing in the library calls either, so no existing output or timing changes.
Zorg.Imaging.Drawing: Shape (lines, quadratic and cubic curves), Canvas with Fill, FillRectangle, Clear, a transform and a clip rectangle, both fill rules. Coverage is exact pixel area by signed-area accumulation; colours blend in the stored values, as PDF viewers do. Marked [Experimental("ZORGDRAW")] so it can still change or move to its own package. Nothing existing calls it; the AOT smoke binary is unchanged in size.
Stroke builds the area a round pen covers: a rectangle per line, a wedge on the outer side of each corner and half a disc at each end, wound alike and filled non-zero. The wedges' straight edges lie on the rectangles' ends and cancel them, so the outer edge doesn't double-count coverage. Widths scale with the transform; MinimumStrokeWidth keeps hairlines visible.
DrawImage fills the image's transformed rectangle, so its edges are anti-aliased, and samples each covered pixel through the inverse transform: bilinear and premultiplied, or nearest as blocks. An image drawn smaller is resized first with the core Resize. The image must share the canvas's colour space.
The smoke test draws a shape, a stroke and an image under Native AOT. A/B timings of the JPEG thumbnail, PNG decode and JPEG and PNG encodes on main and this branch are within noise.
… oracle - Clear copies whole rows; 8-bit layouts blend in their own loops; rows of coverage reach the painter through a generic struct, so a page of glyphs allocates nothing. A4 page of 3,000 glyphs: 22.8 ms to 14.7 ms (Skia 15.6). - Tall fills render in bands: working memory at most 4 MB at any size. - A stroke's segments end at their inner corner instead of overlapping, as an overlap was counted twice in the pixels it crossed. - rsvg-convert in the Alpine gate: fills and strokes checked against cairo's coverage (ink within 0.3 % and 0.5 %, every 4 x 4 block within a third of a pixel for fills). - CanvasBenchmarks times the page against SkiaSharp.
- The pipeline ignores DecodeOptions.ShrinkTo: its own steps decide, so a pipeline that crops first decodes at full size again (it cropped the wrong region, or threw). - Rows of a fill take their x from the line's equation, not by stepping: long edges were off by up to 2.6/255 at their far end, and differed between bands and clips. - Stroke: a lone MoveTo paints nothing, as in PDF and SVG; points too close for a float to give a direction make a dot instead of throwing; a pen narrower than MinimumStrokeWidth in every direction is drawn that wide in pixels, so stretched transforms keep hairlines one pixel wide. - Gentle corners (curves cut into lines) are mitred on the outer side too, without a round wedge: the bold page takes 55 ms instead of 81.5 (Skia 48.7). - An overflowing transform is refused whether it ends in an infinity or NaN, FillRectangle included; DrawImage refuses the canvas's own image; Clear and Convert check for disposal before anything else.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Zorg.Pdf's report asked of the library (its
05-zorg-imaging-gaps.md): ways to read an image inside a larger buffer, shrink on load without the pipeline, change pixel layout, tell whether alpha is used, and a canvas to draw page previews. Nothing the library already did runs differently; the everyday paths were timed before and after (docs/performance.md).New calls
Image.Decode,Image.Identify,AnimationReader.OpenandImagePipeline.LoadtakeReadOnlyMemory<byte>; thebyte[]versions forward to them.DecodeOptions.ShrinkTo: shrink-on-load forImage.Decode. A 4000 x 3000 JPEG to 400 x 300: 43 ms instead of 132. A pipeline ignores it; its own steps decide.Image.Convert(PixelFormat)(refuses to drop alpha that's in use, pointing toFlatten) andImage.IsOpaque(). RGBA to RGB at 12 MP: 5.9 ms.The canvas (
Zorg.Imaging.Drawing, marked[Experimental("ZORGDRAW")]so it can still change or move to its own package)Resize.Checks
ArgumentException.rsvg-convert: fills and strokes against cairo (total ink within 0.3 % and 0.5 %, every 4 x 4 block within a third of a pixel for fills). ImageMagick stays as the loose check.ShrinkToleaking into crop-first pipelines, row drift on long edges, a dot for a loneMoveTo, hairlines under stretched transforms and inconsistent overflow handling, each with a test.Local runs: 2,632 tests on Windows; the Linux gate with AOT (1,955 tests, no skips, 36 AOT checks).