Ejemplo n.º 1
0
        void RandomizeDMI(string sourceDMI, string targetDMI)
        {
            int sourceWidth     = 0;
            int sourceHeight    = 0;
            int sourceYRect     = 0;
            int sourceFileSize  = 0; //Amount of sprites
            int sourceXRows     = 0; //Amount of rows on x (width)
            int sourceYRows     = 0; //Amount of rows on y (height)
            int sourceLastIcons = 0; //Amount of sprites in the last row

            int targetWidth     = 0;
            int targetHeight    = 0;
            int targetYRect     = 0;
            int targetFileSize  = 0; //Amount of sprites
            int targetXRows     = 0; //Amount of rows on x (width)
            int targetYRows     = 0; //Amount of rows on y (height)
            int targetLastIcons = 0; //Amount of sprites in the last row

            Bitmap     sourceBitmap = new Bitmap(sourceDMI);
            Bitmap     targetBitmap = new Bitmap(targetDMI);
            RectangleF sourceRect   = new RectangleF(0, 0, 32, 32);
            RectangleF targetRect   = new RectangleF(0, 0, 32, 32);

            //Set important data from the DMI metadata
            DMIMetadata sourceLocalDmiData = dmidata(sourceDMI);

            sourceWidth    = sourceLocalDmiData.Width;
            sourceHeight   = sourceLocalDmiData.Height;
            sourceFileSize = sourceLocalDmiData.SpriteCount;
            DMIMetadata targetLocalDmiData = dmidata(targetDMI);

            targetWidth    = targetLocalDmiData.Width;
            targetHeight   = targetLocalDmiData.Height;
            targetFileSize = targetLocalDmiData.SpriteCount;

            sourceXRows     = sourceBitmap.Width / sourceWidth;   //Hight of the dmi file in pixel divided by the height of a single sprite, results in amount of sprites vertically
            sourceYRows     = sourceBitmap.Height / sourceHeight; //Hight of the dmi file in pixel divided by the height of a single sprite, results in amount of sprites vertically
            sourceLastIcons = sourceFileSize - (sourceXRows * (sourceYRows - 1));
            targetXRows     = targetBitmap.Width / targetWidth;   //Hight of the dmi file in pixel divided by the height of a single sprite, results in amount of sprites vertically
            targetYRows     = targetBitmap.Height / targetHeight; //Hight of the dmi file in pixel divided by the height of a single sprite, results in amount of sprites vertically
            targetLastIcons = targetFileSize - (targetXRows * (targetYRows - 1));

            int counter = 0;

            if (targetFileSize < sourceFileSize)
            {
                counter = targetFileSize + Convert.ToInt32(0.1 * sourceFileSize); //Smaller file as basis of the amount of copy operations with 10% of the other files size added
            }
            else
            {
                counter = sourceFileSize + Convert.ToInt32(0.1 * targetFileSize); //This should result in a good amount of sprites being injected
            }
            sourceRect.Width  = sourceWidth;
            sourceRect.Height = sourceHeight;
            if (stretch_Checkbox.IsChecked == true)
            {
                targetRect.Width  = targetWidth;
                targetRect.Height = targetHeight;
            }
            else
            {
                targetRect.Width  = sourceWidth;
                targetRect.Height = sourceHeight;
            }

            for (int i = 0; i < counter * multiplier; i++)
            {
                sourceYRect  = y(sourceYRows, sourceHeight);
                sourceRect.Y = sourceYRect;
                if (sourceYRect / sourceHeight == sourceYRows - 1) //If y is the amount of rows aka the last row we need to limit y because the last row probably doesn't have the max amount of items
                {
                    sourceRect.X = x(sourceXRows, sourceLastIcons, true, sourceWidth);
                }
                else
                {
                    sourceRect.X = x(sourceXRows, sourceLastIcons, false, sourceWidth);
                }


                targetYRect  = y(targetYRows, sourceHeight);
                targetRect.Y = targetYRect;
                if (targetYRect / targetHeight == targetYRows - 1) //If y is the amount of rows aka the last row we need to limit y because the last row probably doesn't have the max amount of items
                {
                    targetRect.X = x(targetXRows, targetLastIcons, true, sourceWidth);
                }
                else
                {
                    targetRect.X = x(targetXRows, targetLastIcons, false, sourceWidth);
                }

                try
                {
                    using (Graphics grD = Graphics.FromImage(targetBitmap))
                    {
                        grD.DrawImage(sourceBitmap, targetRect, sourceRect, GraphicsUnit.Pixel);
                    }
                }
                catch
                {
                    //Sometimes this just breaks
                }
            }
            targetBitmap.Save(targetDMI + ".new");
            sourceBitmap.Dispose();
            targetBitmap.Dispose();
            File.Move(targetDMI, targetDMI + ".old");
            process.StartInfo.Arguments = "/S /c \"\"" + exiftool + "\" -overwrite_original -z -TagsFromFile \"" + targetDMI + ".old\"" + " -Description \"" + targetDMI + ".new\"\"";
            process.Start();
            process.WaitForExit();
            File.Delete(targetDMI + ".old");
            File.Move(targetDMI + ".new", targetDMI);
        }
Ejemplo n.º 2
0
        void RandomizeDMI(string DMIPath)
        {
            int        width      = 0;
            int        height     = 0;
            int        yRect      = 0;
            int        fileSize   = 0; //Amount of sprites
            int        xRows      = 0; //Amount of rows on x (width)
            int        yRows      = 0; //Amount of rows on y (height)
            int        lastIcons  = 0; //Amount of sprites in the last row
            Bitmap     myBitmap   = new Bitmap(DMIPath);
            RectangleF sourceRect = new RectangleF(0, 0, 32, 32);
            RectangleF targetRect = new RectangleF(0, 0, 32, 32);

            System.Drawing.Imaging.PixelFormat format = myBitmap.PixelFormat;

            //Set important data from the DMI metadata
            DMIMetadata localDmiData = dmidata(DMIPath);

            width    = localDmiData.Width;
            height   = localDmiData.Height;
            fileSize = localDmiData.SpriteCount;

            xRows     = myBitmap.Width / width;   //Hight of the dmi file in pixel divided by the height of a single sprite, results in amount of sprites horizontally
            yRows     = myBitmap.Height / height; //Hight of the dmi file in pixel divided by the height of a single sprite, results in amount of sprites vertically
            lastIcons = fileSize - (xRows * (yRows - 1));

            sourceRect.Width  = targetRect.Width = width;
            sourceRect.Height = targetRect.Height = height;


            for (int i = 0; i < fileSize * multiplier; i++)
            {
                yRect        = y(yRows, height);
                sourceRect.Y = yRect;
                if (yRect / height == yRows - 1) //If x is the amount of rows aka the last row we need to limit y because the last row probably doesn't have the max amount of items
                {
                    sourceRect.X = x(xRows, lastIcons, true, width);
                }
                else
                {
                    sourceRect.X = x(xRows, lastIcons, false, width);
                }


                yRect        = y(yRows, height);
                targetRect.Y = yRect;
                if (yRect / width == yRows - 1) //If x is the amount of rows aka the last row we need to limit y because the last row probably doesn't have the max amount of items
                {
                    targetRect.X = x(xRows, lastIcons, true, width);
                }
                else
                {
                    targetRect.X = x(xRows, lastIcons, false, width);
                }

                try
                {
                    using (Graphics grD = Graphics.FromImage(myBitmap))
                    {
                        grD.DrawImage(myBitmap, targetRect, sourceRect, GraphicsUnit.Pixel);
                    }
                }
                catch
                {
                    //Sometimes this just breaks
                }
            }
            myBitmap.Save(DMIPath + ".new");
            myBitmap.Dispose();
            File.Move(DMIPath, DMIPath + ".old");
            process.StartInfo.Arguments = "/S /c \"\"" + exiftool + "\" -overwrite_original -z -TagsFromFile \"" + DMIPath + ".old\"" + " -Description \"" + DMIPath + ".new\"\"";
            process.Start();
            process.WaitForExit();
            File.Delete(DMIPath + ".old");
            File.Move(DMIPath + ".new", DMIPath);
        }