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. Bluebox - Chromakey etc

Bluebox - Chromakey etc

Scheduled Pinned Locked Moved C / C++ / MFC
question
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.
  • P Offline
    P Offline
    Pixinger77
    wrote on last edited by
    #1

    Hello I'm looking for a fast way to scan a buffer and check if a pixel color is between a color range, or not. Maybe some code explains it better: I have a buffer with 32Bits per Pixel (RGBA => R=8Bit, G=8Bit, B=8Bit, A=8Bit => 32Bit). This buffer is... let's say 200x200 pixels.

    // Defining color ranges
    char redUpper = 100;
    char redLower = 50;
    char greenUpper = 150;
    char greenLower = 130;
    char blueUpper = 20;
    char blueLower = 10;

    //creating my pixel buffer
    int* pBuffer = new int[200*200];
    fillBufferWithData(pBuffer, 200*200); //some magic function the gets the image data into the buffer.

    //analysing
    char* pCursor = (char*)pBuffer;
    for (int i = 0; i < 200*200; i++)
    {
    //Every Pixel that is between the color range...
    if ((pCursor[0] > redLower) && (pCursor[0] < redUpper)
    && (pCursor[1] > greenLower) && (pCursor[1] < greenUpper)
    && (pCursor[2] > blueLower) && (pCursor[2] < blueUpper))
    {
    pCursor[3] = 0;
    }
    else
    {
    pCursor[3] = 255
    }

    pCursor += 4;
    }
    delete [] pBuffer;

    Okay. I hope that helps to understand what i want to do. I know thats not the fastest way (at least I hope so). Maybe someone knows a better way, perhaps with bit-shifting, or bit-masking? Thanks in advance, SnowProg

    CPalliniC 1 Reply Last reply
    0
    • P Pixinger77

      Hello I'm looking for a fast way to scan a buffer and check if a pixel color is between a color range, or not. Maybe some code explains it better: I have a buffer with 32Bits per Pixel (RGBA => R=8Bit, G=8Bit, B=8Bit, A=8Bit => 32Bit). This buffer is... let's say 200x200 pixels.

      // Defining color ranges
      char redUpper = 100;
      char redLower = 50;
      char greenUpper = 150;
      char greenLower = 130;
      char blueUpper = 20;
      char blueLower = 10;

      //creating my pixel buffer
      int* pBuffer = new int[200*200];
      fillBufferWithData(pBuffer, 200*200); //some magic function the gets the image data into the buffer.

      //analysing
      char* pCursor = (char*)pBuffer;
      for (int i = 0; i < 200*200; i++)
      {
      //Every Pixel that is between the color range...
      if ((pCursor[0] > redLower) && (pCursor[0] < redUpper)
      && (pCursor[1] > greenLower) && (pCursor[1] < greenUpper)
      && (pCursor[2] > blueLower) && (pCursor[2] < blueUpper))
      {
      pCursor[3] = 0;
      }
      else
      {
      pCursor[3] = 255
      }

      pCursor += 4;
      }
      delete [] pBuffer;

      Okay. I hope that helps to understand what i want to do. I know thats not the fastest way (at least I hope so). Maybe someone knows a better way, perhaps with bit-shifting, or bit-masking? Thanks in advance, SnowProg

      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      Due to short-circuit of the boolean operations inside the if statement, the code is reasonably fast. Maybe using three look-up tables will improve the code speed, but I'm not an expert. :)

      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.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      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