2017-08-25 1 views
-1

Ich möchte einen Hardware-Pixel-Puffer, der im Format X8B8G8R8 ist, in unsigned int 24-Bit-Speicherpuffer konvertieren.Convert X8B8G8R8 zu R8G8B8 C++ Code

Dies ist mein Versuch:

// pixels is uin32_t; 
src.pixels = new pixel_t[src.width*src.height]; 





    readbuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD); 
      const Ogre::PixelBox &pb = readbuffer->getCurrentLock(); 

      /// Update the contents of pb here 
      /// Image data starts at pb.data and has format pb.format 
      uint32 *data = static_cast<uint32*>(pb.data); 
      size_t height = pb.getHeight(); 
      size_t width = pb.getWidth(); 
      size_t pitch = pb.rowPitch; // Skip between rows of image 
      for (size_t y = 0; y<height; ++y) 
      { 
       for (size_t x = 0; x<width; ++x) 
       { 
        src.pixels[pitch*y + x] = data[pitch*y + x]; 
       } 
      } 
+0

So, welches Problem haben Sie zu konvertieren? – auburg

+0

Und das Ergebnis/Problem ist? – Matt

Antwort

0

Dies sollte

uint32_t BGRtoRGB(uint32_t col) { 
    return (col & 0x0000ff00) | ((col & 0x000000ff) << 16) | ((col & 0x00ff0000) >> 16) 
} 

Mit

src.pixels[pitch*y + x] = BGRtoRGB(data[pitch*y + x]); 

Hinweis tun: BGRtoRGB in beide Richtungen hier wandelt, wenn Sie es wollen, aber es merken wirft alles weg, was Sie in den X8 Bits (Alpha?) haben, aber es sho halten Sie die Werte selbst.

Um umgekehrt mit einem Alpha von 0xff

uint32_t RGBtoXBGR(uint32_t col) { 
    return 0xff000000 | (col & 0x0000ff00) | ((col & 0x000000ff) << 16) | ((col & 0x00ff0000) >> 16) 
} 
+0

Danke. Ich habe noch etwas anderes. Wie würde ich zurück rgb in xbgr konvertieren – andre

+0

Richtig, konvertiert diese Funktion beide Wege, würde aber die höheren Bits wegwerfen ('X8'?). Sie müssten diese 8 Bits von irgendwo bekommen. – N00byEdge

+0

Wenn Sie die 8 höheren Bits in der konvertierten Zahl behalten möchten (ich bin mir nicht sicher, wie Sie das verwenden, um es zu analysieren), ändern Sie die erste Bitmaske von '0x0000ff00' in' 0xff00ff00' Wenn Sie das tun es wäre vollkommen symmetrisch. – N00byEdge