Comments (1)
I'm not sure what the use case is for such a thing, but I can give some detail for why that doesn't work.
One of the reasons MagicScaler is faster and more memory-efficient than other libraries is that it operates on a pull pipeline model. No pixels exist in the pipeline until they are requested by something. In the case of ProcessImage
, it is the encoder that requests the pixels, so if you have no encoder, nothing requests any pixels, and nothing happens. The whole thing would be a no-op, so the reasonable thing to do there is to throw an exception.
If you have need to access the processed pixels without ending in an encoder, you can do that with a custom pipeline. Here is an example that constructs a pipeline using the built-in TestPatternPixelSource
to generate a large test pattern image and then resizes it, catching the output in a buffer.
using System;
using System.Buffers;
using System.Drawing;
using PhotoSauce.MagicScaler;
class Program
{
static void Main()
{
const int OriginalWidth = 6000;
const int OriginalHeight = 4000;
const int ResizedWidth = 600;
const int ResizedHeight = 400;
// stride is width * bytes-per-pixel (3 for BGR), rounded up to the nearest multiple of 4
const uint stride = ResizedWidth * 3u + 3u & ~3u;
const uint bufflen = ResizedHeight * stride;
var settings = new ProcessImageSettings
{
Width = ResizedWidth,
Height = ResizedHeight,
Sharpen = false
};
// This IPixelSource implementation generates a pre-defined test pattern.
// You could alternatively provide an existing image file to BuildPipeline.
using (var pixels = new TestPatternPixelSource(OriginalWidth, OriginalHeight, PixelFormats.Bgr24bpp))
using (var pipeline = MagicImageProcessor.BuildPipeline(pixels, settings))
{
// Here we use a rented buffer to hold the ouput.
// This could also be a locked buffer from a System.Drawing.Bitmap or from
// another library.
var buffer = ArrayPool<byte>.Shared.Rent((int)bufflen);
// This rectangle defines the pixels we are requesting from the pipeline.
// This example requests them all at once for simplicity, but it would be
// more memory-efficient to request a single output line at a time in a loop,
// assuming the target is compatible with that method of operation.
var rect = new Rectangle(0, 0, ResizedWidth, ResizedHeight);
// All the work is done here.
pipeline.PixelSource.CopyPixels(rect, (int)stride, new Span<byte>(buffer, 0, (int)bufflen));
ArrayPool<byte>.Shared.Return(buffer);
}
}
}
from photosauce.
Related Issues (20)
- Issue with WebP support HOT 15
- System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'length') HOT 9
- Add PhotoSauce.NativeCodecs.Mozjpeg HOT 6
- AVIF Encoder HOT 4
- This is awesome ❤where is the Donate button? HOT 1
- GIF animations with mixed disposal methods not handled correctly HOT 2
- Orientation is not rotating properly HOT 1
- System.Runtime.InteropServices.COMException at PhotoSauce.MagicScaler.WicPlanarCache.loadBuffer
- 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
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.