2
안녕하세요 저는 다음 함수를 사용하여 sampleBuffer를 잘 작동하는 OpenGL 텍스처에 바인딩합니다.IOS 배열을 두 번 배열하는 memcpy
void *imageData;
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
UIImage * image = [self generateUIImageFromSampleBuffer:sampleBuffer];
if(imageData == NULL){
width = CGImageGetWidth(image.CGImage);
height = CGImageGetHeight(image.CGImage);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
imageData = malloc(height * width * 4);
imgcontext = CGBitmapContextCreate(imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
}
CGContextClearRect(imgcontext, CGRectMake(0, 0, width, height));
CGContextTranslateCTM(imgcontext, 0, height - height);
CGContextDrawImage(imgcontext, CGRectMake(0, 0, width, height), image.CGImage);
glBindTexture(GL_TEXTURE_2D, m_textureId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
}
내 질문에 내가 루프를 할 수 있도록 모든 픽셀이 다른 프로세스에 어떤 처리를 할하지만 이중 배열에 imageData의 복사하려고하는 메신저입니다. 여기 내가 사용하고있는 코드는 나에게 내가 기대하는 결과를주지 않는 것이다. 텍스처가 결합하지만, R, G, B 값을 변경되지 않습니다 후
double data[width * height * 4];
memcpy(data, imageData, width * height * 4);
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x += 4)
{
double r = data[ y * width + x];
double g = data[ y * width + x + 1];
double b = data[ y * width + x + 2];
double a = data[ y * width + x + 3];
}
}
이 코드
는 직접 호출되고있다. 어떤 아이디어 내가 뭘 잘못건배
을 그리고 그 "4 바이트 정수는"정말 네 개의 개별 번호, 픽셀 (빨강, 녹색, 파랑, 알파)의 각 구성 요소의 하나입니다 :
다음 게시물이 도움이 될 수 있습니다. 서로 다른 크기와 함께 다른 형식 (정수와 부동 소수점) 인 'int'와 'double'문제도 있습니다. 이러한 두 가지 이유 때문에 각 구성 요소를 별도의 'double'값으로 변환해야합니다. –