2000-04-02 21:36:54 +00:00
|
|
|
/* 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>
|
|
|
|
|
2000-08-14 10:02:22 +00:00
|
|
|
static void gst_colorspace_rgb_to_rgb_identity(GstColorSpaceConverter *space, unsigned char *src, unsigned char *dest);
|
|
|
|
static void gst_colorspace_rgb24_to_bgr24(GstColorSpaceConverter *space, unsigned char *src, unsigned char *dest);
|
|
|
|
static void gst_colorspace_rgb32_to_bgr32(GstColorSpaceConverter *space, unsigned char *src, unsigned char *dest);
|
|
|
|
static void gst_colorspace_rgb555_to_rgb565(GstColorSpaceConverter *space, unsigned char *src, unsigned char *dest);
|
2000-04-02 21:36:54 +00:00
|
|
|
|
2000-08-14 10:02:22 +00:00
|
|
|
GstColorSpaceConvertFunction gst_colorspace_rgb2rgb_get_converter(GstColorSpaceConverter *space, GstColorSpaceType src, GstColorSpaceType dest) {
|
2000-04-02 21:36:54 +00:00
|
|
|
switch(src) {
|
|
|
|
case GST_COLORSPACE_RGB24:
|
2000-06-12 21:27:19 +00:00
|
|
|
space->insize = space->width*space->height*3;
|
2000-04-02 21:36:54 +00:00
|
|
|
switch(dest) {
|
2000-04-09 21:36:56 +00:00
|
|
|
case GST_COLORSPACE_RGB24:
|
2000-06-12 21:27:19 +00:00
|
|
|
space->outsize = space->width*space->height*3;
|
2000-04-09 21:36:56 +00:00
|
|
|
return gst_colorspace_rgb_to_rgb_identity;
|
2000-04-02 21:36:54 +00:00
|
|
|
case GST_COLORSPACE_BGR24:
|
2000-06-12 21:27:19 +00:00
|
|
|
space->outsize = space->width*space->height*3;
|
2000-04-02 21:36:54 +00:00
|
|
|
return gst_colorspace_rgb24_to_bgr24;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_COLORSPACE_BGR24:
|
2000-06-12 21:27:19 +00:00
|
|
|
space->insize = space->width*space->height*3;
|
2000-04-02 21:36:54 +00:00
|
|
|
switch(dest) {
|
|
|
|
case GST_COLORSPACE_RGB24:
|
2000-06-12 21:27:19 +00:00
|
|
|
space->outsize = space->width*space->height*3;
|
2000-04-02 21:36:54 +00:00
|
|
|
return gst_colorspace_rgb24_to_bgr24;
|
2000-04-09 21:36:56 +00:00
|
|
|
case GST_COLORSPACE_BGR24:
|
2000-06-12 21:27:19 +00:00
|
|
|
space->outsize = space->width*space->height*3;
|
2000-04-09 21:36:56 +00:00
|
|
|
return gst_colorspace_rgb_to_rgb_identity;
|
2000-04-02 21:36:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2000-08-14 10:02:22 +00:00
|
|
|
case GST_COLORSPACE_RGB32:
|
|
|
|
space->insize = space->width*space->height*4;
|
|
|
|
switch(dest) {
|
|
|
|
case GST_COLORSPACE_BGR32:
|
|
|
|
space->outsize = space->width*space->height*4;
|
|
|
|
return gst_colorspace_rgb32_to_bgr32;
|
|
|
|
case GST_COLORSPACE_RGB32:
|
|
|
|
space->outsize = space->width*space->height*4;
|
|
|
|
return gst_colorspace_rgb_to_rgb_identity;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_COLORSPACE_BGR32:
|
|
|
|
space->insize = space->width*space->height*4;
|
|
|
|
switch(dest) {
|
|
|
|
case GST_COLORSPACE_RGB32:
|
|
|
|
space->outsize = space->width*space->height*4;
|
|
|
|
return gst_colorspace_rgb32_to_bgr32;
|
|
|
|
case GST_COLORSPACE_BGR32:
|
|
|
|
space->outsize = space->width*space->height*4;
|
|
|
|
return gst_colorspace_rgb_to_rgb_identity;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_COLORSPACE_BGR555:
|
|
|
|
space->insize = space->width*space->height*2;
|
|
|
|
switch(dest) {
|
|
|
|
case GST_COLORSPACE_RGB555:
|
|
|
|
space->outsize = space->width*space->height*2;
|
|
|
|
return gst_colorspace_rgb32_to_bgr32;
|
|
|
|
case GST_COLORSPACE_BGR565:
|
|
|
|
space->outsize = space->width*space->height*2;
|
|
|
|
return gst_colorspace_rgb555_to_rgb565;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-04-02 21:36:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-08-14 10:02:22 +00:00
|
|
|
g_print("gst_colorspace: conversion not supported %d %d\n", src, dest);
|
2000-04-02 21:36:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-08-14 10:02:22 +00:00
|
|
|
static void gst_colorspace_rgb_to_rgb_identity(GstColorSpaceConverter *space, unsigned char *src, unsigned char *dest)
|
2000-06-12 21:27:19 +00:00
|
|
|
{
|
|
|
|
memcpy(dest, src, space->outsize);
|
2000-04-09 21:36:56 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 10:02:22 +00:00
|
|
|
static void gst_colorspace_rgb24_to_bgr24(GstColorSpaceConverter *space, unsigned char *src, unsigned char *dest)
|
2000-06-12 21:27:19 +00:00
|
|
|
{
|
2000-04-02 21:36:54 +00:00
|
|
|
gint size;
|
|
|
|
gchar temp;
|
|
|
|
|
2000-08-14 10:02:22 +00:00
|
|
|
DEBUG("gst_colorspace_rgb24_to_bgr24 %p %p %d\n", src, dest, space->outsize);
|
2000-04-02 21:36:54 +00:00
|
|
|
|
2000-06-18 13:50:18 +00:00
|
|
|
size = space->outsize/3;
|
2000-04-02 21:36:54 +00:00
|
|
|
|
2000-06-12 21:27:19 +00:00
|
|
|
if (src == dest) {
|
|
|
|
while (size--) {
|
|
|
|
temp = src[0];
|
|
|
|
src[0] = src[2];
|
|
|
|
src[2] = temp;
|
|
|
|
src+=3;
|
|
|
|
}
|
2000-04-09 21:36:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2000-06-12 21:27:19 +00:00
|
|
|
while (size--) {
|
|
|
|
*dest++ = src[2];
|
|
|
|
*dest++ = src[1];
|
|
|
|
*dest++ = src[0];
|
|
|
|
src+=3;
|
|
|
|
}
|
2000-04-09 21:36:56 +00:00
|
|
|
}
|
2000-06-12 21:27:19 +00:00
|
|
|
DEBUG("gst_colorspace_rgb24_to_bgr24 end\n");
|
2000-04-02 21:36:54 +00:00
|
|
|
}
|
|
|
|
|
2000-08-14 10:02:22 +00:00
|
|
|
static void gst_colorspace_rgb32_to_bgr32(GstColorSpaceConverter *space, unsigned char *src, unsigned char *dest)
|
|
|
|
{
|
|
|
|
gint size;
|
|
|
|
gchar temp;
|
|
|
|
|
|
|
|
DEBUG("gst_colorspace_rgb32_to_bgr32 %p %p %d\n", src, dest, space->outsize);
|
|
|
|
|
|
|
|
size = space->outsize/4;
|
|
|
|
|
|
|
|
if (src == dest) {
|
|
|
|
while (size--) {
|
|
|
|
temp = src[0];
|
|
|
|
src[0] = src[2];
|
|
|
|
src[2] = temp;
|
|
|
|
src+=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (size--) {
|
|
|
|
*dest++ = src[2];
|
|
|
|
*dest++ = src[1];
|
|
|
|
*dest++ = src[0];
|
|
|
|
dest++;
|
|
|
|
src+=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEBUG("gst_colorspace_rgb32_to_bgr32 end\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gst_colorspace_rgb555_to_rgb565(GstColorSpaceConverter *space, unsigned char *src, unsigned char *dest)
|
|
|
|
{
|
|
|
|
gint size;
|
|
|
|
guint32 *srcptr = (guint32 *) src;
|
|
|
|
guint32 *destptr = (guint32 *) dest;
|
|
|
|
|
|
|
|
DEBUG("gst_colorspace_rgb555_to_rgb565 %p %p %d\n", src, dest, space->outsize);
|
|
|
|
|
|
|
|
size = space->outsize/4;
|
|
|
|
|
|
|
|
if (src == dest) {
|
|
|
|
while (size--) {
|
|
|
|
*srcptr += (*srcptr++)&0xFFE0FFE0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (size--) {
|
|
|
|
*destptr++ = *srcptr + ((*srcptr++)&0xFFE0FFE0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|