From 55077af02d091c068d05741117cd28015c0f7fb5 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 14 Nov 2015 13:12:50 +0100 Subject: stuff --- libavscale/Makefile | 4 +- libavscale/avscale.c | 15 +++-- libavscale/avscale.h | 29 +++++----- libavscale/internal.h | 3 + libavutil/Makefile | 4 +- libavutil/formaton.c | 83 --------------------------- libavutil/formaton.h | 145 ------------------------------------------------ libavutil/frame.c | 2 +- libavutil/frame.h | 2 +- libavutil/pixformaton.c | 78 ++++++++++++++++++++++++++ libavutil/pixformaton.h | 140 ++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 252 insertions(+), 253 deletions(-) delete mode 100644 libavutil/formaton.c delete mode 100644 libavutil/formaton.h create mode 100644 libavutil/pixformaton.c create mode 100644 libavutil/pixformaton.h diff --git a/libavscale/Makefile b/libavscale/Makefile index bae67043ab..9b6f095ec5 100644 --- a/libavscale/Makefile +++ b/libavscale/Makefile @@ -1,7 +1,7 @@ NAME = avscale -HEADERS = avscale.h +HEADERS = avscale.h \ + version.h \ OBJS = avscale.o \ utils.o \ - diff --git a/libavscale/avscale.c b/libavscale/avscale.c index 7cb5ced43f..4860b037c9 100644 --- a/libavscale/avscale.c +++ b/libavscale/avscale.c @@ -56,7 +56,6 @@ err: return ret; } - // FIXME: proof of a concept int avscale_build_chain(AVScaleContext *ctx, AVFrame *src, AVFrame *dst) { @@ -79,7 +78,7 @@ int avscale_build_chain(AVScaleContext *ctx, AVFrame *src, AVFrame *dst) !ctx->dst_fmt->component_desc[0].packed) { if ((ret = prepare_next_stage(ctx, &stage, "rgbunp")) < 0) return ret; - } else if (ctx->src_fmt->component_desc[0].step != ctx->dst_fmt->component_desc[0].step) { + } else if (ctx->src_fmt->component_desc[0].next != ctx->dst_fmt->component_desc[0].next) { if ((ret = prepare_next_stage(ctx, &stage, "rgbunp")) < 0) return ret; if (ctx->cur_w != ctx->dst_w || ctx->cur_h != ctx->dst_h) @@ -91,8 +90,8 @@ int avscale_build_chain(AVScaleContext *ctx, AVFrame *src, AVFrame *dst) if ((ret = prepare_next_stage(ctx, &stage, "murder")) < 0) return ret; } - } else if (ctx->src_fmt->space == AVS_RGB && - ctx->dst_fmt->space == AVS_YUV) { + } else if (ctx->src_fmt->model == AVCOL_MODEL_RGB && + ctx->dst_fmt->model == AVCOL_MODEL_YUV) { if ((ret = prepare_next_stage(ctx, &stage, "rgbunp")) < 0) return ret; if (ctx->cur_w != ctx->dst_w || ctx->cur_h != ctx->dst_h) { @@ -116,7 +115,7 @@ uint8_t *avscale_get_component_ptr(AVFrame *src, int component_id) if (!src->formaton->component_desc[component_id].packed) return src->data[src->formaton->component_desc[component_id].plane]; else - return src->data[0] + src->formaton->component_desc[component_id].off; + return src->data[0] + src->formaton->component_desc[component_id].offset; } int avscale_get_component_stride(AVFrame *src, int component_id) @@ -193,10 +192,12 @@ int avscale_process_frame(AVScaleContext *ctx, AVFrame *srcf, AVFrame *dstf) return 0; } -void avscale_free_context(AVScaleContext *ctx) +void avscale_free(AVScaleContext **pctx) { + AVScaleContext *ctx; AVScaleFilterStage *s, *next; + ctx = *pctx; if (!ctx) return; @@ -210,5 +211,7 @@ void avscale_free_context(AVScaleContext *ctx) s = next; } ctx->head = ctx->tail = 0; + + *pctx = NULL; } diff --git a/libavscale/avscale.h b/libavscale/avscale.h index 7de7d85339..deb66105e4 100644 --- a/libavscale/avscale.h +++ b/libavscale/avscale.h @@ -20,18 +20,11 @@ #ifndef AVSCALE_AVSCALE_H #define AVSCALE_AVSCALE_H -#include - -#include "libavutil/formaton.h" #include "libavutil/frame.h" #include "libavutil/pixdesc.h" #include "version.h" -// XXX luzero is reading a comic book so this values are random -#define AVS_RGB 0 -#define AVS_YUV 1 - typedef struct AVScaleContext AVScaleContext; /** @@ -62,15 +55,15 @@ AVScaleContext *avscale_alloc_context(void); * @see avscale_build_chain * @see avscale_process_frame */ -int avscale_init_context(AVScaleContext *ctx); +int avscale_open(AVScaleContext *ctx); /** - * Free the avscaler context AVScaleContext. - * If AVScaleContext is NULL, then does nothing. + * Free scaling context and everything associated with it and write NULL + * to the supplied pointer. * - * @param ctx The context to free. + * @param ctx double pointer to the scaling context */ -void avscale_free_context(AVScaleContext *ctx); +void avscale_free(AVScaleContext **ctx); /** * Build a conversion chain using the information contained in the @@ -99,9 +92,19 @@ int avscale_build_chain(AVScaleContext *ctx, AVFrame *src, AVFrame *dst); */ int avscale_process_frame(AVScaleContext *c, AVFrame *dst, AVFrame *src); - +/** + * Return the LIBAVSCALE_VERSION_INT constant. + */ unsigned avscale_version(void); + +/** + * Return the libavscale build-time configuration. + */ const char *avscale_configuration(void); + +/** + * Return the libavscale license. + */ const char *avscale_license(void); #endif /* AVSCALE_AVSCALE_H */ diff --git a/libavscale/internal.h b/libavscale/internal.h index b8d12c0a0d..ed5eeec9da 100644 --- a/libavscale/internal.h +++ b/libavscale/internal.h @@ -22,9 +22,12 @@ #include "libavutil/dict.h" #include "libavutil/log.h" +#include "libavutil/pixformaton.h" #include "avscale.h" +#define AVSCALE_MAX_COMPONENTS AV_PIX_FORMATON_COMPONENTS + typedef struct AVScaleFilterStage { void (*deinit)(struct AVScaleFilterStage *stage); void (*do_common)(void *ctx, diff --git a/libavutil/Makefile b/libavutil/Makefile index 6433dccb90..79f08c8494 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -21,7 +21,6 @@ HEADERS = adler32.h \ eval.h \ fifo.h \ file.h \ - formaton.h \ frame.h \ hmac.h \ imgutils.h \ @@ -38,6 +37,7 @@ HEADERS = adler32.h \ parseutils.h \ pixdesc.h \ pixfmt.h \ + pixformaton.h \ random_seed.h \ replaygain.h \ rational.h \ @@ -77,7 +77,6 @@ OBJS = adler32.o \ file.o \ file_open.o \ float_dsp.o \ - formaton.o \ frame.o \ hmac.o \ imgutils.o \ @@ -93,6 +92,7 @@ OBJS = adler32.o \ opt.o \ parseutils.o \ pixdesc.o \ + pixformaton.o \ random_seed.o \ rational.o \ rc4.o \ diff --git a/libavutil/formaton.c b/libavutil/formaton.c deleted file mode 100644 index bcf358438b..0000000000 --- a/libavutil/formaton.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2015 Kostya Shishkov - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING.GPLv3. If not see - * . - */ - -#include - -#include "formaton.h" -#include "mem.h" -#include "pixdesc.h" -#include "pixfmt.h" - -AVPixelFormaton *av_formaton_from_pixfmt(enum AVPixelFormat pix_fmt) -{ - AVPixelFormaton *formaton = av_mallocz(sizeof(AVPixelFormaton)); - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); - int i; - - if (!formaton) - return NULL; - if (!desc) - goto fail; - - formaton->name = strdup(desc->name); - if (!formaton->name) - goto fail; - formaton->flags = desc->flags; - - // XXX luzero disapproves - if (strchr(desc->name, 'j')) - formaton->range = AVCOL_RANGE_JPEG; - else - formaton->range = AVCOL_RANGE_UNSPECIFIED; - formaton->primaries = AVCOL_PRI_UNSPECIFIED; - formaton->transfer = AVCOL_TRC_UNSPECIFIED; - formaton->space = AVCOL_SPC_UNSPECIFIED; - formaton->location = AVCHROMA_LOC_UNSPECIFIED; - - formaton->nb_components = desc->nb_components; - - for (i = 0; i < formaton->nb_components; i++) { - AVChromaton *chromaton = &formaton->component_desc[i]; - const AVComponentDescriptor *comp = &desc->comp[i]; - - chromaton->plane = comp->plane; - chromaton->step = comp->step; - chromaton->h_sub_log = desc->log2_chroma_w; - chromaton->v_sub_log = desc->log2_chroma_h; - chromaton->off = comp->offset; - chromaton->shift = comp->shift; - chromaton->depth = comp->depth; - chromaton->packed = 0; // XXX luzero does not remember - chromaton->next = 0; // XXX luzero does not remember - } - - return formaton; - -fail: - av_formaton_free(&formaton); - return NULL; -} - -void av_formaton_free(AVPixelFormaton **formaton) -{ - if (!formaton || !*formaton) - return; - - av_freep(&(*formaton)->name); - av_freep(formaton); -} diff --git a/libavutil/formaton.h b/libavutil/formaton.h deleted file mode 100644 index 9d4240017e..0000000000 --- a/libavutil/formaton.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2015 Kostya Shishkov - * This file is part of Libav. - * - * Libav is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * Libav is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef AVUTIL_FORMATON_H -#define AVUTIL_FORMATON_H - -#include - -#include "pixdesc.h" - -/** - * Component description - * - * The structure describes a single component in a pixel format. - */ -typedef struct AVPixelChromaton { - /** - * Index of the plane in which the component is located. - */ - int plane; - - /** - * The base-2 logarithm of the ratio between the component with the highest - * resolution and this component. - */ - int h_sub_log, v_sub_log; - - /** - * Bit offset - * - * It is set if the component is not byte-aligned. - * - * The distance in bits from the start of the pixel. - * - * examples: - * - * For RGB565 it will be 11,5,0 - */ - int shift; - - /** - * Component size in bits - * - * examples: - * - * For packed RGB565 you'll have 5,6,5 - */ - int depth; - - /** - * Byte offset to the starting element - * - * It is set if the component is byte-aligned. - * - * The distance in bytes from the start of this plane to the - * first element of this component. - * - * examples: - * - * For YUYV: 0 for Y, 1 for U and 3 for V. - * - */ - int offset; - - /** - * Byte offset to the next element - * - * It is set if the component is byte-aligned. - * - * examples: - * - * For YUYV: 2 for Y and 4 for U and V - */ - int next; - - /** - * Set if the component shares the plane with another - * - * examples: - * - * For RGB24 - 1,1,1 - * For NV12 - 0,1,1 - */ - int packed; - -} AVChromaton; - - - -typedef struct AVPixelFormaton { -#define AV_PIX_FORMATON_FLAG_BE (1 << 0) -#define AV_PIX_FORMATON_FLAG_ALPHA (1 << 1) -#define AV_PIX_FORMATON_FLAG_PAL (1 << 2) - /** - * Or-ed AV_PIX_FORMATON_FLAG_ - */ - unsigned flags; - /** - * Size of all the pixel components packed as one element including - * padding. - * - * Useful to move to the next pixel in packeted formats. - * - * It is set to 0 for planar and quasi-planar formats. - */ - int pixel_next; - - /** - * Number of entries in the palette if a palette is present. - */ - int nb_palette_entries; - - enum AVColorModel model; - enum AVColorRange range; - enum AVColorPrimaries primaries; - enum AVColorTransferCharacteristic transfer; - enum AVColorSpace space; - enum AVChromaLocation location; - - int nb_components; -#define AV_PIX_FORMATON_COMPONENTS 5 - AVPixelChromaton component_desc[AV_PIX_FORMATON_COMPONENTS]; -} AVPixelFormaton; - -AVPixelFormaton *av_formaton_from_pixfmt(enum AVPixelFormat pix_fmt); -void av_formaton_free(AVPixelFormaton **formaton); - - -#endif /* AVUTIL_FORMATON_H */ diff --git a/libavutil/frame.c b/libavutil/frame.c index 135f6d2480..1b9c304bd2 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -25,7 +25,7 @@ #include "imgutils.h" #include "mem.h" #include "samplefmt.h" -#include "formaton.h" +#include "pixformaton.h" static void get_frame_defaults(AVFrame *frame) { diff --git a/libavutil/frame.h b/libavutil/frame.h index 260e5f58d8..ff707f358a 100644 --- a/libavutil/frame.h +++ b/libavutil/frame.h @@ -36,7 +36,7 @@ #include "pixfmt.h" #include "version.h" -#include "formaton.h" +#include "pixformaton.h" /** * @defgroup lavu_frame AVFrame diff --git a/libavutil/pixformaton.c b/libavutil/pixformaton.c new file mode 100644 index 0000000000..5c6ab1cce5 --- /dev/null +++ b/libavutil/pixformaton.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015 Kostya Shishkov + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING.GPLv3. If not see + * . + */ + +#include + +#include "pixformaton.h" +#include "mem.h" +#include "pixdesc.h" +#include "pixfmt.h" + +AVPixelFormaton *av_formaton_from_pixfmt(enum AVPixelFormat pix_fmt) +{ + AVPixelFormaton *formaton = av_mallocz(sizeof(AVPixelFormaton)); + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); + int i; + + if (!formaton) + return NULL; + if (!desc) + goto fail; + + formaton->flags = desc->flags; + + // XXX luzero disapproves + if (strchr(desc->name, 'j')) + formaton->range = AVCOL_RANGE_JPEG; + else + formaton->range = AVCOL_RANGE_UNSPECIFIED; + formaton->primaries = AVCOL_PRI_UNSPECIFIED; + formaton->transfer = AVCOL_TRC_UNSPECIFIED; + formaton->space = AVCOL_SPC_UNSPECIFIED; + formaton->location = AVCHROMA_LOC_UNSPECIFIED; + + formaton->nb_components = desc->nb_components; + + for (i = 0; i < formaton->nb_components; i++) { + AVPixelChromaton *chromaton = &formaton->component_desc[i]; + const AVComponentDescriptor *comp = &desc->comp[i]; + + chromaton->plane = comp->plane; + chromaton->next = comp->step; + chromaton->h_sub_log = desc->log2_chroma_w; + chromaton->v_sub_log = desc->log2_chroma_h; + chromaton->offset = comp->offset; + chromaton->shift = comp->shift; + chromaton->depth = comp->depth; + chromaton->packed = 0; // XXX luzero does not remember + } + + return formaton; + +fail: + av_formaton_free(&formaton); + return NULL; +} + +void av_formaton_free(AVPixelFormaton **formaton) +{ + if (!formaton || !*formaton) + return; + + av_freep(formaton); +} diff --git a/libavutil/pixformaton.h b/libavutil/pixformaton.h new file mode 100644 index 0000000000..59958fead9 --- /dev/null +++ b/libavutil/pixformaton.h @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2015 Kostya Shishkov + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_PIXFORMATON_H +#define AVUTIL_PIXFORMATON_H + +#include "pixdesc.h" + +#define AV_PIX_FORMATON_FLAG_BE (1 << 0) +#define AV_PIX_FORMATON_FLAG_ALPHA (1 << 1) +#define AV_PIX_FORMATON_FLAG_PAL (1 << 2) + +/** + * Component description + * + * The structure describes a single component in a pixel format. + */ +typedef struct AVPixelChromaton { + /** + * Index of the plane in which the component is located. + */ + int plane; + + /** + * The base-2 logarithm of the ratio between the component with the highest + * resolution and this component. + */ + int h_sub_log, v_sub_log; + + /** + * Bit offset + * + * It is set if the component is not byte-aligned. + * + * The distance in bits from the start of the pixel. + * + * examples: + * + * For RGB565 it will be 11,5,0 + */ + int shift; + + /** + * Component size in bits + * + * examples: + * + * For packed RGB565 you'll have 5,6,5 + */ + int depth; + + /** + * Byte offset to the starting element + * + * It is set if the component is byte-aligned. + * + * The distance in bytes from the start of this plane to the + * first element of this component. + * + * examples: + * + * For YUYV: 0 for Y, 1 for U and 3 for V. + * + */ + int offset; + + /** + * Byte offset to the next element + * + * It is set if the component is byte-aligned. + * + * examples: + * + * For YUYV: 2 for Y and 4 for U and V + */ + int next; + + /** + * Set if the component shares the plane with another + * + * examples: + * + * For RGB24 - 1,1,1 + * For NV12 - 0,1,1 + */ + int packed; +} AVPixelChromaton; + +typedef struct AVPixelFormaton { + /** + * Or-ed AV_PIX_FORMATON_FLAG_ + */ + unsigned flags; + /** + * Size of all the pixel components packed as one element including + * padding. + * + * Useful to move to the next pixel in packeted formats. + * + * It is set to 0 for planar and quasi-planar formats. + */ + int pixel_next; + + /** + * Number of entries in the palette if a palette is present. + */ + int nb_palette_entries; + + enum AVColorModel model; + enum AVColorRange range; + enum AVColorPrimaries primaries; + enum AVColorTransferCharacteristic transfer; + enum AVColorSpace space; + enum AVChromaLocation location; + + int nb_components; +#define AV_PIX_FORMATON_COMPONENTS 5 + AVPixelChromaton component_desc[AV_PIX_FORMATON_COMPONENTS]; +} AVPixelFormaton; + +AVPixelFormaton *av_formaton_from_pixfmt(enum AVPixelFormat pix_fmt); +void av_formaton_free(AVPixelFormaton **formaton); + +#endif /* AVUTIL_PIXFORMATON_H */ -- cgit v1.2.3