Can anyone help me with a minimum working example of displaying one frame of YCbCr 4:2:0
This is what I have:
#include “SDL.h”
#include <stdio.h>
int main(int argc, char* argv[]) {
FILE* fd;
Uint8* raw;
Uint32 W = 352;
Uint32 H = 288;
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_Texture *texture = NULL;
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow( “YCbCr”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, W, H, SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, W, H);
fd = fopen(“foreman_cif.yuv”, “rb”);
raw = malloc(sizeof(Uint8) * 152064);
fread(raw, sizeof(Uint8), 152064, fd);
SDL_UpdateTexture(texture, NULL, raw, W * SDL_BYTESPERPIXEL(SDL_PIXELFORMAT_YV12));
// If I insted of the above use the below it works! Function is however only valid for YV12 or IYUV
// according to docs SDL_UpdateTexture() should work for all YCbCr-formats as long as they’re
// contiguous in memory. The pitch parameter though, I don’t get due to the subsampling of the chroma-planes…
// SDL_UpdateYUVTexture(texture, NULL, &raw[0], 352, &raw[352288], 176, &raw[352288+352*288/4], 176);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
SDL_Delay(3000);
free(raw);
SDL_DestroyWindow(window);
SDL_DestroyRenderer(renderer);
SDL_DestroyTexture(texture);
// Clean up
SDL_Quit();
return EXIT_SUCCESS;
}
I compile it with:
gcc -o yv yv.c -std=c99 $(sdl2-config --cflags --libs)
The output is however broken, see http://imgur.com/53YBxpL,u0Jj5K5#1
YCbCr 4:2:0 test-sequences can be downloaded from http://trace.eas.asu.edu/yuv/
I sort of given up on my problem in https://forums.libsdl.org/viewtopic.php?t=9996
Now I’m just trying to get 2.0.x to work properly…