Git Product home page Git Product logo

Comments (7)

saucecontrol avatar saucecontrol commented on May 30, 2024 1

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.

saucecontrol avatar saucecontrol commented on May 30, 2024

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.

iamcarbon avatar iamcarbon commented on May 30, 2024

from photosauce.

mms- avatar mms- commented on May 30, 2024

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.

saucecontrol avatar saucecontrol commented on May 30, 2024

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.

iamcarbon avatar iamcarbon commented on May 30, 2024

This API looks perfect. Going to give it a whirl in the next few hours.

from photosauce.

iamcarbon avatar iamcarbon commented on May 30, 2024

Works perfectly!

from photosauce.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.