c++ - Convert BYTE buffer (0-255) to float buffer (0.0-1.0) -


How do I change a byte buffer (from 0 to 255) in float buffer (0.0 to 1.0)? Of course, there should be a relation between the two values, such as: 0 byf buffer in buffer buffer, will be in 128 byte buffer, in the 5F float buffer, 255 bytes buffer will have 1.f float buffer.

In fact, I have that code:

 for  (int y = 0; y & lt; height; y ++) {for (int x = 0; X & lt; width; x ++) {float * floatpixel = floatbuff + (y * width + x) * 4; BYTE * bytepixel = (Bytebuff + (y * width + x) * 4); Floatpixel [0] = bite pixels [0] / 255.f; Floatpixel [1] = bite pixels [1] /255.f; Floatpixel [2] = bite pixels [2] /255.f; Float pixel [3] = 1.0 f; // A}}  

It runs very slowly My friend suggested me to use a conversion table, but I wanted to know that someone else told me another Can give way.

Whether you choose to use a lookup table or not, your code will be very much like each loop Is doing what it does not really need to do - possibly enough to cover and multiply the cost of convert.

Restrict your pointers, and the content you only read from const, by dividing by 255, multiply by 1/255. Do not count pointers at each frequency of the inner loop, just calculate the initial values ​​and increase them. Unblock the inner loop in some time if your goal supports it then use the vector SIMD operation. Do not compare to max, decrease and increase and instead compare to zero.

Something like this

  float * floatpixel = floatbuffer; BYTE const * restricted bytepixel = bytebuffer; (Integer size = width * height; size> gt; - size) {floatpixel [0] = biotextiles [0] * (1.f / 255.f); Floatpixel [1] = bite pixels [1] * (1.f / 255.f); Floatpixel [2] = biotextiles [2] * (1.f / 255.f); Float pixel [3] = 1.0 f; // a float pixel + = 4; Bitipixel + = 4; }  

will be a start.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -