Problems when scaling a YUV image using libyuv library

前端 未结 5 888
滥情空心
滥情空心 2021-01-07 17:12

I\'m developing a camera app based on Camera API 2 and I have found several problems using the libyuv. I want to convert YUV_420_888 images retriev

5条回答
  •  天涯浪人
    2021-01-07 17:33

    gmetax is almost correct.

    You are using the size of the entire array where you should be using the size of the Y component, which is src_width * src_height.

    gmetax's answer is wrong in that he has put y_size in place of out_size when defining the output frame. The correct code snippet, I believe, would look like:

    //Get input and output length
    int input_size = env->GetArrayLength(yuvByteArray_);
    int y_size = src_width * src_height;
    int out_size = out_height * out_width;
    
    //Generate input frame
    i420_input_frame.width = src_width;
    i420_input_frame.height = src_height;
    i420_input_frame.data = (uint8_t *) yuvByteArray;
    i420_input_frame.y = i420_input_frame.data;
    i420_input_frame.u = i420_input_frame.y + y_size;
    i420_input_frame.v = i420_input_frame.u + y_size / 4;
    
    //Generate output frame
    free(i420_output_frame.data);
    i420_output_frame.width = out_width;
    i420_output_frame.height = out_height;
    i420_output_frame.data = new unsigned char[out_size * 3 / 2];
    i420_output_frame.y = i420_output_frame.data;
    i420_output_frame.u = i420_output_frame.y + out_size;
    i420_output_frame.v = i420_output_frame.u + out_size / 4;
    

提交回复
热议问题