I've implemented some setPixel color operations for native endian and non native endian pixel formats. Using GCC
everything is running fine. Using MSVC some operations for SHORT and HALF_FLOAT values are slowed on
execution, what I can't explain.
Here is the fragment of my setPixelColor method:
brPixelFormatInfo info = gfxUtils.getPixelFormatInfo(m_format);
unsigned int nativeColor = 0;
// if pixel format is native first calculate the native color before
// entering loop to set color value.
if(true==info.isNativeEndian()){
nativeColor = this->getNativePixelColor(color);
}
unsigned int bytesPerPixel = this->getBytesPerPixel();
for(unsigned int y = rect.getY(); y < rect.getY()+ rect.getHeight(); y++)
{
// calculation of the image value stride
unsigned int byteIndex = (this->getBytesPerRow() * y) + rect.getX() * bytesPerPixel;
for (unsigned int x = rect.getX(); x < rect.getX()+rect.getWidth(); x++)
{
if(true==info.isNativeEndian())
{
[...]
}
else{
switch(m_format)
{
// 32bit float value formats
case PF_FLOAT32_RGB:
{
m_data[byteIndex] = (unsigned char)color.getRed();
m_data[byteIndex + 1] = (unsigned char)color.getGreen();
m_data[byteIndex + 2] = (unsigned char)color.getBlue();
break;
}
case PF_SHORT_RGB:
{
unsigned int red, green, blue = 0;
brPixelFormatInfo info = gfxUtils.getPixelFormatInfo(PF_SHORT_RGB);
brPixelFormatInfo::RGBA_BITS bits = info.getBitValues();
brColor::RGBA rgba = color.getRGBA();
red = gfxUtils.convertColorToFixedPoint(rgba.m_red, bits.m_red);
green = gfxUtils.convertColorToFixedPoint(rgba.m_green, bits.m_green);
blue = gfxUtils.convertColorToFixedPoint(rgba.m_blue, bits.m_blue);
m_data[byteIndex] = (unsigned char)red;
m_data[byteIndex + 1] = (unsigned char)green;
m_data[byteIndex + 2] = (unsigned char)blue;
break;
}
// half float precision values
case PF_FLOAT16_R:
{
brColor::RGBA rgba = color.getRGBA();
m_data[byteIndex] = (unsigned char)gfxUtils.convertColorToHalfFloat(rgba.m_red);
break;
}
default:
throw brCore::brIllegalStateException(
"[brImage]::setPixelColor: Invalid pixel format!");
}
}
byteIndex += bytesPerPixel;
}
}
And here is my convert to fixed point method:
unsigned int brGraphicsUtils::convertColorToFixedPoint(float color, unsigned int bits) const
{
unsigned int fixed = 0;
if(color <= 0.0f){
fixed = 0;
}
else if (color >= 1.0f){
fixed = (1U<<bits)-1U;
}
else{
fixed = (unsigned int)(color * (1U<<bits));
}
return fixed;
}
Nothing special... Strange is, if I debug my sources step by step (procedual) anything is fast enough, if I
make a single step over the getPixelColor method it takes nearly some seconds, before the call returns
and the Unit test continue the operation ...
I've checked sources again and again, it looks correct. For evaluation I've added some timestamp calls
to the SHORT_RGB handling:
Quote
- in: 2012-Jan-19 15:44:52.664127
- start convert: 2012-Jan-19 15:44:52.669127
- end convert: 2012-Jan-19 15:44:52.690127
- start writing: 2012-Jan-19 15:44:52.695127
- end writing: 2012-Jan-19 15:44:52.700127
- out: 2012-Jan-19 15:44:52.705127
- start convert: 2012-Jan-19 15:44:52.669127
- end convert: 2012-Jan-19 15:44:52.690127
- start writing: 2012-Jan-19 15:44:52.695127
- end writing: 2012-Jan-19 15:44:52.700127
- out: 2012-Jan-19 15:44:52.705127
It looks to me, that my operations are ok, but the writing of the data takes some milliseconds. But why
only for MSVC?
Has anyone an Idea what could be wrong and how I could fasten up this elementar operations?
Thanks for any hint.
Best regards,
Hellhound













