xcc080414-08
ビンゴー。CVPixelBufferGetPixelFormatTypeが返すフォーマットが

k32ARGBPixelFormat

となりました。
これなら扱えそうなので、さっそく加工。フォーマットがk32ARGBPixelFormatの時だけ実行するようにして

static void
SGVideoDecompTrackingCallback(
.
.
.
OSType t = CVPixelBufferGetPixelFormatType(pixelBuffer);
if (t == k32ARGBPixelFormat) {
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
void* baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer);
int bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
int width = CVPixelBufferGetWidth(pixelBuffer);
int height = CVPixelBufferGetHeight(pixelBuffer);
unsigned char* top_p = (unsigned char*)baseAddress;
unsigned char* bottom_p = top_p + (height - 1) * bytesPerRow;
height = height / 2;
for (int v = 0; v < height; v++) {
memcpy(bottom_p, top_p, bytesPerRow);
bottom_p -= bytesPerRow;
top_p += bytesPerRow;
}
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
}
.
.
if (result == noErr)
[(SGVideo*)decompressionTrackingRefCon displayData:pixelBuffer
.
.
}

実行し、フォーマットをNONEにするとこうなる。

xcc080414-09

人類の夜明けだ。

次回は、最初からNone状態にする方法とか、カメラキャプチャ処理だけ抜き出したアプリを作ってみる。