LEADTOOLS Support
Imaging
Imaging SDK Questions
Apparent incorrect colour order at display time
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Wednesday, February 8, 2006 2:21:21 AM(UTC)
Groups: Registered
Posts: 3
If I create a bitmap using lets say the following parameters:
bitmap->Create( 1024, 1024, 24, ORDER_RGB, NULL, TOP_LEFT, TYPE_CONV, (L_UCHAR L_FAR *)NULL, 0);
And then set the contents using roughly the following
unsigned
char *data = dataPtr;
const int bytesPerRow = 1024 * 3;
LBuffer buf(bytesPerRow);
for (int y = 0; y < 1024; ++y)
{
buf.Copy(data, bytesPerRow);
bitmap->PutRow(buf, y);
data += bytesPerRow;
}
Where the data being set is in the order RGB and dataPtr refers to a buffer of the complete data. Subsequent 'paints' of this image using
bitmap->Paint()->SetDC( hDC );
bitmap->Paint()->PaintDC() ;
Lead to this image being drawn as if the data order were BGR. So, I hear you say, why not change the bitmap creation to using ORDER_BGR, well saving the bitmap works correctly with the order ORDER_RGB but not with ORDER_BGR (it really does save in the order BGR). So how do I fix this?
Just incase it's important, I'm using version 14 of leadtools patched to 14.0.0.43
#2
Posted
:
Thursday, February 9, 2006 8:15:56 AM(UTC)
Groups: Manager, Tech Support
Posts: 367
Was thanked: 1 time(s) in 1 post(s)
Any image created (or loaded) as RGB will not paint correctly because the color order in Windows GDI device contexts is BGR.
Our code samples and demo project always use BGR. If you open and a
save an image using one of them, does the saving problem appear? If so,
can you give me details to reproduce the problem here.
Amin Dodin
Senior Support Engineer
LEAD Technologies, Inc.
#3
Posted
:
Thursday, February 9, 2006 11:07:16 PM(UTC)
Groups: Registered
Posts: 3
Sorry, maybe I wasn't clear on my first post. Below I'll outline the senario, but some of the inconsequencial steps might be missing
bitmap->Create( 1024, 1024, 24, ORDER_RGB, NULL, TOP_LEFT, TYPE_CONV, (L_UCHAR L_FAR *)NULL, 0);
unsigned char *data = dataPtr; //dataPtr in RGB format
const int bytesPerRow = 1024 * 3;
LBuffer buf(bytesPerRow);
for (int y = 0; y < 1024; ++y)
{
buf.Copy(data, bytesPerRow);
bitmap->PutRow(buf, y);
data += bytesPerRow;
}
bitmap->Paint()->SetDC( hDC );
bitmap->Paint()->PaintDC() ;
The image appears as if the data were in the format BGR
LFile theFile( bitmap,
filename );
theFile.SaveFile(FILE_TIF, 24, 2, SAVEFILE_OPTIMIZEDPALETTE);
The saved image is in the correct RGB format
anotherBitmap->Load(filename)
anotherBitmap->Paint()->SetDC( hDC );
anotherBitmap->Paint()->PaintDC() ;
Image appears correctly in the format RGB
Saving is not a problem, it is the displaying of the image without having to save it and then reload it first. We use your product because it is reasonably fast when processing large images (10,000 x 10,000) but having to save and then reload an image of this size is a huge performance hit.
If you would like us to send you a Repeatable Bug Test, I'm sure we can, but the code above I would have thought should be enough
#4
Posted
:
Monday, February 13, 2006 7:02:13 AM(UTC)
Groups: Manager, Tech Support
Posts: 367
Was thanked: 1 time(s) in 1 post(s)
Neil,
When you create the image, it is created correctly. When you save it, it is also saved correctly.
However, when you call anotherBitmap->Load(filename), it is actually
loaded as BGR, not RGB. That's why it paints correctly after loading.
In other words, you can have an RGB image created, loaded and saved
correctly, but you cannot paint it unless you convert it to BGR first.
You can do the conversion without loading and saving by using
LBitmapBase::ColorRes with the flag value of CRF_BYTEORDERBGR.
You can also swap the Red and Blue channels using LBitmap::SwapColors(SWAP_RB)
Amin Dodin
Senior Support Engineer
LEAD Technologies, Inc.
#5
Posted
:
Monday, February 13, 2006 7:11:45 AM(UTC)
Groups: Registered
Posts: 3
Many thanks, that worked a treat.
But one might argue that it isn't very intuitive!
Neil
LEADTOOLS Support
Imaging
Imaging SDK Questions
Apparent incorrect colour order at display time
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.