libvips/libvips/colour/LabS2Lab.c

123 lines
2.8 KiB
C
Raw Permalink Normal View History

2013-07-11 15:37:53 +02:00
/* LabS2Lab()
2009-08-16 17:00:08 +02:00
*
* 12/12/02 JC
* - adapted from im_LabS2LabQ()
2009-11-02 18:54:42 +01:00
* 2/11/09
* - gtkdoc, cleanup
2009-08-16 17:00:08 +02:00
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
2009-08-16 17:00:08 +02:00
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <glib/gi18n-lib.h>
2009-08-16 17:00:08 +02:00
#include <stdio.h>
#include <vips/vips.h>
#include "pcolour.h"
2012-09-20 22:53:47 +02:00
typedef VipsColourCode VipsLabS2Lab;
typedef VipsColourCodeClass VipsLabS2LabClass;
G_DEFINE_TYPE( VipsLabS2Lab, vips_LabS2Lab, VIPS_TYPE_COLOUR_CODE );
2009-08-16 17:00:08 +02:00
/* Convert n pels from signed short to Lab.
*/
2012-09-20 22:53:47 +02:00
static void
vips_LabS2Lab_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
2009-08-16 17:00:08 +02:00
{
2012-09-20 22:53:47 +02:00
signed short *p = (signed short *) in[0];
float *q = (float *) out;
int i;
2009-08-16 17:00:08 +02:00
2012-09-20 22:53:47 +02:00
for( i = 0; i < width; i++ ) {
2009-08-16 17:00:08 +02:00
q[0] = p[0] / (32767.0 / 100.0);
q[1] = p[1] / (32768.0 / 128.0);
q[2] = p[2] / (32768.0 / 128.0);
p += 3;
q += 3;
}
}
2012-09-20 22:53:47 +02:00
static void
vips_LabS2Lab_class_init( VipsLabS2LabClass *class )
{
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class );
object_class->nickname = "LabS2Lab";
object_class->description = _( "transform signed short Lab to float" );
colour_class->process_line = vips_LabS2Lab_line;
}
static void
vips_LabS2Lab_init( VipsLabS2Lab *LabS2Lab )
{
2012-09-26 15:53:14 +02:00
VipsColour *colour = VIPS_COLOUR( LabS2Lab );
VipsColourCode *code = VIPS_COLOUR_CODE( LabS2Lab );
colour->interpretation = VIPS_INTERPRETATION_LAB;
colour->format = VIPS_FORMAT_FLOAT;
colour->input_bands = 3;
2012-09-26 15:53:14 +02:00
colour->bands = 3;
code->input_coding = VIPS_CODING_NONE;
code->input_format = VIPS_FORMAT_SHORT;
2012-09-20 22:53:47 +02:00
}
2009-11-02 18:54:42 +01:00
/**
* vips_LabS2Lab: (method)
2009-11-02 18:54:42 +01:00
* @in: input image
* @out: (out): output image
* @...: %NULL-terminated list of optional named arguments
2009-11-02 18:54:42 +01:00
*
* Convert a LabS three-band signed short image to a three-band float image.
*
2012-09-20 22:53:47 +02:00
* See also: vips_LabS2Lab().
2009-11-02 18:54:42 +01:00
*
* Returns: 0 on success, -1 on error.
*/
2009-08-16 17:00:08 +02:00
int
2012-09-20 22:53:47 +02:00
vips_LabS2Lab( VipsImage *in, VipsImage **out, ... )
2009-08-16 17:00:08 +02:00
{
2012-09-20 22:53:47 +02:00
va_list ap;
int result;
2009-08-16 17:00:08 +02:00
2012-09-20 22:53:47 +02:00
va_start( ap, out );
result = vips_call_split( "LabS2Lab", ap, in, out );
va_end( ap );
2009-08-16 17:00:08 +02:00
2012-09-20 22:53:47 +02:00
return( result );
2009-08-16 17:00:08 +02:00
}
2012-09-20 22:53:47 +02:00