Repository navigation
Commit a67e459
committed
Add managed image processing to Ecng.Drawing: size, resize, PNG conversion, text watermark
ImageHelper is the public surface: GetImageSize, ResizeImage, ConvertToPng,
AddTextWatermark, GetGifFrames / GetAnimationFrames and GetGifLoopCount /
GetAnimationLoopCount, all over a byte array holding an encoded picture.
Everything underneath is internal and written in managed code, with no imaging
package and no OS graphics API behind it:
- PngCodec: every colour type and bit depth, the five scanline filters, Adam7,
tRNS, CRC checks; writes RGBA8, its scanlines packed filtered or unfiltered,
whichever comes out shorter.
- ApngDecoder / ApngEncoder: frame rectangles, SOURCE/OVER blending,
NONE/BACKGROUND/PREVIOUS disposal, delays and the loop count.
- JpegCodec / JpegProgressiveCodec: 8-bit baseline and progressive Huffman JPEG,
grayscale, YCbCr, Adobe CMYK and YCCK, restart markers, the Exif orientation.
JpegEncoder writes baseline 4:4:4 at a quality from 1 to 100 on the scale of
libjpeg, 90 by default, with Huffman tables built for the picture.
- BmpCodec: OS/2 core and Windows V3-V5 headers, indexed 1/4/8 bit, 16/24/32 bit,
bitfields, RLE4 and RLE8; writes 32-bit BGRA with a V4 header.
- GifCodec: GIF87a/GIF89a with global and local palettes, LZW, interlacing,
transparency, disposal 0-3 and the NETSCAPE loop count; every frame is
composited onto the logical screen.
- TrueTypeFont / TextMask: glyf outlines with cmap formats 4 and 12, rendered once
into a mask for the watermark text. The font is an installed family, a .ttf
path, the bytes of a font file, or the subset of DejaVu Sans the library carries
for a machine that has no font; its license is in Drawing/Fonts and in the
package.
- RasterImage: the RGBA8 buffer the codecs share, reduced by averaging the source
area of every pixel with colors weighted by alpha.
A picture keeps its format through resizing and watermarking and is never
enlarged; a GIF or an APNG stays animated through resizing, watermarking and
conversion to PNG. A JPEG is handled the way its Exif orientation shows it. A
picture that needs no change - it fits already, or nothing would be drawn on it -
is returned as it came, byte for byte. The ICC profile of a JPEG or a PNG stays
with the picture if it is one for RGB; Exif does not. A watermark is one line in
the bottom right corner, made smaller to fit between the margins, down to 6 pixels
to the em.
A picture of more than 25 megapixels is not decoded, nor an animation of more than
512 frames or 100 megapixels of canvas.
The 243 tests exercise the codecs through ImageHelper and directly, with
hand-built fixtures and ones encoded by Pillow.
Squashed from feature/drawing-image-utilities at 2879c7d and the twelve commits
of fixes, watermark and encoder work that followed it.1 parent 2cdcfe5 commit a67e459
55 files changed
Lines changed: 13437 additions & 0 deletions
File tree
- Drawing
- Fonts
- Tests/Drawing
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
0 commit comments