Пример #1
0
        static int DrawToBitmap(ref TBitmap bm, BitmapPoint pt, Color color)
        {

            int x = pt.x;

            int y = pt.y;

			bm.values[x + (y * (bm.Width-1))].R = (byte)color.R;
			bm.values[x + (y * (bm.Width-1))].G = (byte)color.G;
			bm.values[x + (y * (bm.Width-1))].B = (byte)color.B;
			bm.values[x + (y * (bm.Width-1))].A = (byte)color.A;

			bm.values[x + (y * (bm.Width-1))].point = pt;

			return 1;
			
        }
Пример #2
0
		public RandomWalk(int maxFileSize, bool populateSpace = false, bool createBitmap = false, BitmapPoint? startingPoint = null, string bitmapFilePath = null)
        {
			int numberDrawn = 0;

			if (bitmapFilePath == null)
				_filePath = @"C:\Users\kylan_000\Desktop\Test Projects\Random Bitmaps\RandomArt.2013\WithPointers\";
			else _filePath = bitmapFilePath;

			_space = new Space();

            Random randomW = new Random();
            //Random randomC = new Random();
            Random rr = new Random();
            Random rg = new Random();
            Random rb = new Random();

            Random random = new Random();

            Random randomR = new Random();

            Random randomG = new Random();

            Random randomB = new Random();

            Random pc = new Random();

            Random myRandom = new Random();

            //int LineLength = 1;

            //int FileSize = 10000000; //in bytes

            int x = (int)Math.Truncate(Math.Sqrt(maxFileSize / 36)) + 1;

            int Width = 4 * x;    // Screen.GetBounds(new Point(5, 5)).Width;

            int Height = 3 * x;   //Screen.GetBounds( new Point(5,5) ).Height;

            Random pick = new Random();

			Console.WriteLine("Setting up data structure...");
			if (createBitmap)
			{
				_tBitmap = new TBitmap(Width, Height);

				Console.WriteLine("Initializing bitmap...");
				for (int k = 0; k < _tBitmap.values.Length; k++)
				{
					_tBitmap.values[k].R = (byte)0;
					_tBitmap.values[k].G = (byte)0;
					_tBitmap.values[k].B = (byte)0;
					_tBitmap.values[k].A = (byte)0;
				}
			}

            int i;

            int randomNumber; randomNumber = random.Next(0, 255);

            //for (int g = 1; g < 10; g++)
            //{
			BitmapPoint ptStart = startingPoint == null ? new BitmapPoint(random.Next(Width), random.Next(Height)) : new BitmapPoint(((BitmapPoint)startingPoint).x,((BitmapPoint)startingPoint).y);

                double rnd;

                rnd = pc.Next(0, 8);

                int PenCase = 4;

                Color startColor = Color.FromArgb(random.Next(0,255),random.Next(0,255),random.Next(0,255));

				BitmapPoint ptEnd = new BitmapPoint(0, 0);

				Random randomC = new Random();

				int iMax = (int)Math.Truncate(Math.Pow(maxFileSize, 0.9));

				Console.WriteLine("Generating random walk...");

				for (i = 1; i < iMax; i++)
                //do
                {

                    //IntPoint[] pts = new IntPoint[2];

                    int c;

                    Color endColor = new Color();

                    switch (PenCase)
                    {
                        case 1:
                            {

                                //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);

                                //ptEnd.Offset(random.Next(-(LineLength), LineLength + 1), random.Next(-(LineLength), LineLength + 1));

                                break;
                            }
                        case 2:
                            { //black
                                //pn.Width = randomW.Next(0, 5);

                                //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);

                                break;
                            }
                        case 3:
                            { //all colors, random line width between 0 and 5 px

                                endColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));

                                //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);
                                break;
                            }
                        case 4:
                            { //all colors, thinnest line width

								ptEnd = GetNextPoint(new Point(ptStart.x, ptStart.y), random, Width, Height);

								endColor = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));

                                //endColor = Blend(startColor, GetPixelColor(ptEnd, tBm), random);

								if(createBitmap)
									numberDrawn += DrawToBitmap(ref _tBitmap, ptEnd, endColor);

								ptStart.x = ptEnd.x; ptStart.y = ptEnd.y;

                                break;
                            }
                        case 5:
                            { //greyscale
                                c = randomC.Next(0, 255);
                                //pn.Color = System.Drawing.Color.FromArgb(c, c, c);

                                //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);
                                break;
                            }
                        case 6:
                            { //white
                                //pn.Color = System.Drawing.Color.White;

                                //ptEnd.X = ptStart.X;

                                //ptEnd.Y = ptStart.Y;

                                //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);
                                break;
                            }
                        case 7:
                            { //black thinnest line width
                                //pn.Width = 1;

                                //ptEnd.X = ptStart.X;

                                //ptEnd.Y = ptStart.Y;

                                //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);
                                break;
                            }
                        case 8: //all colors, wider line width
                            {
                                //pn.Color = System.Drawing.Color.FromArgb( rr.Next(redBottom, redTop), rr.Next(greenBottom, greenCenter), rr.Next(blueBottom, blueTop) );
                                //pn.Width = randomW.Next(0, 50);

                                //ptEnd.X = ptStart.X;

                                //ptEnd.Y = ptStart.Y;

                                //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);
                                break;
                            }
                        default:
                            {

                                //ptEnd.X = ptStart.X;

                                //ptEnd.Y = ptStart.Y;

                                //ptEnd = GetNextPoint(ptStart, random, bpData.Stride, bpData.Height);

                                break;
                            }

                    } //end switch

					if (populateSpace)
					{
						_space.Add(new BitmapPoint(ptEnd.x, ptEnd.y));
						_size++;
					}
                }
            //}

            if(createBitmap)
				WriteDataToStandardBitmap(ref _tBitmap);

        }
Пример #3
0
        private static void WriteTBitmapToBitmap(ref TBitmap tBm, ref Bitmap bm)
        {
			foreach (PixelValue pv in tBm.values)
			{
				bm.SetPixel(pv.point.x, pv.point.y, Color.FromArgb(pv.A, pv.R, pv.G, pv.B));
			}
        }
Пример #4
0
		private static Color GetPixelColor(BitmapPoint ptEnd, TBitmap bm)
        {
            return Color.FromArgb(bm.values[ptEnd.x + ptEnd.y * bm.Height].R, bm.values[ptEnd.x + ptEnd.y * bm.Height].G, bm.values[ptEnd.x + ptEnd.y * bm.Height].B);
        }
Пример #5
0
		private void WriteDataToStandardBitmap(ref TBitmap tBm)
        {
            bitmap = new Bitmap(tBm.Width, tBm.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            WriteTBitmapToBitmap(ref tBm, ref bitmap);

            bitmap.Save(_filePath + "Random Walk " + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + " " + DateTime.Now.Hour + "h" + DateTime.Now.Minute + "m" + DateTime.Now.Second + "s" + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
        }
Пример #6
0
        // Write the .anir file and .bmps or .tbms, depending on fCrunch

        public static bool Export(AnimSet anis, string strExportPath, Palette pal, bool fCrunch, bool fValidateColors)
        {
            Color      clrTransparent = Color.FromArgb(0xff, 0, 0xff);
            SolidBrush brTransparent  = new SolidBrush(clrTransparent);

            if (strExportPath == null)
            {
                strExportPath = ".";
            }

            ASCIIEncoding enc = new ASCIIEncoding();

            FileStream   stm  = new FileStream(strExportPath + @"\" + anis.Name + ".anir", FileMode.Create, FileAccess.Write);
            BinaryWriter stmw = new BinaryWriter(stm);

            // Count the number of FrameSets (aka Strips)

            ushort cstpd = 0;

            foreach (DictionaryEntry deAnimSet in anis.Items)
            {
                Anim ani = (Anim)deAnimSet.Value;
                cstpd += (ushort)ani.Items.Count;
            }

            // Write AnimationFileHeader.cstpd

            stmw.Write(Misc.SwapUShort(cstpd));

            // Write array of offsets to StripDatas (AnimationFileHeader.aoffStpd)

            ushort    offStpd = (ushort)(2 + (2 * cstpd));
            byte      ibm     = 0;
            ArrayList albm    = new ArrayList();

            foreach (DictionaryEntry deAnimSet in anis.Items)
            {
                Anim ani = (Anim)deAnimSet.Value;
                foreach (DictionaryEntry deAnim in ani.Items)
                {
                    FrameSet frms = (FrameSet)deAnim.Value;
                    stmw.Write(Misc.SwapUShort(offStpd));

                    // Advance offset to where the next StripData will be

                    offStpd += (ushort)((26 + 1 + 1 + 2) /* sizeof(StripData) - sizeof(FrameData) */ +
                                        ((1 + 1 + 1 + 1 + 1 + 1) /* sizeof(FrameData) */ * frms.Count));
                }
            }

            // Write array of StripDatas

            foreach (DictionaryEntry deAnimSet in anis.Items)
            {
                Anim ani = (Anim)deAnimSet.Value;
                foreach (DictionaryEntry deAnim in ani.Items)
                {
                    FrameSet frms = (FrameSet)deAnim.Value;

                    // Write StripData.Name

                    string strName = ani.Name + " " + frms.Name;
                    byte[] abT     = new byte[26];
                    enc.GetBytes(strName, 0, Math.Min(strName.Length, 25), abT, 0);
                    abT[25] = 0;
                    stmw.Write(abT);

                    // Write StripData.cDelay

                    stmw.Write((byte)0);

                    // Write StripData.bfFlags

                    stmw.Write((byte)0);

                    // Write StripData.cfrmd

                    ushort cfrmd = (ushort)frms.Count;
                    stmw.Write(Misc.SwapUShort(cfrmd));

                    // Write array of FrameDatas

                    foreach (Frame frm in frms)
                    {
                        // Write FrameData.ibm (the index of the Bitmap as it will be in the Bitmap array)

                        stmw.Write((byte)ibm);
                        ibm++;

                        // Add the Frame's Bitmap for output

                        Bitmap bm = frm.Bitmap;
                        if (fCrunch)
                        {
                            albm.Add(bm);
                        }
                        else
                        {
                            // If not crunching then we need to go through some special work to preserve
                            // the origin point. Since the origin point is determined by finding the center
                            // of the imported bitmap we preserve it at export by creating a new bitmap
                            // sized so that he origin will be in its center.


                            // The '+2' at the end gives us a pixel of transparent space padding the left
                            // and right sides of the bitmap. We don't require this for any particular
                            // reason but it comes in handy.

                            int cxNew = (Math.Max(frm.OriginX, bm.Width - frm.OriginX) * 2) + 2;

                            // The '+2' at the end is to ensure a single blank scanline at the top
                            // which Import relies on to determine the transparent color.

                            int cyNew = (Math.Max(frm.OriginY, bm.Height - frm.OriginY) * 2) + 2;

                            using (Bitmap bmNew = new Bitmap(cxNew, cyNew, bm.PixelFormat)) {
                                using (Graphics g = Graphics.FromImage(bmNew)) {
                                    g.FillRectangle(brTransparent, 0, 0, cxNew, cyNew);
                                    g.DrawImage(bm, cxNew / 2 - frm.OriginX, cyNew / 2 - frm.OriginY);
                                }
                                strName = anis.Name + "_" + ani.Name + "_" + frms.Name + "_" + frm.Index.ToString();
                                bmNew.Save(strExportPath + @"\" + strName + ".png", ImageFormat.Png);
                            }
                        }

                        // Write FrameData.xOrigin, FrameData.yOrigin

                        stmw.Write((byte)frm.OriginX);
                        stmw.Write((byte)frm.OriginY);

                        // Write FrameData.bCustomData1, FrameData.bCustomData2, FrameData.bCustomData3

                        stmw.Write((byte)0);
                        stmw.Write((byte)0);
                        stmw.Write((byte)0);
                    }
                }
            }

            stmw.Close();

            // Write out .tbm

            if (albm.Count != 0)
            {
                string strFileName = strExportPath + @"\" + anis.Name + ".tbm";
                if (gfSuperVerbose)
                {
                    Console.WriteLine("Crunching and writing " + strFileName);
                }
                TBitmap.Save((Bitmap[])albm.ToArray(typeof(Bitmap)), pal, strFileName);
            }

            return(true);
        }
Пример #7
0
 public GifFrame(TBitmap im, int del)
 {
     Image = im;
     Delay = del;
 }
Пример #8
0
        public bool WriteAnir(Palette pal, string strExportPath, string strAnimName)
        {
            Color      clrTransparent = Color.FromArgb(0xff, 0, 0xff);
            SolidBrush brTransparent  = new SolidBrush(clrTransparent);

            ASCIIEncoding enc = new ASCIIEncoding();

            FileStream   stm  = new FileStream(strExportPath + Path.DirectorySeparatorChar + strAnimName + ".anir", FileMode.Create, FileAccess.Write);
            BinaryWriter stmw = new BinaryWriter(stm);

            // Count the number of Strips

            ushort cstpd = (ushort)StripSet.Count;

            // Write AnimationFileHeader.cstpd

            stmw.Write(Misc.SwapUShort(cstpd));

            // Write array of offsets to StripDatas (AnimationFileHeader.aoffStpd)

            ushort    offStpd = (ushort)(2 + (2 * cstpd));
            ArrayList albm    = new ArrayList();

            foreach (Strip stp in StripSet)
            {
                stmw.Write(Misc.SwapUShort(offStpd));

                // Advance offset to where the next StripData will be

                offStpd += (ushort)((26 + 1 + 1 + 2) /* sizeof(StripData) - sizeof(FrameData) */ +
                                    ((1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1) /* sizeof(FrameData) */ * stp.Count));

                // Force word alignment of StripDatas

                if ((offStpd & 1) == 1)
                {
                    offStpd++;
                }
            }

            // Write array of StripDatas

            foreach (Strip stp in StripSet)
            {
                // Write StripData.Name

                byte[] abT = new byte[26];
                enc.GetBytes(stp.Name, 0, Math.Min(stp.Name.Length, 25), abT, 0);
                abT[25] = 0;
                stmw.Write(abT);

                // Write StripData.cHold

                stmw.Write((byte)stp.DefHoldCount);

                // Write StripData.bfFlags

                stmw.Write((byte)0);

                // Write StripData.cfrmd

                ushort cfrmd = (ushort)stp.Count;
                stmw.Write(Misc.SwapUShort(cfrmd));

                // Write array of FrameDatas

                foreach (Frame fr in stp)
                {
                    // Add the Frame's Bitmap for output

                    int    ibm = -1;
                    Bitmap bm;
                    if (fr.BitmapPlacers.Count > 0)
                    {
                        bm  = fr.BitmapPlacers[0].XBitmap.Bitmap;
                        ibm = albm.IndexOf(bm);
                        if (ibm == -1)
                        {
                            ibm = albm.Add(bm);
                        }
                    }

                    // Write FrameData.ibm (the index of the Bitmap as it will be in the Bitmap array)

                    stmw.Write((byte)ibm);

                    ibm = -1;
                    if (fr.BitmapPlacers.Count > 1)
                    {
                        // Add the Frame's Bitmap for output

                        bm  = fr.BitmapPlacers[1].XBitmap.Bitmap;
                        ibm = albm.IndexOf(bm);
                        if (ibm == -1)
                        {
                            ibm = albm.Add(bm);
                        }
                    }

                    // Write FrameData.ibm2 (the index of the Bitmap as it will be in the Bitmap array)

                    stmw.Write((byte)ibm);

                    // Write FrameData.cHold

                    stmw.Write((byte)fr.HoldCount);

                    // Write FrameData.xOrigin, FrameData.yOrigin

                    if (fr.BitmapPlacers.Count > 0)
                    {
                        stmw.Write((byte)fr.BitmapPlacers[0].X);
                        stmw.Write((byte)fr.BitmapPlacers[0].Y);
                    }
                    else
                    {
                        stmw.Write((byte)0);
                        stmw.Write((byte)0);
                    }

                    if (fr.BitmapPlacers.Count > 1)
                    {
                        stmw.Write((byte)fr.BitmapPlacers[1].X);
                        stmw.Write((byte)fr.BitmapPlacers[1].Y);
                    }
                    else
                    {
                        stmw.Write((byte)0);
                        stmw.Write((byte)0);
                    }

                    // Write FrameData.bCustomData1, FrameData.bCustomData2

                    stmw.Write((byte)fr.SpecialPoint.X);
                    stmw.Write((byte)fr.SpecialPoint.Y);

#if false
                    // Write FrameData.bCustomData3

                    stmw.Write((byte)0);
#endif
                }

                // Force word alignment of StripDatas given that FrameDatas are an odd
                // number of bytes long and there may be an odd number of frames.

                if ((cfrmd & 1) == 1)
                {
                    stmw.Write((byte)0);
                }
            }

            stmw.Close();

            // Write out .tbm

            if (albm.Count != 0)
            {
                string strFileName = strExportPath + Path.DirectorySeparatorChar + strAnimName + ".tbm";
//				if (gfSuperVerbose)
//					Console.WriteLine("Crunching and writing " + strFileName);
                TBitmap.Save((Bitmap[])albm.ToArray(typeof(Bitmap)), pal, strFileName);
            }

            return(true);
        }
Пример #9
0
        static void Main(string[] astr)
        {
            // Special cases
            if (astr.Length == 0)
            {
                Usage();
                return;
            }

            bool   fRaw        = false;
            bool   fFont       = false;
            double nScale      = 1.0;
            bool   fSaveScaled = false;

            int istr = 0;

            for (; istr < astr.Length; istr++)
            {
                if (astr[istr][0] != '-')
                {
                    break;
                }
                switch (astr[istr])
                {
                case "-raw":
                    fRaw = true;
                    break;

                case "-font":
                    fFont = true;
                    break;

                case "-scale":
                    istr++;
                    nScale = double.Parse(astr[istr]);
                    break;

                case "-savescaled":
                    fSaveScaled = true;
                    break;
                }
            }

            // Params: palette outputdir filespecs
            // Get palette
            Palette pal = new Palette(astr[istr++]);

            // Get directory
            string strDir = astr[istr++];

            // Expand filespecs
            ArrayList alsFiles = new ArrayList();

            for (; istr < astr.Length; istr++)
            {
                string strFileT = Path.GetFileName(astr[istr]);
                string strDirT  = Path.GetDirectoryName(astr[istr]);
                if (strDirT == "")
                {
                    strDirT = ".";
                }
                string[] astrFiles = Directory.GetFiles(strDirT, strFileT);
                alsFiles.AddRange(astrFiles);
            }

            // Output
            if (fFont)
            {
                foreach (string strFile in alsFiles)
                {
                    string strFileFnt   = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile.Substring(0, strFile.Length - 4) + ".fnt");
                    string strFileAscii = Path.GetDirectoryName(strFile) + Path.DirectorySeparatorChar + Path.GetFileName(strFile.Substring(0, strFile.Length - 4) + ".txt");
                    Console.WriteLine(strFile + " -> " + strFileFnt);
                    TBitmap.SaveFont(strFile, pal, strFileAscii, strFileFnt);
                }
            }
            else
            {
                if (fRaw)
                {
                    foreach (string strFile in alsFiles)
                    {
                        string strFileRaw = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile.Substring(0, strFile.Length - 4) + ".rbm");
                        BitmapRaw.Save(strFile, pal, strFileRaw);
                    }
                }
                else
                {
                    foreach (string strFile in alsFiles)
                    {
                        string strFileTbm = strDir + Path.DirectorySeparatorChar + Path.GetFileName(strFile.Substring(0, strFile.Length - 4) + ".tbm");
                        Console.WriteLine(strFile + " -> " + strFileTbm);
                        Bitmap[] abm = new Bitmap[1];
                        abm[0] = new Bitmap(strFile);
                        if (nScale != 1.0)
                        {
                            abm[0] = TBitmapTools.ScaleBitmap(abm[0], nScale, pal);
                        }
                        if (fSaveScaled)
                        {
                            abm[0].Save(Path.Combine(strDir, Path.GetFileName(strFile)), ImageFormat.Bmp);
                        }
                        else
                        {
                            TBitmap.Save(abm, pal, strFileTbm);
                        }
                    }
                }
            }
        }