0

I want to convert the yuv420p image into RGB24 through libyuv, but the converted image is blue as a whole. I want to know why and go and correct it, thank you! Converted image

Original image

my code:

 const int width = 1280, height = 720;
FILE *src_file = fopen("1280x720.yuv", "rb");
FILE *dst_file = fopen("1280x720.rgb", "wb");

int size_src = width * height * 3 / 2;
int size_dest = width * height * 4;
char *buffer_src = (char *)malloc(size_src);
char *buffer_dest = (char *)malloc(size_dest);

uint64_t start_time = os_gettime_ns();
while (1)
{
    if (fread(buffer_src, 1, size_src, src_file) != size_src)
    {
        break;
    }
    libyuv::I420ToRGB24((const uint8*)buffer_src, width,
        (const uint8*)(buffer_src + width * height), width / 2,
        (const uint8*)(buffer_src + width * height * 5 / 4), width / 2,
        (uint8*)buffer_dest, width * 3,
        width, height);
    fwrite(buffer_dest, 1, size_dest, dst_file);
    fflush(dst_file);
}
uint64_t stop_time = os_gettime_ns();
printf("------ %ld \n", stop_time - start_time);

free(buffer_src);
free(buffer_dest);
//fclose(dst_file);
fclose(src_file);
return 0;

1 Answers1

1

Try it: Replace libyuv::I420ToRGB24 with libyuv::I420ToRAW.

Because the color layout in libyuv: RGB24 is B,G,R in memory. RAW is R,G,B in memory.

techboy
  • 11
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 08 '22 at 04:31
  • Just a note for anyone else like me confused about where they specified the layouts in memory: it's here https://chromium.googlesource.com/libyuv/libyuv/+/refs/heads/main/docs/formats.md#rgb24-and-raw – Eisverygoodletter Dec 24 '22 at 08:11