This commit is contained in:
John Cupitt 2009-10-02 08:24:02 +00:00
parent f4ef665b49
commit af9ea39b6e
8 changed files with 340 additions and 409 deletions

View File

@ -52,6 +52,7 @@
- added im_segment()
- gtk-doc comments for meta
- gtk-doc comments for header
- im_printlines(), im_debugim() deprecated (use im_vips2csv() instead)
25/3/09 started 7.18.0
- revised version numbers

View File

@ -6,6 +6,8 @@ libdeprecated_la_SOURCES = \
im_gadd.c \
im_gaddim.c \
im_cmulnorm.c \
im_printlines.c \
im_debugim.c \
im_gfadd.c \
rename.c \
im_litecor.c

View File

@ -14,7 +14,6 @@ libiofuncs_la_SOURCES = \
im_bits_of_fmt.c \
im_close.c \
im_cp_desc.c \
im_debugim.c \
im_demand_hint.c \
im_generate.c \
im_histlin.c \
@ -30,8 +29,6 @@ libiofuncs_la_SOURCES = \
im_partial.c \
im_piocheck.c \
im_prepare.c \
im_printdesc.c \
im_printlines.c \
im_render.c \
im_setbox.c \
im_setbuf.c \

View File

@ -4,6 +4,9 @@
* - first version
* 24/2/05
* - print more mem allocation info
* 2/10/09
* - im_image_sanity() moved here
* - im_printdesc() moved here
*/
/*
@ -39,6 +42,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vips/vips.h>
#include <vips/internal.h>
@ -51,6 +55,178 @@
*/
GSList *im__open_images = NULL;
static const char *im_Type[] = {
"IM_TYPE_MULTIBAND", /* 0 */
"IM_TYPE_B_W", /* 1 */
"LUMINACE", /* 2 */
"XRAY", /* 3 */
"IR", /* 4 */
"YUV", /* 5 */
"RED_ONLY", /* 6 */
"GREEN_ONLY", /* 7 */
"BLUE_ONLY", /* 8 */
"POWER_SPECTRUM", /* 9 */
"IM_TYPE_HISTOGRAM", /* 10 */
"LUT", /* 11 */
"IM_TYPE_XYZ", /* 12 */
"IM_TYPE_LAB", /* 13 */
"CMC", /* 14 */
"IM_TYPE_CMYK", /* 15 */
"IM_TYPE_LABQ", /* 15 */
"IM_TYPE_RGB", /* 17 */
"IM_TYPE_UCS", /* 18 */
"IM_TYPE_LCH", /* 19 */
"IM_TYPE_LABS", /* 20 */
"<unknown>", /* 21 */
"IM_TYPE_sRGB", /* 22 */
"IM_TYPE_YXY", /* 23 */
"IM_TYPE_FOURIER", /* 24 */
"IM_TYPE_RGB16", /* 25 */
"IM_TYPE_GREY16" /* 26 */
};
static const char *im_BandFmt[] = {
"IM_BANDFMT_UCHAR",
"IM_BANDFMT_CHAR",
"IM_BANDFMT_USHORT",
"IM_BANDFMT_SHORT",
"IM_BANDFMT_UINT",
"IM_BANDFMT_INT",
"IM_BANDFMT_FLOAT",
"IM_BANDFMT_COMPLEX",
"IM_BANDFMT_DOUBLE",
"IM_BANDFMT_DPCOMPLEX"
};
static const char *im_Coding[] = {
"IM_CODING_NONE",
"COLQUANT8",
"IM_CODING_LABQ",
"IM_CODING_LABQ_COMPRESSED",
"RGB_COMPRESSED",
"LUM_COMPRESSED",
"IM_CODING_RAD"
};
static const char *im_Compression[] = {
"NO_COMPRESSION",
"TCSF_COMPRESSION",
"JPEG_COMPRESSION"
};
static const char *im_dtype[] = {
"IM_NONE",
"IM_SETBUF",
"IM_SETBUF_FOREIGN",
"IM_OPENIN",
"IM_MMAPIN",
"IM_MMAPINRW",
"IM_OPENOUT",
"IM_PARTIAL"
};
static const char *im_dhint[] = {
"IM_SMALLTILE",
"IM_FATSTRIP",
"IM_THINSTRIP",
"IM_ANY"
};
/* Stuff to decode an enum.
*/
typedef struct _EnumTable {
const char *error; /* eg. "<bad Coding>" */
const char **names; /* eg. {"IM_CODING_NONE",..} */
int nnames;
} EnumTable;
static EnumTable enumType = {
N_( "<bad Type>" ),
im_Type,
IM_NUMBER( im_Type )
};
static EnumTable enumBandFmt = {
N_( "<bad BandFmt>" ),
im_BandFmt,
IM_NUMBER( im_BandFmt )
};
static EnumTable enumCoding = {
N_( "<bad Coding>" ),
im_Coding,
IM_NUMBER( im_Coding )
};
static EnumTable enumCompression = {
N_( "<bad Compression>" ),
im_Compression,
IM_NUMBER( im_Compression )
};
static EnumTable enumdtype = {
N_( "<bad dtype>" ),
im_dtype,
IM_NUMBER( im_dtype )
};
static EnumTable enumdhint = {
N_( "<bad dhint>" ),
im_dhint,
IM_NUMBER( im_dhint )
};
static const char *
enum2char( EnumTable *etable, int n )
{
if( n < 0 || n > etable->nnames )
return( _( etable->error ) );
else
return( etable->names[n] );
}
static int
char2enum( EnumTable *etable, const char *name )
{
int i;
for( i = 0; i < etable->nnames; i++ )
if( g_ascii_strcasecmp( etable->names[i], name ) == 0 )
return( i );
im_error( "char2enum", "%s", _( etable->error ) );
return( -1 );
}
/* Prettyprint various header fields.
*/
const char *im_Type2char( VipsType type )
{ return( enum2char( &enumType, type ) ); }
const char *im_BandFmt2char( VipsBandFmt fmt )
{ return( enum2char( &enumBandFmt, fmt ) ); }
const char *im_Coding2char( VipsCoding coding )
{ return( enum2char( &enumCoding, coding ) ); }
const char *im_Compression2char( int n )
{ return( enum2char( &enumCompression, n ) ); }
const char *im_dtype2char( im_desc_type n )
{ return( enum2char( &enumdtype, n ) ); }
const char *im_dhint2char( VipsDemandStyle style )
{ return( enum2char( &enumdhint, style ) ); }
int im_char2Type( const char *str )
{ return( char2enum( &enumType, str ) ); }
int im_char2BandFmt( const char *str )
{ return( char2enum( &enumBandFmt, str ) ); }
int im_char2Coding( const char *str )
{ return( char2enum( &enumCoding, str ) ); }
int im_char2Compression( const char *str )
{ return( char2enum( &enumCompression, str ) ); }
im_desc_type im_char2dtype( const char *str )
{ return( char2enum( &enumdtype, str ) ); }
im_demand_type im_char2dhint( const char *str )
{ return( char2enum( &enumdhint, str ) ); }
static void *
print_one_line_region( REGION *r, int *n2, gint64 *total )
{
@ -140,6 +316,116 @@ im__print_all( void )
}
}
static void *
print_field_fn( IMAGE *im, const char *field, GValue *value )
{
const char *extra;
char *str_value;
str_value = g_strdup_value_contents( value );
printf( "%s: %s", field, str_value );
g_free( str_value );
/* Replace NULL static strings with "(null)".
*/
#define NN( X ) ((X) ? (X) : "(null)")
/* Look for known enums and decode them.
*/
extra = NULL;
if( strcmp( field, "Coding" ) == 0 )
extra = NN( im_Coding2char( g_value_get_int( value ) ) );
else if( strcmp( field, "BandFmt" ) == 0 )
extra = NN( im_BandFmt2char( g_value_get_int( value ) ) );
else if( strcmp( field, "Type" ) == 0 )
extra = NN( im_Type2char( g_value_get_int( value ) ) );
else if( strcmp( field, "Compression" ) == 0 )
extra = NN( im_Compression2char( g_value_get_int( value ) ) );
if( extra )
printf( " - %s", extra );
printf( "\n" );
return( NULL );
}
static void *
print_region( REGION *reg, void *a, void *b )
{
printf( "Region defined for area at %dx%d size %dx%d\n",
reg->valid.left, reg->valid.top,
reg->valid.width, reg->valid.height );
if( reg->seq )
printf( "sequence in progress on region\n" );
if( reg->buffer )
printf( "local memory allocated\n" );
return( NULL );
}
void
im_printdesc( IMAGE *image )
{
if( !image ) {
printf( "NULL descriptor\n" );
return;
}
printf( "IMAGE* %p\n", image );
if( im_isMSBfirst( image ) )
printf( "SPARC (MSB first) " );
else
printf( "Intel (LSB first) " );
printf( "byte order image, on a " );
if( im_amiMSBfirst() )
printf( "SPARC (MSB first) " );
else
printf( "Intel (LSB first) " );
printf( "byte order machine\n" );
(void) im_header_map( image, (im_header_map_fn) print_field_fn, NULL );
printf( "Hist: %s", im_history_get( image ) );
/* Print other (non-header) fields.
*/
if( image->generate )
printf( "generate function attached\n" );
if( image->closefns )
printf( "close callbacks attached\n" );
if( image->evalfns )
printf( "eval callbacks attached\n" );
if( image->evalendfns )
printf( "evalend callbacks attached\n" );
if( image->evalstartfns )
printf( "evalstart callbacks attached\n" );
if( image->preclosefns )
printf( "preclose callbacks attached\n" );
if( image->invalidatefns )
printf( "invalidate callbacks attached\n" );
if( image->regions ) {
printf( "%d regions present\n",
g_slist_length( image->regions ) );
im_slist_map2( image->regions,
(VSListMap2Fn) print_region, NULL, NULL );
}
if( image->kill )
printf( "kill flag set\n" );
if( image->closing )
printf( "closing flag set\n" );
if( image->close_pending )
printf( "close_pending flag set\n" );
#ifdef DEBUG
/* Can't get these with im_header_get(), so only show for debugging.
*/
printf( "dhint: %s\n", im_dhint2char( image->dhint ) );
printf( "dtype: %s\n", im_dtype2char( image->dtype ) );
#endif /*DEBUG*/
}
/* Debugging: given an index, print everything we know about that descriptor.
*/
void
@ -154,3 +440,54 @@ im__print_one( int n )
im_printdesc( im );
}
/* Test an image for sanity. We could add many more tests here.
*/
static const char *
image_sanity( IMAGE *im )
{
if( !im )
return( "NULL descriptor" );
if( !im->filename )
return( "NULL filename" );
g_mutex_lock( im__global_lock );
if( !g_slist_find( im__open_images, im ) ) {
g_mutex_unlock( im__global_lock );
return( "not on open image list" );
}
g_mutex_unlock( im__global_lock );
if( im->Xsize <= 0 || im->Ysize <= 0 || im->Bands <= 0 )
return( "bad dimensions" );
if( im->BandFmt < -1 || im->BandFmt > IM_BANDFMT_DPCOMPLEX ||
(im->Coding != -1 &&
im->Coding != IM_CODING_NONE &&
im->Coding != IM_CODING_LABQ &&
im->Coding != IM_CODING_RAD) ||
im->Type < -1 || im->Type > IM_TYPE_GREY16 ||
im->dtype > IM_PARTIAL || im->dhint > IM_ANY )
return( "bad enum value" );
if( im->Xres < 0 || im->Xres < 0 )
return( "bad resolution" );
return( NULL );
}
int
im_image_sanity( IMAGE *im )
{
const char *msg;
if( (msg = image_sanity( im )) ) {
im_warn( "im_image_sanity", "%p", im );
im_warn( "im_image_sanity", "\"%s\" %s",
im ? (im->filename ? im->filename : "") : "",
msg );
im_printdesc( im );
return( -1 );
}
return( 0 );
}

View File

@ -438,57 +438,6 @@ im_open( const char *filename, const char *mode )
return( im );
}
/* Test an image for sanity. We could add many more tests here.
*/
static const char *
image_sanity( IMAGE *im )
{
if( !im )
return( "NULL descriptor" );
if( !im->filename )
return( "NULL filename" );
g_mutex_lock( im__global_lock );
if( !g_slist_find( im__open_images, im ) ) {
g_mutex_unlock( im__global_lock );
return( "not on open image list" );
}
g_mutex_unlock( im__global_lock );
if( im->Xsize <= 0 || im->Ysize <= 0 || im->Bands <= 0 )
return( "bad dimensions" );
if( im->BandFmt < -1 || im->BandFmt > IM_BANDFMT_DPCOMPLEX ||
(im->Coding != -1 &&
im->Coding != IM_CODING_NONE &&
im->Coding != IM_CODING_LABQ &&
im->Coding != IM_CODING_RAD) ||
im->Type < -1 || im->Type > IM_TYPE_GREY16 ||
im->dtype > IM_PARTIAL || im->dhint > IM_ANY )
return( "bad enum value" );
if( im->Xres < 0 || im->Xres < 0 )
return( "bad resolution" );
return( NULL );
}
int
im_image_sanity( IMAGE *im )
{
const char *msg;
if( (msg = image_sanity( im )) ) {
im_warn( "im_image_sanity", "%p", im );
im_warn( "im_image_sanity", "\"%s\" %s",
im ? (im->filename ? im->filename : "") : "",
msg );
im_printdesc( im );
return( -1 );
}
return( 0 );
}
/* Just here for compatibility.
*/
IMAGE *

View File

@ -1,355 +0,0 @@
/* @(#) display VIPS IMAGE descriptor for debugging
* @(#) a valid IMAGE descriptor is needed
* @(#) HANDLESIMAGE
* @(#) Static strings must be modified if header files are changed
* @(#) void im_printdesc(image)
* @(#) IMAGE *image;
*
* Copyright: Nicos Dessipris
* Written on: 15/01/1990
* Modified on : 3/6/92 Kirk Martinez
* 15/4/93 JC
* - partial regions dumped too
* - resolution bug fixed
* 11/5/93 JC
* - formatting changed for ctags
* 1/7/93 JC
* - adapted for partial v2
* 15/11/94 JC
* - new Coding types added
* - new Type values added
* - new Compression type added
* 2/3/98 JC
* - IM_ANY added
* 5/11/98 JC
* - prints byte-order too
* 1/8/05
* - prints meta header fields too
* 9/9/05
* - oops, shouldn't print filename ourselves
* 4/1/07
* - use new im_history_get() thing
*/
/*
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
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 <vips/intl.h>
#include <stdio.h>
#include <string.h>
#include <vips/vips.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/
static const char *im_Type[] = {
"IM_TYPE_MULTIBAND", /* 0 */
"IM_TYPE_B_W", /* 1 */
"LUMINACE", /* 2 */
"XRAY", /* 3 */
"IR", /* 4 */
"YUV", /* 5 */
"RED_ONLY", /* 6 */
"GREEN_ONLY", /* 7 */
"BLUE_ONLY", /* 8 */
"POWER_SPECTRUM", /* 9 */
"IM_TYPE_HISTOGRAM", /* 10 */
"LUT", /* 11 */
"IM_TYPE_XYZ", /* 12 */
"IM_TYPE_LAB", /* 13 */
"CMC", /* 14 */
"IM_TYPE_CMYK", /* 15 */
"IM_TYPE_LABQ", /* 15 */
"IM_TYPE_RGB", /* 17 */
"IM_TYPE_UCS", /* 18 */
"IM_TYPE_LCH", /* 19 */
"IM_TYPE_LABS", /* 20 */
"<unknown>", /* 21 */
"IM_TYPE_sRGB", /* 22 */
"IM_TYPE_YXY", /* 23 */
"IM_TYPE_FOURIER", /* 24 */
"IM_TYPE_RGB16", /* 25 */
"IM_TYPE_GREY16" /* 26 */
};
static const char *im_BandFmt[] = {
"IM_BANDFMT_UCHAR",
"IM_BANDFMT_CHAR",
"IM_BANDFMT_USHORT",
"IM_BANDFMT_SHORT",
"IM_BANDFMT_UINT",
"IM_BANDFMT_INT",
"IM_BANDFMT_FLOAT",
"IM_BANDFMT_COMPLEX",
"IM_BANDFMT_DOUBLE",
"IM_BANDFMT_DPCOMPLEX"
};
static const char *im_Coding[] = {
"IM_CODING_NONE",
"COLQUANT8",
"IM_CODING_LABQ",
"IM_CODING_LABQ_COMPRESSED",
"RGB_COMPRESSED",
"LUM_COMPRESSED",
"IM_CODING_RAD"
};
static const char *im_Compression[] = {
"NO_COMPRESSION",
"TCSF_COMPRESSION",
"JPEG_COMPRESSION"
};
static const char *im_dtype[] = {
"IM_NONE",
"IM_SETBUF",
"IM_SETBUF_FOREIGN",
"IM_OPENIN",
"IM_MMAPIN",
"IM_MMAPINRW",
"IM_OPENOUT",
"IM_PARTIAL"
};
static const char *im_dhint[] = {
"IM_SMALLTILE",
"IM_FATSTRIP",
"IM_THINSTRIP",
"IM_ANY"
};
/* Stuff to decode an enum.
*/
typedef struct _EnumTable {
const char *error; /* eg. "<bad Coding>" */
const char **names; /* eg. {"IM_CODING_NONE",..} */
int nnames;
} EnumTable;
static EnumTable enumType = {
N_( "<bad Type>" ),
im_Type,
IM_NUMBER( im_Type )
};
static EnumTable enumBandFmt = {
N_( "<bad BandFmt>" ),
im_BandFmt,
IM_NUMBER( im_BandFmt )
};
static EnumTable enumCoding = {
N_( "<bad Coding>" ),
im_Coding,
IM_NUMBER( im_Coding )
};
static EnumTable enumCompression = {
N_( "<bad Compression>" ),
im_Compression,
IM_NUMBER( im_Compression )
};
static EnumTable enumdtype = {
N_( "<bad dtype>" ),
im_dtype,
IM_NUMBER( im_dtype )
};
static EnumTable enumdhint = {
N_( "<bad dhint>" ),
im_dhint,
IM_NUMBER( im_dhint )
};
static const char *
enum2char( EnumTable *etable, int n )
{
if( n < 0 || n > etable->nnames )
return( _( etable->error ) );
else
return( etable->names[n] );
}
static int
char2enum( EnumTable *etable, const char *name )
{
int i;
for( i = 0; i < etable->nnames; i++ )
if( g_ascii_strcasecmp( etable->names[i], name ) == 0 )
return( i );
im_error( "char2enum", "%s", _( etable->error ) );
return( -1 );
}
/* Prettyprint various header fields.
*/
const char *im_Type2char( VipsType type )
{ return( enum2char( &enumType, type ) ); }
const char *im_BandFmt2char( VipsBandFmt fmt )
{ return( enum2char( &enumBandFmt, fmt ) ); }
const char *im_Coding2char( VipsCoding coding )
{ return( enum2char( &enumCoding, coding ) ); }
const char *im_Compression2char( int n )
{ return( enum2char( &enumCompression, n ) ); }
const char *im_dtype2char( im_desc_type n )
{ return( enum2char( &enumdtype, n ) ); }
const char *im_dhint2char( VipsDemandStyle style )
{ return( enum2char( &enumdhint, style ) ); }
int im_char2Type( const char *str )
{ return( char2enum( &enumType, str ) ); }
int im_char2BandFmt( const char *str )
{ return( char2enum( &enumBandFmt, str ) ); }
int im_char2Coding( const char *str )
{ return( char2enum( &enumCoding, str ) ); }
int im_char2Compression( const char *str )
{ return( char2enum( &enumCompression, str ) ); }
im_desc_type im_char2dtype( const char *str )
{ return( char2enum( &enumdtype, str ) ); }
im_demand_type im_char2dhint( const char *str )
{ return( char2enum( &enumdhint, str ) ); }
static void *
print_field_fn( IMAGE *im, const char *field, GValue *value )
{
const char *extra;
char *str_value;
str_value = g_strdup_value_contents( value );
printf( "%s: %s", field, str_value );
g_free( str_value );
/* Replace NULL static strings with "(null)".
*/
#define NN( X ) ((X) ? (X) : "(null)")
/* Look for known enums and decode them.
*/
extra = NULL;
if( strcmp( field, "Coding" ) == 0 )
extra = NN( im_Coding2char( g_value_get_int( value ) ) );
else if( strcmp( field, "BandFmt" ) == 0 )
extra = NN( im_BandFmt2char( g_value_get_int( value ) ) );
else if( strcmp( field, "Type" ) == 0 )
extra = NN( im_Type2char( g_value_get_int( value ) ) );
else if( strcmp( field, "Compression" ) == 0 )
extra = NN( im_Compression2char( g_value_get_int( value ) ) );
if( extra )
printf( " - %s", extra );
printf( "\n" );
return( NULL );
}
static void *
print_region( REGION *reg, void *a, void *b )
{
printf( "Region defined for area at %dx%d size %dx%d\n",
reg->valid.left, reg->valid.top,
reg->valid.width, reg->valid.height );
if( reg->seq )
printf( "sequence in progress on region\n" );
if( reg->buffer )
printf( "local memory allocated\n" );
return( NULL );
}
void
im_printdesc( IMAGE *image )
{
if( !image ) {
printf( "NULL descriptor\n" );
return;
}
printf( "IMAGE* %p\n", image );
if( im_isMSBfirst( image ) )
printf( "SPARC (MSB first) " );
else
printf( "Intel (LSB first) " );
printf( "byte order image, on a " );
if( im_amiMSBfirst() )
printf( "SPARC (MSB first) " );
else
printf( "Intel (LSB first) " );
printf( "byte order machine\n" );
(void) im_header_map( image, (im_header_map_fn) print_field_fn, NULL );
printf( "Hist: %s", im_history_get( image ) );
/* Print other (non-header) fields.
*/
if( image->generate )
printf( "generate function attached\n" );
if( image->closefns )
printf( "close callbacks attached\n" );
if( image->evalfns )
printf( "eval callbacks attached\n" );
if( image->evalendfns )
printf( "evalend callbacks attached\n" );
if( image->evalstartfns )
printf( "evalstart callbacks attached\n" );
if( image->preclosefns )
printf( "preclose callbacks attached\n" );
if( image->invalidatefns )
printf( "invalidate callbacks attached\n" );
if( image->regions ) {
printf( "%d regions present\n",
g_slist_length( image->regions ) );
im_slist_map2( image->regions,
(VSListMap2Fn) print_region, NULL, NULL );
}
if( image->kill )
printf( "kill flag set\n" );
if( image->closing )
printf( "closing flag set\n" );
if( image->close_pending )
printf( "close_pending flag set\n" );
#ifdef DEBUG
/* Can't get these with im_header_get(), so only show for debugging.
*/
printf( "dhint: %s\n", im_dhint2char( image->dhint ) );
printf( "dtype: %s\n", im_dtype2char( image->dtype ) );
#endif /*DEBUG*/
}