On 28/08/14 15:59, Diego Biurrun wrote: > On Wed, Aug 27, 2014 at 04:43:52AM +0200, Luca Barbato wrote: >> --- a/libavdevice/x11grab.c >> +++ b/libavdevice/x11grab.c >> @@ -170,6 +170,59 @@ static int setup_shm(AVFormatContext *s, Display *dpy, >> XImage **image) >> >> +static int pixfmt_from_image(AVFormatContext *s, XImage *image, int >> *pix_fmt) >> +{ >> + switch (image->bits_per_pixel) { >> + case 8: >> + *pix_fmt = AV_PIX_FMT_PAL8; >> + break; >> + case 16: >> + if (image->red_mask == 0xf800 && >> + image->green_mask == 0x07e0 && >> + image->blue_mask == 0x001f) { >> + *pix_fmt = AV_PIX_FMT_RGB565; >> + } else if (image->red_mask == 0x7c00 && >> + image->green_mask == 0x03e0 && >> + image->blue_mask == 0x001f) { > > Here and .. > >> + *pix_fmt = AV_PIX_FMT_RGB555; >> + } >> + break; >> + case 24: >> + if (image->red_mask == 0xff0000 && >> + image->green_mask == 0x00ff00 && >> + image->blue_mask == 0x0000ff) { > > .. here and .. > >> + *pix_fmt = AV_PIX_FMT_BGR24; >> + } else if (image->red_mask == 0x0000ff && >> + image->green_mask == 0x00ff00 && >> + image->blue_mask == 0xff0000) { > > .. here there was previously some vertical alignment. > >> + *pix_fmt = AV_PIX_FMT_RGB24; >> + } >> + break; >> + case 32: >> + *pix_fmt = AV_PIX_FMT_RGB32; >> + break; >> + default: >> + av_log(s, AV_LOG_ERROR, >> + "XImages with RGB mask 0x%.6lx 0x%.6lx 0x%.6lx and depth %i " >> + "are currently not supported.\n", >> + image->red_mask, >> + image->green_mask, >> + image->blue_mask, >> + image->bits_per_pixel); >> + >> + return AVERROR_PATCHWELCOME; >> + } >> + >> + return 0; >> +} > > I still think it would be cleaner if you returned an enum AVPixelFormat > instead of int here.
Why? I want to set a value and know if it is correct, the alternative of returning NONE in case of error and the do a check on the value to return AVERROR_PATCHWELCOME isn't any nicer IMHO. lu _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel