Example #1
0
        private Image <Bgra, byte> AddImages(Image <Bgra, byte>[] imageArray)
        {
            if (imageArray == null || imageArray.Length == 0)
            {
                throw new Exception("wtf parameters are empty bro");
            }
            int _height = imageArray[0].Height;
            int _width  = imageArray[0].Width;

            foreach (Image <Bgra, byte> i in imageArray)
            {
                if (i.Height != _height || i.Width != _width)
                {
                    throw new Exception("Array of images are not of the same dimensions");
                }
            }
            //data cleaned

            Image <Bgra, byte> output = EngineTools.CreateTransparent(_width, _height);

            for (int x = 0; x < _width; x++)
            {
                for (int y = 0; y < _height; y++)
                {
                    Bgra          pixeldata  = new Bgra(0, 0, 0, 0);
                    List <double> alphaArray = new List <double>();
                    for (int i = 0; i < imageArray.Length; i++) //check to see if layers have anything on them at all, skip math if there is
                    {
                        alphaArray.Add(imageArray[i][y, x].Alpha);
                    }
                    if (alphaArray.Sum() <= 0.001)
                    {
                        goto SkipSum;
                    }
                    for (int i = 0; i < imageArray.Length; i++)
                    {
                        if (imageArray[i][y, x].Alpha > 0.001)
                        {
                            double a1 = imageArray[i][y, x].Alpha / 255;
                            double r1 = imageArray[i][y, x].Red;
                            double g1 = imageArray[i][y, x].Green;
                            double b1 = imageArray[i][y, x].Blue;
                            double a2 = pixeldata.Alpha / 255;
                            double r2 = pixeldata.Red;
                            double g2 = pixeldata.Green;
                            double b2 = pixeldata.Blue; //stacking value 2 over value 1

                            //additive compositing
                            pixeldata.Alpha = (a2 * (1 - a1) + a1) * 255; //x255 because scale of 0-255
                            pixeldata.Red   = r2 * a2 * (1 - a1) + r1 * a1;
                            pixeldata.Green = g2 * a2 * (1 - a1) + g1 * a1;
                            pixeldata.Blue  = b2 * a2 * (1 - a1) + b1 * a1;
                        }
                    }
SkipSum:            //cancel excecution of adding nothing to itself
                    output[y, x] = pixeldata;
                }
            }
            return(output);
        }
Example #2
0
        public Form1()
        {
            theNullImage = EngineTools.CreateTransparent(300, 400);
            im_eyes      = theNullImage;
            im_face      = theNullImage;
            im_hairBack  = theNullImage;
            im_hairFront = theNullImage;
            im_head      = theNullImage;
            im_outfit    = theNullImage;
            im_bodyBack  = theNullImage;
            redraw       = true; //flag used when mass deselecting to prevent ultralag

            InitializeComponent();
            InitializeOptions();

            imbx_ImagePrimary.FunctionalMode = ImageBox.FunctionalModeOption.Minimum;
        }