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

Notification

Icon
Error

Options
Go to last post Go to first unread
MateuszŁ  
#1 Posted : Sunday, November 24, 2019 5:01:26 AM(UTC)
MateuszŁ

Rank: Newbie

Groups: Member
Joined: 2/7/2019(UTC)
Posts: 2

Thanks: 1 times
please help,
I work on very large graphic files, that's why I use the pipeline method

Can this function be used in two stages?
stage 1
*load image file
*change size (to very large)
stage 2 (in the loop)
*crop big image
*save result


something like this:

Code:

using (var reader = ImageReader.Create("imgFile.jpg"))
using (var resize = new Resize(bigX, bigY))
{
 Pipeline.Run(reader + resize);
 for (int y = 0; y < 1234; y++)
 {
   for (int x = 0; x < 123; x++)
   {
     using (var crop = new Crop(x, y, someWidth, someHeigh))
     using (var writer = new JpegWriter(nazwaPliku + ".png"))
     Pipeline.Run(crop + writer);
   }
 }
}


now I use one-step method but it is not effective because unnecessarily every time the graphics are loaded and cropped:

Code:

using (var reader = ImageReader.Create("imgFile.jpg"))
using (var resize = new Resize(bigX, bigY))
{
 for (int y = 0; y < 1234; y++)
 {
   for (int x = 0; x < 123; x++)
   {
     using (var crop = new Crop(x, y, someWidth, someHeigh))
     using (var writer = new JpegWriter(nazwaPliku + ".png"))
     Pipeline.Run(reader + resize + crop + writer);
   }
 }
}
Fedor  
#2 Posted : Sunday, November 24, 2019 6:17:03 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,625

Thanks: 5 times
Was thanked: 70 time(s) in 68 post(s)
You can use the Receivers collection to build a graph instead of a plain pipeline. Here is a code sample:

Code:
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;

class Program
{
    static void Main(string[] args)
    {
        using (var reader = ImageReader.Create("../../../in.jpg"))
        using (var resize = new Resize(400, 500))
        using (var crop1 = new Crop(0, 0, 300, 400))
        using (var crop2 = new Crop(100, 100, 200, 150))
        using (var writer1 = new JpegWriter("../../../out1.jpg"))
        using (var writer2 = new JpegWriter("../../../out2.jpg"))
        {
            var pipeline = reader + resize;

            resize.Receivers.Add(crop1);
            crop1.Receivers.Add(writer1);

            resize.Receivers.Add(crop2);
            crop2.Receivers.Add(writer2);

            pipeline.Run();
        }
    }
}


Please note, you may experience problems if you have 1000s of elements in the graph. So, don't build a very large pipeline.
Best regards,
Fedor Skvortsov
thanks 1 user thanked Fedor for this useful post.
MateuszŁ on 11/24/2019(UTC)
MateuszŁ  
#3 Posted : Sunday, November 24, 2019 8:55:09 AM(UTC)
MateuszŁ

Rank: Newbie

Groups: Member
Joined: 2/7/2019(UTC)
Posts: 2

Thanks: 1 times
thank you very much, now I fully understood how it works.


I am very impressed with the performance!

previously it took over an hour to process 10,000 "crops"and now less than 5 minutes.

I used your hint like this:

Code:

using (var reader = ImageReader.Create(fileInput))
            {
                using (var resize = new Resize(pixX , pixY))
                {
                    var pipeline = reader + resize;

                    var crops = new List<Crop>();
                    var writers = new List<JpegWriter>();

                    for (int y = 0; y < photosOnHeight; y++)
                    {
                        for (int x = 0; x < photosOnWidth; x++)
                        {
                            crops.Add(new Crop(calcX(x,y), calcY(x,y), calcW(x,y), calcH(x,y)));
                            writers.Add(new JpegWriter(SaveFileName(x,y)));
                        }
                    }

                    for (int a = 0; a < crops.Count; a++)
                    {
                        resize.Receivers.Add(crops[a]);
                        crops[a].Receivers.Add(writers[a]);
                    }

                    pipeline.Run();

                    for (int b = 0; b < crops.Count; b++)
                    {
                        crops[b].Dispose();
                        writers[b].Dispose();
                    }
                }
            }


the code worked even for 100,000 "crops"

Edited by user Sunday, November 24, 2019 9:55:21 AM(UTC)  | Reason: update info

Users browsing this topic
Similar Topics
48bpp Image Pipeline (Discussions – Graphics Mill)
by tde 2/16/2018 10:08:43 AM(UTC)
Access ImageParams during pipeline (Discussions – Graphics Mill)
by SebastianR 6/22/2017 1:35:23 AM(UTC)
Optimising pipeline drawer (Discussions – Graphics Mill)
by Chris Jones 6/20/2017 1:14:03 AM(UTC)
How do I transfer the alpha channel from one image to another using a pipeline?? (Discussions – Graphics Mill)
by SebastianR 5/17/2017 11:37:33 PM(UTC)
How do I set the background color during a pipeline? (Discussions – Graphics Mill)
by SebastianR 5/15/2017 5:28:42 AM(UTC)
How to generate a background during a pipeline? (Discussions – Graphics Mill)
by SebastianR 5/12/2017 4:53:26 AM(UTC)
Pipeline rendering issues over 600dpi (Discussions – Graphics Mill)
by Chris Jones 5/4/2017 7:15:43 AM(UTC)
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.