working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,167 snippets matching: decode

    public by Geometry modified Jul 31, 2016  87282  0  4  0

    Allows to DecodeUInt64

    using System;
    using System.Text;
    
    public static unsafe ulong DecodeUInt64(byte[] buffer, int offset)
    {
    	fixed (byte* ptr = buffer)
    	{
    		return DecodeUInt64(ptr, offset);
    	}
    }

    public by Geometry modified Aug 7, 2016  680  0  5  0

    DecodeFromFile: Decode first frame for the specified file.

    Decode first frame for the specified file. File name to read image from. Return decoded image. In the case if file format support multiple frames, the method return the first frame. The method uses table of registered image decoders to find the one, which should be used for the specified file. If there is not appropriate decoder fo
    static ImageDecoder()
            {
                // register PNM file format
                IImageDecoder decoder = new PNMCodec();
    
                RegisterDecoder("pbm", decoder);
                RegisterDecoder("pgm", decoder);
                RegisterDecoder("pnm", decoder);
                RegisterDecoder("ppm", decoder);
    
                // register FITS file format
                decoder = new FITSCodec();
    
                RegisterDecoder("fit", decoder);
                RegisterDecoder("fits", decoder);
            }
    
    /// <summary>
    /// Decode first frame for the specified file.
    /// </summary>
    /// 
    /// <param name="fileName">File name to read image from.</param>
    /// 
    /// <returns>Return decoded image. In the case if file format support multiple
    /// frames, the method return the first frame.</returns>
    /// 
    /// <remarks><para>The method uses table of registered image decoders to find the one,
    /// which should be used for the specified file. If there is not appropriate decoder
    /// found, the method uses default .NET's image decoding routine (see
    /// <see cref="System.Drawing.Image.FromFile( string )"/>).</para></remarks>
    /// 
    public static Bitmap DecodeFromFile(string fileName)
    {
        ImageInfo imageInfo = null;
    
        return DecodeFromFile(fileName, out imageInfo);
    }

    public by sTiLL-iLL @ SniPitz-KND modified Dec 19, 2014  3879  2  8  28

    .mP3 aUDiO viSUaliZatioN with CANVAS

    sounds dangerous!
    // quick visualization experimentation
    
    <div class="container">
    	
    	<div>
    		<canvas id="canvas" width="124" height="220" style="display: block;"></canvas>
    		<p>
    		  <button id="playBtn">
    		    <span>Play<span></span></span>
    		  </button>
    		</p>
    	</div>
    	
    	<div>
    		<div>
    			<img src="/someImg.jpg"/>
    		</div>
    	</div>
    </div>
    
    <script>
    	if (!window.AudioContext) {
    	  
    		if (!window.webkitAudioContext) {
    			alert('not supported');
    		}
    		
    		window.AudioContext = window.webkitAudioContext;
    	}
    	
    	var cntxt = new AudioContext(),
    		srchr, srchr2,
    	  srcNode, toknzr,
        aBuffer, jsNode,
    	  ctx = $("#canvas").get()[0].getContext("2d");
    
    	var grdt = ctx.createLinearGradient(0,0,0,130);
    	grdt.addColorStop(1,'#000000');
    	grdt.addColorStop(0.75,'#ff0000');
    	grdt.addColorStop(0.25,'#ffff00');
    	grdt.addColorStop(0,'#ffffff');
    
    	setNodes();
    	load("/someSounds.mp3");
    
    	function setNodes() {
    		jsNode = cntxt.createScriptProcessor(2048, 1, 1);
    		jsNode.connect(context.destination);
    		
    		srchr = cntxt.createsrchr();
    	  srchr.smoothingTimeConstant = 0.3;
    		srchr.fftSize = 1024;
    		
    		srchr2 = cntxt.createsrchr();
    		srchr2.smoothingTimeConstant = 0.0;
    		srchr2.fftSize = 1024;
    		
    		srcNode = cntxt.createBufferSource();
    		toknzr = cntxt.createChannelSplitter();
    		srcNode.connect(toknzr);
    		
    		toknzr.connect(srchr,0,0);
    		toknzr.connect(srchr2,1,0);
    		
    		srchr.connect(jsNode);
    		srcNode.connect(cntxt.destination);
    	}
    
    	function load(url) {
    		var req = new XMLHttpRequest();
    		req.open('GET', url, true);
    		req.responseType = 'arraybuffer';
    		
    		req.onload = function() {
    			cntxt.decodeAudioData(req.response, function(bfr) {
    				play(bfr);
    			}, wenError);
    		}
    		req.send({});
    	}
    	
    	function play(buffer) {
    		srcNode.buffer = bfr;
    	}
    	
    	function wenError(err) {
    		console.log(err);
    	}
    	
    	jsNode.onaudioprocess = function() {
    		var ary = new Uint8Array(srchr.frequencyBinCount);
    		srchr.getByteFrequencyData(ary);
    		
    		var avg = medianVolume(ary),
    		    ary2 = new Uint8Array(srchr2.frequencyBinCount);
    		
    		srchr2.getByteFrequencyData(ary2);
    		var avg2 = medianVolume(ary2);
    		
    		ctx.clearRect(0, 0, 60, 130);
    		ctx.fillStyle=gradient;
    		ctx.fillRect(0,130-avg,25,130);
    		ctx.fillRect(30,130-avg2,25,130);
    	}
    	
    	function medianVolume(array) {
    		var vals = 0, i = 0,
      		  len = ary.length,
      		  avg;
    		for (;i<len;i++) {
    			vals+=ary[i];
    		}
    		avg=vals/len;
    		return avg;
    	}
    	
    	$(document).ready(function() {
    		$('#playBtn').click(function(evt){
    			evt.preventDefault();
    			srcNode.start(0);
    		});
    	});
    	
    </script>            

    public by FMXExpress modified Nov 12, 2014  4142  16  6  1

    Decode GZIP Content From TRESTClient In Delphi XE7 Firemonkey

    RESTClient.AcceptEncoding := 'gzip, deflate';
    RESTClient.Execute;
    
    if RESTResponse.ContentEncoding=’gzip’ then
    DecodeGZIPContent(RESTResponse.RawBytes) // decode and do something with the content
    else
    RESTResponse.Content; // do something with the content
    
    function DecodeGZIPContent(RawBytes: System.TArray<System.Byte>): String;
    var
    MSI: TMemoryStream;
    MSO: TStringStream;
    begin
    MSI := TMemoryStream.Create;
    MSO := TStringStream.Create;
    MSI.WriteData(RawBytes,Length(RawBytes));
    MSI.Seek(0,0);
    // Zlib is a TIdCompressorZlib
    Zlib.DecompressGZipStream(MSI,MSO);
    MSI.DisposeOf;
    MSO.Seek(0,0);
    Result := MSO.DataString;
    MSO.Free;
    end;

    public by kvasilov48 modified Oct 20, 2015  2419  4  3  0

    Base64 Encode and Decode with Key

    Base64 Encode and Decode with Key: base64.php
    <?php
    $encrypted = encrypt("to encrypt string", "secret key");
    echo $encrypted ;
    $decrypted = decrypt($encrypted, "secret key");
     
    echo $decrypted ;
     
    function encrypt($string, $key) {
      $result = '';
      for($i=0; $i<strlen($string); $i++) {
        $char = substr($string, $i, 1);
        $keychar = substr($key, ($i % strlen($key))-1, 1);
        $char = chr(ord($char)+ord($keychar));
        $result.=$char;
      }
     
      return base64_encode($result);
    }
     
    function decrypt($string, $key) {
      $result = '';
      $string = base64_decode($string);
     
      for($i=0; $i<strlen($string); $i++) {
        $char = substr($string, $i, 1);
        $keychar = substr($key, ($i % strlen($key))-1, 1);
        $char = chr(ord($char)-ord($keychar));
        $result.=$char;
      }
     
      return $result;
    }
     
    ?>
    
    

    public by Geometry modified Jul 31, 2016  971  0  4  0

    DecodeChecked: Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is removed from the returned data.

    Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is removed from the returned data. If the input is not base 58 or the checksum does not validate.
    using System;
    using System.Linq;
    using System.Text;
    using CoiniumServ.Coin.Address.Exceptions;
    using CoiniumServ.Cryptology;
    using Org.BouncyCastle.Math;
    
    /// <summary>
    /// Uses the checksum in the last 4 bytes of the decoded data to verify the rest are correct. The checksum is
    /// removed from the returned data.
    /// </summary>
    /// <exception cref="AddressFormatException">If the input is not base 58 or the checksum does not validate.</exception>
    public static byte[] DecodeChecked(string input)
    {
        var tmp = Decode(input);
        if (tmp.Length < 4)
            throw new AddressFormatException("Input too short");
        var checksum = new byte[4];
        Array.Copy(tmp, tmp.Length - 4, checksum, 0, 4);
        var bytes = new byte[tmp.Length - 4];
        Array.Copy(tmp, 0, bytes, 0, tmp.Length - 4);
        tmp = bytes.DoubleDigest();
        var hash = new byte[4];
        Array.Copy(tmp, 0, hash, 0, 4);
        if (!hash.SequenceEqual(checksum))
            throw new AddressFormatException("Checksum does not validate");
        return bytes;
    }

    public by Geometry modified Jul 31, 2016  1034  1  5  0

    Allows to DecodeUInt16

    using System;
    using System.Text;
    
    public static unsafe ushort DecodeUInt16(byte[] buffer, int offset)
    {
    	return (ushort)((buffer[offset] << 8) + buffer[offset + 1]);
    }

    public by Geometry modified Jul 31, 2016  945  1  4  0

    Decodes string input

    using System;
    using System.Linq;
    using System.Text;
    using CoiniumServ.Coin.Address.Exceptions;
    using CoiniumServ.Cryptology;
    using Org.BouncyCastle.Math;
    
    private const string Alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
    
    /// <exception cref="AddressFormatException"/>
    public static byte[] Decode(string input)
    {
        var bytes = DecodeToBigInteger(input).ToByteArray();
        // We may have got one more byte than we wanted, if the high bit of the next-to-last byte was not zero. This
        // is because BigIntegers are represented with twos-compliment notation, thus if the high bit of the last
        // byte happens to be 1 another 8 zero bits will be added to ensure the number parses as positive. Detect
        // that case here and chop it off.
        var stripSignByte = bytes.Length > 1 && bytes[0] == 0 && bytes[1] >= 0x80;
        // Count the leading zeros, if any.
        var leadingZeros = 0;
        for (var i = 0; input[i] == Alphabet[0]; i++)
        {
            leadingZeros++;
        }
        // Now cut/pad correctly. Java 6 has a convenience for this, but Android can't use it.
        var tmp = new byte[bytes.Length - (stripSignByte ? 1 : 0) + leadingZeros];
        Array.Copy(bytes, stripSignByte ? 1 : 0, tmp, leadingZeros, tmp.Length - leadingZeros);
        return tmp;
    }

    public by Geometry modified Aug 7, 2016  1041  0  6  0

    RegisterDecoder: Register image decoder for a specified file extension.

    Register image decoder for a specified file extension. File extension to register decoder for ("bmp", for example). Image decoder to use for the specified file extension. The method allows to register image decoder object, which should be used to decode images from files with the specified extension.
    private static Dictionary<string, IImageDecoder> decoders = new Dictionary<string, IImageDecoder>();
    
    static ImageDecoder()
            {
                // register PNM file format
                IImageDecoder decoder = new PNMCodec();
    
                RegisterDecoder("pbm", decoder);
                RegisterDecoder("pgm", decoder);
                RegisterDecoder("pnm", decoder);
                RegisterDecoder("ppm", decoder);
    
                // register FITS file format
                decoder = new FITSCodec();
    
                RegisterDecoder("fit", decoder);
                RegisterDecoder("fits", decoder);
            }
    
    /// <summary>
    /// Register image decoder for a specified file extension.
    /// </summary>
    /// 
    /// <param name="fileExtension">File extension to register decoder for ("bmp", for example).</param>
    /// <param name="decoder">Image decoder to use for the specified file extension.</param>
    /// 
    /// <remarks><para>The method allows to register image decoder object, which should be used
    /// to decode images from files with the specified extension.</para></remarks>
    /// 
    public static void RegisterDecoder(string fileExtension, IImageDecoder decoder)
    {
        System.Diagnostics.Debug.WriteLine("Registering decoder: " + fileExtension);
    
        decoders.Add(fileExtension.ToUpperInvariant(), decoder);
    }

    public by Geometry modified Jul 31, 2016  696  0  4  0

    Allows to DecodeKey

    using System;
    using System.Text;
    
    public static string DecodeKey(byte[] data)
    {
    	if (data == null || data.Length == 0) return null;
    
    	return Encoding.UTF8.GetString(data);
    }
    • Public Snippets
    • Channels Snippets