Pixel formats, CVPixelBufferRefs and glReadPixels

后端 未结 5 2051
太阳男子
太阳男子 2020-12-15 13:16

I\'m using glReadPixels to read data into a CVPixelBufferRef. I use the CVPixelBufferRef as the input into an AVAssetWriter

5条回答
  •  被撕碎了的回忆
    2020-12-15 14:16

    Regarding the bit manipulation, you can get a pointer to the pixel buffer's raw data:

    CVPixelBufferLockBaseAddress(buffer, 0);
    size_t stride = CVPixelBufferGetBytesPerRow(buffer);
    char *data = (char *)CVPixelBufferGetBaseAddress(buffer);
    for (size_t y = 0; y < CVPixelBufferGetHeight(buffer); ++y) {
        uint32_t *pixels = (uint32_t *)(data + stride * y);
        for (size_t x = 0; x < CVPixelBufferGetWidth(buffer); ++x)
            pixels[x] = (pixels[x] >> 8) | (pixels[x] << 24);
    }
    CVPixelBufferUnlockBaseAddress(buffer, 0);
    

提交回复
热议问题