Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
SebastianR  
#1 Posted : Thursday, June 22, 2017 1:35:23 AM(UTC)
SebastianR

Rank: Advanced Member

Groups: Member
Joined: 5/10/2017(UTC)
Posts: 33

Thanks: 10 times
Was thanked: 1 time(s) in 1 post(s)
Greetings,

I am currently working on splitting up several pipelines and centralizing redundant code in commands. My problem is that I need imageparams for some transforms such as size and pixelformat of the current image at the runtime of the pipeline. The steps do not know of each other and are not able to access each others parameters, such as (in step 5) "What was the target pixelformat of the colorconversion?".

For example:

  1. Start with an image with lots of white all around.

  2. Remove the white, it gets smaller.

  3. Scale it, dependend on a fixed threshold of imagesize (say double it if larger in any dimension than (100, 200)). Obviously I cannot use the imageparams from (1) because they are out of date.

  4. Convert the colorspace.

  5. Imprint a image from an ImageGenerator, which needs a pixelformat. (1) is outdated again. (The previous step may or may not be executed or at an other position in the pipeline.)

  6. Write image.

Is there a way to access such image params during the runtime of the pipeline?

Regards,

Sebastian

Eugene Kosmin  
#2 Posted : Thursday, June 22, 2017 4:58:26 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Hi,

Please take a look at OnInit event of PipelineElement class.

And here is a small sample:

Code:
using (var ig = new ImageGenerator(3800, 2200, PixelFormat.Format24bppRgb, RgbColor.White))
using (var colorConverter = new ColorConverter(PixelFormat.Format32bppArgb))
using (var resize = new Resize(500, 200, ResizeInterpolationMode.Anisotropic9, ResizeMode.Fit))
using (var result = new Bitmap())
{
    colorConverter.OnInit += (sender, e) =>
    {
        Console.WriteLine("Size: {0} x {1}, Format: {2}", e.ImageParams.Width, e.ImageParams.Height, e.ImageParams.PixelFormat);

        var cc = (ColorConverter)sender;

        if (e.ImageParams.Width > e.ImageParams.Height)
            cc.DestinationPixelFormat = PixelFormat.Format40bppAcmyk;
        else
            cc.DestinationPixelFormat = PixelFormat.Format48bppRgb;
    };

    Pipeline.Run(ig + resize + colorConverter + result);

    Console.WriteLine("{0}",  result.PixelFormat);
}

Best regards,

Eugene Kosmin

The Aurigma Development Team

SebastianR  
#3 Posted : Friday, June 23, 2017 12:13:23 AM(UTC)
SebastianR

Rank: Advanced Member

Groups: Member
Joined: 5/10/2017(UTC)
Posts: 33

Thanks: 10 times
Was thanked: 1 time(s) in 1 post(s)
Thanks a lot. OnInit solves a lot of problems.

However, I am unable to achieve the following:

Code:

using (var reader = ImageReader.Create("...")) // In place for another pipeline
using (var combiner = new Combiner())
using (var backGroundGenerator = new ImageGenerator(new Size(200, 100), PixelFormat.Format1bppIndexed, RgbColor.Green))
using (var result = new Bitmap())
{
    combiner.TopImage = reader;
    (backGroundGenerator + combiner + result).Run();
}

I get a PixelFormatNotSupportedException. I found no way to either generate the background with a matching pixelformat or convert it back to the pixelformat of the reader after combining (because I found no way to "save the pixelformat).

Please note: The reader is just for simplicity, it is a complete pipeline by itself in my case. I cannot use "reader.Pixelformat".

Eugene Kosmin  
#4 Posted : Sunday, June 25, 2017 6:12:56 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Unfortunately, there is no way. As soon as ImageGenerator initiates running of the pipeline, it's parameters couldn't be changed.

Best regards,

Eugene Kosmin

The Aurigma Development Team

SebastianR  
#5 Posted : Monday, June 26, 2017 5:41:56 AM(UTC)
SebastianR

Rank: Advanced Member

Groups: Member
Joined: 5/10/2017(UTC)
Posts: 33

Thanks: 10 times
Was thanked: 1 time(s) in 1 post(s)
Ok, I think I figured something out with the Pixelformat, but now there are other parameters inaccessible. I'm lacking the ImageParams of the TopImage of the combiner during runtime. How can I access them? Think

(Added resize to the code from above.)

I want to fit an image into 50x50 and place it in the middle of a green area with size 'targetSize'.

Code:

var targetSize = new Size(200, 100);
using (var reader = ImageReader.Create("..."))
using (var resize = new Resize(new Size(50, 50), ResizeMode.Fit)) // Say it results in 40x50
using (var combiner = new Combiner())
using (var backGroundGenerator = new ImageGenerator(targetSize, PixelFormat.Format32bppCmyk, RgbColor.Green))
using (var result = new Bitmap())
{
    combiner.Mode=CombineMode.Alpha;
    combiner.OnInit += (sender, e) =>
        {
            // e.ImageParams is from the background, but where are the ImageParams of the TopImage?

            //positioning stuff here
        };

    combiner.TopImage = reader + resize;
    (backGroundGenerator + combiner + result).Run();
}

Edited by user Monday, June 26, 2017 5:42:34 AM(UTC)  | Reason: Explicit question

Eugene Kosmin  
#6 Posted : Monday, June 26, 2017 6:19:20 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Try the following:

Code:
combiner.OnInit += (sender, e) =>
{
    var args = e as CombinerOnInitEventArgs;

    int offsetX = args.ImageParams.Width - args.TopImageParams.Width;
    int offsetY = args.ImageParams.Height - args.TopImageParams.Height;
    // ...
};
Best regards,

Eugene Kosmin

The Aurigma Development Team

thanks 1 user thanked Eugene Kosmin for this useful post.
SebastianR on 7/3/2017(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.