How can I convert a BYTE buffer (from 0 to 255) to a float buffer (from 0.0 to 1.0)? Of course there should be a relation between the two values, eg: 0 in byte buffer will be .0.f in float buffer, 128 in byte buffer will be .5f in float buffer, 255 in byte buffer will be 1.f in float buffer.
Actually this is the code that I have:
for (int y=0;y<height;y++) {
for (int x=0;x<width;x++) {
float* floatpixel = floatbuffer + (y * width + x) * 4;
BYTE* bytepixel = (bytebuffer + (y * width + x) * 4);
floatpixel[0] = bytepixel[0]/255.f;
floatpixel[1] = bytepixel[1]/255.f;
floatpixel[2] = bytepixel[2]/255.f;
floatpixel[3] = 1.0f; // A
}
}
This runs very slow. A friend of mine suggested me to use a conversion table, but I wanted to know if someone else can give me another approach.
Veehmot.