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 : Monday, June 12, 2006 6:19:34 PM(UTC)

lxconan  
lxconan

Groups: Registered
Posts: 3


Hello!

I'm new to LEADTOOLS, and I am trying to store one-page bitmap data into an one-dimensional array, which is quiet similar to the function imread() in matlab. That is, suppose pixel (x,y) in the bitmap, the correspond index of the color information of the array is width * y + x.

I'm using Ver 14. API interface. Win32. I have tried many methods but still could not implement it. I know that I can use L_GetPixelColor() function, but is there any method which can be faster? Would you please give me a hint?

Thanks in advance!

 

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 : Tuesday, June 13, 2006 10:46:07 PM(UTC)

Bashar  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

Using L_GetPixelColor() is slow, try
using L_SaveBitmapMemory to save to a buffer, and specify FILE_RAW as the target format to save the pixel data only.

 
#3 Posted : Friday, June 16, 2006 10:04:34 PM(UTC)

lxconan  
lxconan

Groups: Registered
Posts: 3


Thanks a lot! Your idea is great! But please forgive me of putting my code below, it is slower than your method, but it is better than L_GetPixelColor() [:)]

BOOL TranslateBitmapToArrayALittleFaster(char* pszfilename, int array[])
{
    BITMAPHANDLE hbmp;      /* bitmap handle */
    L_UCHAR L_FAR* pbuf;    /* buffer of row data */
    HGLOBAL hbuf;           /* handle to the buffer */
    int i, j = 0;           /* row and line indicator */
    int x, y;               /* traslated row and line indicator */
    L_UINT indexer = 0;     /* indexer which holds the start position of the returned data array */

    /* try load bitmap */
    if( L_LoadBitmap((L_CHAR L_FAR*)pszfilename, &hbmp, sizeof(BITMAPHANDLE),
        24, ORDER_BGR, NULL, NULL) != SUCCESS)
    {
        return FALSE;
    }
    else
    {
        /* allocate and lock buffer */
        hbuf = GlobalAlloc( GMEM_MOVEABLE, hbmp.BytesPerLine);
        pbuf = (L_UCHAR L_FAR*)GlobalLock(hbuf);
        /* we should do this to use low level functions */
        L_AccessBitmap(&hbmp);
        /* process each row */
        for( j = 0 ; j < hbmp.Height ; ++j )
        {
            /* prepare to translate coordinate */
            x = 0;
            y = j;
            /* translate coordinate */
            L_PointToBitmap(&hbmp, TOP_LEFT, &x, &y);
            /* get data of each row */
            L_GetBitmapRow(&hbmp, pbuf, y, hbmp.BytesPerLine);
            for(i = 0 ; i < hbmp.Width * 3 ; i += 3)
            {
                array[indexer + i / 3] = ((pbuf[i] << 16) & 0x00FF0000)
                    | ((pbuf[i + 1] << 8) & 0x00FF00) | (pbuf[i + 2]);
            }
            /* update indexer */
            indexer += hbmp.Width;
        }
        /* unlock bitmap */
        L_ReleaseBitmap(&hbmp);
        /* do release operation */
        GlobalUnlock(hbuf);
        GlobalFree(hbuf);
    }
    /* free bitmap */
    L_FreeBitmap(&hbmp);
    return TRUE;
}

 
#4 Posted : Sunday, June 18, 2006 12:56:03 AM(UTC)

Bashar  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

Yes, this method is also good.  I actually forgot to mention it.

 
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-2024, Yet Another Forum.NET
This page was generated in 0.069 seconds.