Merge remote-tracking branch 'origin/7.42'
Conflicts: ChangeLog configure.ac libvips/foreign/vips2tiff.c
This commit is contained in:
commit
41b38f2fd2
@ -15,6 +15,12 @@
|
|||||||
- added vips_info_set(), vips_progress_set(), vips_profile_set() ... bindings
|
- added vips_info_set(), vips_progress_set(), vips_profile_set() ... bindings
|
||||||
can now support all the vips command-line options if they wish
|
can now support all the vips command-line options if they wish
|
||||||
|
|
||||||
|
26/3/15 started 7.42.4
|
||||||
|
- im_maxpos_avg() avoids NaN
|
||||||
|
- small tiffsave doc improvements
|
||||||
|
- better thresholding for tiffsave "squash" mode
|
||||||
|
- add @miniswhite mode to tiffsave
|
||||||
|
|
||||||
6/2/15 started 7.42.3
|
6/2/15 started 7.42.3
|
||||||
- bump version for back-compat ABI change
|
- bump version for back-compat ABI change
|
||||||
- added vips_image_memory(), an alias for vips_image_new_memory()
|
- added vips_image_memory(), an alias for vips_image_new_memory()
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
* - now handles many bands, complex, faster
|
* - now handles many bands, complex, faster
|
||||||
* 27/7/14
|
* 27/7/14
|
||||||
* - fix a race ... did not merge states if max was equal
|
* - fix a race ... did not merge states if max was equal
|
||||||
|
* 26/3/15
|
||||||
|
* - avoid NaN
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -62,32 +64,15 @@
|
|||||||
#include <vips/vips.h>
|
#include <vips/vips.h>
|
||||||
#include <vips/internal.h>
|
#include <vips/internal.h>
|
||||||
|
|
||||||
/* Get the value of pixel (0, 0). Use this to init the min/max value for
|
|
||||||
* im_max()/im_stats()/etc.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
im__value( IMAGE *im, double *value )
|
|
||||||
{
|
|
||||||
IMAGE *t;
|
|
||||||
|
|
||||||
if( !(t = im_open( "im__value", "p" )) )
|
|
||||||
return( -1 );
|
|
||||||
if( im_extract_areabands( im, t, 0, 0, 1, 1, 0, 1 ) ||
|
|
||||||
im_avg( t, value ) ) {
|
|
||||||
im_close( t );
|
|
||||||
return( -1 );
|
|
||||||
}
|
|
||||||
im_close( t );
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* A position and maximum.
|
/* A position and maximum.
|
||||||
*/
|
*/
|
||||||
typedef struct _Maxposavg {
|
typedef struct _Maxposavg {
|
||||||
int xpos;
|
int xpos;
|
||||||
int ypos;
|
int ypos;
|
||||||
double max;
|
double max;
|
||||||
|
|
||||||
|
/* occurences == 0 means we found no points, or we are uninitialised.
|
||||||
|
*/
|
||||||
int occurences;
|
int occurences;
|
||||||
} Maxposavg;
|
} Maxposavg;
|
||||||
|
|
||||||
@ -116,7 +101,9 @@ maxposavg_stop( void *seq, void *a, void *b )
|
|||||||
|
|
||||||
/* Merge.
|
/* Merge.
|
||||||
*/
|
*/
|
||||||
if( maxposavg->max > global_maxposavg->max )
|
if( maxposavg->occurences == 0 ) {
|
||||||
|
}
|
||||||
|
else if( maxposavg->max > global_maxposavg->max )
|
||||||
*global_maxposavg = *maxposavg;
|
*global_maxposavg = *maxposavg;
|
||||||
else if( maxposavg->max == global_maxposavg->max ) {
|
else if( maxposavg->max == global_maxposavg->max ) {
|
||||||
global_maxposavg->xpos += maxposavg->xpos;
|
global_maxposavg->xpos += maxposavg->xpos;
|
||||||
@ -129,7 +116,9 @@ maxposavg_stop( void *seq, void *a, void *b )
|
|||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOOP( TYPE ) { \
|
/* int loop.
|
||||||
|
*/
|
||||||
|
#define ILOOP( TYPE ) { \
|
||||||
TYPE *p = (TYPE *) in; \
|
TYPE *p = (TYPE *) in; \
|
||||||
TYPE m; \
|
TYPE m; \
|
||||||
\
|
\
|
||||||
@ -138,22 +127,53 @@ maxposavg_stop( void *seq, void *a, void *b )
|
|||||||
for( x = 0; x < sz; x++ ) { \
|
for( x = 0; x < sz; x++ ) { \
|
||||||
TYPE v = p[x]; \
|
TYPE v = p[x]; \
|
||||||
\
|
\
|
||||||
if( v == m ) { \
|
if( occurences == 0 || v > m ) { \
|
||||||
xpos += r->left + x / reg->im->Bands; \
|
|
||||||
ypos += r->top + y; \
|
|
||||||
occurences += 1; \
|
|
||||||
} \
|
|
||||||
else if( v > m ) { \
|
|
||||||
m = v; \
|
m = v; \
|
||||||
xpos = r->left + x / reg->im->Bands; \
|
xpos = r->left + x / reg->im->Bands; \
|
||||||
ypos = r->top + y; \
|
ypos = r->top + y; \
|
||||||
occurences = 1; \
|
occurences = 1; \
|
||||||
} \
|
} \
|
||||||
|
else if( v == m ) { \
|
||||||
|
xpos += r->left + x / reg->im->Bands; \
|
||||||
|
ypos += r->top + y; \
|
||||||
|
occurences += 1; \
|
||||||
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
max = m; \
|
max = m; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* float/double loop ... avoid NaN.
|
||||||
|
*/
|
||||||
|
#define FLOOP( TYPE ) { \
|
||||||
|
TYPE *p = (TYPE *) in; \
|
||||||
|
TYPE m; \
|
||||||
|
\
|
||||||
|
m = max; \
|
||||||
|
\
|
||||||
|
for( x = 0; x < sz; x++ ) { \
|
||||||
|
TYPE v = p[x]; \
|
||||||
|
\
|
||||||
|
if( isnan( v ) ) { \
|
||||||
|
} \
|
||||||
|
else if( occurences == 0 || v > m ) { \
|
||||||
|
m = v; \
|
||||||
|
xpos = r->left + x / reg->im->Bands; \
|
||||||
|
ypos = r->top + y; \
|
||||||
|
occurences = 1; \
|
||||||
|
} \
|
||||||
|
else if( v == m ) { \
|
||||||
|
xpos += r->left + x / reg->im->Bands; \
|
||||||
|
ypos += r->top + y; \
|
||||||
|
occurences += 1; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
max = m; \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* complex/dpcomplex loop ... avoid NaN.
|
||||||
|
*/
|
||||||
#define CLOOP( TYPE ) { \
|
#define CLOOP( TYPE ) { \
|
||||||
TYPE *p = (TYPE *) in; \
|
TYPE *p = (TYPE *) in; \
|
||||||
\
|
\
|
||||||
@ -165,17 +185,19 @@ maxposavg_stop( void *seq, void *a, void *b )
|
|||||||
p += 2; \
|
p += 2; \
|
||||||
mod = re * re + im * im; \
|
mod = re * re + im * im; \
|
||||||
\
|
\
|
||||||
if( mod == max ) { \
|
if( isnan( mod ) ) { \
|
||||||
xpos += r->left + x / reg->im->Bands; \
|
|
||||||
ypos += r->top + y; \
|
|
||||||
occurences += 1; \
|
|
||||||
} \
|
} \
|
||||||
else if( mod > max ) { \
|
else if( occurences == 0 || mod > max ) { \
|
||||||
max = mod; \
|
max = mod; \
|
||||||
xpos = r->left + x / reg->im->Bands; \
|
xpos = r->left + x / reg->im->Bands; \
|
||||||
ypos = r->top + y; \
|
ypos = r->top + y; \
|
||||||
occurences = 1; \
|
occurences = 1; \
|
||||||
} \
|
} \
|
||||||
|
else if( mod == max ) { \
|
||||||
|
xpos += r->left + x / reg->im->Bands; \
|
||||||
|
ypos += r->top + y; \
|
||||||
|
occurences += 1; \
|
||||||
|
} \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,14 +223,14 @@ maxposavg_scan( REGION *reg, void *seq, void *a, void *b, gboolean *stop )
|
|||||||
VipsPel *in = VIPS_REGION_ADDR( reg, r->left, r->top + y );
|
VipsPel *in = VIPS_REGION_ADDR( reg, r->left, r->top + y );
|
||||||
|
|
||||||
switch( reg->im->BandFmt ) {
|
switch( reg->im->BandFmt ) {
|
||||||
case IM_BANDFMT_UCHAR: LOOP( unsigned char ); break;
|
case IM_BANDFMT_UCHAR: ILOOP( unsigned char ); break;
|
||||||
case IM_BANDFMT_CHAR: LOOP( signed char ); break;
|
case IM_BANDFMT_CHAR: ILOOP( signed char ); break;
|
||||||
case IM_BANDFMT_USHORT: LOOP( unsigned short ); break;
|
case IM_BANDFMT_USHORT: ILOOP( unsigned short ); break;
|
||||||
case IM_BANDFMT_SHORT: LOOP( signed short ); break;
|
case IM_BANDFMT_SHORT: ILOOP( signed short ); break;
|
||||||
case IM_BANDFMT_UINT: LOOP( unsigned int ); break;
|
case IM_BANDFMT_UINT: ILOOP( unsigned int ); break;
|
||||||
case IM_BANDFMT_INT: LOOP( signed int ); break;
|
case IM_BANDFMT_INT: ILOOP( signed int ); break;
|
||||||
case IM_BANDFMT_FLOAT: LOOP( float ); break;
|
case IM_BANDFMT_FLOAT: FLOOP( float ); break;
|
||||||
case IM_BANDFMT_DOUBLE: LOOP( double ); break;
|
case IM_BANDFMT_DOUBLE: FLOOP( double ); break;
|
||||||
case IM_BANDFMT_COMPLEX: CLOOP( float ); break;
|
case IM_BANDFMT_COMPLEX: CLOOP( float ); break;
|
||||||
case IM_BANDFMT_DPCOMPLEX: CLOOP( double ); break;
|
case IM_BANDFMT_DPCOMPLEX: CLOOP( double ); break;
|
||||||
|
|
||||||
@ -251,21 +273,18 @@ im_maxpos_avg( IMAGE *in, double *xpos, double *ypos, double *out )
|
|||||||
|
|
||||||
if( !(global_maxposavg = IM_NEW( in, Maxposavg )) )
|
if( !(global_maxposavg = IM_NEW( in, Maxposavg )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
if( im__value( in, &global_maxposavg->max ) )
|
global_maxposavg->occurences = 0;
|
||||||
return( -1 );
|
|
||||||
global_maxposavg->xpos = 0;
|
|
||||||
global_maxposavg->ypos = 0;
|
|
||||||
global_maxposavg->occurences = 1;
|
|
||||||
|
|
||||||
/* We use square mod for scanning, for speed.
|
|
||||||
*/
|
|
||||||
if( vips_band_format_iscomplex( in->BandFmt ) )
|
|
||||||
global_maxposavg->max *= global_maxposavg->max;
|
|
||||||
|
|
||||||
if( vips_sink( in, maxposavg_start, maxposavg_scan, maxposavg_stop,
|
if( vips_sink( in, maxposavg_start, maxposavg_scan, maxposavg_stop,
|
||||||
in, global_maxposavg ) )
|
in, global_maxposavg ) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
|
if( global_maxposavg->occurences == 0 ) {
|
||||||
|
*xpos = nan("");
|
||||||
|
*ypos = nan("");
|
||||||
|
*out = nan("");
|
||||||
|
}
|
||||||
|
else {
|
||||||
/* Back to modulus.
|
/* Back to modulus.
|
||||||
*/
|
*/
|
||||||
if( vips_band_format_iscomplex( in->BandFmt ) )
|
if( vips_band_format_iscomplex( in->BandFmt ) )
|
||||||
@ -279,6 +298,7 @@ im_maxpos_avg( IMAGE *in, double *xpos, double *ypos, double *out )
|
|||||||
global_maxposavg->occurences;
|
global_maxposavg->occurences;
|
||||||
if( out )
|
if( out )
|
||||||
*out = global_maxposavg->max;
|
*out = global_maxposavg->max;
|
||||||
|
}
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
@ -1785,7 +1785,7 @@ vips_tiffload( const char *filename, VipsImage **out, ... )
|
|||||||
*
|
*
|
||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
* @page: load this page
|
* @page: %gint, load this page
|
||||||
*
|
*
|
||||||
* Read a TIFF-formatted memory block into a VIPS image. Exactly as
|
* Read a TIFF-formatted memory block into a VIPS image. Exactly as
|
||||||
* vips_tiffload(), but read from a memory source.
|
* vips_tiffload(), but read from a memory source.
|
||||||
@ -1825,19 +1825,20 @@ vips_tiffload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
|||||||
*
|
*
|
||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
* @compression; use this compression scheme
|
* @compression: use this #VipsForeignTiffCompression
|
||||||
* @Q: quality factor
|
* @Q: %gint quality factor
|
||||||
* @predictor; compress with this prediction
|
* @predictor: use this #VipsForeignTiffPredictor
|
||||||
* @profile: attach this ICC profile
|
* @profile: filename of ICC profile to attach
|
||||||
* @tile; set %TRUE to write a tiled tiff
|
* @tile: set %TRUE to write a tiled tiff
|
||||||
* @tile_width; set tile size
|
* @tile_width: %gint for tile size
|
||||||
* @tile_height; set tile size
|
* @tile_height: %gint for tile size
|
||||||
* @pyramid; set %TRUE to write an image pyramid
|
* @pyramid: set %TRUE to write an image pyramid
|
||||||
* @squash; squash 8-bit images down to 1 bit
|
* @squash: set %TRUE to squash 8-bit images down to 1 bit
|
||||||
* @resunit; convert resolution to pixels per inch or cm during write
|
* @miniswhite: set %TRUE to write 1-bit images as MINISWHITE
|
||||||
* @xres; horizontal resolution in pixels/mm
|
* @resunit: #VipsForeignTiffResunit for resolution unit
|
||||||
* @yres; vertical resolution in pixels/mm
|
* @xres: %gdouble horizontal resolution in pixels/mm
|
||||||
* @bigtiff; write a BigTiff file
|
* @yres: %gdouble vertical resolution in pixels/mm
|
||||||
|
* @bigtiff: set %TRUE to write a BigTiff file
|
||||||
*
|
*
|
||||||
* Write a VIPS image to a file as TIFF.
|
* Write a VIPS image to a file as TIFF.
|
||||||
*
|
*
|
||||||
@ -1875,8 +1876,12 @@ vips_tiffload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
|||||||
* Set @pyramid to write the image as a set of images, one per page, of
|
* Set @pyramid to write the image as a set of images, one per page, of
|
||||||
* decreasing size.
|
* decreasing size.
|
||||||
*
|
*
|
||||||
* Set @squash to make 8-bit uchar images write as 1-bit TIFFs with zero
|
* Set @squash to make 8-bit uchar images write as 1-bit TIFFs. Values >128
|
||||||
* pixels written as 0 and non-zero as 1.
|
* are written as white, values <=128 as black. Normally vips will write
|
||||||
|
* MINISBLACK TIFFs where black is a 0 bit, but if you set @miniswhite, it
|
||||||
|
* will use 0 for a white bit. Many pre-press applications only work with
|
||||||
|
* images which use this sense. @miniswhite only affects one-bit images, it
|
||||||
|
* does nothing for greyscale images.
|
||||||
*
|
*
|
||||||
* Use @resunit to override the default resolution unit.
|
* Use @resunit to override the default resolution unit.
|
||||||
* The default
|
* The default
|
||||||
@ -1920,9 +1925,9 @@ vips_tiffsave( VipsImage *in, const char *filename, ... )
|
|||||||
*
|
*
|
||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
* @shrink: shrink by this much on load
|
* @shrink: %gint, shrink by this much on load
|
||||||
* @fail: fail on warnings
|
* @fail: %gboolean, fail on warnings
|
||||||
* @autorotate: use exif Orientation tag to rotate the image during load
|
* @autorotate: %gboolean, use exif Orientation tag to rotate the image during load
|
||||||
*
|
*
|
||||||
* Read a JPEG file into a VIPS image. It can read most 8-bit JPEG images,
|
* Read a JPEG file into a VIPS image. It can read most 8-bit JPEG images,
|
||||||
* including CMYK and YCbCr.
|
* including CMYK and YCbCr.
|
||||||
@ -1998,8 +2003,8 @@ vips_jpegload( const char *filename, VipsImage **out, ... )
|
|||||||
*
|
*
|
||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
* @shrink: shrink by this much on load
|
* @shrink: %gint, shrink by this much on load
|
||||||
* @fail: fail on warnings
|
* @fail: %gboolean, fail on warnings
|
||||||
*
|
*
|
||||||
* Read a JPEG-formatted memory block into a VIPS image. Exactly as
|
* Read a JPEG-formatted memory block into a VIPS image. Exactly as
|
||||||
* vips_jpegload(), but read from a memory buffer.
|
* vips_jpegload(), but read from a memory buffer.
|
||||||
@ -2039,12 +2044,12 @@ vips_jpegload_buffer( void *buf, size_t len, VipsImage **out, ... )
|
|||||||
*
|
*
|
||||||
* Optional arguments:
|
* Optional arguments:
|
||||||
*
|
*
|
||||||
* @Q: quality factor
|
* @Q: %gint, quality factor
|
||||||
* @profile: attach this ICC profile
|
* @profile: filename of ICC profile to attach
|
||||||
* @optimize_coding: compute optimal Huffman coding tables
|
* @optimize_coding: %gboolean, compute optimal Huffman coding tables
|
||||||
* @interlace: write an interlaced (progressive) jpeg
|
* @interlace: %gboolean, write an interlaced (progressive) jpeg
|
||||||
* @strip: remove all metadata from image
|
* @strip: %gboolean, remove all metadata from image
|
||||||
* @no-subsample: disable chroma subsampling
|
* @no-subsample: %gboolean, disable chroma subsampling
|
||||||
*
|
*
|
||||||
* Write a VIPS image to a file as JPEG.
|
* Write a VIPS image to a file as JPEG.
|
||||||
*
|
*
|
||||||
|
@ -46,6 +46,7 @@ int vips__tiff_write( VipsImage *in, const char *filename,
|
|||||||
gboolean tile, int tile_width, int tile_height,
|
gboolean tile, int tile_width, int tile_height,
|
||||||
gboolean pyramid,
|
gboolean pyramid,
|
||||||
gboolean squash,
|
gboolean squash,
|
||||||
|
gboolean miniswhite,
|
||||||
VipsForeignTiffResunit resunit, double xres, double yres,
|
VipsForeignTiffResunit resunit, double xres, double yres,
|
||||||
gboolean bigtiff,
|
gboolean bigtiff,
|
||||||
gboolean rgbjpeg );
|
gboolean rgbjpeg );
|
||||||
|
@ -73,6 +73,7 @@ typedef struct _VipsForeignSaveTiff {
|
|||||||
int tile_height;
|
int tile_height;
|
||||||
gboolean pyramid;
|
gboolean pyramid;
|
||||||
gboolean squash;
|
gboolean squash;
|
||||||
|
gboolean miniswhite;
|
||||||
VipsForeignTiffResunit resunit;
|
VipsForeignTiffResunit resunit;
|
||||||
double xres;
|
double xres;
|
||||||
double yres;
|
double yres;
|
||||||
@ -125,6 +126,7 @@ vips_foreign_save_tiff_build( VipsObject *object )
|
|||||||
tiff->tile, tiff->tile_width, tiff->tile_height,
|
tiff->tile, tiff->tile_width, tiff->tile_height,
|
||||||
tiff->pyramid,
|
tiff->pyramid,
|
||||||
tiff->squash,
|
tiff->squash,
|
||||||
|
tiff->miniswhite,
|
||||||
tiff->resunit, tiff->xres, tiff->yres,
|
tiff->resunit, tiff->xres, tiff->yres,
|
||||||
tiff->bigtiff,
|
tiff->bigtiff,
|
||||||
tiff->rgbjpeg ) )
|
tiff->rgbjpeg ) )
|
||||||
@ -225,13 +227,19 @@ vips_foreign_save_tiff_class_init( VipsForeignSaveTiffClass *class )
|
|||||||
G_STRUCT_OFFSET( VipsForeignSaveTiff, squash ),
|
G_STRUCT_OFFSET( VipsForeignSaveTiff, squash ),
|
||||||
FALSE );
|
FALSE );
|
||||||
|
|
||||||
|
VIPS_ARG_BOOL( class, "miniswhite", 14,
|
||||||
|
_( "Miniswhite" ),
|
||||||
|
_( "Use 0 for white in 1-bit images" ),
|
||||||
|
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||||
|
G_STRUCT_OFFSET( VipsForeignSaveTiff, miniswhite ),
|
||||||
|
FALSE );
|
||||||
|
|
||||||
VIPS_ARG_ENUM( class, "resunit", 15,
|
VIPS_ARG_ENUM( class, "resunit", 15,
|
||||||
_( "Resolution unit" ),
|
_( "Resolution unit" ),
|
||||||
_( "Resolution unit" ),
|
_( "Resolution unit" ),
|
||||||
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
VIPS_ARGUMENT_OPTIONAL_INPUT,
|
||||||
G_STRUCT_OFFSET( VipsForeignSaveTiff, resunit ),
|
G_STRUCT_OFFSET( VipsForeignSaveTiff, resunit ),
|
||||||
VIPS_TYPE_FOREIGN_TIFF_RESUNIT,
|
VIPS_TYPE_FOREIGN_TIFF_RESUNIT, VIPS_FOREIGN_TIFF_RESUNIT_CM );
|
||||||
VIPS_FOREIGN_TIFF_RESUNIT_CM );
|
|
||||||
|
|
||||||
VIPS_ARG_DOUBLE( class, "xres", 16,
|
VIPS_ARG_DOUBLE( class, "xres", 16,
|
||||||
_( "Xres" ),
|
_( "Xres" ),
|
||||||
|
@ -150,6 +150,9 @@
|
|||||||
* - append later layers, don't copy the base image
|
* - append later layers, don't copy the base image
|
||||||
* - use the nice dzsave pyramid code, much faster and simpler
|
* - use the nice dzsave pyramid code, much faster and simpler
|
||||||
* - we now allow strip pyramids
|
* - we now allow strip pyramids
|
||||||
|
* 27/3/15
|
||||||
|
* - squash >128 rather than >0, nicer results for shrink
|
||||||
|
* - add miniswhite option
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -255,6 +258,7 @@ struct _Write {
|
|||||||
int tilew, tileh; /* Tile size */
|
int tilew, tileh; /* Tile size */
|
||||||
int pyramid; /* Write pyramid */
|
int pyramid; /* Write pyramid */
|
||||||
int onebit; /* Write as 1-bit TIFF */
|
int onebit; /* Write as 1-bit TIFF */
|
||||||
|
int miniswhite; /* Write as 0 == white */
|
||||||
int resunit; /* Resolution unit (inches or cm) */
|
int resunit; /* Resolution unit (inches or cm) */
|
||||||
double xres; /* Resolution in X */
|
double xres; /* Resolution in X */
|
||||||
double yres; /* Resolution in Y */
|
double yres; /* Resolution in Y */
|
||||||
@ -486,8 +490,10 @@ write_tiff_header( Write *write, Layer *layer )
|
|||||||
else if( write->onebit ) {
|
else if( write->onebit ) {
|
||||||
TIFFSetField( tif, TIFFTAG_SAMPLESPERPIXEL, 1 );
|
TIFFSetField( tif, TIFFTAG_SAMPLESPERPIXEL, 1 );
|
||||||
TIFFSetField( tif, TIFFTAG_BITSPERSAMPLE, 1 );
|
TIFFSetField( tif, TIFFTAG_BITSPERSAMPLE, 1 );
|
||||||
TIFFSetField( tif,
|
TIFFSetField( tif, TIFFTAG_PHOTOMETRIC,
|
||||||
TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK );
|
tw->miniswhite ?
|
||||||
|
PHOTOMETRIC_MINISWHITE :
|
||||||
|
PHOTOMETRIC_MINISBLACK );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int photometric;
|
int photometric;
|
||||||
@ -499,7 +505,9 @@ write_tiff_header( Write *write, Layer *layer )
|
|||||||
switch( write->im->Bands ) {
|
switch( write->im->Bands ) {
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
photometric = PHOTOMETRIC_MINISBLACK;
|
photometric = tw->miniswhite ?
|
||||||
|
PHOTOMETRIC_MINISWHITE :
|
||||||
|
PHOTOMETRIC_MINISBLACK;
|
||||||
if( write->im->Bands == 2 ) {
|
if( write->im->Bands == 2 ) {
|
||||||
v[0] = EXTRASAMPLE_ASSOCALPHA;
|
v[0] = EXTRASAMPLE_ASSOCALPHA;
|
||||||
TIFFSetField( tif, TIFFTAG_EXTRASAMPLES, 1, v );
|
TIFFSetField( tif, TIFFTAG_EXTRASAMPLES, 1, v );
|
||||||
@ -752,6 +760,7 @@ write_new( VipsImage *im, const char *filename,
|
|||||||
gboolean tile, int tile_width, int tile_height,
|
gboolean tile, int tile_width, int tile_height,
|
||||||
gboolean pyramid,
|
gboolean pyramid,
|
||||||
gboolean squash,
|
gboolean squash,
|
||||||
|
gboolean miniswhite,
|
||||||
VipsForeignTiffResunit resunit, double xres, double yres,
|
VipsForeignTiffResunit resunit, double xres, double yres,
|
||||||
gboolean bigtiff,
|
gboolean bigtiff,
|
||||||
gboolean rgbjpeg )
|
gboolean rgbjpeg )
|
||||||
@ -772,6 +781,7 @@ write_new( VipsImage *im, const char *filename,
|
|||||||
write->tileh = tile_height;
|
write->tileh = tile_height;
|
||||||
write->pyramid = pyramid;
|
write->pyramid = pyramid;
|
||||||
write->onebit = squash;
|
write->onebit = squash;
|
||||||
|
write->miniswhite = miniswhite;
|
||||||
write->icc_profile = profile;
|
write->icc_profile = profile;
|
||||||
write->bigtiff = bigtiff;
|
write->bigtiff = bigtiff;
|
||||||
write->rgbjpeg = rgbjpeg;
|
write->rgbjpeg = rgbjpeg;
|
||||||
@ -818,6 +828,18 @@ write_new( VipsImage *im, const char *filename,
|
|||||||
write->compression = COMPRESSION_NONE;
|
write->compression = COMPRESSION_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We can only MINISWHITE non-complex images of 1 or 2 bands.
|
||||||
|
*/
|
||||||
|
if( write->miniswhite &&
|
||||||
|
(im->Coding != VIPS_CODING_NONE ||
|
||||||
|
vips_band_format_iscomplex( im->BandFmt ) ||
|
||||||
|
im->Bands > 2) ) {
|
||||||
|
vips_warn( "vips2tiff",
|
||||||
|
"%s", _( "can only save non-complex greyscale images "
|
||||||
|
"as miniswhite -- disabling miniswhite" ) );
|
||||||
|
write->miniswhite = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Sizeof a line of bytes in the TIFF tile.
|
/* Sizeof a line of bytes in the TIFF tile.
|
||||||
*/
|
*/
|
||||||
if( im->Coding == VIPS_CODING_LABQ )
|
if( im->Coding == VIPS_CODING_LABQ )
|
||||||
@ -874,16 +896,23 @@ LabQ2LabC( VipsPel *q, VipsPel *p, int n )
|
|||||||
/* Pack 8 bit VIPS to 1 bit TIFF.
|
/* Pack 8 bit VIPS to 1 bit TIFF.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
eightbit2onebit( VipsPel *q, VipsPel *p, int n )
|
eightbit2onebit( TiffWrite *tw, VipsPel *q, VipsPel *p, int n )
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
VipsPel bits;
|
VipsPel bits;
|
||||||
|
|
||||||
|
/* Invert in miniswhite mode.
|
||||||
|
*/
|
||||||
|
int white = tw->miniswhite ? 0 : 1;
|
||||||
|
int black = white ^ 1;
|
||||||
|
|
||||||
bits = 0;
|
bits = 0;
|
||||||
for( x = 0; x < n; x++ ) {
|
for( x = 0; x < n; x++ ) {
|
||||||
bits <<= 1;
|
bits <<= 1;
|
||||||
if( p[x] )
|
if( p[x] > 128 )
|
||||||
bits |= 1;
|
bits |= white;
|
||||||
|
else
|
||||||
|
bits |= black;
|
||||||
|
|
||||||
if( (x & 0x7) == 0x7 ) {
|
if( (x & 0x7) == 0x7 ) {
|
||||||
*q++ = bits;
|
*q++ = bits;
|
||||||
@ -897,6 +926,75 @@ eightbit2onebit( VipsPel *q, VipsPel *p, int n )
|
|||||||
*q++ = bits << (8 - (x & 0x7));
|
*q++ = bits << (8 - (x & 0x7));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Swap the sense of the first channel, if necessary.
|
||||||
|
*/
|
||||||
|
#define GREY_LOOP( TYPE, MAX ) { \
|
||||||
|
TYPE *p1; \
|
||||||
|
TYPE *q1; \
|
||||||
|
\
|
||||||
|
p1 = (TYPE *) p; \
|
||||||
|
q1 = (TYPE *) q; \
|
||||||
|
for( x = 0; x < n; x++ ) { \
|
||||||
|
if( invert ) \
|
||||||
|
q1[0] = MAX - p1[0]; \
|
||||||
|
else \
|
||||||
|
q1[0] = p1[0]; \
|
||||||
|
\
|
||||||
|
for( i = 1; i < im->Bands; i++ ) \
|
||||||
|
q1[i] = p1[i]; \
|
||||||
|
\
|
||||||
|
q1 += im->Bands; \
|
||||||
|
p1 += im->Bands; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we're writing a 1 or 2 band image as a greyscale and MINISWHITE, we need
|
||||||
|
* to swap the sense of the first band. See tiff2vips.c, greyscale_line() for
|
||||||
|
* the opposite conversion.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
invert_band0( TiffWrite *tw, VipsPel *q, VipsPel *p, int n )
|
||||||
|
{
|
||||||
|
VipsImage *im = tw->im;
|
||||||
|
gboolean invert = tw->miniswhite;
|
||||||
|
|
||||||
|
int x, i;
|
||||||
|
|
||||||
|
switch( im->BandFmt ) {
|
||||||
|
case VIPS_FORMAT_UCHAR:
|
||||||
|
case VIPS_FORMAT_CHAR:
|
||||||
|
GREY_LOOP( guchar, UCHAR_MAX );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_SHORT:
|
||||||
|
GREY_LOOP( gshort, SHRT_MAX );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_USHORT:
|
||||||
|
GREY_LOOP( gushort, USHRT_MAX );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_INT:
|
||||||
|
GREY_LOOP( gint, INT_MAX );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_UINT:
|
||||||
|
GREY_LOOP( guint, UINT_MAX );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_FLOAT:
|
||||||
|
GREY_LOOP( float, 1.0 );
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIPS_FORMAT_DOUBLE:
|
||||||
|
GREY_LOOP( double, 1.0 );
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
g_assert( 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Convert VIPS LABS to TIFF 16 bit LAB.
|
/* Convert VIPS LABS to TIFF 16 bit LAB.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
@ -944,7 +1042,10 @@ pack2tiff( Write *write, Layer *layer,
|
|||||||
if( write->im->Coding == VIPS_CODING_LABQ )
|
if( write->im->Coding == VIPS_CODING_LABQ )
|
||||||
LabQ2LabC( q, p, area->width );
|
LabQ2LabC( q, p, area->width );
|
||||||
else if( write->onebit )
|
else if( write->onebit )
|
||||||
eightbit2onebit( q, p, area->width );
|
eightbit2onebit( tw, q, p, area->width );
|
||||||
|
else if( (in->im->Bands == 1 || in->im->Bands == 2) &&
|
||||||
|
tw->miniswhite )
|
||||||
|
invert_band0( tw, q, p, area->width );
|
||||||
else if( write->im->BandFmt == VIPS_FORMAT_SHORT &&
|
else if( write->im->BandFmt == VIPS_FORMAT_SHORT &&
|
||||||
write->im->Type == VIPS_INTERPRETATION_LABS )
|
write->im->Type == VIPS_INTERPRETATION_LABS )
|
||||||
LabS2Lab16( q, p, area->width );
|
LabS2Lab16( q, p, area->width );
|
||||||
@ -1034,7 +1135,12 @@ layer_write_strip( Write *write, Layer *layer, VipsRegion *strip )
|
|||||||
p = write->tbuf;
|
p = write->tbuf;
|
||||||
}
|
}
|
||||||
else if( write->onebit ) {
|
else if( write->onebit ) {
|
||||||
eightbit2onebit( write->tbuf, p, im->Xsize );
|
eightbit2onebit( tw, tw->tbuf, p, im->Xsize );
|
||||||
|
p = write->tbuf;
|
||||||
|
}
|
||||||
|
else if( (im->Bands == 1 || im->Bands == 2) &&
|
||||||
|
tw->miniswhite ) {
|
||||||
|
invert_band0( tw, tw->tbuf, p, im->Xsize );
|
||||||
p = write->tbuf;
|
p = write->tbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1372,6 +1478,7 @@ vips__tiff_write( VipsImage *in, const char *filename,
|
|||||||
gboolean tile, int tile_width, int tile_height,
|
gboolean tile, int tile_width, int tile_height,
|
||||||
gboolean pyramid,
|
gboolean pyramid,
|
||||||
gboolean squash,
|
gboolean squash,
|
||||||
|
gboolean miniswhite,
|
||||||
VipsForeignTiffResunit resunit, double xres, double yres,
|
VipsForeignTiffResunit resunit, double xres, double yres,
|
||||||
gboolean bigtiff,
|
gboolean bigtiff,
|
||||||
gboolean rgbjpeg )
|
gboolean rgbjpeg )
|
||||||
@ -1392,7 +1499,7 @@ vips__tiff_write( VipsImage *in, const char *filename,
|
|||||||
if( !(write = write_new( in, filename,
|
if( !(write = write_new( in, filename,
|
||||||
compression, Q, predictor, profile,
|
compression, Q, predictor, profile,
|
||||||
tile, tile_width, tile_height, pyramid, squash,
|
tile, tile_width, tile_height, pyramid, squash,
|
||||||
resunit, xres, yres, bigtiff, rgbjpeg )) )
|
miniswhite, resunit, xres, yres, bigtiff, rgbjpeg )) )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
|
||||||
if( vips_sink_disc( write->im, write_strip, write ) ) {
|
if( vips_sink_disc( write->im, write_strip, write ) ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user