ffmpegcolorspace: Add support for 16 bit grayscale in little/big endian

This commit is contained in:
Sebastian Dröge 2009-05-26 14:58:28 +02:00
parent d48a5614f4
commit 9d02d1d8ab
3 changed files with 190 additions and 0 deletions

View file

@ -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

View file

@ -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);

View file

@ -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",
@ -2151,6 +2173,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},