summaryrefslogtreecommitdiff
path: root/gst/ffmpegcolorspace
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2009-05-26 14:58:28 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-05-26 15:26:30 +0200
commit9d02d1d8ab87c045d08f4df13dcc4980a2d0df00 (patch)
tree09c756f06f1a2a47890050b339843b5fb7ff5635 /gst/ffmpegcolorspace
parentd48a5614f42eca2872b8c7b411e50aefacb850fd (diff)
ffmpegcolorspace: Add support for 16 bit grayscale in little/big endian
Diffstat (limited to 'gst/ffmpegcolorspace')
-rw-r--r--gst/ffmpegcolorspace/avcodec.h2
-rw-r--r--gst/ffmpegcolorspace/gstffmpegcodecmap.c32
-rw-r--r--gst/ffmpegcolorspace/imgconvert.c156
3 files changed, 190 insertions, 0 deletions
diff --git a/gst/ffmpegcolorspace/avcodec.h b/gst/ffmpegcolorspace/avcodec.h
index f786a75f0..8793cb834 100644
--- a/gst/ffmpegcolorspace/avcodec.h
+++ b/gst/ffmpegcolorspace/avcodec.h
@@ -75,6 +75,8 @@ enum PixelFormat {
PIX_FMT_RGB565, ///< always stored in cpu endianness
PIX_FMT_RGB555, ///< always stored in cpu endianness, most significant bit to 1
PIX_FMT_GRAY8,
+ PIX_FMT_GRAY16_L,
+ PIX_FMT_GRAY16_B,
PIX_FMT_MONOWHITE, ///< 0 is white
PIX_FMT_MONOBLACK, ///< 0 is black
PIX_FMT_PAL8, ///< 8 bit with RGBA palette
diff --git a/gst/ffmpegcolorspace/gstffmpegcodecmap.c b/gst/ffmpegcolorspace/gstffmpegcodecmap.c
index 1f4b45ceb..ea5db1d3b 100644
--- a/gst/ffmpegcolorspace/gstffmpegcodecmap.c
+++ b/gst/ffmpegcolorspace/gstffmpegcodecmap.c
@@ -374,6 +374,18 @@ gst_ffmpeg_pixfmt_to_caps (enum PixelFormat pix_fmt, AVCodecContext * context)
gst_caps_append (caps, tmp);
}
break;
+ case PIX_FMT_GRAY16_L:
+ bpp = depth = 16;
+ caps = gst_ff_vid_caps_new (context, "video/x-raw-gray",
+ "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth,
+ "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, NULL);
+ break;
+ case PIX_FMT_GRAY16_B:
+ bpp = depth = 16;
+ caps = gst_ff_vid_caps_new (context, "video/x-raw-gray",
+ "bpp", G_TYPE_INT, bpp, "depth", G_TYPE_INT, depth,
+ "endianness", G_TYPE_INT, G_BIG_ENDIAN, NULL);
+ break;
default:
/* give up ... */
break;
@@ -732,6 +744,17 @@ gst_ffmpeg_caps_to_pixfmt (const GstCaps * caps,
case 8:
context->pix_fmt = PIX_FMT_GRAY8;
break;
+ case 16:{
+ gint endianness = 0;
+
+ if (gst_structure_get_int (structure, "endianness", &endianness)) {
+ if (endianness == G_LITTLE_ENDIAN)
+ context->pix_fmt = PIX_FMT_GRAY16_L;
+ else if (endianness == G_BIG_ENDIAN)
+ context->pix_fmt = PIX_FMT_GRAY16_B;
+ }
+ }
+ break;
}
}
}
@@ -905,6 +928,15 @@ gst_ffmpegcsp_avpicture_fill (AVPicture * picture,
picture->data[2] = NULL;
picture->linesize[0] = stride;
return size;
+ case PIX_FMT_GRAY16_L:
+ case PIX_FMT_GRAY16_B:
+ stride = GST_ROUND_UP_4 (width * 2);
+ size = stride * height;
+ picture->data[0] = ptr;
+ picture->data[1] = NULL;
+ picture->data[2] = NULL;
+ picture->linesize[0] = stride;
+ return size;
case PIX_FMT_MONOWHITE:
case PIX_FMT_MONOBLACK:
stride = GST_ROUND_UP_4 ((width + 7) >> 3);
diff --git a/gst/ffmpegcolorspace/imgconvert.c b/gst/ffmpegcolorspace/imgconvert.c
index 010ccd53b..16740a19c 100644
--- a/gst/ffmpegcolorspace/imgconvert.c
+++ b/gst/ffmpegcolorspace/imgconvert.c
@@ -367,6 +367,28 @@ static PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
/* .y_chroma_shift = */ 0,
/* .depth = */ 8,
},
+ /* [PIX_FMT_GRAY16_L] = */ {
+ /* .format = */ PIX_FMT_GRAY16_L,
+ /* .name = */ "gray",
+ /* .nb_channels = */ 1,
+ /* .color_type = */ FF_COLOR_GRAY,
+ /* .pixel_type = */ FF_PIXEL_PLANAR,
+ /* .is_alpha = */ 0,
+ /* .x_chroma_shift = */ 0,
+ /* .y_chroma_shift = */ 0,
+ /* .depth = */ 16,
+ },
+ /* [PIX_FMT_GRAY16_B] = */ {
+ /* .format = */ PIX_FMT_GRAY16_B,
+ /* .name = */ "gray",
+ /* .nb_channels = */ 1,
+ /* .color_type = */ FF_COLOR_GRAY,
+ /* .pixel_type = */ FF_PIXEL_PLANAR,
+ /* .is_alpha = */ 0,
+ /* .x_chroma_shift = */ 0,
+ /* .y_chroma_shift = */ 0,
+ /* .depth = */ 16,
+ },
/* [PIX_FMT_MONOWHITE] = */ {
/* .format = */ PIX_FMT_MONOWHITE,
/* .name = */ "monow",
@@ -2152,6 +2174,133 @@ bitcopy_n (unsigned int a, int n)
#include "imgconvert_template.h"
static void
+gray_to_gray16_l (AVPicture * dst, const AVPicture * src, int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int dst_wrap, src_wrap;
+ int x, y;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - width;
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - 2 * width;
+
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ GST_WRITE_UINT16_LE (q, (*p << 8));
+ q += 2;
+ p++;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+static void
+gray_to_gray16_b (AVPicture * dst, const AVPicture * src, int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int dst_wrap, src_wrap;
+ int x, y;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - width;
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - 2 * width;
+
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ GST_WRITE_UINT16_BE (q, (*p << 8));
+ q += 2;
+ p++;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+static void
+gray16_l_to_gray (AVPicture * dst, const AVPicture * src, int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int dst_wrap, src_wrap;
+ int x, y;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - 2 * width;
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - width;
+
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ q[0] = GST_READ_UINT16_LE (p) >> 8;
+ q++;
+ p += 2;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+static void
+gray16_b_to_gray (AVPicture * dst, const AVPicture * src, int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int dst_wrap, src_wrap;
+ int x, y;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - 2 * width;
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - width;
+
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ q[0] = GST_READ_UINT16_BE (p) >> 8;
+ q++;
+ p += 2;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+static void
+gray16_b_to_gray16_l (AVPicture * dst, const AVPicture * src,
+ int width, int height)
+{
+ const unsigned char *p;
+ unsigned char *q;
+ int dst_wrap, src_wrap;
+ int x, y;
+
+ p = src->data[0];
+ src_wrap = src->linesize[0] - 2 * width;
+
+ q = dst->data[0];
+ dst_wrap = dst->linesize[0] - 2 * width;
+
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ q[0] = p[1];
+ q[1] = p[0];
+ q += 2;
+ p += 2;
+ }
+ p += src_wrap;
+ q += dst_wrap;
+ }
+}
+
+static void
mono_to_gray (AVPicture * dst, const AVPicture * src,
int width, int height, int xor_mask)
{
@@ -2488,11 +2637,18 @@ static ConvertEntry convert_table[] = {
{PIX_FMT_GRAY8, PIX_FMT_ABGR32, gray_to_abgr32},
{PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, gray_to_monowhite},
{PIX_FMT_GRAY8, PIX_FMT_MONOBLACK, gray_to_monoblack},
+ {PIX_FMT_GRAY8, PIX_FMT_GRAY16_L, gray_to_gray16_l},
+ {PIX_FMT_GRAY8, PIX_FMT_GRAY16_B, gray_to_gray16_b},
{PIX_FMT_MONOWHITE, PIX_FMT_GRAY8, monowhite_to_gray},
{PIX_FMT_MONOBLACK, PIX_FMT_GRAY8, monoblack_to_gray},
+ {PIX_FMT_GRAY16_L, PIX_FMT_GRAY8, gray16_l_to_gray},
+ {PIX_FMT_GRAY16_L, PIX_FMT_GRAY16_B, gray16_b_to_gray16_l},
+ {PIX_FMT_GRAY16_B, PIX_FMT_GRAY8, gray16_b_to_gray},
+ {PIX_FMT_GRAY16_B, PIX_FMT_GRAY16_L, gray16_b_to_gray16_l},
+
{PIX_FMT_PAL8, PIX_FMT_RGB555, pal8_to_rgb555},
{PIX_FMT_PAL8, PIX_FMT_RGB565, pal8_to_rgb565},
{PIX_FMT_PAL8, PIX_FMT_BGR24, pal8_to_bgr24},