Beispiel #1
0
        internal PCMStream(short *source, int samples, int sampleRate, int channels, int bps)
        {
            _sourceMap = null;

            _bps         = bps; //16
            _numChannels = channels;
            _frequency   = sampleRate;
            _numSamples  = samples;

            _source    = source;
            _samplePos = 0;
        }
Beispiel #2
0
 public void Dispose()
 {
     if (_sourceMap != null)
     {
         _sourceMap.Dispose();
         _sourceMap = null;
     }
     if (_allocatedHGlobal != IntPtr.Zero)
     {
         Marshal.FreeHGlobal(_allocatedHGlobal);
         _allocatedHGlobal = IntPtr.Zero;
     }
     GC.SuppressFinalize(this);
 }
        /// <summary>
        /// Replace the MenSelmapMark texture in toReplace with the image in newBitmap, flipping the channels if the image has solid black in all four corners.
        /// </summary>
        /// <param name="newBitmap">The new texture to use</param>
        /// <param name="toReplace">The TEX0 to insert the texture in</param>
        /// <param name="createNew">If true, the format of the existing texture will not be used as a fallback, even if useExistingAsFallback is true</param>
        private void ReplaceSelmapMark(Bitmap newBitmap, TEX0Node toReplace, bool createNew)
        {
            WiiPixelFormat format =
                selmapMarkFormat != null
                                        ? selmapMarkFormat.Value
                                : useExistingAsFallback && !createNew
                                        ? toReplace.Format
                                : BitmapUtilities.HasAlpha(newBitmap)
                                        ? WiiPixelFormat.IA4
                                        : WiiPixelFormat.I4;

            Console.WriteLine(format);
            Bitmap toEncode = BitmapUtilities.HasSolidCorners(newBitmap) ? BitmapUtilities.AlphaSwap(newBitmap) : newBitmap;

            BrawlLib.IO.FileMap tMap = TextureConverter.Get(format).EncodeTEX0Texture(toEncode, 1);
            toReplace.ReplaceRaw(tMap);
        }
        public void Replace(string filename, bool useTextureConverter)
        {
            if (Texture == null)
            {
                return;
            }

            var ig = StringComparison.CurrentCultureIgnoreCase;

            if (filename.EndsWith(".tex0", ig) || filename.EndsWith(".brres", ig))
            {
                using (ResourceNode node = NodeFactory.FromFile(null, filename)) {
                    TEX0Node tex0;
                    if (node is TEX0Node)
                    {
                        tex0 = (TEX0Node)node;
                    }
                    else
                    {
                        tex0 = (TEX0Node)node.FindChild("Textures(NW4R)", false).Children[0];
                    }
                    string tempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
                    tex0.Export(tempFile);
                    Replace(tempFile, useTextureConverter);                     // call self with new file
                    File.Delete(tempFile);
                }
            }
            else
            {
                if (useTextureConverter)
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog()) {
                        dlg.ImageSource = filename;
                        if (dlg.ShowDialog(null, Texture) == DialogResult.OK)
                        {
                            if (OnUpdate != null)
                            {
                                OnUpdate(this);
                            }
                        }
                    }
                }
                else
                {
                    if (Texture.Format == WiiPixelFormat.CMPR)
                    {
                        Bitmap              bitmap      = new Bitmap(filename);
                        UnsafeBuffer        buffer      = TextureConverter.CMPR.GeneratePreview(bitmap);
                        BrawlLib.IO.FileMap textureData = TextureConverter.CMPR.EncodeTEX0TextureCached(bitmap, Texture.LevelOfDetail, buffer);
                        Texture.ReplaceRaw(textureData);
                    }
                    else
                    {
                        Texture.Replace(filename);
                    }
                    if (OnUpdate != null)
                    {
                        OnUpdate(this);
                    }
                }
            }
        }