简体   繁体   English

使用C ++和目标C从原始图像复制数据

[英]Copying data from a raw image using c++ and objective c

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. You are hard coding width and height; 您正在硬编码宽度和高度;
  2. Your loop must still go to width * height * 4 ; 您的循环必须仍为width * height * 4 ;
  3. You have not allocated m_FrameData ; 您尚未分配m_FrameData
  4. You are not considering bytesPerPixel ; 您没有考虑bytesPerPixel ;
  5. continue; still advance i by one, you must use two indices; 仍将i提前一,您必须使用两个索引;
  6. It's very inefficient, better copy RGB together, skip A, advance src pointer by 4 and dst pointer by 3. 这是非常低效的,最好一起复制RGB,跳过A,将src指针提高4,将dst指针提高3。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM