Saving three 16 bit RGB values in 32 bits::



I have been fiddling with large 16 bit images for a while.
and have been trying to save the image allocation space on the disk.

The following algorithm is the result of the struggle :-)
Any comments ??

Saving three 16 bit RGB values in 32 bits:

The floating point mantissa is defined as 23 bit number.
To sum of three 16 bit numbers  requires at most 18 bits.

Since the image RGB values are independent of each other
and the individual color component values are in the range of 0 to 65535,
they can be stored as a single 32 bit floating point number.

This in turn will result in 33% decrement in storage allocation.

The RGB to double algorithm:

Fno = R * 100000.0 + G + B /100000.0

double to RGB

R = (int) Fno/100000.0;
G = (int) ( Fno - R * 100000.0 )
B = (int) (round up) ( ( Fno - R * 100000.0  - G ) * 100000.0 ) )

//CODE BEGIN:

// * Copyright (c) 2000-2005
// * Wenny Macura, Mac-Eng  All rights reserved.
/*
 * double	Utility::RGB_ToDBL( int R, int G, int B)
 *
 * used to convert three 16 bit RGB values ( 48 bits )
 * to one double ( 32 bits ) value.
 * this results in saving 2 bytes per pixel or 33% of the image data
 * write the image as CMYK
 * NOTE:
 * the R,G,B values must be less then 100000.
 */
#define M_CONST 100000.0

double	Utility::RGB_ToDBL( int R, int G, int B)
{
	static	double result;
	result = R * M_CONST;
	result += G ;
	result += B /M_CONST;
	return result;
}

/*
 * int	*Utility::DBL_ToRGB( double Value)
 *
 * used to convert double representing RGB values
 * to integer RGB values
 * the return values are:
 * RetVal[0] ~ R
 * RetVal[1] ~ G
 * RetVal[0] ~ B
 */

int	*Utility::DBL_ToRGB( double Value)
{
	static	int	Color[4];
	static  double  Tol = 0.5/M_CONST;
    double mTmp;
	int	i_val;
	i_val = (int) ( Value/M_CONST );
	Color[0] = i_val;
	mTmp = Value - (double) i_val * M_CONST;
	i_val = (int) mTmp;
	Color[1] = i_val;
	mTmp -= i_val;
	Color[2] = (int ) ( (Tol + mTmp) * M_CONST);
	return Color;
}
//CODE END:

Wenny Macura
wmacu@xxxxxxxxx
.