Added a colorspace library and removed yuv2rgb conversion from the videosink.

Original commit message from CVS:
Added a colorspace library and removed yuv2rgb conversion from the
videosink.
The aviencoder should now more or less work.
This commit is contained in:
Wim Taymans 2000-04-02 21:36:54 +00:00
parent bf8c785fb0
commit 0d9315223a
15 changed files with 909 additions and 55 deletions

View file

@ -300,6 +300,7 @@ gst/elements/Makefile
gst/xml/Makefile gst/xml/Makefile
libs/Makefile libs/Makefile
libs/riff/Makefile libs/riff/Makefile
libs/colorspace/Makefile
plugins/Makefile plugins/Makefile
plugins/au/Makefile plugins/au/Makefile
plugins/wav/Makefile plugins/wav/Makefile

View file

@ -24,23 +24,13 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include <gst/gstmeta.h> #include <gst/gstmeta.h>
#include <libs/colorspace/gstcolorspace.h>
typedef struct _MetaVideoRaw MetaVideoRaw; typedef struct _MetaVideoRaw MetaVideoRaw;
typedef struct _MetaDGA MetaDGA; typedef struct _MetaDGA MetaDGA;
typedef struct _MetaOverlay MetaOverlay; typedef struct _MetaOverlay MetaOverlay;
typedef struct _OverlayClip OverlayClip; typedef struct _OverlayClip OverlayClip;
enum {
GST_META_VIDEORAW_RGB555,
GST_META_VIDEORAW_BGR555,
GST_META_VIDEORAW_RGB565,
GST_META_VIDEORAW_BGR565,
GST_META_VIDEORAW_RGB24, // RGB
GST_META_VIDEORAW_RGB32,
GST_META_VIDEORAW_YUV420, // YUV planar
GST_META_VIDEORAW_YUV422
};
struct _OverlayClip { struct _OverlayClip {
int x1, x2, y1, y2; int x1, x2, y1, y2;
}; };

View file

@ -1,3 +1,3 @@
SUBDIRS = riff SUBDIRS = riff colorspace
DIST_SUBDIRS = riff DIST_SUBDIRS = riff colorspace

7
libs/colorspace/.gitignore vendored Normal file
View file

@ -0,0 +1,7 @@
Makefile
Makefile.in
*.o
*.lo
*.la
.deps
.libs

View file

@ -0,0 +1,15 @@
filterdir = $(libdir)/gst
filter_LTLIBRARIES = libgstcolorspace.la
libgstcolorspace_la_SOURCES = gstcolorspace.c rgb2rgb.c yuv2rgb.c
libgstcolorspaceincludedir = $(includedir)/gst/libs/gstcolorspace.h
libgstcolorspaceinclude_HEADERS = gstcolorspace.h
noinst_HEADERS = yuv2rgb.h
CFLAGS += -Wall -O2 -fomit-frame-pointer -funroll-all-loops -finline-functions -ffast-math
INCLUDES = $(GLIB_CFLAGS) $(GTK_CFLAGS) -I$(top_srcdir)
LDADD = $(GLIB_LIBS) $(GTK_LIBS) $(top_srcdir)/gst/libgst.la

View file

@ -0,0 +1,65 @@
/* Gnome-Streamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
//#define DEBUG_ENABLED
#include <gst/gst.h>
#include <gstcolorspace.h>
extern GstColorSpaceConverter gst_colorspace_rgb2rgb_get_converter(GstColorSpace srcspace,
GstColorSpace destspace);
extern GstColorSpaceConverter gst_colorspace_yuv2rgb_get_converter(GstColorSpace srcspace,
GstColorSpace destspace);
extern GstColorSpaceConverter gst_colorspace_rgb2yuv_get_converter(GstColorSpace srcspace,
GstColorSpace destspace);
extern GstColorSpaceConverter gst_colorspace_yuv2yuv_get_converter(GstColorSpace srcspace,
GstColorSpace destspace);
GstBuffer *gst_colorspace_convert(GstBuffer *src, GstColorSpace dest) {
switch (dest) {
default:
break;
}
return src;
}
GstColorSpaceConverter gst_colorspace_get_converter(GstColorSpace srcspace, GstColorSpace destspace) {
DEBUG("gst_colorspace: get converter\n");
if (GST_COLORSPACE_IS_RGB_TYPE(srcspace)) {
if (GST_COLORSPACE_IS_RGB_TYPE(destspace)) {
return gst_colorspace_rgb2rgb_get_converter(srcspace, destspace);
}
else {
//return gst_colorspace_rgb2yuv_get_converter(srcspace, destspace);
}
}
else if (GST_COLORSPACE_IS_YUV_TYPE(srcspace)) {
if (GST_COLORSPACE_IS_RGB_TYPE(destspace)) {
return gst_colorspace_yuv2rgb_get_converter(srcspace, destspace);
}
else {
//return gst_colorspace_yuv2yuv_get_converter(srcspace, destspace);
}
}
else {
return NULL;
}
return NULL;
}

View file

@ -0,0 +1,70 @@
/* Gnome-Streamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_COLORSPACE_H__
#define __GST_COLORSPACE_H__
#include <gst/gstbuffer.h>
#include <gst/gstplugin.h>
typedef enum {
#define GST_COLORSPACE_RGB_FIRST GST_COLORSPACE_RGB555
GST_COLORSPACE_RGB555,
GST_COLORSPACE_BGR555,
GST_COLORSPACE_RGB565,
GST_COLORSPACE_BGR565,
GST_COLORSPACE_RGB24, // RGB
GST_COLORSPACE_BGR24, // RGB
GST_COLORSPACE_RGB32,
#define GST_COLORSPACE_RGB_LAST GST_COLORSPACE_RGB32
#define GST_COLORSPACE_YUV_FIRST GST_COLORSPACE_YUV420
GST_COLORSPACE_YUV420, // YUV
GST_COLORSPACE_YUV420P, // YUV planar
GST_COLORSPACE_YUV422,
GST_COLORSPACE_YUV422P,
#define GST_COLORSPACE_YUV_LAST GST_COLORSPACE_YUV422P
} GstColorSpace;
typedef struct _GstColorSpaceParameters GstColorSpaceParameters;
struct _GstColorSpaceParameters {
guint width;
guint height;
gchar *outbuf;
};
#define GST_COLORSPACE_IS_RGB_TYPE(type) ((type)>=GST_COLORSPACE_RGB_FIRST && \
(type)<=GST_COLORSPACE_RGB_LAST)
#define GST_COLORSPACE_IS_YUV_TYPE(type) ((type)>=GST_COLORSPACE_YUV_FIRST && \
(type)<=GST_COLORSPACE_YUV_LAST)
typedef GstBuffer * (*GstColorSpaceConverter) (GstBuffer *src, GstColorSpaceParameters *params);
GstColorSpaceConverter gst_colorspace_get_converter(GstColorSpace srcspace, GstColorSpace destspace);
/* convert a buffer to a new buffer in the given colorspace */
GstBuffer *gst_colorspace_convert(GstBuffer *buf, GstColorSpace destspace);
#endif /* __GST_COLORSPACE_H__ */

71
libs/colorspace/rgb2rgb.c Normal file
View file

@ -0,0 +1,71 @@
/* Gnome-Streamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
//#define DEBUG_ENABLED
#include <gst/gst.h>
#include <gstcolorspace.h>
static GstBuffer *gst_colorspace_rgb24_to_bgr24(GstBuffer *src, GstColorSpaceParameters *params);
GstColorSpaceConverter gst_colorspace_rgb2rgb_get_converter(GstColorSpace src, GstColorSpace dest) {
switch(src) {
case GST_COLORSPACE_RGB24:
switch(dest) {
case GST_COLORSPACE_BGR24:
return gst_colorspace_rgb24_to_bgr24;
default:
break;
}
break;
case GST_COLORSPACE_BGR24:
switch(dest) {
case GST_COLORSPACE_RGB24:
return gst_colorspace_rgb24_to_bgr24;
default:
break;
}
break;
default:
break;
}
return NULL;
}
static GstBuffer *gst_colorspace_rgb24_to_bgr24(GstBuffer *src, GstColorSpaceParameters *params) {
gint size;
gchar temp;
gchar *data;
DEBUG("gst_colorspace_rgb24_to_bgr24 %d\n", GST_BUFFER_SIZE(src));
data = GST_BUFFER_DATA(src);
size = GST_BUFFER_SIZE(src)/3;
while (size--) {
temp = data[0];
data[0] = data[2];
data[2] = temp;
data+=3;
}
DEBUG("gst_colorspace_rgb24_to_bgr24 end %d\n", GST_BUFFER_SIZE(src));
return src;
}

518
libs/colorspace/yuv2rgb.c Normal file
View file

@ -0,0 +1,518 @@
/* Gnome-Streamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <math.h>
#include <stdlib.h>
//#define DEBUG_ENABLED
#include <gst/gst.h>
#include <gstcolorspace.h>
#include "yuv2rgb.h"
static GstBuffer *gst_colorspace_yuv422P_to_rgb24(GstBuffer *src, GstColorSpaceParameters *params);
static GstBuffer *gst_colorspace_yuv422P_to_rgb16(GstBuffer *src, GstColorSpaceParameters *params);
static void gst_colorspace_yuv_to_rgb16(GstColorSpaceYUVTables *tables,
unsigned char *lum,
unsigned char *cr,
unsigned char *cb,
unsigned char *out,
int cols, int rows);
static GstColorSpaceYUVTables * gst_colorspace_init_yuv(long depth,
long red_mask, long green_mask, long blue_mask);
GstColorSpaceConverter gst_colorspace_yuv2rgb_get_converter(GstColorSpace src, GstColorSpace dest) {
DEBUG("gst_colorspace_yuv2rgb_get_converter\n");
switch(src) {
case GST_COLORSPACE_YUV422P:
switch(dest) {
case GST_COLORSPACE_RGB24:
return gst_colorspace_yuv422P_to_rgb24;
case GST_COLORSPACE_RGB555:
case GST_COLORSPACE_RGB565:
return gst_colorspace_yuv422P_to_rgb16;
default:
break;
}
break;
default:
break;
}
return NULL;
}
static GstBuffer *gst_colorspace_yuv422P_to_rgb24(GstBuffer *src, GstColorSpaceParameters *params) {
DEBUG("gst_colorspace_yuv422P_to_rgb24\n");
return src;
}
static GstBuffer *gst_colorspace_yuv422P_to_rgb16(GstBuffer *src, GstColorSpaceParameters *params) {
static GstColorSpaceYUVTables *color_tables = NULL;
DEBUG("gst_colorspace_yuv422P_to_rgb16\n");
g_return_val_if_fail(params != NULL, NULL);
if (color_tables == NULL) {
color_tables = gst_colorspace_init_yuv(16, 0xF800, 0x07E0, 0x001F);
}
gst_colorspace_yuv_to_rgb16(color_tables,
GST_BUFFER_DATA(src), // Y component
GST_BUFFER_DATA(src)+params->width*params->height, // cr component
GST_BUFFER_DATA(src)+params->width*params->height+
(params->width*params->height)/4, // cb component
params->outbuf,
params->height,
params->width);
return src;
}
/*
* How many 1 bits are there in the longword.
* Low performance, do not call often.
*/
static int
number_of_bits_set(a)
unsigned long a;
{
if(!a) return 0;
if(a & 1) return 1 + number_of_bits_set(a >> 1);
return(number_of_bits_set(a >> 1));
}
/*
* Shift the 0s in the least significant end out of the longword.
* Low performance, do not call often.
*/
static unsigned long
shifted_down(a)
unsigned long a;
{
if(!a) return 0;
if(a & 1) return a;
return a >> 1;
}
/*
* How many 0 bits are there at most significant end of longword.
* Low performance, do not call often.
*/
static int
free_bits_at_top(a)
unsigned long a;
{
/* assume char is 8 bits */
if(!a) return sizeof(unsigned long) * 8;
/* assume twos complement */
if(((long)a) < 0l) return 0;
return 1 + free_bits_at_top ( a << 1);
}
/*
* How many 0 bits are there at least significant end of longword.
* Low performance, do not call often.
*/
static int
free_bits_at_bottom(a)
unsigned long a;
{
/* assume char is 8 bits */
if(!a) return sizeof(unsigned long) * 8;
if(((long)a) & 1l) return 0;
return 1 + free_bits_at_bottom ( a >> 1);
}
/*
*--------------------------------------------------------------
*
* InitColor16Dither --
*
* To get rid of the multiply and other conversions in color
* dither, we use a lookup table.
*
* Results:
* None.
*
* Side effects:
* The lookup tables are initialized.
*
*--------------------------------------------------------------
*/
static GstColorSpaceYUVTables *
gst_colorspace_init_yuv(long depth, long red_mask, long green_mask, long blue_mask)
{
int CR, CB, i;
int *L_tab, *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab;
long *r_2_pix_alloc;
long *g_2_pix_alloc;
long *b_2_pix_alloc;
GstColorSpaceYUVTables *tables = g_malloc(sizeof(GstColorSpaceYUVTables));
L_tab = tables->L_tab = (int *)malloc(256*sizeof(int));
Cr_r_tab = tables->Cr_r_tab = (int *)malloc(256*sizeof(int));
Cr_g_tab = tables->Cr_g_tab = (int *)malloc(256*sizeof(int));
Cb_g_tab = tables->Cb_g_tab = (int *)malloc(256*sizeof(int));
Cb_b_tab = tables->Cb_b_tab = (int *)malloc(256*sizeof(int));
r_2_pix_alloc = (long *)malloc(768*sizeof(long));
g_2_pix_alloc = (long *)malloc(768*sizeof(long));
b_2_pix_alloc = (long *)malloc(768*sizeof(long));
if (L_tab == NULL ||
Cr_r_tab == NULL ||
Cr_g_tab == NULL ||
Cb_g_tab == NULL ||
Cb_b_tab == NULL ||
r_2_pix_alloc == NULL ||
g_2_pix_alloc == NULL ||
b_2_pix_alloc == NULL) {
fprintf(stderr, "Could not get enough memory in InitColorDither\n");
exit(1);
}
for (i=0; i<256; i++) {
L_tab[i] = i;
/*
if (gammaCorrectFlag) {
L_tab[i] = GAMMA_CORRECTION(i);
}
*/
CB = CR = i;
/*
if (chromaCorrectFlag) {
CB -= 128;
CB = CHROMA_CORRECTION128(CB);
CR -= 128;
CR = CHROMA_CORRECTION128(CR);
}
else
*/
{
CB -= 128; CR -= 128;
}
Cr_r_tab[i] = (0.419/0.299) * CR;
Cr_g_tab[i] = -(0.299/0.419) * CR;
Cb_g_tab[i] = -(0.114/0.331) * CB;
Cb_b_tab[i] = (0.587/0.331) * CB;
}
/*
* Set up entries 0-255 in rgb-to-pixel value tables.
*/
for (i = 0; i < 256; i++) {
r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(red_mask));
r_2_pix_alloc[i + 256] <<= free_bits_at_bottom(red_mask);
g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(green_mask));
g_2_pix_alloc[i + 256] <<= free_bits_at_bottom(green_mask);
b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set(blue_mask));
b_2_pix_alloc[i + 256] <<= free_bits_at_bottom(blue_mask);
/*
* If we have 16-bit output depth, then we double the value
* in the top word. This means that we can write out both
* pixels in the pixel doubling mode with one op. It is
* harmless in the normal case as storing a 32-bit value
* through a short pointer will lose the top bits anyway.
* A similar optimisation for Alpha for 64 bit has been
* prepared for, but is not yet implemented.
*/
if(!(depth == 32)) {
r_2_pix_alloc[i + 256] |= (r_2_pix_alloc[i + 256]) << 16;
g_2_pix_alloc[i + 256] |= (g_2_pix_alloc[i + 256]) << 16;
b_2_pix_alloc[i + 256] |= (b_2_pix_alloc[i + 256]) << 16;
}
#ifdef SIXTYFOUR_BIT
if(depth == 32) {
r_2_pix_alloc[i + 256] |= (r_2_pix_alloc[i + 256]) << 32;
g_2_pix_alloc[i + 256] |= (g_2_pix_alloc[i + 256]) << 32;
b_2_pix_alloc[i + 256] |= (b_2_pix_alloc[i + 256]) << 32;
}
#endif
}
/*
* Spread out the values we have to the rest of the array so that
* we do not need to check for overflow.
*/
for (i = 0; i < 256; i++) {
r_2_pix_alloc[i] = r_2_pix_alloc[256];
r_2_pix_alloc[i+ 512] = r_2_pix_alloc[511];
g_2_pix_alloc[i] = g_2_pix_alloc[256];
g_2_pix_alloc[i+ 512] = g_2_pix_alloc[511];
b_2_pix_alloc[i] = b_2_pix_alloc[256];
b_2_pix_alloc[i+ 512] = b_2_pix_alloc[511];
}
tables->r_2_pix = r_2_pix_alloc + 256;
tables->g_2_pix = g_2_pix_alloc + 256;
tables->b_2_pix = b_2_pix_alloc + 256;
return tables;
}
/*
*--------------------------------------------------------------
*
* Color16DitherImage --
*
* Converts image into 16 bit color.
*
* Results:
* None.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
static void
gst_colorspace_yuv_to_rgb16(tables, lum, cr, cb, out, rows, cols)
GstColorSpaceYUVTables *tables;
unsigned char *lum;
unsigned char *cr;
unsigned char *cb;
unsigned char *out;
int cols, rows;
{
int L, CR, CB;
unsigned short *row1, *row2;
unsigned char *lum2;
int x, y;
int cr_r;
int cr_g;
int cb_g;
int cb_b;
int cols_2 = cols/2;
row1 = (unsigned short *)out;
row2 = row1 + cols_2 + cols_2;
lum2 = lum + cols_2 + cols_2;
for (y=0; y<rows; y+=2) {
for (x=0; x<cols_2; x++) {
int R, G, B;
CR = *cr++;
CB = *cb++;
cr_r = tables->Cr_r_tab[CR];
cr_g = tables->Cr_g_tab[CR];
cb_g = tables->Cb_g_tab[CB];
cb_b = tables->Cb_b_tab[CB];
L = tables->L_tab[(int) *lum++];
R = L + cr_r;
G = L + cr_g + cb_g;
B = L + cb_b;
*row1++ = (tables->r_2_pix[R] | tables->g_2_pix[G] | tables->b_2_pix[B]);
#ifdef INTERPOLATE
if(x != cols_2 - 1) {
CR = (CR + *cr) >> 1;
CB = (CB + *cb) >> 1;
cr_r = tables->Cr_r_tab[CR];
cr_g = tables->Cr_g_tab[CR];
cb_g = tables->Cb_g_tab[CB];
cb_b = tables->Cb_b_tab[CB];
}
#endif
L = tables->L_tab[(int) *lum++];
R = L + cr_r;
G = L + cr_g + cb_g;
B = L + cb_b;
*row1++ = (tables->r_2_pix[R] | tables->g_2_pix[G] | tables->b_2_pix[B]);
/*
* Now, do second row.
*/
#ifdef INTERPOLATE
if(y != rows - 2) {
CR = (CR + *(cr + cols_2 - 1)) >> 1;
CB = (CB + *(cb + cols_2 - 1)) >> 1;
cr_r = tables->Cr_r_tab[CR];
cr_g = tables->Cr_g_tab[CR];
cb_g = tables->Cb_g_tab[CB];
cb_b = tables->Cb_b_tab[CB];
}
#endif
L = tables->L_tab[(int) *lum2++];
R = L + cr_r;
G = L + cr_g + cb_g;
B = L + cb_b;
*row2++ = (tables->r_2_pix[R] | tables->g_2_pix[G] | tables->b_2_pix[B]);
L = tables->L_tab[(int) *lum2++];
R = L + cr_r;
G = L + cr_g + cb_g;
B = L + cb_b;
*row2++ = (tables->r_2_pix[R] | tables->g_2_pix[G] | tables->b_2_pix[B]);
}
/*
* These values are at the start of the next line, (due
* to the ++'s above),but they need to be at the start
* of the line after that.
*/
lum += cols_2 + cols_2;
lum2 += cols_2 + cols_2;
row1 += cols_2 + cols_2;
row2 += cols_2 + cols_2;
}
}
/*
*--------------------------------------------------------------
*
* Color32DitherImage --
*
* Converts image into 32 bit color (or 24-bit non-packed).
*
* Results:
* None.
*
* Side effects:
* None.
*
*--------------------------------------------------------------
*/
/*
* This is a copysoft version of the function above with ints instead
* of shorts to cause a 4-byte pixel size
*/
static void
gst_colorspace_yuv_to_rgb32(tables, lum, cr, cb, out, rows, cols)
GstColorSpaceYUVTables *tables;
unsigned char *lum;
unsigned char *cr;
unsigned char *cb;
unsigned char *out;
int cols, rows;
{
int L, CR, CB;
unsigned int *row1, *row2;
unsigned char *lum2;
int x, y;
int cr_r;
int cr_g;
int cb_g;
int cb_b;
int cols_2 = cols / 2;
row1 = (unsigned int *)out;
row2 = row1 + cols_2 + cols_2;
lum2 = lum + cols_2 + cols_2;
for (y=0; y<rows; y+=2) {
for (x=0; x<cols_2; x++) {
int R, G, B;
CR = *cr++;
CB = *cb++;
cr_r = tables->Cr_r_tab[CR];
cr_g = tables->Cr_g_tab[CR];
cb_g = tables->Cb_g_tab[CB];
cb_b = tables->Cb_b_tab[CB];
L = tables->L_tab[(int) *lum++];
R = L + cr_r;
G = L + cr_g + cb_g;
B = L + cb_b;
*row1++ = (tables->r_2_pix[R] | tables->g_2_pix[G] | tables->b_2_pix[B]);
#ifdef INTERPOLATE
if(x != cols_2 - 1) {
CR = (CR + *cr) >> 1;
CB = (CB + *cb) >> 1;
cr_r = tables->Cr_r_tab[CR];
cr_g = tables->Cr_g_tab[CR];
cb_g = tables->Cb_g_tab[CB];
cb_b = tables->Cb_b_tab[CB];
}
#endif
L = tables->L_tab[(int) *lum++];
R = L + cr_r;
G = L + cr_g + cb_g;
B = L + cb_b;
*row1++ = (tables->r_2_pix[R] | tables->g_2_pix[G] | tables->b_2_pix[B]);
/*
* Now, do second row.
*/
#ifdef INTERPOLATE
if(y != rows - 2) {
CR = (CR + *(cr + cols_2 - 1)) >> 1;
CB = (CB + *(cb + cols_2 - 1)) >> 1;
cr_r = tables->Cr_r_tab[CR];
cr_g = tables->Cr_g_tab[CR];
cb_g = tables->Cb_g_tab[CB];
cb_b = tables->Cb_b_tab[CB];
}
#endif
L = tables->L_tab [(int) *lum2++];
R = L + cr_r;
G = L + cr_g + cb_g;
B = L + cb_b;
*row2++ = (tables->r_2_pix[R] | tables->g_2_pix[G] | tables->b_2_pix[B]);
L = tables->L_tab [(int) *lum2++];
R = L + cr_r;
G = L + cr_g + cb_g;
B = L + cb_b;
*row2++ = (tables->r_2_pix[R] | tables->g_2_pix[G] | tables->b_2_pix[B]);
}
lum += cols_2 + cols_2;
lum2 += cols_2 + cols_2;
row1 += cols_2 + cols_2;
row2 += cols_2 + cols_2;
}
}

64
libs/colorspace/yuv2rgb.h Normal file
View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 1995 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice and the following
* two paragraphs appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
typedef struct _GstColorSpaceYUVTables GstColorSpaceYUVTables;
struct _GstColorSpaceYUVTables {
int gammaCorrectFlag;
double gammaCorrect;
int chromaCorrectFlag;
double chromaCorrect;
int *L_tab, *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab;
/*
* We define tables that convert a color value between -256 and 512
* into the R, G and B parts of the pixel. The normal range is 0-255.
**/
long *r_2_pix;
long *g_2_pix;
long *b_2_pix;
};
#define CB_BASE 1
#define CR_BASE (CB_BASE*CB_RANGE)
#define LUM_BASE (CR_BASE*CR_RANGE)
#define Min(x,y) (((x) < (y)) ? (x) : (y))
#define Max(x,y) (((x) > (y)) ? (x) : (y))
#define GAMMA_CORRECTION(x) ((int)(pow((x) / 255.0, 1.0 / gammaCorrect) * 255.0))
#define CHROMA_CORRECTION256(x) ((x) >= 128 \
? 128 + Min(127, (int)(((x) - 128.0) * chromaCorrect)) \
: 128 - Min(128, (int)((128.0 - (x)) * chromaCorrect)))
#define CHROMA_CORRECTION128(x) ((x) >= 0 \
? Min(127, (int)(((x) * chromaCorrect))) \
: Max(-128, (int)(((x) * chromaCorrect))))
#define CHROMA_CORRECTION256D(x) ((x) >= 128 \
? 128.0 + Min(127.0, (((x) - 128.0) * chromaCorrect)) \
: 128.0 - Min(128.0, (((128.0 - (x)) * chromaCorrect))))
#define CHROMA_CORRECTION128D(x) ((x) >= 0 \
? Min(127.0, ((x) * chromaCorrect)) \
: Max(-128.0, ((x) * chromaCorrect)))

View file

@ -2,7 +2,7 @@ filterdir = $(libdir)/gst
filter_LTLIBRARIES = libgstriff.la filter_LTLIBRARIES = libgstriff.la
libgstriff_la_SOURCES = gstriff.c libgstriff_la_SOURCES = gstriffparse.c gstriffencode.c gstriffutil.c
noinst_HEADERS = gstriff.h noinst_HEADERS = gstriff.h

View file

@ -26,10 +26,19 @@
#include <gst/gstplugin.h> #include <gst/gstplugin.h>
#define GST_RIFF_OK 0
#define GST_RIFF_ENOTRIFF -1 /* not a RIFF file */ #define GST_RIFF_ENOTRIFF -1 /* not a RIFF file */
#define GST_RIFF_EINVAL -2 /* wrong parameters */ #define GST_RIFF_EINVAL -2 /* wrong parameters */
#define GST_RIFF_ENOMEM -3 /* out of memory */ #define GST_RIFF_ENOMEM -3 /* out of memory */
/* states */
#define GST_RIFF_STATE_INITIAL 0
#define GST_RIFF_STATE_HASAVIH 1
#define GST_RIFF_STATE_HASSTRH 2
#define GST_RIFF_STATE_HASSTRF 3
#define GST_RIFF_STATE_MOVI 4
#define MAKE_FOUR_CC(a,b,c,d) ( ((guint32)a) | (((guint32)b)<< 8) | \ #define MAKE_FOUR_CC(a,b,c,d) ( ((guint32)a) | (((guint32)b)<< 8) | \
((guint32)c)<<16 | (((guint32)d)<<24) ) ((guint32)c)<<16 | (((guint32)d)<<24) )
@ -190,7 +199,7 @@
#define GST_RIFF_rec MAKE_FOUR_CC( 'r', 'e', 'c', ' ') #define GST_RIFF_rec MAKE_FOUR_CC( 'r', 'e', 'c', ' ')
/* common data structures */ /* common data structures */
struct gst_riff_avih { struct _gst_riff_avih {
guint32 us_frame; /* microsec per frame */ guint32 us_frame; /* microsec per frame */
guint32 max_bps; /* byte/s overall */ guint32 max_bps; /* byte/s overall */
guint32 pad_gran; /* pad_gran (???) */ guint32 pad_gran; /* pad_gran (???) */
@ -213,8 +222,8 @@ struct gst_riff_avih {
guint32 length; guint32 length;
}; };
struct gst_riff_strh { struct _gst_riff_strh {
gchar type[4]; /* stream type */ guint32 type; /* stream type */
guint32 fcc_handler; /* fcc_handler */ guint32 fcc_handler; /* fcc_handler */
guint32 flags; guint32 flags;
/* flags values */ /* flags values */
@ -232,13 +241,13 @@ struct gst_riff_strh {
/* XXX 16 bytes ? */ /* XXX 16 bytes ? */
}; };
struct gst_riff_strf_vids { /* == BitMapInfoHeader */ struct _gst_riff_strf_vids { /* == BitMapInfoHeader */
guint32 size; guint32 size;
guint32 width; guint32 width;
guint32 height; guint32 height;
guint16 planes; guint16 planes;
guint16 bit_cnt; guint16 bit_cnt;
gchar compression[4]; guint32 compression;
guint32 image_size; guint32 image_size;
guint32 xpels_meter; guint32 xpels_meter;
guint32 ypels_meter; guint32 ypels_meter;
@ -248,7 +257,7 @@ struct gst_riff_strf_vids { /* == BitMapInfoHeader */
}; };
struct gst_riff_strf_auds { /* == WaveHeader (?) */ struct _gst_riff_strf_auds { /* == WaveHeader (?) */
guint16 format; guint16 format;
/**** from public Microsoft RIFF docs ******/ /**** from public Microsoft RIFF docs ******/
#define GST_RIFF_WAVE_FORMAT_UNKNOWN (0x0000) #define GST_RIFF_WAVE_FORMAT_UNKNOWN (0x0000)
@ -274,7 +283,31 @@ struct gst_riff_strf_auds { /* == WaveHeader (?) */
guint16 size; guint16 size;
}; };
struct _gst_riff_riff {
guint32 id;
guint32 size;
guint32 type;
};
struct _gst_riff_list {
guint32 id;
guint32 size;
guint32 type;
};
struct _gst_riff_chunk {
guint32 id;
guint32 size;
};
typedef struct _gst_riff_riff gst_riff_riff;
typedef struct _gst_riff_list gst_riff_list;
typedef struct _gst_riff_chunk gst_riff_chunk;
typedef struct _gst_riff_avih gst_riff_avih;
typedef struct _gst_riff_strh gst_riff_strh;
typedef struct _gst_riff_strf_vids gst_riff_strf_vids;
typedef struct _gst_riff_strf_auds gst_riff_strf_auds;
typedef struct _GstRiff GstRiff; typedef struct _GstRiff GstRiff;
typedef struct _GstRiffChunk GstRiffChunk; typedef struct _GstRiffChunk GstRiffChunk;
@ -313,9 +346,20 @@ struct _GstRiffChunk {
}; };
GstRiff *gst_riff_new(GstRiffCallback function, gpointer data); /* from gstriffparse.c */
gint gst_riff_next_buffer(GstRiff *riff,GstBuffer *buf,gulong off); GstRiff *gst_riff_parser_new(GstRiffCallback function, gpointer data);
gint gst_riff_parser_next_buffer(GstRiff *riff,GstBuffer *buf,gulong off);
/* from gstriffencode.c */
GstRiff *gst_riff_encoder_new(guint32 type);
gint gst_riff_encoder_avih(GstRiff *riff, gst_riff_avih *head, gulong size);
gint gst_riff_encoder_strh(GstRiff *riff, guint32 fcc_type, gst_riff_strh *head, gulong size);
gint gst_riff_encoder_strf(GstRiff *riff, void *format, gulong size);
gint gst_riff_encoder_chunk(GstRiff *riff, guint32 chunk_type, void *chunk, gulong size);
GstBuffer *gst_riff_encoder_get_buffer(GstRiff *riff);
GstBuffer *gst_riff_encoder_get_and_reset_buffer(GstRiff *riff);
/* from gstriffutil.c */
gulong gst_riff_fourcc_to_id(gchar *fourcc); gulong gst_riff_fourcc_to_id(gchar *fourcc);
gchar *gst_riff_id_to_fourcc(gulong id); gchar *gst_riff_id_to_fourcc(gulong id);

View file

@ -22,8 +22,10 @@ ac3play_SOURCES = ac3play.c mem.c
noinst_HEADERS = mem.h noinst_HEADERS = mem.h
LDADD = $(GLIB_LIBS) $(GTK_LIBS) $(top_builddir)/gst/libgst.la \ #LDADD = $(GLIB_LIBS) $(GTK_LIBS) $(top_builddir)/gst/libgst.la \
$(top_builddir)/plugins/videosink/libvideosink.la # $(top_builddir)/plugins/videosink/libvideosink.la -L/usr/X11/lib -lXxf86dga
LDADD = $(GLIB_LIBS) $(GTK_LIBS) $(top_builddir)/gst/libgst.la
INCLUDES = $(GLIB_CFLAGS) $(GTK_CFLAGS) -I$(top_srcdir) \ INCLUDES = $(GLIB_CFLAGS) $(GTK_CFLAGS) -I$(top_srcdir) \
$(shell gnome-config --cflags gnomeui) $(shell gnome-config --cflags gnomeui)

View file

@ -7,8 +7,8 @@
int main(int argc,char *argv[]) { int main(int argc,char *argv[]) {
int fd; int fd;
GstPipeline *pipeline; GstPipeline *pipeline;
GstElement *audiosrc, *videosrc, *fdsink, *encoder; GstElement *audiosrc, *videosrc, *fdsink, *encoder, *compress;
GstElementFactory *audiosrcfactory, *fdsinkfactory, *encoderfactory; GstElementFactory *audiosrcfactory, *fdsinkfactory, *encoderfactory, *compressfactory;
GstElementFactory *videosrcfactory; GstElementFactory *videosrcfactory;
GList *padlist; GList *padlist;
@ -16,6 +16,7 @@ int main(int argc,char *argv[]) {
gst_plugin_load("v4lsrc"); gst_plugin_load("v4lsrc");
gst_plugin_load("aviencoder"); gst_plugin_load("aviencoder");
gst_plugin_load("jpeg");
pipeline = gst_pipeline_new("pipeline"); pipeline = gst_pipeline_new("pipeline");
@ -23,9 +24,13 @@ int main(int argc,char *argv[]) {
audiosrc = gst_elementfactory_create(audiosrcfactory,"audiosrc"); audiosrc = gst_elementfactory_create(audiosrcfactory,"audiosrc");
videosrcfactory = gst_elementfactory_find("v4lsrc"); videosrcfactory = gst_elementfactory_find("v4lsrc");
videosrc = gst_elementfactory_create(videosrcfactory,"videosrc"); videosrc = gst_elementfactory_create(videosrcfactory,"videosrc");
compressfactory = gst_elementfactory_find("jpegenc");
compress = gst_elementfactory_create(compressfactory,"jpegenc");
encoderfactory = gst_elementfactory_find("aviencoder"); encoderfactory = gst_elementfactory_find("aviencoder");
encoder = gst_elementfactory_create(encoderfactory,"aviencoder"); encoder = gst_elementfactory_create(encoderfactory,"aviencoder");
gtk_object_set(GTK_OBJECT(videosrc),"width",120,"height",80,NULL); gtk_object_set(GTK_OBJECT(videosrc),"width",256,"height",192,NULL);
gtk_object_set(GTK_OBJECT(encoder),"video","00:MJPG",NULL);
fd = open(argv[1],O_CREAT|O_RDWR|O_TRUNC); fd = open(argv[1],O_CREAT|O_RDWR|O_TRUNC);
@ -40,6 +45,8 @@ int main(int argc,char *argv[]) {
/* connect src to sink */ /* connect src to sink */
gst_pad_connect(gst_element_get_pad(videosrc,"src"), gst_pad_connect(gst_element_get_pad(videosrc,"src"),
gst_element_get_pad(compress,"sink"));
gst_pad_connect(gst_element_get_pad(compress,"src"),
gst_element_get_pad(encoder,"video_00")); gst_element_get_pad(encoder,"video_00"));
gst_pad_connect(gst_element_get_pad(encoder,"src"), gst_pad_connect(gst_element_get_pad(encoder,"src"),
gst_element_get_pad(fdsink,"sink")); gst_element_get_pad(fdsink,"sink"));