LabS <-> Lab as classes

This commit is contained in:
John Cupitt 2012-09-20 21:53:47 +01:00
parent 2e1b8bb9ef
commit 969e355701
8 changed files with 155 additions and 54 deletions

View File

@ -1,7 +1,7 @@
31/8/12 started 7.31.0
- redone im_Lab2XYZ(), im_XYZ2Lab(), im_Lab2LCh(), im_LCh2Lab(), im_UCS2LCh,
im_LCh2UCS(), im_XYZ2Yxy(), im_Yxy2XYZ(), im_float2rad(), im_rad2float()
as classes
im_LCh2UCS(), im_XYZ2Yxy(), im_Yxy2XYZ(), im_float2rad(), im_rad2float(),
im_Lab2LabQ(), im_LabQ2Lab(), im_Lab2LabS(), im_LabS2Lab() as classes
13/9/12 started 7.30.3
- linecache sized itself too large

View File

@ -1,10 +1,12 @@
/* im_Lab2LabS: quantise FLOAT Lab image into signed short format
*
* 12/12/02 JC
* - from im_Lab2LabQ
* - from im_Lab2LabS
* 1/11/09
* - gtkdoc
* - cleanups
* 20/9/12
* - redo as a class
*/
/*
@ -43,14 +45,21 @@
#include <vips/vips.h>
void
imb_Lab2LabS( float *in, signed short *out, int n )
{
float *p = in;
signed short *q = out;
int c;
#include "colour.h"
for( c = 0; c < n; c++ ) {
typedef VipsColourCode VipsLab2LabS;
typedef VipsColourCodeClass VipsLab2LabSClass;
G_DEFINE_TYPE( VipsLab2LabS, vips_Lab2LabS, VIPS_TYPE_COLOUR_CODE );
static void
vips_Lab2LabS_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
{
float *p = (float *) in[0];
signed short *q = (signed short *) out;
int i;
for( i = 0; i < width; i++ ) {
q[0] = p[0] * (32767.0 / 100.0);
q[1] = p[1] * (32768.0 / 128.0);
q[2] = p[2] * (32768.0 / 128.0);
@ -60,34 +69,52 @@ imb_Lab2LabS( float *in, signed short *out, int n )
}
}
static void
vips_Lab2LabS_class_init( VipsLab2LabSClass *class )
{
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class );
VipsColourCodeClass *code_class = VIPS_COLOUR_CODE_CLASS( class );
object_class->nickname = "Lab2LabS";
object_class->description = _( "transform float Lab to signed short" );
colour_class->process_line = vips_Lab2LabS_line;
colour_class->interpretation = VIPS_INTERPRETATION_LABS;
colour_class->format = VIPS_FORMAT_SHORT;
colour_class->bands = 3;
code_class->input_coding = VIPS_CODING_NONE;
code_class->input_format = VIPS_FORMAT_FLOAT;
code_class->input_bands = 3;
}
static void
vips_Lab2LabS_init( VipsLab2LabS *Lab2LabS )
{
}
/**
* im_Lab2LabS:
* vips_Lab2LabS:
* @in: input image
* @out: output image
*
* Turn Lab to LabS, signed 16-bit int fixed point.
*
* See also: im_LabQ2Lab().
*
* Returns: 0 on success, -1 on error.
*/
int
im_Lab2LabS( IMAGE *in, IMAGE *out )
vips_Lab2LabS( VipsImage *in, VipsImage **out, ... )
{
IMAGE *t[1];
va_list ap;
int result;
if( im_check_uncoded( "im_Lab2LabS", in ) ||
im_check_bands( "im_Lab2LabS", in, 3 ) ||
im_open_local_array( out, t, 1, "im_Lab2LabS", "p" ) ||
im_clip2fmt( in, t[0], IM_BANDFMT_FLOAT ) )
return( -1 );
va_start( ap, out );
result = vips_call_split( "Lab2LabS", ap, in, out );
va_end( ap );
if( im_cp_desc( out, t[0] ) )
return( -1 );
out->Type = IM_TYPE_LABS;
out->BandFmt = IM_BANDFMT_SHORT;
if( im_wrapone( t[0], out,
(im_wrapone_fn) imb_Lab2LabS, NULL, NULL ) )
return( -1 );
return( 0 );
return( result );
}

View File

@ -41,16 +41,23 @@
#include <vips/vips.h>
#include "colour.h"
typedef VipsColourCode VipsLabS2Lab;
typedef VipsColourCodeClass VipsLabS2LabClass;
G_DEFINE_TYPE( VipsLabS2Lab, vips_LabS2Lab, VIPS_TYPE_COLOUR_CODE );
/* Convert n pels from signed short to Lab.
*/
void
imb_LabS2Lab( signed short *in, float *out, int n )
static void
vips_LabS2Lab_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
{
signed short *p = in;
float *q = out;
int c;
signed short *p = (signed short *) in[0];
float *q = (float *) out;
int i;
for( c = 0; c < n; c++ ) {
for( i = 0; i < width; i++ ) {
q[0] = p[0] / (32767.0 / 100.0);
q[1] = p[1] / (32768.0 / 128.0);
q[2] = p[2] / (32768.0 / 128.0);
@ -60,33 +67,52 @@ imb_LabS2Lab( signed short *in, float *out, int n )
}
}
static void
vips_LabS2Lab_class_init( VipsLabS2LabClass *class )
{
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class );
VipsColourCodeClass *code_class = VIPS_COLOUR_CODE_CLASS( class );
object_class->nickname = "LabS2Lab";
object_class->description = _( "transform signed short Lab to float" );
colour_class->process_line = vips_LabS2Lab_line;
colour_class->interpretation = VIPS_INTERPRETATION_LAB;
colour_class->format = VIPS_FORMAT_FLOAT;
colour_class->bands = 3;
code_class->input_coding = VIPS_CODING_NONE;
code_class->input_format = VIPS_FORMAT_SHORT;
code_class->input_bands = 3;
}
static void
vips_LabS2Lab_init( VipsLabS2Lab *LabS2Lab )
{
}
/**
* im_LabS2Lab:
* vips_LabS2Lab:
* @in: input image
* @out: output image
*
* Convert a LabS three-band signed short image to a three-band float image.
*
* See also: im_Lab2LabS().
* See also: vips_LabS2Lab().
*
* Returns: 0 on success, -1 on error.
*/
int
im_LabS2Lab( IMAGE *in, IMAGE *out )
vips_LabS2Lab( VipsImage *in, VipsImage **out, ... )
{
if( im_check_uncoded( "im_LabS2Lab", in ) ||
im_check_bands( "im_LabS2Lab", in, 3 ) ||
im_check_format( "im_LabS2Lab", in, IM_BANDFMT_SHORT ) )
return( -1 );
va_list ap;
int result;
if( im_cp_desc( out, in ) )
return( -1 );
out->Type = IM_TYPE_LAB;
out->BandFmt = IM_BANDFMT_FLOAT;
va_start( ap, out );
result = vips_call_split( "LabS2Lab", ap, in, out );
va_end( ap );
if( im_wrapone( in, out,
(im_wrapone_fn) imb_LabS2Lab, NULL, NULL ) )
return( -1 );
return( 0 );
return( result );
}

View File

@ -18,12 +18,12 @@ libcolour_la_SOURCES = \
rad2float.c \
Lab2LabQ.c \
LabQ2Lab.c \
LabS2Lab.c \
Lab2LabS.c \
im_icc_transform.c \
im_Lab2LabS.c \
im_LabQ2LabS.c \
im_LabQ2disp.c \
im_LabS2LabQ.c \
im_LabS2Lab.c \
im_lab_morph.c \
im_XYZ2disp.c \
im_dE00_fromLab.c \

View File

@ -381,6 +381,12 @@ vips_colour_operation_init( void )
extern GType vips_UCS2LCh_get_type( void );
extern GType vips_Yxy2XYZ_get_type( void );
extern GType vips_XYZ2Yxy_get_type( void );
extern GType vips_LabQ2Lab_get_type( void );
extern GType vips_Lab2LabQ_get_type( void );
extern GType vips_LabS2Lab_get_type( void );
extern GType vips_Lab2LabS_get_type( void );
extern GType vips_rad2float_get_type( void );
extern GType vips_float2rad_get_type( void );
vips_Lab2XYZ_get_type();
vips_XYZ2Lab_get_type();
@ -390,4 +396,10 @@ vips_colour_operation_init( void )
vips_UCS2LCh_get_type();
vips_XYZ2Yxy_get_type();
vips_Yxy2XYZ_get_type();
vips_LabQ2Lab_get_type();
vips_Lab2LabQ_get_type();
vips_LabS2Lab_get_type();
vips_Lab2LabS_get_type();
vips_rad2float_get_type();
vips_float2rad_get_type();
}

View File

@ -2387,3 +2387,35 @@ im_LabQ2Lab( IMAGE *in, IMAGE *out )
return( 0 );
}
int
im_Lab2LabS( IMAGE *in, IMAGE *out )
{
VipsImage *x;
if( vips_Lab2LabS( in, &x, NULL ) )
return( -1 );
if( im_copy( x, out ) ) {
g_object_unref( x );
return( -1 );
}
g_object_unref( x );
return( 0 );
}
int
im_LabS2Lab( IMAGE *in, IMAGE *out )
{
VipsImage *x;
if( vips_LabS2Lab( in, &x, NULL ) )
return( -1 );
if( im_copy( x, out ) ) {
g_object_unref( x );
return( -1 );
}
g_object_unref( x );
return( 0 );
}

View File

@ -130,6 +130,10 @@ int vips_XYZ2Yxy( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
int vips_Yxy2XYZ( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
int vips_LabS2Lab( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
int vips_Lab2LabS( VipsImage *in, VipsImage **out, ... )
__attribute__((sentinel));
void vips_col_Lab2XYZ( float L, float a, float b,
float *X, float *Y, float *Z );
@ -164,10 +168,8 @@ float im_col_dE00(
float L1, float a1, float b1, float L2, float a2, float b2 );
int im_LabQ2XYZ( VipsImage *in, VipsImage *out );
int im_Lab2LabS( VipsImage *in, VipsImage *out );
int im_LabQ2LabS( VipsImage *in, VipsImage *out );
int im_LabS2LabQ( VipsImage *in, VipsImage *out );
int im_LabS2Lab( VipsImage *in, VipsImage *out );
int im_UCS2XYZ( VipsImage *in, VipsImage *out );
int im_UCS2Lab( VipsImage *in, VipsImage *out );
int im_Lab2UCS( VipsImage *in, VipsImage *out );

View File

@ -726,6 +726,8 @@ int im_float2rad( VipsImage *in, VipsImage *out );
int im_rad2float( VipsImage *in, VipsImage *out );
int im_Lab2LabQ( VipsImage *in, VipsImage *out );
int im_LabQ2Lab( VipsImage *in, VipsImage *out );
int im_Lab2LabS( VipsImage *in, VipsImage *out );
int im_LabS2Lab( VipsImage *in, VipsImage *out );
/* ruby-vips uses this
*/