Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. c libraries needed to deal with bitmaps

c libraries needed to deal with bitmaps

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
32 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Please use proper <pre> tags around code blocks (and proper indentation), not Quoted text. The following code sample is preceded by <pre lang="c++"> and followed by </pre>

    // Calculate the number of palette entries.
    m_nPaletteEntries = 1 << m_pBIH->biBitCount;
    if( m_pBIH->biBitCount > 8 )
    m_nPaletteEntries = 0;
    else if( m_pBIH->biClrUsed != 0 )
    m_nPaletteEntries = m_pBIH->biClrUsed;

    Much more readable.

    C Offline
    C Offline
    Calin Negru
    wrote on last edited by
    #20

    I`m having trouble understanding how this code works. The problem is I`m not a c expert.

    cf.Read( &BFH, sizeof( BITMAPFILEHEADER )

    For instance how does the portion of data read from my file fits into a structure. It`s not a structure of identical items BITMAPFILEHEADER is a mix of WORDs and DWORDS

    L 1 Reply Last reply
    0
    • C Calin Negru

      I`m having trouble understanding how this code works. The problem is I`m not a c expert.

      cf.Read( &BFH, sizeof( BITMAPFILEHEADER )

      For instance how does the portion of data read from my file fits into a structure. It`s not a structure of identical items BITMAPFILEHEADER is a mix of WORDs and DWORDS

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #21

      The sizeof operator gives the number of bytes in the object referred to. So in your case it will be the size of a BITMAPFILEHEADER, and the read operation will read the correct number of bytes into the structure. When complete each field of the structure should be correctly aligned*. *There are conditions where this may not be true, so beware if you have a structure containing single byte elements. You may ignore that for the moment.

      C 1 Reply Last reply
      0
      • L Lost User

        The sizeof operator gives the number of bytes in the object referred to. So in your case it will be the size of a BITMAPFILEHEADER, and the read operation will read the correct number of bytes into the structure. When complete each field of the structure should be correctly aligned*. *There are conditions where this may not be true, so beware if you have a structure containing single byte elements. You may ignore that for the moment.

        C Offline
        C Offline
        Calin Negru
        wrote on last edited by
        #22

        thanks that makes sense. In the code above do I need m_nPaletteEntries at all? Is used to calculate the offset at which individual pixels are stored?

        L 1 Reply Last reply
        0
        • C Calin Negru

          thanks that makes sense. In the code above do I need m_nPaletteEntries at all? Is used to calculate the offset at which individual pixels are stored?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #23

          You need to examine the different items in the info table as described at BITMAPINFOHEADER structure (Windows) | Microsoft Docs[^]. The values of the items related to colours will tell you whether a colour table is included or not.

          C 1 Reply Last reply
          0
          • L Lost User

            You need to examine the different items in the info table as described at BITMAPINFOHEADER structure (Windows) | Microsoft Docs[^]. The values of the items related to colours will tell you whether a colour table is included or not.

            C Offline
            C Offline
            Calin Negru
            wrote on last edited by
            #24

            I have to take a short break. Your insight (last post included) is priceless Richard, thanks

            `DreamLand Page` is my projects facebook page.

            L 1 Reply Last reply
            0
            • C Calin Negru

              I have to take a short break. Your insight (last post included) is priceless Richard, thanks

              `DreamLand Page` is my projects facebook page.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #25

              Sorry to disappoint you, but my 'insight' is actually just a matter of reading the documentation.

              C 1 Reply Last reply
              0
              • L Lost User

                Sorry to disappoint you, but my 'insight' is actually just a matter of reading the documentation.

                C Offline
                C Offline
                Calin Negru
                wrote on last edited by
                #26

                the code you quoted is the bit that throws me into fog. What does the line that has the overload operator do?

                L 1 Reply Last reply
                0
                • C Calin Negru

                  the code you quoted is the bit that throws me into fog. What does the line that has the overload operator do?

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #27

                  fearless_ wrote:

                  What does the line that has the overload operator do?

                  What line?

                  C 1 Reply Last reply
                  0
                  • L Lost User

                    fearless_ wrote:

                    What does the line that has the overload operator do?

                    What line?

                    C Offline
                    C Offline
                    Calin Negru
                    wrote on last edited by
                    #28

                    m_nPaletteEntries = 1 << m_pBIH->biBitCount;

                    P 1 Reply Last reply
                    0
                    • C Calin Negru

                      m_nPaletteEntries = 1 << m_pBIH->biBitCount;

                      P Offline
                      P Offline
                      phil o
                      wrote on last edited by
                      #29

                      This is a bitwise left-shift operation which is equivalent to

                      m_nPaletteEntries = pow(2, m_pBIH->biBitCount); // 2 to the power of bpp

                      What are shift operators in C++?[^] This trick is used quite often, since a bitwise shift operation is way quicker than the pow() method, which is rather intense on processing time. Edit: here's an interesting list of useful bitwise tricks: Bit Twiddling Hacks[^]

                      "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

                      L 1 Reply Last reply
                      0
                      • P phil o

                        This is a bitwise left-shift operation which is equivalent to

                        m_nPaletteEntries = pow(2, m_pBIH->biBitCount); // 2 to the power of bpp

                        What are shift operators in C++?[^] This trick is used quite often, since a bitwise shift operation is way quicker than the pow() method, which is rather intense on processing time. Edit: here's an interesting list of useful bitwise tricks: Bit Twiddling Hacks[^]

                        "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #30

                        It's not pow, it's multiply by 2.

                        P 1 Reply Last reply
                        0
                        • L Lost User

                          It's not pow, it's multiply by 2.

                          P Offline
                          P Offline
                          phil o
                          wrote on last edited by
                          #31

                          For a left-shift by a single bit, yes, a multiplication by 2. But a left-shift by n bits, in the end, is the same as a multiplication by 2 to the power of n; since original value is 1, this leads to 2 to the power of n. Or am I missing something?

                          "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

                          L 1 Reply Last reply
                          0
                          • P phil o

                            For a left-shift by a single bit, yes, a multiplication by 2. But a left-shift by n bits, in the end, is the same as a multiplication by 2 to the power of n; since original value is 1, this leads to 2 to the power of n. Or am I missing something?

                            "Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #32

                            I found myself thinking about this when I woke up this morning and you are, of course, quite correct.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups