19246
Graphics / Some minor issues with sfColor/sfImage
« on: August 20, 2007, 03:34:42 pm »
I agree with you, giving a non-opaque color key will be useless in 99.99% cases. But as you said this is a minor issue, so I'll wait for more feedback to see if it's really needed
Using unions for this leads to undefined behaviors (according to the C++ standard). More practically, the result won't be the same whether you run it on a big-endian processor or a little-endian one.
The only way to get a portable behavior is to combine / extract the components using bitwise operators.
Pixels are not stored in a two-dimensional array, so I can't return a pointer to a sub-rectangle. To give access to a sub-part of the pixels array, I'd need to return a proxy class which would have to add offsets to match the new X and Y values.
Quote
P.S. - As a side note, you could make a small performance enhancement to sfColor by changing it to a union of a UINT and a struct { a,b,g,r }. When someone calls ToRGBA just return the UINT, and when someone calls the UINT constructor, you just set it. (It may seem minor, but if someone is generating procedural textures, it will be inside a very big nested loop.)
Using unions for this leads to undefined behaviors (according to the C++ standard). More practically, the result won't be the same whether you run it on a big-endian processor or a little-endian one.
The only way to get a portable behavior is to combine / extract the components using bitwise operators.
Quote
P.P.S. - On a similar note, it would be great if sfImage::GetPixelsPtr() took optional x and y parameters (defaulted to 0) and returned a non-const pointer. That way if I want to update a small rectangle within an image, it would be easy to get the starting position of each row and iterate quickly across the row.
Pixels are not stored in a two-dimensional array, so I can't return a pointer to a sub-rectangle. To give access to a sub-part of the pixels array, I'd need to return a proxy class which would have to add offsets to match the new X and Y values.