summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2015-11-14 16:42:59 +0100
committerAnton Khirnov <anton@khirnov.net>2015-11-14 16:42:59 +0100
commit855d11fb01aa915bdf325f5ae57f28d9077c4e10 (patch)
tree6e62c850a9058f7673f0f43ae06f476750e05b78
parentc6ed5833ca8d91fcabc29051e535c900588ede88 (diff)
more stuffavscale
-rw-r--r--libavscale/avscale.c8
-rw-r--r--libavutil/frame.c24
-rw-r--r--libavutil/frame.h2
-rw-r--r--libavutil/pixformaton.c130
-rw-r--r--libavutil/pixformaton.h20
5 files changed, 130 insertions, 54 deletions
diff --git a/libavscale/avscale.c b/libavscale/avscale.c
index 4860b037c9..9eabb9421b 100644
--- a/libavscale/avscale.c
+++ b/libavscale/avscale.c
@@ -110,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->formaton->nb_components)
+ if (component_id >= src->formaton->pf->nb_components)
return 0;
- if (!src->formaton->component_desc[component_id].packed)
- return src->data[src->formaton->component_desc[component_id].plane];
+ if (!src->formaton->pf->component_desc[component_id].packed)
+ return src->data[src->formaton->pf->component_desc[component_id].plane];
else
- return src->data[0] + src->formaton->component_desc[component_id].offset;
+ return src->data[0] + src->formaton->pf->component_desc[component_id].offset;
}
int avscale_get_component_stride(AVFrame *src, int component_id)
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 1b9c304bd2..3c1d484f05 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -45,7 +45,7 @@ static void get_frame_defaults(AVFrame *frame)
frame->color_range = AVCOL_RANGE_UNSPECIFIED;
frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
- av_formaton_free(&frame->formaton);
+ av_pixformaton_unref(&frame->formaton);
}
static void free_side_data(AVFrameSideData **ptr_sd)
@@ -94,9 +94,11 @@ static int get_video_buffer(AVFrame *frame, int align)
{
int ret, i;
- frame->formaton = av_formaton_from_pixfmt(frame->format);
- if (!frame->formaton)
- return AVERROR(EINVAL);
+ if (!frame->formaton && frame->format != AV_PIX_FMT_NONE) {
+ frame->formaton = av_pixformaton_from_pixfmt(frame->format);
+ if (!frame->formaton)
+ return AVERROR(EINVAL);
+ }
if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
return ret;
@@ -111,10 +113,10 @@ static int get_video_buffer(AVFrame *frame, int align)
frame->linesize[i] = FFALIGN(frame->linesize[i], align);
}
- for (i = 0; i < frame->formaton->nb_components && frame->linesize[i]; i++) {
+ for (i = 0; i < frame->formaton->pf->nb_components && frame->linesize[i]; i++) {
int h = frame->height;
if (i == 1 || i == 2)
- h = -((-h) >> frame->formaton->component_desc[i].h_sub_log);
+ h = -((-h) >> frame->formaton->pf->component_desc[i].h_sub_log);
frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);
if (!frame->buf[i])
@@ -123,15 +125,15 @@ static int get_video_buffer(AVFrame *frame, int align)
frame->data[i] = frame->buf[i]->data;
}
- if (frame->formaton->flags & AV_PIX_FMT_FLAG_PAL ||
- frame->formaton->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
+ if (frame->formaton->pf->flags & AV_PIX_FMT_FLAG_PAL ||
+ frame->formaton->pf->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
int size;
// XXX Compatibility until the palette_entries information is
// stored somewhere.
- if (frame->formaton->nb_palette_entries) {
- size = frame->formaton->nb_palette_entries *
- frame->formaton->pixel_next;
+ if (frame->formaton->pf->nb_palette_entries) {
+ size = frame->formaton->pf->nb_palette_entries *
+ frame->formaton->pf->pixel_next;
} else
size = 1024;
diff --git a/libavutil/frame.h b/libavutil/frame.h
index ff707f358a..2604a7919b 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -356,7 +356,7 @@ typedef struct AVFrame {
enum AVChromaLocation chroma_location;
- AVPixelFormaton *formaton;
+ AVPixelFormatonRef *formaton;
} AVFrame;
/**
diff --git a/libavutil/pixformaton.c b/libavutil/pixformaton.c
index 5c6ab1cce5..70e69f0a31 100644
--- a/libavutil/pixformaton.c
+++ b/libavutil/pixformaton.c
@@ -18,61 +18,121 @@
#include <string.h>
+#include "avstring.h"
+#include "buffer.h"
#include "pixformaton.h"
#include "mem.h"
#include "pixdesc.h"
#include "pixfmt.h"
-AVPixelFormaton *av_formaton_from_pixfmt(enum AVPixelFormat pix_fmt)
+typedef struct AVPixelFormatonRefInternal {
+ AVPixelFormaton *pf;
+ AVBufferRef *ref;
+} AVPixelFormatonRefInternal;
+
+AVPixelFormatonRef *av_pixformaton_alloc(void)
{
- AVPixelFormaton *formaton = av_mallocz(sizeof(AVPixelFormaton));
- const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt);
- int i;
+ AVPixelFormaton *pf;
+ AVBufferRef *buf = NULL;
+
+ AVPixelFormatonRefInternal *pref = NULL;
- if (!formaton)
+ buf = av_buffer_allocz(sizeof(*pf));
+ if (!buf)
return NULL;
- if (!desc)
+
+ pref = av_mallocz(sizeof(*pref));
+ if (!pref)
goto fail;
- formaton->flags = desc->flags;
+ pf = (AVPixelFormaton*)buf->data;
- // 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;
+ pref->pf = pf;
+ pref->ref = buf;
- formaton->nb_components = desc->nb_components;
+ return (AVPixelFormatonRef*)pref;
+fail:
+ av_buffer_unref(&buf);
+ av_freep(&pref);
+ return NULL;
+}
- for (i = 0; i < formaton->nb_components; i++) {
- AVPixelChromaton *chromaton = &formaton->component_desc[i];
- const AVComponentDescriptor *comp = &desc->comp[i];
+AVPixelFormatonRef *av_pixformaton_ref(AVPixelFormatonRef *pf)
+{
+ AVPixelFormatonRefInternal *src = (AVPixelFormatonRefInternal*)pf;
+ AVPixelFormatonRefInternal *dst;
- 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
+ dst = av_mallocz(sizeof(*dst));
+ if (!dst)
+ return NULL;
+
+ dst->ref = av_buffer_ref(src->ref);
+ if (!dst->ref) {
+ av_freep(&dst);
+ return NULL;
}
- return formaton;
+ dst->pf = src->pf;
-fail:
- av_formaton_free(&formaton);
- return NULL;
+ return (AVPixelFormatonRef*)dst;
}
-void av_formaton_free(AVPixelFormaton **formaton)
+void av_pixformaton_unref(AVPixelFormatonRef **pref)
{
- if (!formaton || !*formaton)
+ AVPixelFormatonRefInternal *pref_int = (AVPixelFormatonRefInternal*)*pref;
+
+ if (!pref_int)
return;
- av_freep(formaton);
+ av_buffer_unref(&pref_int->ref);
+ av_freep(&pref_int);
+}
+
+AVPixelFormatonRef *av_pixformaton_from_pixfmt(enum AVPixelFormat pix_fmt)
+{
+ AVPixelFormaton *pf;
+ AVPixelFormatonRef *pref;
+ const AVPixFmtDescriptor *desc;
+
+ int i;
+
+ desc = av_pix_fmt_desc_get(pix_fmt);
+ if (!desc)
+ return NULL;
+
+ pref = av_pixformaton_alloc();
+ if (!pref)
+ return NULL;
+
+ pf = pref->pf;
+
+ pf->flags = desc->flags;
+
+ if (av_strstart(desc->name, "yuvj", NULL))
+ pf->range = AVCOL_RANGE_JPEG;
+ else
+ pf->range = AVCOL_RANGE_UNSPECIFIED;
+
+ pf->primaries = AVCOL_PRI_UNSPECIFIED;
+ pf->transfer = AVCOL_TRC_UNSPECIFIED;
+ pf->space = AVCOL_SPC_UNSPECIFIED;
+ pf->location = AVCHROMA_LOC_UNSPECIFIED;
+
+ pf->nb_components = desc->nb_components;
+
+ for (i = 0; i < pf->nb_components; i++) {
+ AVPixelChromaton *chromaton = &pf->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 pref;
}
diff --git a/libavutil/pixformaton.h b/libavutil/pixformaton.h
index 36744a0038..ef2831ad3f 100644
--- a/libavutil/pixformaton.h
+++ b/libavutil/pixformaton.h
@@ -115,7 +115,6 @@ typedef struct AVPixelChromaton {
int packed;
} AVPixelChromaton;
-
/**
* Pixel format description
*
@@ -125,6 +124,12 @@ typedef struct AVPixelChromaton {
*/
typedef struct AVPixelFormaton {
/**
+ * Data for internal use only, should not be accessed in any way
+ * by the callers
+ */
+ void *opaque;
+
+ /**
* Defines how to interpret the components
*
* The components in the formaton are enumerated in fixed order
@@ -181,7 +186,16 @@ typedef struct AVPixelFormaton {
AVPixelChromaton component_desc[AV_PIX_FORMATON_COMPONENTS];
} AVPixelFormaton;
-AVPixelFormaton *av_formaton_from_pixfmt(enum AVPixelFormat pix_fmt);
-void av_formaton_free(AVPixelFormaton **formaton);
+typedef struct AVPixelFormatonRef {
+ AVPixelFormaton *pf;
+} AVPixelFormatonRef;
+
+AVPixelFormatonRef *av_pixformaton_alloc(void);
+
+AVPixelFormatonRef *av_pixformaton_ref(AVPixelFormatonRef *pf);
+
+void av_pixformaton_unref(AVPixelFormatonRef **pf);
+
+AVPixelFormatonRef *av_pixformaton_from_pixfmt(enum AVPixelFormat pix_fmt);
#endif /* AVUTIL_PIXFORMATON_H */