Exemple #1
0
        /// <summary>
        /// Generates a preview of this texture.
        /// </summary>
        /// <returns>Preview image of the texture.</returns>
        public Bitmap GetBitmap()
        {
            if (m_flags != 0x02)
            {
                return(null);
            }

            Bitmap bmp = new Bitmap((int)m_width, (int)m_height, PixelFormat.Format8bppIndexed);

            try
            {
                // determine the palette id
                uint paletteId;
                if (m_overridePaletteId.HasValue)
                {
                    paletteId = m_overridePaletteId.Value;
                }
                else
                {
                    paletteId = m_defaultPalette;
                }

                // load the palette
                ACPalette palette = PaletteLoader.Instance.LoadPalette(paletteId);
                bmp.Palette = palette.GetPaletteForPreviewImage(bmp.Palette);

                m_sourceFile.PrepareFileForReading();
                m_sourceFile.Skip(16);                  // skip header
                byte[] textureData = m_sourceFile.ReadBytes((int)(m_width * m_height));

                BitmapData bmpData = null;
                try
                {
                    bmpData = bmp.LockBits(new Rectangle(0, 0, (int)m_width, (int)m_height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
                    Marshal.Copy(textureData, 0, bmpData.Scan0, textureData.Length);
                }
                finally
                {
                    if (bmpData != null)
                    {
                        bmp.UnlockBits(bmpData);
                    }
                }

                return(bmp);
            }
            catch (Exception)
            {
                bmp.Dispose();
                throw;
            }
            finally
            {
                m_sourceFile.FileReadingComplete();
            }
        }
Exemple #2
0
        public ACPalette LoadPalette(uint id)
        {
            EmbeddedFile file = LoadPaletteFile(id);

            if (file == null)
            {
                return(null);
            }
            ACPalette palette = new ACPalette(file);

            palette.ReadPalette();
            return(palette);
        }
        private void lbTextureList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbTextureList.SelectedIndex >= 0)
            {
                uint fileId = ((EmbeddedFileEntry)lbTextureList.SelectedItem).FileID;

                if ((fileId & 0xFF000000) == 0x04000000)
                {
                    ACPalette palette = PaletteLoader.Instance.LoadPalette(fileId);
                    SetPreviewBitmap(palette.GetPreviewBitmap());
                }
                else if ((fileId & 0xFF000000) == 0x05000000)
                {
                    ACTexture texture = TextureLoader.Instance.LoadTexture(fileId);
                    if (cbAlphaMap.Checked)
                    {
                        SetPreviewBitmap(ConvertToAlphaMap(texture.GetBitmap()));
                    }
                    else
                    {
                        SetPreviewBitmap(texture.GetBitmap());
                    }
                }
                else if ((fileId & 0xFF000000) == 0x08000000)
                {
                    MeshDecoration decoration = new MeshDecoration(fileId);
                    Bitmap         bmp        = new Bitmap(pbPreview.Width, pbPreview.Height, PixelFormat.Format24bppRgb);
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        g.Clear(Color.White);
                        int  height = 10;
                        Font font   = new Font("Tahoma", height);
                        g.DrawString(String.Format("Decoration 0x{0:X8}", fileId), font, Brushes.Black, 5, 5 + (0 * height));
                        if (decoration.DecorationType == DecorationType.Texture)
                        {
                            g.DrawString(String.Format("Texture, texture id: 0x{0:X8}", decoration.Texture.ID), font, Brushes.Black, 5, 5 + (1 * height));
                        }
                        else if (decoration.DecorationType == DecorationType.SolidColor)
                        {
                            g.DrawString(String.Format("Solid, color: 0x{0:X8}", decoration.SolidColor.ToArgb()), font, Brushes.Black, 5, 5 + (1 * height));
                        }
                        else if (decoration.DecorationType == DecorationType.Unknown)
                        {
                            g.DrawString(String.Format("Unknown decoration type."), font, Brushes.Black, 5, 5 + (1 * height));
                        }
                        g.DrawString(String.Format("Type flag: {0:X}", decoration.TypeFlag), font, Brushes.Black, 5, 5 + (2 * height));
                    }
                    SetPreviewBitmap(bmp);
                }
            }
        }