Copying data from a raw image using c++ and objective c

时间:2022-12-05 19:29:03

I'm getting a callback from a library that gives me a raw image which is 640*480*4 R8G8B8A8

我从图书馆得到一个回调,给我一张640 * 480 * 4的原始图像R8G8B8A8

I did copying it into another buffer then I try to skip the 4th buffer because my framework works only with R8G8B8

我把它复制到另一个缓冲区,然后我尝试跳过第四个缓冲区,因为我的框架只适用于R8G8B8

I tried to debug and see the bytes in the variable d, but the bytes are all garbage.

我试图调试并查看变量d中的字节,但字节都是垃圾。

-(void)onRawImageBuffer:(NSData * _Nonnull)data withWidth:(int)width andHeight:(int)height andBytesPerPixel:(int)bytesPerPixel;
{
    NSUInteger len = [data length];



    memcpy(m_CopyData, [data bytes], len);


    for(int i =0; i < 640*480*3;i++)
    {
        if ( i%4 == 3 )
            continue;
        else{
            m_FrameData[i] = m_CopyData[i];

        }
    }

    NSData* d = [NSData dataWithBytes:(const void *)m_FrameData length:640*480*3];


    Input::SensorInput::getSingleton()->setVideoData( m_FrameData );



}

1 个解决方案

#1


1  

  1. You are hard coding width and height;
  2. 你很难编码宽度和高度;
  3. Your loop must still go to width * height * 4;
  4. 你的循环必须仍然是宽*高* 4;
  5. You have not allocated m_FrameData;
  6. 你还没有分配m_FrameData;
  7. You are not considering bytesPerPixel;
  8. 你没有考虑bytesPerPixel;
  9. continue; still advance i by one, you must use two indices;
  10. 继续;仍然一个接一个,你必须使用两个指数;
  11. It's very inefficient, better copy RGB together, skip A, advance src pointer by 4 and dst pointer by 3.
  12. 这是非常低效的,更好地将RGB复制在一起,跳过A,将src指针提前4,将dst指针提高3。

#1


1  

  1. You are hard coding width and height;
  2. 你很难编码宽度和高度;
  3. Your loop must still go to width * height * 4;
  4. 你的循环必须仍然是宽*高* 4;
  5. You have not allocated m_FrameData;
  6. 你还没有分配m_FrameData;
  7. You are not considering bytesPerPixel;
  8. 你没有考虑bytesPerPixel;
  9. continue; still advance i by one, you must use two indices;
  10. 继续;仍然一个接一个,你必须使用两个指数;
  11. It's very inefficient, better copy RGB together, skip A, advance src pointer by 4 and dst pointer by 3.
  12. 这是非常低效的,更好地将RGB复制在一起,跳过A,将src指针提前4,将dst指针提高3。