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. Creating a color table

Creating a color table

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsjsonhelpquestion
2 Posts 2 Posters 0 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.
  • T Offline
    T Offline
    TheDelChop
    wrote on last edited by
    #1

    Hi guys, I am trying to use the Win32 API to fill a bitmap, using the function GetDIBBits(). My source bitmap is a 32-bit image, but I am hoping to create a 4-bit destination bitmap. I am of the understanding that this requires me to create a color table, and keep it in a BITMAPINFO structure. Does anybody see a problem with this snippet of code? pbmi = (PBITMAPINFO) LocalAlloc(LPTR,sizeof(BITMAPINFO)); // Initialize the fields in the BITMAPINFO structure. pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER) + 16*sizeof(long); pbmi->bmiHeader.biWidth = bmp.bmWidth; pbmi->bmiHeader.biHeight = bmp.bmHeight; pbmi->bmiHeader.biPlanes = bmp.bmPlanes; pbmi->bmiHeader.biBitCount = 4; pbmi->bmiHeader.biCompression = BI_RGB; if (pbmi->bmiHeader.biSizeImage == 0) pbmi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)pbmi->bmiHeader.biWidth * pbmi->bmiHeader.biBitCount) * pbmi->bmiHeader.biHeight; pbmi->bmiHeader.biClrImportant = 0; for(i = 0; i<16; i++) { pbmi->bmiColors[i].rgbRed = 0; pbmi->bmiColors[i].rgbBlue = 0; pbmi->bmiColors[i].rgbGreen = 0; pbmi->bmiColors[i].rgbReserved = 0; } // Bright Red pbmi->bmiColors[1].rgbRed = 255; // Red pbmi->bmiColors[2].rgbRed = 128; // Bright Green pbmi->bmiColors[3].rgbGreen = 255; // Green pbmi->bmiColors[4].rgbGreen = 128; // Bright Blue pbmi->bmiColors[5].rgbBlue = 255; // Blue pbmi->bmiColors[6].rgbBlue = 128; //Yellow pbmi->bmiColors[7].rgbRed = 255; pbmi->bmiColors[7].rgbGreen = 255; //Brown pbmi->bmiColors[8].rgbRed = 128; pbmi->bmiColors[8].rgbGreen = 128; //Bright Magenta pbmi->bmiColors[9].rgbRed = 255; pbmi->bmiColors[9].rgbBlue = 255; //Magenta pbmi->bmiColors[10].rgbRed = 128; pbmi->bmiColors[10].rgbBlue = 128; //Bright Cyan pbmi->bmiColors[11].rgbGreen = 255; pbmi->bmiColors[11].rgbBlue = 255; //Cyan pbmi->bmiColors[12].rgbGreen = 128; pbmi->bmiColors[12].rgbBlue = 128; //Gray pbmi->bmiColors[13].rgbRed = 0; pbmi->bmiColors[13].rgbGreen = 128; pbmi->bmiColors[13].rgbBlue = 0; //Bright Gray pbmi->bmiColors[14].rgbRed = 192; pbmi->bmiColors[14].rgb

    C 1 Reply Last reply
    0
    • T TheDelChop

      Hi guys, I am trying to use the Win32 API to fill a bitmap, using the function GetDIBBits(). My source bitmap is a 32-bit image, but I am hoping to create a 4-bit destination bitmap. I am of the understanding that this requires me to create a color table, and keep it in a BITMAPINFO structure. Does anybody see a problem with this snippet of code? pbmi = (PBITMAPINFO) LocalAlloc(LPTR,sizeof(BITMAPINFO)); // Initialize the fields in the BITMAPINFO structure. pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER) + 16*sizeof(long); pbmi->bmiHeader.biWidth = bmp.bmWidth; pbmi->bmiHeader.biHeight = bmp.bmHeight; pbmi->bmiHeader.biPlanes = bmp.bmPlanes; pbmi->bmiHeader.biBitCount = 4; pbmi->bmiHeader.biCompression = BI_RGB; if (pbmi->bmiHeader.biSizeImage == 0) pbmi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)pbmi->bmiHeader.biWidth * pbmi->bmiHeader.biBitCount) * pbmi->bmiHeader.biHeight; pbmi->bmiHeader.biClrImportant = 0; for(i = 0; i<16; i++) { pbmi->bmiColors[i].rgbRed = 0; pbmi->bmiColors[i].rgbBlue = 0; pbmi->bmiColors[i].rgbGreen = 0; pbmi->bmiColors[i].rgbReserved = 0; } // Bright Red pbmi->bmiColors[1].rgbRed = 255; // Red pbmi->bmiColors[2].rgbRed = 128; // Bright Green pbmi->bmiColors[3].rgbGreen = 255; // Green pbmi->bmiColors[4].rgbGreen = 128; // Bright Blue pbmi->bmiColors[5].rgbBlue = 255; // Blue pbmi->bmiColors[6].rgbBlue = 128; //Yellow pbmi->bmiColors[7].rgbRed = 255; pbmi->bmiColors[7].rgbGreen = 255; //Brown pbmi->bmiColors[8].rgbRed = 128; pbmi->bmiColors[8].rgbGreen = 128; //Bright Magenta pbmi->bmiColors[9].rgbRed = 255; pbmi->bmiColors[9].rgbBlue = 255; //Magenta pbmi->bmiColors[10].rgbRed = 128; pbmi->bmiColors[10].rgbBlue = 128; //Bright Cyan pbmi->bmiColors[11].rgbGreen = 255; pbmi->bmiColors[11].rgbBlue = 255; //Cyan pbmi->bmiColors[12].rgbGreen = 128; pbmi->bmiColors[12].rgbBlue = 128; //Gray pbmi->bmiColors[13].rgbRed = 0; pbmi->bmiColors[13].rgbGreen = 128; pbmi->bmiColors[13].rgbBlue = 0; //Bright Gray pbmi->bmiColors[14].rgbRed = 192; pbmi->bmiColors[14].rgb

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      TheDelChop wrote:

      Am I missing something here?

      Yes, you didn't allocate memory for the colour entries (pbmi->bmiColors[]). You have to do:

      pbmi = (PBITMAPINFO) LocalAlloc(LPTR, sizeof(BITMAPINFO) + 15 * sizeof(RGBQUAD));

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      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