Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6761371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:10:50+00:00 2026-05-26T14:10:50+00:00

I have an image i.e. drawn using Windows GDI calls (24 bpp) and I

  • 0

I have an image i.e. drawn using Windows GDI calls (24 bpp) and I need to convert this image to 16 bpp. This is on Windows Mobile.

 24 bpp - RGB (rrrrrrrr gggggggg bbbbbbbb)
 16 bpp - RGB (rrrrr gggggg bbbbb)

For this I am using the below code

for (int x = 0; x < iScreenSize; x++)
{
    *iPixel1= (*iPixel & 0x0000001F) |
              (*iPixel & 0x00003F00) >> 3 | 
              (*iPixel & 0x001F0000) >> 5;
}

The code works fine but the performance is not that good since I am modifying pixel by pixel.
Can you suggest any possible improvements to this conversion?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:10:51+00:00Added an answer on May 26, 2026 at 2:10 pm

    Your code isn’t complete; you don’t show the types of the pointers or how you’re incrementing them. The number of operations you perform per pixel looks pretty optimal, so I’m going to guess that any slowness comes from unaligned memory access. You can fix this by unrolling the loop and doing 4 pixels at a time. Also the compiler should be smart enough to optimize multiple accesses to the same pointer, but lets assume it doesn’t and copy them to temporary variables instead. I’m also going to assume you want to keep the upper bits of each color channel rather than the lower bits in your sample code.

    UINT32 * iPixel;
    UINT16 * iPixel1;
    for (int x = 0; x < iScreenSize; x+=4)
    {
        UINT32 dw1 = *iPixel++;
        UINT32 dw2 = *iPixel++;
        UINT32 dw3 = *iPixel++;
        *iPixel1++ = (dw1 & 0x000000F8) >> 3 |
                     (dw1 & 0x0000FC00) >> 5 |
                     (dw1 & 0x00F80000) >> 8;
        *iPixel1++ = (dw1 & 0xF8000000) >> 27 |
                     (dw2 & 0x000000FC) << 3 |
                     (dw2 & 0x0000F800);
        *iPixel1++ = (dw2 & 0x00F80000) >> 19 |
                     (dw2 & 0xFC000000) >> 21 |
                     (dw3 & 0x000000F8) << 8;
        *iPixel1++ = (dw3 & 0x0000F800) >> 11 |
                     (dw3 & 0x00FC0000) >> 13 |
                     (dw3 & 0xF8000000) >> 16;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a raw image buffer in the RGB format. I need to draw
I have a need to do some drawing using win32/GDI (Native, not .NET), and
I need to draw a .png image on an UIView. I have no clue
So I have Image like this (source: de-viz.ru ) I want to get something
I have created a window with createwindow() api using VS2005 in C++ on Windows
I have the following code. QString fileName = QFileDialog::getSaveFileName( this, tr(Output Image file), (),
I'm having a problem using custom components at runtime. I have this custom FlowLayoutPanel
The eventual aim of this is to have a splash screen in windows that
I have a problem with MFC dialog boxes that are drawn using derived MFC
I have an image. Over it I draw a semi transparent polygon. Over the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.