|
Packit |
1f69a5 |
/* GStreamer
|
|
Packit |
1f69a5 |
* Copyright (C) <1999> Erik Walthinsen <omega@temple-baptist.com>
|
|
Packit |
1f69a5 |
*
|
|
Packit |
1f69a5 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
1f69a5 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
1f69a5 |
* License as published by the Free Software Foundation; either
|
|
Packit |
1f69a5 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
1f69a5 |
*
|
|
Packit |
1f69a5 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
1f69a5 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
1f69a5 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
1f69a5 |
* Library General Public License for more details.
|
|
Packit |
1f69a5 |
*
|
|
Packit |
1f69a5 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
1f69a5 |
* License along with this library; if not, write to the
|
|
Packit |
1f69a5 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
1f69a5 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
1f69a5 |
*/
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
1f69a5 |
#include "config.h"
|
|
Packit |
1f69a5 |
#endif
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
#include <string.h>
|
|
Packit |
1f69a5 |
#include <gst/gst.h>
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
#include "flx_color.h"
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
FlxColorSpaceConverter *
|
|
Packit |
1f69a5 |
flx_colorspace_converter_new (gint width, gint height)
|
|
Packit |
1f69a5 |
{
|
|
Packit |
1f69a5 |
FlxColorSpaceConverter *new = g_malloc (sizeof (FlxColorSpaceConverter));
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
new->width = width;
|
|
Packit |
1f69a5 |
new->height = height;
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
memset (new->palvec, 0, sizeof (new->palvec));
|
|
Packit |
1f69a5 |
return new;
|
|
Packit |
1f69a5 |
}
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
void
|
|
Packit |
1f69a5 |
flx_colorspace_converter_destroy (FlxColorSpaceConverter * flxpal)
|
|
Packit |
1f69a5 |
{
|
|
Packit |
1f69a5 |
g_return_if_fail (flxpal != NULL);
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
g_free (flxpal);
|
|
Packit |
1f69a5 |
}
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
void
|
|
Packit |
1f69a5 |
flx_colorspace_convert (FlxColorSpaceConverter * flxpal, guchar * src,
|
|
Packit |
1f69a5 |
guchar * dest)
|
|
Packit |
1f69a5 |
{
|
|
Packit |
1f69a5 |
guint size, col;
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
g_return_if_fail (flxpal != NULL);
|
|
Packit |
1f69a5 |
g_return_if_fail (src != dest);
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
size = flxpal->width * flxpal->height;
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
while (size--) {
|
|
Packit |
1f69a5 |
col = (*src++ * 3);
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
Packit |
1f69a5 |
*dest++ = 0;
|
|
Packit |
1f69a5 |
*dest++ = flxpal->palvec[col];
|
|
Packit |
1f69a5 |
*dest++ = flxpal->palvec[col + 1];
|
|
Packit |
1f69a5 |
*dest++ = flxpal->palvec[col + 2];
|
|
Packit |
1f69a5 |
#else
|
|
Packit |
1f69a5 |
*dest++ = flxpal->palvec[col + 2];
|
|
Packit |
1f69a5 |
*dest++ = flxpal->palvec[col + 1];
|
|
Packit |
1f69a5 |
*dest++ = flxpal->palvec[col];
|
|
Packit |
1f69a5 |
*dest++ = 0;
|
|
Packit |
1f69a5 |
#endif
|
|
Packit |
1f69a5 |
}
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
}
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
void
|
|
Packit |
1f69a5 |
flx_set_palette_vector (FlxColorSpaceConverter * flxpal, guint start, guint num,
|
|
Packit |
1f69a5 |
guchar * newpal, gint scale)
|
|
Packit |
1f69a5 |
{
|
|
Packit |
1f69a5 |
guint grab;
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
g_return_if_fail (flxpal != NULL);
|
|
Packit |
1f69a5 |
g_return_if_fail (start < 0x100);
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
grab = ((start + num) > 0x100 ? 0x100 - start : num);
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
if (scale) {
|
|
Packit |
1f69a5 |
gint i = 0;
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
start *= 3;
|
|
Packit |
1f69a5 |
while (grab) {
|
|
Packit |
1f69a5 |
flxpal->palvec[start++] = newpal[i++] << scale;
|
|
Packit |
1f69a5 |
flxpal->palvec[start++] = newpal[i++] << scale;
|
|
Packit |
1f69a5 |
flxpal->palvec[start++] = newpal[i++] << scale;
|
|
Packit |
1f69a5 |
grab--;
|
|
Packit |
1f69a5 |
}
|
|
Packit |
1f69a5 |
} else {
|
|
Packit |
1f69a5 |
memcpy (&flxpal->palvec[start * 3], newpal, grab * 3);
|
|
Packit |
1f69a5 |
}
|
|
Packit |
1f69a5 |
}
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
void
|
|
Packit |
1f69a5 |
flx_set_color (FlxColorSpaceConverter * flxpal, guint colr, guint red,
|
|
Packit |
1f69a5 |
guint green, guint blue, gint scale)
|
|
Packit |
1f69a5 |
{
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
g_return_if_fail (flxpal != NULL);
|
|
Packit |
1f69a5 |
g_return_if_fail (colr < 0x100);
|
|
Packit |
1f69a5 |
|
|
Packit |
1f69a5 |
flxpal->palvec[(colr * 3)] = red << scale;
|
|
Packit |
1f69a5 |
flxpal->palvec[(colr * 3) + 1] = green << scale;
|
|
Packit |
1f69a5 |
flxpal->palvec[(colr * 3) + 2] = blue << scale;
|
|
Packit |
1f69a5 |
}
|