From 5efccce2a9191ded328233ab68a0767661a26679 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Mon, 27 Apr 2009 23:20:30 +0000 Subject: [PATCH] Implement av_get_bits_per_pixel(). Originally committed as revision 18709 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/pixdesc.c | 13 +++++++++++++ libavcodec/pixdesc.h | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/libavcodec/pixdesc.c b/libavcodec/pixdesc.c index 162b5826d..a313c95cf 100644 --- a/libavcodec/pixdesc.c +++ b/libavcodec/pixdesc.c @@ -581,3 +581,16 @@ const AVPixFmtDescriptor av_pix_fmt_descriptors[PIX_FMT_NB] = { .flags = PIX_FMT_BE, }, }; + +int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc) +{ + int c, bits = 0; + int log2_pixels = pixdesc->log2_chroma_w + pixdesc->log2_chroma_h; + + for (c = 0; c < pixdesc->nb_channels; c++) { + int s = c==1 || c==2 ? 0 : log2_pixels; + bits += (pixdesc->comp[c].depth_minus1+1) << s; + } + + return bits >> log2_pixels; +} diff --git a/libavcodec/pixdesc.h b/libavcodec/pixdesc.h index 6660ea171..0a2acab71 100644 --- a/libavcodec/pixdesc.h +++ b/libavcodec/pixdesc.h @@ -193,4 +193,14 @@ static inline void write_line(const uint16_t *src, uint8_t *data[4], const int l } } +/** + * Returns the number of bits per pixel used by the pixel format + * described by pixdesc. + * + * The returned number of bits refers to the number of bits actually + * used for storing the pixel information, that is padding bits are + * not counted. + */ +int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc); + #endif /* AVCODEC_PIXDESC_H */ -- 2.11.0