Example #1
0
 public ParserState(string rtfValue)
 {
     this.rtfValue = rtfValue;
       position = -1;
       Advance();
       ColorTable = new ColorTable();
 }
Example #2
0
 public mIRCCodeTextBox()
 {
     InitializeComponent();
     ColorTableValue = ColorTable.mIRCDefaultColorTable;
     DefaultBackgroundColorValue = 1;
     DefaultForegroundColorValue = 2;
 }
Example #3
0
        public mIRCCodeTextBox(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
            ColorTableValue = ColorTable.mIRCDefaultColorTable;
            DefaultBackgroundColorValue = 1;
            DefaultForegroundColorValue = 2;
        }
Example #4
0
 /// <summary>
 /// Initialize instance
 /// </summary>
 public DocumentWriter()
 {
     Info = new Hashtable();
     DebugMode = true;
     CollectionInfo = true;
     ColorTable = new ColorTable();
     ListOverrideTable = new ListOverrideTable();
     ListTable = new ListTable();
     FontTable = new Table();
     ColorTable.CheckValueExistWhenAdd = true;
 }
 //拷贝
 public void copyTo(ColorTable otherTable)
 {
     if (otherTable != null)
     {
         otherTable.colorList.Clear();
         for (int i = 0; i < colorList.Count; i++)
         {
             int color = (int)colorList[i];
             otherTable.colorList.Add(color);
         }
     }
 }
Example #6
0
 /// <summary>
 /// Initialize instance from a file
 /// </summary>
 /// <param name="fileName"></param>
 public DocumentWriter(string fileName)
 {
     Info = new Hashtable();
     DebugMode = true;
     CollectionInfo = true;
     ColorTable = new ColorTable();
     ListOverrideTable = new ListOverrideTable();
     ListTable = new ListTable();
     FontTable = new Table();
     ColorTable.CheckValueExistWhenAdd = true;
     // ReSharper disable once DoNotCallOverridableMethodsInConstructor
     Open(fileName);
 }
Example #7
0
        /// <summary>
        /// Erstellt ein neues Bitmap mit den angegebenen Abmessungen. Diese Bitmaps werden am Ende immer nach dem Bottom-Up-Verfahren geschrieben.
        /// </summary>
        /// <param name="width">Die Breite des zu erstellenden Bitmaps.</param>
        /// <param name="height">Die Höhe des zu erstellenden Bitmaps.</param>
        /// <param name="pal">Gibt die zu verwendende 256er-Farbtabelle an. Standardwert ist die 50500er-Farbtabelle.</param>
        public BitmapLoader(int width, int height, ColorTable pal)
        {
            // Header initialisieren
            _header = new Header();
            _header.height = Math.Abs(height);
            _header.width = Math.Abs(width);

            // Farbtabelle initialisieren
            _colorTable = pal;

            // Bilddaten-Array initialisieren
            _imageData = new byte[_header.width * _header.height];
        }
Example #8
0
 /// <summary>
 /// Initialize instance from a stream
 /// </summary>
 /// <param name="stream"></param>
 public DocumentWriter(Stream stream)
 {
     Info = new Hashtable();
     DebugMode = true;
     CollectionInfo = true;
     ColorTable = new ColorTable();
     ListOverrideTable = new ListOverrideTable();
     ListTable = new ListTable();
     FontTable = new Table();
     ColorTable.CheckValueExistWhenAdd = true;
     var writer = new StreamWriter(stream, Encoding.ASCII);
     // ReSharper disable once DoNotCallOverridableMethodsInConstructor
     Open(writer);
 }
Example #9
0
        private void ReloadColors()
        {
            _colorTable = new ColorTable
            {
                ControlBackground = VSColorTheme.GetThemedColor(EnvironmentColors.EnvironmentBackgroundColorKey),
                ControlText = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey),

                MenuBackground = VSColorTheme.GetThemedColor(EnvironmentColors.CommandBarMenuBackgroundGradientBeginColorKey),

                WindowBackground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey),
                WindowText = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey),

                HighlightBackground = VSColorTheme.GetThemedColor(EnvironmentColors.SystemHighlightColorKey),
                HighlightInactiveBackground = VSColorTheme.GetThemedColor(EnvironmentColors.SystemActiveBorderColorKey),

                HighlightText = VSColorTheme.GetThemedColor(EnvironmentColors.SystemHighlightTextColorKey),
                HighlightInactiveText = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey),

                GridLines = VSColorTheme.GetThemedColor(EnvironmentColors.GridLineColorKey),

                TabText = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTabTextColorKey),
            };

            //    //collect all colors
            //    var props = typeof(EnvironmentColors).GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.GetProperty);

            //    var dic = new Dictionary<string, object>();
            //    int i=0;
            //    foreach (var p in props.Where(p => p.PropertyType == typeof(ThemeResourceKey)))
            //    {
            //        try
            //        {
            //            var resKey = (ThemeResourceKey)p.GetValue(null);
            //            var color = VSColorTheme.GetThemedColor(resKey);
            //            dic.Add(p.Name, new
            //            {
            //                index = i,
            //                color = System.Drawing.ColorTranslator.ToHtml(color),
            //            });
            //        }
            //        catch { }
            //        ++i;
            //    }

            //    File.WriteAllText("c:\\vscolors_new.txt", new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(dic));
            //
        }
Example #10
0
 /// <summary>
 /// initialize instance
 /// </summary>
 public DomDocument()
 {
     DefaultRowHeight = 400;
     FooterDistance = 720;
     HeaderDistance = 720;
     BottomMargin = 1440;
     RightMargin = 1800;
     TopMargin = 1440;
     LeftMargin = 1800;
     PaperHeight = 15840;
     PaperWidth = 12240;
     Info = new DocumentInfo();
     ListOverrideTable = new ListOverrideTable();
     ListTable = new ListTable();
     ColorTable = new ColorTable();
     FontTable = new Table();
     ChangeTimesNewRoman = false;
     Generator = null;
     LeadingChars = null;
     FollowingChars = null;
     OwnerDocument = this;
 }
        //创建Alpha图片,并有相应的调色板映射表
        public static Image createAlphaPmtImage(String path_folder, String imgName, String alphaName, String pmtName,int alpha)
        {
            String imgPath = path_folder + Consts.SUBPARH_IMG + imgName;
            String alphaPath = path_folder + Consts.SUBPARH_IMG + alphaName;
            String pmtPath = path_folder + Consts.SUBPARH_IMG + pmtName;
            if (imgPath.ToLower().EndsWith("bmp"))
            {
                byte[] bmpData = IOUtil.ReadFile(imgPath);
                if (bmpData == null)
                {
                    MessageBox.Show("未找到指定图片:" + imgName, "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return null;
                }
                //替换调色板映射表
                if (pmtName != null && !pmtName.Equals(""))
                {
                    MessageBox.Show("BMP图片暂不支持调色板映射,因为颜色太多。后面需要使用调色公式来转换。", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //生成图片
                MemoryStream ms = new MemoryStream(bmpData);
                Bitmap img = new Bitmap(ms);
                //Alpha混合
                bool hasAlphaImg = alphaName != null && !alphaName.Equals("");
                if (hasAlphaImg || alpha != 0xFF)
                {
                    Bitmap imgAlpha = null;
                    if (File.Exists(alphaPath))
                    {
                        imgAlpha = (Bitmap)(IOUtil.createImage(alphaPath));
                    }
                    else if (hasAlphaImg)
                    {
                        MessageBox.Show("Alpha文件丢失:" + alphaName, "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    img = createAlpahImage(img, imgAlpha, alpha);
                }
                return img;
            }
            else if (imgPath.ToLower().EndsWith("png"))
            {
                byte[] pngData = IOUtil.ReadFile(imgPath);
                if (pngData == null)
                {
                    MessageBox.Show("未找到指定图片:" + imgName, "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return null;
                }
                byte[] palData = GraphicsUtil.getPngPal(pngData);
                if (palData!= null)
                {
                    //替换调色板映射表
                    if (pmtName != null && !pmtName.Equals(""))
                    {
                        if (File.Exists(pmtPath))
                        {
                            FileStream fs = new FileStream(pmtPath, FileMode.Open);
                            if (fs.CanRead)
                            {
                                ColorTable srcColorTableNew = new ColorTable();
                                ColorTable destColorTableNew = new ColorTable();
                                srcColorTableNew.readObject(fs, false);
                                destColorTableNew.readObject(fs, false);
                                fs.Close();
                                //int ignoreID = GraphicsUtil.getPngTransID(pngData);
                                applyPmt(palData, srcColorTableNew, destColorTableNew, -1);
                                srcColorTableNew.removeAllColors();
                                destColorTableNew.removeAllColors();
                                srcColorTableNew = null;
                                destColorTableNew = null;
                                //更新CRC
                                GraphicsUtil.updatePalCrc(palData);
                                //替换调色板数据
                                pngData = GraphicsUtil.changePalData(pngData, palData);
                            }
                        }
                        else
                        {
                            MessageBox.Show("映射表文件丢失:" + pmtName, "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                    }
                }

                //生成图片
                MemoryStream ms = new MemoryStream(pngData);
                Bitmap img = new Bitmap(ms);
                //Alpha混合
                bool hasAlphaImg = alphaName != null && !alphaName.Equals("");
                if (hasAlphaImg || alpha != 0xFF)
                {
                    Bitmap imgAlpha = null;
                    if (File.Exists(alphaPath))
                    {
                        imgAlpha = (Bitmap)(IOUtil.createImage(alphaPath));
                    }
                    else if (hasAlphaImg)
                    {
                        MessageBox.Show("Alpha文件丢失:" + alphaName, "警告", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    img = createAlpahImage(img, imgAlpha, alpha);
                }
                return img;
            }
  
            return null;
        }
        public static String DumpDatasetInfo(Dataset ds)
        {
            var sb = new StringBuilder();

            sb.AppendLine("Raster dataset parameters:");
            sb.AppendLine("  Projection: " + ds.GetProjectionRef());
            sb.AppendLine("  RasterCount: " + ds.RasterCount);
            sb.AppendLine("  RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")");

            /* -------------------------------------------------------------------- */
            /*      Get driver                                                      */
            /* -------------------------------------------------------------------- */
            var drv = ds.GetDriver();

            if (drv == null)
            {
                sb.AppendLine("Can't get driver.");
                return(sb.ToString());
            }

            sb.AppendLine("Using driver " + drv.LongName);

            /* -------------------------------------------------------------------- */
            /*      Get metadata                                                    */
            /* -------------------------------------------------------------------- */
            string[] metadata = ds.GetMetadata("");
            if (metadata.Length > 0)
            {
                sb.AppendLine("  Metadata:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    sb.AppendLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report "IMAGE_STRUCTURE" metadata.                              */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("IMAGE_STRUCTURE");
            if (metadata.Length > 0)
            {
                sb.AppendLine("  Image Structure Metadata:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    sb.AppendLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report subdatasets.                                             */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("SUBDATASETS");
            if (metadata.Length > 0)
            {
                sb.AppendLine("  Subdatasets:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    sb.AppendLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report geolocation.                                             */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("GEOLOCATION");
            if (metadata.Length > 0)
            {
                sb.AppendLine("  Geolocation:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    sb.AppendLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report corners.                                                 */
            /* -------------------------------------------------------------------- */
            sb.AppendLine("Corner Coordinates:");
            sb.AppendLine("  Upper Left (" + GdalInfoGetPosition(ds, 0.0, 0.0) + ")");
            sb.AppendLine("  Lower Left (" + GdalInfoGetPosition(ds, 0.0, ds.RasterYSize) + ")");
            sb.AppendLine("  Upper Right (" + GdalInfoGetPosition(ds, ds.RasterXSize, 0.0) + ")");
            sb.AppendLine("  Lower Right (" + GdalInfoGetPosition(ds, ds.RasterXSize, ds.RasterYSize) + ")");
            sb.AppendLine("  Center (" + GdalInfoGetPosition(ds, ds.RasterXSize / 2.0, ds.RasterYSize / 2.0) + ")");
            sb.AppendLine("");

            /* -------------------------------------------------------------------- */
            /*      Report projection.                                              */
            /* -------------------------------------------------------------------- */
            string projection = ds.GetProjectionRef();

            if (projection != null)
            {
                SpatialReference srs = new SpatialReference(null);
                if (srs.ImportFromWkt(ref projection) == 0)
                {
                    srs.ExportToPrettyWkt(out var wkt, 0);
                    sb.AppendLine("Coordinate System is:");
                    sb.AppendLine(wkt);
                }
                else
                {
                    sb.AppendLine("Coordinate System is:");
                    sb.AppendLine(projection);
                }
            }

            /* -------------------------------------------------------------------- */
            /*      Report GCPs.                                                    */
            /* -------------------------------------------------------------------- */
            if (ds.GetGCPCount() > 0)
            {
                sb.AppendLine("GCP Projection: " + ds.GetGCPProjection());
                GCP[] gcps = ds.GetGCPs();
                for (int i = 0; i < ds.GetGCPCount(); i++)
                {
                    sb.AppendLine("GCP[" + i + "]: Id=" + gcps[i].Id + ", Info=" + gcps[i].Info);
                    sb.AppendLine("          (" + gcps[i].GCPPixel + "," + gcps[i].GCPLine + ") -> ("
                                  + gcps[i].GCPX + "," + gcps[i].GCPY + "," + gcps[i].GCPZ + ")");
                    sb.AppendLine("");
                }
                sb.AppendLine("");

                double[] transform = new double[6];
                Gdal.GCPsToGeoTransform(gcps, transform, 0);
                sb.AppendLine("GCP Equivalent geotransformation parameters: " + ds.GetGCPProjection());
                for (int i = 0; i < 6; i++)
                {
                    sb.AppendLine("t[" + i + "] = " + transform[i]);
                }
                sb.AppendLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Get raster band                                                 */
            /* -------------------------------------------------------------------- */
            for (int iBand = 1; iBand <= ds.RasterCount; iBand++)
            {
                Band band = ds.GetRasterBand(iBand);
                sb.AppendLine("Band " + iBand + " :");
                sb.AppendLine("   DataType: " + Gdal.GetDataTypeName(band.DataType));
                sb.AppendLine("   ColorInterpretation: " + Gdal.GetColorInterpretationName(band.GetRasterColorInterpretation()));
                ColorTable ct = band.GetRasterColorTable();
                if (ct != null)
                {
                    sb.AppendLine("   Band has a color table with " + ct.GetCount() + " entries.");
                }

                sb.AppendLine("   Description: " + band.GetDescription());
                sb.AppendLine("   Size (" + band.XSize + "," + band.YSize + ")");
                band.GetBlockSize(out var blockXSize, out var blockYSize);
                sb.AppendLine("   BlockSize (" + blockXSize + "," + blockYSize + ")");
                band.GetMinimum(out var val, out var hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   Minimum: " + val);
                }
                band.GetMaximum(out val, out hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   Maximum: " + val);
                }
                band.GetNoDataValue(out val, out hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   NoDataValue: " + val);
                }
                band.GetOffset(out val, out hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   Offset: " + val);
                }
                band.GetScale(out val, out hasVal);
                if (hasVal != 0)
                {
                    sb.AppendLine("   Scale: " + val);
                }

                for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++)
                {
                    Band over = band.GetOverview(iOver);
                    sb.AppendLine("      OverView " + iOver + " :");
                    sb.AppendLine("         DataType: " + over.DataType);
                    sb.AppendLine("         Size (" + over.XSize + "," + over.YSize + ")");
                    sb.AppendLine("         PaletteInterpretation: " + over.GetRasterColorInterpretation());
                }
            }

            return(sb.ToString());
        }
 //对调色板数据应用映射表
 public static void applyPmt(byte[] palData, ColorTable srcColorTable, ColorTable destColorTable, int ignoreID)
 {
     int color, colorJ;
     int palLen = (palData.Length - 4) / 3;
     ArrayList modifiedColors = new ArrayList();
     for (int i = 0; i < srcColorTable.getColorCount(); i++)
     {
         color = (int)srcColorTable.getColor(i);
         for (int j = 0; j < palLen; j++)
         {
             if (modifiedColors.Contains(j))
             {
                 continue;
             }
             if (j == ignoreID)
             {
                 continue;//跳过透明色
             }
             else
             {
                 colorJ = (0xFF << 24) | (palData[j * 3] << 16) | (palData[j * 3 + 1] << 8) | (palData[j * 3 + 2]);
             }
             if (colorJ == color)
             {
                 int mappedColor = (int)destColorTable.getColor(i);
                 palData[j * 3] = (byte)((mappedColor >> 16) & 0xFF);
                 palData[j * 3 + 1] = (byte)((mappedColor >> 8) & 0xFF);
                 palData[j * 3 + 2] = (byte)((mappedColor) & 0xFF);
                 modifiedColors.Add(j);
             }
         }
     }
     modifiedColors.Clear();
     modifiedColors = null;
 }
Example #14
0
 /// <summary>
 /// Clone the object
 /// </summary>
 /// <returns></returns>
 public ColorTable Clone()
 {
     var colorTable = new ColorTable();
     for (var count = 0; count < _arrayList.Count; count++)
     {
         var c = (Color) _arrayList[count];
         colorTable._arrayList.Add(c);
     }
     return colorTable;
 }
Example #15
0
        private Bitmap ReadPaletteBuffered(int xOffset, int yOffset, int xSize, int ySize, Band first)
        {
            ColorTable ct = first.GetRasterColorTable();

            if (ct == null)
            {
                throw new GdalException("Image was stored with a palette interpretation but has no color table.");
            }

            if (ct.GetPaletteInterpretation() != PaletteInterp.GPI_RGB)
            {
                throw new GdalException("Only RGB palette interpretation is currently supported by this " + " plug-in, " + ct.GetPaletteInterpretation() + " is not supported.");
            }

            Band firstO;
            bool disposeO = false;

            if (_overview >= 0 && first.GetOverviewCount() > 0)
            {
                firstO   = first.GetOverview(_overview);
                disposeO = true;
            }
            else
            {
                firstO = first;
            }

            int width, height;

            NormalizeSizeToBand(xOffset, yOffset, xSize, ySize, firstO, out width, out height);
            byte[] r = new byte[width * height];

            firstO.ReadRaster(xOffset, yOffset, width, height, r, width, height, 0, 0);
            if (disposeO)
            {
                firstO.Dispose();
            }

            Bitmap result = new(width, height, PixelFormat.Format32bppArgb);

            BitmapData bData  = result.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            int        stride = Math.Abs(bData.Stride);

            const int Bpp = 4;

            byte[]   vals       = new byte[stride * height];
            byte[][] colorTable = new byte[ct.GetCount()][];
            for (int i = 0; i < ct.GetCount(); i++)
            {
                ColorEntry ce = ct.GetColorEntry(i);
                colorTable[i] = new[] { (byte)ce.c3, (byte)ce.c2, (byte)ce.c1, (byte)ce.c4 };
            }

            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    Array.Copy(colorTable[r[col + (row * width)]], 0, vals, (row * stride) + (col * Bpp), 4);
                }
            }

            Marshal.Copy(vals, 0, bData.Scan0, vals.Length);
            result.UnlockBits(bData);
            return(result);
        }
Example #16
0
		/// <summary>
		/// Exportiert den angegebenen Frame in eine Bitmap-Datei (50500er-Palette).
		/// </summary>
		/// <param name="frameID">Die ID des zu exportierenden Frame.</param>
		/// <param name="Pal">Die Farbtabelle.</param>
		/// <param name="filename">Die Bitmap-Datei, in die die Daten geschrieben werden sollen.</param>
		/// <param name="mask">Die zu exportierende Maske (oder reine Grafik) als Element der Masks-Enumeration.</param>
		public void exportFrame(int frameID, string filename, ColorTable Pal, Masks mask = Masks.Graphic)
		{
			// Framedaten abrufen
			FrameInformationHeader FIH = _frameInformationHeaders[(int)frameID];

			// Rückgabebild erstellen
			BitmapLoader bmp = new BitmapLoader((int)FIH.Width, (int)FIH.Height, Pal);

			// Welche Maske ist gewollt?
			if(mask == Masks.Graphic) // Es handelt sich um die reine Frame-Grafik
			{
				// Bild pixelweise durchgehen
				for(int i = 0; i < FIH.Width; i++)
				{
					for(int j = 0; j < FIH.Height; j++)
					{
						// Palettenindex abrufen
						int farbID = _frameInformationData[(int)frameID].CommandTable[j, i];

						// Sonderindizes in die jeweiligen Farben umsetzen; meist Rein-Weiß
						switch(farbID)
						{
							case -1:
								farbID = 255;
								break;

							case -2:
								farbID = 255;
								break;

							case -3:
								farbID = 255;
								break;

							case -4:
								farbID = _schatten;
								break;
						}

						// Pixel in das Bild schreiben
						bmp[i, j] = (byte)farbID;
					}
				}
			}
			else if(mask != Masks.PlayerColor) // Es handelt sich um eine Maske (außer der Spielerfarbe)
			{
				// Den Index und die Zielfarbe angeben
				int maskIndex = 0;
				int maskColor = 0;
				if(mask == Masks.Transparency)
				{
					maskIndex = -1;
					maskColor = 0;
				}
				else if(mask == Masks.Outline1)
				{
					maskIndex = -2;
					maskColor = 8;
				}
				else if(mask == Masks.Outline2)
				{
					maskIndex = -3;
					maskColor = 124;
				}
				else if(mask == Masks.Shadow)
				{
					maskIndex = -4;
					maskColor = 131;
				}

				// Bild pixelweise durchgehen
				for(int i = 0; i < FIH.Width; i++)
				{
					for(int j = 0; j < FIH.Height; j++)
					{
						// Palettenindex abrufen
						int farbID = _frameInformationData[(int)frameID].CommandTable[j, i];

						// Je nach Masken Farben setzen
						if(farbID == maskIndex)
						{
							// Masken-Farbe übernehmen
							farbID = maskColor;
						}
						else
						{
							// Keine Maske, also weiß
							farbID = 255;
						}

						// Pixel übernehmen
						bmp[i, j] = (byte)farbID;
					}
				}
			}
			else // Spielerfarbe
			{
				// Bild pixelweise durchgehen
				for(int i = 0; i < FIH.Width; i++)
				{
					for(int j = 0; j < FIH.Height; j++)
					{
						// Palettenindex abrufen
						int farbID = _frameInformationData[(int)frameID].CommandTable[j, i];

						// Liegt keine Spielerfarbe vor?
						if(farbID < 16 || farbID > 23)
						{
							// Pixel weiß einfärben
							farbID = 255;
						}

						// Pixel übernehmen
						bmp[i, j] = (byte)farbID;
					}
				}
			}

			// Fertig, Bild speichern
			bmp.saveToFile(filename);
		}
Example #17
0
		/// <summary>
		/// Gibt den angegebenen Frame als Farbarray zurück.
		/// </summary>
		/// <param name="frameID">Die ID des Frames.</param>
		/// <param name="Pal">Die zu verwendende Farbpalette als Palette-Objekt.</param>
		/// <param name="mask">Optional. Gibt die abzurufende Maske an; Standardwert ist die reine Frame-Grafik.</param>
		/// <remarks></remarks>
		public Color[,] getFrameAsColorArray(uint frameID, ColorTable Pal, Masks mask = Masks.Graphic)
		{
			// Framedaten abrufen
			FrameInformationHeader FIH = _frameInformationHeaders[(int)frameID];

			// Rückgabebild erstellen
			Color[,] ret = new Color[FIH.Width, FIH.Height];

			// Welche Maske ist gewollt?
			if(mask == Masks.Graphic) // Es handelt sich um die reine Frame-Grafik
			{
				// Bild pixelweise durchgehen
				for(int i = 0; i < FIH.Width; i++)
				{
					for(int j = 0; j < FIH.Height; j++)
					{
						// Palettenindex abrufen
						int farbID = _frameInformationData[(int)frameID].CommandTable[j, i];

						// Sonderindizes in die jeweiligen Farben umsetzen; meist Rein-Weiß
						switch(farbID)
						{
							case -1:
								farbID = 255;
								break;

							case -2:
								farbID = 255;
								break;

							case -3:
								farbID = 255;
								break;

							case -4:
								farbID = _schatten;
								break;
						}

						// Pixel in das Bild schreiben
						ret[i, j] = (farbID == 255 ? Color.FromArgb(0, 255, 255, 255) : Pal[farbID]); // 255er-Weiß gilt als transparent (Alpha = 0)
					}
				}
			}
			else if(mask != Masks.PlayerColor) // Es handelt sich um eine Maske (außer der Spielerfarbe)
			{
				// Den Index und die Zielfarbe angeben
				int maskIndex = 0;
				int maskColor = 0;
				if(mask == Masks.Transparency)
				{
					maskIndex = -1;
					maskColor = 0;
				}
				else if(mask == Masks.Outline1)
				{
					maskIndex = -2;
					maskColor = 8;
				}
				else if(mask == Masks.Outline2)
				{
					maskIndex = -3;
					maskColor = 124;
				}
				else if(mask == Masks.Shadow)
				{
					maskIndex = -4;
					maskColor = 131;
				}

				// Bild pixelweise durchgehen
				for(int i = 0; i < FIH.Width; i++)
				{
					for(int j = 0; j < FIH.Height; j++)
					{
						// Palettenindex abrufen
						int farbID = _frameInformationData[(int)frameID].CommandTable[j, i];

						// Je nach Masken Farben setzen
						if(farbID == maskIndex)
						{
							// Masken-Farbe übernehmen
							farbID = maskColor;
						}
						else
						{
							// Keine Maske, also weiß
							farbID = 255;
						}

						// Pixel übernehmen
						ret[i, j] = Pal[farbID];
					}
				}
			}
			else // Spielerfarbe
			{
				// Bild pixelweise durchgehen
				for(int i = 0; i < FIH.Width; i++)
				{
					for(int j = 0; j < FIH.Height; j++)
					{
						// Palettenindex abrufen
						int farbID = _frameInformationData[(int)frameID].CommandTable[j, i];

						// Liegt keine Spielerfarbe vor?
						if(farbID < 16 || farbID > 23)
						{
							// Pixel weiß einfärben
							farbID = 255;
						}

						// Pixel übernehmen
						ret[i, j] = Pal[farbID];
					}
				}
			}

			// Fertig
			return ret;
		}
Example #18
0
 public DefaultUIThemeProvider()
 {
     _colorTable = ColorTable.Default;
 }
Example #19
0
 private void FillPictureEditor(Bitmap btmp, ColorTable workingPalette)
 {
     if (comboBoxZoom.SelectedItem == null)
         comboBoxZoom.SelectedIndex = 0;
     btmp.ChangeColorTable(workingPalette);
     clrs.Clear();
     foreach (var color in btmp.Colors.Values)
     {
         clrs.Add(color);
     }
     clrs.Add(new ColorRecord("TRANS", "Transparent", new CIEYxy(1, 1, 1)));
     colorComboBox1.Items.Clear();
     colorComboBox1.Items.AddRange(clrs.ToArray());
     colorComboBox1.SelectedIndex = 1;
     colorComboBox1.Refresh();
     string zoom = comboBoxZoom.SelectedItem.ToString();
     pictureBoxBitmapEditor.Image = btmp.GetZoomedImage(Convert.ToInt32(zoom.Substring(0, zoom.Length - 1)) / 100, true);
     pictureBoxBitmapEditor.Width = pictureBoxBitmapEditor.Image.Width + 1;
     pictureBoxBitmapEditor.Height = pictureBoxBitmapEditor.Image.Height + 1;
 }
Example #20
0
File: GIF.cs Project: ewxrjk/Defect
 private void WriteColorTable(ColorTable table)
 {
     int entries = 1 << table.BitSize();
       int n;
       for (n = 0; n < table.Table.Length; ++n) {
     WriteByte(table.Table[n].R);
     WriteByte(table.Table[n].G);
     WriteByte(table.Table[n].B);
       }
       for (; n < entries; ++n) {
     WriteByte(0);
     WriteByte(0);
     WriteByte(0);
       }
 }
 /// <summary>
 /// Removes an employee object from the collection
 /// </summary>
 /// <param name="emp"></param>
 public void Remove(ColorTable emp)
 {
     this.List.Remove(emp);
 }
 /// <summary>
 /// Adds an employee object to the collection
 /// </summary>
 /// <param name="emp"></param>
 public void Add(ColorTable emp)
 {
     this.List.Add(emp);
 }
Example #23
0
        /// <summary>
        /// Get All Data from XML file and generate to datagridview
        /// </summary>
        /// <param name="path">full path filename</param>
        private void Get_Data_FromPreset(string path)
        {

            List<ColorTable> colorTable = new List<ColorTable>();



            int Red = 0;
            int Green = 0;
            int Blue = 0;
            int Alpha = 0;



            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(path);
            // получим корневой элемент
            XmlElement xRoot = xDoc.DocumentElement;
            // обход всех узлов в корневом элементе
            foreach (XmlNode xnode in xRoot)
            {
                ColorTable clrTable = new ColorTable();

                // получаем атрибут name
                if (xnode.Attributes.Count > 0)
                {
                    XmlNode attr = xnode.Attributes.GetNamedItem("index");
                    //if (attr != null)
                    //    Trace.WriteLine(attr.Value);
                }
                // обходим все дочерние узлы элемента user
                foreach (XmlNode childnode in xnode.ChildNodes)
                {




                    if (childnode.Name == "ColumnIndex")
                    {
                        //Trace.WriteLine("Column: "+ childnode.InnerText);
                        clrTable.Column = Convert.ToInt32(childnode.InnerText);
                    }

                    if (childnode.Name == "RowIndex")
                    {
                        //Trace.WriteLine("Row: "+ childnode.InnerText);
                        clrTable.Row = Convert.ToInt32(childnode.InnerText);
                    }

                    if (childnode.Name == "R")
                    {
                        //Trace.WriteLine("R= "+ childnode.InnerText);
                        Red = Convert.ToInt32(childnode.InnerText);
                    }

                    if (childnode.Name == "G")
                    {
                        //Trace.WriteLine("G= "+ childnode.InnerText);
                        Green = Convert.ToInt32(childnode.InnerText);
                    }

                    if (childnode.Name == "B")
                    {
                        // Trace.WriteLine("B= "+ childnode.InnerText);
                        Blue = Convert.ToInt32(childnode.InnerText);
                    }

                    if (childnode.Name == "A")
                    {
                        //Trace.WriteLine("A= "+ childnode.InnerText);
                        Alpha = Convert.ToInt32(childnode.InnerText);
                    }

                }

                clrTable.color = Color.FromArgb(Alpha, Red, Green, Blue);
                colorTable.Add(clrTable);
            }

            for (int i = 0; i < colorTable.Count; i++)
            {
                dataGridView1[colorTable[i].Column, colorTable[i].Row].Style.BackColor = colorTable[i].color;
            }
        }
Example #24
0
        /// <summary>
        /// Lädt die angegebene Bitmap-Datei.
        /// </summary>
        /// <param name="filename">Der Pfad zur zu ladenden Bitmap-Datei.</param>
        /// <param name="pal">Optional. Gibt die zu verwendende 256er-Farbtabelle an. Sonst wird die entweder die im Bitmap angegebene oder die 50500er-Farbtabelle verwendet.</param>
        public BitmapLoader(string filename, JASCPalette pal = null)
        {
            // Datei laden
            _buffer = new RAMBuffer(filename);

            // Header laden
            _header = new Header();
            _header.type = ReadUShort();
            _header.fileSize = ReadUInteger();
            _header.reserved = ReadUInteger();
            _header.offsetData = ReadUInteger();
            _header.imageHeaderSize = ReadUInteger();
            _header.width = ReadInteger();
            _header.height = ReadInteger();
            _header.layerCount = ReadUShort();
            _header.bitsPerPixel = ReadUShort();
            _header.compression = ReadUInteger();
            _header.size = ReadUInteger();
            _header.xDPI = ReadInteger();
            _header.yDPI = ReadInteger();
            _header.colorCount = ReadUInteger();
            _header.colorImportantCount = ReadUInteger();

            // Farbtabellenanzahl nachjustieren
            if(_header.colorCount == 0 && _header.bitsPerPixel == 8)
                _header.colorCount = 256;

            // Farbtabelle laden
            bool needAdjustColorTable = false;
            if(_header.colorCount > 0)
            {
                // Bildfarbtabelle laden
                _colorTable = new ColorTable(ref _buffer, _header.colorCount);

                // Falls eine Palette übergeben wurde, diese mit der Bildtabelle vergleichen
                if(pal == null || pal._farben.GetLength(0) != 256)
                    needAdjustColorTable = true;
                else
                    for(int i = 0; i < 256; ++i)
                    {
                        // Farben vergleichen
                        Color aktF = _colorTable[i];
                        if(pal._farben[i, 0] != aktF.R || pal._farben[i, 1] != aktF.G || pal._farben[i, 2] != aktF.B)
                        {
                            // Farbtabellen unterscheiden sich
                            needAdjustColorTable = true;
                            break;
                        }
                    }
            }
            else
            {
                // Bei 24-Bit-Bitmaps wird die Farbtabelle später geladen
                _colorTable = null;
            }

            // Nach Bitzahl unterscheiden
            if(_header.bitsPerPixel == 8)
            {
                // Bilddatenbreite ggf. auf ein Vielfaches von 4 Bytes erhöhen
                int width = _header.width; // Hilfsvariable zur Performanceerhöhung (immer gleichwertig mit _header.width)
                int width2 = width;
                while(width2 % 4 != 0)
                {
                    width2++;
                }

                // Binäre Original-Bilddaten einlesen
                _imageDataBin = _buffer.ReadByteArray(width2 * Math.Abs(_header.height));

                // Neues Bilddaten-Array anlegen (ohne Füllbytes)
                _imageData = new byte[width * Math.Abs(_header.height)];

                // Richtung bestimmen
                bool dirTopDown = (_header.height < 0);

                // Der bisher nächste Farbindex
                byte nearestIndex = 0;

                // Der Abstand zum bisher nächsten Farbindex
                double nearestDistance;

                // Der aktuelle Farbabstand
                double tempDistance = 0.0;

                // Bilddaten abrufen
                int height2 = Math.Abs(_header.height);
                for(int x = 0; x < width2; x++)
                {
                    for(int y = 0; y < height2; y++)
                    {
                        // Wenn es sich bei dem aktuellen Pixel um kein Füllbyte handelt, diesen übernehmen
                        if(x < width)
                        {
                            // Pixel abrufen
                            byte aktCol = _imageDataBin[y * width2 + x];

                            // TODO: 0-Indizes in 255 umwandeln??

                            // Falls nötig, Farben vergleichen
                            if(needAdjustColorTable)
                            {
                                // Alle Farbwerte abrufen
                                byte aktB = _colorTable[aktCol].B;
                                byte aktG = _colorTable[aktCol].G;
                                byte aktR = _colorTable[aktCol].R;

                                // Die zur Pixelfarbe nächste Palettenfarbe suchen
                                {
                                    // Werte zurücksetzen
                                    nearestIndex = 0;
                                    nearestDistance = 441.673; // Anfangswert: maximaler möglicher Abstand

                                    // Alle Einträge durchgehen
                                    for(int i = 0; i < 256; i++)
                                    {
                                        // Aktuelle Paletten-RGB-Werte abrufen
                                        byte pR = pal._farben[i, 0];
                                        byte pG = pal._farben[i, 1];
                                        byte pB = pal._farben[i, 2];

                                        // Gleiche Einträge sofort filtern
                                        if(aktR == pR && aktB == pB && aktG == pG)
                                        {
                                            // Paletten-Index überschreiben
                                            nearestIndex = (byte)i;

                                            // Fertig
                                            break;
                                        }

                                        // Abstand berechnen (Vektorlänge im dreidimensionalen RGB-Farbraum)
                                        tempDistance = Math.Sqrt(Math.Pow(aktR - pR, 2) + Math.Pow(aktG - pG, 2) + Math.Pow(aktB - pB, 2));

                                        // Vergleichen
                                        if(tempDistance < nearestDistance)
                                        {
                                            // Index merken
                                            nearestDistance = tempDistance;
                                            nearestIndex = (byte)i;
                                        }
                                    }

                                    // Paletten-Index überschreiben
                                    aktCol = nearestIndex;
                                }
                            } // Ende Adjust-ColorTable

                            // Pixel zum Hauptbildarray hinzufügen und dabei nach Top-Down / Bottom-Up unterscheiden
                            _imageData[(dirTopDown ? y : height2 - y - 1) * width + x] = aktCol;
                        }
                    }
                }
            }
            else if(_header.bitsPerPixel == 24)
            {
                // Es handelt sich um ein 24-Bit-Bitmap, somit muss eine Farbtabelle eingeführt werden
                {
                    // Farbpalettenreader abrufen
                    JASCPalette tempPal;
                    if(pal == null)
                        tempPal = new JASCPalette(new RAMBuffer(BitmapLibrary.Properties.Resources.pal50500));
                    else
                        tempPal = pal;

                    // Farbpaletteninhalt in eigene Farbtabelle schreiben
                    _colorTable = new ColorTable();
                    for(int i = 0; i < tempPal._farben.GetLength(0); i++)
                    {
                        // Eintrag in Tabelle einfügen
                        _colorTable[i] = Color.FromArgb(tempPal._farben[i, 0], tempPal._farben[i, 1], tempPal._farben[i, 2]);

                        // Sicherheitshalber bei i = 255 abbrechen (falls Palette zu groß sein sollte)
                        if(i == 255)
                            break;
                    }
                }

                // Bilddatenbreite ggf. auf ein Vielfaches von 4 Bytes erhöhen
                int width = _header.width; // Hilfsvariable zur Performanceerhöhung (immer gleichwertig mit _header.width)
                int fillBytes = 0;
                while(((width * 3) + fillBytes) % 4 != 0)
                {
                    fillBytes++;
                }

                // Binäre Original-Bilddaten einlesen
                _imageDataBin = _buffer.ReadByteArray((3 * width + fillBytes) * Math.Abs(_header.height));

                // Neues Bilddaten-Array anlegen (ohne Füllbytes)
                _imageData = new byte[width * Math.Abs(_header.height)];

                // Richtung bestimmen
                bool dirTopDown = (_header.height < 0);

                // Der bisher nächste Farbindex
                byte nearestIndex = 0;

                // Der Abstand zum bisher nächsten Farbindex
                double nearestDistance;

                // Der aktuelle Farbabstand
                double tempDistance = 0.0;

                // Bilddaten abrufen
                int height2 = Math.Abs(_header.height);
                for(int x = 0; x < width; x++)
                {
                    for(int y = 0; y < height2; y++)
                    {
                        // Pixel abrufen
                        byte aktB = _imageDataBin[y * (3 * width + fillBytes) + 3 * x];
                        byte aktG = _imageDataBin[y * (3 * width + fillBytes) + 3 * x + 1];
                        byte aktR = _imageDataBin[y * (3 * width + fillBytes) + 3 * x + 2];

                        // Die zur Pixelfarbe nächste Palettenfarbe suchen
                        {
                            // Werte zurücksetzen
                            nearestIndex = 0;
                            nearestDistance = 441.673; // Anfangswert: maximaler möglicher Abstand

                            // Alle Einträge durchgehen
                            for(int i = 0; i < 256; i++)
                            {
                                // Aktuelle Paletten-RGB-Werte abrufen
                                byte pR = _colorTable[i].R;
                                byte pG = _colorTable[i].G;
                                byte pB = _colorTable[i].B;

                                // Gleiche Einträge sofort filtern
                                if(aktR == pR && aktB == pB && aktG == pG)
                                {
                                    // Pixel zum Hauptbildarray hinzufügen und dabei nach Top-Down / Bottom-Up unterscheiden
                                    _imageData[(dirTopDown ? y : height2 - y - 1) * width + x] = (byte)i;

                                    // Fertig
                                    break;
                                }

                                // Abstand berechnen (Vektorlänge im dreidimensionalen RGB-Farbraum)
                                tempDistance = Math.Sqrt(Math.Pow(aktR - pR, 2) + Math.Pow(aktG - pG, 2) + Math.Pow(aktB - pB, 2));

                                // Vergleichen
                                if(tempDistance < nearestDistance)
                                {
                                    // Index merken
                                    nearestDistance = tempDistance;
                                    nearestIndex = (byte)i;
                                }
                            }

                            // Pixel zum Hauptbildarray hinzufügen und dabei nach Top-Down / Bottom-Up unterscheiden
                            _imageData[(dirTopDown ? y : height2 - y - 1) * width + x] = nearestIndex;
                        }
                    }

                    // Ggf. Füllbytes überspringen (bei Dateiende nicht)
                    if(_buffer.Position < _buffer.Length - fillBytes)
                        _buffer.Position = (_buffer.Position + fillBytes);
                }
            }
        }
Example #25
0
		/// <summary>
		/// Ersetzt einen vorhandenen Frame oder fügt einen neuen am Ende hinzu.
		/// </summary>
		/// <param name="frameID">Die ID des Frames (bei Ersetzung) oder -1 für einen neuen Frame.</param>
		/// <param name="frameBitmap">Die Bilddaten, die in Kommando-Daten umgewandelt werden sollen (mit 50500er-Palette versehen).</param>
		/// <param name="pal">Die zu verwendende Farbpalette.</param>
		/// <param name="ankerX">Die X-Koordinate des Mittelpunkts der Grafik.</param>
		/// <param name="ankerY">Die Y-Koordinate des Mittelpunkts der Grafik.</param>
		/// <param name="settings">Die Einstellungen als Wert der Settings-Enumeration.</param>
		public void addReplaceFrame(int frameID, BitmapLoader frameBitmap, ColorTable pal, int ankerX, int ankerY, Settings settings)
		{
			#region Grundlegenes und Initialisierungen

			// Größen ermitteln
			int height = frameBitmap.Height;
			int width = frameBitmap.Width;

			// Framedaten
			FrameInformationData aktFID;
			FrameInformationHeader aktFIH;

			// Neuer Frame?
			if(frameID < 0 || frameID >= _frameInformationData.Count)
			{
				// Neue Framedaten erstellen
				aktFID = new FrameInformationData();
				_frameInformationData.Add(aktFID);
				aktFIH = new FrameInformationHeader();
				_frameInformationHeaders.Add(aktFIH);

				// Neue Frame-ID ermitteln
				frameID = _frameInformationData.Count - 1;
			}
			else
			{
				// Frame laden
				aktFID = _frameInformationData[frameID];
				aktFIH = _frameInformationHeaders[frameID];
			}

			// Anker speichern
			aktFIH.AnchorX = ankerX;
			aktFIH.AnchorY = ankerY;

			// Speichern der Abmessungen
			aktFIH.Width = (uint)width;
			aktFIH.Height = (uint)height;

			// RowEdge initialisieren
			aktFID.BinaryRowEdge = new BinaryRowedge[height];
			for(int i = 0; i < height; i++)
			{
				aktFID.BinaryRowEdge[i] = new BinaryRowedge();
			}

			// Kommando-Offset-Array initalisieren
			aktFID.CommandTableOffsets = new uint[height];

			// Kommando-Array initialisieren
			aktFID.BinaryCommandTable = new List<BinaryCommand>();

			#endregion Grundlegenes und Initialisierungen

			// Bild in umgesetzte Kommandodaten umwandeln

			#region Umwandlung in umgesetzte Kommandodaten (Masken + Farbenindizes)

			int[,] xCommandTable; // [Y, X] => Hilfsvariable für effizienteren Zugriff, enthält alle Palettenverweise des Bilds bzw. die negativen Masken-Pixel
			aktFID.CommandTable = new int[height, width];
			{
				// Bildindizes (Daten) in die umgesetzte Kommandotabelle schreiben
				for(int i = 0; i < height; i++)
				{
					for(int j = 0; j < width; j++)
					{
						aktFID.CommandTable[i, j] = frameBitmap[j, i];
					}
				}

				// Aus Effizienzgründen die umgewandelte Kommandotabelle in ein nahezu Objekt-freies int-Array kopieren (Direktzugriff ohne Umwege über unnötige OOP)
				xCommandTable = (int[,])aktFID.CommandTable.Clone();

				// Berechnen der Masken

				#region Maskenberechnung

				{
					// Unsichtbar wird immer 255er-Weiß
					int _transMaskIndex = 255;

					// Transparenz
					if((settings & Settings.UseTransparency) == Settings.UseTransparency)
					{
						// Jedem transparenten 255er-Pixel den Index -1 verpassen
						for(int y = 0; y < height; y++)
						{
							for(int x = 0; x < width; x++)
							{
								if(xCommandTable[y, x] == _transMaskIndex)
									xCommandTable[y, x] = -1;
							}
						}
					}

					// Sämtliche Transparenz hat nun den Wert -1
					_transMaskIndex = -1;

					// Umriss 1 (Outline 1): Der Umriss des Objekts in der Grafik (wenn das Objekt hinter einem anderen steht, werden diese Umrisse in der Spielerfarbe dargestellt) Es müssen alle vier Richtungen durchgerechnet werden
					if((settings & Settings.UseOutline1) == Settings.UseOutline1)
					{
						// Waagerecht
						for(int y = 0; y < height; y++)
						{
							// Nach rechts
							for(int x = 0; x < width - 1; x++)
							{
								// Befindet sich beim nächsten Pixel keine Transparenz und auch kein Umriss 1? => Umriss
								if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y, x + 1] != _transMaskIndex && xCommandTable[y, x + 1] != -2)
								{
									xCommandTable[y, x] = -2;
								}
							}

							// Nach links
							for(int x = width - 1; x > 0; x--)
							{
								// Befindet sich beim nächsten Pixel keine Transparenz und auch kein Umriss 1? => Umriss
								if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y, x - 1] != _transMaskIndex && xCommandTable[y, x - 1] != -2)
								{
									xCommandTable[y, x] = -2;
								}
							}
						}

						// Senkrecht
						for(int x = 0; x < width; x++)
						{
							// Nach unten
							for(int y = 0; y < height - 1; y++)
							{
								// Befindet sich beim nächsten Pixel keine Transparenz und auch kein Umriss 1? => Umriss
								if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y + 1, x] != _transMaskIndex && xCommandTable[y + 1, x] != -2)
								{
									xCommandTable[y, x] = -2;
								}
							}

							// Nach oben
							for(int y = height - 1; y > 0; y--)
							{
								// Befindet sich beim nächsten Pixel keine Transparenz und auch kein Umriss 1? => Umriss
								if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y - 1, x] != _transMaskIndex && xCommandTable[y - 1, x] != -2)
								{
									xCommandTable[y, x] = -2;
								}
							}
						}
					}

					// Umriss 2 (Outline 2): Zweiter Umriss, umschließt Umriss 1
					if((settings & Settings.UseOutline2) == Settings.UseOutline2)
					{
						// Zuerst Outline 1 für das Outline 2-Array neu berechnen (falls dies noch nicht passiert ist)
						if((settings & Settings.UseOutline1) != Settings.UseOutline1)
						{
							// Waagerecht
							for(int y = 0; y < height; y++)
							{
								// Nach rechts
								for(int x = 0; x < width - 1; x++)
								{
									// Befindet sich beim nächsten Pixel keine Transparenz und auch kein Umriss 1? => Umriss
									if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y, x + 1] != _transMaskIndex && xCommandTable[y, x + 1] != -2)
									{
										xCommandTable[y, x] = -2;
									}
								}

								// Nach links
								for(int x = width - 1; x > 0; x--)
								{
									// Befindet sich beim nächsten Pixel keine Transparenz und auch kein Umriss 1? => Umriss
									if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y, x - 1] != _transMaskIndex && xCommandTable[y, x - 1] != -2)
									{
										xCommandTable[y, x] = -2;
									}
								}
							}

							// Senkrecht
							for(int x = 0; x < width; x++)
							{
								// Nach unten
								for(int y = 0; y < height - 1; y++)
								{
									// Befindet sich beim nächsten Pixel keine Transparenz und auch kein Umriss 1? => Umriss
									if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y + 1, x] != _transMaskIndex && xCommandTable[y + 1, x] != -2)
									{
										xCommandTable[y, x] = -2;
									}
								}

								// Nach oben
								for(int y = height - 1; y > 0; y--)
								{
									// Befindet sich beim nächsten Pixel keine Transparenz und auch kein Umriss 1? => Umriss
									if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y - 1, x] != _transMaskIndex && xCommandTable[y - 1, x] != -2)
									{
										xCommandTable[y, x] = -2;
									}
								}
							}
						}

						// Outline 2 auf Outline 1 basierend erstellen (Umriss 1 wird wie eine gewöhnliche Farbe behandelt)
						{
							// Waagerecht
							for(int y = 0; y < height; y++)
							{
								// Nach rechts
								for(int x = 0; x < width - 1; x++)
								{
									// Befindet sich beim nächsten Pixel keine Transparenz? => Umriss
									if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y, x + 1] != _transMaskIndex && (x + 1 != width - 1))
									{
										xCommandTable[y, x] = -3;
									}
								}

								// Nach links
								for(int x = width - 1; x > 0; x--)
								{
									// Befindet sich beim nächsten Pixel keine Transparenz? => Umriss
									if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y, x - 1] != _transMaskIndex && (x + 1 != width - 1))
									{
										xCommandTable[y, x] = -3;
									}
								}
							}

							// Senkrecht
							for(int x = 0; x < width; x++)
							{
								// Nach unten
								for(int y = 0; y < height - 1; y++)
								{
									// Befindet sich beim nächsten Pixel keine Transparenz? => Umriss
									if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y + 1, x] != _transMaskIndex)
									{
										xCommandTable[y, x] = -3;
									}
								}

								// Nach oben
								for(int y = height - 1; y > 0; y--)
								{
									// Befindet sich beim nächsten Pixel keine Transparenz? => Umriss
									if(xCommandTable[y, x] == _transMaskIndex && xCommandTable[y - 1, x] != _transMaskIndex)
									{
										xCommandTable[y, x] = -3;
									}
								}
							}
						}
					}

					// Schatten (Farbindex 131)
					if((settings & Settings.UseShadow) == Settings.UseShadow)
					{
						// Jeden Schattenpixel mit -4 markieren
						for(int y = 0; y < height; y++)
						{
							for(int x = 0; x < width; x++)
							{
								if(xCommandTable[y, x] == 131)
									xCommandTable[y, x] = -4;
							}
						}
					}
				} // Ende Maskenberechnung

				#endregion Maskenberechnung

				// Kommandotabelle zwischenspeichern
				aktFID.CommandTable = (int[,])xCommandTable.Clone();
			} // Ende Umwandlung in umgesetzte Kommandodaten

			#endregion Umwandlung in umgesetzte Kommandodaten (Masken + Farbenindizes)

			// Generieren der RowEdge-Daten (Außenränder, Bestimmung waagerecht)

			#region Generierung der RowEdge-Daten

			for(int y = 0; y < height; y++)
			{
				// Von links nach rechts
				int left = 0;
				for(int x = 0; x < width; x++)
				{
					if(xCommandTable[y, x] != -1)
						break;
					else
						left++;
				}

				// Von rechts nach links
				int right = 0;
				for(int x = width - 1; x >= 0; x--)
				{
					if(xCommandTable[y, x] != -1)
						break;
					else
						right++;
				}

				// Liegt eine leere Zeile vor?
				if(left == width)
				{
					// Leere Zeile
					right = 0;
				}

				// Werte speichern
				aktFID.BinaryRowEdge[y] = new BinaryRowedge(left, right);
			}

			#endregion Generierung der RowEdge-Daten

			// Ziel-Kommando-Tabelle erstellen
			CreateBinaryCommandTable(aktFID, width, height, settings);

			// Frame-Daten-Variablen speichern
			_frameInformationHeaders[frameID] = aktFIH;
			_frameInformationData[frameID] = aktFID;

			// Sicherheitshalber Frame-Anzahl im Header aktualisieren
			_headers.FrameCount = (uint)_frameInformationHeaders.Count;

			// Fertig: RowEdge-Daten und Kommandotabelle vollständig erstellt.
		}
Example #26
0
        public void InitColors(IUIThemeProvider uiThemeProvider)
        {
            _uiThemesProvider = uiThemeProvider;
            if (Settings.Default.UseVSColorTheme)
            {
                _colorTable = uiThemeProvider.Colors;
            }
            else
            {
                _colorTable = ColorTable.Default;
            }

            var colorHash = _colorTable.GetHash();
            if (_colorTableHash == colorHash)
            {
                return;
            }
            _colorTableHash = colorHash;

            BackColor = _colorTable.ControlBackground;
            ForeColor = _colorTable.ControlText;
            treeView1.BackColor = _colorTable.WindowBackground;
            treeView1.ForeColor = _colorTable.WindowText;
            lbTaskList.ForeColor = _colorTable.TabText;
            taskListDataGrid.BackColor = _colorTable.WindowBackground;
            taskListDataGrid.BackgroundColor = _colorTable.WindowBackground;
            taskListDataGrid.ForeColor = _colorTable.WindowText;
            taskListDataGrid.GridColor = _colorTable.GridLines;
            taskListDataGrid.RowsDefaultCellStyle.BackColor = _colorTable.WindowBackground;
            taskListDataGrid.RowsDefaultCellStyle.ForeColor = _colorTable.WindowText;

            toolStrip2.BackColor = _colorTable.MenuBackground;

            treeView1.Indent = Settings.Default.UseVSColorTheme ? 10 : 16;
            treeView1.DrawMode = Settings.Default.UseVSColorTheme
                ? TreeViewDrawMode.OwnerDrawAll
                : TreeViewDrawMode.OwnerDrawText;
            treeView1.ShowLines = !Settings.Default.UseVSColorTheme;
        }
Example #27
0
		/// <summary>
		/// Gibt den angegebenen Frame als Bitmap-Bild zurück.
		/// </summary>
		/// <param name="frameID">Die ID des Frames.</param>
		/// <param name="Pal">Die zu verwendende Farbpalette als Palette-Objekt.</param>
		/// <param name="mask">Optional. Gibt die abzurufende Maske an; Standardwert ist die reine Frame-Grafik.</param>
		/// <param name="maskReplacementColor">Optional. Gibt die Farbe an, die anstatt der Masken verwendet werden soll, die nicht angezeigt werden.</param>
		/// <param name="shadowColor">Optional. Gibt die Farbe an, die für Schatten verwendet werden soll.</param>
		/// <remarks></remarks>
		public Bitmap getFrameAsBitmap(uint frameID, ColorTable Pal, Masks mask = Masks.Graphic, Color? maskReplacementColor = null, Color? shadowColor = null)
		{
			// Framedaten abrufen
			FrameInformationHeader frameHeader = _frameInformationHeaders[(int)frameID];
			FrameInformationData frameData = _frameInformationData[(int)frameID];

			// Rückgabebild erstellen
			Bitmap ret = new Bitmap((int)frameHeader.Width, (int)frameHeader.Height);

			// Welche Maske ist gewollt?
			if(mask == Masks.Graphic) // Es handelt sich um die reine Frame-Grafik
			{
				// Unsafe ist hier enorm schneller als SetPixel()
				BitmapData retData = ret.LockBits(new Rectangle(0, 0, ret.Width, ret.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
				int retStride = retData.Stride;
				unsafe
				{
					// Pixelpointer abrufen
					byte* ptr = (byte*)retData.Scan0;

					// Bild pixelweise durchgehen
					for(int i = 0; i < frameHeader.Width; i++)
					{
						for(int j = 0; j < frameHeader.Height; j++)
						{
							// Palettenindex abrufen
							int farbID = frameData.CommandTable[j, i];

							// Sonderindizes in die jeweiligen Farben umsetzen
							Color col;
							switch(farbID)
							{
								case -1:
								case -2:
								case -3:
									col = maskReplacementColor ?? Color.White;
									break;

								case -4:
									col = shadowColor ?? Pal[_schatten];
									break;

								default:
									col = Pal[farbID];
									break;
							}

							// Pixel in das Bild schreiben
							ptr[i * 4 + j * retStride] = col.B;
							ptr[i * 4 + j * retStride + 1] = col.G;
							ptr[i * 4 + j * retStride + 2] = col.R;
							ptr[i * 4 + j * retStride + 3] = col.A;
						}
					}
				}
				ret.UnlockBits(retData);
			}
			else if(mask != Masks.PlayerColor) // Es handelt sich um eine Maske (außer der Spielerfarbe)
			{
				// Den Index und die Zielfarbe angeben
				int maskIndex = 0;
				int maskColor = 0;
				if(mask == Masks.Transparency)
				{
					maskIndex = -1;
					maskColor = 0;
				}
				else if(mask == Masks.Outline1)
				{
					maskIndex = -2;
					maskColor = 8;
				}
				else if(mask == Masks.Outline2)
				{
					maskIndex = -3;
					maskColor = 124;
				}
				else if(mask == Masks.Shadow)
				{
					maskIndex = -4;
					maskColor = 131;
				}

				// Bild pixelweise durchgehen
				for(int i = 0; i < frameHeader.Width; i++)
				{
					for(int j = 0; j < frameHeader.Height; j++)
					{
						// Palettenindex abrufen
						int farbID = _frameInformationData[(int)frameID].CommandTable[j, i];

						// Je nach Masken Farben setzen
						if(farbID == maskIndex)
						{
							// Masken-Farbe übernehmen
							farbID = maskColor;
						}
						else
						{
							// Keine Maske, also weiß
							farbID = 255;
						}

						// Pixel übernehmen
						ret.SetPixel(i, j, Pal[farbID]);
					}
				}
			}
			else // Spielerfarbe
			{
				// Bild pixelweise durchgehen
				for(int i = 0; i < frameHeader.Width; i++)
				{
					for(int j = 0; j < frameHeader.Height; j++)
					{
						// Palettenindex abrufen
						int farbID = _frameInformationData[(int)frameID].CommandTable[j, i];

						// Liegt keine Spielerfarbe vor?
						if(farbID < 16 || farbID > 23)
						{
							// Pixel weiß einfärben
							farbID = 255;
						}

						// Pixel übernehmen
						ret.SetPixel(i, j, Pal[farbID]);
					}
				}
			}

			// Fertig
			return ret;
		}
Example #28
0
    void Start()
    {
        if (cubewidth <= 0)
        {
            cubewidth = 1;
        }
        // variabelen
        moves = new Queue <Rotation>();
        T     = (cubewidth * tiledistance) / 2;
        t     = T - tiledistance / 2;
        Quaternion front  = Quaternion.Euler(new Vector3(0f, 180f, 0f));
        Quaternion back   = Quaternion.Euler(new Vector3(0f, 0f, 0f));
        Quaternion left   = Quaternion.Euler(new Vector3(0f, 270f, 0f));
        Quaternion right  = Quaternion.Euler(new Vector3(0f, 90f, 0f));
        Quaternion top    = Quaternion.Euler(new Vector3(90f, 90f, 0f));
        Quaternion bottom = Quaternion.Euler(new Vector3(270f, 90f, 0f));

        Quaternion[] tilerotations = { front, back, left, right, top, bottom };
        this.tilerotations = tilerotations;
        Vector3 startposfront  = new Vector3(t, t, T);
        Vector3 startposback   = new Vector3(t, t, -T);
        Vector3 startposleft   = new Vector3(T, t, t);
        Vector3 startposright  = new Vector3(-T, t, t);
        Vector3 startpostop    = new Vector3(t, T, t);
        Vector3 startposbottom = new Vector3(t, -T, t);

        Vector3[] startingpoints = { startposfront, startposback, startposleft, startposright, startpostop, startposbottom };
        this.startingpoints = startingpoints;

        Vector3 firstaxisrow  = new Vector3(-tiledistance, 0f, 0f);
        Vector3 secondaxisrow = new Vector3(0f, -tiledistance, 0f);
        Vector3 thirdaxisrow  = new Vector3(0f, 0f, -tiledistance);

        Vector3[] rowsteps = { firstaxisrow, secondaxisrow, thirdaxisrow };
        this.rowsteps = rowsteps;
        Vector3 firstaxiscollumn  = new Vector3(0f, -tiledistance, 0f);
        Vector3 secondaxiscollumn = new Vector3(0f, 0f, -tiledistance);
        Vector3 thirdaxiscollumn  = new Vector3(-tiledistance, 0f, 0f);

        Vector3[] collumnsteps = { firstaxiscollumn, secondaxiscollumn, thirdaxiscollumn };
        this.collumnsteps = collumnsteps;
        // unity objecten
        cubeLogic  = GetComponent <CubeLogic>();
        colorTable = GetComponent <ColorTable>();
        cubeLogic.InitializeCube(this.cubewidth);
        rotator = new GameObject("rotator");
        rotator.transform.parent = transform;
        allTiles         = new Tile[cubeLogic.triplemove, cubewidth];
        cubeHolder       = new GameObject("CubeHolder");
        transform.parent = cubeHolder.transform;
        Camera.main.GetComponent <CameraScript>().SetParent(transform);
        if (afterImage)
        {
            afterImageObject = Instantiate(afterImageObject);
            afterImageObject.transform.parent = transform;
            afterImage_ms = afterImageObject.GetComponent <MeshRenderer>();
        }
        if (rotationCover)
        {
            coverTiles    = new Transform[4];
            coverTiles_ms = new MeshRenderer[4];
            for (int i = 0; i < 4; i++)
            {
                coverTiles[i]            = Instantiate(coverTile.transform, transform);
                coverTiles_ms[i]         = coverTiles[i].GetComponent <MeshRenderer>();
                coverTiles_ms[i].enabled = false;
            }
            for (int i = 0; i < 2; i++)
            {
                coverTiles[i].parent = rotator.transform;
            }
        }
        if (blocks)
        {
            blockarray = new GameObject[cubewidth, cubewidth, cubewidth];
            SpawnCubeBlocks();
        }
        // kubus
        SpawnTiles();
        Graphical_UpdateEverything();
    }
Example #29
0
    private static Bitmap CreateCompatibleBitmap(Dataset ds, int imageWidth, int imageHeight)
    {
        if (ds.RasterCount == 0)
            return null;

        bandMap = new int[4] { 1, 1, 1, 1 };
        channelCount = 1;
        hasAlpha = false;
        isPremultiplied = false;
        isIndexed = false;
        channelSize = 8;
        // Evaluate the bands and find out a proper image transfer format
        for (int i = 0; i < ds.RasterCount; i++)
        {
            Band band = ds.GetRasterBand(i + 1);
            if (Gdal.GetDataTypeSize(band.DataType) > 8)
                channelSize = 16;

            // retrieving the premultiplied alpha flag
            string[] metadata = band.GetMetadata("");
            for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
            {
                if (metadata[iMeta].StartsWith("PREMULTIPLIED_ALPHA"))
                    isPremultiplied = true;
            }

            switch (band.GetRasterColorInterpretation())
            {
                case ColorInterp.GCI_AlphaBand:
                    channelCount = 4;
                    hasAlpha = true;
                    bandMap[3] = i + 1;
                    break;
                case ColorInterp.GCI_BlueBand:
                    if (channelCount < 3)
                        channelCount = 3;
                    bandMap[0] = i + 1;
                    break;
                case ColorInterp.GCI_RedBand:
                    if (channelCount < 3)
                        channelCount = 3;
                    bandMap[2] = i + 1;
                    break;
                case ColorInterp.GCI_GreenBand:
                    if (channelCount < 3)
                        channelCount = 3;
                    bandMap[1] = i + 1;
                    break;
                case ColorInterp.GCI_PaletteIndex:
                    ct = band.GetRasterColorTable();
                    isIndexed = true;
                    bandMap[0] = i + 1;
                    break;
                case ColorInterp.GCI_GrayIndex:
                    isIndexed = true;
                    bandMap[0] = i + 1;
                    break;
                default:
                    // we create the bandmap using the dataset ordering by default
                    if (i < 4 && bandMap[i] == 0)
                    {
                        if (channelCount < i)
                            channelCount = i;
                        bandMap[i] = i + 1;
                    }
                    break;
            }
        }

        // find out the pixel format based on the gathered information
        if (isIndexed)
        {
            pixelFormat = PixelFormat.Format8bppIndexed;
            dataType = DataType.GDT_Byte;
            pixelSpace = 1;
        }
        else
        {
            if (channelCount == 1)
            {
                if (channelSize > 8)
                {
                    pixelFormat = PixelFormat.Format16bppGrayScale;
                    dataType = DataType.GDT_Int16;
                    pixelSpace = 2;
                }
                else
                {
                    pixelFormat = PixelFormat.Format24bppRgb;
                    channelCount = 3;
                    dataType = DataType.GDT_Byte;
                    pixelSpace = 3;
                }
            }
            else
            {
                if (hasAlpha)
                {
                    if (channelSize > 8)
                    {
                        if (isPremultiplied)
                            pixelFormat = PixelFormat.Format64bppArgb;
                        else
                            pixelFormat = PixelFormat.Format64bppPArgb;
                        dataType = DataType.GDT_UInt16;
                        pixelSpace = 8;
                    }
                    else
                    {
                        if (isPremultiplied)
                            pixelFormat = PixelFormat.Format32bppPArgb;
                        else
                            pixelFormat = PixelFormat.Format32bppArgb;
                        dataType = DataType.GDT_Byte;
                        pixelSpace = 4;
                    }
                    channelCount = 4;
                }
                else
                {
                    if (channelSize > 8)
                    {
                        pixelFormat = PixelFormat.Format48bppRgb;
                        dataType = DataType.GDT_UInt16;
                        pixelSpace = 6;
                    }
                    else
                    {
                        pixelFormat = PixelFormat.Format24bppRgb;
                        dataType = DataType.GDT_Byte;
                        pixelSpace = 3;
                    }
                    channelCount = 3;
                }
            }
        }

        // Create a Bitmap to store the GDAL image in
        return new Bitmap(imageWidth, imageHeight, pixelFormat);
    }
Example #30
0
 public ConsoleProperties()
 {
     nt_console_props = NT_CONSOLE_PROPS.AnEmptyOne();
     colorTable = new ColorTable(this);
 }
Example #31
0
        public static Bitmap LoadImage(string file)
        {
            lock (locker)
            {
                using (var ds = Gdal.Open(file, GdalconstJNI.GA_ReadOnly_get()))
                {
                    // 8bit geotiff - single band
                    if (ds.RasterCount == 1)
                    {
                        Band band = ds.GetRasterBand(1);
                        if (band == null)
                        {
                            return(null);
                        }

                        ColorTable ct = band.GetRasterColorTable();

                        PixelFormat format = PixelFormat.Format8bppIndexed;

                        // Create a Bitmap to store the GDAL image in
                        Bitmap bitmap = new Bitmap(ds.RasterXSize, ds.RasterYSize, format);

                        // Obtaining the bitmap buffer
                        BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, ds.RasterXSize, ds.RasterYSize),
                                                                ImageLockMode.ReadWrite, format);
                        try
                        {
                            if (ct != null)
                            {
                                int          iCol = ct.GetCount();
                                ColorPalette pal  = bitmap.Palette;
                                for (int i = 0; i < iCol; i++)
                                {
                                    ColorEntry ce = ct.GetColorEntry(i);
                                    pal.Entries[i] = Color.FromArgb(ce.c4, ce.c1, ce.c2, ce.c3);
                                }

                                bitmap.Palette = pal;
                            }
                            else
                            {
                            }

                            int    stride = bitmapData.Stride;
                            IntPtr buf    = bitmapData.Scan0;

                            var buffer = new byte[ds.RasterXSize * ds.RasterYSize];

                            band.ReadRaster(0, 0, ds.RasterXSize, ds.RasterYSize, ds.RasterXSize, ds.RasterYSize,
                                            (int)DataType.GDT_Byte, buffer);

                            Marshal.Copy(buffer, 0, buf, buffer.Length);
                        }
                        finally
                        {
                            bitmap.UnlockBits(bitmapData);
                        }


                        return(bitmap);
                    }

                    {
                        Bitmap bitmap = new Bitmap(ds.RasterXSize, ds.RasterYSize, PixelFormat.Format32bppArgb);
                        if (ds.RasterCount == 3)
                        {
                            // when we load a 24bit bitmap, we need to set the alpha channel else we get nothing
                            using (var tmp = Graphics.FromImage(bitmap))
                            {
                                tmp.Clear(Color.White);
                            }
                        }

                        for (int a = 1; a <= ds.RasterCount; a++)
                        {
                            // Get the GDAL Band objects from the Dataset
                            Band band = ds.GetRasterBand(a);
                            if (band == null)
                            {
                                return(null);
                            }

                            var cint = (ColorInterp)band.GetColorInterpretation();


                            // Obtaining the bitmap buffer
                            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, ds.RasterXSize, ds.RasterYSize),
                                                                    ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                            try
                            {
                                int    stride = bitmapData.Stride;
                                IntPtr buf    = bitmapData.Scan0;
                                var    buffer = new byte[ds.RasterXSize * ds.RasterYSize];

                                band.ReadRaster(0, 0, ds.RasterXSize, ds.RasterYSize, ds.RasterXSize,
                                                ds.RasterYSize, (int)DataType.GDT_Byte, buffer);

                                int c = 0;
                                if (cint == ColorInterp.GCI_AlphaBand)
                                {
                                    foreach (var b in buffer)
                                    {
                                        Marshal.WriteByte(buf, 3 + c * 4, (byte)b);
                                        c++;
                                    }
                                }
                                else if (cint == ColorInterp.GCI_RedBand)
                                {
                                    foreach (var b in buffer)
                                    {
                                        Marshal.WriteByte(buf, 2 + c * 4, (byte)b);
                                        c++;
                                    }
                                }
                                else if (cint == ColorInterp.GCI_GreenBand)
                                {
                                    foreach (var b in buffer)
                                    {
                                        Marshal.WriteByte(buf, 1 + c * 4, (byte)b);
                                        c++;
                                    }
                                }
                                else if (cint == ColorInterp.GCI_BlueBand)
                                {
                                    foreach (var b in buffer)
                                    {
                                        Marshal.WriteByte(buf, 0 + c * 4, (byte)b);
                                        c++;
                                    }
                                }
                                else
                                {
                                }
                            }
                            finally
                            {
                                bitmap.UnlockBits(bitmapData);
                            }
                        }

                        //bitmap.Save("gdal.png", ImageFormat.Png);
                        return(bitmap);
                    }
                }
            }

            return(null);
        }
Example #32
0
    public static void Main(string[] args)
    {
        if (args.Length != 1)
        {
            usage();
        }

        Console.WriteLine("");

        try
        {
            /* -------------------------------------------------------------------- */
            /*      Register driver(s).                                             */
            /* -------------------------------------------------------------------- */
            Gdal.AllRegister();

            /* -------------------------------------------------------------------- */
            /*      Open dataset.                                                   */
            /* -------------------------------------------------------------------- */
            Dataset ds = Gdal.Open(args[0], Access.GA_ReadOnly);

            if (ds == null)
            {
                Console.WriteLine("Can't open " + args[0]);
                System.Environment.Exit(-1);
            }

            Console.WriteLine("Raster dataset parameters:");
            Console.WriteLine("  Projection: " + ds.GetProjectionRef());
            Console.WriteLine("  RasterCount: " + ds.RasterCount);
            Console.WriteLine("  RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")");

            /* -------------------------------------------------------------------- */
            /*      Get driver                                                      */
            /* -------------------------------------------------------------------- */
            Driver drv = ds.GetDriver();

            if (drv == null)
            {
                Console.WriteLine("Can't get driver.");
                System.Environment.Exit(-1);
            }

            Console.WriteLine("Using driver " + drv.LongName);

            /* -------------------------------------------------------------------- */
            /*      Get metadata                                                    */
            /* -------------------------------------------------------------------- */
            string[] metadata = ds.GetMetadata("");
            if (metadata.Length > 0)
            {
                Console.WriteLine("  Metadata:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    Console.WriteLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report "IMAGE_STRUCTURE" metadata.                              */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("IMAGE_STRUCTURE");
            if (metadata.Length > 0)
            {
                Console.WriteLine("  Image Structure Metadata:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    Console.WriteLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report subdatasets.                                             */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("SUBDATASETS");
            if (metadata.Length > 0)
            {
                Console.WriteLine("  Subdatasets:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    Console.WriteLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report geolocation.                                             */
            /* -------------------------------------------------------------------- */
            metadata = ds.GetMetadata("GEOLOCATION");
            if (metadata.Length > 0)
            {
                Console.WriteLine("  Geolocation:");
                for (int iMeta = 0; iMeta < metadata.Length; iMeta++)
                {
                    Console.WriteLine("    " + iMeta + ":  " + metadata[iMeta]);
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Report corners.                                                 */
            /* -------------------------------------------------------------------- */
            Console.WriteLine("Corner Coordinates:");
            Console.WriteLine("  Upper Left (" + GDALInfoGetPosition(ds, 0.0, 0.0) + ")");
            Console.WriteLine("  Lower Left (" + GDALInfoGetPosition(ds, 0.0, ds.RasterYSize) + ")");
            Console.WriteLine("  Upper Right (" + GDALInfoGetPosition(ds, ds.RasterXSize, 0.0) + ")");
            Console.WriteLine("  Lower Right (" + GDALInfoGetPosition(ds, ds.RasterXSize, ds.RasterYSize) + ")");
            Console.WriteLine("  Center (" + GDALInfoGetPosition(ds, ds.RasterXSize / 2, ds.RasterYSize / 2) + ")");
            Console.WriteLine("");

            /* -------------------------------------------------------------------- */
            /*      Report projection.                                              */
            /* -------------------------------------------------------------------- */
            string projection = ds.GetProjectionRef();
            if (projection != null)
            {
                SpatialReference srs = new SpatialReference(null);
                if (srs.ImportFromWkt(ref projection) == 0)
                {
                    string wkt;
                    srs.ExportToPrettyWkt(out wkt, 0);
                    Console.WriteLine("Coordinate System is:");
                    Console.WriteLine(wkt);
                }
                else
                {
                    Console.WriteLine("Coordinate System is:");
                    Console.WriteLine(projection);
                }
            }

            /* -------------------------------------------------------------------- */
            /*      Report GCPs.                                                    */
            /* -------------------------------------------------------------------- */
            if (ds.GetGCPCount( ) > 0)
            {
                Console.WriteLine("GCP Projection: ", ds.GetGCPProjection());
                GCP[] GCPs = ds.GetGCPs();
                for (int i = 0; i < ds.GetGCPCount(); i++)
                {
                    Console.WriteLine("GCP[" + i + "]: Id=" + GCPs[i].Id + ", Info=" + GCPs[i].Info);
                    Console.WriteLine("          (" + GCPs[i].GCPPixel + "," + GCPs[i].GCPLine + ") -> ("
                                      + GCPs[i].GCPX + "," + GCPs[i].GCPY + "," + GCPs[i].GCPZ + ")");
                    Console.WriteLine("");
                }
                Console.WriteLine("");

                double[] transform = new double[6];
                Gdal.GCPsToGeoTransform(GCPs, transform, 0);
                Console.WriteLine("GCP Equivalent geotransformation parameters: ", ds.GetGCPProjection());
                for (int i = 0; i < 6; i++)
                {
                    Console.WriteLine("t[" + i + "] = " + transform[i].ToString());
                }
                Console.WriteLine("");
            }

            /* -------------------------------------------------------------------- */
            /*      Get raster band                                                 */
            /* -------------------------------------------------------------------- */
            for (int iBand = 1; iBand <= ds.RasterCount; iBand++)
            {
                Band band = ds.GetRasterBand(iBand);
                Console.WriteLine("Band " + iBand + " :");
                Console.WriteLine("   DataType: " + Gdal.GetDataTypeName(band.DataType));
                Console.WriteLine("   ColorInterpretation: " + Gdal.GetColorInterpretationName(band.GetRasterColorInterpretation()));
                ColorTable ct = band.GetRasterColorTable();
                if (ct != null)
                {
                    Console.WriteLine("   Band has a color table with " + ct.GetCount() + " entries.");
                }

                Console.WriteLine("   Description: " + band.GetDescription());
                Console.WriteLine("   Size (" + band.XSize + "," + band.YSize + ")");
                int BlockXSize, BlockYSize;
                band.GetBlockSize(out BlockXSize, out BlockYSize);
                Console.WriteLine("   BlockSize (" + BlockXSize + "," + BlockYSize + ")");
                double val;
                int    hasval;
                band.GetMinimum(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   Minimum: " + val.ToString());
                }
                band.GetMaximum(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   Maximum: " + val.ToString());
                }
                band.GetNoDataValue(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   NoDataValue: " + val.ToString());
                }
                band.GetOffset(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   Offset: " + val.ToString());
                }
                band.GetScale(out val, out hasval);
                if (hasval != 0)
                {
                    Console.WriteLine("   Scale: " + val.ToString());
                }

                for (int iOver = 0; iOver < band.GetOverviewCount(); iOver++)
                {
                    Band over = band.GetOverview(iOver);
                    Console.WriteLine("      OverView " + iOver + " :");
                    Console.WriteLine("         DataType: " + over.DataType);
                    Console.WriteLine("         Size (" + over.XSize + "," + over.YSize + ")");
                    Console.WriteLine("         PaletteInterp: " + over.GetRasterColorInterpretation().ToString());
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine("Application error: " + e.Message);
        }
    }
Example #33
0
        /// <summary>
        /// This should update the palette cached and in the file.
        /// </summary>
        /// <param name="value"></param>
        public override void SetColorPalette(IEnumerable<Color> value)
        {
            ColorPalette = value;
            _dataset = Gdal.Open(Filename, Access.GA_Update);

            ColorTable ct = new ColorTable(PaletteInterp.GPI_RGB);
            int index = 0;
            foreach (Color c in value)
            {
                ColorEntry ce = new ColorEntry();
                ce.c4 = c.A;
                ce.c3 = c.B;
                ce.c2 = c.G;
                ce.c1 = c.R;
                ct.SetColorEntry(index, ce);
                index++;
            }
            using (Band first = _dataset.GetRasterBand(1))
            {
                first.SetRasterColorTable(ct);
            }
        }
 /// <summary> 
 /// Required method for Designer support - do not modify 
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.components = new System.ComponentModel.Container();
     this.panel1 = new System.Windows.Forms.Panel();
     this.m_tooltip = new System.Windows.Forms.ToolTip(this.components);
     this.m_colorSample = new AxiomCoders.PdfTemplateEditor.Controls.LabelRotate();
     this.m_infoLabel = new AxiomCoders.PdfTemplateEditor.Controls.LabelRotate();
     this.m_colorTable = new AxiomCoders.PdfTemplateEditor.Controls.ColorTable();
     this.m_eyedropColorPicker = new AxiomCoders.PdfTemplateEditor.Controls.EyedropColorPicker();
     this.m_colorWheel = new AxiomCoders.PdfTemplateEditor.Controls.ColorWheelCtrl();
     this.m_opacitySlider = new AxiomCoders.PdfTemplateEditor.Controls.ColorSlider();
     this.panel1.SuspendLayout();
     this.SuspendLayout();
     //
     // panel1
     //
     this.panel1.BackColor = System.Drawing.Color.Transparent;
     this.panel1.Controls.Add(this.m_colorWheel);
     this.panel1.Controls.Add(this.m_opacitySlider);
     this.panel1.Location = new System.Drawing.Point(257, 4);
     this.panel1.Name = "panel1";
     this.panel1.Size = new System.Drawing.Size(254, 242);
     this.panel1.TabIndex = 9;
     //
     // m_colorSample
     //
     this.m_colorSample.Location = new System.Drawing.Point(1, 150);
     this.m_colorSample.Name = "m_colorSample";
     this.m_colorSample.RotatePointAlignment = System.Drawing.ContentAlignment.MiddleCenter;
     this.m_colorSample.Size = new System.Drawing.Size(186, 60);
     this.m_colorSample.TabIndex = 1;
     this.m_colorSample.TabStop = false;
     this.m_colorSample.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     this.m_colorSample.TextAngle = 0F;
     //
     // m_infoLabel
     //
     this.m_infoLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.m_infoLabel.Location = new System.Drawing.Point(1, 217);
     this.m_infoLabel.Name = "m_infoLabel";
     this.m_infoLabel.RotatePointAlignment = System.Drawing.ContentAlignment.MiddleCenter;
     this.m_infoLabel.Size = new System.Drawing.Size(252, 28);
     this.m_infoLabel.TabIndex = 3;
     this.m_infoLabel.TabStop = false;
     this.m_infoLabel.Text = "This is some sample text";
     this.m_infoLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
     this.m_infoLabel.TextAngle = 0F;
     //
     // m_colorTable
     //
     this.m_colorTable.Cols = 16;
     this.m_colorTable.FieldSize = new System.Drawing.Size(12, 12);
     this.m_colorTable.Location = new System.Drawing.Point(1, 7);
     this.m_colorTable.Name = "m_colorTable";
     this.m_colorTable.Padding = new System.Windows.Forms.Padding(8, 8, 0, 0);
     this.m_colorTable.RotatePointAlignment = System.Drawing.ContentAlignment.MiddleCenter;
     this.m_colorTable.SelectedItem = System.Drawing.Color.Black;
     this.m_colorTable.Size = new System.Drawing.Size(252, 138);
     this.m_colorTable.TabIndex = 0;
     this.m_colorTable.Text = "m_colorTable";
     this.m_colorTable.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     this.m_colorTable.TextAngle = 0F;
     //
     // m_eyedropColorPicker
     //
     this.m_eyedropColorPicker.BackColor = System.Drawing.SystemColors.Control;
     this.m_eyedropColorPicker.Location = new System.Drawing.Point(193, 150);
     this.m_eyedropColorPicker.Name = "m_eyedropColorPicker";
     this.m_eyedropColorPicker.SelectedColor = System.Drawing.Color.Empty;
     this.m_eyedropColorPicker.Size = new System.Drawing.Size(60, 60);
     this.m_eyedropColorPicker.TabIndex = 2;
     this.m_eyedropColorPicker.TabStop = false;
     this.m_tooltip.SetToolTip(this.m_eyedropColorPicker, "Color Selector. Click and Drag to pick a color from the screen");
     this.m_eyedropColorPicker.Zoom = 4;
     //
     // m_colorWheel
     //
     this.m_colorWheel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                 | System.Windows.Forms.AnchorStyles.Left)
                 | System.Windows.Forms.AnchorStyles.Right)));
     this.m_colorWheel.BackColor = System.Drawing.Color.Transparent;
     this.m_colorWheel.Location = new System.Drawing.Point(-1, 0);
     this.m_colorWheel.Name = "m_colorWheel";
     this.m_colorWheel.SelectedColor = System.Drawing.Color.FromArgb(((int)(((byte)(252)))), ((int)(((byte)(235)))), ((int)(((byte)(205)))));
     this.m_colorWheel.Size = new System.Drawing.Size(254, 209);
     this.m_colorWheel.TabIndex = 0;
     //
     // m_opacitySlider
     //
     this.m_opacitySlider.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                 | System.Windows.Forms.AnchorStyles.Right)));
     this.m_opacitySlider.BackColor = System.Drawing.Color.Transparent;
     this.m_opacitySlider.BarPadding = new System.Windows.Forms.Padding(60, 12, 80, 25);
     this.m_opacitySlider.Color1 = System.Drawing.Color.White;
     this.m_opacitySlider.Color2 = System.Drawing.Color.Black;
     this.m_opacitySlider.Color3 = System.Drawing.Color.Black;
     this.m_opacitySlider.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     this.m_opacitySlider.ForeColor = System.Drawing.Color.Black;
     this.m_opacitySlider.Location = new System.Drawing.Point(2, 213);
     this.m_opacitySlider.Name = "m_opacitySlider";
     this.m_opacitySlider.NumberOfColors = AxiomCoders.PdfTemplateEditor.Controls.ColorSlider.eNumberOfColors.Use2Colors;
     this.m_opacitySlider.Orientation = System.Windows.Forms.Orientation.Horizontal;
     this.m_opacitySlider.Padding = new System.Windows.Forms.Padding(5, 0, 0, 0);
     this.m_opacitySlider.Percent = 1F;
     this.m_opacitySlider.RotatePointAlignment = System.Drawing.ContentAlignment.MiddleCenter;
     this.m_opacitySlider.Size = new System.Drawing.Size(248, 28);
     this.m_opacitySlider.TabIndex = 1;
     this.m_opacitySlider.Text = "Opacity";
     this.m_opacitySlider.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     this.m_opacitySlider.TextAngle = 0F;
     this.m_opacitySlider.ValueOrientation = AxiomCoders.PdfTemplateEditor.Controls.ColorSlider.eValueOrientation.MinToMax;
     //
     // ColorPickerCtrl
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     this.BackColor = System.Drawing.Color.Transparent;
     this.Controls.Add(this.m_colorSample);
     this.Controls.Add(this.m_infoLabel);
     this.Controls.Add(this.m_colorTable);
     this.Controls.Add(this.m_eyedropColorPicker);
     this.Controls.Add(this.panel1);
     this.Name = "ColorPickerCtrl";
     this.Padding = new System.Windows.Forms.Padding(3, 3, 0, 0);
     this.Size = new System.Drawing.Size(507, 250);
     this.panel1.ResumeLayout(false);
     this.ResumeLayout(false);
 }
Example #35
0
 ///<summary>
 ///  Makes a copy of another ConsoleProperty
 ///</summary>
 ///<remarks>
 ///  Note that the 'owner' field is not copied here.
 ///</remarks>
 public ConsoleProperties(ConsoleProperties another)
 {
     nt_console_props = another.nt_console_props;
     colorTable = new ColorTable(this);
 }
Example #36
0
        public void makeColorBalance()
        {
            ColorTable v_SourceTable = formPallete.destColorTableBak;
            ColorTable v_DestTable   = formPallete.destColorTable;
            int        v_A;
            double     v_H, v_L, v_S;
            int        v_R, v_G, v_B, v_r_n, v_g_n, v_b_n;
            int        RGB_Src;
            int        colorNew;

            double[] hsb;
            int      colorCount = formPallete.currentColorIDs.Count;

            if (colorCount == 0)
            {
                colorCount = v_SourceTable.getColorCount();
                for (int v_i = 0; v_i < colorCount; v_i++)
                {
                    // Reserve the Alpha channel of the Dest.
                    RGB_Src = v_SourceTable.getColor(v_i);
                    v_A     = 0xFF;
                    if (v_i == formPallete.transID)//透明色
                    {
                        continue;
                    }
                    // Extract the RGB values from the Source.
                    v_R = (RGB_Src >> 16) & 0xFF;
                    v_G = (RGB_Src >> 8) & 0xFF;
                    v_B = (RGB_Src) & 0xFF;
                    // Get the new RGB values.
                    v_r_n = f_Red_Lookup[v_R];
                    v_g_n = f_Green_Lookup[v_G];
                    v_b_n = f_Blue_Lookup[v_B];
                    // Modify the RGB values of the Dest.
                    colorNew = (v_A << 24) | (v_r_n << 16) | (v_g_n << 8) | v_b_n;
                    v_DestTable.setColor(v_i, colorNew);

                    if (f_PreserveLuminosity)
                    {
                        // Get the new HLS.
                        //RGBToHLS_32(colorNew);
                        hsb = GraphicsUtil.RGBtoHSB(v_r_n, v_g_n, v_b_n);
                        v_H = hsb[0] * 360;
                        v_S = hsb[1] * 100;
                        v_L = hsb[2] * 255;
                        //v_S = IntToSaturation((int)v_S);
                        // Get the original L.
                        //colorNew  = RGB_Src;
                        //v_L = IntToByte(RGBToLightness_32(RGB_Src));
                        hsb = GraphicsUtil.RGBtoHSB(v_R, v_G, v_B);
                        // Combine the new H, S and the original L.
                        //colorNew=HLSToRGB_32(v_A, v_H, v_L, v_S);
                        v_L      = hsb[2] * 255;
                        colorNew = GraphicsUtil.HSBtoRGB(v_H / 360.0D, v_S / 100.0D, v_L / 255.0D);
                        v_DestTable.setColor(v_i, colorNew);
                        //Console.WriteLine(MiscUtil.convertHexString(RGB_Src) + "," + MiscUtil.convertHexString(colorNew));
                    }
                }
            }
            else
            {
                int id;
                for (int v_i = 0; v_i < colorCount; v_i++)
                {
                    id = (int)formPallete.currentColorIDs[v_i];
                    // Reserve the Alpha channel of the Dest.
                    RGB_Src = v_SourceTable.getColor(id);
                    v_A     = 0xFF;
                    if (id == formPallete.transID)//透明色
                    {
                        continue;
                    }
                    // Extract the RGB values from the Source.
                    v_R = (RGB_Src >> 16) & 0xFF;
                    v_G = (RGB_Src >> 8) & 0xFF;
                    v_B = (RGB_Src) & 0xFF;
                    // Get the new RGB values.
                    v_r_n = f_Red_Lookup[v_R];
                    v_g_n = f_Green_Lookup[v_G];
                    v_b_n = f_Blue_Lookup[v_B];
                    // Modify the RGB values of the Dest.
                    colorNew = (v_A << 24) | (v_r_n << 16) | (v_g_n << 8) | v_b_n;
                    v_DestTable.setColor(id, colorNew);

                    if (f_PreserveLuminosity)
                    {
                        // Get the new HLS.
                        //RGBToHLS_32(colorNew);
                        hsb = GraphicsUtil.RGBtoHSB(v_r_n, v_g_n, v_b_n);
                        v_H = hsb[0] * 360;
                        v_S = hsb[1] * 100;
                        v_L = hsb[2] * 255;
                        //v_S = IntToSaturation((int)v_S);
                        // Get the original L.
                        //colorNew  = RGB_Src;
                        //v_L = IntToByte(RGBToLightness_32(RGB_Src));
                        hsb = GraphicsUtil.RGBtoHSB(v_R, v_G, v_B);
                        // Combine the new H, S and the original L.
                        //colorNew=HLSToRGB_32(v_A, v_H, v_L, v_S);
                        v_L      = hsb[2] * 255;
                        colorNew = GraphicsUtil.HSBtoRGB(v_H / 360.0D, v_S / 100.0D, v_L / 255.0D);
                        v_DestTable.setColor(id, colorNew);
                        //Console.WriteLine(MiscUtil.convertHexString(RGB_Src) + "," + MiscUtil.convertHexString(colorNew));
                    }
                }
            }
        }