encoder.js
function getDownscaleType( n_type, analysis ) {
	switch (n_type) {

		// Not possible to downscale from 1-byte
		case NUMTYPE.UINT8:
		case NUMTYPE.INT8:
			return NUMTYPE.UNKNOWN;

		case NUMTYPE.UINT16:
			switch (analysis.type) {

				// UINT16 -> (U)INT8 = UINT8
				case NUMTYPE.INT8: // Unsigned, so always positive
				case NUMTYPE.UINT8:
					return NUMTYPE.UINT8;

				// Anything else is equal to or bigger than 2 bytes
				default:
					return NUMTYPE.UNKNOWN;					
			}

		case NUMTYPE.INT16:
			switch (analysis.type) {

				// INT16 -> UINT8 = INT8 (if v < INT8_MAX)
				case NUMTYPE.UINT8:
					if (analysis.max < INT8_MAX) {
						return NUMTYPE.INT8;
					} else {
						return NUMTYPE.UNKNOWN;
					}

				// INT16 -> INT8
				case NUMTYPE.INT8:
					return NUMTYPE.INT8;

				// Anything else is equal to or bigger than 2 bytes
				default:
					return NUMTYPE.UNKNOWN;					
			}

		case NUMTYPE.UINT32:
			switch (analysis.type) {

				// UINT32 -> (U)INT8 [= UINT8]
				case NUMTYPE.INT8:
				case NUMTYPE.UINT8:
					return NUMTYPE.UINT8;

				// UINT32 -> (U)INT16 = UINT16
				case NUMTYPE.INT16:
				case NUMTYPE.UINT16:
					return NUMTYPE.UINT16;

				// Anything else is equal to or bigger than 4 bytes
				default:
					return NUMTYPE.UNKNOWN;					

			}

		case NUMTYPE.INT32:
			switch (analysis.type) {

				// INT32 -> UINT8 = INT8/INT16 (if v < INT8_MAX)
				case NUMTYPE.UINT8:
					if (analysis.max < INT8_MAX) {
						return NUMTYPE.INT8;
					} else {
						return NUMTYPE.INT16;
					}

				// INT32 -> INT8
				case NUMTYPE.INT8:
					return NUMTYPE.INT8;

				// INT32 -> UINT16 = INT16 (if v < INT16_MAX)
				case NUMTYPE.UINT16:
					if (analysis.max < INT16_MAX) {
						return NUMTYPE.INT16;
					} else {
						return NUMTYPE.UNKNOWN;
					}

				// INT32 -> INT16
				case NUMTYPE.INT16:
					return NUMTYPE.INT16;

				// Anything else is equal to or bigger than 4 bytes
				default:
					return NUMTYPE.UNKNOWN;					

			}

		case NUMTYPE.FLOAT32:
			switch (analysis.type) {

				// FLOAT32 -> Anything 1-2 bytes
				case NUMTYPE.UINT8:
					return NUMTYPE.UINT8;
				case NUMTYPE.INT8:
					return NUMTYPE.INT8;
				case NUMTYPE.UINT16:
					return NUMTYPE.UINT16
				case NUMTYPE.INT16:
					return NUMTYPE.INT16

				// Everything else is discarded
				default:
					return NUMTYPE.UNKNOWN;
			}

		case NUMTYPE.FLOAT64:
			switch (analysis.type) {

				// FLOAT64 -> Anything 1-2 bytes
				case NUMTYPE.UINT8:
					return NUMTYPE.UINT8;
				case NUMTYPE.INT8:
					return NUMTYPE.INT8;
				case NUMTYPE.UINT16:
					return NUMTYPE.UINT16
				case NUMTYPE.INT16:
					return NUMTYPE.INT16

				// FLOAT64 -> FLOAT32
				case NUMTYPE.FLOAT32:
					return NUMTYPE.FLOAT32

				// Everything else is discarded
				default:
					return NUMTYPE.UNKNOWN;
			}

	}
}
function getDownscaleType( n_type, analysis ) {
	switch (n_type) {

		// Not possible to downscale from 1-byte
		case NUMTYPE.UINT8:
		case NUMTYPE.INT8:
			return NUMTYPE.UNKNOWN;

		case NUMTYPE.UINT16:
			switch (analysis.type) {

				// UINT16 -> (U)INT8 = UINT8
				case NUMTYPE.INT8: // Unsigned, so always positive
				case NUMTYPE.UINT8:
					return NUMTYPE.UINT8;

				// Anything else is equal to or bigger than 2 bytes
				default:
					return NUMTYPE.UNKNOWN;					
			}

		case NUMTYPE.INT16:
			switch (analysis.type) {

				// INT16 -> UINT8 = INT8 (if v < INT8_MAX)
				case NUMTYPE.UINT8:
					if (analysis.max < INT8_MAX) {
						return NUMTYPE.INT8;
					} else {
						return NUMTYPE.UNKNOWN;
					}

				// INT16 -> INT8
				case NUMTYPE.INT8:
					return NUMTYPE.INT8;

				// Anything else is equal to or bigger than 2 bytes
				default:
					return NUMTYPE.UNKNOWN;					
			}

		case NUMTYPE.UINT32:
			switch (analysis.type) {

				// UINT32 -> (U)INT8 [= UINT8]
				case NUMTYPE.INT8:
				case NUMTYPE.UINT8:
					return NUMTYPE.UINT8;

				// UINT32 -> (U)INT16 = UINT16
				case NUMTYPE.INT16:
				case NUMTYPE.UINT16:
					return NUMTYPE.UINT16;

				// Anything else is equal to or bigger than 4 bytes
				default:
					return NUMTYPE.UNKNOWN;					

			}

		case NUMTYPE.INT32:
			switch (analysis.type) {

				// INT32 -> UINT8 = INT8/INT16 (if v < INT8_MAX)
				case NUMTYPE.UINT8:
					if (analysis.max < INT8_MAX) {
						return NUMTYPE.INT8;
					} else {
						return NUMTYPE.INT16;
					}

				// INT32 -> INT8
				case NUMTYPE.INT8:
					return NUMTYPE.INT8;

				// INT32 -> UINT16 = INT16 (if v < INT16_MAX)
				case NUMTYPE.UINT16:
					if (analysis.max < INT16_MAX) {
						return NUMTYPE.INT16;
					} else {
						return NUMTYPE.UNKNOWN;
					}

				// INT32 -> INT16
				case NUMTYPE.INT16:
					return NUMTYPE.INT16;

				// Anything else is equal to or bigger than 4 bytes
				default:
					return NUMTYPE.UNKNOWN;					

			}

		case NUMTYPE.FLOAT32:
			switch (analysis.type) {

				// FLOAT32 -> Anything 1-2 bytes
				case NUMTYPE.UINT8:
					return NUMTYPE.UINT8;
				case NUMTYPE.INT8:
					return NUMTYPE.INT8;
				case NUMTYPE.UINT16:
					return NUMTYPE.UINT16
				case NUMTYPE.INT16:
					return NUMTYPE.INT16

				// Everything else is discarded
				default:
					return NUMTYPE.UNKNOWN;
			}

		case NUMTYPE.FLOAT64:
			switch (analysis.type) {

				// FLOAT64 -> Anything 1-2 bytes
				case NUMTYPE.UINT8:
					return NUMTYPE.UINT8;
				case NUMTYPE.INT8:
					return NUMTYPE.INT8;
				case NUMTYPE.UINT16:
					return NUMTYPE.UINT16
				case NUMTYPE.INT16:
					return NUMTYPE.INT16

				// FLOAT64 -> FLOAT32
				case NUMTYPE.FLOAT32:
					return NUMTYPE.FLOAT32

				// Everything else is discarded
				default:
					return NUMTYPE.UNKNOWN;
			}

	}
}
function getDownscaleType ( n_type , analysis ) { switch ( n_type ) { // Not possible to downscale from 1-byte case NUMTYPE . UINT8 : case NUMTYPE . INT8 : return NUMTYPE . UNKNOWN ; case NUMTYPE . UINT16 : switch ( analysis . type ) { // UINT16 -> (U)INT8 = UINT8 case NUMTYPE . INT8 : // Unsigned, so always positive case NUMTYPE . UINT8 : return NUMTYPE . UINT8 ; // Anything else is equal to or bigger than 2 bytes default : return NUMTYPE . UNKNOWN ; } case NUMTYPE . INT16 : switch ( analysis . type ) { // INT16 -> UINT8 = INT8 (if v < INT8_MAX) case NUMTYPE . UINT8 : if ( analysis . max < INT8_MAX ) { return NUMTYPE . INT8 ; } else { return NUMTYPE . UNKNOWN ; } // INT16 -> INT8 case NUMTYPE . INT8 : return NUMTYPE . INT8 ; // Anything else is equal to or bigger than 2 bytes default : return NUMTYPE . UNKNOWN ; } case NUMTYPE . UINT32 : switch ( analysis . type ) { // UINT32 -> (U)INT8 [= UINT8] case NUMTYPE . INT8 : case NUMTYPE . UINT8 : return NUMTYPE . UINT8 ; // UINT32 -> (U)INT16 = UINT16 case NUMTYPE . INT16 : case NUMTYPE . UINT16 : return NUMTYPE . UINT16 ; // Anything else is equal to or bigger than 4 bytes default : return NUMTYPE . UNKNOWN ; } case NUMTYPE . INT32 : switch ( analysis . type ) { // INT32 -> UINT8 = INT8/INT16 (if v < INT8_MAX) case NUMTYPE . UINT8 : if ( analysis . max < INT8_MAX ) { return NUMTYPE . INT8 ; } else { return NUMTYPE . INT16 ; } // INT32 -> INT8 case NUMTYPE . INT8 : return NUMTYPE . INT8 ; // INT32 -> UINT16 = INT16 (if v < INT16_MAX) case NUMTYPE . UINT16 : if ( analysis . max < INT16_MAX ) { return NUMTYPE . INT16 ; } else { return NUMTYPE . UNKNOWN ; } // INT32 -> INT16 case NUMTYPE . INT16 : return NUMTYPE . INT16 ; // Anything else is equal to or bigger than 4 bytes default : return NUMTYPE . UNKNOWN ; } case NUMTYPE . FLOAT32 : switch ( analysis . type ) { // FLOAT32 -> Anything 1-2 bytes case NUMTYPE . UINT8 : return NUMTYPE . UINT8 ; case NUMTYPE . INT8 : return NUMTYPE . INT8 ; case NUMTYPE . UINT16 : return NUMTYPE . UINT16 case NUMTYPE . INT16 : return NUMTYPE . INT16 // Everything else is discarded default : return NUMTYPE . UNKNOWN ; } case NUMTYPE . FLOAT64 : switch ( analysis . type ) { // FLOAT64 -> Anything 1-2 bytes case NUMTYPE . UINT8 : return NUMTYPE . UINT8 ; case NUMTYPE . INT8 : return NUMTYPE . INT8 ; case NUMTYPE . UINT16 : return NUMTYPE . UINT16 case NUMTYPE . INT16 : return NUMTYPE . INT16 // FLOAT64 -> FLOAT32 case NUMTYPE . FLOAT32 : return NUMTYPE . FLOAT32 // Everything else is discarded default : return NUMTYPE . UNKNOWN ; } } }
Get the possible downscale type based on the specified analysis
Get the possible downscale type based on the specified analysis