I'll start with the function so you can see what I'm trying to do:
Code:
int SaveImagePPM( IMAGE *Image, FILE *file )
{
	ulong Rows = Image->Rows, row;
	ulong Cols = Image->Cols, col, i;
	ulong keep = ~(~0UL << Image->Depth);

	fprintf( file, "P3\n%lu %lu\n%u\n", Cols, Rows, 255 );

	for ( row = 0; row < Rows; ++row )
	{
		char * whitespace = "\n";

		for ( col = 0; col < Cols; ++col )
		{
			for ( i = 0; i < IMAGE_CHANNEL_A; ++i )
			{
				ulong index = ImagePixelX( Image, row, col );
				ulong value = *ImagePixel( Image, index, i ) << 1;

				if ( value )
				{
					value = keep / value;
					value = (value >> 1) + (value & 1);
				}

				fprintf( file, "%s%5lu", whitespace, value );
				whitespace = " ";
			}
		}
	}

	fputc('\n', file );

	fflush( file );
	return 0;
}
Previously I've just used the existing depth and values, now I want to learn how to scale the values from their current range to an 8 bit range without the use of floating point, the reason for this is I want the reduce my reliance on FPNs in places where it would be helpful to the porting process to not rely on FPNs, what I mean is that a number of years ago systems had to work without FPNs, this naturally meant even the images and fonts had to be loaded without FPNs and I would like to learn this technique, since I know the image displayed correctly when depth was used as is I figured it would be the best choice to learn the technique on, the above attempt resulted in a black image with barely some grey in the bottom left corner, naturally that wasn't the image I was expecting, is there anyone here familiar with how to do it?