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. WHat do i do when a struct requires a "RGBQUAD [1]" type?

WHat do i do when a struct requires a "RGBQUAD [1]" type?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
3 Posts 3 Posters 5 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.
  • R Offline
    R Offline
    redeemer
    wrote on last edited by
    #1

    The BITMAPINFO struct is defined as follows:

    typedef struct tagBITMAPINFO {
    BITMAPINFOHEADER bmiHeader;
    RGBQUAD bmiColors[1];
    } BITMAPINFO, *PBITMAPINFO;

    It's the bmiColors[1] property i'm confused about. This requires an array to RGBQUAD structs and all i have is a pointer to an array of them, how do i use the pointer when it wants an array? Thanks

    J L 2 Replies Last reply
    0
    • R redeemer

      The BITMAPINFO struct is defined as follows:

      typedef struct tagBITMAPINFO {
      BITMAPINFOHEADER bmiHeader;
      RGBQUAD bmiColors[1];
      } BITMAPINFO, *PBITMAPINFO;

      It's the bmiColors[1] property i'm confused about. This requires an array to RGBQUAD structs and all i have is a pointer to an array of them, how do i use the pointer when it wants an array? Thanks

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

      MSDN : The RGBQUAD structure describes a color consisting of relative intensities of red, green, and blue. typedef struct tagRGBQUAD { // rgbq BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; } RGBQUAD; Members rgbBlue Specifies the intensity of blue in the color. rgbGreen Specifies the intensity of green in the color. rgbRed Specifies the intensity of red in the color. rgbReserved Reserved; must be zero. Remarks The bmiColors member of the BITMAPINFO structure consists of an array of RGBQUAD structures. And keep in mind that an array is a pointer! u can always write: int a[5]; a[1] = 2; *(a+1) = 3; // Means a[1] = 3; Papa Murex Co.

      1 Reply Last reply
      0
      • R redeemer

        The BITMAPINFO struct is defined as follows:

        typedef struct tagBITMAPINFO {
        BITMAPINFOHEADER bmiHeader;
        RGBQUAD bmiColors[1];
        } BITMAPINFO, *PBITMAPINFO;

        It's the bmiColors[1] property i'm confused about. This requires an array to RGBQUAD structs and all i have is a pointer to an array of them, how do i use the pointer when it wants an array? Thanks

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        This bmiColors is the tip of a variably-sized array of RGBQUADs. Suppose for instance your palette has nBmiColors entries, you'd allocate and stuff the thing like this:

        unsigned nBmiColors=256;
        BIMAPINFO* lpbmi=(BITMAPINFO *)malloc(
        sizeof(BITMAPINFO)+
        nBmiColors==0?0:(nBmiColors-1)*sizeof(RGBQUAD));
        for(unsigned n=0;n<nBmiColors;++n)
        {
        lpbmi->bmiColors[n]=...;
        }

        Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        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