How to do a color reduction calculation?

Started by
1 comment, last by Norman Barrows 8 years, 5 months ago

Let's say I had a color whose value is 130 and is a unsigned char (BYTE) value

I want to convert it into a float value within the range of 0...1

How do I go about doing that?

I tried to cast directly, but it is no working

like

SrMaterial mat = subMesh->material;
D3DMATERIAL9 material;
material.Diffuse.r = mat.diffuse.r;

Here the SrMaterial consists of color values whose type is srbyte which is in turn defined as unsigned char.

But their values are incredibly large. I don't believe that they are supposed to be rendered in Direct3D environment..

Thanks in advance

Jack

Advertisement

Assuming you're referring to a single color channel you just cast it to float and then divide it by 255.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

I want to convert it into a float value within the range of 0...1
How do I go about doing that?

as i recall, dx9 uses rgb bytes, not floats internally. one of the first things i figured out when deciding whether to use bytes or floats for colors. so needless to say, bytes won.

there are APIs and macros for both.

FYI, that's a format conversion, not color reduction.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement