libvips/libvips/colour/LabQ2Lab.c

168 lines
4.0 KiB
C
Raw Normal View History

2013-07-11 15:37:53 +02:00
/* LabQ2Lab
2009-11-02 18:54:42 +01:00
*
* Copyright Kirk Martinez 2/5/1993
*
* Modified: 16/6/93
2009-08-16 17:00:08 +02:00
* 7/6/93 JC
* - adapted for partial v2
* 16/11/94 JC
* - adapted to new im_wrap_oneonebuf() function.
* 9/2/95 JC
* - new im_wrapone function
* 22/5/95 JC
* - changed char to unsigned char for RS/6000
* - small tidies and speed-ups
* 4/9/97 JC
* - L* = 100.0 now handled correctly
2009-11-02 18:54:42 +01:00
* 2/11/09
* - gtkdoc
2012-09-20 22:21:08 +02:00
* 20/9/12
* - redo as a class
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 <vips/internal.h>
2009-08-16 17:00:08 +02:00
#include "pcolour.h"
2012-09-20 22:21:08 +02:00
typedef VipsColourCode VipsLabQ2Lab;
typedef VipsColourCodeClass VipsLabQ2LabClass;
G_DEFINE_TYPE( VipsLabQ2Lab, vips_LabQ2Lab, VIPS_TYPE_COLOUR_CODE );
2009-08-16 17:00:08 +02:00
/* imb_LabQ2Lab: CONVERT n pels from packed 32bit Lab to float values
* in a buffer
2011-12-31 19:22:42 +01:00
* ARGS: VipsPel *inp pointer to first byte of Lab32 buffer
2009-08-16 17:00:08 +02:00
* float *outbuf destination buffer
* int n number of pels to process
* (C) K.Martinez 2/5/93
*/
2012-09-20 22:21:08 +02:00
static void
vips_LabQ2Lab_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
2009-08-16 17:00:08 +02:00
{
2013-12-03 15:25:22 +01:00
signed char * restrict p = (signed char *) in[0];
float * restrict q = (float *) out;
2012-09-20 22:21:08 +02:00
2009-08-16 17:00:08 +02:00
int l;
int lsbs; /* for lsbs byte */
2012-09-20 22:21:08 +02:00
int i; /* counter */
2009-08-16 17:00:08 +02:00
/* Read input with a signed pointer to get signed ab easily.
*/
2012-09-20 22:21:08 +02:00
for( i = 0; i < width; i++ ) {
2009-08-16 17:00:08 +02:00
/* Get extra bits.
*/
2012-09-20 22:21:08 +02:00
lsbs = ((unsigned char *) p)[3];
2009-08-16 17:00:08 +02:00
/* Build L.
*/
2012-09-20 22:21:08 +02:00
l = ((unsigned char *)p)[0];
2009-08-16 17:00:08 +02:00
l = (l << 2) | (lsbs >> 6);
2012-09-20 22:21:08 +02:00
q[0] = (float) l * (100.0 / 1023.0);
2009-08-16 17:00:08 +02:00
/* Build a.
*/
l = VIPS_LSHIFT_INT( p[1], 3) | ((lsbs >> 3) & 0x7);
2012-09-20 22:21:08 +02:00
q[1] = (float) l * 0.125;
2009-08-16 17:00:08 +02:00
/* And b.
*/
l = VIPS_LSHIFT_INT( p[2], 3) | (lsbs & 0x7);
2012-09-20 22:21:08 +02:00
q[2] = (float) l * 0.125;
2009-08-16 17:00:08 +02:00
2012-09-20 22:21:08 +02:00
p += 4;
q += 3;
2009-08-16 17:00:08 +02:00
}
}
2012-09-20 22:21:08 +02:00
void
vips__LabQ2Lab_vec( float *out, VipsPel *in, int width )
{
vips_LabQ2Lab_line( NULL, (VipsPel *) out, &in, width );
}
static void
vips_LabQ2Lab_class_init( VipsLabQ2LabClass *class )
{
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class );
object_class->nickname = "LabQ2Lab";
object_class->description = _( "unpack a LabQ image to float Lab" );
colour_class->process_line = vips_LabQ2Lab_line;
}
static void
vips_LabQ2Lab_init( VipsLabQ2Lab *LabQ2Lab )
{
2012-09-26 15:53:14 +02:00
VipsColour *colour = VIPS_COLOUR( LabQ2Lab );
VipsColourCode *code = VIPS_COLOUR_CODE( LabQ2Lab );
colour->coding = VIPS_CODING_NONE;
colour->interpretation = VIPS_INTERPRETATION_LAB;
colour->format = VIPS_FORMAT_FLOAT;
colour->bands = 3;
code->input_coding = VIPS_CODING_LABQ;
2012-09-20 22:21:08 +02:00
}
2009-11-02 18:54:42 +01:00
/**
* vips_LabQ2Lab: (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
*
2014-11-17 11:32:40 +01:00
* Unpack a LabQ (#VIPS_CODING_LABQ) image to a three-band float image.
2009-11-02 18:54:42 +01:00
*
2013-07-11 15:37:53 +02:00
* See also: vips_LabQ2Lab(), vips_LabQ2LabS(), vips_rad2float().
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:21:08 +02:00
vips_LabQ2Lab( VipsImage *in, VipsImage **out, ... )
2009-08-16 17:00:08 +02:00
{
2012-09-20 22:21:08 +02:00
va_list ap;
int result;
2009-08-16 17:00:08 +02:00
2012-09-20 22:21:08 +02:00
va_start( ap, out );
result = vips_call_split( "LabQ2Lab", ap, in, out );
va_end( ap );
2009-08-16 17:00:08 +02:00
2012-09-20 22:21:08 +02:00
return( result );
2009-08-16 17:00:08 +02:00
}