Example #1
0
        public void SetFrame(ImageFormat format, byte[] frameBytes, ImagePalette palette)
        {
            var targetFormat = ImageFormats.GetBestSuitedFormat(format);
            var canConvertFrom = ImageHelper.CanConvertFrom(format);
            if (null == targetFormat || !canConvertFrom )
            {
                throw new UnsupportedImageFormatException(format);
            }

            // Special case - no need to convert
            if( targetFormat.Equals(format))
            {
                SetFrame(frameBytes);
            } else
            {
                var convertedFrameBytes = ImageHelper.Convert(targetFormat, frameBytes, format);
                SetFrame(convertedFrameBytes);
            }
        }
Example #2
0
 record Options(string InputMapPath, ImagePalette Theme, string ImageName, int Scale);
Example #3
0
 static MapPalette PickPalette(ImagePalette palette) => palette switch
 {
Example #4
0
 public void SetFrame(ImageFormat format, byte[] frameBytes, ImagePalette palette)
 {
 }
Example #5
0
        public override void Use(Player p, string message)
        {
            if (!Directory.Exists("extra/images/"))
            {
                Directory.CreateDirectory("extra/images/");
            }
            if (message.Length == 0)
            {
                Help(p); return;
            }
            string[] parts = message.SplitSpaces(3);

            DrawArgs dArgs = new DrawArgs();

            dArgs.palette = ImagePalette.Find("color");
            if (dArgs.palette == null)
            {
                dArgs.palette = ImagePalette.Palettes[0];
            }
            dArgs.dualLayered = false;

            if (parts.Length == 3)
            {
                string mode = parts[2];
                if (mode.CaselessEq("horizontal"))
                {
                    dArgs.layer = true;
                }
                if (mode.CaselessEq("vertical2layer"))
                {
                    dArgs.dualLayered = true;
                }
            }

            if (parts.Length >= 2)
            {
                dArgs.palette = ImagePalette.Find(parts[1]);
                if (dArgs.palette == null)
                {
                    Player.Message(p, "Palette {0} not found.", parts[1]); return;
                }

                if (dArgs.palette.Entries == null || dArgs.palette.Entries.Length == 0)
                {
                    Player.Message(p, "Palette {0} does not have any entries", dArgs.palette.Name);
                    Player.Message(p, "Use %T/Palette %Sto add entries to it"); return;
                }
            }

            if (parts[0].IndexOf('.') != -1)
            {
                if (!DownloadWebFile(parts[0], p))
                {
                    return;
                }
                dArgs.name = "tempImage_" + p.name;
            }
            else
            {
                dArgs.name = parts[0];
            }

            if (!File.Exists("extra/images/" + dArgs.name + ".bmp"))
            {
                Player.Message(p, "The URL entered was invalid!"); return;
            }
            Player.Message(p, "Place or break two blocks to determine direction.");
            p.MakeSelection(2, "Selecting direction for %SImagePrint", dArgs, DoImage);
        }
Example #6
0
        private static RawImage Minimize(ImageBase source, ImagePalette src, ImagePalette dest)
        {
            if(source == null)return null;
            byte[] full = source.ImageData;
            byte[] mini = new byte[64];

            for(int y = 0; y < 8; y++)
            for(int x = 0; x < 8; x++)
            {
                int rs = 0, gs = 0, bs = 0, cn = 0;
                for(int y2 = 0; y2 < 8; y2++)
                for(int x2 = 0; x2 < 8; x2++)
                {
                    Color c = src[full[x*8+x2+(y*8+y2)*64]];
                    rs += c.R;
                    gs += c.G;
                    bs += c.B;
                    cn += 1;
                }
                Color average = Color.FromArgb(Convert.ToInt32(rs/(float)cn), Convert.ToInt32(gs/(float)cn), Convert.ToInt32(bs/(float)cn));
                byte avgbyte = (byte)dest.GetNearestColorIndex(average);
                mini[x+y*8] = avgbyte;
            }
            return new RawImage(mini, 8, 8);
        }
Example #7
0
 public MinimapPalette(ImagePalette source)
     : this(source, MinimapType.Classic)
 {
 }
Example #8
0
        void DoDrawImage(Player p, CatchPos cpos, int direction)
        {
            Bitmap bmp = null;

            try {
                bmp = new Bitmap("extra/images/" + cpos.bitmapLoc + ".bmp");
                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
            } catch (Exception ex) {
                Server.ErrorLog(ex);
                if (bmp != null)
                {
                    bmp.Dispose();
                }
                Player.SendMessage(p, "&cThere was an error reading the downloaded image.");
                Player.SendMessage(p, "&cThe url may need to end with its extension (such as .jpg).");
                return;
            }

            byte popType = cpos.popType;
            bool layer   = cpos.layer;

            if (layer)
            {
                if (popType == 1)
                {
                    popType = 2;
                }
                if (popType == 3)
                {
                    popType = 4;
                }
            }
            ImagePalette.ColorBlock[] palette = ImagePalette.GetPalette(popType);
            ImagePalette.ColorBlock   cur;

            for (int yy = 0; yy < bmp.Height; yy++)
            {
                for (int xx = 0; xx < bmp.Width; xx++)
                {
                    if (layer)
                    {
                        cur.y = cpos.y;
                        if (direction <= 1)
                        {
                            if (direction == 0)
                            {
                                cur.x = (ushort)(cpos.x + xx); cur.z = (ushort)(cpos.z - yy);
                            }
                            else
                            {
                                cur.x = (ushort)(cpos.x - xx); cur.z = (ushort)(cpos.z + yy);
                            }
                        }
                        else
                        {
                            if (direction == 2)
                            {
                                cur.z = (ushort)(cpos.z + xx); cur.x = (ushort)(cpos.x + yy);
                            }
                            else
                            {
                                cur.z = (ushort)(cpos.z - xx); cur.x = (ushort)(cpos.x - yy);
                            }
                        }
                    }
                    else
                    {
                        cur.y = (ushort)(cpos.y + yy);
                        if (direction <= 1)
                        {
                            if (direction == 0)
                            {
                                cur.x = (ushort)(cpos.x + xx);
                            }
                            else
                            {
                                cur.x = (ushort)(cpos.x - xx);
                            }
                            cur.z = cpos.z;
                        }
                        else
                        {
                            if (direction == 2)
                            {
                                cur.z = (ushort)(cpos.z + xx);
                            }
                            else
                            {
                                cur.z = (ushort)(cpos.z - xx);
                            }
                            cur.x = cpos.x;
                        }
                    }

                    Color col = bmp.GetPixel(xx, yy);
                    cur.r = col.R; cur.g = col.G; cur.b = col.B; cur.a = col.A;
                    if (popType == 6)
                    {
                        int brightness = (cur.r + cur.g + cur.b) / 3;
                        if (brightness < (256 / 4))
                        {
                            cur.type = Block.obsidian;
                        }
                        else if (brightness >= (256 / 4) && brightness < (256 / 4) * 2)
                        {
                            cur.type = Block.darkgrey;
                        }
                        else if (brightness >= (256 / 4) * 2 && brightness < (256 / 4) * 3)
                        {
                            cur.type = Block.lightgrey;
                        }
                        else
                        {
                            cur.type = Block.white;
                        }
                    }
                    else
                    {
                        int minimum = int.MaxValue, position = 0;
                        for (int i = 0; i < palette.Length; i++)
                        {
                            ImagePalette.ColorBlock pixel = palette[i];
                            int dist = (cur.r - pixel.r) * (cur.r - pixel.r)
                                       + (cur.g - pixel.g) * (cur.g - pixel.g)
                                       + (cur.b - pixel.b) * (cur.b - pixel.b);

                            if (dist < minimum)
                            {
                                minimum = dist; position = i;
                            }
                        }

                        cur.type = palette[position].type;
                        if (popType == 1 || popType == 3)
                        {
                            int threshold = popType == 1 ? 20 : 3;
                            if (position <= threshold)
                            {
                                if (direction == 0)
                                {
                                    cur.z = (ushort)(cur.z + 1);
                                }
                                else if (direction == 2)
                                {
                                    cur.x = (ushort)(cur.x - 1);
                                }
                                else if (direction == 1)
                                {
                                    cur.z = (ushort)(cur.z - 1);
                                }
                                else if (direction == 3)
                                {
                                    cur.x = (ushort)(cur.x + 1);
                                }
                            }
                        }
                    }

                    if (cur.a < 20)
                    {
                        cur.type = Block.air;
                    }
                    p.level.UpdateBlock(p, cur.x, cur.y, cur.z, cur.type, 0);
                }
            }

            if (cpos.bitmapLoc == "tempImage_" + p.name)
            {
                File.Delete("extra/images/tempImage_" + p.name + ".bmp");
            }
            Player.SendMessage(p, "Finished printing image using " + ImagePalette.Names[popType]);
        }
		public void SetFrame(ImageFormat format, byte[] frameBytes, ImagePalette palette)
		{
		}
Example #10
0
 /// <summary>
 /// Creates new instance.
 /// </summary>
 public static RawImage FromBitmap(Bitmap bmp, ImagePalette palette)
 {
     return new RawImage(Drawing.LoadBitmap(bmp, palette), bmp.Width, bmp.Height);
 }
Example #11
0
 public static byte[] Convert(ImageFormat destinationFormat, byte[] sourcePixels, ImageFormat sourceFormat, ImagePalette palette)
 {
     throw new NotImplementedException();
 }
Example #12
0
        /// <summary>
        /// Combines all tiles to form a graphic plane.
        /// </summary>
        /// <returns>
        /// Newly created graphic plane.
        /// </returns>
        public GraphicPlane Combine(CombineArgs args)
        {
            if (this.Type == MapType.Map2D)
            {
                GraphicPlane plane = new GraphicPlane(this.Width * 16, this.Height * 16);
                plane.Palette = ImagePalette.GetFullPalette(this.Palette);
                foreach (Tile t in this.TileData)
                {
                    Point loc = new Point(t.X * 16, t.Y * 16);
                    if (args.ShowUnderlays)
                    {
                        RawImage ul = MapIcons.GetTileUnderlay(this.Tileset, t);
                        plane.Objects.Add(new GraphicObject(ul, loc));
                    }
                    if (!args.ShowHelpers && IsHelperTile(tilesid, t.Overlay))
                    {
                        continue;
                    }
                    if (args.ShowOverlays)
                    {
                        RawImage ol = MapIcons.GetTileOverlay(this.Tileset, t);
                        plane.Objects.Add(new GraphicObject(ol, loc));
                    }
                }
                if (args.ShowNPCs2D)
                {
                    foreach (NPC npc in UsedNPCs)
                    {
                        ImageBase img = NPCGraphics.GetNPCBig(npc.ObjectID)[6];
                        Point     loc = new Point(npc.X * 16, npc.Y * 16 - img.GetHeight() + 16);
                        plane.Objects.Add(new GraphicObject(img, loc));
                    }
                }
                return(plane);
            }
            else if (this.Type == MapType.Map3D)
            {
                MinimapType mt = MinimapType.Classic;
                LabData     ld = LabData.GetLabData(this.Labdata);

                GraphicPlane plane = new GraphicPlane(this.Width * 8, this.Height * 8);
                ImagePalette src   = ImagePalette.GetFullPalette(this.Palette);
                ImagePalette dest  = plane.Palette = new MinimapPalette(src);

                if (ld != null)
                {
                    if (args.ShowFloors)
                    {
                        //Floors
                        IndexedCache <RawImage> floorcache = new IndexedCache <RawImage>(i => Minimize(LabGraphics.GetFloor(this.Labdata, i), src, dest));
                        foreach (Block b in this.BlockData)
                        {
                            if (b.Floor != 0)
                            {
                                Point loc = new Point(b.X * 8, b.Y * 8);
                                plane.Objects.Add(new GraphicObject(floorcache[b.Floor], loc));
                            }
                        }
                    }

                    if (args.ShowWalls)
                    {
                        //Walls
                        foreach (Block b in this.BlockData)
                        {
                            if (b.IsWall && !ld.GetMinimapForm(b).VisibleOnMinimap)
                            {
                                WallForm form = WallForm.Close;
                                if (b.Y > 0 && BlockData[b.X, b.Y - 1].IsWall)
                                {
                                    form |= WallForm.OpenTop;
                                }
                                if (b.X < Width - 1 && BlockData[b.X + 1, b.Y].IsWall)
                                {
                                    form |= WallForm.OpenRight;
                                }
                                if (b.Y < Height - 1 && BlockData[b.X, b.Y + 1].IsWall)
                                {
                                    form |= WallForm.OpenBottom;
                                }
                                if (b.X > 0 && BlockData[b.X - 1, b.Y].IsWall)
                                {
                                    form |= WallForm.OpenLeft;
                                }
                                Point loc = new Point(b.X * 8, b.Y * 8);
                                plane.Objects.Add(new GraphicObject(AutoGFX.GetWall(form, mt), loc));
                            }
                        }
                    }
                }

                foreach (Block b in this.BlockData)
                {
                    Point loc = new Point(b.X * 8, (b.Y - 1) * 8);
                    if (args.ShowNPCs3D)
                    {
                        //NPCs
                        foreach (NPC npc in UsedNPCs)
                        {
                            if (npc.Positions[0].X == b.X && npc.Positions[0].Y == b.Y)
                            {
                                byte type = 0;
                                if (npc.Interaction == 2)
                                {
                                    type = 8;
                                }
                                else
                                {
                                    type = 17;
                                }
                                if (type != 0)
                                {
                                    plane.Objects.Add(new GraphicObject(AutoGFX.GetIcon(type, mt), loc));
                                }
                            }
                        }
                    }

                    if (args.ShowObjects)
                    {
                        //Objects
                        if (ld != null)
                        {
                            if (!b.IsEmpty)
                            {
                                byte type = ld.GetMinimapForm(b).MinimapType;
                                plane.Objects.Add(new GraphicObject(AutoGFX.GetIcon(type, mt), loc));
                            }
                        }
                    }

                    if (args.ShowGotoPoints)
                    {
                        //Goto-points
                        if (b.GotoPoint != null)
                        {
                            plane.Objects.Add(new GraphicObject(AutoGFX.GetIcon(18, mt), loc));
                        }
                    }
                }
                return(plane);
            }
            return(null);
        }
Example #13
0
 public MinimapPalette(ImagePalette source, ImagePalette minimap)
 {
     this.source = source;
     this.minimap = minimap;
 }
Example #14
0
 public MinimapPalette(ImagePalette source, MinimapType type)
     : this(source, type==MinimapType.Classic?ImagePalette.GetPalette(21):ImagePalette.GetPalette(46))
 {
 }
Example #15
0
 /// <summary>
 /// Creates new instance using source palette.
 /// </summary>
 /// <param name="inner">Souce palette.</param>
 public ModifierPalette(ImagePalette inner)
 {
     Inner = inner;
 }
Example #16
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (!Directory.Exists("extra/images/"))
            {
                Directory.CreateDirectory("extra/images/");
            }
            if (message.Length == 0)
            {
                Help(p); return;
            }
            string[] parts = message.SplitSpaces(5);

            DrawArgs dArgs = new DrawArgs();

            dArgs.Pal = ImagePalette.Find("color");
            if (dArgs.Pal == null)
            {
                dArgs.Pal = ImagePalette.Palettes[0];
            }

            if (parts.Length > 1)
            {
                dArgs.Pal = ImagePalette.Find(parts[1]);
                if (dArgs.Pal == null)
                {
                    p.Message("Palette {0} not found.", parts[1]); return;
                }

                if (dArgs.Pal.Entries == null || dArgs.Pal.Entries.Length == 0)
                {
                    p.Message("Palette {0} does not have any entries", dArgs.Pal.Name);
                    p.Message("Use &T/Palette %Sto add entries to it"); return;
                }
            }

            if (parts.Length > 2)
            {
                string mode = parts[2];
                if (mode.CaselessEq("horizontal"))
                {
                    dArgs.Layer = true;
                }
                if (mode.CaselessEq("vertical2layer"))
                {
                    dArgs.Dual = true;
                }
            }

            if (parts.Length > 4)
            {
                if (!CommandParser.GetInt(p, parts[3], "Width", ref dArgs.Width, 1, 1024))
                {
                    return;
                }
                if (!CommandParser.GetInt(p, parts[4], "Height", ref dArgs.Height, 1, 1024))
                {
                    return;
                }
            }

            if (parts[0].IndexOf('.') != -1)
            {
                dArgs.Data = HttpUtil.DownloadImage(parts[0], p);
                if (dArgs.Data == null)
                {
                    return;
                }
            }
            else
            {
                string path = "extra/images/" + parts[0] + ".bmp";
                if (!File.Exists(path))
                {
                    p.Message("{0} does not exist", path); return;
                }
                dArgs.Data = File.ReadAllBytes(path);
            }

            p.Message("Place or break two blocks to determine direction.");
            p.MakeSelection(2, "Selecting direction for %SImagePrint", dArgs, DoImage);
        }
Example #17
0
 public ModifierPalette(ImagePalette inner, params BlockModifier[] modifiers)
 {
     Inner = inner;
     Modifiers = modifiers;
 }
Example #18
0
 /// <summary>
 /// Draws the image to bitmap.
 /// </summary>
 /// <param name="palette">
 /// Palette.
 /// </param>
 /// <returns>
 /// Drawn image.
 /// </returns>
 public Image Render(ImagePalette palette)
 {
     return Render(new RenderOptions(palette));
 }
Example #19
0
 public static byte[] Convert(ImageFormat destinationFormat, byte[] sourcePixels, ImageFormat sourceFormat, ImagePalette palette)
 {
     throw new NotImplementedException();
 }
Example #20
0
 /// <summary>
 /// Converts bitmap to byte array using external palette.
 /// </summary>
 public static byte[] LoadBitmap(Bitmap bmp, ImagePalette palette)
 {
     byte[] result = new byte[bmp.Width*bmp.Height];
     BitmapData data = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
     for(int y = 0; y < bmp.Height; y++)
     for(int x = 0; x < bmp.Width; x++)
     {
         byte r = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3);
         byte g = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3+1);
         byte b = Marshal.ReadByte(data.Scan0, y*data.Stride+x*3+2);
         result[y*bmp.Width+x] = (byte)palette.GetNearestColorIndex(Color.FromArgb(r,g,b));
     }
     return result;
 }