Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, February 8, 2006 2:26:21 AM(UTC)
NeilTippett

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

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Thursday, February 9, 2006 8:20:56 AM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 353


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.
LEAD Logo
 
#3 Posted : Thursday, February 9, 2006 11:12:16 PM(UTC)
NeilTippett

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:07:13 AM(UTC)

Amin  
Amin

Groups: Manager, Tech Support
Posts: 353


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.
LEAD Logo
 
#5 Posted : Monday, February 13, 2006 7:16:45 AM(UTC)
NeilTippett

Groups: Registered
Posts: 3


Many thanks, that worked a treat.

But one might argue that it isn't very intuitive!

Neil

 
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.

Powered by YAF.NET | YAF.NET © 2003-2019, Yet Another Forum.NET
This page was generated in 0.186 seconds.