<commit_before>/*
* NeuQuant Neural-Net Quantization Algorithm
* ------------------------------------------
*
* Copyright (c) 1994 <NAME>
*
* NEUQUANT Neural-Net quantization algorithm by <NAME>, 1994. See
* "Kohonen neural networks for optimal colour quantization" in "Network:
* Computation in Neural Systems" Vol. 5 (1994) pp 351-367. for a discussion of
* the algorithm.
*
* Any party obtaining a copy of these files from the author, directly or
* indirectly, is granted, free of charge, a full and unrestricted irrevocable,
* world-wide, paid up, royalty-free, nonexclusive right and license to deal in
* this software and documentation files (the "Software"), including without
* limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons who
* receive copies from any such party to do so, with the only requirement being
* that this copyright notice remain intact.
*/

/*
* This class handles Neural-Net quantization algorithm
* @author <NAME> (original Java version - <EMAIL>)
* @author <NAME> (AS3 version - bytearray.org)
* @version 0.1 AS3 implementation
*/

	//import flash.utils.ByteArray;

	NeuQuant = function()
	{
	    var exports = {};
		/*private_static*/ var netsize = 256; /* number of colours used */

		/* four primes near 500 - assume no image has a length so large */
		/* that it is divisible by all four primes */

		/*private_static*/ var prime1 = 499;
		/*private_static*/ var prime2 = 491;
		/*private_static*/ var prime3 = 487;
		/*private_static*/ var prime4 = 503;
		/*private_static*/ var minpicturebytes = (3 * prime4);

		/* minimum size for input image */
		/*
		* Program Skeleton ---------------- [select samplefac in range 1..30] [read
		* image from input file] pic = (unsigned char*) malloc(3*width*height);
		* initnet(pic,3*width*height,samplefac); learn(); unbiasnet(); [write output
		* image header, using writecolourmap(f)] inxbuild(); write output image using
		* inxsearch(b,g,r)
		*/

		/*
		* Network Definitions -------------------
		*/

		/*private_static*/ var maxnetpos = (netsize - 1);
		/*private_static*/ var netbiasshift = 4; /* bias for colour values */
		/*private_static*/ var ncycles = 100; /* no. of learning cycles */

		/* defs for freq and bias */
		/*private_static*/ var intbiasshift = 16; /* bias for fractions */
		/*private_static*/ var intbias = (1 << intbiasshift);
		/*private_static*/ var gammashift = 10; /* gamma = 1024 */
		/*private_static*/ var gamma = (1 << gammashift);
		/*private_static*/ var betashift = 10;
		/*private_static*/ var beta = (intbias >> betashift); /* beta = 1/1024 */
		/*private_static*/ var betagamma = (intbias << (gammashift - betashift));

		/* defs for decreasing radius factor */
		/*private_static*/ var initrad = (netsize >> 3); /*
	                                                         * for 256 cols, radius
	                                                         * starts
	                                                         */

		/*private_static*/ var radiusbiasshift = 6; /* at 32.0 biased by 6 bits */
		/*private_static*/ var radiusbias = (1 << radiusbiasshift);
		/*private_static*/ var initradius = (initrad * radiusbias); /*
	                                                                   * and
	                                                                   * decreases
	                                                                   * by a
	                                                                   */

		/*private_static*/ var radiusdec = 30; /* factor of 1/30 each cycle */

		/* defs for decreasing alpha factor */
		/*private_static*/ var alphabiasshift = 10; /* alpha starts at 1.0 */
		/*private_static*/ var initalpha = (1 << alphabiasshift);
		/*private*/ var alphadec /* biased by 10 bits */

		/* radbias and alpharadbias used for radpower calculation */
		/*private_static*/ var radbiasshift = 8;
		/*private_static*/ var radbias = (1 << radbiasshift);
		/*private_static*/ var alpharadbshift = (alphabiasshift + radbiasshift);

		/*private_static*/ var alpharadbias = (1 << alpharadbshift);

		/*
		* Types and Global Variables --------------------------
		*/

		/*private*/ var thepicture/*ByteArray*//* the input image itself */
		/*private*/ var lengthcount; /* lengthcount = H*W*3 */
		/*private*/ var samplefac; /* sampling factor 1..30 */

		// typedef int pixel[4]; /* BGRc */
		/*private*/ var network/*Array*/; /* the network itself - [netsize][4] */
		/*protected*/ var netindex/*Array*/ = new Array();

		/* for network lookup - really 256 */
		/*private*/ var bias/*Array*/ = new Array();

		/* bias and freq arrays for learning */
		/*private*/ var freq/*Array*/ = new Array();
		/*private*/ var radpower/*Array*/ = new Array();

		var NeuQuant = exports.NeuQuant = function NeuQuant(thepic/*ByteArray*/, len, sample)
		{

			var i;
			var p/*Array*/;

			thepicture = thepic;
			lengthcount = len;
			samplefac = sample;

			network = new Array(netsize);<commit_msg>Remove 'private' type comment easily inferred from context.<commit_after>/*
* NeuQuant Neural-Net Quantization Algorithm
* ------------------------------------------
*
* Copyright (c) 1994 <NAME>
*
* NEUQUANT Neural-Net quantization algorithm by <NAME>, 1994. See
* "Kohonen neural networks for optimal colour quantization" in "Network:
* Computation in Neural Systems" Vol. 5 (1994) pp 351-367. for a discussion of
* the algorithm.
*
* Any party obtaining a copy of these files from the author, directly or
* indirectly, is granted, free of charge, a full and unrestricted irrevocable,
* world-wide, paid up, royalty-free, nonexclusive right and license to deal in
* this software and documentation files (the "Software"), including without
* limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons who
* receive copies from any such party to do so, with the only requirement being
* that this copyright notice remain intact.
*/

/*
* This class handles Neural-Net quantization algorithm
* @author <NAME> (original Java version - <EMAIL>)
* @author <NAME> (AS3 version - bytearray.org)
* @version 0.1 AS3 implementation
*/

	//import flash.utils.ByteArray;

	NeuQuant = function()
	{
	    var exports = {};
		var netsize = 256; /* number of colours used */

		/* four primes near 500 - assume no image has a length so large */
		/* that it is divisible by all four primes */

		var prime1 = 499;
		var prime2 = 491;
		var prime3 = 487;
		var prime4 = 503;
		var minpicturebytes = (3 * prime4);

		/* minimum size for input image */
		/*
		* Program Skeleton ---------------- [select samplefac in range 1..30] [read
		* image from input file] pic = (unsigned char*) malloc(3*width*height);
		* initnet(pic,3*width*height,samplefac); learn(); unbiasnet(); [write output
		* image header, using writecolourmap(f)] inxbuild(); write output image using
		* inxsearch(b,g,r)
		*/

		/*
		* Network Definitions -------------------
		*/

		var maxnetpos = (netsize - 1);
		var netbiasshift = 4; /* bias for colour values */
		var ncycles = 100; /* no. of learning cycles */

		/* defs for freq and bias */
		var intbiasshift = 16; /* bias for fractions */
		var intbias = (1 << intbiasshift);
		var gammashift = 10; /* gamma = 1024 */
		var gamma = (1 << gammashift);
		var betashift = 10;
		var beta = (intbias >> betashift); /* beta = 1/1024 */
		var betagamma = (intbias << (gammashift - betashift));

		/* defs for decreasing radius factor */
		var initrad = (netsize >> 3); /*
	                                                         * for 256 cols, radius
	                                                         * starts
	                                                         */

		var radiusbiasshift = 6; /* at 32.0 biased by 6 bits */
		var radiusbias = (1 << radiusbiasshift);
		var initradius = (initrad * radiusbias); /*
	                                                                   * and
	                                                                   * decreases
	                                                                   * by a
	                                                                   */

		var radiusdec = 30; /* factor of 1/30 each cycle */

		/* defs for decreasing alpha factor */
		var alphabiasshift = 10; /* alpha starts at 1.0 */
		var initalpha = (1 << alphabiasshift);
		var alphadec /* biased by 10 bits */

		/* radbias and alpharadbias used for radpower calculation */
		var radbiasshift = 8;
		var radbias = (1 << radbiasshift);
		var alpharadbshift = (alphabiasshift + radbiasshift);

		var alpharadbias = (1 << alpharadbshift);

		/*
		* Types and Global Variables --------------------------
		*/

		var thepicture/*ByteArray*//* the input image itself */
		var lengthcount; /* lengthcount = H*W*3 */
		var samplefac; /* sampling factor 1..30 */

		// typedef int pixel[4]; /* BGRc */
		var network/*Array*/; /* the network itself - [netsize][4] */
		/*protected*/ var netindex/*Array*/ = new Array();

		/* for network lookup - really 256 */
		var bias/*Array*/ = new Array();

		/* bias and freq arrays for learning */
		var freq/*Array*/ = new Array();
		var radpower/*Array*/ = new Array();

		var NeuQuant = exports.NeuQuant = function NeuQuant(thepic/*ByteArray*/, len, sample)
		{

			var i;
			var p/*Array*/;

			thepicture = thepic;
			lengthcount = len;
			samplefac = sample;

			network = new Array(netsize);
{'fraction_non_alphanumeric': 0.1386169876855068, 'fraction_numerical': 0.022734449005367856, 'mean_word_length': 2.140118968935889, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6381040', 'n_tokens_mistral': 3014, 'n_tokens_neox': 2556, 'n_words': 951}