Beispiel #1
0
        /// <summary>
        /// liefert den einfachstmöglichen BitmapColorMode
        /// </summary>
        /// <param name="bm"></param>
        /// <returns></returns>
        protected BitmapColorMode GetMinBitmapColorMode(Bitmap bm)
        {
            bool bWithTransp, bWithAlpha;

            Color[] coltab;
            return(PixMap.AnalyseBitmap(bm, true, out coltab, out bWithTransp, out bWithAlpha));
        }
Beispiel #2
0
 /// <summary>
 /// erzeugt eine Kopie des Bildes
 /// </summary>
 /// <param name="xpm"></param>
 public PixMap(PixMap xpm)
 {
     data          = new PixData(xpm.data);
     Colormode     = xpm.Colormode;
     colColorTable = new Color[xpm.colColorTable.Length];
     xpm.colColorTable.CopyTo(colColorTable, 0);
 }
Beispiel #3
0
 public GraphicElement(GraphicElement ge)
     : this()
 {
     Type    = ge.Type;
     Subtype = ge.Subtype;
     Text    = new MultiText(ge.Text);
     for (int i = 0; i < colDayColor.Length; i++)
     {
         colDayColor[i] = ge.colDayColor[i];
     }
     for (int i = 0; i < colNightColor.Length; i++)
     {
         colNightColor[i] = ge.colNightColor[i];
     }
     for (int i = 0; i < colFontColour.Length; i++)
     {
         colFontColour[i] = ge.colFontColour[i];
     }
     Options      = ge.Options;
     ExtOptions   = ge.ExtOptions;
     FontType     = ge.FontType;
     FontColType  = ge.FontColType;
     XBitmapDay   = new PixMap(XBitmapDay);
     XBitmapNight = new PixMap(XBitmapNight);
 }
Beispiel #4
0
        /// <summary>
        /// setzt die Bitmaps (falls nicht null) mit dem einfachstmöglichen BitmapColorMode
        /// </summary>
        /// <param name="bmday"></param>
        /// <param name="bmnight"></param>
        /// <param name="bOnlyGarminColors">Die jeweils nächstgelegene Garminfarbe verwenden?</param>
        public void SetBitmaps(Bitmap bmday, Bitmap bmnight, bool bOnlyGarminColors)
        {
            if (bmday == null)
            {
                throw new Exception("Wenigstens das Tag-Bitmap muß gesetzt werden.");
            }
            if (bmnight != null)
            {
                if (bmday.Width != bmnight.Width || bmday.Height != bmnight.Height)
                {
                    throw new Exception("Beide Bitmaps müßen die gleiche Größe haben.");
                }
            }
            if ((bmday.Width > 255 || bmday.Height > 255) ||
                (bmnight != null && (bmnight.Width > 255 || bmnight.Height > 255)))
            {
                throw new Exception("Das Bitmap darf höchstens 255x255 groß sein.");
            }
            BitmapColorMode cm = GetMinBitmapColorMode(GetMinBitmapColorMode(bmday), GetMinBitmapColorMode(bmnight));

            ColormodeDay = cm;
            if (bmday != null)     // sonst bleibt das alte bestehen
            {
                XBitmapDay = new PixMap(bmday, ColormodeDay);
                if (bOnlyGarminColors)
                {
                    for (uint i = 0; i < XBitmapDay.Colors; i++)
                    {
                        XBitmapDay.SetNewColor(i, GraphicElement.GetNearestGarminColor(XBitmapDay.GetColor(i)));
                    }
                }
            }
            if (bmnight != null)
            {
                XBitmapNight = new PixMap(bmnight, ColormodeDay);
                WithNightXpm = true;
                if (bOnlyGarminColors)
                {
                    for (uint i = 0; i < XBitmapNight.Colors; i++)
                    {
                        XBitmapNight.SetNewColor(i, GraphicElement.GetNearestGarminColor(XBitmapNight.GetColor(i)));
                    }
                }
            }
            else
            {
                XBitmapNight = null;
                WithNightXpm = false;
            }
            Width  = XBitmapDay.Width;
            Height = XBitmapDay.Height;
        }
Beispiel #5
0
 public POI(uint iTyp, uint iSubtyp)
     : base()
 {
     Type                  = iTyp;
     Subtype               = iSubtyp;
     NightXpmHasData       = true;
     WithNightXpm          = false;
     nonvirtual_WithString = false;
     nonvirtual_WithString = false;
     XBitmapDay            = new PixMap(16, 16, 2, BitmapColorMode.POI_ALPHA);
     XBitmapNight          = new PixMap(XBitmapDay);
     ColormodeDay          = XBitmapDay.Colormode;
 }
Beispiel #6
0
        public void Read(BinaryReaderWriter br)
        {
            try {
                Options = br.ReadByte();
                uint iWidth  = br.ReadByte();
                uint iHeight = br.ReadByte();
                colsday         = br.ReadByte();
                ColormodeDay    = (BitmapColorMode)br.ReadByte();
                this.XBitmapDay = new PixMap(iWidth, iHeight, colsday, ColormodeDay, br);
                if (WithNightXpm)
                {
                    colsnight      = br.ReadByte();
                    ColormodeNight = (BitmapColorMode)br.ReadByte();
                    if (!NightXpmHasData)
                    {
                        Color[] col = BinaryColor.ReadColorTable(br, colsnight);
                        XBitmapNight = new PixMap(XBitmapDay);
                        XBitmapNight.SetNewColors(col);
                    }
                    else
                    {
                        XBitmapNight = new PixMap(Width, Height, colsnight, ColormodeNight, br);
                    }
                }
                if (WithString)
                {
                    Text = new MultiText(br);
                }
                if (WithExtendedOptions)
                {
                    ExtOptions = br.ReadByte();
                    switch (FontColType)
                    {
                    case FontColours.Day:
                        colFontColour[0] = BinaryColor.ReadColor(br);
                        break;

                    case FontColours.Night:
                        colFontColour[1] = BinaryColor.ReadColor(br);
                        break;

                    case FontColours.DayAndNight:
                        colFontColour = BinaryColor.ReadColorTable(br, 2);
                        break;
                    }
                }
            } catch (Exception ex) {
                throw new Exception(string.Format("Fehler beim Lesen des Punktes 0x{0:x} 0x{1:x}: {2}", Type, Subtype, ex.Message));
            }
        }
Beispiel #7
0
        /// <summary>
        /// setzt das Bitmap und die Farben neu
        /// </summary>
        /// <param name="typ"></param>
        /// <param name="bmday"></param>
        public void SetBitmap(PolylineType typ, Bitmap bmday)
        {
            if (bmday.Width != 32 || bmday.Height > 31)
            {
                throw new Exception("Das Bitmap muß 32 breit sein und darf höchstens 31 hoch sein.");
            }
            if (Polylinetype != typ)
            {
                Polylinetype = typ;
            }
            switch (Polylinetype)
            {
            case PolylineType.Day1_Night2:
            case PolylineType.NoBorder_Day1:
            case PolylineType.NoBorder_Day1_Night1:
                XBitmapDay = new PixMap(bmday, BitmapColorMode.POLY1TR);
                break;

            case PolylineType.Day2:
            case PolylineType.Day2_Night2:
            case PolylineType.NoBorder_Day2_Night1:
                XBitmapDay = new PixMap(bmday, BitmapColorMode.POLY2);
                break;
            }
            BitmapHeight = (uint)bmday.Height;
            DayColor1    = XBitmapDay.GetColor(0);
            switch (typ)
            {
            case PolylineType.Day2:
            case PolylineType.Day2_Night2:
            case PolylineType.NoBorder_Day2_Night1:
                DayColor2 = XBitmapDay.Colors > 1 ? XBitmapDay.GetColor(1) : Color.CornflowerBlue;
                break;
            }
            switch (typ)
            {
            case PolylineType.NoBorder_Day1_Night1:
            case PolylineType.NoBorder_Day2_Night1:
                NightColor1 = DayColor1;
                break;

            case PolylineType.Day1_Night2:
            case PolylineType.Day2_Night2:
                base.NightColor1 = DayColor1;
                base.NightColor2 = DayColor2;
                break;
            }
        }
Beispiel #8
0
        private PixMap GetDummyXPixMap(BitmapColorMode bcm, bool b4Day, PixMap old)
        {
            if (old != null)
            {
                if (old.Colormode != bcm)
                {
                    switch (old.Colormode)
                    {
                    case BitmapColorMode.POLY1TR:
                        old.ChangeColorMode(BitmapColorMode.POLY2);
                        old.InvertBits();
                        old.SetNewColors(new Color[] { old.GetColor(0), Color.White });     // 2. Farbe einfach Weiß
                        break;

                    case BitmapColorMode.POLY2:
                        old.ChangeColorMode(BitmapColorMode.POLY1TR);
                        old.InvertBits();
                        old.SetNewColors(new Color[] { old.GetColor(0) });
                        break;
                    }
                }
                return(old);
            }

            PixMap pic = new PixMap(32, 32, 2, bcm);

            if (b4Day)
            {
                pic.SetNewColor(0, DayColor1);
                if (bcm == BitmapColorMode.POLY2)
                {
                    pic.SetNewColor(1, DayColor2);
                }
            }
            else
            {
                pic.SetNewColor(0, NightColor1);
                if (bcm == BitmapColorMode.POLY2)
                {
                    pic.SetNewColor(1, NightColor2);
                }
            }
            return(pic);
        }
Beispiel #9
0
 /// <summary>
 /// liefert das Bitmap
 /// </summary>
 /// <param name="b4Day">für Tag oder Nacht</param>
 /// <returns></returns>
 public Bitmap AsBitmap(bool b4Day)
 {
     if (b4Day && XBitmapDay != null)
     {
         PixMap tmp = new PixMap(XBitmapDay);
         if (tmp.Colors > 0)
         {
             tmp.InvertBits();
         }
         return(tmp.AsBitmap());
     }
     if (!b4Day && XBitmapNight != null)
     {
         PixMap tmp = new PixMap(XBitmapNight);
         if (tmp.Colors > 0)
         {
             tmp.InvertBits();
         }
         return(tmp.AsBitmap());
     }
     return(null);
 }
Beispiel #10
0
        /// <summary>
        /// liefert das Bitmap (falls vorhanden)
        /// </summary>
        /// <param name="b4Day">für Tag oder Nacht</param>
        /// <param name="bExt">auch "bitmaplose" Linie als Bitmap 32 x n</param>
        /// <returns></returns>
        public override Bitmap AsBitmap(bool b4Day, bool bExt)
        {
            Bitmap bm = null;

            if (WithDayBitmap)
            {
                PixMap tmp = new PixMap(XBitmapDay);
                // Das Bitmap hat bisher nur eine Dummyfarbe. Jetzt müßen noch die richtigen Farben gesetzt werden.
                if (b4Day)
                {
                    switch (Polylinetype)
                    {
                    case PolylineType.Day2:
                    case PolylineType.Day2_Night2:
                    case PolylineType.NoBorder_Day2_Night1:
                        tmp.SetNewColors(colDayColor);
                        break;

                    case PolylineType.Day1_Night2:
                    case PolylineType.NoBorder_Day1:
                    case PolylineType.NoBorder_Day1_Night1:
                        tmp.SetNewColor(0, colDayColor[0]);
                        break;
                    }
                }
                else
                {
                    switch (Polylinetype)
                    {
                    case PolylineType.Day2:
                    case PolylineType.NoBorder_Day1:
                        tmp = null;
                        break;

                    case PolylineType.Day1_Night2:
                    case PolylineType.Day2_Night2:
                        tmp.SetNewColors(colNightColor);
                        break;

                    case PolylineType.NoBorder_Day2_Night1:
                    case PolylineType.NoBorder_Day1_Night1:
                        tmp.SetNewColor(0, colNightColor[0]);
                        break;
                    }
                }
                if (tmp != null)
                {
                    bm = tmp.AsBitmap();
                }
            }
            else
            {
                if (bExt)
                {
                    bm = new Bitmap(32, (int)(InnerWidth + 2 * BorderWidth));
                    for (int y = 0; y < bm.Height; y++)
                    {
                        bool  bBorder = y < BorderWidth || y >= (InnerWidth + BorderWidth);
                        Color col;
                        if (b4Day)
                        {
                            col = bBorder ? colDayColor[1] : colDayColor[0];
                        }
                        else
                        {
                            col = bBorder ? colNightColor[1] : colNightColor[0];
                        }
                        for (int x = 0; x < bm.Width; x++)
                        {
                            bm.SetPixel(x, y, col);
                        }
                    }
                }
            }
            return(bm);
        }
Beispiel #11
0
        public void Read(BinaryReaderWriter br)
        {
            long startpos = br.BaseStream.Position;

            try {
                Options  = br.ReadByte();
                Options2 = br.ReadByte();

                // Farben einlesen (1 bis max. 4)
                switch (Polylinetype)
                {
                case PolylineType.Day2:
                    colDayColor = BinaryColor.ReadColorTable(br, 2);
                    break;

                case PolylineType.Day2_Night2:
                    colDayColor   = BinaryColor.ReadColorTable(br, 2);
                    colNightColor = BinaryColor.ReadColorTable(br, 2);
                    break;

                case PolylineType.Day1_Night2:
                    colDayColor[0] = BinaryColor.ReadColor(br);
                    colNightColor  = BinaryColor.ReadColorTable(br, 2);
                    break;

                case PolylineType.NoBorder_Day2_Night1:
                    colDayColor      = BinaryColor.ReadColorTable(br, 2);
                    colNightColor[0] = BinaryColor.ReadColor(br);
                    break;

                case PolylineType.NoBorder_Day1:
                    colDayColor[0] = BinaryColor.ReadColor(br);
                    break;

                case PolylineType.NoBorder_Day1_Night1:
                    colDayColor[0]   = BinaryColor.ReadColor(br);
                    colNightColor[0] = BinaryColor.ReadColor(br);
                    break;
                }

                if (BitmapHeight == 0) // Linien- und Randbreite ermitteln
                {
                    switch (Polylinetype)
                    {
                    case PolylineType.Day2:
                    case PolylineType.Day2_Night2:
                    case PolylineType.Day1_Night2:
                        InnerWidth = br.ReadByte();
                        if (InnerWidth > 0)              // sonst Bitmap, also KEINE BorderWidth
                        {
                            BorderWidth = (br.ReadByte() - InnerWidth) / 2;
                        }
                        break;

                    case PolylineType.NoBorder_Day2_Night1:
                    case PolylineType.NoBorder_Day1:
                    case PolylineType.NoBorder_Day1_Night1:
                        InnerWidth = br.ReadByte();      // es folgt KEINE BorderWidth
                        break;
                    }
                }
                else   // Bitmap einlesen (Höhe ist Thickness Pixel, Breite 32 Pixel, Dummyfarbe!)
                {
                    XBitmapDay = new PixMap(32, BitmapHeight, new Color[1] {
                        Color.White
                    }, BitmapColorMode.POLY1TR, br);
                }

                if (WithString)
                {
                    Text = new MultiText(br);
                }

                if (WithExtendedOptions)
                {
                    ExtOptions = br.ReadByte();
                    switch (FontColType)
                    {
                    case FontColours.Day:
                        colFontColour[0] = BinaryColor.ReadColor(br);
                        break;

                    case FontColours.Night:
                        colFontColour[1] = BinaryColor.ReadColor(br);
                        break;

                    case FontColours.DayAndNight:
                        colFontColour = BinaryColor.ReadColorTable(br, 2);
                        break;
                    }
                }
            } catch (Exception ex) {
                throw new Exception(string.Format("Fehler beim Lesen der Linie 0x{0:x} 0x{1:x}: {2}", Type, Subtype, ex.Message));
            }
        }
Beispiel #12
0
        /// <summary>
        /// setzt der oder die 32x32-Bitmaps für die Darstellung
        /// </summary>
        /// <param name="typ"></param>
        /// <param name="bmday"></param>
        /// <param name="bmnight"></param>
        public void SetBitmaps(ColorType typ, Bitmap bmday, Bitmap bmnight = null)
        {
            if (bmday == null)
            {
                throw new Exception("Kein Bitmap angegeben.");
            }
            if (typ == ColorType.Day1 ||
                typ == ColorType.Day1_Night1)
            {
                throw new Exception("Falscher Typ für eine Darstellung mit Bitmap.");
            }
            if (bmday.Width != 32 || bmday.Height != 32)
            {
                throw new Exception("Das Bitmap muß 32x32 groß sein.");
            }
            if (Colortype != typ)
            {
                Colortype = typ;
            }
            switch (typ)
            {
            case ColorType.BM_Day1:
            case ColorType.BM_Day1_Night1:
            case ColorType.BM_Day1_Night2:
                XBitmapDay = new PixMap(bmday, BitmapColorMode.POLY1TR);
                DayColor1  = XBitmapDay.GetColor(0);
                break;

            case ColorType.BM_Day2:
            case ColorType.BM_Day2_Night1:
            case ColorType.BM_Day2_Night2:
                XBitmapDay = new PixMap(bmday, BitmapColorMode.POLY2);
                DayColor1  = XBitmapDay.GetColor(0);
                DayColor2  = XBitmapDay.GetColor(1);
                break;
            }

            if (bmnight != null)
            {
                if (bmday.Width != bmnight.Width || bmday.Height != bmnight.Height)
                {
                    throw new Exception("Beide Bitmaps müßen die gleiche Größe haben.");
                }
                switch (typ)
                {
                case ColorType.BM_Day1_Night1:
                case ColorType.BM_Day2_Night1:
                    XBitmapNight = new PixMap(bmnight, BitmapColorMode.POLY1TR);
                    NightColor1  = XBitmapNight.GetColor(0);
                    break;

                case ColorType.BM_Day1_Night2:
                case ColorType.BM_Day2_Night2:
                    XBitmapNight = new PixMap(bmnight, BitmapColorMode.POLY1TR);
                    NightColor1  = XBitmapNight.GetColor(0);
                    NightColor2  = XBitmapNight.GetColor(1);
                    break;
                }
            }
            else
            {
                XBitmapNight = null;
            }
        }
Beispiel #13
0
        public void Read(BinaryReaderWriter br)
        {
            try {
                Options = br.ReadByte();

                // es folgen 1 bis max. 4 Farben und ev. 1 Bitmap
                switch (Colortype) // hier muss sicher noch überprüft werden, ob die Typen wirklich richtig interpretiert werden
                {
                case ColorType.Day1:
                    colDayColor[0] = BinaryColor.ReadColor(br);
                    break;

                case ColorType.Day1_Night1:
                    colDayColor[0]   = BinaryColor.ReadColor(br);
                    colNightColor[0] = BinaryColor.ReadColor(br);
                    break;

                case ColorType.BM_Day2:          // 2 Farben + 1x Pixeldaten
                    colDayColor = BinaryColor.ReadColorTable(br, 2);
                    XBitmapDay  = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY2, br);
                    break;

                case ColorType.BM_Day2_Night2:   // 4 Farben + 1x Pixeldaten
                    colDayColor   = BinaryColor.ReadColorTable(br, 2);
                    colNightColor = BinaryColor.ReadColorTable(br, 2);
                    XBitmapDay    = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY2, br);
                    XBitmapNight  = new PixMap(XBitmapDay);
                    XBitmapNight.SetNewColors(colNightColor);
                    break;

                case ColorType.BM_Day1_Night2:   // 3 Farben + 1x Pixeldaten
                    colDayColor[0] = BinaryColor.ReadColor(br);
                    colDayColor[1] = PixMap.TransparentColor;
                    colNightColor  = BinaryColor.ReadColorTable(br, 2);
                    XBitmapDay     = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY2, br);
                    XBitmapNight   = new PixMap(XBitmapDay);
                    XBitmapNight.ChangeColorMode(BitmapColorMode.POLY2);
                    XBitmapNight.SetNewColors(colNightColor);
                    break;

                case ColorType.BM_Day2_Night1:   // 3 Farben + 1x Pixeldaten
                    colDayColor      = BinaryColor.ReadColorTable(br, 2);
                    colNightColor[0] = BinaryColor.ReadColor(br);
                    colNightColor[1] = PixMap.TransparentColor;
                    XBitmapDay       = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY2, br);
                    XBitmapNight     = new PixMap(XBitmapDay);
                    XBitmapNight.ChangeColorMode(BitmapColorMode.POLY1TR);
                    XBitmapNight.SetNewColors(colNightColor);
                    break;

                case ColorType.BM_Day1:          // 1 Farbe + 1x Pixeldaten
                    colDayColor[0] = colNightColor[0] = BinaryColor.ReadColor(br);
                    colDayColor[1] = colNightColor[1] = PixMap.TransparentColor;
                    XBitmapDay     = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY1TR, br);
                    break;

                case ColorType.BM_Day1_Night1:   // 2 Farben + 1x Pixeldaten
                    colDayColor[0]   = BinaryColor.ReadColor(br);
                    colDayColor[1]   = PixMap.TransparentColor;
                    colNightColor[0] = BinaryColor.ReadColor(br);
                    colNightColor[1] = PixMap.TransparentColor;
                    XBitmapDay       = new PixMap(32, 32, colDayColor, BitmapColorMode.POLY1TR, br);
                    XBitmapNight     = new PixMap(XBitmapDay);
                    XBitmapNight.SetNewColors(colNightColor);
                    break;
                }
                if (WithDayBitmap)
                {
                    // sicherheitshalber nochmal die Bitmapfarben übernehmen
                    DayColor1 = XBitmapDay.GetColor(0);
                    if (XBitmapDay.Colors > 1)
                    {
                        DayColor2 = XBitmapDay.GetColor(1);
                    }
                    if (XBitmapNight != null)
                    {
                        NightColor1 = XBitmapNight.GetColor(0);
                        if (XBitmapNight.Colors > 1)
                        {
                            NightColor2 = XBitmapNight.GetColor(1);
                        }
                    }
                }

                if (WithString)
                {
                    Text = new MultiText(br);
                }

                if (WithExtendedOptions)  // es folgen weitere (max. 2) Farben
                {
                    ExtOptions = br.ReadByte();
                    switch (FontColType)
                    {
                    case FontColours.Day:
                        colFontColour[0] = BinaryColor.ReadColor(br);
                        break;

                    case FontColours.Night:
                        colFontColour[1] = BinaryColor.ReadColor(br);
                        break;

                    case FontColours.DayAndNight:
                        colFontColour = BinaryColor.ReadColorTable(br, 2);
                        break;
                    }
                }
            } catch (Exception ex) {
                throw new Exception(string.Format("Fehler beim Lesen des Polygons 0x{0:x} 0x{1:x}: {2}", Type, Subtype, ex.Message));
            }
        }