symisc/sod

Not an issue

ridams opened this issue · 3 comments

How should we convert an AVFrame (ffmpeg decoding result in RGB format) to sod_img ?

You should probably create an empty image via sod_make_image() and fill each RGB pixel via sod_img_set_pixel() as follows:

sod_img img = sod_make_image(640, 580, 3/* RGB*/);
for(int i = 0; i < img.w ; i++){
for(int j = 0; j < img.h; j++){
sod_img_set_pixel(img, i, j, 0 /*RED*/, val);
sod_img_set_pixel(img, i, j, 1 /*GREEN*/, val);
sod_img_set_pixel(img, i, j, 2 /*BLUE*/, val);
}
}

Thanks for reply, It should work but I tried this way :
av_image_copy_to_buffer(buf, size,(const uint8_t * const *)pFrame->data,
(const int *)pFrame->linesize,pFrame->format,width,height, 1);

then sod_img img=sod_img_load_from_mem((const unsigned char*)buf,size,1);

img.data is NULL
buf here is a raw image so does sod_img_load_from_mem accept a raw data without a header ?
cause the 1st method is slow

sod_img_load_from_mem() require an image header such as PNG, JPEG, BMP, PPM, etc. to be present in order to decode the image into raw pixels. If you already have your raw pixels decoded, you should use the solution above which is quite fast for most scenarios.