示例#1
0
        private void Coverpath2BrowseButton_Click_1(object sender, EventArgs e)
        {
            OpenFileDialog Coverpath2Browse = new OpenFileDialog();

            Coverpath2Browse.Title       = "Browse for Cover";
            Coverpath2Browse.Filter      = "Cover File (*.tga*, *.png*, *.jpg*)|*.tga*; *.png*; *.jpg*";
            Coverpath2Browse.FilterIndex = 1;

            if (Coverpath2Browse.ShowDialog() == DialogResult.OK)
            {
                Coverpath2Textbox.Text = Coverpath2Browse.FileName;
            }


            string Preview = @Coverpath2Textbox.Text;
            string tga     = Path.GetExtension(Preview);

            if (tga == ".tga")
            {
                T = new TGA(Preview);
                ShowTga();
            }
            else
            {
                using (Bitmap original = new Bitmap(@Coverpath2Textbox.Text))
                    using (Bitmap clone = new Bitmap(original))
                        using (Bitmap newbmp = clone.Clone(new Rectangle(0, 0, clone.Width, clone.Height), PixelFormat.Format32bppArgb))
                            T = (TGA)newbmp;
                ShowTga();
            }
        }
示例#2
0
        public override unsafe void Replace(string fileName)
        {
            string ext = Path.GetExtension(fileName);
            Bitmap bmp;

            if (String.Equals(ext, ".tga", StringComparison.OrdinalIgnoreCase))
            {
                bmp = TGA.FromFile(fileName);
            }
            else if (
                String.Equals(ext, ".png", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(ext, ".tif", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(ext, ".tiff", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(ext, ".bmp", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(ext, ".jpg", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(ext, ".jpeg", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(ext, ".gif", StringComparison.OrdinalIgnoreCase))
            {
                bmp = (Bitmap)Bitmap.FromFile(fileName);
            }
            else
            {
                base.Replace(fileName);
                return;
            }

            using (Bitmap b = bmp)
                Replace(b);
        }
示例#3
0
        /// <summary>
        /// Load an image into one of AK86's classes.
        /// </summary>
        /// <param name="im">AK86 image already, just return it unless null. Then load from fileToLoad.</param>
        /// <param name="fileToLoad">Path to file to be loaded. Irrelevent if im is provided.</param>
        /// <returns>AK86 Image file.</returns>
        public static ImageFile LoadAKImageFile(ImageFile im, string fileToLoad)
        {
            ImageFile imgFile = null;

            if (im != null)
            {
                imgFile = im;
            }
            else
            {
                if (!File.Exists(fileToLoad))
                {
                    throw new FileNotFoundException("invalid file to replace: " + fileToLoad);
                }

                // check if replacing image is supported
                string fileFormat = Path.GetExtension(fileToLoad);
                switch (fileFormat)
                {
                case ".dds": imgFile = new DDS(fileToLoad, null); break;

                case ".tga": imgFile = new TGA(fileToLoad, null); break;

                default: throw new FileNotFoundException(fileFormat + " image extension not supported");
                }
            }
            return(imgFile);
        }
示例#4
0
 public static BitmapImage TgaToBitmap(TGA tga)
 {
     try
     {
         using (var tgaBitmap = tga.ToBitmap())
         {
             using (var memory = new MemoryStream())
             {
                 tgaBitmap.Save(memory, ImageFormat.Png);
                 memory.Position = 0;
                 var bitmapImage = new BitmapImage();
                 bitmapImage.BeginInit();
                 bitmapImage.StreamSource = memory;
                 bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                 bitmapImage.EndInit();
                 bitmapImage.Freeze();
                 return(bitmapImage);
             }
         }
     }
     catch (Exception e)
     {
         logger.Error(e, $"Failed to create bitmap from TGA image.");
         return(null);
     }
 }
示例#5
0
        public override unsafe void Replace(string fileName)
        {
            Bitmap bmp;

            if (fileName.EndsWith(".tga"))
            {
                bmp = TGA.FromFile(fileName);
            }
            else if (fileName.EndsWith(".png") ||
                     fileName.EndsWith(".tiff") || fileName.EndsWith(".tif") ||
                     fileName.EndsWith(".bmp") ||
                     fileName.EndsWith(".jpg") || fileName.EndsWith(".jpeg") ||
                     fileName.EndsWith(".gif"))
            {
                bmp = (Bitmap)Bitmap.FromFile(fileName);
            }
            else
            {
                base.Replace(fileName);
                return;
            }

            using (Bitmap b = bmp)
                Replace(b);
        }
示例#6
0
文件: tga.cs 项目: tsu-kunn/TGA
            /// <summary>
            /// TGAヘッダーの読み込み
            /// </summary>
            /// <param name="pSrc">画像データ</param>
            /// <param name="offset">ヘッダーまでのオフセット</param>
            /// <returns>true:読み込み成功</returns>
            public bool ReadHeader(byte[] pSrc, int offset)
            {
                if (pSrc == null)
                {
                    return(false);
                }

                int ofs = offset;

                IDField      = pSrc[ofs++];
                usePalette   = pSrc[ofs++];
                imageType    = pSrc[ofs++];
                paletteIndex = BitConverter.ToUInt16(pSrc, ofs); ofs += sizeof(ushort);
                paletteColor = BitConverter.ToUInt16(pSrc, ofs); ofs += sizeof(ushort);
                paletteBit   = pSrc[ofs++];
                imageX       = BitConverter.ToUInt16(pSrc, ofs); ofs += sizeof(ushort);
                imageY       = BitConverter.ToUInt16(pSrc, ofs); ofs += sizeof(ushort);
                imageW       = BitConverter.ToUInt16(pSrc, ofs); ofs += sizeof(ushort);
                imageH       = BitConverter.ToUInt16(pSrc, ofs); ofs += sizeof(ushort);
                imageBit     = pSrc[ofs++];
                discripter   = pSrc[ofs++];

                // DEBUG:サイズチェック
                string str = "TGAヘッダーサイズエラー" + ofs + " == " + HEADER_SIZE + "\n";

                System.Diagnostics.Debug.Assert(ofs == HEADER_SIZE, str);

                return(TGA.CheckSupport(this));
            }
        public static Bitmap getThumbnail(string path, int width = 64, int height = 64)
        {
            switch (Path.GetExtension(path).ToLower())
            {
            case ".tga":
                TGA    tga          = new TGA(path);
                Bitmap rawThumbnail = tga.GetThumbnail();
                Bitmap thumbnail    = new Bitmap(width, height);

                using (Graphics g = Graphics.FromImage(thumbnail)) {
                    g.DrawImage(rawThumbnail, 0, 0, width, height);
                    return(thumbnail);
                }

            case ".webp":
                using (WebP webp = new WebP()) {
                    return(webp.LoadThumbnail(path, width, height));
                }

            case ".emf":
                using (Metafile source = new Metafile(path)) {
                    Bitmap target = new Bitmap(width, height);
                    using (var g = Graphics.FromImage(target)) {
                        g.Clear(Color.White);
                        g.DrawImage(source, 0, 0, width, height);
                        return(target);
                    }
                }

            default:
                Image src = Image.FromFile(path);
                return((Bitmap)src.GetThumbnailImage(width, height, () => false, IntPtr.Zero));
            }
        }
        private void bgWorkBoxartUpdate_DoWork(object sender, DoWorkEventArgs e)
        {
            updateProgress(currentItem, exportBoxData.Count);
            updateProgressLabel("checking item " + (currentItem + 1) + " of " + exportBoxData.Count);

            string hash = frmMain.getGameHashCheck(exportBoxData[currentItem].fn);

            if (hash == "")
            {
                return;
            }
            string dest = Path.Combine(dir, hash + ".png");

            if (!File.Exists(dest))
            {
                updateProgressLabel("exporting " + hash + ".TGA");

                TGA   t   = new TGA(Path.Combine(exportBoxData[currentItem].fn, "BOX.TGA"));
                Image img = (Bitmap)t;
                img.Save(dest, ImageFormat.Png);
                exported++;
            }
            else
            {
                updateProgressLabel("skipped, already exists");
            }
        }
        public void ResizeImage(Bitmap image, int newWidth, int newHeight, string path)
        {
            Rectangle destRect  = new Rectangle(0, 0, newWidth, newHeight);
            Bitmap    destImage = new Bitmap(newWidth, newHeight);

            destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);

            using (var graphics = Graphics.FromImage(destImage))
            {
                graphics.CompositingMode    = CompositingMode.SourceCopy;
                graphics.CompositingQuality = CompositingQuality.HighQuality;
                graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode      = SmoothingMode.HighQuality;
                graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;

                using (var wrapMode = new ImageAttributes())
                {
                    wrapMode.SetWrapMode(WrapMode.TileFlipXY);
                    graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
                }
            }
            TGA dest = new TGA(destImage);

            dest.Save(path);
        }
示例#10
0
        public static bool ExportTexture2D(AssetItem item, string exportPathName)
        {
            var m_Texture2D = (Texture2D)item.Asset;

            if (Properties.Settings.Default.convertTexture)
            {
                var bitmap = m_Texture2D.ConvertToBitmap(true);
                if (bitmap == null)
                {
                    return(false);
                }
                ImageFormat format = null;
                var         ext    = Properties.Settings.Default.convertType;
                bool        tga    = false;
                switch (ext)
                {
                case "BMP":
                    format = ImageFormat.Bmp;
                    break;

                case "PNG":
                    format = ImageFormat.Png;
                    break;

                case "JPEG":
                    format = ImageFormat.Jpeg;
                    break;

                case "TGA":
                    tga = true;
                    break;
                }
                var exportFullName = GetExportFullName(exportPathName, item.Text, "." + ext.ToLower());
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                if (tga)
                {
                    var file = new TGA(bitmap);
                    file.Save(exportFullName);
                }
                else
                {
                    bitmap.Save(exportFullName, format);
                }
                bitmap.Dispose();
                return(true);
            }
            else
            {
                var exportFullName = GetExportFullName(exportPathName, item.Text, ".tex");
                if (ExportFileExists(exportFullName))
                {
                    return(false);
                }
                File.WriteAllBytes(exportFullName, m_Texture2D.image_data.GetData());
                return(true);
            }
        }
示例#11
0
 public void extractFiles(string archievedFile, string relativePath, string OutputPath, int scaling)
 {
     foreach (ZipArchiveEntry entry in zipfile.Entries)
     {
         if (entry.FullName.StartsWith(archievedFile))
         {
             string path = OutputPath + entry.FullName.Replace(relativePath, "");
             Directory.CreateDirectory(Path.GetDirectoryName(path));
             entry.ExtractToFile(path, true);
             if (Path.GetExtension(path).Contains("tga"))
             {
                 bool skip = false;
                 foreach (string excludePath in excludeResizePaths)
                 {
                     if (path.Contains(excludePath))
                     {
                         skip = true;
                     }
                 }
                 if (!skip)
                 {
                     int         multiplier = scaling;
                     TGA         image      = new TGA(path);
                     ImageScaler scaler     = new ImageScalerImpl();
                     scaler.ResizeImage(image.ToBitmap(), image.Width * multiplier, image.Height * multiplier, path);
                 }
             }
         }
     }
 }
示例#12
0
        public void Export(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            byte[] buffer = null;
            switch (m_TextureFormat)
            {
            case TextureFormat.DXT1:
            case TextureFormat.DXT5:
                byte[] dds_header = DDS.CreateHeader(m_Width, m_Height, 32, m_MipMap ? 2 : 0, m_TextureFormat);
                writer.Write(dds_header);
                buffer = image_data;
                break;

            case TextureFormat.RGB24:
                byte[] tga_header = TGA.CreateHeader((ushort)m_Width, (ushort)m_Height, 24);
                writer.Write(tga_header);
                buffer = new byte[image_data.Length];
                for (int i = 0, j = 2; j < m_CompleteImageSize; i += 3, j += 3)
                {
                    byte b = image_data[j];
                    buffer[j]     = image_data[i];
                    buffer[i]     = b;
                    buffer[i + 1] = image_data[i + 1];
                }
                break;

            case TextureFormat.ARGB32:
                tga_header = TGA.CreateHeader((ushort)m_Width, (ushort)m_Height, 32);
                writer.Write(tga_header);
                buffer = new byte[image_data.Length];
                for (int i = 0, j = 3, k = 1, l = 2; j < m_CompleteImageSize; i += 4, j += 4, k += 4, l += 4)
                {
                    byte b = image_data[j];
                    buffer[j] = image_data[i];
                    buffer[i] = b;
                    b         = image_data[l];
                    buffer[l] = image_data[k];
                    buffer[k] = b;
                }
                break;

            case TextureFormat.Alpha8:
                tga_header = TGA.CreateHeader((ushort)m_Width, (ushort)m_Height, 8);
                writer.Write(tga_header);
                buffer = (byte[])image_data.Clone();
                break;

            case TextureFormat.RGBA32:
                tga_header = TGA.CreateHeader((ushort)m_Width, (ushort)m_Height, 32);
                writer.Write(tga_header);
                buffer = (byte[])image_data.Clone();
                break;

            default:
                throw new Exception("Unhandled Texture2D format: " + m_TextureFormat);
            }
            writer.Write(buffer);
        }
示例#13
0
        public void extractImage(ImageInfo imgInfo, string archiveDir = null, string fileName = null)
        {
            ImageFile imgFile;

            if (fileName == null)
            {
                fileName = texName + "_" + imgInfo.imgSize + getFileFormat();
            }

            byte[] imgBuffer;

            switch (imgInfo.storageType)
            {
            case storage.pccSto:
                imgBuffer = new byte[imgInfo.uncSize];
                Buffer.BlockCopy(imageData, imgInfo.offset, imgBuffer, 0, imgInfo.uncSize);
                break;

            case storage.arcCpr:
            case storage.arcUnc:
                string archivePath = archiveDir + "\\" + arcName + ".tfc";
                if (!File.Exists(archivePath))
                {
                    throw new FileNotFoundException("Texture archive not found in " + archivePath);
                }

                using (FileStream archiveStream = File.OpenRead(archivePath))
                {
                    archiveStream.Seek(imgInfo.offset, SeekOrigin.Begin);
                    if (imgInfo.storageType == storage.arcCpr)
                    {
                        imgBuffer = ZBlock.Decompress(archiveStream, imgInfo.cprSize);
                    }
                    else
                    {
                        imgBuffer = new byte[imgInfo.uncSize];
                        archiveStream.Read(imgBuffer, 0, imgBuffer.Length);
                    }
                }
                break;

            default:
                throw new FormatException("Unsupported texture storage type");
            }

            if (getFileFormat() == ".dds")
            {
                imgFile = new DDS(fileName, imgInfo.imgSize, texFormat, imgBuffer);
            }
            else
            {
                imgFile = new TGA(fileName, imgInfo.imgSize, texFormat, imgBuffer);
            }

            byte[] saveImg = imgFile.ToArray();
            using (FileStream outputImg = new FileStream(imgFile.fileName, FileMode.Create, FileAccess.Write))
                outputImg.Write(saveImg, 0, saveImg.Length);
        }
示例#14
0
 private void Form1_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(DataFormats.FileDrop) && e.Effect == DragDropEffects.Move)
     {
         string[] Files = (string[])e.Data.GetData(DataFormats.FileDrop);
         T = TGA.FromFile(Files[0]);
         ShowTga();
     }
 }
示例#15
0
        private void buttonTryConvert_Click(object sender, EventArgs e)
        {
            if (T == null)
            {
                return;
            }

            T = (TGA)((Bitmap)T);
            ShowTga();
        }
        public static bool ExportSprite(AssetItem item, string exportPath)
        {
            ImageFormat format = null;
            var         type   = Properties.Settings.Default.convertType;
            var         tga    = false;

            switch (type)
            {
            case "BMP":
                format = ImageFormat.Bmp;
                break;

            case "PNG":
                format = ImageFormat.Png;
                break;

            case "JPEG":
                format = ImageFormat.Jpeg;
                break;

            case "TGA":
                tga = true;
                break;
            }

            if (!TryExportFile(exportPath, item, "." + type.ToLower(), out var exportFullPath))
            {
                return(false);
            }
            var bitmap = ((Sprite)item.Asset).GetImage();

            if (bitmap == null)
            {
                return(false);
            }
            if (tga)
            {
                var file = new TGA(bitmap);
                file.Save(exportFullPath);
            }
            else
            {
                try
                {
                    bitmap.Save(exportFullPath, format);
                    bitmap.Dispose();
                }
                catch (ExternalException)
                {
                    return(ExportSprite(item, exportPath));
                }
            }

            return(true);
        }
示例#17
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string TgaFile = Files[listBox1.SelectedIndex];

            if (File.Exists(TgaFile))
            {
                T = new TGA(TgaFile);
                //T.UpdatePostageStampImage();
                ShowTga();
            }
        }
示例#18
0
        //rgb-"jghsdfag.sdf":a
        private static Pipe LoadPipe(string pipeString)
        {
            int hyphenIndex = pipeString.IndexOf('-');
            int colonIndex  = pipeString.IndexOf(':');

            string outputChannelsStr = pipeString.Substring(0, hyphenIndex);
            string path             = pipeString.Substring(hyphenIndex + 1, colonIndex - hyphenIndex - 1).Replace("\"", string.Empty);
            string inputChannelsStr = pipeString.Substring(colonIndex + 1, pipeString.Length - colonIndex - 1);

            Bitmap bitmap = (Bitmap)TGA.FromFile(path);

            return(new Pipe(ParseChannels(inputChannelsStr), ParseChannels(outputChannelsStr), bitmap));
        }
示例#19
0
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Escape)
     {
         this.Close();
     }
     else if (e.KeyCode == Keys.F1)
     {
         if (T != null)
         {
             T = TGA.FromBytes(T.ToBytes());
             ShowTga();
         }
     }
 }
示例#20
0
        public static bool ExportSprite(AssetItem item, string exportPath)
        {
            ImageFormat format = null;
            var         type   = Properties.Settings.Default.convertType;
            bool        tga    = false;

            switch (type)
            {
            case "BMP":
                format = ImageFormat.Bmp;
                break;

            case "PNG":
                format = ImageFormat.Png;
                break;

            case "JPEG":
                format = ImageFormat.Jpeg;
                break;

            case "TGA":
                tga = true;
                break;
            }
            var exportFullName = GetExportFullName(exportPath, item.Text, "." + type.ToLower());

            if (ExportFileExists(exportFullName))
            {
                return(false);
            }
            var bitmap = ((Sprite)item.Asset).GetImage();

            if (bitmap != null)
            {
                if (tga)
                {
                    var file = new TGA(bitmap);
                    file.Save(exportFullName);
                }
                else
                {
                    bitmap.Save(exportFullName, format);
                }
                bitmap.Dispose();
                return(true);
            }
            return(false);
        }
示例#21
0
        public static TGA LoadTGA32(string path)
        {
            TGA tga = new TGA();

            try
            {
                using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader binaryReader = new BinaryReader(fileStream))
                    {
                        tga.tgaHeader.idLength     = binaryReader.ReadByte();
                        tga.tgaHeader.colorMapType = binaryReader.ReadByte();
                        tga.tgaHeader.imageType    = binaryReader.ReadByte();
                        tga.tgaHeader.colorMapSpecification.firstEntryIndex   = binaryReader.ReadUInt16();
                        tga.tgaHeader.colorMapSpecification.colorMapLength    = binaryReader.ReadUInt16();
                        tga.tgaHeader.colorMapSpecification.colorMapEntrySize = binaryReader.ReadByte();
                        tga.tgaHeader.imageSpecification.imageXOrigin         = binaryReader.ReadUInt16();
                        tga.tgaHeader.imageSpecification.imageYOrigin         = binaryReader.ReadUInt16();
                        tga.tgaHeader.imageSpecification.imageWidth           = binaryReader.ReadUInt16();
                        tga.tgaHeader.imageSpecification.imageHeight          = binaryReader.ReadUInt16();
                        tga.tgaHeader.imageSpecification.pixelDepth           = binaryReader.ReadByte();
                        tga.tgaHeader.imageSpecification.imageDescriptor      = binaryReader.ReadByte();

                        if (tga.tgaHeader.idLength != 0 || tga.tgaHeader.colorMapType != 0 || tga.tgaHeader.imageType != 2 ||
                            tga.tgaHeader.imageSpecification.pixelDepth != 32)
                        {
                            MessageBox.Show("Source file is not an uncompressed Targa 32bpp (alpha channel) file");
                        }

                        int width  = Convert.ToInt32(tga.tgaHeader.imageSpecification.imageWidth);
                        int height = Convert.ToInt32(tga.tgaHeader.imageSpecification.imageHeight);

                        tga.fileData = binaryReader.ReadBytes(width * height * 4);
                        tga.tgaFooter.extensionAreaOffset      = binaryReader.ReadUInt64();
                        tga.tgaFooter.developerDirectoryOffset = binaryReader.ReadUInt64();
                        tga.tgaFooter.signature                  = binaryReader.ReadChars(16);
                        tga.tgaFooter.asciiCharacter             = binaryReader.ReadChar();
                        tga.tgaFooter.binaryZeroStringTerminator = binaryReader.ReadByte();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(tga);
        }
示例#22
0
        public static BitmapImage TgaToBitmap(TGA tga)
        {
            var tgaBitmap = tga.ToBitmap();

            using (var memory = new MemoryStream())
            {
                tgaBitmap.Save(memory, ImageFormat.Png);
                memory.Position = 0;
                var bitmapImage = new BitmapImage();
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
                bitmapImage.Freeze();
                return(bitmapImage);
            }
        }
示例#23
0
        private static bool ExportBitmap(AssetItem item, string exportPath, System.Drawing.Bitmap bitmap, string postfix = "")
        {
            if (bitmap == null)
            {
                return(false);
            }
            ImageFormat format = null;
            var         ext    = Properties.Settings.Default.convertType;
            bool        tga    = false;

            switch (ext)
            {
            case "BMP":
                format = ImageFormat.Bmp;
                break;

            case "PNG":
                format = ImageFormat.Png;
                break;

            case "JPEG":
                format = ImageFormat.Jpeg;
                break;

            case "TGA":
                tga = true;
                break;
            }
            if (!TryExportFile(exportPath, item, postfix + "." + ext.ToLower(), out var exportFullPath))
            {
                return(false);
            }
            if (tga)
            {
                var file = new TGA(bitmap);
                file.Save(exportFullPath);
            }
            else
            {
                bitmap.Save(exportFullPath, format);
            }
            bitmap.Dispose();
            return(true);
        }
示例#24
0
        static string vtf2png(string vtf)
        {
            string matname = Path.GetFileNameWithoutExtension(vtf.Split("/").Last());
            string png     = $"tmp\\{matname}.png";

            if (File.Exists(png))
            {
                return(png);
            }
            try
            {
                string tga = vtf2tga(vtf);
                Bitmap bmp = new TGA(tga).ToBitmap();
                bmp.Save(png, ImageFormat.Png);
                File.Delete(tga);
            }
            catch { }
            return(png);
        }
示例#25
0
    void SmkFrameReady(byte[] pixelBuffer, byte[] palette,
                       byte[][] audioBuffers)
    {
        Console.WriteLine("SmkFrameReady");
        frame_count++;
        byte[] pixbuf_data = new byte[pixelBuffer.Length * 3];

        for (int i = 0; i < pixelBuffer.Length; i++)
        {
            Array.Copy(palette, pixelBuffer[i] * 3, pixbuf_data, i * 3, 3);
        }

        current_frame = new Gdk.Pixbuf(pixbuf_data,
                                       Colorspace.Rgb,
                                       false,
                                       8,
                                       (int)smk.PaddedWidth, (int)smk.Height,
                                       (int)smk.PaddedWidth * 3,
                                       null);

        TGA.WriteTGA(String.Format("frame{0:0000}.tga", frame_count),
                     pixbuf_data, smk.PaddedWidth, smk.PaddedHeight);

        if (audioFiles == null)
        {
            audioFiles        = new FileStream[7];
            dataChunkPosition = new uint[7];
        }

        for (int ch = 0; ch < 7; ch++)
        {
            if (audioBuffers[ch] != null)
            {
                if (audioFiles[ch] == null)
                {
                    StartupAudio(ch);
                }

                audioFiles[ch].Write(audioBuffers[ch], 0, audioBuffers[ch].Length);
            }
        }
    }
示例#26
0
        public void Replace()
        {
            TEX0Node tNode = Node as TEX0Node;

            string path;
            Bitmap bmp = null;

            switch (Program.OpenFile(Filters.TextureReplaceFilter, out path))
            {
            case 2:
            case 4:
            case 5:
            case 6:
            case 7:
                bmp = Bitmap.FromFile(path) as Bitmap; break;

            case 3:
                bmp = TGA.FromFile(path); break;

            case 8:
                tNode.Replace(path); return;

            default: return;
            }

            try
            {
                //if ((bmp.Width != tNode.Width) || (bmp.Height != tNode.Height))
                //    MessageBox.Show(String.Format("Texture size does not match original! ({0} x {1})", tNode.Width, tNode.Height));
                //else
                tNode.Replace(bmp);

                //automatically replace multiple nodes
                //if (_nodePath.Contains("Type1[90]/Textures(NW4R)/InfStc."))
                //{
                //    string id = _nodePath.Substring(_nodePath.LastIndexOf('.'));
                //    ResourceNode node = ResourceCache.FindNode("stage\\melee\\STGRESULT.PAC", "2/Type1[120]/Textures(NW4R)/InfStc" + id);
                //    ((TEX0Node)node).Replace(bmp);
                //}
            }
            finally { bmp.Dispose(); }
        }
示例#27
0
        private void ConvertTexture2D(Texture2D m_Texture2D, string name)
        {
            var iTex = ImportedHelpers.FindTexture(name, TextureList);

            if (iTex != null)
            {
                return;
            }

            var bitmap = m_Texture2D.ConvertToBitmap(true);

            if (bitmap != null)
            {
                using (var stream = new MemoryStream())
                {
                    switch (imageFormat)
                    {
                    case "BMP":
                        bitmap.Save(stream, ImageFormat.Bmp);
                        break;

                    case "PNG":
                        bitmap.Save(stream, ImageFormat.Png);
                        break;

                    case "JPEG":
                        bitmap.Save(stream, ImageFormat.Jpeg);
                        break;

                    case "TGA":
                        var tga = new TGA(bitmap);
                        tga.Save(stream);
                        break;
                    }
                    iTex = new ImportedTexture(stream, name);
                    TextureList.Add(iTex);
                    bitmap.Dispose();
                }
            }
        }
示例#28
0
        private Bitmap SearchDirectory(string path)
        {
            Bitmap bmp = null;

            if (!String.IsNullOrEmpty(path))
            {
                DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path));
                if (dir.Exists && Name != "<null>")
                {
                    foreach (FileInfo file in dir.GetFiles(Name + ".*"))
                    {
                        if (File.Exists(file.FullName))
                        {
                            if (file.Name.EndsWith(".tga"))
                            {
                                Source = file.FullName;
                                bmp    = TGA.FromFile(file.FullName);
                                break;
                            }
                            else if (
                                file.Name.EndsWith(".png") ||
                                file.Name.EndsWith(".tiff") ||
                                file.Name.EndsWith(".tif") ||
                                file.Name.EndsWith(".jpg") ||
                                file.Name.EndsWith(".jpeg") ||
                                file.Name.EndsWith(".bmp") ||
                                file.Name.EndsWith(".gif"))
                            {
                                Source = file.FullName;
                                bmp    = CopyImage(file.FullName);
                                break;
                            }
                        }
                    }
                }
            }
            return(bmp);
        }
示例#29
0
        private bool LoadImages(string path)
        {
            DisposeImages();

            if (path.EndsWith(".tga"))
            {
                _source = TGA.FromFile(path);
            }
            else
            {
                _source = (Bitmap)Bitmap.FromFile(path);
            }

            //if (_source.PixelFormat != PixelFormat.Format32bppArgb)
            //    using (Bitmap bmp = _source)
            //        _source = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), PixelFormat.Format32bppArgb);

            //_source.SetResolution(96.0f, 96.0f);
            _preview = new Bitmap(_source.Width, _source.Height, PixelFormat.Format32bppArgb);

            txtPath.Text = path;
            lblSize.Text = String.Format("{0} x {1}", _source.Width, _source.Height);

            _colorInfo             = _source.GetColorInformation();
            lblColors.Text         = _colorInfo.ColorCount.ToString();
            lblTransparencies.Text = _colorInfo.AlphaColors.ToString();

            //Get max LOD
            int maxLOD = 1;

            for (int w = _source.Width, h = _source.Height; (w != 1) && (h != 1); w >>= 1, h >>= 1, maxLOD++)
            {
                ;
            }
            numLOD.Maximum = maxLOD;

            return(true);
        }
示例#30
0
        /// <summary>
        /// Converts a byte array of a VTF file into a bitmap var
        /// </summary>
        /// <param name="vtf">The byte array read from a VTF</param>
        /// <param name="launcher">An instance of the Source SDK lib</param>
        /// <returns></returns>
        public static Bitmap ToBitmap(byte[] vtf, Launcher launcher)
        {
            if (vtf == null || vtf.Length == 0 || launcher == null)
            {
                return(null);
            }

            string gamePath = launcher.GetCurrentGame().installPath;
            string modPath  = launcher.GetCurrentMod().installPath;
            string filePath = modPath + "\\materials";

            string vtf2tgaPath = gamePath + "\\bin\\vtf2tga.exe";

            Directory.CreateDirectory(filePath);
            File.WriteAllBytes(filePath + "\\temp.vtf", vtf);

            Process process = new Process();

            process.StartInfo.FileName         = vtf2tgaPath;
            process.StartInfo.Arguments        = "-i temp -o temp";
            process.StartInfo.WorkingDirectory = filePath;
            process.StartInfo.WindowStyle      = System.Diagnostics.ProcessWindowStyle.Hidden;
            process.Start();
            process.WaitForExit();

            if (!File.Exists(filePath + "\\temp.tga"))
            {
                return(null);
            }

            Bitmap src = TGA.FromFile(filePath + "\\temp.tga").ToBitmap();

            File.Delete(filePath + "\\temp.tga");
            File.Delete(filePath + "\\temp.vtf");

            return(src);
        }