redo LabQ2LabS / LabS2LabQ as classes
This commit is contained in:
parent
969e355701
commit
5fff90bc95
@ -1,7 +1,8 @@
|
||||
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(),
|
||||
im_Lab2LabQ(), im_LabQ2Lab(), im_Lab2LabS(), im_LabS2Lab() as classes
|
||||
im_Lab2LabQ(), im_LabQ2Lab(), im_Lab2LabS(), im_LabS2Lab(), im_LabQ2LabS(),
|
||||
im_LabS2LabQ() as classes
|
||||
|
||||
13/9/12 started 7.30.3
|
||||
- linecache sized itself too large
|
||||
|
@ -1,13 +1,15 @@
|
||||
/* im_LabQ2LabS
|
||||
*
|
||||
* 17/11/93 JC
|
||||
* - adapted from im_LabQ2Lab()
|
||||
* - adapted from im_LabQ2LabS()
|
||||
* 16/11/94 JC
|
||||
* - uses new im_wrap_oneonebuf() fn
|
||||
* 9/2/95 JC
|
||||
* - new im_wrapone function
|
||||
* 2/11/09
|
||||
* - gtkdoc
|
||||
* 21/9/12
|
||||
* - redo as a class
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -45,18 +47,26 @@
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
#include "colour.h"
|
||||
|
||||
typedef VipsColourCode VipsLabQ2LabS;
|
||||
typedef VipsColourCodeClass VipsLabQ2LabSClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsLabQ2LabS, vips_LabQ2LabS, VIPS_TYPE_COLOUR_CODE );
|
||||
|
||||
/* CONVERT n pels from packed 32bit Lab to signed short.
|
||||
*/
|
||||
void
|
||||
imb_LabQ2LabS( unsigned char *in, signed short *out, int n )
|
||||
static void
|
||||
vips_LabQ2LabS_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
|
||||
{
|
||||
int c;
|
||||
unsigned char *p = in;
|
||||
unsigned char *p = (unsigned char *) in[0];
|
||||
signed short *q = (signed short *) out;
|
||||
|
||||
int i;
|
||||
unsigned char ext;
|
||||
signed short *q = out;
|
||||
signed short l, a, b;
|
||||
|
||||
for( c = 0; c < n; c++ ) {
|
||||
for( i = 0; i < width; i++ ) {
|
||||
/* Get most significant 8 bits of lab.
|
||||
*/
|
||||
l = p[0] << 7;
|
||||
@ -83,37 +93,50 @@ imb_LabQ2LabS( unsigned char *in, signed short *out, int n )
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vips_LabQ2LabS_class_init( VipsLabQ2LabSClass *class )
|
||||
{
|
||||
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||
VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class );
|
||||
VipsColourCodeClass *code_class = VIPS_COLOUR_CODE_CLASS( class );
|
||||
|
||||
object_class->nickname = "LabQ2LabS";
|
||||
object_class->description = _( "unpack a LabQ image to short Lab" );
|
||||
|
||||
colour_class->process_line = vips_LabQ2LabS_line;
|
||||
colour_class->coding = VIPS_CODING_NONE;
|
||||
colour_class->interpretation = VIPS_INTERPRETATION_LABS;
|
||||
colour_class->format = VIPS_FORMAT_SHORT;
|
||||
colour_class->bands = 3;
|
||||
|
||||
code_class->input_coding = VIPS_CODING_LABQ;
|
||||
}
|
||||
|
||||
static void
|
||||
vips_LabQ2LabS_init( VipsLabQ2LabS *LabQ2LabS )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* im_LabQ2LabS:
|
||||
* vips_LabQ2LabS:
|
||||
* @in: input image
|
||||
* @out: output image
|
||||
*
|
||||
* Unpack a LabQ (#IM_CODING_LABQ) image to a three-band signed short image.
|
||||
* Unpack a LabQ (#IM_CODING_LABQ) image to a three-band short image.
|
||||
*
|
||||
* See also: im_LabS2LabQ(), im_LabQ2Lab(), im_rad2float().
|
||||
* See also: im_LabS2LabQ(), im_LabQ2LabS(), im_rad2float().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
im_LabQ2LabS( IMAGE *in, IMAGE *out )
|
||||
vips_LabQ2LabS( VipsImage *in, VipsImage **out, ... )
|
||||
{
|
||||
if( im_check_coding_labq( "im_LabQ2LabS", in ) )
|
||||
return( -1 );
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
/* set up output image
|
||||
*/
|
||||
if( im_cp_desc( out, in ) )
|
||||
return( -1 );
|
||||
out->Bands = 3;
|
||||
out->Type = IM_TYPE_LABS;
|
||||
out->BandFmt = IM_BANDFMT_SHORT;
|
||||
out->Coding = IM_CODING_NONE;
|
||||
va_start( ap, out );
|
||||
result = vips_call_split( "LabQ2LabS", ap, in, out );
|
||||
va_end( ap );
|
||||
|
||||
/* Produce output.
|
||||
*/
|
||||
if( im_wrapone( in, out,
|
||||
(im_wrapone_fn) imb_LabQ2LabS, NULL, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
return( result );
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/* im_LabS2LabQ()
|
||||
*
|
||||
* 17/11/93 JC
|
||||
* - adapted from im_LabQ2LabS()
|
||||
* - adapted from im_LabS2LabQ()
|
||||
* 16/11/94 JC
|
||||
* - adapted to new im_wrap_oneonebuf() function
|
||||
* 15/6/95 JC
|
||||
@ -13,6 +13,8 @@
|
||||
* - a/b ==0 rounding was broken
|
||||
* 2/11/09
|
||||
* - gtkdoc, cleanup
|
||||
* 21/9/12
|
||||
* - redo as a class
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -50,25 +52,30 @@
|
||||
|
||||
#include <vips/vips.h>
|
||||
|
||||
#include "colour.h"
|
||||
|
||||
typedef VipsColourCode VipsLabS2LabQ;
|
||||
typedef VipsColourCodeClass VipsLabS2LabQClass;
|
||||
|
||||
G_DEFINE_TYPE( VipsLabS2LabQ, vips_LabS2LabQ, VIPS_TYPE_COLOUR_CODE );
|
||||
|
||||
/* Convert n pels from signed short to IM_CODING_LABQ.
|
||||
*/
|
||||
void
|
||||
imb_LabS2LabQ( signed short *in, unsigned char *out, int n )
|
||||
static void
|
||||
vips_LabS2LabQ_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
|
||||
{
|
||||
int c;
|
||||
signed short *p = in;
|
||||
signed short *p = (signed short *) in[0];
|
||||
unsigned char *q = (unsigned char *) out;
|
||||
|
||||
int i;
|
||||
int l, a, b;
|
||||
unsigned char *q = out;
|
||||
unsigned char ext;
|
||||
|
||||
for( c = 0; c < n; c++ ) {
|
||||
for( i = 0; i < width; i++ ) {
|
||||
/* Get LAB, rounding to 10, 11, 11.
|
||||
*/
|
||||
l = p[0] + 16;
|
||||
if( l < 0 )
|
||||
l = 0;
|
||||
else if( l > 32767 )
|
||||
l = 32767;
|
||||
l = VIPS_CLIP( 0, l, 32767 );
|
||||
l >>= 5;
|
||||
|
||||
/* Make sure we round -ves in the right direction!
|
||||
@ -78,10 +85,7 @@ imb_LabS2LabQ( signed short *in, unsigned char *out, int n )
|
||||
a += 16;
|
||||
else
|
||||
a -= 16;
|
||||
if( a < -32768 )
|
||||
a = -32768;
|
||||
else if( a > 32767 )
|
||||
a = 32767;
|
||||
a = VIPS_CLIP( -32768, a, 32767 );
|
||||
a >>= 5;
|
||||
|
||||
b = p[2];
|
||||
@ -89,10 +93,7 @@ imb_LabS2LabQ( signed short *in, unsigned char *out, int n )
|
||||
b += 16;
|
||||
else
|
||||
b -= 16;
|
||||
if( b < -32768 )
|
||||
b = -32768;
|
||||
else if( b > 32767 )
|
||||
b = 32767;
|
||||
b = VIPS_CLIP( -32768, b, 32767 );
|
||||
b >>= 5;
|
||||
|
||||
p += 3;
|
||||
@ -109,44 +110,57 @@ imb_LabS2LabQ( signed short *in, unsigned char *out, int n )
|
||||
ext |= (a << 3) & 0x38;
|
||||
ext |= b & 0x7;
|
||||
q[3] = ext;
|
||||
|
||||
q += 4;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vips_LabS2LabQ_class_init( VipsLabS2LabQClass *class )
|
||||
{
|
||||
VipsObjectClass *object_class = (VipsObjectClass *) class;
|
||||
VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class );
|
||||
VipsColourCodeClass *code_class = VIPS_COLOUR_CODE_CLASS( class );
|
||||
|
||||
object_class->nickname = "LabS2LabQ";
|
||||
object_class->description = _( "transform short Lab to LabQ coding" );
|
||||
|
||||
colour_class->process_line = vips_LabS2LabQ_line;
|
||||
colour_class->coding = VIPS_CODING_LABQ;
|
||||
colour_class->interpretation = VIPS_INTERPRETATION_LABQ;
|
||||
colour_class->format = VIPS_FORMAT_UCHAR;
|
||||
colour_class->bands = 4;
|
||||
|
||||
code_class->input_coding = VIPS_CODING_NONE;
|
||||
code_class->input_format = VIPS_FORMAT_SHORT;
|
||||
code_class->input_bands = 3;
|
||||
}
|
||||
|
||||
static void
|
||||
vips_LabS2LabQ_init( VipsLabS2LabQ *LabS2LabQ )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* im_LabS2LabQ:
|
||||
* vips_LabS2LabQ:
|
||||
* @in: input image
|
||||
* @out: output image
|
||||
*
|
||||
* Convert a LabS three-band signed short image to LabQ
|
||||
*
|
||||
* See also: im_LabQ2LabS().
|
||||
* See also: vips_LabQ2LabS().
|
||||
*
|
||||
* Returns: 0 on success, -1 on error.
|
||||
*/
|
||||
int
|
||||
im_LabS2LabQ( IMAGE *in, IMAGE *out )
|
||||
vips_LabS2LabQ( VipsImage *in, VipsImage **out, ... )
|
||||
{
|
||||
IMAGE *t[1];
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
if( im_check_uncoded( "im_LabS2LabQ", in ) ||
|
||||
im_check_bands( "im_LabS2LabQ", in, 3 ) ||
|
||||
im_open_local_array( out, t, 1, "im_LabS2LabQ", "p" ) ||
|
||||
im_clip2fmt( in, t[0], IM_BANDFMT_SHORT ) )
|
||||
return( -1 );
|
||||
va_start( ap, out );
|
||||
result = vips_call_split( "LabS2LabQ", ap, in, out );
|
||||
va_end( ap );
|
||||
|
||||
/* Set up output image
|
||||
*/
|
||||
if( im_cp_desc( out, in ) )
|
||||
return( -1 );
|
||||
out->Bands = 4;
|
||||
out->Type = IM_TYPE_LABQ;
|
||||
out->BandFmt = IM_BANDFMT_UCHAR;
|
||||
out->Coding = IM_CODING_LABQ;
|
||||
|
||||
if( im_wrapone( in, out,
|
||||
(im_wrapone_fn) imb_LabS2LabQ, NULL, NULL ) )
|
||||
return( -1 );
|
||||
|
||||
return( 0 );
|
||||
return( result );
|
||||
}
|
@ -20,10 +20,10 @@ libcolour_la_SOURCES = \
|
||||
LabQ2Lab.c \
|
||||
LabS2Lab.c \
|
||||
Lab2LabS.c \
|
||||
im_icc_transform.c \
|
||||
im_LabQ2LabS.c \
|
||||
LabS2LabQ.c \
|
||||
LabQ2LabS.c \
|
||||
im_LabQ2disp.c \
|
||||
im_LabS2LabQ.c \
|
||||
im_icc_transform.c \
|
||||
im_lab_morph.c \
|
||||
im_XYZ2disp.c \
|
||||
im_dE00_fromLab.c \
|
||||
|
@ -383,6 +383,8 @@ vips_colour_operation_init( 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_LabQ2LabS_get_type( void );
|
||||
extern GType vips_LabS2LabQ_get_type( void );
|
||||
extern GType vips_LabS2Lab_get_type( void );
|
||||
extern GType vips_Lab2LabS_get_type( void );
|
||||
extern GType vips_rad2float_get_type( void );
|
||||
@ -398,6 +400,8 @@ vips_colour_operation_init( void )
|
||||
vips_Yxy2XYZ_get_type();
|
||||
vips_LabQ2Lab_get_type();
|
||||
vips_Lab2LabQ_get_type();
|
||||
vips_LabQ2LabS_get_type();
|
||||
vips_LabS2LabQ_get_type();
|
||||
vips_LabS2Lab_get_type();
|
||||
vips_Lab2LabS_get_type();
|
||||
vips_rad2float_get_type();
|
||||
|
@ -321,19 +321,6 @@ vips_argb2rgba( VipsImage *in, VipsImage **out, ... )
|
||||
return( result );
|
||||
}
|
||||
|
||||
int
|
||||
vips_LabS2LabQ( VipsImage *in, VipsImage **out, ... )
|
||||
{
|
||||
va_list ap;
|
||||
int result;
|
||||
|
||||
va_start( ap, out );
|
||||
result = vips_call_split( "im_LabS2LabQ", ap, in, out );
|
||||
va_end( ap );
|
||||
|
||||
return( result );
|
||||
}
|
||||
|
||||
int
|
||||
vips_Yxy2Lab( VipsImage *in, VipsImage **out, ... )
|
||||
{
|
||||
|
@ -2419,3 +2419,35 @@ im_LabS2Lab( IMAGE *in, IMAGE *out )
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_LabQ2LabS( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
VipsImage *x;
|
||||
|
||||
if( vips_LabQ2LabS( in, &x, NULL ) )
|
||||
return( -1 );
|
||||
if( im_copy( x, out ) ) {
|
||||
g_object_unref( x );
|
||||
return( -1 );
|
||||
}
|
||||
g_object_unref( x );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
int
|
||||
im_LabS2LabQ( IMAGE *in, IMAGE *out )
|
||||
{
|
||||
VipsImage *x;
|
||||
|
||||
if( vips_LabS2LabQ( in, &x, NULL ) )
|
||||
return( -1 );
|
||||
if( im_copy( x, out ) ) {
|
||||
g_object_unref( x );
|
||||
return( -1 );
|
||||
}
|
||||
g_object_unref( x );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -103,6 +103,8 @@ int vips_float2rad( VipsImage *in, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_LabS2LabQ( VipsImage *in, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_LabQ2LabS( VipsImage *in, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_LabQ2Lab( VipsImage *in, VipsImage **out, ... )
|
||||
__attribute__((sentinel));
|
||||
int vips_Lab2LabQ( VipsImage *in, VipsImage **out, ... )
|
||||
@ -168,8 +170,6 @@ 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_LabQ2LabS( VipsImage *in, VipsImage *out );
|
||||
int im_LabS2LabQ( 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 );
|
||||
|
@ -728,6 +728,8 @@ 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 );
|
||||
int im_LabQ2LabS( VipsImage *in, VipsImage *out );
|
||||
int im_LabS2LabQ( VipsImage *in, VipsImage *out );
|
||||
|
||||
/* ruby-vips uses this
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user