summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2015-10-30 01:09:11 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2015-10-30 01:09:11 +0100
commit3b303499969972e45bb147d9d62b850a98c51ac8 (patch)
tree2132eb0e667fac9e04af315f49f9e45bb86ca220
parent4e12e196868b8162c8fee41647a0ce409f56601d (diff)
avascale: initial implementation
-rw-r--r--cmdutils.c2
-rwxr-xr-xconfigure3
-rw-r--r--libavscale/avscale.c29
-rw-r--r--libavscale/avscale.h37
-rw-r--r--libavscale/utils.c20
-rw-r--r--libavscale/version.h2
-rw-r--r--libavutil/Makefile2
-rw-r--r--libavutil/formaton.c83
-rw-r--r--libavutil/formaton.h85
-rw-r--r--libavutil/frame.c16
-rw-r--r--libavutil/frame.h3
11 files changed, 237 insertions, 45 deletions
diff --git a/cmdutils.c b/cmdutils.c
index 5cb22f6946..6a5fcbcdc4 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -33,6 +33,7 @@
#include "libavformat/avformat.h"
#include "libavfilter/avfilter.h"
#include "libavdevice/avdevice.h"
+#include "libavscale/avscale.h"
#include "libavresample/avresample.h"
#include "libswscale/swscale.h"
#include "libavutil/avassert.h"
@@ -814,6 +815,7 @@ static void print_all_libs_info(int flags, int level)
PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level);
PRINT_LIB_INFO(avfilter, AVFILTER, flags, level);
PRINT_LIB_INFO(avresample, AVRESAMPLE, flags, level);
+ PRINT_LIB_INFO(avscale, AVSCALE, flags, level);
PRINT_LIB_INFO(swscale, SWSCALE, flags, level);
}
diff --git a/configure b/configure
index 31ce56eb25..898dd54053 100755
--- a/configure
+++ b/configure
@@ -118,6 +118,7 @@ Component options:
--disable-avformat disable libavformat build
--disable-avscale disable libavscale build
--disable-avutil disable libavutil build
+ --disable-avscale disable libavscale build
--disable-swscale disable libswscale build
--disable-avfilter disable video filter support [no]
--disable-avresample disable libavresample build [no]
@@ -2330,7 +2331,7 @@ avscale_deps="avutil"
swscale_deps="avutil"
# programs
-avconv_deps="avcodec avfilter avformat avresample swscale"
+avconv_deps="avcodec avfilter avformat avresample avscale swscale"
avconv_select="aformat_filter anull_filter asyncts_filter atrim_filter format_filter
fps_filter null_filter resample_filter scale_filter
setpts_filter trim_filter"
diff --git a/libavscale/avscale.c b/libavscale/avscale.c
index f6d1bb1e2d..4c0b8149ec 100644
--- a/libavscale/avscale.c
+++ b/libavscale/avscale.c
@@ -16,6 +16,9 @@
* <http://www.gnu.org/licenses/>.
*/
+#include <stdint.h>
+#include <string.h>
+
#include "libavutil/mem.h"
#include "internal.h"
@@ -59,20 +62,23 @@ int avscale_build_chain(AVScaleContext *ctx, AVFrame *src, AVFrame *dst)
AVScaleFilterStage *stage = 0;
int ret;
- ctx->src_fmt = src->pixfmt;
- ctx->dst_fmt = dst->pixfmt;
+ // XXX luzero stabs anton because avformaton is not refcounted
+ ctx->src_fmt = src->formaton;
+ ctx->dst_fmt = dst->formaton;
+ // XXX luzero blames kostya
+ // TODO av_formaton_clone and/or av_formaton_ref
ctx->cur_w = src->width;
ctx->cur_h = src->height;
ctx->dst_w = dst->width;
ctx->dst_h = dst->height;
ctx->cur_fmt = *ctx->src_fmt;
- if (ctx->src_fmt->colourspace == ctx->dst_fmt->colourspace) {
+ if (ctx->src_fmt->space == ctx->dst_fmt->space) {
if ( ctx->src_fmt->component_desc[0].packed &&
!ctx->dst_fmt->component_desc[0].packed) {
if ((ret = prepare_next_stage(ctx, &stage, "rgbunp")) < 0)
return ret;
- } else if (ctx->src_fmt->entry_size != ctx->dst_fmt->entry_size) {
+ } else if (ctx->src_fmt->component_desc[0].step != ctx->dst_fmt->component_desc[0].step) {
if ((ret = prepare_next_stage(ctx, &stage, "rgbunp")) < 0)
return ret;
if (ctx->cur_w != ctx->dst_w || ctx->cur_h != ctx->dst_h)
@@ -84,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->colourspace == AVS_RGB &&
- ctx->dst_fmt->colourspace == AVS_YUV) {
+ } else if (ctx->src_fmt->space == AVS_RGB &&
+ ctx->dst_fmt->space == AVS_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) {
@@ -104,12 +110,12 @@ int avscale_build_chain(AVScaleContext *ctx, AVFrame *src, AVFrame *dst)
uint8_t *avscale_get_component_ptr(AVFrame *src, int component_id)
{ // currently a simple hack - it has to be extended for e.g. NV12
- if (component_id >= src->pixfmt->components)
+ if (component_id >= src->formaton->nb_components)
return 0;
- if (!src->pixfmt->component_desc[component_id].packed)
- return src->data[src->pixfmt->component_desc[component_id].plane];
+ if (!src->formaton->component_desc[component_id].packed)
+ return src->data[src->formaton->component_desc[component_id].plane];
else
- return src->data[0] + src->pixfmt->component_desc[component_id].off;
+ return src->data[0] + src->formaton->component_desc[component_id].off;
}
int avscale_get_component_stride(AVFrame *src, int component_id)
@@ -131,7 +137,6 @@ int avscale_process_frame(AVScaleContext *ctx, AVFrame *srcf, AVFrame *dstf)
int sstride[AVSCALE_MAX_COMPONENTS];
uint8_t *dst[AVSCALE_MAX_COMPONENTS];
int dstride[AVSCALE_MAX_COMPONENTS];
- int w[AVSCALE_MAX_COMPONENTS], h[AVSCALE_MAX_COMPONENTS];
uint8_t *src2[AVSCALE_MAX_COMPONENTS];
uint8_t *dst2[AVSCALE_MAX_COMPONENTS];
@@ -183,6 +188,8 @@ int avscale_process_frame(AVScaleContext *ctx, AVFrame *srcf, AVFrame *dstf)
}
stage = stage->next;
}
+
+ return 0;
}
void avscale_free_context(AVScaleContext *ctx)
diff --git a/libavscale/avscale.h b/libavscale/avscale.h
index 66f235ef6e..a2f0e04092 100644
--- a/libavscale/avscale.h
+++ b/libavscale/avscale.h
@@ -21,36 +21,15 @@
#include <stdint.h>
+#include "libavutil/formaton.h"
#include "libavutil/frame.h"
#include "libavutil/pixdesc.h"
-#define AVSCALE_MAX_COMPONENTS 5
+#include "version.h"
-typedef struct AVChromaton {
- int plane;
- int h_sub_log, v_sub_log; ///< subsampling information
- int off; ///< offset to the starting element - e.g. 0 for Y, 1 for U and 3 for V in YUYV
- int shift; ///< component shift for packed, e.g. for RGB565 it will be 11,5,0
- int bpp; ///< bits per component, e.g. for packed RGB565 you'll have 5,6,5
- int packed; ///< if component is packed with others (e.g. RGB24 - 1,1,1, NV12 - 0,1,1)
- int next; ///< offset to the next element - e.g. 2 for Y and 4 for U and V in YUYV
-} AVChromaton;
-
-typedef struct AVPixelFormaton {
- const char *name;
-
- unsigned flags; // has alpha, uses BE order, uses palette etc
- int entry_size; // might serve useful for packed formats - e.g. 4 or 2 bytes per entry
-
- enum AVColorRange range;
- enum AVColorPrimaries primaries;
- enum AVColorTransferCharacteristic trc;
- enum AVColorSpace colorspace;
- enum AVChromaLocation chroma_location;
-
- int nb_components;
- AVChromaton component_desc[AVSCALE_MAX_COMPONENTS];
-} AVPixelFormaton;
+// XXX luzero is reading a comic book so this values are random
+#define AVS_RGB 0
+#define AVS_YUV 1
typedef struct AVScaleContext AVScaleContext;
@@ -119,5 +98,9 @@ int avscale_build_chain(AVScaleContext *ctx, AVFrame *src, AVFrame *dst);
*/
int avscale_process_frame(AVScaleContext *c, AVFrame *dst, AVFrame *src);
-#endif /* AVSCALE_AVSCALE_H */
+unsigned avscale_version(void);
+const char *avscale_configuration(void);
+const char *avscale_license(void);
+
+#endif /* AVSCALE_AVSCALE_H */
diff --git a/libavscale/utils.c b/libavscale/utils.c
new file mode 100644
index 0000000000..a97ae87f89
--- /dev/null
+++ b/libavscale/utils.c
@@ -0,0 +1,20 @@
+
+#include "config.h"
+
+#include "avscale.h"
+
+unsigned avscale_version(void)
+{
+ return LIBAVUTIL_VERSION_INT;
+}
+
+const char *avscale_configuration(void)
+{
+ return LIBAV_CONFIGURATION;
+}
+
+const char *avscale_license(void)
+{
+#define LICENSE_PREFIX "libavutil license: "
+ return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
+}
diff --git a/libavscale/version.h b/libavscale/version.h
index 3e9f76878a..375c973564 100644
--- a/libavscale/version.h
+++ b/libavscale/version.h
@@ -27,7 +27,7 @@
#include "libavutil/version.h"
-#define LIBAVSCALE_VERSION_MAJOR 1
+#define LIBAVSCALE_VERSION_MAJOR 0
#define LIBAVSCALE_VERSION_MINOR 0
#define LIBAVSCALE_VERSION_MICRO 0
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 17bd57e8b7..6433dccb90 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -21,6 +21,7 @@ HEADERS = adler32.h \
eval.h \
fifo.h \
file.h \
+ formaton.h \
frame.h \
hmac.h \
imgutils.h \
@@ -76,6 +77,7 @@ OBJS = adler32.o \
file.o \
file_open.o \
float_dsp.o \
+ formaton.o \
frame.o \
hmac.o \
imgutils.o \
diff --git a/libavutil/formaton.c b/libavutil/formaton.c
new file mode 100644
index 0000000000..bcf358438b
--- /dev/null
+++ b/libavutil/formaton.c
@@ -0,0 +1,83 @@
+/*
+ * 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
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include <string.h>
+
+#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
new file mode 100644
index 0000000000..7d038e67e9
--- /dev/null
+++ b/libavutil/formaton.h
@@ -0,0 +1,85 @@
+/*
+ * 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
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef AVUTIL_FORMATON_H
+#define AVUTIL_FORMATON_H
+
+#include <stdint.h>
+
+#include "pixdesc.h"
+
+typedef struct AVChromaton {
+ int plane;
+
+ /**
+ * might serve useful for packed formats - e.g. 4 or 2 bytes per entry
+ */
+ int step;
+
+ /**
+ * subsampling information
+ */
+ int h_sub_log, v_sub_log;
+
+ /**
+ * offset to the starting element, e.g. 0 for Y, 1 for U and 3 for V in YUYV
+ */
+ int off;
+
+ /**
+ * component shift for packed, e.g. for RGB565 it will be 11,5,0
+ */
+ int shift;
+
+ /**
+ * bits per component, e.g. for packed RGB565 you'll have 5,6,5
+ */
+ int depth;
+
+ /**
+ * if component is packed with others (e.g. RGB24 - 1,1,1, NV12 - 0,1,1)
+ */
+ int packed;
+
+ /**
+ * offset to the next element - e.g. 2 for Y and 4 for U and V in YUYV
+ */
+ int next;
+} AVChromaton;
+
+typedef struct AVPixelFormaton {
+ const char *name;
+
+ unsigned flags; // has alpha, uses BE order, uses palette etc
+
+ enum AVColorRange range;
+ enum AVColorPrimaries primaries;
+ enum AVColorTransferCharacteristic transfer;
+ enum AVColorSpace space;
+ enum AVChromaLocation location;
+
+ int nb_components;
+#define AVSCALE_MAX_COMPONENTS 5
+ AVChromaton component_desc[AVSCALE_MAX_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 e4f6ab3daa..4d167fbefe 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -25,6 +25,7 @@
#include "imgutils.h"
#include "mem.h"
#include "samplefmt.h"
+#include "formaton.h"
static void get_frame_defaults(AVFrame *frame)
{
@@ -43,6 +44,8 @@ static void get_frame_defaults(AVFrame *frame)
frame->colorspace = AVCOL_SPC_UNSPECIFIED;
frame->color_range = AVCOL_RANGE_UNSPECIFIED;
frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
+
+ av_formaton_free(&frame->formaton);
}
static void free_side_data(AVFrameSideData **ptr_sd)
@@ -89,10 +92,10 @@ void av_frame_free(AVFrame **frame)
static int get_video_buffer(AVFrame *frame, int align)
{
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
int ret, i;
- if (!desc)
+ frame->formaton = av_formaton_from_pixfmt(frame->format);
+ if (!frame->formaton)
return AVERROR(EINVAL);
if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
@@ -108,10 +111,10 @@ static int get_video_buffer(AVFrame *frame, int align)
frame->linesize[i] = FFALIGN(frame->linesize[i], align);
}
- for (i = 0; i < 4 && frame->linesize[i]; i++) {
+ for (i = 0; i < frame->formaton->nb_components && frame->linesize[i]; i++) {
int h = frame->height;
if (i == 1 || i == 2)
- h = -((-h) >> desc->log2_chroma_h);
+ h = -((-h) >> frame->formaton->component_desc[i].h_sub_log);
frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);
if (!frame->buf[i])
@@ -119,7 +122,10 @@ static int get_video_buffer(AVFrame *frame, int align)
frame->data[i] = frame->buf[i]->data;
}
- if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
+
+ // XXX luzero wants full fledged palettes
+ if (frame->formaton->flags & AV_PIX_FMT_FLAG_PAL ||
+ frame->formaton->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
av_buffer_unref(&frame->buf[1]);
frame->buf[1] = av_buffer_alloc(1024);
if (!frame->buf[1])
diff --git a/libavutil/frame.h b/libavutil/frame.h
index c723cb02c3..260e5f58d8 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -36,6 +36,7 @@
#include "pixfmt.h"
#include "version.h"
+#include "formaton.h"
/**
* @defgroup lavu_frame AVFrame
@@ -354,6 +355,8 @@ typedef struct AVFrame {
enum AVColorSpace colorspace;
enum AVChromaLocation chroma_location;
+
+ AVPixelFormaton *formaton;
} AVFrame;
/**