Added plain C scaler

Original commit message from CVS:
Added plain C scaler
Fixed a bug for 32 bits displays
This commit is contained in:
Wim Taymans 2001-01-26 21:19:49 +00:00
parent 59211a49ff
commit de37358730
8 changed files with 280 additions and 1311 deletions

View file

@ -2,11 +2,18 @@ filterdir = $(libdir)/gst
filter_LTLIBRARIES = libgstvideoscale.la filter_LTLIBRARIES = libgstvideoscale.la
libgstvideoscale_la_SOURCES = gstvideoscale.c if HAVE_CPU_I386
SCALER = gstscale_x86.c
else
SCALER =
endif
libgstvideoscale_la_SOURCES = gstvideoscale.c $(SCALER)
libgstvideoscaleincludedir = $(includedir)/gst/libs/gstvideoscale libgstvideoscaleincludedir = $(includedir)/gst/libs/gstvideoscale
libgstvideoscaleinclude_HEADERS = gstvideoscale.h libgstvideoscaleinclude_HEADERS = gstvideoscale.h
noinst_HEADERS = yuv2rgb.h noinst_HEADERS = gstscale_x86.h
CFLAGS += -O1 $(FOMIT_FRAME_POINTER) -funroll-all-loops -finline-functions -ffast-math #CFLAGS += -S -O1 $(FOMIT_FRAME_POINTER) -funroll-all-loops -finline-functions -ffast-math
CFLAGS = -g $(GLIB_CFLAGS) $(GST_CFLAGS) $(XML_CFLAGS) -O5 -fomit-frame-pointer -ffast-math

View file

@ -0,0 +1,118 @@
/* 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 "gstvideoscale.h"
/* scalers */
void gst_videoscale_generate_rowbytes_x86 (unsigned char *copy_row, int src_w, int dst_w, int bpp);
void gst_videoscale_scale_nearest_x86 (GstVideoScale *scale,
unsigned char *src, unsigned char *dest,
int sw, int sh, int dw, int dh);
#define PREFIX16 0x66
#define STORE_BYTE 0xAA
#define STORE_WORD 0xAB
#define LOAD_BYTE 0xAC
#define LOAD_WORD 0xAD
#define RETURN 0xC3
void
gst_videoscale_generate_rowbytes_x86 (unsigned char *copy_row, int src_w, int dst_w, int bpp)
{
int i;
int pos, inc;
unsigned char *eip;
unsigned char load, store;
GST_DEBUG (0,"videoscale: setup scaling %p\n", copy_row);
switch (bpp) {
case 1:
load = LOAD_BYTE;
store = STORE_BYTE;
break;
case 2:
case 4:
load = LOAD_WORD;
store = STORE_WORD;
break;
default:
return;
}
pos = 0x10000;
inc = (src_w << 16) / dst_w;
eip = copy_row;
for ( i=0; i<dst_w; ++i ) {
while ( pos >= 0x10000L ) {
if ( bpp == 2 ) {
*eip++ = PREFIX16;
}
*eip++ = load;
pos -= 0x10000L;
}
if ( bpp == 2 ) {
*eip++ = PREFIX16;
}
*eip++ = store;
pos += inc;
}
*eip++ = RETURN;
GST_DEBUG (0,"scaler start/end %p %p %p\n", copy_row, eip, (void*)(eip-copy_row));
}
void
gst_videoscale_scale_nearest_x86 (GstVideoScale *scale,
unsigned char *src,
unsigned char *dest,
int sw, int sh, int dw, int dh)
{
int pos, inc, y;
int u1, u2;
scale->temp = scale->copy_row;
GST_DEBUG (0,"videoscale: scaling nearest %p %p %p %d\n", scale->copy_row, src, dest, dw);
pos = 0x10000;
inc = (sh<<16)/dh;
for (y = dh; y > 0; y--) {
while (pos >0x10000) {
src += sw;
pos-=0x10000;
}
__asm__ __volatile__ ("
movl %2, %%eax\n
call *%%eax
"
: "=&D" (u1), "=&S" (u2)
: "g" (scale->temp), "0" (dest), "1" (src)
: "memory" );
dest+= dw;
pos += inc;
}
GST_DEBUG(0,"videoscale: scaling nearest done %p\n", scale->copy_row);
}

View file

@ -0,0 +1,30 @@
/* 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_VIDEOSCALE__X86_H__
#define __GST_VIDEOSCALE__X86_H__
/* scalers */
void gst_videoscale_generate_rowbytes_x86 (unsigned char *copy_row, int src_w, int dst_w, int bpp);
void gst_videoscale_scale_nearest_x86 (GstVideoScale *scale,
unsigned char *src, unsigned char *dest,
int sw, int sh, int dw, int dh);
#endif /* __GST_VIDEOSCALE__X86_H__ */

View file

@ -21,27 +21,34 @@
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "config.h"
#include "gstvideoscale.h" #include "gstvideoscale.h"
#ifdef HAVE_CPU_I386
#include "gstscale_x86.h"
#endif
//FIXME //FIXME
#include <gst/meta/videoraw.h> #include <gst/meta/videoraw.h>
static void gst_videoscale_scale_yuv(GstVideoScale *scale, unsigned char *src, unsigned char *dest); static void gst_videoscale_scale_yuv (GstVideoScale *scale, unsigned char *src, unsigned char *dest);
static void gst_videoscale_scale_rgb(GstVideoScale *scale, unsigned char *src, unsigned char *dest); static void gst_videoscale_scale_rgb (GstVideoScale *scale, unsigned char *src, unsigned char *dest);
/* scalers */ /* scalers */
static void generate_rowbytes(unsigned char *copy_row, int src_w, int dst_w, int bpp); static void gst_videoscale_scale_nearest (GstVideoScale *scale, unsigned char *src, unsigned char *dest,
static void gst_videoscale_scale_nearest(GstVideoScale *scale, unsigned char *src, unsigned char *dest, int sw, int sh, int dw, int dh); int sw, int sh, int dw, int dh);
static void gst_videoscale_scale_plane_slow(GstVideoScale *scale, unsigned char *src, unsigned char *dest, int sw, int sh, int dw, int dh); static void gst_videoscale_scale_plane_slow (GstVideoScale *scale, unsigned char *src, unsigned char *dest,
static void gst_videoscale_scale_point_sample(GstVideoScale *scale, unsigned char *src, unsigned char *dest, int sw, int sh, int dw, int dh); int sw, int sh, int dw, int dh);
static void gst_videoscale_scale_point_sample (GstVideoScale *scale, unsigned char *src, unsigned char *dest,
int sw, int sh, int dw, int dh);
/* filters */ /* filters */
static unsigned char gst_videoscale_bilinear(unsigned char *src, double x, double y, int sw, int sh); static unsigned char gst_videoscale_bilinear (unsigned char *src, double x, double y, int sw, int sh);
static unsigned char gst_videoscale_bicubic(unsigned char *src, double x, double y, int sw, int sh); static unsigned char gst_videoscale_bicubic (unsigned char *src, double x, double y, int sw, int sh);
GstVideoScale *gst_videoscale_new(gint sw, gint sh, gint dw, gint dh, GstColorSpaceType format, GstVideoScaleMethod method) GstVideoScale*
gst_videoscale_new (gint sw, gint sh, gint dw, gint dh,
GstColorSpaceType format, GstVideoScaleMethod method)
{ {
GstVideoScale *new = g_malloc(sizeof(GstVideoScale)); GstVideoScale *new = g_malloc(sizeof(GstVideoScale));
gint scale_bytes;
new->source_width = sw; new->source_width = sw;
new->source_height = sh; new->source_height = sh;
@ -54,19 +61,19 @@ GstVideoScale *gst_videoscale_new(gint sw, gint sh, gint dw, gint dh, GstColorSp
switch (format) { switch (format) {
case GST_COLORSPACE_YUV420P: case GST_COLORSPACE_YUV420P:
new->scale = gst_videoscale_scale_yuv; new->scale = gst_videoscale_scale_yuv;
scale_bytes = 1; new->scale_bytes = 1;
break; break;
case GST_COLORSPACE_RGB555: case GST_COLORSPACE_RGB555:
case GST_COLORSPACE_RGB565: case GST_COLORSPACE_RGB565:
case GST_COLORSPACE_BGR555: case GST_COLORSPACE_BGR555:
case GST_COLORSPACE_BGR565: case GST_COLORSPACE_BGR565:
new->scale = gst_videoscale_scale_rgb; new->scale = gst_videoscale_scale_rgb;
scale_bytes = 2; new->scale_bytes = 2;
break; break;
case GST_COLORSPACE_RGB32: case GST_COLORSPACE_RGB32:
case GST_COLORSPACE_BGR32: case GST_COLORSPACE_BGR32:
new->scale = gst_videoscale_scale_rgb; new->scale = gst_videoscale_scale_rgb;
scale_bytes = 4; new->scale_bytes = 4;
break; break;
default: default:
g_print("videoscale: unsupported video format %d\n", format); g_print("videoscale: unsupported video format %d\n", format);
@ -80,8 +87,12 @@ GstVideoScale *gst_videoscale_new(gint sw, gint sh, gint dw, gint dh, GstColorSp
GST_DEBUG (0,"videoscale: scaling method POINT_SAMPLE\n"); GST_DEBUG (0,"videoscale: scaling method POINT_SAMPLE\n");
break; break;
case GST_VIDEOSCALE_NEAREST: case GST_VIDEOSCALE_NEAREST:
generate_rowbytes(new->copy_row, sw, dw, scale_bytes); #ifdef HAVE_CPU_I386
gst_videoscale_generate_rowbytes_x86 (new->copy_row, sw, dw, new->scale_bytes);
new->scaler = gst_videoscale_scale_nearest_x86;
#else
new->scaler = gst_videoscale_scale_nearest; new->scaler = gst_videoscale_scale_nearest;
#endif
GST_DEBUG (0,"videoscale: scaling method NEAREST\n"); GST_DEBUG (0,"videoscale: scaling method NEAREST\n");
break; break;
case GST_VIDEOSCALE_BILINEAR: case GST_VIDEOSCALE_BILINEAR:
@ -103,12 +114,14 @@ GstVideoScale *gst_videoscale_new(gint sw, gint sh, gint dw, gint dh, GstColorSp
return new; return new;
} }
void gst_videoscale_destroy(GstVideoScale *scale) void
gst_videoscale_destroy (GstVideoScale *scale)
{ {
g_free(scale); g_free(scale);
} }
static void gst_videoscale_scale_rgb(GstVideoScale *scale, unsigned char *src, unsigned char *dest) static void
gst_videoscale_scale_rgb (GstVideoScale *scale, unsigned char *src, unsigned char *dest)
{ {
int sw = scale->source_width; int sw = scale->source_width;
int sh = scale->source_height; int sh = scale->source_height;
@ -116,13 +129,25 @@ static void gst_videoscale_scale_rgb(GstVideoScale *scale, unsigned char *src, u
int dh = scale->dest_height; int dh = scale->dest_height;
GST_DEBUG (0,"videoscale: scaling RGB %dx%d to %dx%d\n", sw, sh, dw, dh); GST_DEBUG (0,"videoscale: scaling RGB %dx%d to %dx%d\n", sw, sh, dw, dh);
switch (scale->scale_bytes) {
case 2:
dw = ((dw + 1) & ~1) << 1; dw = ((dw + 1) & ~1) << 1;
sw = sw<<1; sw = sw<<1;
break;
case 4:
dw = ((dw + 2) & ~3) << 2;
sw = sw<<2;
break;
default:
break;
}
GST_DEBUG (0,"videoscale: %p %p\n", src, dest); GST_DEBUG (0,"videoscale: %p %p\n", src, dest);
scale->scaler(scale, src, dest, sw, sh, dw, dh); scale->scaler(scale, src, dest, sw, sh, dw, dh);
} }
static void gst_videoscale_scale_yuv(GstVideoScale *scale, unsigned char *src, unsigned char *dest) static void
gst_videoscale_scale_yuv (GstVideoScale *scale, unsigned char *src, unsigned char *dest)
{ {
int sw = scale->source_width; int sw = scale->source_width;
int sh = scale->source_height; int sh = scale->source_height;
@ -151,7 +176,9 @@ static void gst_videoscale_scale_yuv(GstVideoScale *scale, unsigned char *src, u
#define RC(x,y) *(src+(int)(x)+(int)((y)*sw)) #define RC(x,y) *(src+(int)(x)+(int)((y)*sw))
static unsigned char gst_videoscale_bilinear(unsigned char *src, double x, double y, int sw, int sh) { static unsigned char
gst_videoscale_bilinear (unsigned char *src, double x, double y, int sw, int sh)
{
int j=floor(x); int j=floor(x);
int k=floor(y); int k=floor(y);
double a=x-j; double a=x-j;
@ -176,7 +203,9 @@ static unsigned char gst_videoscale_bilinear(unsigned char *src, double x, doubl
return (unsigned char) color; return (unsigned char) color;
} }
static unsigned char gst_videoscale_bicubic(unsigned char *src, double x, double y, int sw, int sh) { static unsigned char
gst_videoscale_bicubic (unsigned char *src, double x, double y, int sw, int sh)
{
int j=floor(x); int j=floor(x);
int k=floor(y), k2; int k=floor(y), k2;
double a=x-j; double a=x-j;
@ -210,7 +239,9 @@ static unsigned char gst_videoscale_bicubic(unsigned char *src, double x, double
return (unsigned char) color; return (unsigned char) color;
} }
static void gst_videoscale_scale_plane_slow(GstVideoScale *scale, unsigned char *src, unsigned char *dest, int sw, int sh, int dw, int dh) static void
gst_videoscale_scale_plane_slow (GstVideoScale *scale, unsigned char *src, unsigned char *dest,
int sw, int sh, int dw, int dh)
{ {
double zoomx = ((double)dw)/(double)sw; double zoomx = ((double)dw)/(double)sw;
double zoomy = ((double)dh)/(double)sh; double zoomy = ((double)dh)/(double)sh;
@ -238,66 +269,16 @@ static void gst_videoscale_scale_plane_slow(GstVideoScale *scale, unsigned char
} }
} }
#define PREFIX16 0x66 static void
#define STORE_BYTE 0xAA gst_videoscale_scale_point_sample (GstVideoScale *scale, unsigned char *src, unsigned char *dest,
#define STORE_WORD 0xAB int sw, int sh, int dw, int dh)
#define LOAD_BYTE 0xAC
#define LOAD_WORD 0xAD
#define RETURN 0xC3
static void generate_rowbytes(unsigned char *copy_row, int src_w, int dst_w, int bpp)
{
int i;
int pos, inc;
unsigned char *eip;
unsigned char load, store;
GST_DEBUG (0,"videoscale: setup scaling %p\n", copy_row);
switch (bpp) {
case 1:
load = LOAD_BYTE;
store = STORE_BYTE;
break;
case 2:
case 4:
load = LOAD_WORD;
store = STORE_WORD;
break;
default:
return;
}
pos = 0x10000;
inc = (src_w << 16) / dst_w;
eip = copy_row;
for ( i=0; i<dst_w; ++i ) {
while ( pos >= 0x10000L ) {
if ( bpp == 2 ) {
*eip++ = PREFIX16;
}
*eip++ = load;
pos -= 0x10000L;
}
if ( bpp == 2 ) {
*eip++ = PREFIX16;
}
*eip++ = store;
pos += inc;
}
*eip++ = RETURN;
GST_DEBUG (0,"scaler start/end %p %p %p\n", copy_row, eip, (void*)(eip-copy_row));
}
static void gst_videoscale_scale_point_sample(GstVideoScale *scale, unsigned char *src, unsigned char *dest, int sw, int sh, int dw, int dh)
{ {
int ypos, yinc, y; int ypos, yinc, y;
int xpos, xinc, x; int xpos, xinc, x;
int sum, xcount, ycount, loop; int sum, xcount, ycount, loop;
unsigned char *srcp, *srcp2; unsigned char *srcp, *srcp2;
GST_DEBUG (0,"videoscale: scaling nearest %p %p %d\n", src, dest, dw); GST_DEBUG (0,"videoscale: scaling nearest point sample %p %p %d\n", src, dest, dw);
ypos = 0x10000; ypos = 0x10000;
yinc = (sh<<16)/dh; yinc = (sh<<16)/dh;
@ -336,37 +317,79 @@ static void gst_videoscale_scale_point_sample(GstVideoScale *scale, unsigned cha
} }
} }
static void gst_videoscale_scale_nearest(GstVideoScale *scale, unsigned char *src, unsigned char *dest, int sw, int sh, int dw, int dh) static void
gst_videoscale_scale_nearest (GstVideoScale *scale,
unsigned char *src,
unsigned char *dest,
int sw, int sh, int dw, int dh)
{ {
int pos, inc, y; int ypos, yinc, y;
int u1, u2; int xpos, xinc, x;
scale->temp = scale->copy_row; GST_DEBUG (0, "videoscale: scaling nearest %p %p %d %d\n", src, dest, dw, scale->scale_bytes);
GST_DEBUG (0,"videoscale: scaling nearest %p %p %p %d\n", scale->copy_row, src, dest, dw);
pos = 0x10000; ypos = 0x10000;
inc = (sh<<16)/dh; yinc = (sh<<16)/dh;
xinc = (sw<<16)/dw;
for (y = dh; y > 0; y--) { for (y = dh; y; y--) {
while (pos >0x10000) { while (ypos >0x10000) {
ypos-=0x10000;
src += sw; src += sw;
pos-=0x10000;
} }
__asm__ __volatile__ (" xpos = 0x10000;
movl %2, %%eax\n
call *%%eax
"
: "=&D" (u1), "=&S" (u2)
: "g" (scale->temp), "0" (dest), "1" (src)
: "memory" );
dest+= dw; switch (scale->scale_bytes) {
case 4:
{
guint32 *destp = (guint32 *)dest;
guint32 *srcp = (guint32 *)src;
pos += inc; for ( x=dw>>2; x; x-- ) {
while ( xpos >= 0x10000L ) {
srcp++;
xpos -= 0x10000L;
}
*destp++ = *srcp;
xpos += xinc;
}
break;
}
case 2:
{
guint16 *destp = (guint16 *)dest;
guint16 *srcp = (guint16 *)src;
for ( x=dw>>1; x; x-- ) {
while ( xpos >= 0x10000L ) {
srcp++;
xpos -= 0x10000L;
}
*destp++ = *srcp;
xpos += xinc;
}
break;
}
case 1:
{
guchar *destp = dest;
guchar *srcp = src;
for ( x=dw; x; x-- ) {
while ( xpos >= 0x10000L ) {
srcp++;
xpos -= 0x10000L;
}
*destp++ = *srcp;
xpos += xinc;
}
}
}
dest += dw;
ypos += yinc;
} }
GST_DEBUG(0,"videoscale: scaling nearest done %p\n", scale->copy_row);
} }

View file

@ -41,6 +41,7 @@ struct _GstVideoScale {
guint dest_height; guint dest_height;
GstColorSpaceType format; GstColorSpaceType format;
GstVideoScaleMethod method; GstVideoScaleMethod method;
guint scale_bytes;
/* private */ /* private */
guchar copy_row[8192]; guchar copy_row[8192];
guchar *temp; guchar *temp;

View file

@ -1,88 +0,0 @@
/* 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);
static GstBuffer *gst_colorspace_rgb_to_rgb_identity(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_RGB24:
return gst_colorspace_rgb_to_rgb_identity;
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;
case GST_COLORSPACE_BGR24:
return gst_colorspace_rgb_to_rgb_identity;
default:
break;
}
break;
default:
break;
}
g_print("gst_colorspace: conversion not supported\n");
return NULL;
}
static GstBuffer *gst_colorspace_rgb_to_rgb_identity(GstBuffer *src, GstColorSpaceParameters *params) {
return src;
}
static GstBuffer *gst_colorspace_rgb24_to_bgr24(GstBuffer *src, GstColorSpaceParameters *params) {
gint size;
gchar temp;
gchar *data;
GST_DEBUG (0,"gst_colorspace_rgb24_to_bgr24 %d\n", GST_BUFFER_SIZE(src));
size = GST_BUFFER_SIZE(src)/3;
if (params != NULL && params->outbuf != NULL) {
data = params->outbuf;
GST_DEBUG (0,"gst_colorspace: to buffer %p\n", data);
}
else {
data = GST_BUFFER_DATA(src);
}
while (size--) {
temp = data[0];
data[0] = data[2];
data[2] = temp;
data+=3;
}
GST_DEBUG (0,"gst_colorspace_rgb24_to_bgr24 end %d\n", GST_BUFFER_SIZE(src));
return src;
}

File diff suppressed because it is too large Load diff

View file

@ -1,64 +0,0 @@
/*
* 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)))