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

  • Home
  • SEARCH
  • 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 9134375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:38:55+00:00 2026-06-17T08:38:55+00:00

I am writting a C++ command line application that will apply the Haar transform

  • 0

I am writting a C++ command line application that will apply the Haar transform to the pixels of a bmp image. I have successfully been able to extract the header information and determine the byte array size for the pixels. After filling a char[pixelHeight][rowSizeInBytes] with the pixel data from the file, I am reading each pixel (24 bits for the bmp I’m using) into a vector. It is working on my machine but I would like to know if my implementation for converting the char array representing a pixel into an unsigned int is safe and/or the idiomatic C++ way. I am assuming a little endian architecture.

unsigned char pixelData[infoHeader->pixelHeight][rowSize];
fseek(pFile, basicHeader->pixelDataOffset, SEEK_SET);
fread(&pixelData, pixelArraySize, 1, pFile);

for(int row = 0; row < infoHeader->pixelHeight; row++)
{
    for(int i = 0; i < rowSize; i = i + 3)
    {
        unsigned char blue = pixelData[row][i];
        unsigned char green = pixelData[row][i + 1];
        unsigned char red = pixelData[row][i + 2];

        char vals[4];
        vals[0] = blue;
        vals[1] = green;
        vals[2] = red;
        vals[3] = '\0';

        unsigned int pixelVal = *((unsigned int *)vals);

        pixelVec.push_back(pixelVal);
    }
}
  • 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-06-17T08:38:56+00:00Added an answer on June 17, 2026 at 8:38 am

    No, this is unidiomatic. You should code what you mean rather than relying on the endianness of the system. For example:

     unsigned int pixelVal = static_cast<unsigned int>(blue) |
         (static_cast<unsigned int>(green) << 8) |
         (static_cast<unsigned int>(red) << 16);
    

    This assumes your intention was to get a vector with specific values for unsigned integers. If your intention was to get a vector with specific bytes, you should use a vector of byte-sized structures, not unsigned integers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a .NET command-line application that will migrate users from an existing database
I'm writing a small Ruby command-line application that uses fileutils from the standard library
I'm writing an command line application which will take a lot of input from
Is there any application/project that provides you with a command line SQL client that
I am writing an application that sends command line commands to a 3rd party
Alright, what I need is a command-line application that allows you to take a
I am writing a Java application that takes command line arguments which are processed
I've got a command line application that starts up and does some work. During
I'm writing a command-line tool that will ultimately output an HTML report. The tool
Good day, I am writing a simple CLI (command-line interface) application that provides a

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.