Comments (7)
Good deal. I'm looking to replace my WIC stuff with managed implementations, so I'll have an analogous custom interface, but it'll work the same. I'll keep this on my to-do list.
from photosauce.
That's an interesting one. I've been considering how I can make my processing pipeline more extensible without sacrificing the things that make it fast and lightweight. The pipeline today is set up with a pull model built around IWICBitmapSource. Using that interface allows me to request only the pixels I need immediately (typically enough to process a single output scanline) into a small buffer. That, in turn, allows the upstream pixel source to avoid loading large images in memory all at once. If you've already got the whole image decoded and sitting there, it's easy enough to fill that buffer, but then you end up copying the data when the original could be accessed instead. I'll have to give that some thought.
Oh, and your example method signature leaves out the destination buffer/stream. Was that just an oversight, or were you thinking the input buffer could be recycled to store the output?
from photosauce.
from photosauce.
This is also something that would help us a lot. Currently we can't plug MagicScaler into our pipeline and maintain the performance benefits.
from photosauce.
I've finally got the architecture changes done to make this possible and have taken a stab at the interfaces. Pixels can be fed into or pulled out of the pipeline using the IPixelSource
interface, which is a simplified version of IWICBitmapSource
. Here's how they go:
Option 1. Feed pixels into MagicScaler pipeline, and complete processing in the pipeline.
var pix = new TestPatternPixelSource(1024, 768, PixelFormats.Bgr24bpp);
using (var fs = new FileStream(@"c:\img\testpattern.png", FileMode.Create))
MagicImageProcessor.ProcessImage(pix, fs, new ProcessImageSettings { Width = 100, SaveFormat = FileFormat.Png });
Option 2. Use MagicScaler to decode, color correct, resize, and sharpen... then pull the pixels out of the pipeline for continued processing. This example resizes an image and draws it onto a System.Drawing.Bitmap
, allowing further manipulation.
using (var pl = MagicImageProcessor.BuildPipeline(@"c:\img\big.jpg", new ProcessImageSettings { Width = 100 }))
using (var fs = new FileStream(@"c:\img\small.png", FileMode.Create))
using (var bmp = new Bitmap(pl.PixelSource.Width, pl.PixelSource.Height, PixelFormat.Format24bppRgb))
{
var rec = new Rectangle(0, 0, bmp.Width, bmp.Height);
var lck = bmp.LockBits(rec, ImageLockMode.ReadWrite, bmp.PixelFormat);
pl.PixelSource.CopyPixels(rec, lck.Stride, (lck.Stride * lck.Height), lck.Scan0);
bmp.UnlockBits(lck);
// do some drawing or something
bmp.Save(fs, ImageFormat.Png);
}
Option 3. You can do IPixelSource both in and out
The IPixelSource
provided as input can theoretically use any pixel format supported by WIC, and the output will always be BGRA, BGR, or Grey. Those Guids are included as static fields the PixelFormats
class for ease of use.
An alpha build is up on nuget now.
Does that cover your needs or are there some scenarios I've missed?
from photosauce.
This API looks perfect. Going to give it a whirl in the next few hours.
from photosauce.
Works perfectly!
from photosauce.
Related Issues (20)
- Problem with certain PNG images HOT 8
- Transparent Color on PadTransform HOT 1
- RobiniaDocs API Explorer
- Update libwebp HOT 4
- Option to retain gif loop count when resizing HOT 6
- Could not load type 'PhotoSauce.MagicScaler.Converters.ChannelChanger`1' HOT 8
- ColorMatrixTransform does not unpremultiply/premultiply HOT 1
- Default JPEG encoding options are not publicly accessible HOT 4
- EncoderInfo not set correctly if output to Stream
- MagicScalar Linux issue
- libpng throws bad adaptive filter will abort writing result HOT 3
- libpng fails to convert several files that WIC can handle HOT 2
- `ArgumentOutOfRangeException` reading JPEG XL image from their test page HOT 3
- After update the solution to .NET 8 version the NativeCodecs dependency started to fail HOT 3
- Noob question: Having a hard time understanding the native codec binary build steps.
- How to gain best possible quality, disregard performance.
- IMultiFrameDecoderOptions support missing for JPEG XL HOT 1
- Decoder FrameRange validation is not valid HOT 2
- Build warning with net8.0 app HOT 2
- Native png encoder not working in 14.1 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from photosauce.