X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=libavutil%2Fpixdesc.c;h=5cd7b32f2fbc80e58e5ed3bcb5a76671a3dd0f1d;hb=2268db2cd052674fde55c7d48b7a5098ce89b4ba;hp=bff45e522a5ab51839f7ef2f6e68900b4b4b681d;hpb=5c511ad4ce20aff96ec587de1a8be6f28aed4544;p=ffmpeg diff --git a/libavutil/pixdesc.c b/libavutil/pixdesc.c index bff45e522a5..5cd7b32f2fb 100644 --- a/libavutil/pixdesc.c +++ b/libavutil/pixdesc.c @@ -21,889 +21,1612 @@ #include #include + +#include "avstring.h" +#include "common.h" #include "pixfmt.h" #include "pixdesc.h" - +#include "internal.h" #include "intreadwrite.h" +#include "version.h" -void av_read_image_line(uint16_t *dst, const uint8_t *data[4], const int linesize[4], - const AVPixFmtDescriptor *desc, int x, int y, int c, int w, int read_pal_component) +void av_read_image_line(uint16_t *dst, + const uint8_t *data[4], const int linesize[4], + const AVPixFmtDescriptor *desc, + int x, int y, int c, int w, + int read_pal_component) { - AVComponentDescriptor comp= desc->comp[c]; - int plane= comp.plane; - int depth= comp.depth_minus1+1; - int mask = (1<flags; - - if (flags & PIX_FMT_BITSTREAM){ - int skip = x*step + comp.offset_plus1-1; - const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); - int shift = 8 - depth - (skip&7); - - while(w--){ + AVComponentDescriptor comp = desc->comp[c]; + int plane = comp.plane; + int depth = comp.depth; + int mask = (1 << depth) - 1; + int shift = comp.shift; + int step = comp.step; + int flags = desc->flags; + + if (flags & AV_PIX_FMT_FLAG_BITSTREAM) { + int skip = x * step + comp.offset; + const uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3); + int shift = 8 - depth - (skip & 7); + + while (w--) { int val = (*p >> shift) & mask; - if(read_pal_component) - val= data[1][4*val + c]; + if (read_pal_component) + val = data[1][4*val + c]; shift -= step; - p -= shift>>3; + p -= shift >> 3; shift &= 7; - *dst++= val; + *dst++ = val; } } else { - const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; + const uint8_t *p = data[plane] + y * linesize[plane] + + x * step + comp.offset; int is_8bit = shift + depth <= 8; if (is_8bit) - p += !!(flags & PIX_FMT_BE); + p += !!(flags & AV_PIX_FMT_FLAG_BE); - while(w--){ + while (w--) { int val = is_8bit ? *p : - flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p); - val = (val>>shift) & mask; - if(read_pal_component) - val= data[1][4*val + c]; - p+= step; - *dst++= val; + flags & AV_PIX_FMT_FLAG_BE ? AV_RB16(p) : AV_RL16(p); + val = (val >> shift) & mask; + if (read_pal_component) + val = data[1][4 * val + c]; + p += step; + *dst++ = val; } } } -void av_write_image_line(const uint16_t *src, uint8_t *data[4], const int linesize[4], - const AVPixFmtDescriptor *desc, int x, int y, int c, int w) +void av_write_image_line(const uint16_t *src, + uint8_t *data[4], const int linesize[4], + const AVPixFmtDescriptor *desc, + int x, int y, int c, int w) { AVComponentDescriptor comp = desc->comp[c]; int plane = comp.plane; - int depth = comp.depth_minus1+1; - int step = comp.step_minus1+1; + int depth = comp.depth; + int step = comp.step; int flags = desc->flags; - if (flags & PIX_FMT_BITSTREAM) { - int skip = x*step + comp.offset_plus1-1; - uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); - int shift = 8 - depth - (skip&7); + if (flags & AV_PIX_FMT_FLAG_BITSTREAM) { + int skip = x * step + comp.offset; + uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3); + int shift = 8 - depth - (skip & 7); while (w--) { *p |= *src++ << shift; shift -= step; - p -= shift>>3; + p -= shift >> 3; shift &= 7; } } else { int shift = comp.shift; - uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; + uint8_t *p = data[plane] + y * linesize[plane] + + x * step + comp.offset; if (shift + depth <= 8) { - p += !!(flags & PIX_FMT_BE); + p += !!(flags & AV_PIX_FMT_FLAG_BE); while (w--) { - *p |= (*src++<log2_chroma_w + pixdesc->log2_chroma_h; for (c = 0; c < pixdesc->nb_components; c++) { - int s = c==1 || c==2 ? 0 : log2_pixels; - bits += (pixdesc->comp[c].depth_minus1+1) << s; + int s = c == 1 || c == 2 ? 0 : log2_pixels; + bits += pixdesc->comp[c].depth << s; } return bits >> log2_pixels; } -char *av_get_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt) +char *av_get_pix_fmt_string(char *buf, int buf_size, + enum AVPixelFormat pix_fmt) { /* print header */ if (pix_fmt < 0) { - snprintf (buf, buf_size, "name " " nb_components" " nb_bits"); + snprintf (buf, buf_size, "name" " nb_components" " nb_bits"); } else { const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt]; - snprintf(buf, buf_size, "%-11s %7d %10d", - pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc)); + snprintf(buf, buf_size, "%-11s %7d %10d", pixdesc->name, + pixdesc->nb_components, av_get_bits_per_pixel(pixdesc)); } return buf; } + +const AVPixFmtDescriptor *av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt) +{ + if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB) + return NULL; + return &av_pix_fmt_descriptors[pix_fmt]; +} + +const AVPixFmtDescriptor *av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev) +{ + if (!prev) + return &av_pix_fmt_descriptors[0]; + if (prev - av_pix_fmt_descriptors < FF_ARRAY_ELEMS(av_pix_fmt_descriptors) - 1) + return prev + 1; + return NULL; +} + +enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc) +{ + if (desc < av_pix_fmt_descriptors || + desc >= av_pix_fmt_descriptors + FF_ARRAY_ELEMS(av_pix_fmt_descriptors)) + return AV_PIX_FMT_NONE; + + return desc - av_pix_fmt_descriptors; +} +FF_ENABLE_DEPRECATION_WARNINGS + +int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, + int *h_shift, int *v_shift) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); + if (!desc) + return AVERROR(ENOSYS); + *h_shift = desc->log2_chroma_w; + *v_shift = desc->log2_chroma_h; + + return 0; +} + +int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); + int i, planes[4] = { 0 }, ret = 0; + + if (!desc) + return AVERROR(EINVAL); + + for (i = 0; i < desc->nb_components; i++) + planes[desc->comp[i].plane] = 1; + for (i = 0; i < FF_ARRAY_ELEMS(planes); i++) + ret += planes[i]; + return ret; +} + + +enum AVPixelFormat av_pix_fmt_swap_endianness(enum AVPixelFormat pix_fmt) +{ +#define PIX_FMT_SWAP_ENDIANNESS(fmt) \ + case AV_PIX_FMT_ ## fmt ## BE: return AV_PIX_FMT_ ## fmt ## LE; \ + case AV_PIX_FMT_ ## fmt ## LE: return AV_PIX_FMT_ ## fmt ## BE + + switch (pix_fmt) { + PIX_FMT_SWAP_ENDIANNESS(GRAY16); + PIX_FMT_SWAP_ENDIANNESS(YA16); + PIX_FMT_SWAP_ENDIANNESS(RGB48); + PIX_FMT_SWAP_ENDIANNESS(RGB565); + PIX_FMT_SWAP_ENDIANNESS(RGB555); + PIX_FMT_SWAP_ENDIANNESS(RGB444); + PIX_FMT_SWAP_ENDIANNESS(BGR48); + PIX_FMT_SWAP_ENDIANNESS(BGR565); + PIX_FMT_SWAP_ENDIANNESS(BGR555); + PIX_FMT_SWAP_ENDIANNESS(BGR444); + + PIX_FMT_SWAP_ENDIANNESS(YUV420P9); + PIX_FMT_SWAP_ENDIANNESS(YUV422P9); + PIX_FMT_SWAP_ENDIANNESS(YUV444P9); + PIX_FMT_SWAP_ENDIANNESS(YUV420P10); + PIX_FMT_SWAP_ENDIANNESS(YUV422P10); + PIX_FMT_SWAP_ENDIANNESS(YUV444P10); + PIX_FMT_SWAP_ENDIANNESS(YUV420P16); + PIX_FMT_SWAP_ENDIANNESS(YUV422P16); + PIX_FMT_SWAP_ENDIANNESS(YUV444P16); + + PIX_FMT_SWAP_ENDIANNESS(GBRP9); + PIX_FMT_SWAP_ENDIANNESS(GBRP10); + PIX_FMT_SWAP_ENDIANNESS(GBRP16); + PIX_FMT_SWAP_ENDIANNESS(YUVA420P9); + PIX_FMT_SWAP_ENDIANNESS(YUVA422P9); + PIX_FMT_SWAP_ENDIANNESS(YUVA444P9); + PIX_FMT_SWAP_ENDIANNESS(YUVA420P10); + PIX_FMT_SWAP_ENDIANNESS(YUVA422P10); + PIX_FMT_SWAP_ENDIANNESS(YUVA444P10); + PIX_FMT_SWAP_ENDIANNESS(YUVA420P16); + PIX_FMT_SWAP_ENDIANNESS(YUVA422P16); + PIX_FMT_SWAP_ENDIANNESS(YUVA444P16); + + PIX_FMT_SWAP_ENDIANNESS(XYZ12); + PIX_FMT_SWAP_ENDIANNESS(NV20); + PIX_FMT_SWAP_ENDIANNESS(RGBA64); + PIX_FMT_SWAP_ENDIANNESS(BGRA64); + default: + return AV_PIX_FMT_NONE; + } +#undef PIX_FMT_SWAP_ENDIANNESS +} + +const char *av_color_range_name(enum AVColorRange range) +{ + return (unsigned) range < AVCOL_RANGE_NB ? + color_range_names[range] : NULL; +} + +const char *av_color_primaries_name(enum AVColorPrimaries primaries) +{ + return (unsigned) primaries < AVCOL_PRI_NB ? + color_primaries_names[primaries] : NULL; +} + +const char *av_color_transfer_name(enum AVColorTransferCharacteristic transfer) +{ + return (unsigned) transfer < AVCOL_TRC_NB ? + color_transfer_names[transfer] : NULL; +} + +const char *av_color_space_name(enum AVColorSpace space) +{ + return (unsigned) space < AVCOL_SPC_NB ? + color_space_names[space] : NULL; +} + +const char *av_chroma_location_name(enum AVChromaLocation location) +{ + return (unsigned) location < AVCHROMA_LOC_NB ? + chroma_location_names[location] : NULL; +} +