/// <summary>
        /// Set the preview pane to a previewable item
        /// </summary>
        /// <param name="item"></param>
        public void SetPreviewItem(object item)
        {
            if (item is Thumbnail)
            {
                // Set the underlying object's preview then add a context menu
                Thumbnail thumb = (Thumbnail)item;
                SetPreviewItem(thumb.ThumbnailOf);
            }
            else if (item is BitmapType)
            {
                BitmapType preview = (BitmapType)item;
                imagePreview.Source = preview.Bitmap;

                InputBindings.Clear();

                MouseBinding doubleclick = new MouseBinding(Commands.CmdFullscreen, new MouseGesture(MouseAction.LeftDoubleClick));
                doubleclick.CommandTarget    = this;
                doubleclick.CommandParameter = preview;
                InputBindings.Add(doubleclick);

                List <MenuItem> menuitems = GetMenuItems(item, item);
                ContextMenu = new ContextMenu()
                {
                    ItemsSource = menuitems
                };
            }
            else
            {
                imagePreview.Source = null;
                InputBindings.Clear();
                ContextMenu = null;
            }
        }
Example #2
0
        public void Save(string filename, BitmapType type, bool withBorder)
        {
            FileStream stream = new FileStream(filename, FileMode.Create);

            this.Save(stream, type, withBorder);
            stream.Close();
        }
        public Texture(PakFile Pak, PakFile.PakTag Item)
        {
            var reader = Pak.Reader;
            reader.EndianType = EndianFormat.LittleEndian;
            reader.SeekTo(Item.Offset + 6);

            isLittleEndian = reader.ReadInt32() == 1346978644; //PICT
            if (!isLittleEndian) reader.EndianType = Endian.EndianFormat.BigEndian;

            reader.SeekTo(Item.Offset + (isLittleEndian ? 16 : 12));
            Width = reader.ReadInt32();
            Height = reader.ReadInt32();

            reader.SeekTo(Item.Offset + (isLittleEndian ? 38 : 32));
            Format = BitmapFormat.Dxt5;
            var intFormat = reader.ReadInt32();
            switch (intFormat)
            {
                case 0:
                    Format = BitmapFormat.A8R8G8B8;
                    break;
                case 10:
                    Format = BitmapFormat.A8Y8;
                    break;
                case 12:
                    Format = BitmapFormat.Dxt1;
                    break;
                case 13:
                    Format = BitmapFormat.Dxt1;
                    break;
                case 15:
                    Format = BitmapFormat.Dxt3;
                    break;
                case 17:
                    Format = BitmapFormat.Dxt5;
                    break;
                case 22:
                    Format = BitmapFormat.X8R8G8B8;
                    break;
                case 36:
                    Format = BitmapFormat.Dxn;
                    break;
                case 37:
                    Format = BitmapFormat.DXT5a;
                    break;
                default:
                    throw new Exception("CHECK THIS");
            }

            reader.SeekTo(Item.Offset + (isLittleEndian ? 28 : 24));
            int mapCount = reader.ReadInt32();
            if (mapCount == 6) Type = BitmapType.CubeMap;
            else Type = BitmapType.Texture2D;

            if (mapCount > 1 && mapCount != 6)
                throw new Exception("CHECK THIS");

            DataAddress = Item.Offset + (isLittleEndian ? 58 : 4096);
            reader.EndianType = Endian.EndianFormat.LittleEndian; //in case it was PICT
        }
Example #4
0
    public BaseBitmap(BitmapTextureInterleavedInteropResource definition, int index, Bitmap.Image image)
    {
        var def = definition.Texture.Definition;

        if (index == 0)
        {
            Height      = def.Height1;
            Width       = def.Width1;
            Depth       = def.Depth1;
            MipMapCount = def.MipmapCount1 - 1;
            Type        = def.Type1;
            Flags       = image.Flags;
            UpdateFormat(image.Format);
        }
        else
        {
            Height      = def.Height2;
            Width       = def.Width2;
            Depth       = def.Depth2;
            MipMapCount = def.MipmapCount2 - 1;
            Type        = def.Type2;
            Flags       = image.Flags;
            UpdateFormat(image.Format);
        }
    }
Example #5
0
        public void Save(string filename, BitmapType type)
        {
            FileStream stream = new FileStream(filename, FileMode.Create);

            this.Save(stream, type, false);
            stream.Close();
        }
Example #6
0
        public void Load(string filename, BitmapType type, bool setSize)
        {
            FileStream stream = new FileStream(filename, FileMode.Open);

            this.Load(stream, type, setSize);
            stream.Close();
        }
Example #7
0
 public BaseBitmap(BitmapTextureInterleavedInteropResource definition, int index, Bitmap.Image image)
 {
     if (index == 0)
     {
         var def = definition.Texture.Definition.Bitmap1;
         Height      = def.Height;
         Width       = def.Width;
         Depth       = def.Depth;
         MipMapCount = def.MipmapCount - 1;
         Type        = def.BitmapType;
         Flags       = image.Flags;
         UpdateFormat(image.Format);
     }
     else
     {
         var def = definition.Texture.Definition.Bitmap2;
         Height      = def.Height;
         Width       = def.Width;
         Depth       = def.Depth;
         MipMapCount = def.MipmapCount - 1;
         Type        = def.BitmapType;
         Flags       = image.Flags;
         UpdateFormat(image.Format);
     }
     MipMapOffset = image.MipMapOffset;
     Curve        = image.Curve;
 }
Example #8
0
 public static bool ContrainsElement(string name, BitmapType type)
 {
     if ((graphicElements.FindAll(x => x.Name == name && x.eType == type).Count > 0))
     {
         return(true);
     }
     return(false);
 }
 internal TouchManipulationBitmap(SKBitmap bitmap, BitmapType type, string text, SKColor color = default)
 {
     Matrix = SKMatrix.MakeIdentity();
     Bitmap = bitmap;
     Type   = type;
     Color  = color;
     Text   = text;
 }
 internal TouchManipulationBitmap(SKBitmap bitmap, SKMatrix matrix, BitmapType type, string text, SKColor color = default)
 {
     Bitmap = bitmap;
     Matrix = matrix;
     Type   = type;
     Text   = text;
     Color  = color;
 }
Example #11
0
        public Thumbnail(BitmapType represents)
            : base()
        {
            ThumbnailOf = represents;

            Source = ThumbnailOf.GetThumbnail(false);

//            ContextMenu = GetContextMenu();
        }
Example #12
0
 public BaseBitmap(BaseBitmap bitmap)
 {
     Height      = bitmap.Height;
     Width       = bitmap.Width;
     Depth       = bitmap.Depth;
     MipMapCount = bitmap.MipMapCount;
     Type        = bitmap.Type;
     Flags       = bitmap.Flags;
     UpdateFormat(bitmap.Format);
 }
 public virtual void Load(ref BinaryReader input)
 {
     Type   = (BitmapType)input.ReadInt16();
     Format = (BitmapFormat)input.ReadInt16();
     Usage  = (BitmapUsage)input.ReadInt16();
     input.BaseStream.Position += 16;
     ColorPlateWidth            = input.ReadInt16();
     ColorPlateHeight           = input.ReadInt16();
     ColorPlateData             = input.ReadInt32();
 }
Example #14
0
        //---------------------------------------------------------------------

        private static IntPtr LoadImageFromByteArray(byte[] data, BitmapType type)
        {
            IntPtr DataPtr = IntPtr.Zero;

            DataPtr = Marshal.AllocHGlobal(data.Length);

            Marshal.Copy(data, 0, DataPtr, data.Length);

            return(wxImage_ctorByByteArray(DataPtr, data.Length, type));
        }
Example #15
0
 public BaseBitmap(Bitmap.Image image)
 {
     Height      = image.Height;
     Width       = image.Width;
     Depth       = image.Depth;
     MipMapCount = image.MipmapCount;
     Type        = image.Type;
     Flags       = image.Flags;
     UpdateFormat(image.Format);
 }
 // Full-screen view
 public void CmdFullscreenExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (e.Parameter is BitmapType || e.Parameter is Thumbnail)
     {
         BitmapType     target  = (BitmapType)e.Parameter;
         PreviewPane    restore = PreviewPane;
         FullscreenView fsview  = new FullscreenView(target, () => PreviewPane = restore);
         fsview.Show();
         PreviewPane = fsview.previewFullScreen;
     }
 }
Example #17
0
        //---------------------------------------------------------------------

        private static IntPtr LoadPossibleResource(string name, BitmapType type, Assembly asm)
        {
            if (type == BitmapType.wxBITMAP_TYPE_RESOURCE)
            {
                return(Object.SafePtr(new Image(name, asm)));
            }
            else
            {
                return(wxImage_ctorByName(name, type));
            }
        }
Example #18
0
        private void ChangeOutputType(object sender, UserEventArgs <BitmapType> e)
        {
            ((PictureBox)ImageController).Image = null;
            currentOutputType = e.item;
            var elements = (List <LocalDataGraphicsElement>)LocalDataBase.GetTypedElements(currentOutputType);

            if (elements != null)
            {
                ((GraphicsInfoControlMenu)ListController).SetListBoxItems(elements);
            }
        }
Example #19
0
        /// <summary>
        /// Find the thumnail that matches the specified item
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public Thumbnail FindThumbnail(BitmapType item)
        {
            foreach (Thumbnail thumb in myThumbnails)
            {
                if (thumb.ThumbnailOf == item)
                {
                    return(thumb);
                }
            }

            return(null);
        }
Example #20
0
 public BaseBitmap(BitmapTextureInteropDefinition definition, Bitmap.Image image)
 {
     Height       = definition.Height;
     Width        = definition.Width;
     Depth        = definition.Depth;
     MipMapCount  = definition.MipmapCount != 0 ? definition.MipmapCount - 1 : 0;
     Type         = definition.BitmapType;
     Flags        = image.Flags;
     Curve        = image.Curve;
     MipMapOffset = image.MipMapOffset;
     UpdateFormat(image.Format);
 }
Example #21
0
    public BaseBitmap(BitmapTextureInteropResource definition, Bitmap.Image image)
    {
        var def = definition.Texture.Definition;

        Height      = def.Height;
        Width       = def.Width;
        Depth       = def.Depth;
        MipMapCount = def.MipmapCount - 1;
        Type        = def.Type;
        Flags       = image.Flags;
        UpdateFormat(image.Format);
    }
Example #22
0
        public ushort[] GetData(BitmapType type)
        {
            switch (type)
            {
            case BitmapType.Depth:
                return(this.depthData);

            case BitmapType.Infrared:
                return(this.infraredData);
            }

            return(null);
        }
        /// <summary>
        /// Deserializes this structure from binary data.
        /// </summary>
        /// <param name="reader">The <see cref="BinaryReader"/> to read the data from.</param>
        public void ReadFrom(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            _width        = reader.ReadUInt32();
            _height       = reader.ReadUInt32();
            _flags        = (BitmapDescriptionFlags)reader.ReadUInt16();
            _bitsPerPixel = reader.ReadByte();
            _type         = (BitmapType)reader.ReadByte();
        }
Example #24
0
        public Texture(BinaryReader reader)
        {
            Magic                = Encoding.ASCII.GetString(reader.ReadBytes(4));
            Width                = reader.ReadInt32();
            Height               = reader.ReadInt32();
            BitsPerPixel         = reader.ReadInt32();
            OriginalBitsPerPixel = reader.ReadInt32();
            MipCount             = reader.ReadInt32();
            PaletteEntryCount    = reader.ReadInt32();
            CompressionCandidate = reader.ReadInt32();
            CompressionAllowed   = reader.ReadInt32();
            UsesAlpha            = reader.ReadInt32();
            UsesChromaKey        = reader.ReadInt32();
            Type     = (BitmapType)reader.ReadUInt32();
            Padding0 = reader.ReadUInt32();
            Padding1 = reader.ReadUInt32();
            Padding2 = reader.ReadUInt32();
            Padding3 = reader.ReadUInt32();

            if (PaletteEntryCount > 0 && Type != BitmapType.DXT3)
            {
                PaletteData = reader.ReadBytes(4 * PaletteEntryCount);
            }

            int bytes = 0;

            if ((Magic == MAGIC_PCT2 && (Type == BitmapType.RGBA || Type == BitmapType.BGRA)) || (Magic == MAGIC_PCT1 && PaletteEntryCount == 0))
            {
                bytes     = (int)(Width * Height * BitsPerPixel / 8);
                PixelData = reader.ReadBytes(bytes);
            }
            else if ((Magic == MAGIC_PCT2 && Type == BitmapType.Paletted) || (Magic == MAGIC_PCT1 && PaletteEntryCount > 0))
            {
                bytes     = (int)(Width * Height * BitsPerPixel / 8);
                PixelData = reader.ReadBytes(bytes);
            }
            else if (Magic == MAGIC_PCT2 && Type == BitmapType.DXT3)
            {
                bytes     = ((int)Width / 4) * ((int)Height / 4) * 16;
                PixelData = reader.ReadBytes(bytes);
            }

            if ((PixelData?.Length ?? 0) != bytes)
            {
                //System.Diagnostics.Debugger.Break();
                //Console.WriteLine(Unk08.ToString("X8") + " [BAD]");
                Console.WriteLine("[ERROR]: " + ToString());
                throw new NotSupportedException("No pixel data!");
            }
        }
Example #25
0
 public DDSImage(int Height, int Width, byte[] Buffer, BitmapFormat Format, BitmapType Type,
                 bool Swizzled, int Depth, int PixelOffset, int MipMapCount)
 {
     this.Height      = Height;
     this.Width       = Width;
     this.Buffer      = Buffer;
     this.Size        = Buffer.Length;
     this.Format      = Format;
     this.Type        = Type;
     this.Swizzled    = Swizzled;
     this.Depth       = Depth;
     this.PixelOffset = PixelOffset;
     this.MipMapCount = MipMapCount;
 }
 public virtual void Load(ref BinaryReader input)
 {
     Signature   = input.ReadUInt32();
     Width       = input.ReadInt16();
     Height      = input.ReadInt16();
     Depth       = input.ReadInt16();
     Type        = (BitmapType)input.ReadInt16();
     Format      = (BitmapDataFormat)input.ReadInt16();
     Flags       = (BitmapDataFlags)input.ReadInt16();
     RegPointX   = input.ReadInt16();
     RegPointY   = input.ReadInt16();
     NumMipmaps  = input.ReadInt16();
     PixelOffset = input.ReadInt16();
 }
Example #27
0
        /// <summary>
        /// Checks if the photo type is Thumbnail and if it is disables manipulation of all image controls for the layout grid.
        /// </summary>
        private static void OnPhotoTypeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            LayoutGrid layoutGrid = d as LayoutGrid;
            BitmapType type       = (BitmapType)e.NewValue;

            if (layoutGrid != null && type == BitmapType.Thumbnail)
            {
                // This layout grid is one of many displaying possible layouts that the user can choose from
                // and it must not have the option of manipulating individual photos
                foreach (Image img in layoutGrid.images)
                {
                    img.IsHitTestVisible = false;
                }
            }
        }
Example #28
0
 /// <summary>
 /// 添加位图到画布
 /// </summary>
 /// <param name="bitmap"></param>
 /// <param name="type"></param>
 internal void AddBitmapToCanvas(SKBitmap bitmap, BitmapType type)
 {
     if (bitmap != null)
     {
         if (type != BitmapType.Main)
         {
             AddBitmapToCanvas(new TouchManipulationBitmap(bitmap, type, null));
         }
         else
         {
             SetMainBitmap(bitmap);
         }
         InvalidateSurface();
     }
 }
Example #29
0
 internal ShaderTemplateParameterBlockBase(BinaryReader binaryReader)
 {
     this.name                 = binaryReader.ReadStringID();
     this.explanation          = ReadData(binaryReader);
     this.type                 = (Type)binaryReader.ReadInt16();
     this.flags                = (Flags)binaryReader.ReadInt16();
     this.defaultBitmap        = binaryReader.ReadTagReference();
     this.defaultConstValue    = binaryReader.ReadSingle();
     this.defaultConstColor    = binaryReader.ReadColorR8G8B8();
     this.bitmapType           = (BitmapType)binaryReader.ReadInt16();
     this.invalidName_         = binaryReader.ReadBytes(2);
     this.bitmapAnimationFlags = (BitmapAnimationFlags)binaryReader.ReadInt16();
     this.invalidName_0        = binaryReader.ReadBytes(2);
     this.bitmapScale          = binaryReader.ReadSingle();
 }
 /// <summary>
 /// Save image to a file
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void CmdSaveDepthmapExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         BitmapType image = e.Parameter as BitmapType;
         if (image != null)
         {
             theViewModel.SaveBitmapToFile(image, "Save Depthmap", theViewModel.DepthmapPalette.sDefaultDirectory);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error");
     }
 }
Example #31
0
        private void makebitmap(PictureBox box, BitmapType btype)
        {
            try
            {
                image = new Bitmap(512, 512);
                if (btype == BitmapType.SMA)
                {
                    var idx = SmaFormatter.GetIndex("tileinfo", "EventType");

                    var temp = (_SmaData[1] as object[]).Select(x => (byte)(x as object[])[idx]).ToArray();
                    for (int x = 0; x < 256; x++)
                    {
                        for (int y = 0; y < 256; y++)
                        {
                            for (int i = 0; i < 2; i++)
                            {
                                for (int j = 0; j < 2; j++)
                                {
                                    image.SetPixel(2 * (255 - y) + i, 2 * x + j, temp[x + 256 * y] == 0 ? Color.LightBlue : Color.Black);
                                }
                            }
                        }
                    }
                    box.Image = image;
                }

                if (btype == BitmapType.DAT)
                {
                    var idx  = MapFormatter.GetIndex("tileinfo", "EventType");
                    var temp = (_DatData[2] as object[]).Select(x => (byte)(x as object[])[idx]).ToArray();
                    for (int x = 0; x < 256; x++)
                    {
                        for (int y = 0; y < 256; y++)
                        {
                            for (int i = 0; i < 2; i++)
                            {
                                for (int j = 0; j < 2; j++)
                                {
                                    image.SetPixel(2 * (255 - y) + i, 2 * x + j, temp[x + 256 * y] == 0 ? Color.LightBlue : Color.Black);
                                }
                            }
                        }
                    }
                    box.Image = image;
                }
            }catch (Exception ex) { ErrorLogger.LogException(ex); }
        }
Example #32
0
        /// <summary>
        /// The decode bitmap.
        /// </summary>
        /// <param name="fart">The fart.</param>
        /// <param name="height">The height.</param>
        /// <param name="width">The width.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="bitsPerPixel">The bits per pixel.</param>
        /// <param name="type">The type.</param>
        /// <param name="format">The format.</param>
        /// <param name="swizzle">The swizzle.</param>
        /// <param name="map">The map.</param>
        /// <param name="visualchunkindex">The visualchunkindex.</param>
        /// <param name="ident">The ident.</param>
        /// <returns>The decode bitmap.</returns>
        /// <remarks></remarks>
        private static int DecodeBitmap(
            ref byte[] fart, 
            int height, 
            int width, 
            int depth, 
            int bitsPerPixel, 
            BitmapType type, 
            BitmapFormat format, 
            bool swizzle, 
            Map map, 
            int visualchunkindex, 
            int ident)
        {
            byte[] poo = new byte[0];

            int poolength;
            byte[] tempData;
            DecodeDXT decode = new DecodeDXT();

            int stride = width;

            if (swizzle)
            {
                fart = Swizzler.Swizzle(fart, width, height, depth, bitsPerPixel, true);
            }

            switch (format)
            {
                    #region DXT1

                case (BitmapFormat)14:
                    if (swizzle)
                    {
                        MessageBox.Show("Swizzled");
                    }

                    fart = decode.DecodeDXT1(height, width, fart);
                    stride *= 4;
                    break;

                    #endregion

                    #region DXT2/3

                case (BitmapFormat)15:
                    if (swizzle)
                    {
                        MessageBox.Show("Swizzled");
                    }

                    fart = decode.DecodeDXT23(height, width, fart);
                    stride *= 4;
                    break;

                    #endregion

                    #region DXT 4/5

                case (BitmapFormat)16:
                    if (swizzle)
                    {
                        MessageBox.Show("Swizzled");
                    }

                    fart = decode.DecodeDXT45(height, width, fart);
                    stride *= 4;
                    break;

                    #endregion

                    #region A8R8G8B8

                case (BitmapFormat)11:
                    stride *= 4;
                    break;

                    #endregion

                    #region X8R8G8B8

                case (BitmapFormat)10:
                    stride *= 4;

                    /*
                    poolength = fart.Length;
                    tempData = new byte[poolength];
                    for (int e = 0; e < poolength; e++)
                        tempData[e * 4 + 3] = 255;     // Alpha always 255
                    fart = tempData;
                    */
                    break;

                    #endregion

                    #region // 16 bit \\

                    #region A4R4G4B4

                case (BitmapFormat)9:
                    stride *= 4;
                    poolength = fart.Length;
                    tempData = new byte[poolength * 2];
                    for (int e = 0; e < poolength / 2; e++)
                    {
                        int r = e * 2;
                        tempData[r * 2 + 0] = (byte)((fart[r + 1] & 0xFF) >> 0); // Blue
                        tempData[r * 2 + 1] = (byte)((fart[r + 0] & 0xFF) >> 0); // Green
                        tempData[r * 2 + 2] = (byte)((fart[r + 0] & 0xFF) >> 0); // Red
                        tempData[r * 2 + 3] = 255; // (byte)(((fart[r + 1] & 0xFF) >> 0));        // Alpha
                    }

                    fart = tempData;
                    break;

                    #endregion

                    #region G8B8

                case (BitmapFormat)22:
                    stride *= 4;
                    poolength = fart.Length;
                    tempData = new byte[poolength / 2 * 4];

                    // These are actually signed (+/-128), so convert to unsigned
                    for (int e = 0; e < poolength / 2; e++)
                    {
                        int r = e * 2;
                        tempData[r * 2 + 0] = (byte)(fart[r + 1] + 128); // Blue
                        tempData[r * 2 + 1] = (byte)(fart[r + 1] + 128); // Green
                        tempData[r * 2 + 2] = (byte)(fart[r + 0] + 128); // Red
                        tempData[r * 2 + 3] = (byte)(fart[r + 0] + 128); // Alpha
                    }

                    fart = tempData;
                    break;

                    #endregion

                    #region A1R5G5B5

                case (BitmapFormat)8:
                    stride *= 4;
                    poolength = fart.Length;
                    tempData = new byte[poolength / 2 * 4];

                    for (int r = 0; r < fart.Length; r += 2)
                    {
                        int temp = fart[r + 0] + (fart[r + 1] << 8);
                        tempData[r * 2 + 0] = (byte)(((temp >> 0) & 0x1F) * 255 / 0x1F); // 5-bit Blue
                        tempData[r * 2 + 1] = (byte)(((temp >> 5) & 0x1F) * 255 / 0x1F); // 5-bit Green
                        tempData[r * 2 + 2] = (byte)(((temp >> 10) & 0x1F) * 255 / 0x1F); // 5-bit Red
                        tempData[r * 2 + 3] = (byte)(((temp >> 15) & 0x01) * 255); // 1-bit Alpha
                    }

                    fart = tempData;
                    break;

                    #endregion

                    #region R5G6B5

                case (BitmapFormat)6:
                    stride *= 4;
                    poolength = fart.Length;
                    tempData = new byte[poolength / 2 * 4];
                    for (int r = 0; r < fart.Length; r += 2)
                    {
                        int temp = fart[r + 0] + (fart[r + 1] << 8);
                        tempData[r * 2 + 0] = (byte)(((temp >> 0) & 0x1F) * 255 / 0x1F); // 5-bit Blue
                        tempData[r * 2 + 1] = (byte)(((temp >> 5) & 0x3F) * 255 / 0x3F); // 6-bit Green
                        tempData[r * 2 + 2] = (byte)(((temp >> 11) & 0x1F) * 255 / 0x1F); // 5-bit Red
                        tempData[r * 2 + 3] = 255; // Alpha always 255
                    }

                    fart = tempData;
                    break;

                    #endregion

                    #region A8Y8

                case (BitmapFormat)3:
                    poolength = fart.Length;
                    tempData = new byte[poolength / 2 * 4];
                    for (int e = 0; e < poolength / 2; e++)
                    {
                        int r = e * 2;
                        tempData[r * 2 + 0] = fart[r + 1]; // B
                        tempData[r * 2 + 1] = fart[r + 1]; // G
                        tempData[r * 2 + 2] = fart[r + 1]; // R
                        tempData[r * 2 + 3] = fart[r + 0]; // A
                    }

                    fart = tempData;
                    stride *= 4;
                    break;

                    #endregion

                    #region Unknown - Very similar (exactly?) to G8B8

                case (BitmapFormat)23:
                    stride *= 4;
                    poolength = fart.Length;
                    tempData = new byte[poolength / 2 * 4];

                    // These are actually signed (+/-128), so convert to unsigned
                    for (int e = 0; e < poolength / 2; e++)
                    {
                        int r = e * 2;
                        tempData[r * 2 + 0] = (byte)(fart[r + 1] + 128); // Blue
                        tempData[r * 2 + 1] = (byte)(fart[r + 1] + 128); // Green
                        tempData[r * 2 + 2] = (byte)(fart[r + 0] + 128); // Red
                        tempData[r * 2 + 3] = (byte)(fart[r + 0] + 128); // Alpha
                    }

                    fart = tempData;
                    break;

                    #endregion

                    #endregion

                    #region // 8 bit \\

                    #region P8

                case BitmapFormat.BITM_FORMAT_P8:
                    poolength = fart.Length;
                    tempData = new byte[poolength * 4];
                    for (int e = 0; e < poolength; e++)
                    {
                        int r = e * 4;
                        tempData[r + 0] = fart[e];
                        tempData[r + 1] = fart[e];
                        tempData[r + 2] = fart[e];
                        tempData[r + 3] = 255;
                    }

                    fart = tempData;
                    stride *= 4;
                    break;

                    #endregion

                    #region A8

                case BitmapFormat.BITM_FORMAT_A8:
                    poolength = fart.Length;
                    tempData = new byte[poolength * 4];
                    for (int e = 0; e < poolength; e++)
                    {
                        int r = e * 4;
                        tempData[r + 0] = fart[e];
                        tempData[r + 1] = fart[e];
                        tempData[r + 2] = fart[e];
                        tempData[r + 3] = 255;
                    }

                    fart = tempData;
                    stride *= 4;
                    break;

                    #endregion

                    #region AY8

                case BitmapFormat.BITM_FORMAT_AY8:
                    poolength = fart.Length;
                    tempData = new byte[poolength * 4];
                    for (int e = 0; e < poolength; e++)
                    {
                        int r = e * 4;
                        tempData[r + 0] = (byte)(fart[e]);
                        tempData[r + 1] = (byte)(fart[e]);
                        tempData[r + 2] = (byte)(fart[e]);
                        tempData[r + 3] = (byte)(fart[e] == 0 ? 0 : 255);
                    }

                    fart = tempData;
                    stride *= 4;
                    break;

                    #endregion

                    #region Y8

                case (BitmapFormat)1:
                    poolength = fart.Length;
                    tempData = new byte[poolength * 4];
                    for (int e = 0; e < poolength; e++)
                    {
                        int r = e * 4;
                        tempData[r + 0] = fart[e];
                        tempData[r + 1] = fart[e];
                        tempData[r + 2] = fart[e];
                        tempData[r + 3] = 255;
                    }

                    fart = tempData;
                    stride *= 4;
                    break;

                    #endregion

                    #region LightMap

                case BitmapFormat.BITM_FORMAT_LIGHTMAP:
                    poolength = fart.Length;
                    tempData = new byte[poolength * 4];
                    int bspnumber = ident;
                    int paletteindex = -1;

                    if (visualchunkindex < 0)
                    {
                        int wtf = 0 - (visualchunkindex + 1);
                        paletteindex = map.BSP.sbsp[bspnumber].SceneryChunk_LightMap_Index[wtf];
                    }

                    if (paletteindex == -1)
                    {
                        for (int i = 0; i < map.BSP.sbsp[bspnumber].VisualChunk_Bitmap_Index.Length; i++)
                        {
                            if (map.BSP.sbsp[bspnumber].VisualChunk_Bitmap_Index[i] == visualchunkindex)
                            {
                                paletteindex = map.BSP.sbsp[bspnumber].VisualChunk_LightMap_Index[visualchunkindex];
                                break;
                            }
                        }
                    }

                    if (paletteindex == -1)
                    {
                        for (int i = 0; i < map.BSP.sbsp[bspnumber].SceneryChunk_Bitmap_Index.Length; i++)
                        {
                            if (map.BSP.sbsp[bspnumber].SceneryChunk_Bitmap_Index[i] == visualchunkindex)
                            {
                                paletteindex = map.BSP.sbsp[bspnumber].SceneryChunk_LightMap_Index[i];
                                break;
                            }
                        }
                    }

                    if (paletteindex != 255)
                    {
                        for (int e = 0; e < poolength; e++)
                        {
                            int r = e * 4;
                            tempData[r + 0] = (byte)map.BSP.sbsp[bspnumber].LightMap_Palettes[paletteindex][fart[e]].r;
                            tempData[r + 1] = (byte)map.BSP.sbsp[bspnumber].LightMap_Palettes[paletteindex][fart[e]].g;
                            tempData[r + 2] = (byte)map.BSP.sbsp[bspnumber].LightMap_Palettes[paletteindex][fart[e]].b;
                            tempData[r + 3] = (byte)map.BSP.sbsp[bspnumber].LightMap_Palettes[paletteindex][fart[e]].a;
                        }

                        fart = tempData;
                        stride *= 4;
                    }

                    break;

                    #endregion

                    #endregion
            }

            return stride;
        }
Example #33
0
        private void Save(Stream stream, BitmapType type, bool withBorder, int aWidth, int aHeight, Bitmap aSrcImage)
        {
            BinaryWriter writer = new BinaryWriter(stream);
            int width = 0;
            int height = aHeight;
            if ((aWidth % 8) == 0)
            {
                width = aWidth / 8;
            }
            else
            {
                width = (aWidth / 8) + 1;
            }
            if ((width % 4) != 0)
            {
                width += 4 - (width % 4);
            }
            BMPHEADER bmpheader = new BMPHEADER();
            bmpheader.header.bfSize = bmpheader.header.bfOffBits + ((uint) (width * height));
            bmpheader.info.bmiHeader.biWidth = aWidth;
            bmpheader.info.bmiHeader.biHeight = height;
            bmpheader.info.bmiHeader.biSizeImage = (uint) (width * height);
            bmpheader.info.bmiColor1 = new RGBQUAD(this.BackColor.B, this.BackColor.G, this.BackColor.R);
            bmpheader.info.bmiColor2 = new RGBQUAD(this.ForeColor.B, this.ForeColor.G, this.ForeColor.R);
            switch (type)
            {
                case BitmapType.Bmp1:
                    bmpheader.Write(writer);
                    break;

                case BitmapType.Binary:
                case BitmapType.BinaryStrict:
                {
                    BINARYHEADER binaryheader = new BINARYHEADER();
                    binaryheader.iWidth = aWidth;
                    binaryheader.iHeight = height;
                    binaryheader.cBackground = new RGBQUAD(this.BackColor.B, this.BackColor.G, this.BackColor.R);
                    binaryheader.cForeground = new RGBQUAD(this.ForeColor.B, this.ForeColor.G, this.ForeColor.R);
                    binaryheader.Write(writer);
                    break;
                }
            }
            Graphics graphics = Graphics.FromImage(aSrcImage);
            IntPtr hdc = graphics.GetHdc();
            IntPtr ptr2 = CreateCompatibleDC(hdc);
            SelectObject(ptr2, aSrcImage.GetHbitmap());
            IntPtr ptr3 = CreateCompatibleDC(hdc);
            graphics.ReleaseHdc(hdc);
            IntPtr zero = IntPtr.Zero;
            IntPtr ptr = LocalAlloc(0x40, (uint) (bmpheader.info.bmiHeader.biSize + 8));
            Marshal.StructureToPtr(bmpheader.info.bmiHeader, ptr, false);
            new RGBQUAD(0, 0, 0).WriteToPtr(ptr, bmpheader.info.bmiHeader.biSize);
            new RGBQUAD(0xff, 0xff, 0xff).WriteToPtr(ptr, bmpheader.info.bmiHeader.biSize + 4);
            IntPtr hObj = CreateDIBSection(ptr2, ptr, 0, ref zero, IntPtr.Zero, 0);
            IntPtr ptr7 = SelectObject(ptr3, hObj);
            BitBlt(ptr3, 0, 0, bmpheader.info.bmiHeader.biWidth, bmpheader.info.bmiHeader.biHeight, ptr2, 0, 0, 0xcc0020);
            if (withBorder)
            {
                IntPtr ptr8 = CreatePen(0, this.m_IsQvga ? 1 : 2, 0xffffff);
                if ((ptr3 != IntPtr.Zero) && (ptr8 != IntPtr.Zero))
                {
                    SelectObject(ptr3, ptr8);
                }
                this.LineTo(ptr3, 0, 0, aWidth - 1, 0);
                this.LineTo(ptr3, aWidth - 1, 0, aWidth - 1, aHeight - 1);
                this.LineTo(ptr3, aWidth - 1, aHeight - 1, 0, aHeight - 1);
                this.LineTo(ptr3, 0, aHeight - 1, 0, 0);
                if (ptr8 != IntPtr.Zero)
                {
                    DeleteObject(ptr8);
                }
            }
            byte[] destination = new byte[bmpheader.info.bmiHeader.biSizeImage];
            Marshal.Copy(zero, destination, 0, (int) bmpheader.info.bmiHeader.biSizeImage);
            if (type == BitmapType.BinaryStrict)
            {
                this.SwapLines(destination, width, height);
            }
            writer.Write(destination);
            DeleteObject(SelectObject(ptr3, ptr7));
            DeleteDC(ptr3);
            DeleteDC(ptr2);
            LocalFree(ptr);
        }
Example #34
0
 public void Load(Stream stream, BitmapType type, bool setSize)
 {
     BinaryReader reader = new BinaryReader(stream);
     Stream output = stream;
     BMPHEADER bmpheader = null;
     byte[] pBits = null;
     int width = 0;
     int iWidth = 0;
     int height = 0;
     switch (type)
     {
         case BitmapType.Binary:
         case BitmapType.BinaryStrict:
         {
             BINARYHEADER binaryheader = new BINARYHEADER();
             binaryheader.Read(reader);
             width = binaryheader.iWidth;
             iWidth = binaryheader.iWidth;
             height = binaryheader.iHeight;
             if ((width % 8) != 0)
             {
                 width = (width / 8) + 1;
             }
             else
             {
                 width /= 8;
             }
             if ((width % 4) != 0)
             {
                 width += 4 - (width % 4);
             }
             this.ForeColor = Color.FromArgb(binaryheader.cForeground.rgbRed, binaryheader.cForeground.rgbGreen, binaryheader.cForeground.rgbBlue);
             this.BackColor = Color.FromArgb(binaryheader.cBackground.rgbRed, binaryheader.cBackground.rgbGreen, binaryheader.cBackground.rgbBlue);
             output = new MemoryStream();
             BinaryWriter writer = new BinaryWriter(output);
             bmpheader = new BMPHEADER();
             bmpheader.header.bfSize = bmpheader.header.bfOffBits + ((uint) (width * height));
             bmpheader.info.bmiHeader.biWidth = iWidth;
             bmpheader.info.bmiHeader.biHeight = height;
             bmpheader.info.bmiHeader.biSizeImage = (uint) (width * height);
             bmpheader.info.bmiColor1 = new RGBQUAD(this.BackColor.B, this.BackColor.G, this.BackColor.R);
             bmpheader.info.bmiColor2 = new RGBQUAD(this.ForeColor.B, this.ForeColor.G, this.ForeColor.R);
             bmpheader.Write(writer);
             long position = reader.BaseStream.Position;
             pBits = reader.ReadBytes((int) (reader.BaseStream.Length - reader.BaseStream.Position));
             if (type == BitmapType.BinaryStrict)
             {
                 this.SwapLines(pBits, width, height);
             }
             writer.Write(pBits);
             reader.BaseStream.Position = position;
             break;
         }
         default:
             bmpheader = new BMPHEADER();
             bmpheader.Read(reader);
             width = bmpheader.info.bmiHeader.biWidth;
             iWidth = bmpheader.info.bmiHeader.biWidth;
             height = bmpheader.info.bmiHeader.biHeight;
             if ((width % 8) == 0)
             {
                 width /= 8;
             }
             else
             {
                 width = (width / 8) + 1;
             }
             if ((width % 4) != 0)
             {
                 width += 4 - (width % 4);
             }
             this.BackColor = Color.FromArgb(bmpheader.info.bmiColor1.rgbRed, bmpheader.info.bmiColor1.rgbGreen, bmpheader.info.bmiColor1.rgbBlue);
             this.ForeColor = Color.FromArgb(bmpheader.info.bmiColor2.rgbRed, bmpheader.info.bmiColor2.rgbGreen, bmpheader.info.bmiColor2.rgbBlue);
             pBits = reader.ReadBytes((int) bmpheader.info.bmiHeader.biSizeImage);
             break;
     }
     if (setSize)
     {
         this.m_ImageSize.Width = iWidth;
         this.m_ImageSize.Height = height;
         if (!this.m_ImageSizeCustom)
         {
             this.Size = this.m_ImageSize;
         }
     }
     base.CreateGraphics();
     this.CreateMemoryBitmap();
     this.CreateGdiObjects();
     this.CreatePenObjects();
     Bitmap image = new Bitmap(this.ImageSize.Width, this.ImageSize.Height);
     Graphics.FromImage(image).Clear(Color.FromArgb(0xff, 0, 0xff));
     Bitmap bitmap2 = new Bitmap(output);
     ImageAttributes imageAttr = new ImageAttributes();
     imageAttr.SetColorKey(this.BackColor, this.BackColor);
     Graphics.FromImage(image).DrawImage(bitmap2, new Rectangle(0, 0, image.Width, image.Height), 0, 0, bitmap2.Width, bitmap2.Height, GraphicsUnit.Pixel, imageAttr);
     if (bitmap2 != null)
     {
         bitmap2.Dispose();
         bitmap2 = null;
     }
     this.Clear();
     IntPtr dC = GetDC(base.Handle);
     IntPtr hdc = CreateCompatibleDC(dC);
     IntPtr zero = IntPtr.Zero;
     IntPtr ptr = LocalAlloc(0x40, (uint) (bmpheader.info.bmiHeader.biSize + 8));
     Marshal.StructureToPtr(bmpheader.info.bmiHeader, ptr, false);
     Marshal.WriteInt32(ptr, bmpheader.info.bmiHeader.biSize, 0);
     Marshal.WriteInt32(ptr, bmpheader.info.bmiHeader.biSize + 4, 0xffffff);
     IntPtr hObj = CreateDIBSection(dC, ptr, 0, ref zero, IntPtr.Zero, 0);
     if ((type == BitmapType.BinaryStrict) && (pBits == null))
     {
         pBits = reader.ReadBytes((int) bmpheader.info.bmiHeader.biSizeImage);
         this.SwapLines(pBits, width, height);
     }
     Marshal.Copy(pBits, 0, zero, (int) bmpheader.info.bmiHeader.biSizeImage);
     pBits = null;
     IntPtr ptr7 = SelectObject(hdc, hObj);
     Graphics graphics = Graphics.FromImage(this.m_ImageDC);
     IntPtr hdcDest = graphics.GetHdc();
     BitBlt(hdcDest, 0, 0, bmpheader.info.bmiHeader.biWidth, bmpheader.info.bmiHeader.biHeight, hdc, 0, 0, 0xcc0020);
     DeleteObject(SelectObject(hdc, ptr7));
     DeleteDC(hdc);
     graphics.ReleaseHdc(hdcDest);
     LocalFree(ptr);
     this.m_isEmpty = false;
     if (this.m_bmp != null)
     {
         this.m_bmp.Dispose();
         this.m_bmp = null;
     }
     this.m_bmp = image;
     this.Refresh();
 }
Example #35
0
 public void Load(string filename, BitmapType type, bool setSize)
 {
     FileStream stream = new FileStream(filename, FileMode.Open);
     this.Load(stream, type, setSize);
     stream.Close();
 }
Example #36
0
 public ISO8583Message(BitmapType Type, bool secondaryBitmapPresent)
 {
     this.Bitmap = Type;
     this.isSecondaryBitmapPresent = secondaryBitmapPresent;
 }
Example #37
0
 public ISO8583Message(BitmapType Type)
 {
     this.Bitmap = Type;
 }
Example #38
0
 public void Save(string filename, BitmapType type)
 {
     FileStream stream = new FileStream(filename, FileMode.Create);
     this.Save(stream, type, false);
     stream.Close();
 }
Example #39
0
 public void Save(Stream stream, BitmapType type, bool withBorder)
 {
     this.Save(stream, type, withBorder, this.ImageSize.Width, this.ImageSize.Height, this.m_ImageDC);
 }
Example #40
0
 public void Save(string filename, BitmapType type, bool withBorder)
 {
     FileStream stream = new FileStream(filename, FileMode.Create);
     this.Save(stream, type, withBorder);
     stream.Close();
 }
Example #41
0
 public void Save(Stream stream, BitmapType type, bool withBorder, ZoomPercent aZoom)
 {
     Bitmap thumbnailBmp = GetThumbnail.GetThumbnailBmp(this.m_ImageDC, aZoom);
     this.Save(stream, type, withBorder, thumbnailBmp.Width, thumbnailBmp.Height, thumbnailBmp);
 }
Example #42
0
 internal IntPtr AllockBitmap(BitmapType type, int width, int height, uint linePadding, ref GflColor backgroundColor)
 {
     this.ThrowIfDisposed();
     if(this._AllockBitmapDelegate == null){
         this._AllockBitmapDelegate = this.LoadMethod<AllockBitmapDelegate>("gflAllockBitmap");
     }
     return this._AllockBitmapDelegate(type, width, height, linePadding, ref backgroundColor);
 }
Example #43
0
            /// <summary>
            /// Initializes a new instance of the <see cref="BitmapInfo"/> class.
            /// </summary>
            /// <param name="offset">The offset.</param>
            /// <param name="meta">The meta.</param>
            /// <remarks></remarks>
            public BitmapInfo(int offset, ref Meta meta)
            {
                BinaryReader BR = new BinaryReader(meta.MS);
                BR.BaseStream.Position = offset;
                tagtype = BR.ReadChars(4);
                width = BR.ReadUInt16();
                height = BR.ReadUInt16();
                depth = BR.ReadUInt16();
                type = BR.ReadUInt16();
                typename = (BitmapType)type;

                // case BitmapFormat.BITM_TYPE_LIGHTMAP:
                format = BR.ReadUInt16();
                formatname = (BitmapFormat)format;
                switch (formatname)
                {
                    case BitmapFormat.BITM_FORMAT_A8:
                    case BitmapFormat.BITM_FORMAT_P8:
                    case BitmapFormat.BITM_FORMAT_Y8:
                    case BitmapFormat.BITM_FORMAT_AY8:
                    case BitmapFormat.BITM_FORMAT_LIGHTMAP:
                        bitsPerPixel = 8;
                        break;
                    case BitmapFormat.BITM_FORMAT_A1R5G5B5:
                    case BitmapFormat.BITM_FORMAT_A4R4G4B4:
                    case BitmapFormat.BITM_FORMAT_A8Y8:
                    case BitmapFormat.BITM_FORMAT_R5G6B5:
                    case BitmapFormat.BITM_FORMAT_G8B8:
                  case BitmapFormat.BITM_FORMAT_UNKNOWN:
                        bitsPerPixel = 16;
                        break;
                    case BitmapFormat.BITM_FORMAT_X8R8G8B8:
                    case BitmapFormat.BITM_FORMAT_A8R8G8B8:
                    case BitmapFormat.BITM_FORMAT_DXT1:
                    case BitmapFormat.BITM_FORMAT_DXT2AND3:
                    case BitmapFormat.BITM_FORMAT_DXT4AND5:
                        bitsPerPixel = 32;
                        break;
                    default:
                        bitsPerPixel = 0;
                        break;
                }

                flags = BR.ReadUInt16();

                // if ((flags & 0x1000) == 0x1000) { swizzle = true; }
                if ((flags & 0x8) == 0x8)
                {
                    swizzle = true;
                }

                regPointX = BR.ReadUInt16();
                regPointY = BR.ReadUInt16();
                mipMapCount = BR.ReadUInt16();
                pixelOffset = BR.ReadUInt16();
            }
Example #44
0
 public Bitmap toBitmap(BitmapType type)
 {
     Bitmap bmp = new Bitmap(height, width);
     if (BitmapType.GrayScale == type)
     {
         for (int x = 0; x < O3DImage.height; x++)
         {
             for (int y = 0; y < O3DImage.width; y++)
             {
                 float dum = ((imageData[x, y] - min) / (max - min)) * 255;
                 int gray = (int)dum;
                 bmp.SetPixel(x, y, Color.FromArgb(gray, gray, gray));
             }
         }
     }
     return bmp;
 }
Example #45
0
        /// <summary>
        /// The decode bitm.
        /// </summary>
        /// <param name="bitmBytes">The bitm bytes.</param>
        /// <param name="height">The height.</param>
        /// <param name="width">The width.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="bitsPerPixel">The bits per pixel.</param>
        /// <param name="type">The type.</param>
        /// <param name="format">The format.</param>
        /// <param name="swizzle">The swizzle.</param>
        /// <param name="map">The map.</param>
        /// <param name="visualchunkindex">The visualchunkindex.</param>
        /// <param name="ident">The ident.</param>
        /// <returns></returns>
        /// <exception cref="Exception">
        ///   </exception>
        ///   
        /// <exception cref="Exception">
        ///   </exception>
        /// <remarks></remarks>
        public static Bitmap DecodeBitm(
            byte[] bitmBytes, 
            int height, 
            int width, 
            int depth, 
            int bitsPerPixel, 
            BitmapType type, 
            BitmapFormat format, 
            bool swizzle, 
            Map map, 
            int visualchunkindex, 
            int ident)
        {
            int stride = 0;

            #region Volume Textures / 3D
            if (type == BitmapType.BITM_TYPE_3D)
            {
                List<Bitmap> images = new List<Bitmap>();
                Bitmap finalImage = null;
                List<IntPtr> tPtr = new List<IntPtr>();
                if (swizzle)
                {
                    bitmBytes = Swizzler.Swizzle(bitmBytes, width, height, depth, bitsPerPixel, true);
                }

                try
                {
                    // Make our new image large enough to handle a square of all the images together with a 2 pixel pad between
                    int imageSize = width * height * bitsPerPixel >> 3;
                    int rCount = (int)(Math.Sqrt(depth) + 0.5);
                    int tWidth = rCount * (width + 1);
                    int tHeight = (int)Math.Round(depth / rCount + 0.5f, MidpointRounding.AwayFromZero) * (height + 2);

                    // Display 3D bitmaps combined as a 2D bitmap
                    if (visualchunkindex == 0)
                    {
                        for (int i = 0; i < depth; i++)
                        {
                            byte[] tempBytes = new byte[imageSize];
                            Array.Copy(bitmBytes, i * imageSize, tempBytes, 0, imageSize);

                            stride = DecodeBitmap(
                                ref tempBytes,
                                height,
                                width,
                                1,
                                bitsPerPixel,
                                type,
                                format,
                                false,
                                map,
                                visualchunkindex,
                                ident);

                            tPtr.Add(Marshal.AllocHGlobal(tempBytes.Length));
                            RtlMoveMemory(tPtr[tPtr.Count - 1], tempBytes, tempBytes.Length);
                            Bitmap bitmap = new Bitmap(
                                width, height, stride, PixelFormat.Format32bppArgb, tPtr[tPtr.Count - 1]);

                            images.Add(bitmap);
                        }
                    }
                    // Display only one of the 3D images
                    else
                    {
                        byte[] tempBytes = new byte[imageSize];
                        Array.Copy(bitmBytes, (visualchunkindex - 1) * imageSize, tempBytes, 0, imageSize);

                        stride = DecodeBitmap(
                            ref tempBytes,
                            height,
                            width,
                            1,
                            bitsPerPixel,
                            type,
                            format,
                            false,
                            map,
                            visualchunkindex,
                            ident);
                        tPtr.Add(Marshal.AllocHGlobal(tempBytes.Length));
                        RtlMoveMemory(tPtr[tPtr.Count - 1], tempBytes, tempBytes.Length);
                        images.Add(new Bitmap(width, height, stride, PixelFormat.Format32bppArgb, tPtr[tPtr.Count - 1]));
                        tWidth = width;
                        tHeight = height;
                    }

                    // create a bitmap to hold the combined image
                    finalImage = new Bitmap(tWidth, tHeight);

                    // get a graphics object from the image so we can draw on it
                    using (Graphics g = Graphics.FromImage(finalImage))
                    {
                        // set background color
                        g.Clear(Color.Empty);

                        // go through each image and draw it on the final image
                        int offset = 0;
                        foreach (Bitmap image in images)
                        {
                            g.DrawImage(
                                image,
                                new Rectangle(
                                    offset % tWidth, (offset / tWidth) * (image.Height + 1), image.Width, image.Height));
                            offset += image.Width + 1;
                        }
                    }
                    return finalImage;

                }
                catch (Exception ex)
                {
                    if (finalImage != null)
                    {
                        finalImage.Dispose();
                    }

                    throw ex;
                    //Global.ShowErrorMsg("Error loading bitmap", ex);
                }
                finally
                {
                    // clean up memory
                    foreach (Bitmap image in images)
                    {
                        image.Dispose();
                    }

                    foreach (IntPtr p in tPtr)
                    {
                        Marshal.FreeHGlobal(p);
                    }
                }
            }
            #endregion
            #region Cubemap
            else if (type == BitmapType.BITM_TYPE_CUBEMAP)
            {
                // stride = DecodeBitmap(ref bitmBytes, height, width, 1, bitsPerPixel, type, format, swizzle, map, visualchunkindex, ident);
                List<Bitmap> images = new List<Bitmap>();
                Bitmap finalImage = null;
                List<IntPtr> tPtr = new List<IntPtr>();

                // Don't think any cubemaps are swizzled, but...
                if (swizzle)
                {
                    int imageSize = bitmBytes.Length / 6; // width * height * bitsPerPixel >> 3;
                    for (int i = 0; i < 6; i++)
                    {
                        bitmBytes = Swizzler.Swizzle(bitmBytes, i * imageSize, width, height, depth, bitsPerPixel, true);
                    }
                }

                try
                {
                    // Make our new image large enough to handle a square of all the images together with a 2 pixel pad between
                    //int tWidth = 2 * (width + 2) + 10; // Add some extras..
                    int tWidth = 4 * width; // Add some extras..
                    int tHeight = 3 * height;
                    int imageSize = width * height * (bitsPerPixel >> 3);

                    // Total image size has each image (including it's mipmaps) padded to 256
                    int tImageSize = bitmBytes.Length / 6;

                    // Unused, just divide stream size by 6 as above
                    int ttImageSize = imageSize +
                                      ((imageSize / 6) % 256 == 0 ? 0 : ((256 * 6) - (imageSize % (256 * 6))));

                    // All cubemaps should be DXT1...
                    switch (format)
                    {
                        case BitmapFormat.BITM_FORMAT_DXT1:
                            imageSize = Math.Max(imageSize / 8, 8);
                            break;
                        case BitmapFormat.BITM_FORMAT_DXT2AND3:
                        case BitmapFormat.BITM_FORMAT_DXT4AND5:
                            imageSize = Math.Max(imageSize / 4, 16);
                            break;
                    }

                    //int mipmaps = 0;
                    for (int i = 0; i < 6; i++)
                    {
                        int tw = width;
                        int th = height;
                        int tempSize = imageSize;
                        int offset = 0;
                        //while (tw > 2 & th > 2)
                        {
                            byte[] tempBytes = new byte[tempSize];

                            Array.Copy(bitmBytes, i * tImageSize + offset, tempBytes, 0, tempSize);

                            stride = DecodeBitmap(
                                ref tempBytes,
                                th,
                                tw,
                                1,
                                bitsPerPixel,
                                type,
                                format,
                                false,
                                map,
                                visualchunkindex,
                                ident);

                            tPtr.Add(Marshal.AllocHGlobal(tempBytes.Length));
                            RtlMoveMemory(tPtr[tPtr.Count - 1], tempBytes, tempBytes.Length);
                            Bitmap bitmap = new Bitmap(
                                tw, th, stride, PixelFormat.Format32bppArgb, tPtr[tPtr.Count - 1]);

                            images.Add(bitmap);
                            offset += tempSize;
                            tempSize /= 4;
                            tw /= 2;
                            th /= 2;
                        }
                    }

                    // create a bitmap to hold the combined image
                    finalImage = new Bitmap(tWidth, tHeight);

                    // get a graphics object from the image so we can draw on it
                    using (Graphics g = Graphics.FromImage(finalImage))
                    {
                        // set background color
                        g.Clear(Color.Empty);

                        //
                        int[] crossX = new int[6] { 2, 0, 1, 1, 1, 3 }; // Right, Left, Top, Bottom, Front, Back
                        int[] crossY = new int[6] { 1, 1, 0, 2, 1, 1 }; // Right, Left, Top, Bottom, Front, Back
                        // go through each image and draw it on the final image
                        int xOffset = 0;
                        int yOffset = 0;
                        int tempCount = 0;
                        foreach (Bitmap image in images)
                        {
                            /*
                            if (mipmapCount == 0)
                            {
                                xOffset = 0;
                                yOffset += image.Height + 2;
                                mipmapCount = images.Count / 6;
                            }
                            */
                            xOffset = crossX[tempCount] * image.Width;
                            yOffset = crossY[tempCount] * image.Height;

                            g.DrawImage(image, new Rectangle(xOffset, yOffset, image.Width, image.Height));
                            tempCount++;
                        }
                    }

                    return finalImage;
                }
                catch (Exception ex)
                {
                    if (finalImage != null)
                    {
                        finalImage.Dispose();
                    }

                    throw ex;
                    //Global.ShowErrorMsg("Error while processing bitmap", ex);
                }
                finally
                {
                    // clean up memory
                    foreach (Bitmap image in images)
                    {
                        image.Dispose();
                    }

                    foreach (IntPtr p in tPtr)
                    {
                        Marshal.FreeHGlobal(p);
                    }
                }
            }
            #endregion
            #region 2D Textures
            else
            {
                stride = DecodeBitmap(
                    ref bitmBytes, height, width, 1, bitsPerPixel, type, format, swizzle, map, visualchunkindex, ident);
            }
            #endregion

            /*
            // This creates a memory leaks from HGlobal
            IntPtr intPtr = Marshal.AllocHGlobal(bitmBytes.Length);
            RtlMoveMemory(intPtr, bitmBytes, bitmBytes.Length);
            Bitmap temp = new Bitmap(width, height, stride, PixelFormat.Format32bppArgb, intPtr);
            temp.Tag = intPtr; // This NEEDS to be released when disposed
            */

            Bitmap temp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            Rectangle rect = new Rectangle( 0, 0, width, height);
            BitmapData data = null;
            try
            {
                data = temp.LockBits(rect, ImageLockMode.WriteOnly, temp.PixelFormat);
                System.Runtime.InteropServices.Marshal.Copy(bitmBytes, 0, data.Scan0, Math.Min(bitmBytes.Length, data.Width * data.Height * 4));
            }
            finally
            {
                if (data != null)
                    temp.UnlockBits(data);
            }
            return temp;
        }
 public void setBitmapType(BitmapType type)
 {
     this.bitmapType = type;
 }